public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/vineet/arc-port-latest] Linux: Use rseq in sched_getcpu if available
@ 2020-07-09 16:33 Vineet Gupta
  0 siblings, 0 replies; only message in thread
From: Vineet Gupta @ 2020-07-09 16:33 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6e29cb3f61ff5432c78a1c84b0d9b123a350ab36

commit 6e29cb3f61ff5432c78a1c84b0d9b123a350ab36
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Date:   Mon Jul 6 10:21:31 2020 +0200

    Linux: Use rseq in sched_getcpu if available
    
    When available, use the cpu_id field from __rseq_abi on Linux to
    implement sched_getcpu().  Fall-back on the vgetcpu vDSO if unavailable.
    
    Benchmarks:
    
    x86-64: Intel E5-2630 v3@2.40GHz, 16-core, hyperthreading
    
    glibc sched_getcpu():                     13.7 ns (baseline)
    glibc sched_getcpu() using rseq:           2.5 ns (speedup:  5.5x)
    inline load cpuid from __rseq_abi TLS:     0.8 ns (speedup: 17.1x)

Diff:
---
 sysdeps/unix/sysv/linux/sched_getcpu.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c
index c019cfb3cf..c0f992e056 100644
--- a/sysdeps/unix/sysv/linux/sched_getcpu.c
+++ b/sysdeps/unix/sysv/linux/sched_getcpu.c
@@ -18,10 +18,12 @@
 #include <errno.h>
 #include <sched.h>
 #include <sysdep.h>
+#include <atomic.h>
 #include <sysdep-vdso.h>
+#include <sys/rseq.h>
 
-int
-sched_getcpu (void)
+static int
+vsyscall_sched_getcpu (void)
 {
   unsigned int cpu;
   int r = -1;
@@ -32,3 +34,19 @@ sched_getcpu (void)
 #endif
   return r == -1 ? r : cpu;
 }
+
+#ifdef RSEQ_SIG
+int
+sched_getcpu (void)
+{
+  int cpu_id = atomic_load_relaxed (&__rseq_abi.cpu_id);
+
+  return cpu_id >= 0 ? cpu_id : vsyscall_sched_getcpu ();
+}
+#else /* RSEQ_SIG */
+int
+sched_getcpu (void)
+{
+  return vsyscall_sched_getcpu ();
+}
+#endif /* RSEQ_SIG */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-09 16:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 16:33 [glibc/vineet/arc-port-latest] Linux: Use rseq in sched_getcpu if available Vineet Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).