diff mbox series

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

Message ID 20230715152339.13234-5-remi@remlab.net
State New
Headers show
Series checkasm: RISC-V Linux perf enablement | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Rémi Denis-Courmont July 15, 2023, 3:23 p.m. UTC
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 mbox series

Patch

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;
 }