what's with "get_cpu_ptr" and "put_cpu_ptr"?

Robert P. J. Day rpjday at crashcourse.ca
Sun Sep 30 10:35:20 EDT 2012


  at the moment, i'm working my way through numerous kernel topics in
aid of tracking updates for LKD3 and making personal notes.  for
instance, here's my wiki page for per-CPU variables:

http://www.crashcourse.ca/wiki/index.php/Per-CPU_variables

  as you can see, lots of links to docs and tutorials and excerpts
from header and source files, just for my own benefit for the time
being and to be organized later.

  but toward the end, you can read where i'm a bit puzzled by two
macros i ran across just this morning that i had never seen before,
and defined in <linux/percpu.h>:

#define get_cpu_ptr(var) ({                             \
        preempt_disable();                              \
        this_cpu_ptr(var); })

#define put_cpu_ptr(var) do {                           \
        (void)(var);                                    \
        preempt_enable();                               \
} while (0)

  i don't recall ever seeing a reference to those two macros anywhere
i've read, and a tree-wide search shows *very* few uses:

$ grep -rw get_cpu_ptr *
include/linux/percpu.h:#define get_cpu_ptr(var) ({				\
kernel/events/core.c:		cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
kernel/events/core.c:		cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
kernel/events/core.c:		cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
$ grep -rw put_cpu_ptr *
include/linux/percpu.h:#define put_cpu_ptr(var) do {				\
kernel/events/core.c:		put_cpu_ptr(pmu->pmu_cpu_context);
kernel/events/core.c:		put_cpu_ptr(pmu->pmu_cpu_context);
kernel/events/core.c:		put_cpu_ptr(pmu->pmu_cpu_context);
$

  that's it, that appears to be the extent of usage in the entire
kernel source tree.  i'm sure i'll figure them out given a bit more
time, but anyone want to clarify the purpose of those macros?  and
perhaps whether they're rarely used because normal kernel programmers
shouldn't be using them?  thanks.

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================



More information about the Kernelnewbies mailing list