diff mbox series

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

Message ID 20230719195540.46961-4-remi@remlab.net
State New
Headers show
Series RISC-V Linux perf run-time 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 19, 2023, 7:55 p.m. UTC
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 mbox series

Patch

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