diff mbox series

[v2,5/8] Linux: Use rseq to accelerate sched_getcpu

Message ID 450326fdf3964e5539aa2da1b9836d51491f8fdb.1638880889.git.fweimer@redhat.com
State Committed
Commit 1d350aa06091211863e41169729cee1bca39f72f
Headers show
Series Extensible rseq integration | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Florian Weimer Dec. 7, 2021, 1:02 p.m. UTC
Co-Authored-By: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
v2: Use volatile access.

 sysdeps/unix/sysv/linux/sched_getcpu.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Szabolcs Nagy Dec. 8, 2021, 4:53 p.m. UTC | #1
The 12/07/2021 14:02, Florian Weimer via Libc-alpha wrote:
> Co-Authored-By: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> ---
> v2: Use volatile access.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c
index c41e986f2c..6f78edaea1 100644
--- a/sysdeps/unix/sysv/linux/sched_getcpu.c
+++ b/sysdeps/unix/sysv/linux/sched_getcpu.c
@@ -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 */