Message ID | 20200501021439.2456-3-mathieu.desnoyers@efficios.com |
---|---|
State | New |
Headers | show |
Series | Restartable Sequences enablement | expand |
* Mathieu Desnoyers via Libc-alpha: > diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c > index c019cfb3cf..2269c4f2bd 100644 > --- a/sysdeps/unix/sysv/linux/sched_getcpu.c > +++ b/sysdeps/unix/sysv/linux/sched_getcpu.c > @@ -18,10 +18,15 @@ > #include <errno.h> > #include <sched.h> > #include <sysdep.h> > +#include <atomic.h> > #include <sysdep-vdso.h> > > -int > -sched_getcpu (void) > +#ifdef HAVE_GETCPU_VSYSCALL > +# define HAVE_VSYSCALL > +#endif I think the #ifdef is a result of an incorrect merge of commit d0def09ff6bbf1537beec305fdfe96a21174fb31 ("linux: Fix vDSO macros build with time64 interfaces") and it should be removed. The commit subject should probably say “Linux: Use rseq in sched_getcpu if available”. Thanks, Florian
diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c index c019cfb3cf..2269c4f2bd 100644 --- a/sysdeps/unix/sysv/linux/sched_getcpu.c +++ b/sysdeps/unix/sysv/linux/sched_getcpu.c @@ -18,10 +18,15 @@ #include <errno.h> #include <sched.h> #include <sysdep.h> +#include <atomic.h> #include <sysdep-vdso.h> -int -sched_getcpu (void) +#ifdef HAVE_GETCPU_VSYSCALL +# define HAVE_VSYSCALL +#endif + +static int +vsyscall_sched_getcpu (void) { unsigned int cpu; int r = -1; @@ -32,3 +37,21 @@ sched_getcpu (void) #endif return r == -1 ? r : cpu; } + +#include <sys/rseq.h> + +#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 +int +sched_getcpu (void) +{ + return vsyscall_sched_getcpu (); +} +#endif