A key question, of course, is how exactly can you access (read) and update (write) to per-CPU variables? The kernel provides several helper routines to do so; let's take a simple example to understand how. We define a single integer per-CPU variable, and at a later point in time, we want to access and print its current value. You should realize that, being per-CPU, the value retrieved will be auto-calculated based on the CPU core the code is currently running on; in other words, if the following code is running on core 1, then in effect, the pcpa[1] value is fetched (it's not done exactly like this; this is just conceptual):
DEFINE_PER_CPU(int, pcpa);
int val;
[ ... ]
val = get_cpu_var(pcpa);
pr_info("cpu0: pcpa = %+d\n", val);
put_cpu_var(pcpa);
The pair of {get,put}_cpu_var() macros allows us to safely retrieve or modify the per-CPU value of the given per-CPU variable (its parameter...