]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getcpu.2
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man2 / getcpu.2
1 .\" This man page is Copyright (C) 2006 Andi Kleen <ak@muc.de>.
2 .\"
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.
8 .\" %%%LICENSE_END
9 .\"
10 .\" 2008, mtk, various edits
11 .\"
12 .TH getcpu 2 (date) "Linux man-pages (unreleased)"
13 .SH NAME
14 getcpu \- determine CPU and NUMA node on which the calling thread is running
15 .SH LIBRARY
16 Standard C library
17 .RI ( libc ", " \-lc )
18 .SH SYNOPSIS
19 .nf
20 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
21 .B #include <sched.h>
22 .PP
23 .BI "int getcpu(unsigned int *" cpu ", unsigned int *" node );
24 .fi
25 .SH DESCRIPTION
26 The
27 .BR getcpu ()
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
31 .I cpu
32 and
33 .I node
34 arguments.
35 The processor is a unique small integer identifying a CPU.
36 The node is a unique small identifier identifying a NUMA node.
37 When either
38 .I cpu
39 or
40 .I node
41 is NULL nothing is written to the respective pointer.
42 .PP
43 The information placed in
44 .I cpu
45 is guaranteed to be current only at the time of the call:
46 unless the CPU affinity has been fixed using
47 .BR sched_setaffinity (2),
48 the kernel might change the CPU at any time.
49 (Normally this does not happen
50 because the scheduler tries to minimize movements between CPUs to
51 keep caches hot, but it is possible.)
52 The caller must allow for the possibility that the information returned in
53 .I cpu
54 and
55 .I node
56 is no longer current by the time the call returns.
57 .SH RETURN VALUE
58 On success, 0 is returned.
59 On error, \-1 is returned, and
60 .I errno
61 is set to indicate the error.
62 .SH ERRORS
63 .TP
64 .B EFAULT
65 Arguments point outside the calling process's address space.
66 .SH VERSIONS
67 .BR getcpu ()
68 was added in kernel 2.6.19 for x86-64 and i386.
69 Library support was added in glibc 2.29
70 (Earlier glibc versions did not provide a wrapper for this system call,
71 necessitating the use of
72 .BR syscall (2).)
73 .SH STANDARDS
74 .BR getcpu ()
75 is Linux-specific.
76 .SH NOTES
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
79 .BR vdso (7).)
80 The intention of
81 .BR getcpu ()
82 is to allow programs to make optimizations with per-CPU data
83 or for NUMA optimization.
84 .\"
85 .SS C library/kernel differences
86 The kernel system call has a third argument:
87 .PP
88 .in +4n
89 .nf
90 .BI "int getcpu(unsigned int *" cpu ", unsigned int *" node ,
91 .BI " struct getcpu_cache *" tcache );
92 .fi
93 .in
94 .PP
95 The
96 .I tcache
97 argument is unused since Linux 2.6.24,
98 and (when invoking the system call directly)
99 should be specified as NULL,
100 unless portability to Linux 2.6.23 or earlier is required.
101 .PP
102 .\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1
103 .\" Author: Ingo Molnar <mingo@elte.hu>
104 .\" Date: Wed Nov 7 18:37:48 2007 +0100
105 .\" x86: ignore the sys_getcpu() tcache parameter
106 In Linux 2.6.23 and earlier, if the
107 .I tcache
108 argument was non-NULL,
109 then it specified a pointer to a caller-allocated buffer in thread-local
110 storage that was used to provide a caching mechanism for
111 .BR getcpu ().
112 Use of the cache could speed
113 .BR getcpu ()
114 calls, at the cost that there was a very small chance that
115 the returned information would be out of date.
116 The caching mechanism was considered to cause problems when
117 migrating threads between CPUs, and so the argument is now ignored.
118 .\"
119 .\" ===== Before kernel 2.6.24: =====
120 .\" .I tcache
121 .\" is a pointer to a
122 .\" .IR "struct getcpu_cache"
123 .\" that is used as a cache by
124 .\" .BR getcpu ().
125 .\" The caller should put the cache into a thread-local variable
126 .\" if the process is multithreaded,
127 .\" because the cache cannot be shared between different threads.
128 .\" .I tcache
129 .\" can be NULL.
130 .\" If it is not NULL
131 .\" .BR getcpu ()
132 .\" will use it to speed up operation.
133 .\" The information inside the cache is private to the system call
134 .\" and should not be accessed by the user program.
135 .\" The information placed in the cache can change between kernel releases.
136 .\"
137 .\" When no cache is specified
138 .\" .BR getcpu ()
139 .\" will be slower,
140 .\" but always retrieve the current CPU and node information.
141 .\" With a cache
142 .\" .BR getcpu ()
143 .\" is faster.
144 .\" However, the cached information is updated only once per jiffy (see
145 .\" .BR time (7)).
146 .\" This means that the information could theoretically be out of date,
147 .\" although in practice the scheduler's attempt to maintain
148 .\" soft CPU affinity means that the information is unlikely to change
149 .\" over the course of the caching interval.
150 .SH SEE ALSO
151 .BR mbind (2),
152 .BR sched_setaffinity (2),
153 .BR set_mempolicy (2),
154 .BR sched_getcpu (3),
155 .BR cpuset (7),
156 .BR vdso (7)