what is __get_cpu_var() ?

Dave Hylands dhylands at gmail.com
Wed Feb 23 03:22:47 EST 2011


Hi Murali,

On Tue, Feb 22, 2011 at 9:27 PM, Murali N <nalajala.murali at gmail.com> wrote:
> Hi,
> can somebody explain me what "__get_cpu_var()" macro does?
> I try to understand this macro but i couldn't, its representation is weired!!!

get_cpu_var returns the contents of a per-cpu variable.

__get_cpu_var contains the actual machine-dependant implementation. It
looks like all of the architectures use the one in
asm-generic/percpu.h

In general, all of the per-cpu data is gathered together into a
section. Multiple sections are allocated (one per CPU). I think that
the address of the variable is really the offset within the section,
and each allocated section is cache-line aligned. This offset is then
added to the "offset for my cpu" to come up with the final address of
the variable, which is dereferenced as a pointer dereference. There
are lots of extra doo-dads to get around warnings, and to prevent the
linker from producing relocation references for for the variable
access (since it looks like an access of a global variable, but it's
really just doing a game of using the offset of the variable within
the section).

So you could think of it as a very fancy offsetof macro.

There are several other macros involved, perhaps you could be a bit
more specific about your request?

Dave Hylands



More information about the Kernelnewbies mailing list