From a092ca9453df677053787b376322362e3bbe91ca Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 7 Dec 2018 09:17:37 -0800 Subject: Add getcpu Add #include 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. --- manual/resource.texi | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'manual/resource.texi') 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, } +@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 -- cgit v1.2.3