[FFmpeg-devel] [PATCH 1/2] avutil/timer: define macos kperf as AV_READ_TIME
Zhao Zhili
quinkblack at foxmail.com
Wed Jun 12 18:22:51 EEST 2024
From: Zhao Zhili <zhilizhao at tencent.com>
Firstly, make ff_kperf_cycles as an implementation of AV_READ_TIME
avoids code duplication.
Secondly, fix compilation error since 6a18c0bc87e when macos-kperf
is enabled. mach_time.h is included only when CONFIG_MACOS_KPERF
is 0. The error happened due to define mach_absolute_time as
AV_READ_TIME but missing include mach_time.h. Define macos kperf
as AV_READ_TIME fixed the issue.
---
libavutil/macos_kperf.c | 8 +++-----
libavutil/macos_kperf.h | 3 ++-
libavutil/timer.h | 10 ----------
tests/checkasm/checkasm.c | 8 --------
4 files changed, 5 insertions(+), 24 deletions(-)
diff --git a/libavutil/macos_kperf.c b/libavutil/macos_kperf.c
index 9fb047eeee..a0bc845fd3 100644
--- a/libavutil/macos_kperf.c
+++ b/libavutil/macos_kperf.c
@@ -96,15 +96,13 @@ static void kperf_init(void)
av_assert0(kpc_set_thread_counting(KPC_MASK) == 0);
}
-void ff_kperf_init(void)
+uint64_t ff_kperf_cycles(void)
{
static AVOnce init_static_once = AV_ONCE_INIT;
+ uint64_t counters[COUNTERS_COUNT];
+
ff_thread_once(&init_static_once, kperf_init);
-}
-uint64_t ff_kperf_cycles(void)
-{
- uint64_t counters[COUNTERS_COUNT];
if (kpc_get_thread_counters(0, COUNTERS_COUNT, counters)) {
return -1;
}
diff --git a/libavutil/macos_kperf.h b/libavutil/macos_kperf.h
index d039691340..40bbc616df 100644
--- a/libavutil/macos_kperf.h
+++ b/libavutil/macos_kperf.h
@@ -21,7 +21,8 @@
#include <stdint.h>
-void ff_kperf_init(void);
uint64_t ff_kperf_cycles(void);
+#define AV_READ_TIME ff_kperf_cycles
+
#endif /* AVUTIL_MACOS_KPERF_H */
diff --git a/libavutil/timer.h b/libavutil/timer.h
index 6bd6a0c645..16f2b1a96c 100644
--- a/libavutil/timer.h
+++ b/libavutil/timer.h
@@ -142,16 +142,6 @@
read(linux_perf_fd, &tperf, sizeof(tperf)); \
TIMER_REPORT(id, tperf)
-#elif CONFIG_MACOS_KPERF
-
-#define START_TIMER \
- uint64_t tperf; \
- ff_kperf_init(); \
- tperf = ff_kperf_cycles();
-
-#define STOP_TIMER(id) \
- TIMER_REPORT(id, ff_kperf_cycles() - tperf);
-
#elif defined(AV_READ_TIME)
#define START_TIMER \
uint64_t tend; \
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 2329e2e1bc..28237b4d25 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -775,12 +775,6 @@ static int bench_init_linux(void)
}
return 0;
}
-#elif CONFIG_MACOS_KPERF
-static int bench_init_kperf(void)
-{
- ff_kperf_init();
- return 0;
-}
#else
static int bench_init_ffmpeg(void)
{
@@ -806,8 +800,6 @@ static int bench_init(void)
{
#if CONFIG_LINUX_PERF
int ret = bench_init_linux();
-#elif CONFIG_MACOS_KPERF
- int ret = bench_init_kperf();
#else
int ret = bench_init_ffmpeg();
#endif
--
2.42.0
More information about the ffmpeg-devel
mailing list