Message ID | Zsnd84mx4M3ZuKwZ@humpty.home.comstyle.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
ping. On 2024-08-24 9:19 a.m., Brad Smith wrote: > avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() > > Initially used for getauxval() but will be used to add support for > other API. > > Signed-off-by: Brad Smith <brad@comstyle.com> > --- > libavutil/aarch64/cpu.c | 4 ++-- > libavutil/arm/cpu.c | 2 +- > libavutil/cpu.c | 14 ++++++++++++++ > libavutil/cpu_internal.h | 2 ++ > libavutil/loongarch/cpu.c | 2 +- > libavutil/mips/cpu.c | 2 +- > libavutil/riscv/cpu.c | 2 +- > 7 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c > index cfa9306663..084c81e999 100644 > --- a/libavutil/aarch64/cpu.c > +++ b/libavutil/aarch64/cpu.c > @@ -31,8 +31,8 @@ static int detect_flags(void) > { > int flags = 0; > > - unsigned long hwcap = getauxval(AT_HWCAP); > - unsigned long hwcap2 = getauxval(AT_HWCAP2); > + unsigned long hwcap = ff_getauxval(AT_HWCAP); > + unsigned long hwcap2 = ff_getauxval(AT_HWCAP2); > > if (hwcap & HWCAP_AARCH64_ASIMDDP) > flags |= AV_CPU_FLAG_DOTPROD; > diff --git a/libavutil/arm/cpu.c b/libavutil/arm/cpu.c > index c84a655c37..b84882005a 100644 > --- a/libavutil/arm/cpu.c > +++ b/libavutil/arm/cpu.c > @@ -55,7 +55,7 @@ > static int get_auxval(uint32_t *hwcap) > { > #if HAVE_GETAUXVAL > - unsigned long ret = getauxval(AT_HWCAP); > + unsigned long ret = ff_getauxval(AT_HWCAP); > if (ret == 0) > return -1; > *hwcap = ret; > diff --git a/libavutil/cpu.c b/libavutil/cpu.c > index 41cee7fa77..61c1cf3faf 100644 > --- a/libavutil/cpu.c > +++ b/libavutil/cpu.c > @@ -49,6 +49,10 @@ > #include <unistd.h> > #endif > > +#if HAVE_GETAUXVAL > +#include <sys/auxv.h> > +#endif > + > static atomic_int cpu_flags = -1; > static atomic_int cpu_count = -1; > > @@ -283,3 +287,13 @@ size_t av_cpu_max_align(void) > > return 8; > } > + > +unsigned long ff_getauxval(unsigned long type) > +{ > +#if HAVE_GETAUXVAL > + return getauxval(type); > +#else > + errno = ENOSYS; > + return 0; > +#endif > +} > diff --git a/libavutil/cpu_internal.h b/libavutil/cpu_internal.h > index 634f28bac4..585a115c49 100644 > --- a/libavutil/cpu_internal.h > +++ b/libavutil/cpu_internal.h > @@ -59,4 +59,6 @@ size_t ff_get_cpu_max_align_ppc(void); > size_t ff_get_cpu_max_align_x86(void); > size_t ff_get_cpu_max_align_loongarch(void); > > +unsigned long ff_getauxval(unsigned long type); > + > #endif /* AVUTIL_CPU_INTERNAL_H */ > diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c > index cad8504fde..d8c67ad7c8 100644 > --- a/libavutil/loongarch/cpu.c > +++ b/libavutil/loongarch/cpu.c > @@ -28,7 +28,7 @@ > static int cpu_flags_getauxval(void) > { > int flags = 0; > - int flag = (int)getauxval(AT_HWCAP); > + int flag = (int)ff_getauxval(AT_HWCAP); > > if (flag & LA_HWCAP_LSX) > flags |= AV_CPU_FLAG_LSX; > diff --git a/libavutil/mips/cpu.c b/libavutil/mips/cpu.c > index 59619d54de..2009c70f71 100644 > --- a/libavutil/mips/cpu.c > +++ b/libavutil/mips/cpu.c > @@ -34,7 +34,7 @@ > > static int cpucfg_available(void) > { > - return getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG; > + return ff_getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG; > } > > /* Most toolchains have no CPUCFG support yet */ > diff --git a/libavutil/riscv/cpu.c b/libavutil/riscv/cpu.c > index 52ca2ce814..4ec6d6c826 100644 > --- a/libavutil/riscv/cpu.c > +++ b/libavutil/riscv/cpu.c > @@ -86,7 +86,7 @@ int ff_get_cpu_flags_riscv(void) > } > #elif HAVE_GETAUXVAL > { > - const unsigned long hwcap = getauxval(AT_HWCAP); > + const unsigned long hwcap = ff_getauxval(AT_HWCAP); > > if (hwcap & HWCAP_RV('I')) > ret |= AV_CPU_FLAG_RVI;
On Sat, 24 Aug 2024, Brad Smith wrote: > avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() > > Initially used for getauxval() but will be used to add support for > other API. > > Signed-off-by: Brad Smith <brad@comstyle.com> > --- > libavutil/aarch64/cpu.c | 4 ++-- > libavutil/arm/cpu.c | 2 +- > libavutil/cpu.c | 14 ++++++++++++++ > libavutil/cpu_internal.h | 2 ++ > libavutil/loongarch/cpu.c | 2 +- > libavutil/mips/cpu.c | 2 +- > libavutil/riscv/cpu.c | 2 +- > 7 files changed, 22 insertions(+), 6 deletions(-) LGTM, this looks reasonable to me. // Martin
On Sat, Aug 24, 2024 at 3:30 PM Brad Smith <brad-at-comstyle.com@ffmpeg.org> wrote: > avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() > > Initially used for getauxval() but will be used to add support for > other API. I'm curious, what other API do you have in mind? Is ff_getauxval() going to simulate getauxval() on other platforms? If that's the case, wouldn't it be better to create a function to get hardware capabilities instead (which may use getauxval or other API under the hood)?
On 2024-09-09 5:23 a.m., Ramiro Polla wrote: > On Sat, Aug 24, 2024 at 3:30 PM Brad Smith > <brad-at-comstyle.com@ffmpeg.org> wrote: >> avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() >> >> Initially used for getauxval() but will be used to add support for >> other API. > I'm curious, what other API do you have in mind? Is ff_getauxval() > going to simulate getauxval() on other platforms? If that's the case, > wouldn't it be better to create a function to get hardware > capabilities instead (which may use getauxval or other API under the > hood)? elf_aux_info() for FreeBSD / OpenBSD. It would probably make sense to move the /proc/self/auxv fallback path for Linux there too. No, it will not.
On Mon, Sep 9, 2024 at 11:34 AM Brad Smith <brad@comstyle.com> wrote: > On 2024-09-09 5:23 a.m., Ramiro Polla wrote: > > On Sat, Aug 24, 2024 at 3:30 PM Brad Smith > <brad-at-comstyle.com@ffmpeg.org> wrote: > > avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() > > Initially used for getauxval() but will be used to add support for > other API. > > I'm curious, what other API do you have in mind? Is ff_getauxval() > going to simulate getauxval() on other platforms? If that's the case, > wouldn't it be better to create a function to get hardware > capabilities instead (which may use getauxval or other API under the > hood)? > > elf_aux_info() for FreeBSD / OpenBSD. Perhaps add this to the commit message as well? Either way the patch looks good to me too. Thanks! > It would probably make sense > to move the /proc/self/auxv fallback path for Linux there too. Yes, that makes sense to me.
On 2024-09-09 5:55 a.m., Ramiro Polla wrote: > On Mon, Sep 9, 2024 at 11:34 AM Brad Smith <brad@comstyle.com> wrote: >> On 2024-09-09 5:23 a.m., Ramiro Polla wrote: >> >> On Sat, Aug 24, 2024 at 3:30 PM Brad Smith >> <brad-at-comstyle.com@ffmpeg.org> wrote: >> >> avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() >> >> Initially used for getauxval() but will be used to add support for >> other API. >> >> I'm curious, what other API do you have in mind? Is ff_getauxval() >> going to simulate getauxval() on other platforms? If that's the case, >> wouldn't it be better to create a function to get hardware >> capabilities instead (which may use getauxval or other API under the >> hood)? >> >> elf_aux_info() for FreeBSD / OpenBSD. > Perhaps add this to the commit message as well? Will do so. > > Either way the patch looks good to me too. Thanks! > >> It would probably make sense >> to move the /proc/self/auxv fallback path for Linux there too. > Yes, that makes sense to me. > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Le 9 septembre 2024 12:23:18 GMT+03:00, Ramiro Polla <ramiro.polla@gmail.com> a écrit : >On Sat, Aug 24, 2024 at 3:30 PM Brad Smith ><brad-at-comstyle.com@ffmpeg.org> wrote: >> avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() >> >> Initially used for getauxval() but will be used to add support for >> other API. > >I'm curious, what other API do you have in mind? FreeBSD's auxillary vector access helper is more generic than glibc's, allowing data of any size, rather than just longs. That's all.
diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c index cfa9306663..084c81e999 100644 --- a/libavutil/aarch64/cpu.c +++ b/libavutil/aarch64/cpu.c @@ -31,8 +31,8 @@ static int detect_flags(void) { int flags = 0; - unsigned long hwcap = getauxval(AT_HWCAP); - unsigned long hwcap2 = getauxval(AT_HWCAP2); + unsigned long hwcap = ff_getauxval(AT_HWCAP); + unsigned long hwcap2 = ff_getauxval(AT_HWCAP2); if (hwcap & HWCAP_AARCH64_ASIMDDP) flags |= AV_CPU_FLAG_DOTPROD; diff --git a/libavutil/arm/cpu.c b/libavutil/arm/cpu.c index c84a655c37..b84882005a 100644 --- a/libavutil/arm/cpu.c +++ b/libavutil/arm/cpu.c @@ -55,7 +55,7 @@ static int get_auxval(uint32_t *hwcap) { #if HAVE_GETAUXVAL - unsigned long ret = getauxval(AT_HWCAP); + unsigned long ret = ff_getauxval(AT_HWCAP); if (ret == 0) return -1; *hwcap = ret; diff --git a/libavutil/cpu.c b/libavutil/cpu.c index 41cee7fa77..61c1cf3faf 100644 --- a/libavutil/cpu.c +++ b/libavutil/cpu.c @@ -49,6 +49,10 @@ #include <unistd.h> #endif +#if HAVE_GETAUXVAL +#include <sys/auxv.h> +#endif + static atomic_int cpu_flags = -1; static atomic_int cpu_count = -1; @@ -283,3 +287,13 @@ size_t av_cpu_max_align(void) return 8; } + +unsigned long ff_getauxval(unsigned long type) +{ +#if HAVE_GETAUXVAL + return getauxval(type); +#else + errno = ENOSYS; + return 0; +#endif +} diff --git a/libavutil/cpu_internal.h b/libavutil/cpu_internal.h index 634f28bac4..585a115c49 100644 --- a/libavutil/cpu_internal.h +++ b/libavutil/cpu_internal.h @@ -59,4 +59,6 @@ size_t ff_get_cpu_max_align_ppc(void); size_t ff_get_cpu_max_align_x86(void); size_t ff_get_cpu_max_align_loongarch(void); +unsigned long ff_getauxval(unsigned long type); + #endif /* AVUTIL_CPU_INTERNAL_H */ diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c index cad8504fde..d8c67ad7c8 100644 --- a/libavutil/loongarch/cpu.c +++ b/libavutil/loongarch/cpu.c @@ -28,7 +28,7 @@ static int cpu_flags_getauxval(void) { int flags = 0; - int flag = (int)getauxval(AT_HWCAP); + int flag = (int)ff_getauxval(AT_HWCAP); if (flag & LA_HWCAP_LSX) flags |= AV_CPU_FLAG_LSX; diff --git a/libavutil/mips/cpu.c b/libavutil/mips/cpu.c index 59619d54de..2009c70f71 100644 --- a/libavutil/mips/cpu.c +++ b/libavutil/mips/cpu.c @@ -34,7 +34,7 @@ static int cpucfg_available(void) { - return getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG; + return ff_getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG; } /* Most toolchains have no CPUCFG support yet */ diff --git a/libavutil/riscv/cpu.c b/libavutil/riscv/cpu.c index 52ca2ce814..4ec6d6c826 100644 --- a/libavutil/riscv/cpu.c +++ b/libavutil/riscv/cpu.c @@ -86,7 +86,7 @@ int ff_get_cpu_flags_riscv(void) } #elif HAVE_GETAUXVAL { - const unsigned long hwcap = getauxval(AT_HWCAP); + const unsigned long hwcap = ff_getauxval(AT_HWCAP); if (hwcap & HWCAP_RV('I')) ret |= AV_CPU_FLAG_RVI;
avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul() Initially used for getauxval() but will be used to add support for other API. Signed-off-by: Brad Smith <brad@comstyle.com> --- libavutil/aarch64/cpu.c | 4 ++-- libavutil/arm/cpu.c | 2 +- libavutil/cpu.c | 14 ++++++++++++++ libavutil/cpu_internal.h | 2 ++ libavutil/loongarch/cpu.c | 2 +- libavutil/mips/cpu.c | 2 +- libavutil/riscv/cpu.c | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-)