getcpu(2) System Calls Manual getcpu(2) getcpu - NUMA, C (libc, -lc) #define _GNU_SOURCE /* feature_test_macros(7) */ #include int getcpu(unsigned int *_Nullable cpu, unsigned int *_Nullable node); getcpu() , , cpu node. , . , NUMA. cpu node NULL, . , cpu, : unless the CPU affinity has been fixed using sched_setaffinity(2), the kernel might change the CPU at any time. (Normally this does not happen because the scheduler tries to minimize movements between CPUs to keep caches hot, but it is possible.) , cpu, : sched_setaffinity(2), ( , , ). , , cpu node, . On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error. EFAULT . Linux. Linux 2.6.19 (x86-64 and i386), glibc 2.29. C The kernel system call has a third argument: int getcpu(unsigned int *cpu, unsigned int *node, struct getcpu_cache *tcache); The tcache argument is unused since Linux 2.6.24, and (when invoking the system call directly) should be specified as NULL, unless portability to Linux 2.6.23 or earlier is required. In Linux 2.6.23 and earlier, if the tcache argument was non-NULL, then it specified a pointer to a caller-allocated buffer in thread-local storage that was used to provide a caching mechanism for getcpu(). Use of the cache could speed getcpu() calls, at the cost that there was a very small chance that the returned information would be out of date. The caching mechanism was considered to cause problems when migrating threads between CPUs, and so the argument is now ignored. Linux ( vdso(7)). getcpu() -- NUMA. mbind(2), sched_setaffinity(2), set_mempolicy(2), sched_getcpu(3), cpuset(7), vdso(7) () Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 2 2024 . getcpu(2)