[FFmpeg-cvslog] aarch64: Use cntvct_el0 as timer register on Android and macOS
Martin Storsjö
git at videolan.org
Mon Jun 17 14:02:05 EEST 2024
ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Jun 7 11:39:08 2024 +0300| [ab8f7030bc46e5031d2ba438eddf0739098e3e5d] | committer: Martin Storsjö
aarch64: Use cntvct_el0 as timer register on Android and macOS
The default timer register pmccntr_el0 usually requires enabling
access with e.g. a kernel module (while it is accessible by
default on Windows). On Linux, the default for checkasm benchmarks
is to use perf (if suitable headers are available) though.
On macOS, using cntvct_el0 gives measurements with the same
magnitude as mach_absolute_time (which is used currently), but
possibly with a little less overhead/noise.
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ab8f7030bc46e5031d2ba438eddf0739098e3e5d
---
libavutil/aarch64/timer.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavutil/aarch64/timer.h b/libavutil/aarch64/timer.h
index fadc9568f8..922b0c5598 100644
--- a/libavutil/aarch64/timer.h
+++ b/libavutil/aarch64/timer.h
@@ -24,7 +24,7 @@
#include <stdint.h>
#include "config.h"
-#if HAVE_INLINE_ASM && !defined(__APPLE__)
+#if HAVE_INLINE_ASM
#define AV_READ_TIME read_time
@@ -33,7 +33,16 @@ static inline uint64_t read_time(void)
uint64_t cycle_counter;
__asm__ volatile(
"isb \t\n"
+#if defined(__ANDROID__) || defined(__APPLE__)
+ // cntvct_el0 has lower resolution than pmccntr_el0, but is usually
+ // accessible from user space by default.
+ "mrs %0, cntvct_el0 "
+#else
+ // pmccntr_el0 has higher resolution, but is usually not accessible
+ // from user space by default (but access can be enabled with a custom
+ // kernel module).
"mrs %0, pmccntr_el0 "
+#endif
: "=r"(cycle_counter) :: "memory" );
return cycle_counter;
More information about the ffmpeg-cvslog
mailing list