1 .\" This man page is Copyright (C) 2006 Andi Kleen <ak@muc.de>.
3 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
10 .\" 2008, mtk, various edits
12 .TH GETCPU 2 2017-09-15 "Linux" "Linux Programmer's Manual"
14 getcpu \- determine CPU and NUMA node on which the calling thread is running
17 .B #include <linux/getcpu.h>
19 .BI "int getcpu(unsigned *" cpu ", unsigned *" node \
20 ", struct getcpu_cache *" tcache );
24 There is no glibc wrapper for this system call; see NOTES.
28 system call identifies the processor and node on which the calling
29 thread or process is currently running and writes them into the
30 integers pointed to by the
35 The processor is a unique small integer identifying a CPU.
36 The node is a unique small identifier identifying a NUMA node.
41 is NULL nothing is written to the respective pointer.
43 The third argument to this system call is nowadays unused,
44 and should be specified as NULL
45 unless portability to Linux 2.6.23 or earlier is required (see NOTES).
47 The information placed in
49 is guaranteed to be current only at the time of the call:
50 unless the CPU affinity has been fixed using
51 .BR sched_setaffinity (2),
52 the kernel might change the CPU at any time.
53 (Normally this does not happen
54 because the scheduler tries to minimize movements between CPUs to
55 keep caches hot, but it is possible.)
56 The caller must allow for the possibility that the information returned in
60 is no longer current by the time the call returns.
62 On success, 0 is returned.
63 On error, \-1 is returned, and
69 Arguments point outside the calling process's address space.
72 was added in kernel 2.6.19 for x86-64 and i386.
77 Linux makes a best effort to make this call as fast as possible.
78 (On some architectures, this is done via an implementation in the
82 is to allow programs to make optimizations with per-CPU data
83 or for NUMA optimization.
85 Glibc does not provide a wrapper for this system call; call it using
93 argument is unused since Linux 2.6.24.
94 .\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1
95 .\" Author: Ingo Molnar <mingo@elte.hu>
96 .\" Date: Wed Nov 7 18:37:48 2007 +0100
97 .\" x86: ignore the sys_getcpu() tcache parameter
99 if this argument was non-NULL,
100 then it specified a pointer to a caller-allocated buffer in thread-local
101 storage that was used to provide a caching mechanism for
103 Use of the cache could speed
105 calls, at the cost that there was a very small chance that
106 the returned information would be out of date.
107 The caching mechanism was considered to cause problems when
108 migrating threads between CPUs, and so the argument is now ignored.
110 .\" ===== Before kernel 2.6.24: =====
112 .\" is a pointer to a
113 .\" .IR "struct getcpu_cache"
114 .\" that is used as a cache by
116 .\" The caller should put the cache into a thread-local variable
117 .\" if the process is multithreaded,
118 .\" because the cache cannot be shared between different threads.
121 .\" If it is not NULL
123 .\" will use it to speed up operation.
124 .\" The information inside the cache is private to the system call
125 .\" and should not be accessed by the user program.
126 .\" The information placed in the cache can change between kernel releases.
128 .\" When no cache is specified
131 .\" but always retrieve the current CPU and node information.
135 .\" However, the cached information is updated only once per jiffy (see
137 .\" This means that the information could theoretically be out of date,
138 .\" although in practice the scheduler's attempt to maintain
139 .\" soft CPU affinity means that the information is unlikely to change
140 .\" over the course of the caching interval.
143 .BR sched_setaffinity (2),
144 .BR set_mempolicy (2),
145 .BR sched_getcpu (3),