`sched_getcpu()` has been supported since glibc 2.6 (2007), and is faster since it can use a vsyscall. Plus, FreeBSD implements it as well.
From: Brendan Shanks bshanks@codeweavers.com
--- configure.ac | 1 + dlls/ntdll/unix/thread.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac index ac710721ae6..fa57b75a0fd 100644 --- a/configure.ac +++ b/configure.ac @@ -2079,6 +2079,7 @@ AC_CHECK_FUNCS(\ posix_fadvise \ posix_fallocate \ prctl \ + sched_getcpu \ sched_yield \ setproctitle \ setprogname \ diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index a7114825118..1f7a46b832d 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -37,6 +37,9 @@ #include <sys/types.h> #include <unistd.h> #include <sys/mman.h> +#ifdef HAVE_SCHED_H +#include <sched.h> +#endif #ifdef HAVE_SYS_TIMES_H #include <sys/times.h> #endif @@ -2560,9 +2563,9 @@ ULONG WINAPI NtGetCurrentProcessorNumber(void) { ULONG processor;
-#if defined(__linux__) && defined(__NR_getcpu) - int res = syscall(__NR_getcpu, &processor, NULL, NULL); - if (res != -1) return processor; +#if defined(HAVE_SCHED_GETCPU) + int res = sched_getcpu(); + if (res >= 0) return res; #endif
if (peb->NumberOfProcessors > 1)