diff mbox series

[FFmpeg-devel] avutil: use getauxval on linux/android for CPU capabilities

Message ID 20220204201621.20125-1-ffmpeg@tmm1.net
State New
Headers show
Series [FFmpeg-devel] avutil: use getauxval on linux/android for CPU capabilities | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Aman Karmani Feb. 4, 2022, 8:16 p.m. UTC
From: Aman Karmani <aman@tmm1.net>

fixes #6578

Signed-off-by: Aman Karmani <aman@tmm1.net>
---
 libavutil/arm/cpu.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Martin Storsjö Feb. 4, 2022, 10:20 p.m. UTC | #1
On Fri, 4 Feb 2022, Aman Karmani wrote:

> From: Aman Karmani <aman@tmm1.net>
>
> fixes #6578
>
> Signed-off-by: Aman Karmani <aman@tmm1.net>
> ---
> libavutil/arm/cpu.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)

It would be good if the commit message actually explained the upsides to 
doing this.

It's also important to point out that this function didn't use to exist in 
all Android versions (hence the /proc/cpuinfo parsing). The point when the 
function appeared (Android 4.4, API 20, according to the referenced trac 
issue) is kinda far in the past today, but I'm not sure if strictly all 
users of the library have stopped supporting older versions still - at 
least for some use cases I've heard of recently, Android 4.1 was still 
supported.

If coupled with a configure check for the function, so that users 
explicitly targeting an older version that lack it wouldn't get it, I 
guess this could be more easily acceptable.

// Martin
Aman Karmani Feb. 5, 2022, 6:25 a.m. UTC | #2
On Fri, Feb 4, 2022 at 2:20 PM Martin Storsjö <martin@martin.st> wrote:

> On Fri, 4 Feb 2022, Aman Karmani wrote:
>
> > From: Aman Karmani <aman@tmm1.net>
> >
> > fixes #6578
> >
> > Signed-off-by: Aman Karmani <aman@tmm1.net>
> > ---
> > libavutil/arm/cpu.c | 17 ++++++++++++++---
> > 1 file changed, 14 insertions(+), 3 deletions(-)
>
> It would be good if the commit message actually explained the upsides to
> doing this.
>
> It's also important to point out that this function didn't use to exist in
> all Android versions (hence the /proc/cpuinfo parsing). The point when the
> function appeared (Android 4.4, API 20, according to the referenced trac
> issue) is kinda far in the past today, but I'm not sure if strictly all
> users of the library have stopped supporting older versions still - at
> least for some use cases I've heard of recently, Android 4.1 was still
> supported.
>
> If coupled with a configure check for the function, so that users
> explicitly targeting an older version that lack it wouldn't get it, I
> guess this could be more easily acceptable.


Thanks for the review.

I discovered some older Linux arm toolchains (< glibc 2.16) are also
missing the function, so a configure check seems prudent.

Sent v2 patch with the requested changes.


>
> // Martin
>
>
diff mbox series

Patch

diff --git a/libavutil/arm/cpu.c b/libavutil/arm/cpu.c
index 81e85e2525..983e5a4d83 100644
--- a/libavutil/arm/cpu.c
+++ b/libavutil/arm/cpu.c
@@ -36,6 +36,7 @@ 
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/auxv.h>
 #include "libavutil/avstring.h"
 
 #define AT_HWCAP        16
@@ -48,6 +49,15 @@ 
 #define HWCAP_VFPv3     (1 << 13)
 #define HWCAP_TLS       (1 << 15)
 
+static int get_auxval(uint32_t *hwcap)
+{
+    unsigned long ret = getauxval(AT_HWCAP);
+    if (ret == 0)
+        return -1;
+    *hwcap = ret;
+    return 0;
+}
+
 static int get_hwcap(uint32_t *hwcap)
 {
     struct { uint32_t a_type; uint32_t a_val; } auxv;
@@ -106,9 +116,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)              \