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

Rémi Denis-Courmont remi at remlab.net
Sat Jul 15 18:23:37 EEST 2023


Because we might as well at this point. This incidentally fixes a corner
case bug that state.sys_fd == 0 could be either the initial value from
.bss or a valid file descriptor (in which case it didn't 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 c90f361ff7..2e327de3a4 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -319,7 +319,9 @@ static struct {
 
     /* perf */
     int nop_time;
+#ifdef CONFIG_LINUX_PERF
     int sysfd;
+#endif
 
     int cpu_flag;
     const char *cpu_flag_name;
@@ -516,6 +518,7 @@ static int cmp_nop(const void *a, const void *b)
 
 static uint64_t (*checkasm_bench_start)(void);
 static uint64_t (*checkasm_bench_stop)(void);
+static void (*checkasm_bench_close)(void);
 
 /* Measure the overhead of the timing code (in decicycles) */
 static int measure_nop_time(void)
@@ -677,6 +680,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 = {
@@ -697,6 +705,7 @@ static int bench_init_linux(void)
     }
     checkasm_bench_start = checkasm_bench_linux_perf_start;
     checkasm_bench_stop = checkasm_bench_linux_perf_stop;
+    checkasm_bench_close = checkasm_bench_linux_perf_close;
     return 0;
 }
 #elif CONFIG_MACOS_KPERF
@@ -743,14 +752,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
-}
-
 int main(int argc, char *argv[])
 {
     unsigned int seed = av_get_random_seed();
@@ -805,7 +806,8 @@ int main(int argc, char *argv[])
     }
 
     destroy_func_tree(state.funcs);
-    bench_uninit();
+    if (checkasm_bench_close != NULL)
+        checkasm_bench_close();
     return ret;
 }
 
-- 
2.40.1



More information about the ffmpeg-devel mailing list