[FFmpeg-devel] [PATCH 4/6] checkasm: make bench clean-up also a function pointer

Rémi Denis-Courmont remi at remlab.net
Wed Jul 19 22:55:38 EEST 2023


There are no performance concerns with cleaning up, so might as well
indirect it. This incidentally fixes a corner case (and
inconsequential) bug whereby the Linux perf descriptor is zero and did
not get closed.
---
 tests/checkasm/checkasm.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 987162e6b5..fad660a924 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -320,9 +320,12 @@ static struct {
 
     /* perf */
     int nop_time;
+#if CONFIG_LINUX_PERF
     int sysfd;
+#endif
     uint64_t (*start)(void);
     uint64_t (*stop)(void);
+    void (*close)(void);
 
     int cpu_flag;
     const char *cpu_flag_name;
@@ -683,6 +686,11 @@ static uint64_t checkasm_bench_linux_perf_stop(void)
     return (read(fd, &t, sizeof(t)) == sizeof (t)) ? t : 0;
 }
 
+static void checkasm_bench_linux_perf_close(void)
+{
+    close(state.sysfd);
+}
+
 static int bench_init_linux(void)
 {
     struct perf_event_attr attr = {
@@ -703,6 +711,7 @@ static int bench_init_linux(void)
     }
     state.start = checkasm_bench_linux_perf_start;
     state.stop = checkasm_bench_linux_perf_stop;
+    state.close = checkasm_bench_linux_perf_close;
     return 0;
 }
 #elif CONFIG_MACOS_KPERF
@@ -742,14 +751,6 @@ static int bench_init(void)
     return 0;
 }
 
-static void bench_uninit(void)
-{
-#if CONFIG_LINUX_PERF
-    if (state.sysfd > 0)
-        close(state.sysfd);
-#endif
-}
-
 static int usage(const char *path)
 {
     fprintf(stderr,
@@ -816,7 +817,8 @@ int main(int argc, char *argv[])
     }
 
     destroy_func_tree(state.funcs);
-    bench_uninit();
+    if (state.close != NULL)
+        state.close();
     return ret;
 }
 
-- 
2.40.1



More information about the ffmpeg-devel mailing list