public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* RFC: Add getcpu wrapper
@ 2018-12-05 14:30 H.J. Lu
  2018-12-05 15:35 ` Florian Weimer
  2018-12-05 17:33 ` Carlos O'Donell
  0 siblings, 2 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 14:30 UTC (permalink / raw)
  To: GNU C Library

To optimize for multi-node NUMA system, I need a very fast way to identity which
node the current process is running on.  getcpu:

NAME
       getcpu  -  determine  CPU  and NUMA node on which the calling thread is
       running

SYNOPSIS
       #include <linux/getcpu.h>

       int getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);

       Note: There is no glibc wrapper for this system call; see NOTES.

DESCRIPTION
       The getcpu() system call identifies the processor and node on which the
       calling thread or process is currently running and writes them into the
       integers pointed to by the cpu and node arguments.  The processor is  a
       unique  small  integer  identifying  a CPU.  The node is a unique small
       identifier identifying a NUMA node.  When either cpu or  node  is  NULL
       nothing is written to the respective pointer.

returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
glibc.   Any comments?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: RFC: Add getcpu wrapper
  2018-12-05 14:30 RFC: Add getcpu wrapper H.J. Lu
@ 2018-12-05 15:35 ` Florian Weimer
  2018-12-05 15:40   ` H.J. Lu
  2018-12-05 17:33 ` Carlos O'Donell
  1 sibling, 1 reply; 32+ messages in thread
From: Florian Weimer @ 2018-12-05 15:35 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

* H. J. Lu:

> returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
> glibc.   Any comments?

We already have it as sched_getcpu, I think.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: RFC: Add getcpu wrapper
  2018-12-05 15:35 ` Florian Weimer
@ 2018-12-05 15:40   ` H.J. Lu
  2018-12-05 15:49     ` Florian Weimer
  0 siblings, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 15:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Wed, Dec 5, 2018 at 7:35 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
> > glibc.   Any comments?
>
> We already have it as sched_getcpu, I think.
>

We have

int
sched_getcpu (void)
{
#ifdef __NR_getcpu
  unsigned int cpu;
  int r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL);

  ^^^^^  I need the node info.

  return r == -1 ? r : cpu;
#else
  __set_errno (ENOSYS);
  return -1;
#endif
}



-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: RFC: Add getcpu wrapper
  2018-12-05 15:40   ` H.J. Lu
@ 2018-12-05 15:49     ` Florian Weimer
  2018-12-05 16:01       ` Zack Weinberg
  0 siblings, 1 reply; 32+ messages in thread
From: Florian Weimer @ 2018-12-05 15:49 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

* H. J. Lu:

> On Wed, Dec 5, 2018 at 7:35 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu:
>>
>> > returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
>> > glibc.   Any comments?
>>
>> We already have it as sched_getcpu, I think.
>>
>
> We have
>
> int
> sched_getcpu (void)
> {
> #ifdef __NR_getcpu
>   unsigned int cpu;
>   int r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL);
>
>   ^^^^^  I need the node info.
>
>   return r == -1 ? r : cpu;
> #else
>   __set_errno (ENOSYS);
>   return -1;
> #endif
> }

Ah, so you want to pass a non-null second argument to getcpu?

I think we can expose getcpu (with two arguments), under that name.  Add
it to <sched.h> or <unistd.h>; I do not have a strong preference.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: RFC: Add getcpu wrapper
  2018-12-05 15:49     ` Florian Weimer
@ 2018-12-05 16:01       ` Zack Weinberg
  2018-12-05 16:05         ` H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: Zack Weinberg @ 2018-12-05 16:01 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu, GNU C Library

On Wed, Dec 5, 2018 at 10:49 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> Ah, so you want to pass a non-null second argument to getcpu?
>
> I think we can expose getcpu (with two arguments), under that name.  Add
> it to <sched.h> or <unistd.h>; I do not have a strong preference.

What's the third argument for?  Is there a concrete reason not to
expose it as well?

zw

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: RFC: Add getcpu wrapper
  2018-12-05 16:01       ` Zack Weinberg
@ 2018-12-05 16:05         ` H.J. Lu
  0 siblings, 0 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 16:05 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Florian Weimer, GNU C Library

On Wed, Dec 5, 2018 at 8:00 AM Zack Weinberg <zackw@panix.com> wrote:
>
> On Wed, Dec 5, 2018 at 10:49 AM Florian Weimer <fweimer@redhat.com> wrote:
> >
> > Ah, so you want to pass a non-null second argument to getcpu?
> >
> > I think we can expose getcpu (with two arguments), under that name.  Add
> > it to <sched.h> or <unistd.h>; I do not have a strong preference.
>
> What's the third argument for?  Is there a concrete reason not to
> expose it as well?
>
> zw

       The  third  argument to this system call is nowadays unused, and should
       be specified as NULL unless portability to Linux 2.6.23 or  earlier  is
       required (see NOTES).


-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: RFC: Add getcpu wrapper
  2018-12-05 14:30 RFC: Add getcpu wrapper H.J. Lu
  2018-12-05 15:35 ` Florian Weimer
@ 2018-12-05 17:33 ` Carlos O'Donell
  2018-12-05 17:42   ` [PATCH] Add getcpu H.J. Lu
  1 sibling, 1 reply; 32+ messages in thread
From: Carlos O'Donell @ 2018-12-05 17:33 UTC (permalink / raw)
  To: H.J. Lu, GNU C Library

On 12/5/18 9:29 AM, H.J. Lu wrote:
> To optimize for multi-node NUMA system, I need a very fast way to identity which
> node the current process is running on.  getcpu:
> 
> NAME
>        getcpu  -  determine  CPU  and NUMA node on which the calling thread is
>        running
> 
> SYNOPSIS
>        #include <linux/getcpu.h>
> 
>        int getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
> 
>        Note: There is no glibc wrapper for this system call; see NOTES.
> 
> DESCRIPTION
>        The getcpu() system call identifies the processor and node on which the
>        calling thread or process is currently running and writes them into the
>        integers pointed to by the cpu and node arguments.  The processor is  a
>        unique  small  integer  identifying  a CPU.  The node is a unique small
>        identifier identifying a NUMA node.  When either cpu or  node  is  NULL
>        nothing is written to the respective pointer.
> 
> returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
> glibc.   Any comments?

I don't object to adding syscall wrappers, but your comment appears to indicate
that the glibc wrapper will be doing something more than just wrapping, what
do you have in mind?

On some architectures we might have vdso support for this, while on others it
will be a syscall. What's  wrong with just using the fastest mechanism possible
and that's it?

I see that on x86 you have a vdso vgetcpu, and that lsl is one instruction and
loads the cpunode mask and ccpunode bits in one shot (atomic). So this should
work fine, but for all other callers I assume this will be a syscall.

-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH] Add getcpu
  2018-12-05 17:33 ` Carlos O'Donell
@ 2018-12-05 17:42   ` H.J. Lu
  2018-12-05 18:14     ` H.J. Lu
                       ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 17:42 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: GNU C Library

