]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Use rseq to accelerate sched_getcpu
authorFlorian Weimer <fweimer@redhat.com>
Thu, 9 Dec 2021 08:49:32 +0000 (09:49 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 9 Dec 2021 08:49:32 +0000 (09:49 +0100)
Co-Authored-By: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
sysdeps/unix/sysv/linux/sched_getcpu.c

index c41e986f2cab5e42127f4632218bd6a6a56cc857..6f78edaea14953424f3be3efca0b8daa17d1b030 100644 (file)
@@ -20,8 +20,8 @@
 #include <sysdep.h>
 #include <sysdep-vdso.h>
 
-int
-sched_getcpu (void)
+static int
+vsyscall_sched_getcpu (void)
 {
   unsigned int cpu;
   int r = -1;
@@ -32,3 +32,18 @@ sched_getcpu (void)
 #endif
   return r == -1 ? r : cpu;
 }
+
+#ifdef RSEQ_SIG
+int
+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)
+{
+  return vsyscall_sched_getcpu ();
+}
+#endif /* RSEQ_SIG */