@@ -35,15 +35,18 @@ vsyscall_sched_getcpu (void)
#ifdef RSEQ_SIG
int
-sched_getcpu (void)
+__sched_getcpu (void)
{
int cpu_id = THREAD_GETMEM_VOLATILE (THREAD_SELF, rseq_area.cpu_id);
return __glibc_likely (cpu_id >= 0) ? cpu_id : vsyscall_sched_getcpu ();
}
#else /* RSEQ_SIG */
int
-sched_getcpu (void)
+__sched_getcpu (void)
{
return vsyscall_sched_getcpu ();
}
#endif /* RSEQ_SIG */
+#ifndef USE_IFUNC_SCHED_GETCPU
+weak_alias (__sched_getcpu, sched_getcpu)
+#endif /* !USE_IFUNC_SCHED_GETCPU */
new file mode 100644
@@ -0,0 +1,48 @@
+/* sched_getcpu -- Get current processor. Linux/x86 version.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+
+
+#if defined __x86_64__ && defined USE_MULTIARCH && IS_IN (libc)
+# define USE_IFUNC_SCHED_GETCPU
+
+# include <init-arch.h>
+int __sched_getcpu (void);
+
+int
+__sched_getcpu_rdpid (void)
+{
+# if __has_builtin (__builtin_ia32_rdpid)
+ return __builtin_ia32_rdpid();
+# else
+ unsigned long cpu;
+ asm volatile("rdpid %[cpu]" : [cpu] "=r" (cpu) : :);
+ return cpu;
+# endif
+}
+
+# undef INIT_ARCH
+# define INIT_ARCH() \
+ const struct cpu_features *cpu_features = __get_cpu_features ();
+
+libc_ifunc (sched_getcpu, CPU_FEATURE_USABLE_P (cpu_features, RDPID)
+ ? (void *) __sched_getcpu_rdpid
+ : (void *) __sched_getcpu)
+
+#endif
+#include <sysdeps/unix/sysv/linux/sched_getcpu.c>