[FFmpeg-cvslog] avutil: use getauxval(3) for CPU capabilities on linux/android ARM

Aman Karmani git at videolan.org
Mon Feb 7 23:46:12 EET 2022


ffmpeg | branch: master | Aman Karmani <aman at tmm1.net> | Fri Feb  4 12:14:57 2022 -0800| [2f299c0b8b4ab1b549b25ab48aa2adbc9f8718ea] | committer: Aman Karmani

avutil: use getauxval(3) for CPU capabilities on linux/android ARM

getauxval is marginally faster, and works even when procfs is not mounted

support on Linux was added in glibc 2.16
support on Android was added in 4.4 (API 20)
fixes #6578

Signed-off-by: Aman Karmani <aman at tmm1.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2f299c0b8b4ab1b549b25ab48aa2adbc9f8718ea
---

 configure           |  1 +
 libavutil/arm/cpu.c | 24 +++++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index c915953430..395f0a64ee 100755
--- a/configure
+++ b/configure
@@ -6261,6 +6261,7 @@ check_func_headers lzo/lzo1x.h lzo1x_999_compress
 check_func_headers mach/mach_time.h mach_absolute_time
 check_func_headers stdlib.h getenv
 check_func_headers sys/stat.h lstat
+check_func_headers sys/auxv.h getauxval
 
 check_func_headers windows.h GetModuleHandle
 check_func_headers windows.h GetProcessAffinityMask
diff --git a/libavutil/arm/cpu.c b/libavutil/arm/cpu.c
index 81e85e2525..c84a655c37 100644
--- a/libavutil/arm/cpu.c
+++ b/libavutil/arm/cpu.c
@@ -38,6 +38,10 @@
 #include <string.h>
 #include "libavutil/avstring.h"
 
+#if HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#endif
+
 #define AT_HWCAP        16
 
 /* Relevant HWCAP values from kernel headers */
@@ -48,6 +52,19 @@
 #define HWCAP_VFPv3     (1 << 13)
 #define HWCAP_TLS       (1 << 15)
 
+static int get_auxval(uint32_t *hwcap)
+{
+#if HAVE_GETAUXVAL
+    unsigned long ret = getauxval(AT_HWCAP);
+    if (ret == 0)
+        return -1;
+    *hwcap = ret;
+    return 0;
+#else
+    return -1;
+#endif
+}
+
 static int get_hwcap(uint32_t *hwcap)
 {
     struct { uint32_t a_type; uint32_t a_val; } auxv;
@@ -106,9 +123,10 @@ int ff_get_cpu_flags_arm(void)
     int flags = CORE_CPU_FLAGS;
     uint32_t hwcap;
 
-    if (get_hwcap(&hwcap) < 0)
-        if (get_cpuinfo(&hwcap) < 0)
-            return flags;
+    if (get_auxval(&hwcap) < 0)
+        if (get_hwcap(&hwcap) < 0)
+            if (get_cpuinfo(&hwcap) < 0)
+                return flags;
 
 #define check_cap(cap, flag) do {               \
         if (hwcap & HWCAP_ ## cap)              \



More information about the ffmpeg-cvslog mailing list