]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getcpu.2
ldd.1, capget.2, clone.2, create_module.2, fallocate.2, futex.2, get_kernel_syms...
[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 .\" %%%END_LICENSE
9 .\" 2008, mtk, various edits
10 .TH GETCPU 2 2012-07-13 "Linux" "Linux Programmer's Manual"
11 .SH NAME
12 getcpu \- determine CPU and NUMA node on which the calling thread is running
13 .SH SYNOPSIS
14 .nf
15 .B #include <linux/getcpu.h>
16 .sp
17 .BI "int getcpu(unsigned *" cpu ", unsigned *" node \
18 ", struct getcpu_cache *" tcache );
19 .fi
20
21 .IR Note :
22 There is no glibc wrapper for this system call; see NOTES.
23 .SH DESCRIPTION
24 The
25 .BR getcpu ()
26 system call identifies the processor and node on which the calling
27 thread or process is currently running and writes them into the
28 integers pointed to by the
29 .I cpu
30 and
31 .I node
32 arguments.
33 The processor is a unique small integer identifying a CPU.
34 The node is a unique small identifier identifying a NUMA node.
35 When either
36 .I cpu
37 or
38 .I node
39 is NULL nothing is written to the respective pointer.
40
41 The third argument to this system call is nowadays unused (see NOTES).
42
43 The information placed in
44 .I cpu
45 is only guaranteed to be current 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 appropriately.
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 .SH CONFORMING TO
70 .BR getcpu ()
71 is Linux specific.
72 .SH NOTES
73 Linux makes a best effort to make this call as fast possible.
74 The intention of
75 .BR getcpu ()
76 is to allow programs to make optimizations with per-CPU data
77 or for NUMA optimization.
78
79 Glibc does not provide a wrapper for this system call; call it using
80 .BR syscall (2);
81 or use
82 .BR sched_getcpu (3)
83 instead.
84
85 The
86 .I tcache
87 argument is unused since Linux 2.6.24.
88 .\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1
89 .\" Author: Ingo Molnar <mingo@elte.hu>
90 .\" Date: Wed Nov 7 18:37:48 2007 +0100
91 .\" x86: ignore the sys_getcpu() tcache parameter
92 In earlier kernels,
93 if this argument was non-NULL,
94 then it specified a pointer to a caller-allocated buffer in thread-local
95 storage that was used to provide a caching mechanism for
96 .BR getcpu ().
97 Use of the cache could speed
98 .BR getcpu ()
99 calls, at the cost that there was a very small chance that
100 the returned information would be out of date.
101 The caching mechanism was considered to cause problems when
102 migrating threads between CPUs, and so the argument is now ignored.
103 .\"
104 .\" ===== Before kernel 2.6.24: =====
105 .\" .I tcache
106 .\" is a pointer to a
107 .\" .IR "struct getcpu_cache"
108 .\" that is used as a cache by
109 .\" .BR getcpu ().
110 .\" The caller should put the cache into a thread-local variable
111 .\" if the process is multithreaded,
112 .\" because the cache cannot be shared between different threads.
113 .\" .I tcache
114 .\" can be NULL.
115 .\" If it is not NULL
116 .\" .BR getcpu ()
117 .\" will use it to speed up operation.
118 .\" The information inside the cache is private to the system call
119 .\" and should not be accessed by the user program.
120 .\" The information placed in the cache can change between kernel releases.
121 .\"
122 .\" When no cache is specified
123 .\" .BR getcpu ()
124 .\" will be slower,
125 .\" but always retrieve the current CPU and node information.
126 .\" With a cache
127 .\" .BR getcpu ()
128 .\" is faster.
129 .\" However, the cached information is only updated once per jiffy (see
130 .\" .BR time (7)).
131 .\" This means that the information could theoretically be out of date,
132 .\" although in practice the scheduler's attempt to maintain
133 .\" soft CPU affinity means that the information is unlikely to change
134 .\" over the course of the caching interval.
135 .SH SEE ALSO
136 .BR mbind (2),
137 .BR sched_setaffinity (2),
138 .BR set_mempolicy (2),
139 .BR sched_getcpu (3),
140 .BR cpuset (7)