]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getcpu.2
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man2 / getcpu.2
CommitLineData
80997bc3 1.\" This man page is Copyright (C) 2006 Andi Kleen <ak@muc.de>.
2297bf0e 2.\"
00acdba1 3.\" %%%LICENSE_START(VERBATIM_ONE_PARA)
80997bc3
MK
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.
8ff7380d 8.\" %%%LICENSE_END
4366109b 9.\"
80997bc3 10.\" 2008, mtk, various edits
4784c377 11.\"
4c1c5274 12.TH getcpu 2 (date) "Linux man-pages (unreleased)"
80997bc3
MK
13.SH NAME
14getcpu \- determine CPU and NUMA node on which the calling thread is running
db24e10d
AC
15.SH LIBRARY
16Standard C library
8fc3b2cf 17.RI ( libc ", " \-lc )
80997bc3
MK
18.SH SYNOPSIS
19.nf
c9eec92c
MK
20.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
21.B #include <sched.h>
68e4db0a 22.PP
c9eec92c 23.BI "int getcpu(unsigned int *" cpu ", unsigned int *" node );
80997bc3
MK
24.fi
25.SH DESCRIPTION
26The
27.BR getcpu ()
28system call identifies the processor and node on which the calling
29thread or process is currently running and writes them into the
30integers pointed to by the
31.I cpu
32and
33.I node
34arguments.
35The processor is a unique small integer identifying a CPU.
36The node is a unique small identifier identifying a NUMA node.
37When either
38.I cpu
39or
40.I node
41is NULL nothing is written to the respective pointer.
efeece04 42.PP
80997bc3
MK
43The information placed in
44.I cpu
33a0ccb2 45is guaranteed to be current only at the time of the call:
80997bc3
MK
46unless the CPU affinity has been fixed using
47.BR sched_setaffinity (2),
48the kernel might change the CPU at any time.
49(Normally this does not happen
50because the scheduler tries to minimize movements between CPUs to
51keep caches hot, but it is possible.)
0ab8aeec 52The caller must allow for the possibility that the information returned in
80997bc3
MK
53.I cpu
54and
55.I node
ded312a3 56is no longer current by the time the call returns.
47297adb 57.SH RETURN VALUE
178df36f
MF
58On success, 0 is returned.
59On error, \-1 is returned, and
60.I errno
f6a4078b 61is set to indicate the error.
178df36f
MF
62.SH ERRORS
63.TP
64.B EFAULT
65Arguments point outside the calling process's address space.
80997bc3 66.SH VERSIONS
90fe01c5 67.BR getcpu ()
9ea5bc66 68was added in kernel 2.6.19 for x86-64 and i386.
d8be53ac
MK
69Library support was added in glibc 2.29
70(Earlier glibc versions did not provide a wrapper for this system call,
71necessitating the use of
72.BR syscall (2).)
3113c7f3 73.SH STANDARDS
90fe01c5 74.BR getcpu ()
76c637e1 75is Linux-specific.
80997bc3 76.SH NOTES
f55912a9 77Linux makes a best effort to make this call as fast as possible.
5f963653
MK
78(On some architectures, this is done via an implementation in the
79.BR vdso (7).)
80997bc3 80The intention of
90fe01c5 81.BR getcpu ()
80997bc3
MK
82is to allow programs to make optimizations with per-CPU data
83or for NUMA optimization.
c9eec92c
MK
84.\"
85.SS C library/kernel differences
86The 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
efeece04 94.PP
80997bc3
MK
95The
96.I tcache
c9eec92c
MK
97argument is unused since Linux 2.6.24,
98and (when invoking the system call directly)
99should be specified as NULL,
100unless portability to Linux 2.6.23 or earlier is required.
101.PP
80997bc3
MK
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
c9eec92c
MK
106In Linux 2.6.23 and earlier, if the
107.I tcache
108argument was non-NULL,
80997bc3
MK
109then it specified a pointer to a caller-allocated buffer in thread-local
110storage that was used to provide a caching mechanism for
111.BR getcpu ().
112Use of the cache could speed
113.BR getcpu ()
114calls, at the cost that there was a very small chance that
115the returned information would be out of date.
116The caching mechanism was considered to cause problems when
117migrating 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.
c17a5c8b 136.\"
80997bc3
MK
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.
33a0ccb2 144.\" However, the cached information is updated only once per jiffy (see
80997bc3
MK
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
80997bc3 151.BR mbind (2),
f0c34053 152.BR sched_setaffinity (2),
80997bc3 153.BR set_mempolicy (2),