[x264-devel] [Git][videolan/x264][master] Make use of sysconf(3) _SC_NPROCESSORS_ONLN and _SC_NPROCESSORS_CONF

Anton Mitrofanov (@BugMaster) gitlab at videolan.org
Sat Oct 26 09:00:32 UTC 2024



Anton Mitrofanov pushed to branch master at VideoLAN / x264


Commits:
da14df55 by Brad Smith at 2024-10-27T12:28:19-04:00
Make use of sysconf(3) _SC_NPROCESSORS_ONLN and _SC_NPROCESSORS_CONF

Make use of _SC_NPROCESSORS_ONLN if it exists and fallback to
_SC_NPROCESSORS_CONF for really old operating systems. This adds
support for retrieving the number of CPUs on a few OS's such as
NetBSD, DragonFly and a few others.

- - - - -


2 changed files:

- common/cpu.c
- configure


Changes:

=====================================
common/cpu.c
=====================================
@@ -30,20 +30,16 @@
 #if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
 #include <sys/auxv.h>
 #endif
-#if SYS_CYGWIN || SYS_SunOS || SYS_OPENBSD
+#if HAVE_SYSCONF
 #include <unistd.h>
 #endif
-#if SYS_LINUX
-#ifdef __ANDROID__
-#include <unistd.h>
-#else
+#if SYS_LINUX && !defined(__ANDROID__)
 #include <sched.h>
 #endif
-#endif
 #if SYS_BEOS
 #include <kernel/OS.h>
 #endif
-#if SYS_MACOSX || SYS_OPENBSD || SYS_FREEBSD
+#if SYS_MACOSX || SYS_FREEBSD || SYS_NETBSD || SYS_OPENBSD
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
@@ -342,7 +338,7 @@ uint32_t x264_cpu_detect( void )
     return flags;
 }
 
-#elif SYS_MACOSX || SYS_OPENBSD || SYS_FREEBSD || SYS_NETBSD
+#elif SYS_MACOSX || SYS_FREEBSD || SYS_NETBSD || SYS_OPENBSD
 
 uint32_t x264_cpu_detect( void )
 {
@@ -548,9 +544,6 @@ int x264_cpu_num_processors( void )
 #elif SYS_WINDOWS
     return x264_pthread_num_processors_np();
 
-#elif SYS_CYGWIN || SYS_SunOS || SYS_OPENBSD
-    return sysconf( _SC_NPROCESSORS_ONLN );
-
 #elif SYS_LINUX
 #ifdef __ANDROID__
     // Android NDK does not expose sched_getaffinity
@@ -575,7 +568,7 @@ int x264_cpu_num_processors( void )
     get_system_info( &info );
     return info.cpu_count;
 
-#elif SYS_MACOSX || SYS_FREEBSD
+#elif SYS_MACOSX
     int ncpu;
     size_t length = sizeof( ncpu );
     if( sysctlbyname("hw.ncpu", &ncpu, &length, NULL, 0) )
@@ -584,6 +577,12 @@ int x264_cpu_num_processors( void )
     }
     return ncpu;
 
+#elif defined(_SC_NPROCESSORS_ONLN)
+    return sysconf( _SC_NPROCESSORS_ONLN );
+
+#elif defined(_SC_NPROCESSORS_CONF)
+    return sysconf( _SC_NPROCESSORS_CONF );
+
 #else
     return 1;
 #endif


=====================================
configure
=====================================
@@ -411,7 +411,8 @@ NL="
 # list of all preprocessor HAVE values we can define
 CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON AARCH64 BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
              LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
-             MSA LSX MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10 SVE SVE2 ELF_AUX_INFO GETAUXVAL"
+             MSA LSX MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10 SVE SVE2 ELF_AUX_INFO GETAUXVAL \
+             SYSCONF"
 
 # parse options
 
@@ -1158,6 +1159,10 @@ if cc_check 'sys/auxv.h' '' 'unsigned long auxv = 0; elf_aux_info(AT_HWCAP, &aux
     define HAVE_ELF_AUX_INFO
 fi
 
+if cc_check 'unistd.h' '' 'sysconf(0);' ; then
+    define HAVE_SYSCONF
+fi
+
 if [ "$SYS" != "WINDOWS" ] && cpp_check "sys/mman.h unistd.h" "" "defined(MAP_PRIVATE)"; then
     define HAVE_MMAP
 fi



View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/da14df5535fd46776fb1c9da3130973295c87aca

-- 
View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/da14df5535fd46776fb1c9da3130973295c87aca
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the x264-devel mailing list