By Jonathan Corbet
December 16, 2009
Per-CPU variables are a performance-improving technology. They allow
processors to work with data without having to worry about locking or cache
contention. One would want these operations to be well optimized, but, as
it turns out, they can be improved; Tejun Heo and Christoph Lameter have
done just that for
2.6.33. In the process, they have changed the way developers work with these
variables.
There is a set of new operations:
this_cpu_read(scalar);
this_cpu_write(scalar, value);
this_cpu_add(scalar, value);
this_cpu_sub(scalar, value);
this_cpu_inc(scalar);
this_cpu_dec(scalar);
this_cpu_and(scalar, value);
this_cpu_or(scalar, value);
this_cpu_xor(scalar, value);
In each case, scalar is either a per-CPU variable obtained with a
new allocator or a static per-CPU variable as obtained from
per_cpu_var(). All of them are atomic, in that the operation will
not be interrupted part-way through on the current processor. It is not
necessary to call put_cpu() after using these operations.
See, for example, the VM
statistics conversion for an example of how operations on per-CPU
variables change under the new scheme.
(
Log in to post comments)