[lkml]   [2008]   [Jul]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjectgetcpu(2) man page
Hi Andi,

Long ago, when I ran out of time, things stalled on incorporating a getcpu.2 man page that you
wrote ino man-pages. There were still some open questions that I wanted to get sorted before
releasing the page. Could you take a look at the FIXME(ak)s below please?



.\" This man page is Copyright (C) 2006 Andi Kleen <>.
.\" Permission is granted to distribute possibly modified copies
.\" of this page provided the header is included verbatim,
.\" and in case of nontrivial modification author and date
.\" of the modification is added to the header.
.TH getcpu 2 2008-06-02 "Linux" "Linux Programmer's Manual"
getcpu \- determine CPU and NUMA node on which the calling thread is running
.B #include <linux/getcpu.h>
.BI "int getcpu(unsigned *" cpu ", unsigned *" node \
", struct getcpu_cache *" tcache );
.BR getcpu ()
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 node
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 node
is NULL nothing is written to the respective pointer.
.I tcache
is a pointer to a
.I struct getcpu_cache.
The caller should put the cache into a thread
local variable if the process is multithreaded because the cache
cannot be shared between different threads.
.I tcache
can be NULL.
If it is not NULL
.BR getcpu ()
will use it to speed up operation.
The information inside the cache is private to the system call
and should not be accessed by the user program.
The information placed in the cache can change between kernel releases.

.\" FIXME(ak) If the following formulation is correct, I think it would
.\" be better to substitute it instead of the next sentence:
.\" The information placed in \fIcpu\fP is only guaranteed to be
.\" current at the time of the call: ...
This information is only a hint: unless the CPU affinity
has been fixed using
.BR sched_setaffinity (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.)
.\" FIXME(ak) Can you explain what you mean in the next sentence when
.\" you say "recover"
The caller has to properly recover from the case when
.I cpu
.I node
are not the current CPU and node anymore.
.\" FIXME(ak) In the following, what precisely do you mean by "advisory"?
.\" It is not really clear to me whether you mean the information
.\" may not be "true", or whether you are just reiterating the point that
.\" the CPU/node might already have changed by the time the call returns.
All information returned by
.I getcpu(2)
is just advisory and not a guarantee.

When no cache is specified
.BR getcpu ()
will be slower, but always retrieve the current state.
With a cache
.\" FIXME(ak) what does the phrase "but might query the current state
.\" only during a short implementation specific interval" mean?
it will be faster, but might query the current state only during
a short implementation specific interval.

Linux makes a best effort to make this call as fast possible. The
intention of
.I getcpu(2)
is to allow programs to make optimizations with per-CPU data
or for NUMA optimization.
.BR getcpu (2)
was added in 2.6.19 for x86_64 and i386.
.BR mbind (2),
.BR set_mempolicy (2),
.BR sched_setaffinity (2)

 \ /
  Last update: 2008-07-02 21:13    [W:0.052 / U:0.572 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site