]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getcpu.2
SEE ALSO: Add getcpu(2).
[thirdparty/man-pages.git] / man2 / getcpu.2
CommitLineData
80997bc3
MK
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
9getcpu \- 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
18The
19.BR getcpu ()
20system call identifies the processor and node on which the calling
21thread or process is currently running and writes them into the
22integers pointed to by the
23.I cpu
24and
25.I node
26arguments.
27The processor is a unique small integer identifying a CPU.
28The node is a unique small identifier identifying a NUMA node.
29When either
30.I cpu
31or
32.I node
33is NULL nothing is written to the respective pointer.
34
35The third argument to this system call is nowadays unused.
36
37The information placed in
38.I cpu
39is only guaranteed to be current at the time of the call:
40unless the CPU affinity has been fixed using
41.BR sched_setaffinity (2),
42the kernel might change the CPU at any time.
43(Normally this does not happen
44because the scheduler tries to minimize movements between CPUs to
45keep caches hot, but it is possible.)
46The caller must be prepared to handle the situation when
47.I cpu
48and
49.I node
50are no longer the current CPU and node.
51.SH VERSIONS
52.BR getcpu (2)
53was added in kernel 2.6.19 for x86_64 and i386.
54.SH NOTES
55Linux makes a best effort to make this call as fast possible.
56The intention of
57.I getcpu(2)
58is to allow programs to make optimizations with per-CPU data
59or for NUMA optimization.
60
61The
62.I tcache
63argument is unused since Linux 2.6.24.
64.\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1
65.\" Author: Ingo Molnar <mingo@elte.hu>
66.\" Date: Wed Nov 7 18:37:48 2007 +0100
67.\" x86: ignore the sys_getcpu() tcache parameter
68In earlier kernels,
69if this argument was non-NULL,
70then it specified a pointer to a caller-allocated buffer in thread-local
71storage that was used to provide a caching mechanism for
72.BR getcpu ().
73Use of the cache could speed
74.BR getcpu ()
75calls, at the cost that there was a very small chance that
76the returned information would be out of date.
77The caching mechanism was considered to cause problems when
78migrating threads between CPUs, and so the argument is now ignored.
79.\"
80.\" ===== Before kernel 2.6.24: =====
81.\" .I tcache
82.\" is a pointer to a
83.\" .IR "struct getcpu_cache"
84.\" that is used as a cache by
85.\" .BR getcpu ().
86.\" The caller should put the cache into a thread-local variable
87.\" if the process is multithreaded,
88.\" because the cache cannot be shared between different threads.
89.\" .I tcache
90.\" can be NULL.
91.\" If it is not NULL
92.\" .BR getcpu ()
93.\" will use it to speed up operation.
94.\" The information inside the cache is private to the system call
95.\" and should not be accessed by the user program.
96.\" The information placed in the cache can change between kernel releases.
97.\"
98.\" When no cache is specified
99.\" .BR getcpu ()
100.\" will be slower,
101.\" but always retrieve the current CPU and node information.
102.\" With a cache
103.\" .BR getcpu ()
104.\" is faster.
105.\" However, the cached information is only updated once per jiffy (see
106.\" .BR time (7)).
107.\" This means that the information could theoretically be out of date,
108.\" although in practice the scheduler's attempt to maintain
109.\" soft CPU affinity means that the information is unlikely to change
110.\" over the course of the caching interval.
111.SH SEE ALSO
112.\" FIXME(mk) add SEE ALSO entries in other pages, pointing to this page
113.BR mbind (2),
114.BR set_mempolicy (2),
115.BR sched_setaffinity (2)