]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getcpu.2
sched_setattr.2: tfix
[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.\"
9ba01802 12.TH GETCPU 2 2019-03-06 "Linux" "Linux Programmer's Manual"
80997bc3
MK
13.SH NAME
14getcpu \- determine CPU and NUMA node on which the calling thread is running
15.SH SYNOPSIS
16.nf
17.B #include <linux/getcpu.h>
68e4db0a 18.PP
80997bc3
MK
19.BI "int getcpu(unsigned *" cpu ", unsigned *" node \
20", struct getcpu_cache *" tcache );
21.fi
22.SH DESCRIPTION
23The
24.BR getcpu ()
25system call identifies the processor and node on which the calling
26thread or process is currently running and writes them into the
27integers pointed to by the
28.I cpu
29and
30.I node
31arguments.
32The processor is a unique small integer identifying a CPU.
33The node is a unique small identifier identifying a NUMA node.
34When either
35.I cpu
36or
37.I node
38is NULL nothing is written to the respective pointer.
efeece04 39.PP
a8956139
MK
40The third argument to this system call is nowadays unused,
41and should be specified as NULL
42unless portability to Linux 2.6.23 or earlier is required (see NOTES).
efeece04 43.PP
80997bc3
MK
44The information placed in
45.I cpu
33a0ccb2 46is guaranteed to be current only at the time of the call:
80997bc3
MK
47unless the CPU affinity has been fixed using
48.BR sched_setaffinity (2),
49the kernel might change the CPU at any time.
50(Normally this does not happen
51because the scheduler tries to minimize movements between CPUs to
52keep caches hot, but it is possible.)
0ab8aeec 53The caller must allow for the possibility that the information returned in
80997bc3
MK
54.I cpu
55and
56.I node
ded312a3 57is no longer current by the time the call returns.
47297adb 58.SH RETURN VALUE
178df36f
MF
59On success, 0 is returned.
60On error, \-1 is returned, and
61.I errno
62is set appropriately.
63.SH ERRORS
64.TP
65.B EFAULT
66Arguments point outside the calling process's address space.
80997bc3 67.SH VERSIONS
90fe01c5 68.BR getcpu ()
9ea5bc66 69was added in kernel 2.6.19 for x86-64 and i386.
d8be53ac
MK
70Library support was added in glibc 2.29
71(Earlier glibc versions did not provide a wrapper for this system call,
72necessitating the use of
73.BR syscall (2).)
90fe01c5
MK
74.SH CONFORMING TO
75.BR getcpu ()
76c637e1 76is Linux-specific.
80997bc3 77.SH NOTES
f55912a9 78Linux makes a best effort to make this call as fast as possible.
5f963653
MK
79(On some architectures, this is done via an implementation in the
80.BR vdso (7).)
80997bc3 81The intention of
90fe01c5 82.BR getcpu ()
80997bc3
MK
83is to allow programs to make optimizations with per-CPU data
84or for NUMA optimization.
efeece04 85.PP
80997bc3
MK
86The
87.I tcache
88argument is unused since Linux 2.6.24.
89.\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1
90.\" Author: Ingo Molnar <mingo@elte.hu>
91.\" Date: Wed Nov 7 18:37:48 2007 +0100
92.\" x86: ignore the sys_getcpu() tcache parameter
93In earlier kernels,
94if this argument was non-NULL,
95then it specified a pointer to a caller-allocated buffer in thread-local
96storage that was used to provide a caching mechanism for
97.BR getcpu ().
98Use of the cache could speed
99.BR getcpu ()
100calls, at the cost that there was a very small chance that
101the returned information would be out of date.
102The caching mechanism was considered to cause problems when
103migrating threads between CPUs, and so the argument is now ignored.
104.\"
105.\" ===== Before kernel 2.6.24: =====
106.\" .I tcache
107.\" is a pointer to a
108.\" .IR "struct getcpu_cache"
109.\" that is used as a cache by
110.\" .BR getcpu ().
111.\" The caller should put the cache into a thread-local variable
112.\" if the process is multithreaded,
113.\" because the cache cannot be shared between different threads.
114.\" .I tcache
115.\" can be NULL.
116.\" If it is not NULL
117.\" .BR getcpu ()
118.\" will use it to speed up operation.
119.\" The information inside the cache is private to the system call
120.\" and should not be accessed by the user program.
121.\" The information placed in the cache can change between kernel releases.
c17a5c8b 122.\"
80997bc3
MK
123.\" When no cache is specified
124.\" .BR getcpu ()
125.\" will be slower,
126.\" but always retrieve the current CPU and node information.
127.\" With a cache
128.\" .BR getcpu ()
129.\" is faster.
33a0ccb2 130.\" However, the cached information is updated only once per jiffy (see
80997bc3
MK
131.\" .BR time (7)).
132.\" This means that the information could theoretically be out of date,
133.\" although in practice the scheduler's attempt to maintain
134.\" soft CPU affinity means that the information is unlikely to change
135.\" over the course of the caching interval.
136.SH SEE ALSO
80997bc3 137.BR mbind (2),
f0c34053 138.BR sched_setaffinity (2),
80997bc3 139.BR set_mempolicy (2),