There are broadly two types of per-CPU variables: statically and dynamically allocated ones. Statically allocated per-CPU variables are allocated at compile time itself, typically via one of these macros: DEFINE_PER_CPU or DECLARE_PER_CPU. Using the DEFINE one allows you to allocate and initialize the variable. Here's an example of allocating a single integer as a per-CPU variable:
DEFINE_PER_CPU(int, pcpa); // signature: DEFINE_PER_CPU(type, name)
Now, on a system with, say, four CPU cores, it would conceptually appear like this at initialization:
(The actual implementation is quite a bit more complex than this, of course; please refer to the Further reading section of this chapter to see more on the internal implementation.)
In a nutshell, using per-CPU variables...