]>
Commit | Line | Data |
---|---|---|
7c4ddad1 | 1 | .\" SPDX-License-Identifier: Linux-man-pages-1-para |
2297bf0e | 2 | .\" |
7c4ddad1 | 3 | .\" This man page is Copyright (C) 2006 Andi Kleen <ak@muc.de>. |
4366109b | 4 | .\" |
80997bc3 | 5 | .\" 2008, mtk, various edits |
4784c377 | 6 | .\" |
4c1c5274 | 7 | .TH getcpu 2 (date) "Linux man-pages (unreleased)" |
80997bc3 MK |
8 | .SH NAME |
9 | getcpu \- determine CPU and NUMA node on which the calling thread is running | |
db24e10d AC |
10 | .SH LIBRARY |
11 | Standard C library | |
8fc3b2cf | 12 | .RI ( libc ", " \-lc ) |
80997bc3 MK |
13 | .SH SYNOPSIS |
14 | .nf | |
c9eec92c MK |
15 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
16 | .B #include <sched.h> | |
c6d039a3 | 17 | .P |
0a0b3f85 AC |
18 | .BI "int getcpu(unsigned int *_Nullable " cpu ", \ |
19 | unsigned int *_Nullable " node ); | |
80997bc3 MK |
20 | .fi |
21 | .SH DESCRIPTION | |
22 | The | |
23 | .BR getcpu () | |
24 | system call identifies the processor and node on which the calling | |
25 | thread or process is currently running and writes them into the | |
26 | integers pointed to by the | |
27 | .I cpu | |
28 | and | |
29 | .I node | |
30 | arguments. | |
31 | The processor is a unique small integer identifying a CPU. | |
32 | The node is a unique small identifier identifying a NUMA node. | |
33 | When either | |
34 | .I cpu | |
35 | or | |
36 | .I node | |
37 | is NULL nothing is written to the respective pointer. | |
c6d039a3 | 38 | .P |
80997bc3 MK |
39 | The information placed in |
40 | .I cpu | |
33a0ccb2 | 41 | is guaranteed to be current only at the time of the call: |
80997bc3 MK |
42 | unless the CPU affinity has been fixed using |
43 | .BR sched_setaffinity (2), | |
44 | the kernel might change the CPU at any time. | |
45 | (Normally this does not happen | |
46 | because the scheduler tries to minimize movements between CPUs to | |
47 | keep caches hot, but it is possible.) | |
0ab8aeec | 48 | The caller must allow for the possibility that the information returned in |
80997bc3 MK |
49 | .I cpu |
50 | and | |
51 | .I node | |
ded312a3 | 52 | is no longer current by the time the call returns. |
47297adb | 53 | .SH RETURN VALUE |
178df36f MF |
54 | On success, 0 is returned. |
55 | On error, \-1 is returned, and | |
56 | .I errno | |
f6a4078b | 57 | is set to indicate the error. |
178df36f MF |
58 | .SH ERRORS |
59 | .TP | |
60 | .B EFAULT | |
61 | Arguments point outside the calling process's address space. | |
3113c7f3 | 62 | .SH STANDARDS |
4131356c AC |
63 | Linux. |
64 | .SH HISTORY | |
65 | Linux 2.6.19 (x86-64 and i386), | |
66 | glibc 2.29. | |
c9eec92c MK |
67 | .\" |
68 | .SS C library/kernel differences | |
69 | The kernel system call has a third argument: | |
c6d039a3 | 70 | .P |
c9eec92c MK |
71 | .in +4n |
72 | .nf | |
73 | .BI "int getcpu(unsigned int *" cpu ", unsigned int *" node , | |
74 | .BI " struct getcpu_cache *" tcache ); | |
75 | .fi | |
76 | .in | |
c6d039a3 | 77 | .P |
80997bc3 MK |
78 | The |
79 | .I tcache | |
c9eec92c MK |
80 | argument is unused since Linux 2.6.24, |
81 | and (when invoking the system call directly) | |
82 | should be specified as NULL, | |
83 | unless portability to Linux 2.6.23 or earlier is required. | |
c6d039a3 | 84 | .P |
80997bc3 MK |
85 | .\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1 |
86 | .\" Author: Ingo Molnar <mingo@elte.hu> | |
87 | .\" Date: Wed Nov 7 18:37:48 2007 +0100 | |
88 | .\" x86: ignore the sys_getcpu() tcache parameter | |
c9eec92c MK |
89 | In Linux 2.6.23 and earlier, if the |
90 | .I tcache | |
91 | argument was non-NULL, | |
80997bc3 MK |
92 | then it specified a pointer to a caller-allocated buffer in thread-local |
93 | storage that was used to provide a caching mechanism for | |
94 | .BR getcpu (). | |
95 | Use of the cache could speed | |
96 | .BR getcpu () | |
97 | calls, at the cost that there was a very small chance that | |
98 | the returned information would be out of date. | |
99 | The caching mechanism was considered to cause problems when | |
100 | migrating threads between CPUs, and so the argument is now ignored. | |
101 | .\" | |
b324e17d | 102 | .\" ===== Before Linux 2.6.24: ===== |
80997bc3 MK |
103 | .\" .I tcache |
104 | .\" is a pointer to a | |
105 | .\" .IR "struct getcpu_cache" | |
106 | .\" that is used as a cache by | |
107 | .\" .BR getcpu (). | |
108 | .\" The caller should put the cache into a thread-local variable | |
109 | .\" if the process is multithreaded, | |
110 | .\" because the cache cannot be shared between different threads. | |
111 | .\" .I tcache | |
112 | .\" can be NULL. | |
113 | .\" If it is not NULL | |
114 | .\" .BR getcpu () | |
115 | .\" will use it to speed up operation. | |
116 | .\" The information inside the cache is private to the system call | |
117 | .\" and should not be accessed by the user program. | |
b324e17d | 118 | .\" The information placed in the cache can change between Linux releases. |
c17a5c8b | 119 | .\" |
80997bc3 MK |
120 | .\" When no cache is specified |
121 | .\" .BR getcpu () | |
122 | .\" will be slower, | |
123 | .\" but always retrieve the current CPU and node information. | |
124 | .\" With a cache | |
125 | .\" .BR getcpu () | |
126 | .\" is faster. | |
33a0ccb2 | 127 | .\" However, the cached information is updated only once per jiffy (see |
80997bc3 MK |
128 | .\" .BR time (7)). |
129 | .\" This means that the information could theoretically be out of date, | |
130 | .\" although in practice the scheduler's attempt to maintain | |
131 | .\" soft CPU affinity means that the information is unlikely to change | |
132 | .\" over the course of the caching interval. | |
4131356c AC |
133 | .SH NOTES |
134 | Linux makes a best effort to make this call as fast as possible. | |
135 | (On some architectures, this is done via an implementation in the | |
136 | .BR vdso (7).) | |
137 | The intention of | |
138 | .BR getcpu () | |
139 | is to allow programs to make optimizations with per-CPU data | |
140 | or for NUMA optimization. | |
80997bc3 | 141 | .SH SEE ALSO |
80997bc3 | 142 | .BR mbind (2), |
f0c34053 | 143 | .BR sched_setaffinity (2), |
80997bc3 | 144 | .BR set_mempolicy (2), |