aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2024-06-07 11:39:08 +0300
committerMartin Storsjö <martin@martin.st>2024-06-17 14:00:34 +0300
commitab8f7030bc46e5031d2ba438eddf0739098e3e5d (patch)
treed7510a47d00d0e2fc88782a0bae926c0a39f79a9
parentfcf72966a5f20b9d5df6889e748abd04019b56aa (diff)
downloadffmpeg-ab8f7030bc46e5031d2ba438eddf0739098e3e5d.tar.gz
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@martin.st>
-rw-r--r--libavutil/aarch64/timer.h11
1 files changed, 10 insertions, 1 deletions
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;