OSDN Git Service

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