Well this is an improvement and may be ok if the preemption is disabled at
this point. There is another possibility here to use this_cpu_read/add/inc
instead of determining the pointer to the local cpu first and then
performing operations on the fields. The pointer relocation with
this_cpu_xxx ops is implicit in the instructions and safe against changing
of processors. It would also save us the determination of a pointer to the
current cpus stats structure.
Well this is an improvement and may be ok if the preemption is disabled at
this point. There is another possibility here to use this_cpu_read/add/inc
instead of determining the pointer to the local cpu first and then
performing operations on the fields. The pointer relocation with
this_cpu_xxx ops is implicit in the instructions and safe against changing
of processors. It would also save us the determination of a pointer to the
current cpus stats structure.
yes, this_cpu_ptr just locate the point to current cpu per-cpu data domain.
and then operating [read/write/inc/sub] fields of this per-cpu variable
maybe on other cpu because task is rescheduled for preemption, interrupt.
But for different field in same per-cpu variable, how to guarantee n_missed
and n_hit are from same cpu?
this_cpu_read(dp->stats_percpu->n_missed);
[processor changed]
this_cpu_read(dp->stats_percpu->n_hit);
In addition, following usage of per_cpu_ptr can be replaced by this_cpu_read.
cpu=get_cpu()
....
*per_cpu_ptr(p,cpu)
....
....
put_cpu()
From: Christoph Lameter <hidden> Date: 2012-11-01 14:33:49
On Thu, 1 Nov 2012, Shan Wei wrote:
But for different field in same per-cpu variable, how to guarantee n_missed
and n_hit are from same cpu?
this_cpu_read(dp->stats_percpu->n_missed);
[processor changed]
this_cpu_read(dp->stats_percpu->n_hit);
What does current guarantee that? If it is guaranteed then you can use the
__this_cpu_xxx ops.
In addition, following usage of per_cpu_ptr can be replaced by this_cpu_read.
cpu=get_cpu()
....
*per_cpu_ptr(p,cpu)
....
....
put_cpu()
On Thu, Nov 1, 2012 at 7:33 AM, Christoph Lameter [off-list ref] wrote:
On Thu, 1 Nov 2012, Shan Wei wrote:
quoted
But for different field in same per-cpu variable, how to guarantee n_missed
and n_hit are from same cpu?
this_cpu_read(dp->stats_percpu->n_missed);
[processor changed]
this_cpu_read(dp->stats_percpu->n_hit);
What does current guarantee that? If it is guaranteed then you can use the
__this_cpu_xxx ops.
Preemption is disabled in all of the places where writes are done and
all of the reads are from foreign CPUs.
From: Christoph Lameter <hidden> Date: 2012-11-02 14:01:16
On Thu, 1 Nov 2012, Jesse Gross wrote:
On Thu, Nov 1, 2012 at 7:33 AM, Christoph Lameter [off-list ref] wrote:
quoted
On Thu, 1 Nov 2012, Shan Wei wrote:
quoted
But for different field in same per-cpu variable, how to guarantee n_missed
and n_hit are from same cpu?
this_cpu_read(dp->stats_percpu->n_missed);
[processor changed]
this_cpu_read(dp->stats_percpu->n_hit);
What does current guarantee that? If it is guaranteed then you can use the
__this_cpu_xxx ops.
Preemption is disabled in all of the places where writes are done and
all of the reads are from foreign CPUs.
Since preemption is disabled no processor change can occur. So its safe to
use __this_cpu ops throughout and they will operate on the current per cpu
area.