[-- Attachment #1: Type: text/plain, Size: 2048 bytes --]

On Wed, Dec 5, 2018 at 9:33 AM Carlos O'Donell <carlos@redhat.com> wrote:
>
> On 12/5/18 9:29 AM, H.J. Lu wrote:
> > To optimize for multi-node NUMA system, I need a very fast way to identity which
> > node the current process is running on.  getcpu:
> >
> > NAME
> >        getcpu  -  determine  CPU  and NUMA node on which the calling thread is
> >        running
> >
> > SYNOPSIS
> >        #include <linux/getcpu.h>
> >
> >        int getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
> >
> >        Note: There is no glibc wrapper for this system call; see NOTES.
> >
> > DESCRIPTION
> >        The getcpu() system call identifies the processor and node on which the
> >        calling thread or process is currently running and writes them into the
> >        integers pointed to by the cpu and node arguments.  The processor is  a
> >        unique  small  integer  identifying  a CPU.  The node is a unique small
> >        identifier identifying a NUMA node.  When either cpu or  node  is  NULL
> >        nothing is written to the respective pointer.
> >
> > returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
> > glibc.   Any comments?
>
> I don't object to adding syscall wrappers, but your comment appears to indicate
> that the glibc wrapper will be doing something more than just wrapping, what
> do you have in mind?

I am enclosing a patch to add getcpu.  Testing on x86-64, x32 and i686
are done.  I am running build-many-glibcs.py as we speak.

> On some architectures we might have vdso support for this, while on others it
> will be a syscall. What's  wrong with just using the fastest mechanism possible
> and that's it?
>
> I see that on x86 you have a vdso vgetcpu, and that lsl is one instruction and
> loads the cpunode mask and ccpunode bits in one shot (atomic). So this should
> work fine, but for all other callers I assume this will be a syscall.

I need vdso getcpu to avoid syscall.  I am working on a NUMA spinlock
library which depends on a very fast getcpu.

--
H.J.

[-- Attachment #2: 0001-Add-getcpu.patch --]
[-- Type: application/x-patch, Size: 29920 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 17:42   ` [PATCH] Add getcpu H.J. Lu
@ 2018-12-05 18:14     ` H.J. Lu
  2018-12-05 18:48     ` Florian Weimer
  2018-12-10 12:22     ` [PATCH] Add getcpu Szabolcs Nagy
  2 siblings, 0 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 18:14 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: GNU C Library

On Wed, Dec 5, 2018 at 9:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Wed, Dec 5, 2018 at 9:33 AM Carlos O'Donell <carlos@redhat.com> wrote:
> >
> > On 12/5/18 9:29 AM, H.J. Lu wrote:
> > > To optimize for multi-node NUMA system, I need a very fast way to identity which
> > > node the current process is running on.  getcpu:
> > >
> > > NAME
> > >        getcpu  -  determine  CPU  and NUMA node on which the calling thread is
> > >        running
> > >
> > > SYNOPSIS
> > >        #include <linux/getcpu.h>
> > >
> > >        int getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
> > >
> > >        Note: There is no glibc wrapper for this system call; see NOTES.
> > >
> > > DESCRIPTION
> > >        The getcpu() system call identifies the processor and node on which the
> > >        calling thread or process is currently running and writes them into the
> > >        integers pointed to by the cpu and node arguments.  The processor is  a
> > >        unique  small  integer  identifying  a CPU.  The node is a unique small
> > >        identifier identifying a NUMA node.  When either cpu or  node  is  NULL
> > >        nothing is written to the respective pointer.
> > >
> > > returns such info.  But syscall () is too slow.  I'd like to add a wrapper to
> > > glibc.   Any comments?
> >
> > I don't object to adding syscall wrappers, but your comment appears to indicate
> > that the glibc wrapper will be doing something more than just wrapping, what
> > do you have in mind?
>
> I am enclosing a patch to add getcpu.  Testing on x86-64, x32 and i686
> are done.  I am running build-many-glibcs.py as we speak.

build-many-glibcs.py passed.  OK for trunk?

https://sourceware.org/ml/libc-alpha/2018-12/msg00161.html

-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 17:42   ` [PATCH] Add getcpu H.J. Lu
  2018-12-05 18:14     ` H.J. Lu
@ 2018-12-05 18:48     ` Florian Weimer
  2018-12-05 19:51       ` H.J. Lu
  2018-12-05 20:43       ` Joseph Myers
  2018-12-10 12:22     ` [PATCH] Add getcpu Szabolcs Nagy
  2 siblings, 2 replies; 32+ messages in thread
From: Florian Weimer @ 2018-12-05 18:48 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Carlos O'Donell, GNU C Library

* H. J. Lu:

> +extern int __getcpu (unsigned *, unsigned *) __THROW;

“unsigned int”; perhaps  use __typeof__ (getcpu)?

> diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
> index 34f27a7d9b..ea5d51a80d 100644
> --- a/sysdeps/unix/sysv/linux/bits/sched.h
> +++ b/sysdeps/unix/sysv/linux/bits/sched.h
> @@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
>  /* Get index of currently used CPU.  */
>  extern int sched_getcpu (void) __THROW;
>  
> +/* Get currently used CPU and NUMA node.  */
> +extern int getcpu (unsigned int *, unsigned int *) __THROW;

Can either pointer be NULL?

> +__getcpu (unsigned *cpu, unsigned *node)

“unsigned int”.

> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-affinity-getcpu.c
> @@ -0,0 +1,292 @@
> +/* Test case for CPU affinity functions with getcpu.
> +   Copyright (C) 2018 Free Software Foundation, Inc.

I think this is a copy of another test, right?

Maybe we should move bits of it to support/?

We have a parallel discussion about a new requirement that all new
functions must have documentation in the manual.  I don't know what will
come out of that.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 18:48     ` Florian Weimer
@ 2018-12-05 19:51       ` H.J. Lu
  2018-12-05 19:57         ` Florian Weimer
  2018-12-05 20:43       ` Joseph Myers
  1 sibling, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 19:51 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Carlos O'Donell, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 1478 bytes --]

On Wed, Dec 5, 2018 at 10:48 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > +extern int __getcpu (unsigned *, unsigned *) __THROW;
>
> “unsigned int”; perhaps  use __typeof__ (getcpu)?

Fixed.

> > diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
> > index 34f27a7d9b..ea5d51a80d 100644
> > --- a/sysdeps/unix/sysv/linux/bits/sched.h
> > +++ b/sysdeps/unix/sysv/linux/bits/sched.h
> > @@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
> >  /* Get index of currently used CPU.  */
> >  extern int sched_getcpu (void) __THROW;
> >
> > +/* Get currently used CPU and NUMA node.  */
> > +extern int getcpu (unsigned int *, unsigned int *) __THROW;
>
> Can either pointer be NULL?

Yes.  Either pointer can be NULL.

> > +__getcpu (unsigned *cpu, unsigned *node)
>
> “unsigned int”.

Fixed.

> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/tst-affinity-getcpu.c
> > @@ -0,0 +1,292 @@
> > +/* Test case for CPU affinity functions with getcpu.
> > +   Copyright (C) 2018 Free Software Foundation, Inc.
>
> I think this is a copy of another test, right?
>
> Maybe we should move bits of it to support/?

I updated the patch with a very simple test.

> We have a parallel discussion about a new requirement that all new
> functions must have documentation in the manual.  I don't know what will
> come out of that.

Here is the updated patch.

-- 
H.J.

[-- Attachment #2: 0001-Add-getcpu.patch --]
[-- Type: text/x-patch, Size: 23430 bytes --]

From 633a466738a11d780688735f491a8dba2b00753b Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 5 Dec 2018 08:36:46 -0800
Subject: [PATCH] Add getcpu

Add

  #include <sched.h>

  int getcpu (unsigned int *cpu, unsigned int *node);

to return currently used CPU and NUMA node.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.

	* NEWS: Mention getcpu.
	* include/sched.h (__getcpu): New libc_hidden_proto.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add
	getcpu.
	(tests): Add tst-affinity-getcpu.
	(tests-static): Add tst-affinity-getcpu-static.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/bits/sched.h (getcpu): New prototype.
	* sysdeps/unix/sysv/linux/getcpu.c: New file.
	* sysdeps/unix/sysv/linux/tst-getcpu-static.c: Likewise.
	* sysdeps/unix/sysv/linux/tst-getcpu.c: Likewise.
---
 NEWS                                          |  3 ++
 include/sched.h                               |  2 +
 sysdeps/unix/sysv/linux/Makefile              |  6 +--
 sysdeps/unix/sysv/linux/Versions              |  3 ++
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
 sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
 sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
 sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
 .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
 .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +
 .../sysv/linux/powerpc/powerpc64/libc.abilist |  1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |  1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |  1 +
 sysdeps/unix/sysv/linux/sh/libc.abilist       |  1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/tst-getcpu-static.c   |  1 +
 sysdeps/unix/sysv/linux/tst-getcpu.c          | 47 +++++++++++++++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |  1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |  1 +
 34 files changed, 126 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/getcpu.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-getcpu-static.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-getcpu.c

diff --git a/NEWS b/NEWS
index 8483dcf492..666416a268 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Version 2.29
 
 Major new features:
 
+* The getcpu wrapper function has been added, which returns currently
+  used CPU and NUMA node.
+
 * A new convenience target has been added for distribution maintainers
   to build and install all locales as directories with files.  The new
   target is run by issuing the following command in your build tree:
diff --git a/include/sched.h b/include/sched.h
index b698f78666..0843c26d73 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -26,5 +26,7 @@ libc_hidden_proto (__clone)
 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		     size_t __child_stack_size, int __flags, void *__arg, ...);
 libc_hidden_proto (__clone2)
+extern __typeof__ (getcpu) __getcpu;
+libc_hidden_proto (__getcpu)
 #endif
 #endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 362cf3b950..73b13b4eaf 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -142,11 +142,11 @@ endif
 ifeq ($(subdir),posix)
 sysdep_headers += bits/initspin.h
 
-sysdep_routines += sched_getcpu oldglob
+sysdep_routines += sched_getcpu oldglob getcpu
 
-tests += tst-affinity tst-affinity-pid
+tests += tst-affinity tst-affinity-pid tst-getcpu
 
-tests-static := tst-affinity-static
+tests-static := tst-affinity-static tst-getcpu-static
 tests += $(tests-static)
 
 CFLAGS-fork.c = $(libio-mtsafe)
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 336c13b57d..f1e12d9c69 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -171,6 +171,9 @@ libc {
     mlock2;
     pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
   }
+  GLIBC_2.29 {
+    getcpu;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index e66c741d04..c2ca32e9d2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2138,4 +2138,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 8df162fe99..a86ce442e7 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2033,6 +2033,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 43c804f9dc..b10c07a51d 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index 34f27a7d9b..ea5d51a80d 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
 /* Get index of currently used CPU.  */
 extern int sched_getcpu (void) __THROW;
 
+/* Get currently used CPU and NUMA node.  */
+extern int getcpu (unsigned int *, unsigned int *) __THROW;
+
 /* Switch process to namespace of type NSTYPE indicated by FD.  */
 extern int setns (int __fd, int __nstype) __THROW;
 #endif
diff --git a/sysdeps/unix/sysv/linux/getcpu.c b/sysdeps/unix/sysv/linux/getcpu.c
new file mode 100644
index 0000000000..59c6cc4a14
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getcpu.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2007-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <sysdep.h>
+
+#ifdef HAVE_GETCPU_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
+
+int
+__getcpu (unsigned int *cpu, unsigned int *node)
+{
+#ifdef __NR_getcpu
+  return INLINE_VSYSCALL (getcpu, 3, cpu, node, NULL);
+#else
+  __set_errno (ENOSYS);
+  return -1;
+#endif
+}
+weak_alias (__getcpu, getcpu)
+libc_hidden_def (__getcpu)
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 88b01c2e75..3527d39971 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1880,6 +1880,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 6d02f31612..979aaae1db 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2045,6 +2045,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index 4249712611..a4a90236f8 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1914,6 +1914,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index d47b808862..9f86f26730 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index d5e38308be..558ba5fd4d 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1989,6 +1989,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index 8596b84399..ca773e3d07 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2130,4 +2130,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 88e0f896d5..89c5c296d2 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1967,6 +1967,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index aff7462c34..429624bc95 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1965,6 +1965,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 71d82444aa..fbe714e0bc 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1973,6 +1973,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index de6c53d293..baa657f65b 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index e724bab9fb..a2f407b92e 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2171,4 +2171,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index e9ecbccb71..1fd4fca8c8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1993,6 +1993,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index da83ea6028..cd3dcc0924 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
index 4535b40d15..54ddbb3f80 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
@@ -2228,4 +2228,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
index 65725de4f0..5b9e494071 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 _Exit F
 GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index bbb3c4a8e7..36f5de94d5 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2100,4 +2100,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index e85ac2a178..b74e995d37 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2002,6 +2002,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index d56931022c..964ada9d33 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1908,6 +1908,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index ff939a15c4..7c689af861 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1884,6 +1884,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 64fa9e10a5..e3cc7c1a2e 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1996,6 +1996,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index db909d1506..a7dae1e16d 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1937,6 +1937,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/tst-getcpu-static.c b/sysdeps/unix/sysv/linux/tst-getcpu-static.c
new file mode 100644
index 0000000000..e205d856b5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-getcpu-static.c
@@ -0,0 +1 @@
+#include "tst-getcpu.c"
diff --git a/sysdeps/unix/sysv/linux/tst-getcpu.c b/sysdeps/unix/sysv/linux/tst-getcpu.c
new file mode 100644
index 0000000000..e628ee02fa
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-getcpu.c
@@ -0,0 +1,47 @@
+/* Test case for getcpu.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <sched.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+  int active_cpu = sched_getcpu ();
+  if (active_cpu < 0)
+    {
+      printf ("error: getcpu: %m\n");
+      return EXIT_FAILURE;
+    }
+  unsigned int numa_cpu, numa_node;
+  if (getcpu (&numa_cpu, &numa_node))
+    {
+      printf ("error: getcpu: %m\n");
+      return EXIT_FAILURE;
+    }
+  if ((unsigned int) active_cpu != numa_cpu)
+    {
+      printf ("error: Unexpected CPU %d, expected %d\n",
+	      active_cpu, numa_cpu);
+      return EXIT_FAILURE;;
+    }
+  return EXIT_SUCCESS;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 3b175f104b..87b6b6d639 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1895,6 +1895,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 1b57710477..39a0009398 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2146,4 +2146,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
-- 
2.19.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 19:51       ` H.J. Lu
@ 2018-12-05 19:57         ` Florian Weimer
  2018-12-05 20:07           ` H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: Florian Weimer @ 2018-12-05 19:57 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Carlos O'Donell, GNU C Library

* H. J. Lu:

> I updated the patch with a very simple test.

The simple test has a race condition unfortunately.

I think we could fold the test into the existing affinity tests.

The main question is whether getcpu is fast enough.  It does not perform
a system call, but in my tests a while back, it was still rather slow.

The new rseq-based getcpu does not support NUMA nodes, it seems.  Maybe
it's still possible to fix that.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 19:57         ` Florian Weimer
@ 2018-12-05 20:07           ` H.J. Lu
  2018-12-05 20:14             ` H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 20:07 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Carlos O'Donell, GNU C Library

On Wed, Dec 5, 2018 at 11:57 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > I updated the patch with a very simple test.
>
> The simple test has a race condition unfortunately.
>
> I think we could fold the test into the existing affinity tests.

Sure, I will do that.

> The main question is whether getcpu is fast enough.  It does not perform
> a system call, but in my tests a while back, it was still rather slow.

It is fast enough for NUMA spinlock.

> The new rseq-based getcpu does not support NUMA nodes, it seems.  Maybe
> it's still possible to fix that.

That will be great.  We can take advantage it when it is available.

-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 20:07           ` H.J. Lu
@ 2018-12-05 20:14             ` H.J. Lu
  2018-12-07 12:51               ` Tulio Magno Quites Machado Filho
  0 siblings, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 20:14 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Carlos O'Donell, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 801 bytes --]

On Wed, Dec 5, 2018 at 12:07 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Wed, Dec 5, 2018 at 11:57 AM Florian Weimer <fweimer@redhat.com> wrote:
> >
> > * H. J. Lu:
> >
> > > I updated the patch with a very simple test.
> >
> > The simple test has a race condition unfortunately.
> >
> > I think we could fold the test into the existing affinity tests.
>
> Sure, I will do that.

Like this.

> > The main question is whether getcpu is fast enough.  It does not perform
> > a system call, but in my tests a while back, it was still rather slow.
>
> It is fast enough for NUMA spinlock.
>
> > The new rseq-based getcpu does not support NUMA nodes, it seems.  Maybe
> > it's still possible to fix that.
>
> That will be great.  We can take advantage it when it is available.
>
> --
> H.J.



-- 
H.J.

[-- Attachment #2: 0001-Add-getcpu.patch --]
[-- Type: text/x-patch, Size: 21852 bytes --]

From 4288dc1c24cd79a837ebfb80f9925949d415d51a Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 5 Dec 2018 08:36:46 -0800
Subject: [PATCH] Add getcpu

Add

  #include <sched.h>

  int getcpu (unsigned int *cpu, unsigned int *node);

to return currently used CPU and NUMA node.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.

	* NEWS: Mention getcpu.
	* include/sched.h (__getcpu): New libc_hidden_proto.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/bits/sched.h (getcpu): New prototype.
	* sysdeps/unix/sysv/linux/getcpu.c: New file.
	* sysdeps/unix/sysv/linux/tst-skeleton-affinity.c (test_size):
	Also check getcpu.
---
 NEWS                                          |  3 ++
 include/sched.h                               |  2 +
 sysdeps/unix/sysv/linux/Makefile              |  2 +-
 sysdeps/unix/sysv/linux/Versions              |  3 ++
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
 sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
 sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
 sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++++++
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
 .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
 .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +
 .../sysv/linux/powerpc/powerpc64/libc.abilist |  1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |  1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |  1 +
 sysdeps/unix/sysv/linux/sh/libc.abilist       |  1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |  1 +
 .../unix/sysv/linux/tst-skeleton-affinity.c   | 12 ++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |  1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |  1 +
 33 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/getcpu.c

diff --git a/NEWS b/NEWS
index 8483dcf492..666416a268 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Version 2.29
 
 Major new features:
 
+* The getcpu wrapper function has been added, which returns currently
+  used CPU and NUMA node.
+
 * A new convenience target has been added for distribution maintainers
   to build and install all locales as directories with files.  The new
   target is run by issuing the following command in your build tree:
diff --git a/include/sched.h b/include/sched.h
index b698f78666..0843c26d73 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -26,5 +26,7 @@ libc_hidden_proto (__clone)
 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		     size_t __child_stack_size, int __flags, void *__arg, ...);
 libc_hidden_proto (__clone2)
+extern __typeof__ (getcpu) __getcpu;
+libc_hidden_proto (__getcpu)
 #endif
 #endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 362cf3b950..988855d897 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -142,7 +142,7 @@ endif
 ifeq ($(subdir),posix)
 sysdep_headers += bits/initspin.h
 
-sysdep_routines += sched_getcpu oldglob
+sysdep_routines += sched_getcpu oldglob getcpu
 
 tests += tst-affinity tst-affinity-pid
 
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 336c13b57d..f1e12d9c69 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -171,6 +171,9 @@ libc {
     mlock2;
     pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
   }
+  GLIBC_2.29 {
+    getcpu;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index e66c741d04..c2ca32e9d2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2138,4 +2138,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 8df162fe99..a86ce442e7 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2033,6 +2033,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 43c804f9dc..b10c07a51d 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index 34f27a7d9b..ea5d51a80d 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
 /* Get index of currently used CPU.  */
 extern int sched_getcpu (void) __THROW;
 
+/* Get currently used CPU and NUMA node.  */
+extern int getcpu (unsigned int *, unsigned int *) __THROW;
+
 /* Switch process to namespace of type NSTYPE indicated by FD.  */
 extern int setns (int __fd, int __nstype) __THROW;
 #endif
diff --git a/sysdeps/unix/sysv/linux/getcpu.c b/sysdeps/unix/sysv/linux/getcpu.c
new file mode 100644
index 0000000000..59c6cc4a14
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getcpu.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2007-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <sysdep.h>
+
+#ifdef HAVE_GETCPU_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
+
+int
+__getcpu (unsigned int *cpu, unsigned int *node)
+{
+#ifdef __NR_getcpu
+  return INLINE_VSYSCALL (getcpu, 3, cpu, node, NULL);
+#else
+  __set_errno (ENOSYS);
+  return -1;
+#endif
+}
+weak_alias (__getcpu, getcpu)
+libc_hidden_def (__getcpu)
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 88b01c2e75..3527d39971 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1880,6 +1880,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 6d02f31612..979aaae1db 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2045,6 +2045,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index 4249712611..a4a90236f8 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1914,6 +1914,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index d47b808862..9f86f26730 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index d5e38308be..558ba5fd4d 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1989,6 +1989,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index 8596b84399..ca773e3d07 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2130,4 +2130,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 88e0f896d5..89c5c296d2 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1967,6 +1967,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index aff7462c34..429624bc95 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1965,6 +1965,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 71d82444aa..fbe714e0bc 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1973,6 +1973,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index de6c53d293..baa657f65b 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index e724bab9fb..a2f407b92e 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2171,4 +2171,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index e9ecbccb71..1fd4fca8c8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1993,6 +1993,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index da83ea6028..cd3dcc0924 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
index 4535b40d15..54ddbb3f80 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
@@ -2228,4 +2228,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
index 65725de4f0..5b9e494071 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 _Exit F
 GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index bbb3c4a8e7..36f5de94d5 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2100,4 +2100,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index e85ac2a178..b74e995d37 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2002,6 +2002,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index d56931022c..964ada9d33 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1908,6 +1908,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index ff939a15c4..7c689af861 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1884,6 +1884,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 64fa9e10a5..e3cc7c1a2e 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1996,6 +1996,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index db909d1506..a7dae1e16d 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1937,6 +1937,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
index 695c1ccdbd..fd1357beb1 100644
--- a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
+++ b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
@@ -165,6 +165,18 @@ test_size (const struct conf *conf, size_t size)
   for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
     {
       int active_cpu = sched_getcpu ();
+      unsigned int numa_cpu, numa_node;
+      if (getcpu (&numa_cpu, &numa_node))
+	{
+	  printf ("error: getcpu: %m\n");
+	  return false;
+	}
+      if ((unsigned int) active_cpu != numa_cpu)
+	{
+	  printf ("error: Unexpected CPU %d, expected %d\n",
+		  active_cpu, numa_cpu);
+	  return false;
+	}
       if (last_active_cpu >= 0 && last_active_cpu != active_cpu)
 	{
 	  printf ("error: Unexpected CPU %d, expected %d\n",
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 3b175f104b..87b6b6d639 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1895,6 +1895,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 1b57710477..39a0009398 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2146,4 +2146,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
-- 
2.19.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 18:48     ` Florian Weimer
  2018-12-05 19:51       ` H.J. Lu
@ 2018-12-05 20:43       ` Joseph Myers
  2018-12-05 20:56         ` The future of the manual (was Re: [PATCH] Add getcpu) Zack Weinberg
  2018-12-05 21:40         ` [PATCH] Add getcpu H.J. Lu
  1 sibling, 2 replies; 32+ messages in thread
From: Joseph Myers @ 2018-12-05 20:43 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu, Carlos O'Donell, GNU C Library

On Wed, 5 Dec 2018, Florian Weimer wrote:

> We have a parallel discussion about a new requirement that all new
> functions must have documentation in the manual.  I don't know what will
> come out of that.

It's not a new requirement at all.  Documenting new interfaces was added 
to <https://sourceware.org/glibc/wiki/Contribution%20checklist> on 
2012-04-17.

There are questions about the details of when some function might be 
excluded from being documented (such as if it's part of a family of 
functions none of which are documented yet), and of how much documentation 
should be included for a Linux-specific function whose main semantics 
*are* to pass its arguments through to a Linux kernel syscall (but even 
there you should document the argument and return types, error and 
cancellation handling, what header declares the function under what 
feature test macros - everything that is not part of the syscall interface 
- even if one might link to external freely-licensed documentation of 
exactly what the syscall does).  But the basic principle that new 
functions should be documented, in the absence of an explicitly stated 
reason that documenting a given function is problematic, seems clear 
enough - just like the principle that a new function should have test 
coverage (in the absence of stated justification of being hard to test), 
and that a new function needs a reason to be architecture-specific, for 
example.

In this case, the proposed function has a prototype *different* from that 
for the syscall, which makes it especially clear that documentation is 
needed.

(The NEWS entry also needs to state that this function is Linux-specific.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 32+ messages in thread

* The future of the manual (was Re: [PATCH] Add getcpu)
  2018-12-05 20:43       ` Joseph Myers
@ 2018-12-05 20:56         ` Zack Weinberg
  2018-12-05 21:29           ` Joseph Myers
  2018-12-07 13:11           ` Florian Weimer
  2018-12-05 21:40         ` [PATCH] Add getcpu H.J. Lu
  1 sibling, 2 replies; 32+ messages in thread
From: Zack Weinberg @ 2018-12-05 20:56 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Florian Weimer, GNU C Library

On Wed, Dec 5, 2018 at 3:43 PM Joseph Myers <joseph@codesourcery.com> wrote:
> On Wed, 5 Dec 2018, Florian Weimer wrote:
>
> > We have a parallel discussion about a new requirement that all new
> > functions must have documentation in the manual.
>
> It's not a new requirement at all.  Documenting new interfaces was added
> to <https://sourceware.org/glibc/wiki/Contribution%20checklist> on
> 2012-04-17.

I get the impression that Florian either believes that the existing
manual is no longer useful, or has some kind of principled objection
to adding new material to it.  Either would be reason to open a
new_discussion about changing this rule.

Florian, would you mind, at your convenience, explaining why you do
not want to add new material to the manual?

zw

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: The future of the manual (was Re: [PATCH] Add getcpu)
  2018-12-05 20:56         ` The future of the manual (was Re: [PATCH] Add getcpu) Zack Weinberg
@ 2018-12-05 21:29           ` Joseph Myers
  2018-12-07 13:11           ` Florian Weimer
  1 sibling, 0 replies; 32+ messages in thread
From: Joseph Myers @ 2018-12-05 21:29 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Florian Weimer, GNU C Library

On Wed, 5 Dec 2018, Zack Weinberg wrote:

> On Wed, Dec 5, 2018 at 3:43 PM Joseph Myers <joseph@codesourcery.com> wrote:
> > On Wed, 5 Dec 2018, Florian Weimer wrote:
> >
> > > We have a parallel discussion about a new requirement that all new
> > > functions must have documentation in the manual.
> >
> > It's not a new requirement at all.  Documenting new interfaces was added
> > to <https://sourceware.org/glibc/wiki/Contribution%20checklist> on
> > 2012-04-17.
> 
> I get the impression that Florian either believes that the existing
> manual is no longer useful, or has some kind of principled objection
> to adding new material to it.  Either would be reason to open a
> new_discussion about changing this rule.
> 
> Florian, would you mind, at your convenience, explaining why you do
> not want to add new material to the manual?

I would also suggest that people reread the previous discussion 
<https://sourceware.org/ml/libc-alpha/2012-04/threads.html#00315> 
(especially Roland's comments 
<https://sourceware.org/ml/libc-alpha/2012-04/msg00988.html>).

I see then I was listing possible exceptions to requiring documentation 
for functions from external standards and direct wrappers round system 
calls <https://sourceware.org/ml/libc-alpha/2012-04/msg00724.html>.  I 
don't now think such exceptions are generally a good idea, but there may 
be cases where we can't usefully say much about semantics beyond that a 
function calls the Linux system call of the same name (plus the 
information about things that aren't part of the syscall interface) - say 
if we add a wrapper for the bpf syscall (bug 18271).

For the bulk of new functions added since that discussion coming from 
external standards - for example, the C11 threads functions and the TS 
18661 floating-point functions - documentation *has* been added to the 
glibc manual (and in many cases not to Linux man-pages).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 20:43       ` Joseph Myers
  2018-12-05 20:56         ` The future of the manual (was Re: [PATCH] Add getcpu) Zack Weinberg
@ 2018-12-05 21:40         ` H.J. Lu
  2018-12-05 21:45           ` Joseph Myers
  2018-12-05 21:55           ` Florian Weimer
  1 sibling, 2 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-05 21:40 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Florian Weimer, Carlos O'Donell, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 1883 bytes --]

On Wed, Dec 5, 2018 at 12:43 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Wed, 5 Dec 2018, Florian Weimer wrote:
>
> > We have a parallel discussion about a new requirement that all new
> > functions must have documentation in the manual.  I don't know what will
> > come out of that.
>
> It's not a new requirement at all.  Documenting new interfaces was added
> to <https://sourceware.org/glibc/wiki/Contribution%20checklist> on
> 2012-04-17.
>
> There are questions about the details of when some function might be
> excluded from being documented (such as if it's part of a family of
> functions none of which are documented yet), and of how much documentation
> should be included for a Linux-specific function whose main semantics
> *are* to pass its arguments through to a Linux kernel syscall (but even
> there you should document the argument and return types, error and
> cancellation handling, what header declares the function under what
> feature test macros - everything that is not part of the syscall interface
> - even if one might link to external freely-licensed documentation of
> exactly what the syscall does).  But the basic principle that new
> functions should be documented, in the absence of an explicitly stated
> reason that documenting a given function is problematic, seems clear
> enough - just like the principle that a new function should have test
> coverage (in the absence of stated justification of being hard to test),
> and that a new function needs a reason to be architecture-specific, for
> example.
>
> In this case, the proposed function has a prototype *different* from that
> for the syscall, which makes it especially clear that documentation is
> needed.

I added an entry to manual/process.texi.

> (The NEWS entry also needs to state that this function is Linux-specific.)
>

Fixed.

Here is the updated patch.

-- 
H.J.

[-- Attachment #2: 0001-Add-getcpu.patch --]
[-- Type: text/x-patch, Size: 23821 bytes --]

From c65b0fa41dbce3f60bb3a22241dae5fc49901ef5 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 5 Dec 2018 08:36:46 -0800
Subject: [PATCH] Add getcpu

Add

  #include <sched.h>

  int getcpu (unsigned int *cpu, unsigned int *node);

to return currently used CPU and NUMA node.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.

	* NEWS: Mention getcpu.
	* include/sched.h (__getcpu): New libc_hidden_proto.
	* manual/process.texi: Document getcpu.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/bits/sched.h (getcpu): New prototype.
	* sysdeps/unix/sysv/linux/getcpu.c: New file.
	* sysdeps/unix/sysv/linux/tst-skeleton-affinity.c (test_size):
	Also check getcpu.
---
 NEWS                                          |  3 ++
 include/sched.h                               |  2 +
 manual/process.texi                           | 24 ++++++++++++
 sysdeps/unix/sysv/linux/Makefile              |  2 +-
 sysdeps/unix/sysv/linux/Versions              |  3 ++
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
 sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
 sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
 sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++++++
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
 .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
 .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +
 .../sysv/linux/powerpc/powerpc64/libc.abilist |  1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |  1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |  1 +
 sysdeps/unix/sysv/linux/sh/libc.abilist       |  1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |  1 +
 .../unix/sysv/linux/tst-skeleton-affinity.c   | 12 ++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |  1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |  1 +
 34 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/getcpu.c

diff --git a/NEWS b/NEWS
index 8483dcf492..3ade0e6231 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Version 2.29
 
 Major new features:
 
+* The getcpu wrapper function has been added, which returns currently
+  used CPU and NUMA node.  This function is Linux-specific.
+
 * A new convenience target has been added for distribution maintainers
   to build and install all locales as directories with files.  The new
   target is run by issuing the following command in your build tree:
diff --git a/include/sched.h b/include/sched.h
index b698f78666..0843c26d73 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -26,5 +26,7 @@ libc_hidden_proto (__clone)
 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		     size_t __child_stack_size, int __flags, void *__arg, ...);
 libc_hidden_proto (__clone2)
+extern __typeof__ (getcpu) __getcpu;
+libc_hidden_proto (__getcpu)
 #endif
 #endif
diff --git a/manual/process.texi b/manual/process.texi
index b82b91f9f1..d40e5d83b6 100644
--- a/manual/process.texi
+++ b/manual/process.texi
@@ -32,6 +32,7 @@ primitive functions to do each step individually instead.
 * Running a Command::           The easy way to run another program.
 * Process Creation Concepts::   An overview of the hard way to do it.
 * Process Identification::      How to get the process ID of a process.
+* Process Information::         How to get current CPU and node of a process.
 * Creating a Process::          How to fork a child process.
 * Executing a File::            How to make a process execute another program.
 * Process Completion::          How to tell when a child process has completed.
@@ -202,6 +203,29 @@ The @code{getppid} function returns the process ID of the parent of the
 current process.
 @end deftypefun
 
+@node Process Information
+@section Process Information
+
+@deftypefun int getcpu (unsigned int *cpu, unsigned int *node)
+@standards{Linux, <sched.h>}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{getcpu} function identifies the processor and node on which
+the calling thread or process is currently running and writes them into
+the integers pointed to by the @var{cpu} and @var{node} arguments.  The
+processor is a unique small integer identifying a CPU.  The node is a
+unique small identifier identifying a NUMA node.  When either @var{cpu}
+or @var{node} is @code{NULL}, nothing is written to the respective
+pointer.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error condition is defined for this function:
+
+@table @code
+@item EFAULT
+Arguments point outside the calling process's address space.
+@end table
+@end deftypefun
+
 @node Creating a Process
 @section Creating a Process
 
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 362cf3b950..988855d897 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -142,7 +142,7 @@ endif
 ifeq ($(subdir),posix)
 sysdep_headers += bits/initspin.h
 
-sysdep_routines += sched_getcpu oldglob
+sysdep_routines += sched_getcpu oldglob getcpu
 
 tests += tst-affinity tst-affinity-pid
 
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 336c13b57d..f1e12d9c69 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -171,6 +171,9 @@ libc {
     mlock2;
     pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
   }
+  GLIBC_2.29 {
+    getcpu;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index e66c741d04..c2ca32e9d2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2138,4 +2138,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 8df162fe99..a86ce442e7 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2033,6 +2033,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 43c804f9dc..b10c07a51d 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index 34f27a7d9b..ea5d51a80d 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
 /* Get index of currently used CPU.  */
 extern int sched_getcpu (void) __THROW;
 
+/* Get currently used CPU and NUMA node.  */
+extern int getcpu (unsigned int *, unsigned int *) __THROW;
+
 /* Switch process to namespace of type NSTYPE indicated by FD.  */
 extern int setns (int __fd, int __nstype) __THROW;
 #endif
diff --git a/sysdeps/unix/sysv/linux/getcpu.c b/sysdeps/unix/sysv/linux/getcpu.c
new file mode 100644
index 0000000000..59c6cc4a14
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getcpu.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2007-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <sysdep.h>
+
+#ifdef HAVE_GETCPU_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
+
+int
+__getcpu (unsigned int *cpu, unsigned int *node)
+{
+#ifdef __NR_getcpu
+  return INLINE_VSYSCALL (getcpu, 3, cpu, node, NULL);
+#else
+  __set_errno (ENOSYS);
+  return -1;
+#endif
+}
+weak_alias (__getcpu, getcpu)
+libc_hidden_def (__getcpu)
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 88b01c2e75..3527d39971 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1880,6 +1880,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 6d02f31612..979aaae1db 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2045,6 +2045,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index 4249712611..a4a90236f8 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1914,6 +1914,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index d47b808862..9f86f26730 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index d5e38308be..558ba5fd4d 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1989,6 +1989,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index 8596b84399..ca773e3d07 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2130,4 +2130,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 88e0f896d5..89c5c296d2 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1967,6 +1967,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index aff7462c34..429624bc95 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1965,6 +1965,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 71d82444aa..fbe714e0bc 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1973,6 +1973,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index de6c53d293..baa657f65b 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index e724bab9fb..a2f407b92e 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2171,4 +2171,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index e9ecbccb71..1fd4fca8c8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1993,6 +1993,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index da83ea6028..cd3dcc0924 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
index 4535b40d15..54ddbb3f80 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
@@ -2228,4 +2228,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
index 65725de4f0..5b9e494071 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 _Exit F
 GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index bbb3c4a8e7..36f5de94d5 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2100,4 +2100,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index e85ac2a178..b74e995d37 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2002,6 +2002,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index d56931022c..964ada9d33 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1908,6 +1908,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index ff939a15c4..7c689af861 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1884,6 +1884,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 64fa9e10a5..e3cc7c1a2e 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1996,6 +1996,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index db909d1506..a7dae1e16d 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1937,6 +1937,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
index 695c1ccdbd..fd1357beb1 100644
--- a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
+++ b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
@@ -165,6 +165,18 @@ test_size (const struct conf *conf, size_t size)
   for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
     {
       int active_cpu = sched_getcpu ();
+      unsigned int numa_cpu, numa_node;
+      if (getcpu (&numa_cpu, &numa_node))
+	{
+	  printf ("error: getcpu: %m\n");
+	  return false;
+	}
+      if ((unsigned int) active_cpu != numa_cpu)
+	{
+	  printf ("error: Unexpected CPU %d, expected %d\n",
+		  active_cpu, numa_cpu);
+	  return false;
+	}
       if (last_active_cpu >= 0 && last_active_cpu != active_cpu)
 	{
 	  printf ("error: Unexpected CPU %d, expected %d\n",
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 3b175f104b..87b6b6d639 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1895,6 +1895,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 1b57710477..39a0009398 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2146,4 +2146,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
-- 
2.19.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 21:40         ` [PATCH] Add getcpu H.J. Lu
@ 2018-12-05 21:45           ` Joseph Myers
  2018-12-05 21:55           ` Florian Weimer
  1 sibling, 0 replies; 32+ messages in thread
From: Joseph Myers @ 2018-12-05 21:45 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Florian Weimer, Carlos O'Donell, GNU C Library

On Wed, 5 Dec 2018, H.J. Lu wrote:

> I added an entry to manual/process.texi.

Thanks.  Note that @standards{} does not currently expand to any text in 
the manual; it only generates entries in the library summary.  So for now 
function descriptions in the manual need to say explicitly what standards 
they come from (i.e., that the function is Linux-specific, in this case) 
and what headers declare the functions.  (In many cases, one or both of 
those pieces of information may well be stated in the relevant section of 
the manual as applying to all the functions in it, rather than needing to 
be repeated in each individual function description.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 21:40         ` [PATCH] Add getcpu H.J. Lu
  2018-12-05 21:45           ` Joseph Myers
@ 2018-12-05 21:55           ` Florian Weimer
  2018-12-06 20:27             ` H.J. Lu
  1 sibling, 1 reply; 32+ messages in thread
From: Florian Weimer @ 2018-12-05 21:55 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Joseph S. Myers, Carlos O'Donell, GNU C Library

* H. J. Lu:

> +@node Process Information
> +@section Process Information

I'm not sure if this is the right place.  This is specifically not a
process attribute, after all.  Perhaps it will fit better into the
discussion of scheduling-related functionality?

> +@deftypefun int getcpu (unsigned int *cpu, unsigned int *node)
> +@standards{Linux, <sched.h>}
> +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}

Can we unwind through vsyscalls?  If not, the function is not AC-safe.

> +The @code{getcpu} function identifies the processor and node on which
> +the calling thread or process is currently running and writes them into
> +the integers pointed to by the @var{cpu} and @var{node} arguments.  The
> +processor is a unique small integer identifying a CPU.  The node is a

“small nonnegative integer”

> +unique small identifier identifying a NUMA node.  When either @var{cpu}

“small nonnegative integer” (not “identifier”)

> +or @var{node} is @code{NULL}, nothing is written to the respective
> +pointer.

Should we add a caveat that due to CPU hotplugging, the values might not
be so small after a while?

> +The return value is @code{0} on success and @code{-1} on failure.  The
> +following @code{errno} error condition is defined for this function:
> +
> +@table @code
> +@item EFAULT
> +Arguments point outside the calling process's address space.
> +@end table
> +@end deftypefun

I don't think the vsyscall can detect the EFAULT error condition
reliably.  Should we really document it?

What about ENOSYS?  Is this system call really supported on all
architectures?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 21:55           ` Florian Weimer
@ 2018-12-06 20:27             ` H.J. Lu
  2018-12-07 16:52               ` Florian Weimer
  0 siblings, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-06 20:27 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Joseph S. Myers, Carlos O'Donell, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 2071 bytes --]

On Wed, Dec 5, 2018 at 1:55 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > +@node Process Information
> > +@section Process Information
>
> I'm not sure if this is the right place.  This is specifically not a
> process attribute, after all.  Perhaps it will fit better into the
> discussion of scheduling-related functionality?

I moved it to manual/resource.texi.

> > +@deftypefun int getcpu (unsigned int *cpu, unsigned int *node)
> > +@standards{Linux, <sched.h>}
> > +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
>
> Can we unwind through vsyscalls?  If not, the function is not AC-safe.

Yes, see:

https://bugzilla.kernel.org/show_bug.cgi?id=201741

> > +The @code{getcpu} function identifies the processor and node on which
> > +the calling thread or process is currently running and writes them into
> > +the integers pointed to by the @var{cpu} and @var{node} arguments.  The
> > +processor is a unique small integer identifying a CPU.  The node is a
>
> “small nonnegative integer”

I changed it to "nonnegative integer” .

> > +unique small identifier identifying a NUMA node.  When either @var{cpu}
>
> “small nonnegative integer” (not “identifier”)

I changed it to "nonnegative integer” .

> > +or @var{node} is @code{NULL}, nothing is written to the respective
> > +pointer.
>
> Should we add a caveat that due to CPU hotplugging, the values might not
> be so small after a while?

I removed "small".

> > +The return value is @code{0} on success and @code{-1} on failure.  The
> > +following @code{errno} error condition is defined for this function:
> > +
> > +@table @code
> > +@item EFAULT
> > +Arguments point outside the calling process's address space.
> > +@end table
> > +@end deftypefun
>
> I don't think the vsyscall can detect the EFAULT error condition
> reliably.  Should we really document it?

Removed.

> What about ENOSYS?  Is this system call really supported on all
> architectures?

Added.

OK for master?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-Add-getcpu.patch --]
[-- Type: text/x-patch, Size: 23297 bytes --]

From edf0e8943a164e21a854568c2b99458d6fbdc192 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 5 Dec 2018 08:36:46 -0800
Subject: [PATCH] Add getcpu

Add

  #include <sched.h>

  int getcpu (unsigned int *cpu, unsigned int *node);

to return currently used CPU and NUMA node.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.

	* NEWS: Mention getcpu.
	* include/sched.h (__getcpu): New libc_hidden_proto.
	* manual/resource.texi: Document getcpu.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/bits/sched.h (getcpu): New prototype.
	* sysdeps/unix/sysv/linux/getcpu.c: New file.
	* sysdeps/unix/sysv/linux/tst-skeleton-affinity.c (test_size):
	Also check getcpu.
---
 NEWS                                          |  3 ++
 include/sched.h                               |  2 +
 manual/resource.texi                          | 21 ++++++++++
 sysdeps/unix/sysv/linux/Makefile              |  2 +-
 sysdeps/unix/sysv/linux/Versions              |  3 ++
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
 sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
 sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
 sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++++++
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
 .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
 .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +
 .../sysv/linux/powerpc/powerpc64/libc.abilist |  1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |  1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |  1 +
 sysdeps/unix/sysv/linux/sh/libc.abilist       |  1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |  1 +
 .../unix/sysv/linux/tst-skeleton-affinity.c   | 12 ++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |  1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |  1 +
 34 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/getcpu.c

diff --git a/NEWS b/NEWS
index 8483dcf492..3ade0e6231 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Version 2.29
 
 Major new features:
 
+* The getcpu wrapper function has been added, which returns currently
+  used CPU and NUMA node.  This function is Linux-specific.
+
 * A new convenience target has been added for distribution maintainers
   to build and install all locales as directories with files.  The new
   target is run by issuing the following command in your build tree:
diff --git a/include/sched.h b/include/sched.h
index b698f78666..0843c26d73 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -26,5 +26,7 @@ libc_hidden_proto (__clone)
 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		     size_t __child_stack_size, int __flags, void *__arg, ...);
 libc_hidden_proto (__clone2)
+extern __typeof__ (getcpu) __getcpu;
+libc_hidden_proto (__getcpu)
 #endif
 #endif
diff --git a/manual/resource.texi b/manual/resource.texi
index 8bc2a803d4..8c4c92a184 100644
--- a/manual/resource.texi
+++ b/manual/resource.texi
@@ -1429,6 +1429,27 @@ not leave a processor for the process or thread to run on.
 This function is a GNU extension and is declared in @file{sched.h}.
 @end deftypefun
 
+@deftypefun int getcpu (unsigned int *cpu, unsigned int *node)
+@standards{Linux, <sched.h>}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{getcpu} function identifies the processor and node on which
+the calling thread or process is currently running and writes them into
+the integers pointed to by the @var{cpu} and @var{node} arguments.  The
+processor is a unique nonnegative integer identifying a CPU.  The node
+is a unique nonnegative integer identifying a NUMA node.  When either
+@var{cpu} or @var{node} is @code{NULL}, nothing is written to the
+respective pointer.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error condition is defined for this function:
+
+@table @code
+@item ENOSYS
+The operating system does not support this function.
+@end table
+
+This function is Linux-specific and is declared in @file{sched.h}.
+@end deftypefun
 
 @node Memory Resources
 @section Querying memory available resources
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 362cf3b950..988855d897 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -142,7 +142,7 @@ endif
 ifeq ($(subdir),posix)
 sysdep_headers += bits/initspin.h
 
-sysdep_routines += sched_getcpu oldglob
+sysdep_routines += sched_getcpu oldglob getcpu
 
 tests += tst-affinity tst-affinity-pid
 
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 336c13b57d..f1e12d9c69 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -171,6 +171,9 @@ libc {
     mlock2;
     pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
   }
+  GLIBC_2.29 {
+    getcpu;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index e66c741d04..c2ca32e9d2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2138,4 +2138,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 8df162fe99..a86ce442e7 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2033,6 +2033,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 43c804f9dc..b10c07a51d 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index 34f27a7d9b..ea5d51a80d 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
 /* Get index of currently used CPU.  */
 extern int sched_getcpu (void) __THROW;
 
+/* Get currently used CPU and NUMA node.  */
+extern int getcpu (unsigned int *, unsigned int *) __THROW;
+
 /* Switch process to namespace of type NSTYPE indicated by FD.  */
 extern int setns (int __fd, int __nstype) __THROW;
 #endif
diff --git a/sysdeps/unix/sysv/linux/getcpu.c b/sysdeps/unix/sysv/linux/getcpu.c
new file mode 100644
index 0000000000..59c6cc4a14
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getcpu.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2007-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <sysdep.h>
+
+#ifdef HAVE_GETCPU_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
+
+int
+__getcpu (unsigned int *cpu, unsigned int *node)
+{
+#ifdef __NR_getcpu
+  return INLINE_VSYSCALL (getcpu, 3, cpu, node, NULL);
+#else
+  __set_errno (ENOSYS);
+  return -1;
+#endif
+}
+weak_alias (__getcpu, getcpu)
+libc_hidden_def (__getcpu)
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 88b01c2e75..3527d39971 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1880,6 +1880,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 6d02f31612..979aaae1db 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2045,6 +2045,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index 4249712611..a4a90236f8 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1914,6 +1914,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index d47b808862..9f86f26730 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index d5e38308be..558ba5fd4d 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1989,6 +1989,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index 8596b84399..ca773e3d07 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2130,4 +2130,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 88e0f896d5..89c5c296d2 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1967,6 +1967,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index aff7462c34..429624bc95 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1965,6 +1965,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 71d82444aa..fbe714e0bc 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1973,6 +1973,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index de6c53d293..baa657f65b 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index e724bab9fb..a2f407b92e 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2171,4 +2171,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index e9ecbccb71..1fd4fca8c8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1993,6 +1993,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index da83ea6028..cd3dcc0924 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
index 4535b40d15..54ddbb3f80 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
@@ -2228,4 +2228,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
index 65725de4f0..5b9e494071 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 _Exit F
 GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index bbb3c4a8e7..36f5de94d5 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2100,4 +2100,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index e85ac2a178..b74e995d37 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2002,6 +2002,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index d56931022c..964ada9d33 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1908,6 +1908,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index ff939a15c4..7c689af861 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1884,6 +1884,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 64fa9e10a5..e3cc7c1a2e 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1996,6 +1996,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index db909d1506..a7dae1e16d 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1937,6 +1937,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
index 695c1ccdbd..fd1357beb1 100644
--- a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
+++ b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
@@ -165,6 +165,18 @@ test_size (const struct conf *conf, size_t size)
   for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
     {
       int active_cpu = sched_getcpu ();
+      unsigned int numa_cpu, numa_node;
+      if (getcpu (&numa_cpu, &numa_node))
+	{
+	  printf ("error: getcpu: %m\n");
+	  return false;
+	}
+      if ((unsigned int) active_cpu != numa_cpu)
+	{
+	  printf ("error: Unexpected CPU %d, expected %d\n",
+		  active_cpu, numa_cpu);
+	  return false;
+	}
       if (last_active_cpu >= 0 && last_active_cpu != active_cpu)
 	{
 	  printf ("error: Unexpected CPU %d, expected %d\n",
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 3b175f104b..87b6b6d639 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1895,6 +1895,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 1b57710477..39a0009398 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2146,4 +2146,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
-- 
2.19.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 20:14             ` H.J. Lu
@ 2018-12-07 12:51               ` Tulio Magno Quites Machado Filho
  2018-12-07 16:51                 ` H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: Tulio Magno Quites Machado Filho @ 2018-12-07 12:51 UTC (permalink / raw)
  To: H.J. Lu, Florian Weimer
  Cc: Carlos O'Donell, GNU C Library, Andreas Schwab

"H.J. Lu" <hjl.tools@gmail.com> writes:

> 	* NEWS: Mention getcpu.
> 	* include/sched.h (__getcpu): New libc_hidden_proto.
> 	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
> 	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
> 	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
> 	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
> 	Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
> 	Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
> 	Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
> 	Likewise.

I noticed the powerpc64le abilist file is missing in the ChangeLog.

>  NEWS                                          |  3 ++
>  include/sched.h                               |  2 +
>  sysdeps/unix/sysv/linux/Makefile              |  2 +-
>  sysdeps/unix/sysv/linux/Versions              |  3 ++
>  sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
>  sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
>  sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
>  sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
>  sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++++++
>  sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
>  sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
>  sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
>  .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
>  .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
>  .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
>  .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
>  .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
>  .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
>  .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
>  sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
>  .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
>  .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
>  .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +

While you're making the correct changes.  So, just a ChangeLog entry missing.

This patch will conflict with an earlier patch from Andreas Schwab:
https://sourceware.org/ml/libc-alpha/2018-11/msg00752.html

-- 
Tulio Magno

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: The future of the manual (was Re: [PATCH] Add getcpu)
  2018-12-05 20:56         ` The future of the manual (was Re: [PATCH] Add getcpu) Zack Weinberg
  2018-12-05 21:29           ` Joseph Myers
@ 2018-12-07 13:11           ` Florian Weimer
  1 sibling, 0 replies; 32+ messages in thread
From: Florian Weimer @ 2018-12-07 13:11 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Joseph Myers, GNU C Library

* Zack Weinberg:

> I get the impression that Florian either believes that the existing
> manual is no longer useful, or has some kind of principled objection
> to adding new material to it.  Either would be reason to open a
> new_discussion about changing this rule.
>
> Florian, would you mind, at your convenience, explaining why you do
> not want to add new material to the manual?

First of all, from my perspective, it's not about Texinfo at all.  I
actually prefer Texinfo to quite a few of the documentation markup
languages out there.

Visibility of the manual is poor compared to the man-pages project.
Academic citations are far fewer than for man7.org.  I don't know why
this is.

Debian only ships a very old version of the manual, in the non-free
section, so Debian users have to rely on the web version.

I recently discovered ‘C-h S sprintf RET’ in Emacs, which takes you
directly to the documentation of the printf function, similar to ‘M-x
man RET sprintf RET’.  But the manual is structured poorly to support
this kind of usage.  For example, the subsection about sprintf does not
give you a link to the format strings accepted by sprintf.

All in all, it makes me feel that the manual is for a really small
audience, which makes work on it not very satisfying.  I think we should
rather contribute to the man7.org manual pages and make sure that the
information found there is up to our standards.

And of course, the GFDL is problematic (it's the reason why Debian
doesn't ship the manual, and why we can't add Javascript code to improve
the web version, similar to what OpenJDK did), and so is the
U.S. regulatory notice.  I feel someone needs to make a stand here,
otherwise things will never change.

I had a lengthy chat about this with Carlos yesterday, and my position
has mellowed somewhat.  But I still find the situation frustrating.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-07 12:51               ` Tulio Magno Quites Machado Filho
@ 2018-12-07 16:51                 ` H.J. Lu
  0 siblings, 0 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-07 16:51 UTC (permalink / raw)
  To: Tulio Magno Quites Machado Filho
  Cc: Florian Weimer, Carlos O'Donell, GNU C Library, Andreas Schwab

On Fri, Dec 7, 2018 at 4:51 AM Tulio Magno Quites Machado Filho
<tuliom@ascii.art.br> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> >       * NEWS: Mention getcpu.
> >       * include/sched.h (__getcpu): New libc_hidden_proto.
> >       * sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
> >       * sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
> >       * sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
> >       * sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
> >       Likewise.
> >       * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
> >       * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
> >       Likewise.
> >       * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
> >       Likewise.
> >       * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
> >       Likewise.
>
> I noticed the powerpc64le abilist file is missing in the ChangeLog.

Fixed.

> >  NEWS                                          |  3 ++
> >  include/sched.h                               |  2 +
> >  sysdeps/unix/sysv/linux/Makefile              |  2 +-
> >  sysdeps/unix/sysv/linux/Versions              |  3 ++
> >  sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
> >  sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
> >  sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
> >  sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
> >  sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++++++
> >  sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
> >  sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
> >  sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
> >  .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
> >  .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
> >  .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
> >  .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
> >  .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
> >  .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
> >  .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
> >  sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
> >  .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
> >  .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
> >  .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +
>
> While you're making the correct changes.  So, just a ChangeLog entry missing.
>
> This patch will conflict with an earlier patch from Andreas Schwab:
> https://sourceware.org/ml/libc-alpha/2018-11/msg00752.html

One of us has to resolve the conflict.

-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-06 20:27             ` H.J. Lu
@ 2018-12-07 16:52               ` Florian Weimer
  2018-12-07 17:16                 ` H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: Florian Weimer @ 2018-12-07 16:52 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Joseph S. Myers, Carlos O'Donell, GNU C Library

* H. J. Lu:

> +* The getcpu wrapper function has been added, which returns currently
> +  used CPU and NUMA node.  This function is Linux-specific.

“returns the currently used” (not sure)?

> diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
> index 695c1ccdbd..fd1357beb1 100644
> --- a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
> +++ b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
> @@ -165,6 +165,18 @@ test_size (const struct conf *conf, size_t size)
>    for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
>      {
>        int active_cpu = sched_getcpu ();
> +      unsigned int numa_cpu, numa_node;
> +      if (getcpu (&numa_cpu, &numa_node))

!= NULL

> +	{
> +	  printf ("error: getcpu: %m\n");
> +	  return false;

Okay, ENOSYS is a hard error here because we have checked for a working
sched_getcpu.

> +	}
> +      if ((unsigned int) active_cpu != numa_cpu)
> +	{
> +	  printf ("error: Unexpected CPU %d, expected %d\n",
> +		  active_cpu, numa_cpu);
> +	  return false;
> +	}
>        if (last_active_cpu >= 0 && last_active_cpu != active_cpu)

I think you need to move the getcpu call and this check down further,
after the setaffinity call with a single-element CPU set.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-07 16:52               ` Florian Weimer
@ 2018-12-07 17:16                 ` H.J. Lu
  2018-12-07 17:17                   ` Florian Weimer
  0 siblings, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-07 17:16 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Joseph S. Myers, Carlos O'Donell, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 1666 bytes --]

On Fri, Dec 7, 2018 at 8:51 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > +* The getcpu wrapper function has been added, which returns currently
> > +  used CPU and NUMA node.  This function is Linux-specific.
>
> “returns the currently used” (not sure)?

Fixed.

> > diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
> > index 695c1ccdbd..fd1357beb1 100644
> > --- a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
> > +++ b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
> > @@ -165,6 +165,18 @@ test_size (const struct conf *conf, size_t size)
> >    for (int cpu = 0; cpu <= conf->last_cpu; ++cpu)
> >      {
> >        int active_cpu = sched_getcpu ();
> > +      unsigned int numa_cpu, numa_node;
> > +      if (getcpu (&numa_cpu, &numa_node))
>
> != NULL

I changed to

if (getcpu (&numa_cpu, &numa_node) != 0)

since getcpu returns int.

> > +     {
> > +       printf ("error: getcpu: %m\n");
> > +       return false;
>
> Okay, ENOSYS is a hard error here because we have checked for a working
> sched_getcpu.
>
> > +     }
> > +      if ((unsigned int) active_cpu != numa_cpu)
> > +     {
> > +       printf ("error: Unexpected CPU %d, expected %d\n",
> > +               active_cpu, numa_cpu);
> > +       return false;
> > +     }
> >        if (last_active_cpu >= 0 && last_active_cpu != active_cpu)
>
> I think you need to move the getcpu call and this check down further,
> after the setaffinity call with a single-element CPU set.
>

Done.

Here is the updated patch.  OK for master?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-Add-getcpu.patch --]
[-- Type: text/x-patch, Size: 24052 bytes --]

From d78846c626756c0c275ba5a29bebbec7fdc8f4e1 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 5 Dec 2018 08:36:46 -0800
Subject: [PATCH] Add getcpu

Add

  #include <sched.h>

  int getcpu (unsigned int *cpu, unsigned int *node);

to return currently used CPU and NUMA node.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.

	* NEWS: Mention getcpu.
	* include/sched.h (__getcpu): New libc_hidden_proto.
	* manual/resource.texi: Document getcpu.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add getcpu.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_2.29): Add getcpu.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add getcpu.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/bits/sched.h (getcpu): New prototype.
	* sysdeps/unix/sysv/linux/getcpu.c: New file.
	* sysdeps/unix/sysv/linux/tst-skeleton-affinity.c (test_size):
	Also check getcpu.
---
 NEWS                                          |  3 ++
 include/sched.h                               |  2 +
 manual/resource.texi                          | 21 ++++++++++
 sysdeps/unix/sysv/linux/Makefile              |  2 +-
 sysdeps/unix/sysv/linux/Versions              |  3 ++
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |  1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  1 +
 sysdeps/unix/sysv/linux/arm/libc.abilist      |  1 +
 sysdeps/unix/sysv/linux/bits/sched.h          |  3 ++
 sysdeps/unix/sysv/linux/getcpu.c              | 38 +++++++++++++++++++
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |  1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |  1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |  1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |  1 +
 .../unix/sysv/linux/microblaze/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |  1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |  1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |  1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |  1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |  1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |  1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |  1 +
 .../linux/powerpc/powerpc64/libc-le.abilist   |  1 +
 .../sysv/linux/powerpc/powerpc64/libc.abilist |  1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |  1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |  1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |  1 +
 sysdeps/unix/sysv/linux/sh/libc.abilist       |  1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |  1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |  1 +
 .../unix/sysv/linux/tst-skeleton-affinity.c   | 12 ++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |  1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |  1 +
 34 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/getcpu.c

diff --git a/NEWS b/NEWS
index f338c32e92..ae80818df4 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Version 2.29
 
 Major new features:
 
+* The getcpu wrapper function has been added, which returns the currently
+  used CPU and NUMA node.  This function is Linux-specific.
+
 * A new convenience target has been added for distribution maintainers
   to build and install all locales as directories with files.  The new
   target is run by issuing the following command in your build tree:
diff --git a/include/sched.h b/include/sched.h
index b698f78666..0843c26d73 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -26,5 +26,7 @@ libc_hidden_proto (__clone)
 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		     size_t __child_stack_size, int __flags, void *__arg, ...);
 libc_hidden_proto (__clone2)
+extern __typeof__ (getcpu) __getcpu;
+libc_hidden_proto (__getcpu)
 #endif
 #endif
diff --git a/manual/resource.texi b/manual/resource.texi
index 8bc2a803d4..8c4c92a184 100644
--- a/manual/resource.texi
+++ b/manual/resource.texi
@@ -1429,6 +1429,27 @@ not leave a processor for the process or thread to run on.
 This function is a GNU extension and is declared in @file{sched.h}.
 @end deftypefun
 
+@deftypefun int getcpu (unsigned int *cpu, unsigned int *node)
+@standards{Linux, <sched.h>}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+The @code{getcpu} function identifies the processor and node on which
+the calling thread or process is currently running and writes them into
+the integers pointed to by the @var{cpu} and @var{node} arguments.  The
+processor is a unique nonnegative integer identifying a CPU.  The node
+is a unique nonnegative integer identifying a NUMA node.  When either
+@var{cpu} or @var{node} is @code{NULL}, nothing is written to the
+respective pointer.
+
+The return value is @code{0} on success and @code{-1} on failure.  The
+following @code{errno} error condition is defined for this function:
+
+@table @code
+@item ENOSYS
+The operating system does not support this function.
+@end table
+
+This function is Linux-specific and is declared in @file{sched.h}.
+@end deftypefun
 
 @node Memory Resources
 @section Querying memory available resources
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 362cf3b950..988855d897 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -142,7 +142,7 @@ endif
 ifeq ($(subdir),posix)
 sysdep_headers += bits/initspin.h
 
-sysdep_routines += sched_getcpu oldglob
+sysdep_routines += sched_getcpu oldglob getcpu
 
 tests += tst-affinity tst-affinity-pid
 
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 336c13b57d..f1e12d9c69 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -171,6 +171,9 @@ libc {
     mlock2;
     pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
   }
+  GLIBC_2.29 {
+    getcpu;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index 8763e7b618..9c330f325e 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2138,5 +2138,6 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index c7dfef32d6..f630fa4c6f 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2033,6 +2033,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index a306d13a0f..b96f45590f 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.4 _Exit F
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index 34f27a7d9b..ea5d51a80d 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -86,6 +86,9 @@ extern int unshare (int __flags) __THROW;
 /* Get index of currently used CPU.  */
 extern int sched_getcpu (void) __THROW;
 
+/* Get currently used CPU and NUMA node.  */
+extern int getcpu (unsigned int *, unsigned int *) __THROW;
+
 /* Switch process to namespace of type NSTYPE indicated by FD.  */
 extern int setns (int __fd, int __nstype) __THROW;
 #endif
diff --git a/sysdeps/unix/sysv/linux/getcpu.c b/sysdeps/unix/sysv/linux/getcpu.c
new file mode 100644
index 0000000000..59c6cc4a14
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getcpu.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2007-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <sysdep.h>
+
+#ifdef HAVE_GETCPU_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
+
+int
+__getcpu (unsigned int *cpu, unsigned int *node)
+{
+#ifdef __NR_getcpu
+  return INLINE_VSYSCALL (getcpu, 3, cpu, node, NULL);
+#else
+  __set_errno (ENOSYS);
+  return -1;
+#endif
+}
+weak_alias (__getcpu, getcpu)
+libc_hidden_def (__getcpu)
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 4285936c2c..088a8ee369 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1880,6 +1880,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index d190399192..f7ff2c57b9 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2045,6 +2045,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index 918daeb348..becd8b1033 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1914,6 +1914,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index c9e534cf8b..74e42a5209 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.4 _Exit F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index c8e70be876..4af5a74e8a 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1989,6 +1989,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index e356ec6d33..ccef673fd2 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2130,5 +2130,6 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 3154251d25..1054bb599e 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1967,6 +1967,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index e9445adf14..4f5b5ffebf 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1965,6 +1965,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 4043077bc3..943aee58d4 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1973,6 +1973,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index e47cb434dc..17a5d17ef9 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index 024c55f29e..4d62a540fd 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2171,5 +2171,6 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index 5c26044f5e..ecc2d6fa13 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1993,6 +1993,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index a12e7b6708..f5830f9c33 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
index 939978e2af..2c712636ef 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
@@ -2228,5 +2228,6 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
index 82f5aeed33..633d8f4792 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 _Exit F
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index 9e7c904d2c..195bc8b2cf 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2100,5 +2100,6 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index f4a52b543a..334def033c 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2002,6 +2002,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index 8d8a4035bb..536f4c4ced 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1908,6 +1908,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index 5c05555842..30ae3b6ebb 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1884,6 +1884,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 4d4e972d58..68b107d080 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1996,6 +1996,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index 96ad7b8325..e5b6a4da50 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1937,6 +1937,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
index 695c1ccdbd..0f11eeb37c 100644
--- a/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
+++ b/sysdeps/unix/sysv/linux/tst-skeleton-affinity.c
@@ -189,6 +189,18 @@ test_size (const struct conf *conf, size_t size)
 	  printf ("error: Unexpected CPU %d, expected %d\n", active_cpu, cpu);
 	  return false;
 	}
+      unsigned int numa_cpu, numa_node;
+      if (getcpu (&numa_cpu, &numa_node) != 0)
+	{
+	  printf ("error: getcpu: %m\n");
+	  return false;
+	}
+      if ((unsigned int) active_cpu != numa_cpu)
+	{
+	  printf ("error: Unexpected CPU %d, expected %d\n",
+		  active_cpu, numa_cpu);
+	  return false;
+	}
       if (getaffinity (kernel_size, set2) < 0)
 	{
 	  printf ("error: size %zu: getaffinity (2): %m\n", size);
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 52e65c5020..86dfb0c94d 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1895,6 +1895,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index dccc15bb67..dd688263aa 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2146,5 +2146,6 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 getcpu F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
-- 
2.19.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-07 17:16                 ` H.J. Lu
@ 2018-12-07 17:17                   ` Florian Weimer
  2018-12-07 20:38                     ` [PATCH] Don't use __typeof__ (getcpu) H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: Florian Weimer @ 2018-12-07 17:17 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Joseph S. Myers, Carlos O'Donell, GNU C Library

* H. J. Lu:

> Here is the updated patch.  OK for master?

Looks okay to me now.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH] Don't use __typeof__ (getcpu)
  2018-12-07 17:17                   ` Florian Weimer
@ 2018-12-07 20:38                     ` H.J. Lu
  2018-12-07 20:49                       ` Samuel Thibault
  0 siblings, 1 reply; 32+ messages in thread
From: H.J. Lu @ 2018-12-07 20:38 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Joseph S. Myers, Carlos O'Donell, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 252 bytes --]

On Fri, Dec 7, 2018 at 9:15 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > Here is the updated patch.  OK for master?
>
> Looks okay to me now.

This is needed for Hurd.

Tested with build-many-glibcs.py.  OK for master?

-- 
H.J.

[-- Attachment #2: 0001-Don-t-use-__typeof__-getcpu.patch --]
[-- Type: text/x-patch, Size: 1064 bytes --]

From 2894f9226744f94a03bcd2d9ca3794a2bdbe8923 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 7 Dec 2018 12:25:33 -0800
Subject: [PATCH] Don't use __typeof__ (getcpu)

We can't use "__typeof__ (getcpu)" since getcpu is Linux specific and
Hurd doesn't have it.

Tested with build-many-glibcs.py.

	* include/sched.h (__getcpu): Don't use __typeof__ (getcpu).
---
 include/sched.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/sched.h b/include/sched.h
index 0843c26d73..4abc440176 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -26,7 +26,9 @@ libc_hidden_proto (__clone)
 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		     size_t __child_stack_size, int __flags, void *__arg, ...);
 libc_hidden_proto (__clone2)
-extern __typeof__ (getcpu) __getcpu;
+/* NB: Can't use "__typeof__ (getcpu)" since getcpu is Linux specific
+   and Hurd doesn't have it.  */
+extern int __getcpu (unsigned int *, unsigned int *);
 libc_hidden_proto (__getcpu)
 #endif
 #endif
-- 
2.19.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Don't use __typeof__ (getcpu)
  2018-12-07 20:38                     ` [PATCH] Don't use __typeof__ (getcpu) H.J. Lu
@ 2018-12-07 20:49                       ` Samuel Thibault
  2018-12-07 22:18                         ` H.J. Lu
  0 siblings, 1 reply; 32+ messages in thread
From: Samuel Thibault @ 2018-12-07 20:49 UTC (permalink / raw)
  To: H.J. Lu
  Cc: Florian Weimer, Joseph S. Myers, Carlos O'Donell, GNU C Library

H.J. Lu, le ven. 07 déc. 2018 12:29:50 -0800, a ecrit:
> On Fri, Dec 7, 2018 at 9:15 AM Florian Weimer <fweimer@redhat.com> wrote:
> >
> > * H. J. Lu:
> >
> > > Here is the updated patch.  OK for master?
> >
> > Looks okay to me now.
> 
> This is needed for Hurd.
> 
> Tested with build-many-glibcs.py.  OK for master?

I was testing the same patch :)

Please commit :)

Samuel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Don't use __typeof__ (getcpu)
  2018-12-07 20:49                       ` Samuel Thibault
@ 2018-12-07 22:18                         ` H.J. Lu
  0 siblings, 0 replies; 32+ messages in thread
From: H.J. Lu @ 2018-12-07 22:18 UTC (permalink / raw)
  To: Samuel Thibault
  Cc: Florian Weimer, Joseph S. Myers, Carlos O'Donell, GNU C Library

On Fri, Dec 7, 2018 at 12:38 PM Samuel Thibault
<samuel.thibault@ens-lyon.org> wrote:
>
> H.J. Lu, le ven. 07 déc. 2018 12:29:50 -0800, a ecrit:
> > On Fri, Dec 7, 2018 at 9:15 AM Florian Weimer <fweimer@redhat.com> wrote:
> > >
> > > * H. J. Lu:
> > >
> > > > Here is the updated patch.  OK for master?
> > >
> > > Looks okay to me now.
> >
> > This is needed for Hurd.
> >
> > Tested with build-many-glibcs.py.  OK for master?
>
> I was testing the same patch :)
>
> Please commit :)
>

Done.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-05 17:42   ` [PATCH] Add getcpu H.J. Lu
  2018-12-05 18:14     ` H.J. Lu
  2018-12-05 18:48     ` Florian Weimer
@ 2018-12-10 12:22     ` Szabolcs Nagy
  2018-12-10 13:28       ` Florian Weimer
  2 siblings, 1 reply; 32+ messages in thread
From: Szabolcs Nagy @ 2018-12-10 12:22 UTC (permalink / raw)
  To: H.J. Lu, Carlos O'Donell; +Cc: nd, GNU C Library

On 05/12/18 17:41, H.J. Lu wrote:
> On Wed, Dec 5, 2018 at 9:33 AM Carlos O'Donell <carlos@redhat.com> wrote:
>>
>> On 12/5/18 9:29 AM, H.J. Lu wrote:
>>> To optimize for multi-node NUMA system, I need a very fast way to identity which
>>> node the current process is running on.  getcpu:
>>>
>>> NAME
>>>        getcpu  -  determine  CPU  and NUMA node on which the calling thread is
>>>        running
...
>> I see that on x86 you have a vdso vgetcpu, and that lsl is one instruction and
>> loads the cpunode mask and ccpunode bits in one shot (atomic). So this should
>> work fine, but for all other callers I assume this will be a syscall.
> 
> I need vdso getcpu to avoid syscall.  I am working on a NUMA spinlock
> library which depends on a very fast getcpu.

hm i thought rseq will let you access cpuid faster than vdso.
(and that can even protect against preemptive scheduling.
i don't know much about numa, but i'd expect the cpuid to
numa node mapping to be fixed and then cpuid is enough)

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH] Add getcpu
  2018-12-10 12:22     ` [PATCH] Add getcpu Szabolcs Nagy
@ 2018-12-10 13:28       ` Florian Weimer
  0 siblings, 0 replies; 32+ messages in thread
From: Florian Weimer @ 2018-12-10 13:28 UTC (permalink / raw)
  To: Szabolcs Nagy; +Cc: H.J. Lu, Carlos O'Donell, nd, GNU C Library

* Szabolcs Nagy:

> On 05/12/18 17:41, H.J. Lu wrote:
>> On Wed, Dec 5, 2018 at 9:33 AM Carlos O'Donell <carlos@redhat.com> wrote:
>>>
>>> On 12/5/18 9:29 AM, H.J. Lu wrote:
>>>> To optimize for multi-node NUMA system, I need a very fast way to identity which
>>>> node the current process is running on.  getcpu:
>>>>
>>>> NAME
>>>>        getcpu  -  determine  CPU  and NUMA node on which the calling thread is
>>>>        running
> ...
>>> I see that on x86 you have a vdso vgetcpu, and that lsl is one instruction and
>>> loads the cpunode mask and ccpunode bits in one shot (atomic). So this should
>>> work fine, but for all other callers I assume this will be a syscall.
>> 
>> I need vdso getcpu to avoid syscall.  I am working on a NUMA spinlock
>> library which depends on a very fast getcpu.
>
> hm i thought rseq will let you access cpuid faster than vdso.
> (and that can even protect against preemptive scheduling.
> i don't know much about numa, but i'd expect the cpuid to
> numa node mapping to be fixed and then cpuid is enough)

The mapping is not fixed, due to CPU hotplug/unplug, VM migration and
CRIU.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2018-12-10 12:22 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 14:30 RFC: Add getcpu wrapper H.J. Lu
2018-12-05 15:35 ` Florian Weimer
2018-12-05 15:40   ` H.J. Lu
2018-12-05 15:49     ` Florian Weimer
2018-12-05 16:01       ` Zack Weinberg
2018-12-05 16:05         ` H.J. Lu
2018-12-05 17:33 ` Carlos O'Donell
2018-12-05 17:42   ` [PATCH] Add getcpu H.J. Lu
2018-12-05 18:14     ` H.J. Lu
2018-12-05 18:48     ` Florian Weimer
2018-12-05 19:51       ` H.J. Lu
2018-12-05 19:57         ` Florian Weimer
2018-12-05 20:07           ` H.J. Lu
2018-12-05 20:14             ` H.J. Lu
2018-12-07 12:51               ` Tulio Magno Quites Machado Filho
2018-12-07 16:51                 ` H.J. Lu
2018-12-05 20:43       ` Joseph Myers
2018-12-05 20:56         ` The future of the manual (was Re: [PATCH] Add getcpu) Zack Weinberg
2018-12-05 21:29           ` Joseph Myers
2018-12-07 13:11           ` Florian Weimer
2018-12-05 21:40         ` [PATCH] Add getcpu H.J. Lu
2018-12-05 21:45           ` Joseph Myers
2018-12-05 21:55           ` Florian Weimer
2018-12-06 20:27             ` H.J. Lu
2018-12-07 16:52               ` Florian Weimer
2018-12-07 17:16                 ` H.J. Lu
2018-12-07 17:17                   ` Florian Weimer
2018-12-07 20:38                     ` [PATCH] Don't use __typeof__ (getcpu) H.J. Lu
2018-12-07 20:49                       ` Samuel Thibault
2018-12-07 22:18                         ` H.J. Lu
2018-12-10 12:22     ` [PATCH] Add getcpu Szabolcs Nagy
2018-12-10 13:28       ` Florian Weimer

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).