]> git.ipfire.org Git - thirdparty/man-pages.git/blame_incremental - man2/getcpu.2
console_codes.4, inode.7: srcfix
[thirdparty/man-pages.git] / man2 / getcpu.2
... / ...
CommitLineData
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 2019-03-06 "Linux" "Linux Programmer's Manual"
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>
18.PP
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.
39.PP
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).
43.PP
44The information placed in
45.I cpu
46is guaranteed to be current only at the time of the call:
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.)
53The caller must allow for the possibility that the information returned in
54.I cpu
55and
56.I node
57is no longer current by the time the call returns.
58.SH RETURN VALUE
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.
67.SH VERSIONS
68.BR getcpu ()
69was added in kernel 2.6.19 for x86-64 and i386.
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).)
74.SH CONFORMING TO
75.BR getcpu ()
76is Linux-specific.
77.SH NOTES
78Linux makes a best effort to make this call as fast as possible.
79(On some architectures, this is done via an implementation in the
80.BR vdso (7).)
81The intention of
82.BR getcpu ()
83is to allow programs to make optimizations with per-CPU data
84or for NUMA optimization.
85.PP
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.
122.\"
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.
130.\" However, the cached information is updated only once per jiffy (see
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
137.BR mbind (2),
138.BR sched_setaffinity (2),
139.BR set_mempolicy (2),
140.BR sched_getcpu (3),
141.BR cpuset (7),
142.BR vdso (7)