94084c
commit 1d350aa06091211863e41169729cee1bca39f72f
94084c
Author: Florian Weimer <fweimer@redhat.com>
94084c
Date:   Thu Dec 9 09:49:32 2021 +0100
94084c
94084c
    Linux: Use rseq to accelerate sched_getcpu
94084c
    
94084c
    Co-Authored-By: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
94084c
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
94084c
94084c
diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c
94084c
index c41e986f2cab5e42..6f78edaea1495342 100644
94084c
--- a/sysdeps/unix/sysv/linux/sched_getcpu.c
94084c
+++ b/sysdeps/unix/sysv/linux/sched_getcpu.c
94084c
@@ -20,8 +20,8 @@
94084c
 #include <sysdep.h>
94084c
 #include <sysdep-vdso.h>
94084c
 
94084c
-int
94084c
-sched_getcpu (void)
94084c
+static int
94084c
+vsyscall_sched_getcpu (void)
94084c
 {
94084c
   unsigned int cpu;
94084c
   int r = -1;
94084c
@@ -32,3 +32,18 @@ sched_getcpu (void)
94084c
 #endif
94084c
   return r == -1 ? r : cpu;
94084c
 }
94084c
+
94084c
+#ifdef RSEQ_SIG
94084c
+int
94084c
+sched_getcpu (void)
94084c
+{
94084c
+  int cpu_id = THREAD_GETMEM_VOLATILE (THREAD_SELF, rseq_area.cpu_id);
94084c
+  return __glibc_likely (cpu_id >= 0) ? cpu_id : vsyscall_sched_getcpu ();
94084c
+}
94084c
+#else /* RSEQ_SIG */
94084c
+int
94084c
+sched_getcpu (void)
94084c
+{
94084c
+  return vsyscall_sched_getcpu ();
94084c
+}
94084c
+#endif /* RSEQ_SIG */