]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getcpu.2
getcpu.2, sendfile.2, cmsg.3, rtnetlink.3, arp.7, ddp.7, fifo.7, icmp.7, ip.7, ipv6...
[thirdparty/man-pages.git] / man2 / getcpu.2
1 .\" This man page is Copyright (C) 2006 Andi Kleen <ak@muc.de>.
2 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
3 .\" Permission is granted to distribute possibly modified copies
4 .\" of this page provided the header is included verbatim,
5 .\" and in case of nontrivial modification author and date
6 .\" of the modification is added to the header.
7 .\" %%%END_LICENSE
8 .\" 2008, mtk, various edits
9 .TH GETCPU 2 2012-07-13 "Linux" "Linux Programmer's Manual"
10 .SH NAME
11 getcpu \- determine CPU and NUMA node on which the calling thread is running
12 .SH SYNOPSIS
13 .nf
14 .B #include <linux/getcpu.h>
15 .sp
16 .BI "int getcpu(unsigned *" cpu ", unsigned *" node \
17 ", struct getcpu_cache *" tcache );
18 .fi
19
20 .IR Note :
21 There is no glibc wrapper for this system call; see NOTES.
22 .SH DESCRIPTION
23 The
24 .BR getcpu ()
25 system call identifies the processor and node on which the calling
26 thread or process is currently running and writes them into the
27 integers pointed to by the
28 .I cpu
29 and
30 .I node
31 arguments.
32 The processor is a unique small integer identifying a CPU.
33 The node is a unique small identifier identifying a NUMA node.
34 When either
35 .I cpu
36 or
37 .I node
38 is NULL nothing is written to the respective pointer.
39
40 The third argument to this system call is nowadays unused (see NOTES).
41
42 The information placed in
43 .I cpu
44 is only guaranteed to be current at the time of the call:
45 unless the CPU affinity has been fixed using
46 .BR sched_setaffinity (2),
47 the kernel might change the CPU at any time.
48 (Normally this does not happen
49 because the scheduler tries to minimize movements between CPUs to
50 keep caches hot, but it is possible.)
51 The caller must allow for the possibility that the information returned in
52 .I cpu
53 and
54 .I node
55 is no longer current by the time the call returns.
56 .SH RETURN VALUE
57 On success, 0 is returned.
58 On error, \-1 is returned, and
59 .I errno
60 is set appropriately.
61 .SH ERRORS
62 .TP
63 .B EFAULT
64 Arguments point outside the calling process's address space.
65 .SH VERSIONS
66 .BR getcpu ()
67 was added in kernel 2.6.19 for x86_64 and i386.
68 .SH CONFORMING TO
69 .BR getcpu ()
70 is Linux specific.
71 .SH NOTES
72 Linux makes a best effort to make this call as fast possible.
73 The intention of
74 .BR getcpu ()
75 is to allow programs to make optimizations with per-CPU data
76 or for NUMA optimization.
77
78 Glibc does not provide a wrapper for this system call; call it using
79 .BR syscall (2);
80 or use
81 .BR sched_getcpu (3)
82 instead.
83
84 The
85 .I tcache
86 argument is unused since Linux 2.6.24.
87 .\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1
88 .\" Author: Ingo Molnar <mingo@elte.hu>
89 .\" Date: Wed Nov 7 18:37:48 2007 +0100
90 .\" x86: ignore the sys_getcpu() tcache parameter
91 In earlier kernels,
92 if this argument was non-NULL,
93 then it specified a pointer to a caller-allocated buffer in thread-local
94 storage that was used to provide a caching mechanism for
95 .BR getcpu ().
96 Use of the cache could speed
97 .BR getcpu ()
98 calls, at the cost that there was a very small chance that
99 the returned information would be out of date.
100 The caching mechanism was considered to cause problems when
101 migrating threads between CPUs, and so the argument is now ignored.
102 .\"
103 .\" ===== Before kernel 2.6.24: =====
104 .\" .I tcache
105 .\" is a pointer to a
106 .\" .IR "struct getcpu_cache"
107 .\" that is used as a cache by
108 .\" .BR getcpu ().
109 .\" The caller should put the cache into a thread-local variable
110 .\" if the process is multithreaded,
111 .\" because the cache cannot be shared between different threads.
112 .\" .I tcache
113 .\" can be NULL.
114 .\" If it is not NULL
115 .\" .BR getcpu ()
116 .\" will use it to speed up operation.
117 .\" The information inside the cache is private to the system call
118 .\" and should not be accessed by the user program.
119 .\" The information placed in the cache can change between kernel releases.
120 .\"
121 .\" When no cache is specified
122 .\" .BR getcpu ()
123 .\" will be slower,
124 .\" but always retrieve the current CPU and node information.
125 .\" With a cache
126 .\" .BR getcpu ()
127 .\" is faster.
128 .\" However, the cached information is only updated once per jiffy (see
129 .\" .BR time (7)).
130 .\" This means that the information could theoretically be out of date,
131 .\" although in practice the scheduler's attempt to maintain
132 .\" soft CPU affinity means that the information is unlikely to change
133 .\" over the course of the caching interval.
134 .SH SEE ALSO
135 .BR mbind (2),
136 .BR sched_setaffinity (2),
137 .BR set_mempolicy (2),
138 .BR sched_getcpu (3),
139 .BR cpuset (7)