OSDN Git Service

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