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