222 lines
4.9 KiB
HTML
222 lines
4.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETCPU</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETCPU</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
getcpu - determine CPU and NUMA node on which the calling thread is running
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/linux/getcpu.h">linux/getcpu.h</A>></B>
|
|
|
|
<B>int getcpu(unsigned *</B><I>cpu</I><B>, unsigned *</B><I>node</I><B>, struct getcpu_cache *</B><I>tcache</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>getcpu</B>()
|
|
|
|
system call identifies the processor and node on which the calling
|
|
thread or process is currently running and writes them into the
|
|
integers pointed to by the
|
|
<I>cpu</I>
|
|
|
|
and
|
|
<I>node</I>
|
|
|
|
arguments.
|
|
The processor is a unique small integer identifying a CPU.
|
|
The node is a unique small identifier identifying a NUMA node.
|
|
When either
|
|
<I>cpu</I>
|
|
|
|
or
|
|
<I>node</I>
|
|
|
|
is NULL nothing is written to the respective pointer.
|
|
<P>
|
|
|
|
The third argument to this system call is nowadays unused,
|
|
and should be specified as NULL
|
|
unless portability to Linux 2.6.23 or earlier is required (see NOTES).
|
|
<P>
|
|
|
|
The information placed in
|
|
<I>cpu</I>
|
|
|
|
is guaranteed to be current only at the time of the call:
|
|
unless the CPU affinity has been fixed using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sched_setaffinity">sched_setaffinity</A></B>(2),
|
|
|
|
the kernel might change the CPU at any time.
|
|
(Normally this does not happen
|
|
because the scheduler tries to minimize movements between CPUs to
|
|
keep caches hot, but it is possible.)
|
|
The caller must allow for the possibility that the information returned in
|
|
<I>cpu</I>
|
|
|
|
and
|
|
<I>node</I>
|
|
|
|
is no longer current by the time the call returns.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, 0 is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
Arguments point outside the calling process's address space.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>getcpu</B>()
|
|
|
|
was added in kernel 2.6.19 for x86-64 and i386.
|
|
Library support was added in glibc 2.29
|
|
(Earlier glibc versions did not provide a wrapper for this system call,
|
|
necessitating the use of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).)
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>getcpu</B>()
|
|
|
|
is Linux-specific.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Linux makes a best effort to make this call as fast as possible.
|
|
(On some architectures, this is done via an implementation in the
|
|
<B><A HREF="/cgi-bin/man/man2html?7+vdso">vdso</A></B>(7).)
|
|
|
|
The intention of
|
|
<B>getcpu</B>()
|
|
|
|
is to allow programs to make optimizations with per-CPU data
|
|
or for NUMA optimization.
|
|
<P>
|
|
|
|
The
|
|
<I>tcache</I>
|
|
|
|
argument is unused since Linux 2.6.24.
|
|
|
|
|
|
|
|
|
|
In earlier kernels,
|
|
if this argument was non-NULL,
|
|
then it specified a pointer to a caller-allocated buffer in thread-local
|
|
storage that was used to provide a caching mechanism for
|
|
<B>getcpu</B>().
|
|
|
|
Use of the cache could speed
|
|
<B>getcpu</B>()
|
|
|
|
calls, at the cost that there was a very small chance that
|
|
the returned information would be out of date.
|
|
The caching mechanism was considered to cause problems when
|
|
migrating threads between CPUs, and so the argument is now ignored.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mbind">mbind</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sched_setaffinity">sched_setaffinity</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+set_mempolicy">set_mempolicy</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sched_getcpu">sched_getcpu</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+cpuset">cpuset</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+vdso">vdso</A></B>(7)
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="11"><A HREF="#lbAK">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:32 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|