2012-11-02 16:03:55

by Shan Wei

[permalink] [raw]
Subject: [PATCH v2 1/9] net: core: use this_cpu_ptr per-cpu helper

From: Shan Wei <[email protected]>

Signed-off-by: Shan Wei <[email protected]>
Reviewed-by: Christoph Lameter <[email protected]>
---
net/core/flow.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/net/core/flow.c b/net/core/flow.c
index e318c7e..3bad824 100644
--- a/net/core/flow.c
+++ b/net/core/flow.c
@@ -327,11 +327,9 @@ static void flow_cache_flush_tasklet(unsigned long data)
static void flow_cache_flush_per_cpu(void *data)
{
struct flow_flush_info *info = data;
- int cpu;
struct tasklet_struct *tasklet;

- cpu = smp_processor_id();
- tasklet = &per_cpu_ptr(info->cache->percpu, cpu)->flush_tasklet;
+ tasklet = &this_cpu_ptr(info->cache->percpu)->flush_tasklet;
tasklet->data = (unsigned long)info;
tasklet_schedule(tasklet);
}
--
1.7.1


Subject: Re: [PATCH v2 1/9] net: core: use this_cpu_ptr per-cpu helper

On Sat, 3 Nov 2012, Shan Wei wrote:
> +++ b/net/core/flow.c
> @@ -327,11 +327,9 @@ static void flow_cache_flush_tasklet(unsigned long data)
> static void flow_cache_flush_per_cpu(void *data)
> {
> struct flow_flush_info *info = data;
> - int cpu;
> struct tasklet_struct *tasklet;
>
> - cpu = smp_processor_id();
> - tasklet = &per_cpu_ptr(info->cache->percpu, cpu)->flush_tasklet;
> + tasklet = &this_cpu_ptr(info->cache->percpu)->flush_tasklet

Another case for the use of this_cpu_read

2012-11-03 08:21:01

by Steffen Klassert

[permalink] [raw]
Subject: Re: [PATCH v2 1/9] net: core: use this_cpu_ptr per-cpu helper

On Fri, Nov 02, 2012 at 05:44:55PM +0000, Christoph Lameter wrote:
> On Sat, 3 Nov 2012, Shan Wei wrote:
> > +++ b/net/core/flow.c
> > @@ -327,11 +327,9 @@ static void flow_cache_flush_tasklet(unsigned long data)
> > static void flow_cache_flush_per_cpu(void *data)
> > {
> > struct flow_flush_info *info = data;
> > - int cpu;
> > struct tasklet_struct *tasklet;
> >
> > - cpu = smp_processor_id();
> > - tasklet = &per_cpu_ptr(info->cache->percpu, cpu)->flush_tasklet;
> > + tasklet = &this_cpu_ptr(info->cache->percpu)->flush_tasklet
>
> Another case for the use of this_cpu_read

Actually, smp_processor_id() is used if either preemtion is off or
in a thread that is bound to the current cpu. So all code that uses
smp_processor_id() should be able to use __this_cpu_read instead of
this_cpu_read.

In this case, flow_cache_flush_per_cpu() is called via smp_call_function(),
so it is bound on the current cpu.