[PATCH v3] drivers: staging: remove last usage of NIPQUAD and NIP6 in gdm72xx

2012-11-26 Thread Shan Wei
From: Shan Wei 

commit cf4ca4874fc45 removed the definition of NIPQUAD and NIPQUAD_FMT,
and NIP6 also is out of date.

Because DEBUG_SDU is not defined in gdm_wimax.h, no error message when compiling
this code. And remove constant condition judge.


Signed-off-by: Shan Wei 
---
V3:
   As suggestion of greg k-h's patch email bot, recreate this patch base on 
greg's staging tree,
   v2 is on David Miller's net-next tree.
---
 drivers/staging/gdm72xx/gdm_wimax.c |   10 +-
 1 files changed, 1 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c 
b/drivers/staging/gdm72xx/gdm_wimax.c
index 6cb8107..c0ec4d0 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -166,21 +166,13 @@ static void dump_eth_packet(const char *title, u8 *data, 
int len)
get_ip_protocol_name(ip_protocol),
get_port_name(port));
 
-   #if 1
if (!(data[0] == 0xff && data[1] == 0xff)) {
if (protocol == ETH_P_IP) {
-   printk(KERN_DEBUG " src=%u.%u.%u.%u\n",
-   NIPQUAD(ih->saddr));
+   printk(KERN_DEBUG " src=%pI4\n", &ih->saddr);
} else if (protocol == ETH_P_IPV6) {
-   #ifdef NIP6
-   printk(KERN_DEBUG " src=%x:%x:%x:%x:%x:%x:%x:%x\n",
-   NIP6(ih->saddr));
-   #else
printk(KERN_DEBUG " src=%pI6\n", &ih->saddr);
-   #endif
}
}
-   #endif
 
#if (DUMP_PACKET & DUMP_SDU_ALL)
printk_hex(data, len);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4] drivers: staging: remove last usage of NIPQUAD and NIP6 in gdm72xx

2012-11-27 Thread Shan Wei
Greg KH said, at 2012/11/28 1:19:
> On Tue, Nov 27, 2012 at 10:37:46AM +0800, Shan Wei wrote:
>> From: Shan Wei 
>>
>> commit cf4ca4874fc45 removed the definition of NIPQUAD and NIPQUAD_FMT,
>> and NIP6 also is out of date.
>>
>> Because DEBUG_SDU is not defined in gdm_wimax.h, no error message when 
>> compiling
>> this code. And remove constant condition judge.
>>
>>
>> Signed-off-by: Shan Wei 
>> ---
>> V3:
>>As suggestion of greg k-h's patch email bot, recreate this patch base on 
>> greg's staging tree,
>>v2 is on David Miller's net-next tree.
> 
> Are you sure you got the right branch?  This does not apply to my
> staging-next branch of the staging.git tree, what did you use?

Just create the patch base on you master of the staging.git, not the 
staging-next branch.
(It's different from David Miller, who has individual git tree for next 
development. :-( )

-----

>From 0b48de95a28f68f6d32f25b77ecc006a9d8a94b9 Mon Sep 17 00:00:00 2001
From: Shan Wei 
Date: Wed, 28 Nov 2012 10:45:00 +0800
Subject: [PATCH staging-next v4] drivers: staging: use %pI4 format to print 
IPv4 address and remove last usage of NIP6

commit cf4ca4874fc45 removed the definition of NIPQUAD and NIPQUAD_FMT,
and NIP6 also is out of date.

commit 2874762b31d8d replace deprecated NIPQUAD marco to C code, but we can use 
%pI4 to
print IPv4 address more simply. And remove constant condition judge.

Because DEBUG_SDU is not defined in gdm_wimax.h, no error message when 
compiling. 


Signed-off-by: Shan Wei 
---
 drivers/staging/gdm72xx/gdm_wimax.c |   13 +
 1 files changed, 1 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c 
b/drivers/staging/gdm72xx/gdm_wimax.c
index c302769..41efbee 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -168,24 +168,13 @@ static void dump_eth_packet(const char *title, u8 *data, 
int len)
get_ip_protocol_name(ip_protocol),
get_port_name(port));
 
-   #if 1
if (!(data[0] == 0xff && data[1] == 0xff)) {
if (protocol == ETH_P_IP) {
-   printk(KERN_DEBUG " src=%u.%u.%u.%u\n",
-   ((unsigned char *)&(ih->saddr))[0],
-   ((unsigned char *)&(ih->saddr))[1],
-   ((unsigned char *)&(ih->saddr))[2],
-   ((unsigned char *)&(ih->saddr))[3]);
+   printk(KERN_DEBUG " src=%pI4\n", &ih->saddr);
} else if (protocol == ETH_P_IPV6) {
-   #ifdef NIP6
-   printk(KERN_DEBUG " src=%x:%x:%x:%x:%x:%x:%x:%x\n",
-   NIP6(ih->saddr));
-   #else
printk(KERN_DEBUG " src=%pI6\n", &ih->saddr);
-   #endif
}
}
-   #endif
 
#if (DUMP_PACKET & DUMP_SDU_ALL)
printk_hex(data, len);
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] trace: use __this_cpu_inc/dec operation instead of __get_cpu_var

2012-11-29 Thread Shan Wei
ping ..


Shan Wei said, at 2012/11/19 13:21:
> From: Shan Wei 
> 
> __this_cpu_inc_return() or __this_cpu_dec generates a single instruction,
> which is faster than __get_cpu_var operation.
> 
> Signed-off-by: Shan Wei 
> ---
>  kernel/trace/trace.c |4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 18c0aa8..3795694 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -1313,7 +1313,7 @@ static void __ftrace_trace_stack(struct ring_buffer 
> *buffer,
>*/
>   preempt_disable_notrace();
>  
> - use_stack = ++__get_cpu_var(ftrace_stack_reserve);
> + use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
>   /*
>* We don't need any atomic variables, just a barrier.
>* If an interrupt comes in, we don't care, because it would
> @@ -1367,7 +1367,7 @@ static void __ftrace_trace_stack(struct ring_buffer 
> *buffer,
>   out:
>   /* Again, don't let gcc optimize things here */
>   barrier();
> - __get_cpu_var(ftrace_stack_reserve)--;
> + __this_cpu_dec(ftrace_stack_reserve);
>   preempt_enable_notrace();
>  
>  }
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 7/9] trace: use this_cpu_ptr per-cpu helper

2012-11-29 Thread Shan Wei
Shan Wei said, at 2012/11/16 16:34:
> Shan Wei said, at 2012/11/13 9:53:
>> From: Shan Wei 
>>
>> typeof(&buffer) is a pointer to array of 1024 char, or char (*)[1024].
>> But, typeof(&buffer[0]) is a pointer to char which match the return type of 
>> get_trace_buf().
>> As well-known, the value of &buffer is equal to &buffer[0].
>> so return this_cpu_ptr(&percpu_buffer->buffer[0]) can avoid type cast. 
>>
>> Signed-off-by: Shan Wei 
> 
> Steven Rostedt,  would you like to pick it up to your tree?

ping..

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/9] use this_cpu_ptr instead of per_cpu_ptr(p, smp_processor_id())

2012-10-31 Thread Shan Wei
this_cpu_ptr is faster than per_cpu_ptr(p, smp_processor_id()).
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following. 


per_cpu_ptr(p, smp_processor_id()):
  1e:   65 8b 04 25 00 00 00 00 mov%gs:0x0,%eax
  26:   48 98   cltq
  28:   31 f6   xor%esi,%esi
  2a:   48 c7 c7 00 00 00 00mov$0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00 mov0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00 movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)
  1e:   65 48 03 14 25 00 00 00 00  add%gs:0x0,%rdx
  27:   31 f6   xor%esi,%esi
  29:   c7 42 04 14 00 00 00movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00mov$0x0,%rdi


$ git diff --stat a932657f51eadb8280166e82dc7034dfbff3985a..
 drivers/clocksource/arm_generic.c |2 +-
 include/trace/ftrace.h|4 +---
 kernel/padata.c   |2 +-
 kernel/rcutree.c  |2 +-
 kernel/trace/blktrace.c   |2 +-
 kernel/trace/trace.c  |2 +-
 net/core/flow.c   |4 +---
 net/openvswitch/datapath.c|4 ++--
 net/openvswitch/vport.c   |5 ++---
 net/rds/ib_recv.c |2 +-
 net/xfrm/xfrm_ipcomp.c|7 +++
 11 files changed, 15 insertions(+), 21 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-10-31 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/9] net: rds: use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 net/rds/ib_recv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 8d19491..a4a5064 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -423,7 +423,7 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
 
local_irq_save(flags);
 
-   chp = per_cpu_ptr(cache->percpu, smp_processor_id());
+   chp = this_cpu_ptr(cache->percpu);
if (!chp->first)
INIT_LIST_HEAD(new_item);
else /* put on front */
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/9] net: xfrm: use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 net/xfrm/xfrm_ipcomp.c |7 +++
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index e5246fb..af6c78a 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -276,14 +276,13 @@ static struct crypto_comp * __percpu 
*ipcomp_alloc_tfms(const char *alg_name)
struct crypto_comp * __percpu *tfms;
int cpu;
 
-   /* This can be any valid CPU ID so we don't need locking. */
-   cpu = raw_smp_processor_id();
-
list_for_each_entry(pos, &ipcomp_tfms_list, list) {
struct crypto_comp *tfm;
 
tfms = pos->tfms;
-   tfm = *per_cpu_ptr(tfms, cpu);
+
+   /* This can be any valid CPU ID so we don't need locking. */
+   tfm = *this_cpu_ptr(tfms);
 
if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
---
 net/openvswitch/datapath.c |4 ++--
 net/openvswitch/vport.c|5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 4c4b62c..77d16a5 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -208,7 +208,7 @@ void ovs_dp_process_received_packet(struct vport *p, struct 
sk_buff *skb)
int error;
int key_len;
 
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
/* Extract flow from 'skb' into 'key'. */
error = ovs_flow_extract(skb, p->port_no, &key, &key_len);
@@ -282,7 +282,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
return 0;
 
 err:
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
u64_stats_update_begin(&stats->sync);
stats->n_lost++;
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 03779e8..70af0be 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -333,8 +333,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff 
*skb)
 {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
-
+   stats = this_cpu_ptr(vport->percpu_stats);
u64_stats_update_begin(&stats->sync);
stats->rx_packets++;
stats->rx_bytes += skb->len;
@@ -359,7 +358,7 @@ int ovs_vport_send(struct vport *vport, struct sk_buff *skb)
if (likely(sent)) {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
+   stats = this_cpu_ptr(vport->percpu_stats);
 
u64_stats_update_begin(&stats->sync);
stats->tx_packets++;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/9] ftrace: use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
---
 include/trace/ftrace.h |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index a763888..7c9fde7 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -638,7 +638,6 @@ __attribute__((section("_ftrace_events"))) *__event_##call 
= &event_##call
  * struct trace_entry *ent;
  * int __entry_size;
  * int __data_size;
- * int __cpu
  * int pc;
  *
  * pc = preempt_count();
@@ -654,7 +653,6 @@ __attribute__((section("_ftrace_events"))) *__event_##call 
= &event_##call
  * // Protect the non nmi buffer
  * // This also protects the rcu read side
  * local_irq_save(irq_flags);
- * __cpu = smp_processor_id();
  *
  * if (in_nmi())
  * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
@@ -664,7 +662,7 @@ __attribute__((section("_ftrace_events"))) *__event_##call 
= &event_##call
  * if (!trace_buf)
  * goto end;
  *
- * trace_buf = per_cpu_ptr(trace_buf, __cpu);
+ * trace_buf = this_cpu_ptr(trace_buf);
  *
  * // Avoid recursion from perf that could mess up the buffer
  * if (trace_buf->recursion++)
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/9] kernel: padata : use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 kernel/padata.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 89fe3d1..70dffe8 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -204,7 +204,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
goto out;
}
 
-   queue = per_cpu_ptr(pd->pqueue, smp_processor_id());
+   queue = this_cpu_ptr(pd->pqueue);
if (queue->cpu_index == next_queue->cpu_index) {
padata = ERR_PTR(-ENODATA);
goto out;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 kernel/trace/blktrace.c |2 +-
 kernel/trace/trace.c|2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c0bd030..71259e2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const char 
*fmt, ...)
return;
 
local_irq_save(flags);
-   buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
+   buf = this_cpu_ptr(bt->msg_data);
va_start(args, fmt);
n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
va_end(args);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 31e4f55..81ae35b 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1513,7 +1513,7 @@ static char *get_trace_buf(void)
if (!percpu_buffer)
return NULL;
 
-   buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
+   buffer = this_cpu_ptr(percpu_buffer);
 
return buffer->buffer;
 }
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 9/9] clocksource: use this_cpu_ptr per-cpu helper

2012-10-31 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 drivers/clocksource/arm_generic.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/clocksource/arm_generic.c 
b/drivers/clocksource/arm_generic.c
index c4d9f95..cb445ab 100644
--- a/drivers/clocksource/arm_generic.c
+++ b/drivers/clocksource/arm_generic.c
@@ -224,7 +224,7 @@ int __init arm_generic_timer_init(void)
lpj_fine = arch_timer_rate / HZ;
 
/* Immediately configure the timer on the boot CPU */
-   arch_timer_setup(per_cpu_ptr(&arch_timer_evt, smp_processor_id()));
+   arch_timer_setup(this_cpu_ptr(&arch_timer_evt));
 
register_cpu_notifier(&arch_timer_cpu_nb);
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 7/9] rcu: use this_cpu_ptr per-cpu helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-10-31 Thread Shan Wei
From: Shan Wei 

smp_processor_id is defined as raw_smp_processor_id.
replace per_cpu_ptr(p, raw_smp_processor_id()) is also ok.

Signed-off-by: Shan Wei 
---
 kernel/rcutree.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 74df86b..3a21fcf 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1960,7 +1960,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
struct rcu_node *rnp_old = NULL;
 
/* Funnel through hierarchy to reduce memory contention. */
-   rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
+   rnp = this_cpu_ptr(rsp->rda)->mynode;
for (; rnp != NULL; rnp = rnp->parent) {
ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
  !raw_spin_trylock(&rnp->fqslock);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 7/9] rcu: use this_cpu_ptr per-cpu helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-10-31 Thread Shan Wei
Paul E. McKenney said, at 2012/10/31 19:51:
> 
> The first uses smp_processor_id(), which will complain if
> force_quiescent_state() is called with preemption disabled, which it
> sometimes is.
> 
> So what am I missing here?

Hi Paul

this patch is not right for CONFIG_DEBUG_PREEMPT case.
__this_cpu_ptr is ok which do not check for preemption context.


> 
>   Thanx, Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] net: xfrm: use this_cpu_ptr per-cpu helper

2012-11-01 Thread Shan Wei
Christoph Lameter said, at 2012/11/1 1:35:
> It would be better to use
> 
>   this_cpu_read(tfms)
> 
> since that would also make it atomic vs interrupts. The above code (both
> original and modified) could determine a pointer to a per cpu structure
> and then take an interrupt which would move the task. On return we would
> be accessing the per cpu variable of another processor.

this_cpu_read
|-_this_cpu_generic_read

#define _this_cpu_generic_read(pcp) \
({  typeof(pcp) ret__;  \
preempt_disable();  \
ret__ = *this_cpu_ptr(&(pcp));  \
preempt_enable();   \
ret__;  \
})


this_cpu_read operations locate per-cpu variable with preemption safe, not
disable interrupts. why is it atomic vs interrupts?

I have no idea whether we need to disable preemption for this code?
At least, xfrm code run well with per_cpu_ptr which don't disable preemption.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] net: xfrm: use this_cpu_ptr per-cpu helper

2012-11-01 Thread Shan Wei
Herbert Xu said, at 2012/11/1 11:41:
> Please refer to the comment in the patch above.
> 
> But I think the patch is wrong anyway because it would introduce
> a warning, no?

yes, __this_cpu_ptr(or __this_cpu_read) is more reasonable 
which don't check preemption context.

> 
> Thanks,
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 7/9] rcu: use this_cpu_ptr per-cpu helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-11-01 Thread Shan Wei
Paul E. McKenney said, at 2012/11/1 4:08:
> 
> One thing to keep in mind -- the only purpose of this is to diffuse
> memory contention.  So there is no need to disable preemption.

same question to me.
Christoph, maybe __this_cpu_read is a better choice which don't disable 
preemption.

> 
>   Thanx, Paul
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-01 Thread Shan Wei
Christoph Lameter said, at 2012/11/1 1:39:
> On Wed, 31 Oct 2012, Shan Wei wrote:
> 
>> --- a/net/openvswitch/datapath.c
>> +++ b/net/openvswitch/datapath.c
>> @@ -208,7 +208,7 @@ void ovs_dp_process_received_packet(struct vport *p, 
>> struct sk_buff *skb)
>>  int error;
>>  int key_len;
>>
>> -stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
>> +stats = this_cpu_ptr(dp->stats_percpu);
> 
> 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()

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

2012-11-02 Thread Shan Wei
Christoph Lameter said, at 2012/11/1 1:50:
>>
>> -buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
>> +buffer = this_cpu_ptr(percpu_buffer);
>>
>>  return buffer->buffer;
> 
> 
> Just do a
> 
>   return this_cpu_read(percpu_buffer->buffer);
> 
> and get rid of the this_cpu_ptr op

can not do that.
kernel/trace/trace.c:1515: error: incompatible types when assigning to type 
'char[1024]' from type 'char *'

 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/9 v2] use efficient this_cpu_* helper

2012-11-02 Thread Shan Wei
this_cpu_ptr is faster than per_cpu_ptr(p, smp_processor_id()) 
and can reduce  memory accesses.
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following. 

per_cpu_ptr(p, smp_processor_id()):
  1e:   65 8b 04 25 00 00 00 00 mov%gs:0x0,%eax
  26:   48 98   cltq
  28:   31 f6   xor%esi,%esi
  2a:   48 c7 c7 00 00 00 00mov$0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00 mov0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00 movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)
  1e:   65 48 03 14 25 00 00 00 00  add%gs:0x0,%rdx
  27:   31 f6   xor%esi,%esi
  29:   c7 42 04 14 00 00 00movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00mov$0x0,%rdi

Changelog V2:
1. Use this_cpu_read directly instead of ref to field of per-cpu variable.
2. Patch5 about ftrace is dropped from this series.
3. Add new patch9 to replace get_cpu;per_cpu_ptr;put_cpu with this_cpu_add opt.
4. For preemption disable case, use __this_cpu_read instead.
  
$ git diff --stat b77bc2069d1e437d5a1a71bb5cfcf4556ee40015 
 drivers/clocksource/arm_generic.c |2 +-
 kernel/padata.c   |5 ++---
 kernel/rcutree.c  |2 +-
 kernel/trace/blktrace.c   |2 +-
 kernel/trace/trace.c  |4 +---
 net/batman-adv/main.h |4 +---
 net/core/flow.c   |4 +---
 net/openvswitch/datapath.c|4 ++--
 net/openvswitch/vport.c   |5 ++---
 net/rds/ib_recv.c |2 +-
 net/xfrm/xfrm_ipcomp.c|7 +++
 11 files changed, 16 insertions(+), 25 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/9] net: rds: use this_cpu_ptr per-cpu helper

2012-11-02 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
 net/rds/ib_recv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 8d19491..a4a5064 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -423,7 +423,7 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
 
local_irq_save(flags);
 
-   chp = per_cpu_ptr(cache->percpu, smp_processor_id());
+   chp = this_cpu_ptr(cache->percpu);
if (!chp->first)
INIT_LIST_HEAD(new_item);
else /* put on front */
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/9] net: xfrm: use __this_cpu_read per-cpu helper

2012-11-02 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 net/xfrm/xfrm_ipcomp.c |7 +++
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index e5246fb..394d672 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -276,14 +276,13 @@ static struct crypto_comp * __percpu 
*ipcomp_alloc_tfms(const char *alg_name)
struct crypto_comp * __percpu *tfms;
int cpu;
 
-   /* This can be any valid CPU ID so we don't need locking. */
-   cpu = raw_smp_processor_id();
-
list_for_each_entry(pos, &ipcomp_tfms_list, list) {
struct crypto_comp *tfm;
 
tfms = pos->tfms;
-   tfm = *per_cpu_ptr(tfms, cpu);
+
+   /* This can be any valid CPU ID so we don't need locking. */
+   tfm = __this_cpu_read(tfms);
 
if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-02 Thread Shan Wei
From: Shan Wei 

no change vs v1.

Lots of drivers use this kind to read/write per-cpu variable.
stats = this_cpu_ptr(dp->stats_percpu);
u64_stats_update_begin(&stats->sync);
stats->tx_packets++;
u64_stats_update_begin(&stats->sync);


Signed-off-by: Shan Wei 
---
 net/openvswitch/datapath.c |4 ++--
 net/openvswitch/vport.c|5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 4c4b62c..77d16a5 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -208,7 +208,7 @@ void ovs_dp_process_received_packet(struct vport *p, struct 
sk_buff *skb)
int error;
int key_len;
 
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
/* Extract flow from 'skb' into 'key'. */
error = ovs_flow_extract(skb, p->port_no, &key, &key_len);
@@ -282,7 +282,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
return 0;
 
 err:
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
u64_stats_update_begin(&stats->sync);
stats->n_lost++;
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 03779e8..70af0be 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -333,8 +333,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff 
*skb)
 {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
-
+   stats = this_cpu_ptr(vport->percpu_stats);
u64_stats_update_begin(&stats->sync);
stats->rx_packets++;
stats->rx_bytes += skb->len;
@@ -359,7 +358,7 @@ int ovs_vport_send(struct vport *vport, struct sk_buff *skb)
if (likely(sent)) {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
+   stats = this_cpu_ptr(vport->percpu_stats);
 
u64_stats_update_begin(&stats->sync);
stats->tx_packets++;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 5/9] kernel: padata : use this_cpu_read per-cpu helper

2012-11-02 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 kernel/padata.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 89fe3d1..cf94137 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -171,7 +171,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
 {
int cpu, num_cpus;
unsigned int next_nr, next_index;
-   struct padata_parallel_queue *queue, *next_queue;
+   struct padata_parallel_queue *next_queue;
struct padata_priv *padata;
struct padata_list *reorder;
 
@@ -204,8 +204,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
goto out;
}
 
-   queue = per_cpu_ptr(pd->pqueue, smp_processor_id());
-   if (queue->cpu_index == next_queue->cpu_index) {
+   if (this_cpu_read(pd->pqueue->cpu_index) == next_queue->cpu_index) {
padata = ERR_PTR(-ENODATA);
goto out;
}
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-11-02 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
---
 kernel/rcutree.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 74df86b..441b945 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1960,7 +1960,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
struct rcu_node *rnp_old = NULL;
 
/* Funnel through hierarchy to reduce memory contention. */
-   rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
+   rnp = __this_cpu_read(rsp->rda->mynode);
for (; rnp != NULL; rnp = rnp->parent) {
ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
  !raw_spin_trylock(&rnp->fqslock);
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 7/9] trace: use this_cpu_ptr per-cpu helper

2012-11-02 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
 kernel/trace/blktrace.c |2 +-
 kernel/trace/trace.c|2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c0bd030..71259e2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const char 
*fmt, ...)
return;
 
local_irq_save(flags);
-   buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
+   buf = this_cpu_ptr(bt->msg_data);
va_start(args, fmt);
n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
va_end(args);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 31e4f55..81ae35b 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1513,7 +1513,7 @@ static char *get_trace_buf(void)
if (!percpu_buffer)
return NULL;
 
-   buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
+   buffer = this_cpu_ptr(percpu_buffer);
 
return buffer->buffer;
 }
-- 1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 8/9] clocksource: use this_cpu_ptr per-cpu helper

2012-11-02 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
 drivers/clocksource/arm_generic.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/clocksource/arm_generic.c 
b/drivers/clocksource/arm_generic.c
index c4d9f95..cb445ab 100644
--- a/drivers/clocksource/arm_generic.c
+++ b/drivers/clocksource/arm_generic.c
@@ -224,7 +224,7 @@ int __init arm_generic_timer_init(void)
lpj_fine = arch_timer_rate / HZ;
 
/* Immediately configure the timer on the boot CPU */
-   arch_timer_setup(per_cpu_ptr(&arch_timer_evt, smp_processor_id()));
+   arch_timer_setup(this_cpu_ptr(&arch_timer_evt));
 
register_cpu_notifier(&arch_timer_cpu_nb);
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 9/9] net: batman-adv: use per_cpu_add helper

2012-11-02 Thread Shan Wei
From: Shan Wei 


As Christoph Lameter said:

> 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()

Right.

Signed-off-by: Shan Wei 
---
 net/batman-adv/main.h |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 897ba6a..3aef5b2 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -263,9 +263,7 @@ static inline bool batadv_has_timed_out(unsigned long 
timestamp,
 static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx,
  size_t count)
 {
-   int cpu = get_cpu();
-   per_cpu_ptr(bat_priv->bat_counters, cpu)[idx] += count;
-   put_cpu();
+   this_cpu_add(bat_priv->bat_counters[idx], count);
 }
 
 #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1)
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/9 v2] use efficient this_cpu_* helper

2012-11-02 Thread Shan Wei
this_cpu_ptr is faster than per_cpu_ptr(p, smp_processor_id()) 
and can reduce  memory accesses.
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following. 

per_cpu_ptr(p, smp_processor_id()):
  1e:   65 8b 04 25 00 00 00 00 mov%gs:0x0,%eax
  26:   48 98   cltq
  28:   31 f6   xor%esi,%esi
  2a:   48 c7 c7 00 00 00 00mov$0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00 mov0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00 movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)
  1e:   65 48 03 14 25 00 00 00 00  add%gs:0x0,%rdx
  27:   31 f6   xor%esi,%esi
  29:   c7 42 04 14 00 00 00movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00mov$0x0,%rdi

Changelog V2:
1. Use this_cpu_read directly instead of ref to field of per-cpu variable.
2. Patch5 about ftrace is dropped from this series.
3. Add new patch9 to replace get_cpu;per_cpu_ptr;put_cpu with this_cpu_add opt.
4. For preemption disable case, use __this_cpu_read instead.
  
$ git diff --stat b77bc2069d1e437d5a1a71bb5cfcf4556ee40015 
 drivers/clocksource/arm_generic.c |2 +-
 kernel/padata.c   |5 ++---
 kernel/rcutree.c  |2 +-
 kernel/trace/blktrace.c   |2 +-
 kernel/trace/trace.c  |4 +---
 net/batman-adv/main.h |4 +---
 net/core/flow.c   |4 +---
 net/openvswitch/datapath.c|4 ++--
 net/openvswitch/vport.c   |5 ++---
 net/rds/ib_recv.c |2 +-
 net/xfrm/xfrm_ipcomp.c|7 +++
 11 files changed, 16 insertions(+), 25 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-11-02 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
 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


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH cleanup RFC] ftrace: kill unused and puzzled sample code in ftrace.h

2012-11-02 Thread Shan Wei
From: Shan Wei 

When doing per-cpu helper optimizing work, find that this code is so puzzled.
1. It's mark as comment text, maybe a sample function for guidelines 
   or a todo work.
2. But, this sample code is odd where struct perf_trace_buf is nonexistent.
   commit ce71b9 delete struct perf_trace_buf definition.

   Author: Frederic Weisbecker 
   Date:   Sun Nov 22 05:26:55 2009 +0100

   tracing: Use the perf recursion protection from trace event

Is it necessary to keep there?
just compile test. 



Signed-off-by: Shan Wei 
---
 include/trace/ftrace.h |   73 
 1 files changed, 0 insertions(+), 73 deletions(-)

diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index a763888..4f993c2 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -620,79 +620,6 @@ __attribute__((section("_ftrace_events"))) *__event_##call 
= &event_##call
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
-/*
- * Define the insertion callback to perf events
- *
- * The job is very similar to ftrace_raw_event_ except that we don't
- * insert in the ring buffer but in a perf counter.
- *
- * static void ftrace_perf_(proto)
- * {
- * struct ftrace_data_offsets_ __maybe_unused __data_offsets;
- * struct ftrace_event_call *event_call = &event_;
- * extern void perf_tp_event(int, u64, u64, void *, int);
- * struct ftrace_raw_##call *entry;
- * struct perf_trace_buf *trace_buf;
- * u64 __addr = 0, __count = 1;
- * unsigned long irq_flags;
- * struct trace_entry *ent;
- * int __entry_size;
- * int __data_size;
- * int __cpu
- * int pc;
- *
- * pc = preempt_count();
- *
- * __data_size = ftrace_get_offsets_(&__data_offsets, args);
- *
- * // Below we want to get the aligned size by taking into account
- * // the u32 field that will later store the buffer size
- * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
- *  sizeof(u64));
- * __entry_size -= sizeof(u32);
- *
- * // Protect the non nmi buffer
- * // This also protects the rcu read side
- * local_irq_save(irq_flags);
- * __cpu = smp_processor_id();
- *
- * if (in_nmi())
- * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
- * else
- * trace_buf = rcu_dereference_sched(perf_trace_buf);
- *
- * if (!trace_buf)
- * goto end;
- *
- * trace_buf = per_cpu_ptr(trace_buf, __cpu);
- *
- * // Avoid recursion from perf that could mess up the buffer
- * if (trace_buf->recursion++)
- * goto end_recursion;
- *
- * raw_data = trace_buf->buf;
- *
- * // Make recursion update visible before entering perf_tp_event
- * // so that we protect from perf recursions.
- *
- * barrier();
- *
- * //zero dead bytes from alignment to avoid stack leak to userspace:
- * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
- * entry = (struct ftrace_raw_ *)raw_data;
- * ent = &entry->ent;
- * tracing_generic_entry_update(ent, irq_flags, pc);
- * ent->type = event_call->id;
- *
- *  <- do some jobs with dynamic arrays
- *
- *   <- affect our values
- *
- * perf_tp_event(event_call->id, __addr, __count, entry,
- *  __entry_size);  <- submit them to perf counter
- *
- * }
- */
 
 #ifdef CONFIG_PERF_EVENTS
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

2012-11-02 Thread Shan Wei
Christoph Lameter said, at 2012/11/3 1:53:
> 
> hmm what is actually returned is a pointer to char right? And buffer
> is char[1024] so I guess then you need to pass a pointer to char to
> this_cpu_read.
> 
> return this_cpu_read(&(percpu_buffer->buffer))
 
still error

kernel/trace/trace.c: In function 'get_trace_buf':
kernel/trace/trace.c:1517: error: lvalue required as unary '&' operand
kernel/trace/trace.c:1517: warning: type defaults to 'int' in declaration of 
'type name'
kernel/trace/trace.c:1517: warning: cast from pointer to integer of different 
size
kernel/trace/trace.c:1517: warning: return from incompatible pointer type
kernel/trace/trace.c:1498: warning: unused variable 'buffer'
kernel/trace/trace.c:1517: error: memory input 1 is not directly addressable
kernel/trace/trace.c:1517: error: memory input 1 is not directly addressable

this_cpu_read just read the actual value which a pointer point to.
some case, we just need the pointer.
It's better to use this_cpu_ptr.
return (char *)this_cpu_ptr(&percpu_buffer->buffer);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [B.A.T.M.A.N.] [PATCH v2 9/9] net: batman-adv: use per_cpu_add helper

2012-11-02 Thread Shan Wei
Sven Eckelmann said, at 2012/11/3 1:55:
> On Saturday 03 November 2012 00:02:06 Shan Wei wrote:
>> From: Shan Wei 
>>
>> As Christoph Lameter said:
>>> 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()
>>
>> Right.
>>
>> Signed-off-by: Shan Wei 
>> ---
> 
> Is this really supposed to be the commit message?

Maybe it's ok when Linus said this. :-)

Christoph is the maintainer of per-cpu.
So

PER-CPU MEMORY ALLOCATOR
M:  Tejun Heo 
M:  Christoph Lameter 
T:  git git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu.git
S:  Maintained
F:  include/linux/percpu*.h
F:  mm/percpu*.c
F:  arch/*/include/asm/percpu.h

> 
> Kind regards,
>   Sven
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-11-04 Thread Shan Wei
Paul E. McKenney said, at 2012/11/3 17:19:
> OK, I do understand why it happens to work.  My question is instead why
> it is considered a good idea.  

Maybe objdump gives the answer.
 __this_cpu_read which read member pointer of per-cpu variable
can reduce two instructions on x86-64 arch.


*test code:* 
struct eater_state {
u32 state;
struct eater __percpu *eater_info;
};

struct eater {
char name[4];
u32 age;
};

static u32 test_func(struct eater_state *tstas)
{
struct eater *aeater;

//aeater = __this_cpu_ptr(tstas->eater_info);   <-1
//return aeater->age;
return  __this_cpu_read(tstas->eater_info->age); <-2
}

static int __init demo_init(void)
{
int ret = 0 ;
int age;
struct eater_state as;
struct eater david;

as.state = 1;
as.eater_info = &david;

age = test_func(&as);

return ret;
}


__this_cpu_ptr <-1
 :
   0:   55  push   %rbp
   1:   48 89 e5mov%rsp,%rbp
   4:   48 83 ec 10 sub$0x10,%rsp
   8:   48 8d 45 f0 lea-0x10(%rbp),%rax
   c:   65 48 03 04 25 00 00 00 00  add%gs:0x0,%rax
  15:   31 c0   xor%eax,%eax
  17:   c9  leaveq 
  18:   c3  retq   


 __this_cpu_read<-2
 :
   0:   55  push   %rbp
   1:   31 c0   xor%eax,%eax
   3:   48 89 e5mov%rsp,%rbp
   6:   48 83 ec 10 sub$0x10,%rsp
   a:   c9  leaveq 
   b:   c3  retq   


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] net: core: fix unused variable sparse warning

2012-12-07 Thread Shan Wei
Cong Ding said, at 2012/12/7 8:15:
> On Fri, Dec 07, 2012 at 12:06:44AM +, Cong Ding wrote:
>> the variables zero and unres_qlen_max are only used when CONFIG_SYSCTL is
>> defined, otherwise it causes the following sparse warning when we turn on
>> CONFIG_SYSCTL.
> sorry for disturbing again, the sparse warning is
> net/core/neighbour.c:65:12: warning: ‘zero’ defined but not used 
> [-Wunused-variable]
> net/core/neighbour.c:66:12: warning: ‘unres_qlen_max’ defined but not used 
> [-Wunused-variable]
> 
> it happens if we turn off CONFIG_SYSCTL.

It has been fixed yesterday.
see b93196dc5af7729ff7cc50d3d322ab1a364aa14f

> 
>>
>> Signed-off-by: Cong Ding 
>> ---
>>  net/core/neighbour.c |2 ++
>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
>> index 36fc692..4a15278 100644
>> --- a/net/core/neighbour.c
>> +++ b/net/core/neighbour.c
>> @@ -62,8 +62,10 @@ static void __neigh_notify(struct neighbour *n, int type, 
>> int flags);
>>  static void neigh_update_notify(struct neighbour *neigh);
>>  static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
>>  
>> +#ifdef CONFIG_SYSCTL
>>  static int zero;
>>  static int unres_qlen_max = INT_MAX / SKB_TRUESIZE(ETH_FRAME_LEN);
>> +#endif
>>  
>>  static struct neigh_table *neigh_tables;
>>  #ifdef CONFIG_PROC_FS
>> -- 
>> 1.7.4.5
>>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/9] net: xfrm: use __this_cpu_read per-cpu helper

2012-11-11 Thread Shan Wei
Christoph Lameter said, at 2012/11/10 4:12:
> On Fri, 9 Nov 2012, Shan Wei wrote:
> 
>> v3 fix compile warning:
>> net/xfrm/xfrm_ipcomp.c: In function 'ipcomp_alloc_tfms':
>> net/xfrm/xfrm_ipcomp.c:285: warning: assignment from incompatible pointer 
>> type
> 
> Why exactly is the pointer type not compatible? Looks like we have a
> problem here.
> 

pos->tfms(struct crypto_comp **tfms) is a double pointer that point to struct 
crypto_comp.
returned value is a pointer that point to struct crypto_comp;
So, we need to dereference and then read.

+ tfm = __this_cpu_read(*pos->tfms);

I will update this patch in v4 to fix it.

Thanks~
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper

2012-11-11 Thread Shan Wei
Christoph Lameter said, at 2012/11/10 4:15:
> On Fri, 9 Nov 2012, Shan Wei wrote:
> 
>> -return buffer->buffer;
>> +return (char *)this_cpu_ptr(&percpu_buffer->buffer);
>>  }
> 
> Add a comment to explain the cast?

typeof(&buffer) is a pointer to array of 1024 char, or char (*)[1024].
But, typeof(&buffer[0]) is a pointer to char which match the return type of 
get_trace_buf().
As well-known, the value of &buffer is equal to &buffer[0].
so return this_cpu_ptr(&percpu_buffer->buffer[0]) can avoid this cast. 

I will submit v4 version patch which improve it.

Thanks~
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/9] net: rds: use this_cpu_ptr per-cpu helper

2012-11-12 Thread Shan Wei
Christoph Lameter said, at 2012/11/10 4:09:
>> -chp = per_cpu_ptr(cache->percpu, smp_processor_id());
>> +chp = this_cpu_ptr(cache->percpu);
>>  if (!chp->first)
> 
> if (!__this_cpu_read(cache-0>percpu->first))
> 
> ?

__percpu annotations in struct rds_ib_refill_cache is missing.

you mean that read/write fields of struct rds_ib_cache_head
using __this_cpu_* operation like following?
How about it?

diff --git a/net/rds/ib.h b/net/rds/ib.h
index 8d2b3d5..7280ab8 100644
--- a/net/rds/ib.h
+++ b/net/rds/ib.h
@@ -50,7 +50,7 @@ struct rds_ib_cache_head {
 };
 
 struct rds_ib_refill_cache {
-   struct rds_ib_cache_head *percpu;
+   struct rds_ib_cache_head __percpu *percpu;
struct list_head *xfer;
struct list_head *ready;
 };
diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 8d19491..8c5bc85 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -418,20 +418,21 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
 struct rds_ib_refill_cache *cache)
 {
unsigned long flags;
-   struct rds_ib_cache_head *chp;
struct list_head *old;
+   struct list_head __percpu *chpfirst;
 
local_irq_save(flags);
 
-   chp = per_cpu_ptr(cache->percpu, smp_processor_id());
-   if (!chp->first)
+   chpfirst = __this_cpu_read(cache->percpu->first);
+   if (!chpfirst)
INIT_LIST_HEAD(new_item);
else /* put on front */
-   list_add_tail(new_item, chp->first);
-   chp->first = new_item;
-   chp->count++;
+   list_add_tail(new_item, chpfirst);
 
-   if (chp->count < RDS_IB_RECYCLE_BATCH_COUNT)
+   __this_cpu_write(chpfirst, new_item);
+   __this_cpu_inc(cache->percpu->count);
+
+   if (__this_cpu_read(cache->percpu->count) < RDS_IB_RECYCLE_BATCH_COUNT)
goto end;
 
/*
@@ -443,12 +444,13 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
do {
old = xchg(&cache->xfer, NULL);
if (old)
-   list_splice_entire_tail(old, chp->first);
-   old = cmpxchg(&cache->xfer, NULL, chp->first);
+   list_splice_entire_tail(old, chpfirst);
+   old = cmpxchg(&cache->xfer, NULL, chpfirst);
} while (old);
 
-   chp->first = NULL;
-   chp->count = 0;
+
+   __this_cpu_write(chpfirst, NULL);
+   __this_cpu_write(cache->percpu->count, 0);
 end:
local_irq_restore(flags);
 }

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH cleanup RFC] ftrace: kill unused and puzzled sample code in ftrace.h

2012-11-12 Thread Shan Wei

ping...

Shan Wei said, at 2012/11/3 12:38:
> From: Shan Wei 
> 
> When doing per-cpu helper optimizing work, find that this code is so puzzled.
> 1. It's mark as comment text, maybe a sample function for guidelines 
>or a todo work.
> 2. But, this sample code is odd where struct perf_trace_buf is nonexistent.
>commit ce71b9 delete struct perf_trace_buf definition.
> 
>Author: Frederic Weisbecker 
>Date:   Sun Nov 22 05:26:55 2009 +0100
> 
>tracing: Use the perf recursion protection from trace event
> 
> Is it necessary to keep there?
> just compile test. 

> 
> 
> 
> Signed-off-by: Shan Wei 
> ---
>  include/trace/ftrace.h |   73 
> 
>  1 files changed, 0 insertions(+), 73 deletions(-)
> 
> diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
> index a763888..4f993c2 100644
> --- a/include/trace/ftrace.h
> +++ b/include/trace/ftrace.h
> @@ -620,79 +620,6 @@ __attribute__((section("_ftrace_events"))) 
> *__event_##call = &event_##call
>  
>  #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
>  
> -/*
> - * Define the insertion callback to perf events
> - *
> - * The job is very similar to ftrace_raw_event_ except that we don't
> - * insert in the ring buffer but in a perf counter.
> - *
> - * static void ftrace_perf_(proto)
> - * {
> - *   struct ftrace_data_offsets_ __maybe_unused __data_offsets;
> - *   struct ftrace_event_call *event_call = &event_;
> - *   extern void perf_tp_event(int, u64, u64, void *, int);
> - *   struct ftrace_raw_##call *entry;
> - *   struct perf_trace_buf *trace_buf;
> - *   u64 __addr = 0, __count = 1;
> - *   unsigned long irq_flags;
> - *   struct trace_entry *ent;
> - *   int __entry_size;
> - *   int __data_size;
> - *   int __cpu
> - *   int pc;
> - *
> - *   pc = preempt_count();
> - *
> - *   __data_size = ftrace_get_offsets_(&__data_offsets, args);
> - *
> - *   // Below we want to get the aligned size by taking into account
> - *   // the u32 field that will later store the buffer size
> - *   __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
> - *sizeof(u64));
> - *   __entry_size -= sizeof(u32);
> - *
> - *   // Protect the non nmi buffer
> - *   // This also protects the rcu read side
> - *   local_irq_save(irq_flags);
> - *   __cpu = smp_processor_id();
> - *
> - *   if (in_nmi())
> - *   trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
> - *   else
> - *   trace_buf = rcu_dereference_sched(perf_trace_buf);
> - *
> - *   if (!trace_buf)
> - *   goto end;
> - *
> - *   trace_buf = per_cpu_ptr(trace_buf, __cpu);
> - *
> - *   // Avoid recursion from perf that could mess up the buffer
> - *   if (trace_buf->recursion++)
> - *   goto end_recursion;
> - *
> - *   raw_data = trace_buf->buf;
> - *
> - *   // Make recursion update visible before entering perf_tp_event
> - *   // so that we protect from perf recursions.
> - *
> - *   barrier();
> - *
> - *   //zero dead bytes from alignment to avoid stack leak to userspace:
> - *   *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
> - *   entry = (struct ftrace_raw_ *)raw_data;
> - *   ent = &entry->ent;
> - *   tracing_generic_entry_update(ent, irq_flags, pc);
> - *   ent->type = event_call->id;
> - *
> - *<- do some jobs with dynamic arrays
> - *
> - * <- affect our values
> - *
> - *   perf_tp_event(event_call->id, __addr, __count, entry,
> - *__entry_size);  <- submit them to perf counter
> - *
> - * }
> - */
>  
>  #ifdef CONFIG_PERF_EVENTS
>  
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/9 v4] use efficient this_cpu_* helper

2012-11-12 Thread Shan Wei
this_cpu_ptr/this_cpu_read is faster than per_cpu_ptr(p, smp_processor_id()) 
and can reduce  memory accesses.
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following. 

this_cpu_ptr relocates and address. this_cpu_read() relocates the address
and performs the fetch. If you want to operate on rda(defined as per_cpu) 
then you can only use this_cpu_ptr. this_cpu_read() saves you more instructions
since it can do the relocation and the fetch in one instruction.

per_cpu_ptr(p, smp_processor_id()):
  1e:   65 8b 04 25 00 00 00 00 mov%gs:0x0,%eax
  26:   48 98   cltq
  28:   31 f6   xor%esi,%esi
  2a:   48 c7 c7 00 00 00 00mov$0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00 mov0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00 movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)
  1e:   65 48 03 14 25 00 00 00 00  add%gs:0x0,%rdx
  27:   31 f6   xor%esi,%esi
  29:   c7 42 04 14 00 00 00movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00mov$0x0,%rdi



Changelog V4:
1. [read|write]ing fields of struct rds_ib_cache_head using __this_cpu_* 
operation for rds subsystem.
   see patch2
2. fix bug in xfrm to read pointer. see patch3. 
3. avoid type cast in patch7.

Changelog V3:
1. use this_cpu_read directly read member of per-cpu variable,
   so that droping the this_cpu_ptr operation.
2. for preemption off and bottom halves off case,
   use __this_cpu_read instead of this_cpu_read. 

Changelog V2:
1. Use this_cpu_read directly instead of ref to field of per-cpu variable.
2. Patch5 about ftrace is dropped from this series.
3. Add new patch9 to replace get_cpu;per_cpu_ptr;put_cpu with this_cpu_add opt.
4. For preemption disable case, use __this_cpu_read instead.
  

$ git diff --stat d4185bbf62a5d8d777ee445db1581beb17882a07
 drivers/clocksource/arm_generic.c |2 +-
 kernel/padata.c   |5 ++---
 kernel/rcutree.c  |2 +-
 kernel/trace/blktrace.c   |2 +-
 kernel/trace/trace.c  |5 +
 net/batman-adv/main.h |4 +---
 net/core/flow.c   |4 +---
 net/openvswitch/datapath.c|4 ++--
 net/openvswitch/vport.c   |5 ++---
 net/rds/ib.h  |2 +-
 net/rds/ib_recv.c |   24 +---
 net/xfrm/xfrm_ipcomp.c|8 +++-
 12 files changed, 29 insertions(+), 38 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 1/9] net: core: use this_cpu_ptr per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 

flush_tasklet is a struct, not a pointer in percpu var.
so use this_cpu_ptr to get the member pointer.

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
no changes vs v3.
---
 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..b0901ee 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 2/9] net: rds: use this_cpu_* per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
v4:
1. add missing __percpu annotations.
2. [read|write]ing fields of struct rds_ib_cache_head
using __this_cpu_* operation, drop per_cpu_ptr.
---
 net/rds/ib.h  |2 +-
 net/rds/ib_recv.c |   24 +---
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/net/rds/ib.h b/net/rds/ib.h
index 8d2b3d5..7280ab8 100644
--- a/net/rds/ib.h
+++ b/net/rds/ib.h
@@ -50,7 +50,7 @@ struct rds_ib_cache_head {
 };
 
 struct rds_ib_refill_cache {
-   struct rds_ib_cache_head *percpu;
+   struct rds_ib_cache_head __percpu *percpu;
struct list_head *xfer;
struct list_head *ready;
 };
diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 8d19491..8c5bc85 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -418,20 +418,21 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
 struct rds_ib_refill_cache *cache)
 {
unsigned long flags;
-   struct rds_ib_cache_head *chp;
struct list_head *old;
+   struct list_head __percpu *chpfirst;
 
local_irq_save(flags);
 
-   chp = per_cpu_ptr(cache->percpu, smp_processor_id());
-   if (!chp->first)
+   chpfirst = __this_cpu_read(cache->percpu->first);
+   if (!chpfirst)
INIT_LIST_HEAD(new_item);
else /* put on front */
-   list_add_tail(new_item, chp->first);
-   chp->first = new_item;
-   chp->count++;
+   list_add_tail(new_item, chpfirst);
 
-   if (chp->count < RDS_IB_RECYCLE_BATCH_COUNT)
+   __this_cpu_write(chpfirst, new_item);
+   __this_cpu_inc(cache->percpu->count);
+
+   if (__this_cpu_read(cache->percpu->count) < RDS_IB_RECYCLE_BATCH_COUNT)
goto end;
 
/*
@@ -443,12 +444,13 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
do {
old = xchg(&cache->xfer, NULL);
if (old)
-   list_splice_entire_tail(old, chp->first);
-   old = cmpxchg(&cache->xfer, NULL, chp->first);
+   list_splice_entire_tail(old, chpfirst);
+   old = cmpxchg(&cache->xfer, NULL, chpfirst);
} while (old);
 
-   chp->first = NULL;
-   chp->count = 0;
+
+   __this_cpu_write(chpfirst, NULL);
+   __this_cpu_write(cache->percpu->count, 0);
 end:
local_irq_restore(flags);
 }
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 3/9] net: xfrm: use __this_cpu_read per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
v4:
  derefrence pointer before reading to avoid compile warning.
---
 net/xfrm/xfrm_ipcomp.c |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index e5246fb..2906d52 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -276,18 +276,16 @@ static struct crypto_comp * __percpu 
*ipcomp_alloc_tfms(const char *alg_name)
struct crypto_comp * __percpu *tfms;
int cpu;
 
-   /* This can be any valid CPU ID so we don't need locking. */
-   cpu = raw_smp_processor_id();
 
list_for_each_entry(pos, &ipcomp_tfms_list, list) {
struct crypto_comp *tfm;
 
-   tfms = pos->tfms;
-   tfm = *per_cpu_ptr(tfms, cpu);
+   /* This can be any valid CPU ID so we don't need locking. */
+   tfm = __this_cpu_read(*pos->tfms);
 
if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++;
-   return tfms;
+   return pos->tfms;
}
}
 
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 5/9] kernel: padata : use __this_cpu_read per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 

For bottom halves off, __this_cpu_read is better.

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
no changes vs v4.
---
 kernel/padata.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 89fe3d1..072f4ee 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -171,7 +171,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
 {
int cpu, num_cpus;
unsigned int next_nr, next_index;
-   struct padata_parallel_queue *queue, *next_queue;
+   struct padata_parallel_queue *next_queue;
struct padata_priv *padata;
struct padata_list *reorder;
 
@@ -204,8 +204,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
goto out;
}
 
-   queue = per_cpu_ptr(pd->pqueue, smp_processor_id());
-   if (queue->cpu_index == next_queue->cpu_index) {
+   if (__this_cpu_read(pd->pqueue->cpu_index) == next_queue->cpu_index) {
padata = ERR_PTR(-ENODATA);
goto out;
}
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-11-12 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
Acked-by: Christoph Lameter 
---
no changes vs v3,v2.
---
 kernel/rcutree.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 74df86b..441b945 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1960,7 +1960,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
struct rcu_node *rnp_old = NULL;
 
/* Funnel through hierarchy to reduce memory contention. */
-   rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
+   rnp = __this_cpu_read(rsp->rda->mynode);
for (; rnp != NULL; rnp = rnp->parent) {
ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
  !raw_spin_trylock(&rnp->fqslock);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 

just use more faster this_cpu_ptr instead of per_cpu_ptr(p, smp_processor_id());


Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
no changes vs v3,v2.
---
 net/openvswitch/datapath.c |4 ++--
 net/openvswitch/vport.c|5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 4c4b62c..77d16a5 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -208,7 +208,7 @@ void ovs_dp_process_received_packet(struct vport *p, struct 
sk_buff *skb)
int error;
int key_len;
 
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
/* Extract flow from 'skb' into 'key'. */
error = ovs_flow_extract(skb, p->port_no, &key, &key_len);
@@ -282,7 +282,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
return 0;
 
 err:
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
u64_stats_update_begin(&stats->sync);
stats->n_lost++;
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 03779e8..70af0be 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -333,8 +333,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff 
*skb)
 {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
-
+   stats = this_cpu_ptr(vport->percpu_stats);
u64_stats_update_begin(&stats->sync);
stats->rx_packets++;
stats->rx_bytes += skb->len;
@@ -359,7 +358,7 @@ int ovs_vport_send(struct vport *vport, struct sk_buff *skb)
if (likely(sent)) {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
+   stats = this_cpu_ptr(vport->percpu_stats);
 
u64_stats_update_begin(&stats->sync);
stats->tx_packets++;
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 7/9] trace: use this_cpu_ptr per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 

typeof(&buffer) is a pointer to array of 1024 char, or char (*)[1024].
But, typeof(&buffer[0]) is a pointer to char which match the return type of 
get_trace_buf().
As well-known, the value of &buffer is equal to &buffer[0].
so return this_cpu_ptr(&percpu_buffer->buffer[0]) can avoid type cast. 

Signed-off-by: Shan Wei 
---
v4: avoid type cast using &percpu_buffer->buffer[0].
---
 kernel/trace/blktrace.c |2 +-
 kernel/trace/trace.c|5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c0bd030..71259e2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const char 
*fmt, ...)
return;
 
local_irq_save(flags);
-   buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
+   buf = this_cpu_ptr(bt->msg_data);
va_start(args, fmt);
n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
va_end(args);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 31e4f55..65cb003 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1495,7 +1495,6 @@ static struct trace_buffer_struct 
*trace_percpu_nmi_buffer;
 static char *get_trace_buf(void)
 {
struct trace_buffer_struct *percpu_buffer;
-   struct trace_buffer_struct *buffer;
 
/*
 * If we have allocated per cpu buffers, then we do not
@@ -1513,9 +1512,7 @@ static char *get_trace_buf(void)
if (!percpu_buffer)
return NULL;
 
-   buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
-
-   return buffer->buffer;
+   return this_cpu_ptr(&percpu_buffer->buffer[0]);
 }
 
 static int alloc_percpu_trace_buffer(void)
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 8/9] clocksource: use this_cpu_ptr per-cpu helper

2012-11-12 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
no changes vs v3,v2.
---
 drivers/clocksource/arm_generic.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/clocksource/arm_generic.c 
b/drivers/clocksource/arm_generic.c
index c4d9f95..cb445ab 100644
--- a/drivers/clocksource/arm_generic.c
+++ b/drivers/clocksource/arm_generic.c
@@ -224,7 +224,7 @@ int __init arm_generic_timer_init(void)
lpj_fine = arch_timer_rate / HZ;
 
/* Immediately configure the timer on the boot CPU */
-   arch_timer_setup(per_cpu_ptr(&arch_timer_evt, smp_processor_id()));
+   arch_timer_setup(this_cpu_ptr(&arch_timer_evt));
 
register_cpu_notifier(&arch_timer_cpu_nb);
 
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 9/9] net: batman-adv: use per_cpu_add helper

2012-11-12 Thread Shan Wei
From: Shan Wei 

this_cpu_add is an atomic operation.
and be more faster than per_cpu_ptr operation.

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
v4: no changes vs v3.
---
 net/batman-adv/main.h |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 897ba6a..3aef5b2 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -263,9 +263,7 @@ static inline bool batadv_has_timed_out(unsigned long 
timestamp,
 static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx,
  size_t count)
 {
-   int cpu = get_cpu();
-   per_cpu_ptr(bat_priv->bat_counters, cpu)[idx] += count;
-   put_cpu();
+   this_cpu_add(bat_priv->bat_counters[idx], count);
 }
 
 #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1)
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 3/9] net: xfrm: use __this_cpu_read per-cpu helper

2012-11-13 Thread Shan Wei
Steffen Klassert said, at 2012/11/13 15:21:
> 
> This should just fetch the tfm pointer, so why exactly __this_cpu_read
> is better than __this_cpu_ptr? Please keep in mind that performance is
> not the most important thing here. It's much more important that it
> works in any case.
 
[0/9] describes why we should submit this series patches.
you are not included in original mail.

this_cpu_ptr relocates and address. this_cpu_read() relocates the address
and performs the fetch. If you want to operate on rda(defined as per_cpu) 
then you can only use this_cpu_ptr. this_cpu_read() saves you more instructions
since it can do the relocation and the fetch in one instruction.

More info, please refer to http://www.spinics.net/lists/kernel/msg1435153.html

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [B.A.T.M.A.N.] [PATCH v4 9/9] net: batman-adv: use per_cpu_add helper

2012-11-13 Thread Shan Wei
Marek Lindner said, at 2012/11/13 17:55:
>>  net/batman-adv/main.h |4 +---
>>  1 files changed, 1 insertions(+), 3 deletions(-)
> 
> Applied in our tree (revision f8b19e1). We will pass along this patch through 
> our standard workflow. No need to resend this patch in the future.

OK thanks~

> 
> Thanks,
> Marek
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5 3/9] net: xfrm: use __this_cpu_read per-cpu helper

2012-11-13 Thread Shan Wei
Steffen Klassert said, at 2012/11/13 18:48:
> 
> Ok, so please add a commit message to describe your changes.
> 
> Thanks.
> 

[PATCH v5] net: xfrm: use __this_cpu_read per-cpu helper

this_cpu_ptr/this_cpu_read is faster than per_cpu_ptr(p, smp_processor_id()) 
and can reduce  memory accesses.
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following. 

this_cpu_ptr relocates and address. this_cpu_read() relocates the address
and performs the fetch. this_cpu_read() saves you more instructions
since it can do the relocation and the fetch in one instruction.

per_cpu_ptr(p, smp_processor_id()):
  1e:   65 8b 04 25 00 00 00 00 mov%gs:0x0,%eax
  26:   48 98   cltq
  28:   31 f6   xor%esi,%esi
  2a:   48 c7 c7 00 00 00 00mov$0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00 mov0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00 movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)
  1e:   65 48 03 14 25 00 00 00 00  add%gs:0x0,%rdx
  27:   31 f6   xor%esi,%esi
  29:   c7 42 04 14 00 00 00movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00mov$0x0,%rdi

Signed-off-by: Shan Wei 
---
 net/xfrm/xfrm_ipcomp.c |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index e5246fb..2906d52 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -276,18 +276,16 @@ static struct crypto_comp * __percpu 
*ipcomp_alloc_tfms(const char *alg_name)
struct crypto_comp * __percpu *tfms;
int cpu;
 
-   /* This can be any valid CPU ID so we don't need locking. */
-   cpu = raw_smp_processor_id();
 
list_for_each_entry(pos, &ipcomp_tfms_list, list) {
struct crypto_comp *tfm;
 
-   tfms = pos->tfms;
-   tfm = *per_cpu_ptr(tfms, cpu);
+   /* This can be any valid CPU ID so we don't need locking. */
+   tfm = __this_cpu_read(*pos->tfms);
 
if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++;
-   return tfms;
+   return pos->tfms;
}
}
 
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
Christoph Lameter said, at 2012/11/3 1:46:
>>  u64_stats_update_begin(&stats->sync);
>>  stats->tx_packets++;
> 
> Use this_cpu_inc(vport->percpu_stats->packets) here?
 
Lots of network drivers use u64_stats_sync infrastructure for statistics
on 32bit or 64bit hosts no matter how many members in per-cpu variable. 

keep them be consistent, so no plan to change them.

Thanks 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
Christoph Lameter said, at 2012/11/9 1:18:
> On Thu, 8 Nov 2012, Shan Wei wrote:
> 
>> Christoph Lameter said, at 2012/11/3 1:46:
>>>>u64_stats_update_begin(&stats->sync);
>>>>stats->tx_packets++;
>>>
>>> Use this_cpu_inc(vport->percpu_stats->packets) here?
>>
>> Lots of network drivers use u64_stats_sync infrastructure for statistics
> 
> So they would all have an advantage from the patch.

I will try to do the optimizing next time in another patchset which not included
in this series patchset.

I will submit v3 version of this series after testing today.

Thanks

 
 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/9 v3] use efficient this_cpu_* helper

2012-11-08 Thread Shan Wei
this_cpu_ptr/this_cpu_read is faster than per_cpu_ptr(p, smp_processor_id()) 
and can reduce  memory accesses.
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following. 

this_cpu_ptr relocates and address. this_cpu_read() relocates the address
and performs the fetch. If you want to operate on rda(defined as per_cpu) 
then you can only use this_cpu_ptr. this_cpu_read() saves you more instructions
since it can do the relocation and the fetch in one instruction.

per_cpu_ptr(p, smp_processor_id()):
  1e:   65 8b 04 25 00 00 00 00 mov%gs:0x0,%eax
  26:   48 98   cltq
  28:   31 f6   xor%esi,%esi
  2a:   48 c7 c7 00 00 00 00mov$0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00 mov0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00 movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)
  1e:   65 48 03 14 25 00 00 00 00  add%gs:0x0,%rdx
  27:   31 f6   xor%esi,%esi
  29:   c7 42 04 14 00 00 00movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00mov$0x0,%rdi


Changelog V3:
1. use this_cpu_read directly read member of per-cpu variable,
   so that droping the this_cpu_ptr operation.
2. for preemption off and bottom halves off case,
   use __this_cpu_read instead of this_cpu_read. 

Changelog V2:
1. Use this_cpu_read directly instead of ref to field of per-cpu variable.
2. Patch5 about ftrace is dropped from this series.
3. Add new patch9 to replace get_cpu;per_cpu_ptr;put_cpu with this_cpu_add opt.
4. For preemption disable case, use __this_cpu_read instead.
  

$ git diff --stat 7da716aee2532399e213a14f656d304098f67a11..
 drivers/clocksource/arm_generic.c |2 +-
 kernel/padata.c   |5 ++---
 kernel/rcutree.c  |2 +-
 kernel/trace/blktrace.c   |2 +-
 kernel/trace/trace.c  |5 +
 net/batman-adv/main.h |4 +---
 net/core/flow.c   |4 +---
 net/openvswitch/datapath.c|4 ++--
 net/openvswitch/vport.c   |5 ++---
 net/rds/ib_recv.c |2 +-
 net/xfrm/xfrm_ipcomp.c|7 ++-
 11 files changed, 15 insertions(+), 27 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/9] net: core: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 

flush_tasklet is a struct, not a pointer in percpu var.
so use this_cpu_ptr to get the member pointer.

Signed-off-by: Shan Wei 
---
 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..b0901ee 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/9] net: rds: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
no changes vs v2.
---
 net/rds/ib_recv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 8d19491..a4a5064 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -423,7 +423,7 @@ static void rds_ib_recv_cache_put(struct list_head 
*new_item,
 
local_irq_save(flags);
 
-   chp = per_cpu_ptr(cache->percpu, smp_processor_id());
+   chp = this_cpu_ptr(cache->percpu);
if (!chp->first)
INIT_LIST_HEAD(new_item);
else /* put on front */
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 3/9] net: xfrm: use __this_cpu_read per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
v3 fix compile warning:
net/xfrm/xfrm_ipcomp.c: In function 'ipcomp_alloc_tfms':
net/xfrm/xfrm_ipcomp.c:285: warning: assignment from incompatible pointer type

---
 net/xfrm/xfrm_ipcomp.c |7 ++-
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index e5246fb..898c899 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -276,18 +276,15 @@ static struct crypto_comp * __percpu 
*ipcomp_alloc_tfms(const char *alg_name)
struct crypto_comp * __percpu *tfms;
int cpu;
 
-   /* This can be any valid CPU ID so we don't need locking. */
-   cpu = raw_smp_processor_id();
 
list_for_each_entry(pos, &ipcomp_tfms_list, list) {
struct crypto_comp *tfm;
 
-   tfms = pos->tfms;
-   tfm = *per_cpu_ptr(tfms, cpu);
+   tfm = (struct crypto_comp *) __this_cpu_read(pos->tfms);
 
if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++;
-   return tfms;
+   return pos->tfms;
}
}
 
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 

just use more faster this_cpu_ptr instead of per_cpu_ptr(p, smp_processor_id());


Signed-off-by: Shan Wei 
---
no changes vs v2.
---
 net/openvswitch/datapath.c |4 ++--
 net/openvswitch/vport.c|5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 4c4b62c..77d16a5 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -208,7 +208,7 @@ void ovs_dp_process_received_packet(struct vport *p, struct 
sk_buff *skb)
int error;
int key_len;
 
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
/* Extract flow from 'skb' into 'key'. */
error = ovs_flow_extract(skb, p->port_no, &key, &key_len);
@@ -282,7 +282,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
return 0;
 
 err:
-   stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+   stats = this_cpu_ptr(dp->stats_percpu);
 
u64_stats_update_begin(&stats->sync);
stats->n_lost++;
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 03779e8..70af0be 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -333,8 +333,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff 
*skb)
 {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
-
+   stats = this_cpu_ptr(vport->percpu_stats);
u64_stats_update_begin(&stats->sync);
stats->rx_packets++;
stats->rx_bytes += skb->len;
@@ -359,7 +358,7 @@ int ovs_vport_send(struct vport *vport, struct sk_buff *skb)
if (likely(sent)) {
struct vport_percpu_stats *stats;
 
-   stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
+   stats = this_cpu_ptr(vport->percpu_stats);
 
u64_stats_update_begin(&stats->sync);
stats->tx_packets++;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 5/9] kernel: padata : use __this_cpu_read per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 

For bottom halves off, __this_cpu_read is better.

Signed-off-by: Shan Wei 
---
v3: use __this_cpu_read instead of this_cpu_read.
---
 kernel/padata.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 89fe3d1..072f4ee 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -171,7 +171,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
 {
int cpu, num_cpus;
unsigned int next_nr, next_index;
-   struct padata_parallel_queue *queue, *next_queue;
+   struct padata_parallel_queue *next_queue;
struct padata_priv *padata;
struct padata_list *reorder;
 
@@ -204,8 +204,7 @@ static struct padata_priv *padata_get_next(struct 
parallel_data *pd)
goto out;
}
 
-   queue = per_cpu_ptr(pd->pqueue, smp_processor_id());
-   if (queue->cpu_index == next_queue->cpu_index) {
+   if (__this_cpu_read(pd->pqueue->cpu_index) == next_queue->cpu_index) {
padata = ERR_PTR(-ENODATA);
goto out;
}
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-11-08 Thread Shan Wei
From: Shan Wei 

Signed-off-by: Shan Wei 
---
no changes vs v2.
---
 kernel/rcutree.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index 74df86b..441b945 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1960,7 +1960,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
struct rcu_node *rnp_old = NULL;
 
/* Funnel through hierarchy to reduce memory contention. */
-   rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
+   rnp = __this_cpu_read(rsp->rda->mynode);
for (; rnp != NULL; rnp = rnp->parent) {
ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
  !raw_spin_trylock(&rnp->fqslock);
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
---
v3:
  directly return member address of per-cpu variable.
---
 kernel/trace/blktrace.c |2 +-
 kernel/trace/trace.c|5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c0bd030..71259e2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const char 
*fmt, ...)
return;
 
local_irq_save(flags);
-   buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
+   buf = this_cpu_ptr(bt->msg_data);
va_start(args, fmt);
n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
va_end(args);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 31e4f55..65cb003 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1495,7 +1495,6 @@ static struct trace_buffer_struct 
*trace_percpu_nmi_buffer;
 static char *get_trace_buf(void)
 {
struct trace_buffer_struct *percpu_buffer;
-   struct trace_buffer_struct *buffer;
 
/*
 * If we have allocated per cpu buffers, then we do not
@@ -1513,9 +1512,7 @@ static char *get_trace_buf(void)
if (!percpu_buffer)
return NULL;
 
-   buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
-
-   return buffer->buffer;
+   return (char *)this_cpu_ptr(&percpu_buffer->buffer);
 }
 
 static int alloc_percpu_trace_buffer(void)
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 8/9] clocksource: use this_cpu_ptr per-cpu helper

2012-11-08 Thread Shan Wei
From: Shan Wei 


Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
no changes vs v2.
---
 drivers/clocksource/arm_generic.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/clocksource/arm_generic.c 
b/drivers/clocksource/arm_generic.c
index c4d9f95..cb445ab 100644
--- a/drivers/clocksource/arm_generic.c
+++ b/drivers/clocksource/arm_generic.c
@@ -224,7 +224,7 @@ int __init arm_generic_timer_init(void)
lpj_fine = arch_timer_rate / HZ;
 
/* Immediately configure the timer on the boot CPU */
-   arch_timer_setup(per_cpu_ptr(&arch_timer_evt, smp_processor_id()));
+   arch_timer_setup(this_cpu_ptr(&arch_timer_evt));
 
register_cpu_notifier(&arch_timer_cpu_nb);
 
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 9/9] net: batman-adv: use per_cpu_add helper

2012-11-08 Thread Shan Wei
From: Shan Wei 

this_cpu_add is an atomic operation.
and be more faster than per_cpu_ptr operation.

Signed-off-by: Shan Wei 
Reviewed-by: Christoph Lameter 
---
v3: change commit message.
---
 net/batman-adv/main.h |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 897ba6a..3aef5b2 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -263,9 +263,7 @@ static inline bool batadv_has_timed_out(unsigned long 
timestamp,
 static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx,
  size_t count)
 {
-   int cpu = get_cpu();
-   per_cpu_ptr(bat_priv->bat_counters, cpu)[idx] += count;
-   put_cpu();
+   this_cpu_add(bat_priv->bat_counters[idx], count);
 }
 
 #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1)
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 0/9 v4] use efficient this_cpu_* helper

2012-11-16 Thread Shan Wei
Hi Tejun Heo:

Tejun Heo said, at 2012/11/15 22:53:
> On Thu, Nov 15, 2012 at 02:19:38PM +, Christoph Lameter wrote:
>> Tejon: Could you pick up this patchset?
> 
> Sure, but, Shan, when posting patchset, please make the patches
> replies to the head message; otherwise, it's pretty difficult to track
> what's going on with the patchset as a whole.  I see that some patches
> are being picked up by respective subsystems.  If you have patches
> left, please let me know.

OK, next time i will do as you suggest.

This patchset include more subsystem, i.e network, rcu, trace.
The best way to avoid code conflict is subsystem maintainer to pick them up
to their code tree. I will remind them in each patch that not yet applied and 
add you to the receiver list.

Best Regards
Shan Wei

> 
> Thanks.
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())

2012-11-16 Thread Shan Wei
Shan Wei said, at 2012/11/13 9:52:
> From: Shan Wei 
> 
> Signed-off-by: Shan Wei 
> Acked-by: Christoph Lameter 

Paul, would you like to pick it up to your tree?

> ---
> no changes vs v3,v2.
> ---
>  kernel/rcutree.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/rcutree.c b/kernel/rcutree.c
> index 74df86b..441b945 100644
> --- a/kernel/rcutree.c
> +++ b/kernel/rcutree.c
> @@ -1960,7 +1960,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
>   struct rcu_node *rnp_old = NULL;
>  
>   /* Funnel through hierarchy to reduce memory contention. */
> - rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
> + rnp = __this_cpu_read(rsp->rda->mynode);
>   for (; rnp != NULL; rnp = rnp->parent) {
>   ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
> !raw_spin_trylock(&rnp->fqslock);
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 7/9] trace: use this_cpu_ptr per-cpu helper

2012-11-16 Thread Shan Wei
Shan Wei said, at 2012/11/13 9:53:
> From: Shan Wei 
> 
> typeof(&buffer) is a pointer to array of 1024 char, or char (*)[1024].
> But, typeof(&buffer[0]) is a pointer to char which match the return type of 
> get_trace_buf().
> As well-known, the value of &buffer is equal to &buffer[0].
> so return this_cpu_ptr(&percpu_buffer->buffer[0]) can avoid type cast. 
> 
> Signed-off-by: Shan Wei 

Steven Rostedt,  would you like to pick it up to your tree?

> ---
> v4: avoid type cast using &percpu_buffer->buffer[0].
> ---
>  kernel/trace/blktrace.c |2 +-
>  kernel/trace/trace.c|5 +
>  2 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index c0bd030..71259e2 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const 
> char *fmt, ...)
>   return;
>  
>   local_irq_save(flags);
> - buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
> + buf = this_cpu_ptr(bt->msg_data);
>   va_start(args, fmt);
>   n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
>   va_end(args);
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 31e4f55..65cb003 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -1495,7 +1495,6 @@ static struct trace_buffer_struct 
> *trace_percpu_nmi_buffer;
>  static char *get_trace_buf(void)
>  {
>   struct trace_buffer_struct *percpu_buffer;
> - struct trace_buffer_struct *buffer;
>  
>   /*
>* If we have allocated per cpu buffers, then we do not
> @@ -1513,9 +1512,7 @@ static char *get_trace_buf(void)
>   if (!percpu_buffer)
>   return NULL;
>  
> - buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
> -
> - return buffer->buffer;
> + return this_cpu_ptr(&percpu_buffer->buffer[0]);
>  }
>  
>  static int alloc_percpu_trace_buffer(void)
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper

2012-11-16 Thread Shan Wei
Shan Wei said, at 2012/11/13 9:52:
> From: Shan Wei 
> 
> just use more faster this_cpu_ptr instead of per_cpu_ptr(p, 
> smp_processor_id());
> 
> 
> Signed-off-by: Shan Wei 
> Reviewed-by: Christoph Lameter 

Jesse Gross,  would you like to pick it up to your tree?

> ---
> no changes vs v3,v2.
> ---
>  net/openvswitch/datapath.c |4 ++--
>  net/openvswitch/vport.c|5 ++---
>  2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
> index 4c4b62c..77d16a5 100644
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
> @@ -208,7 +208,7 @@ void ovs_dp_process_received_packet(struct vport *p, 
> struct sk_buff *skb)
>   int error;
>   int key_len;
>  
> - stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
> + stats = this_cpu_ptr(dp->stats_percpu);
>  
>   /* Extract flow from 'skb' into 'key'. */
>   error = ovs_flow_extract(skb, p->port_no, &key, &key_len);
> @@ -282,7 +282,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff 
> *skb,
>   return 0;
>  
>  err:
> - stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
> + stats = this_cpu_ptr(dp->stats_percpu);
>  
>   u64_stats_update_begin(&stats->sync);
>   stats->n_lost++;
> diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
> index 03779e8..70af0be 100644
> --- a/net/openvswitch/vport.c
> +++ b/net/openvswitch/vport.c
> @@ -333,8 +333,7 @@ void ovs_vport_receive(struct vport *vport, struct 
> sk_buff *skb)
>  {
>   struct vport_percpu_stats *stats;
>  
> - stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
> -
> + stats = this_cpu_ptr(vport->percpu_stats);
>   u64_stats_update_begin(&stats->sync);
>   stats->rx_packets++;
>   stats->rx_bytes += skb->len;
> @@ -359,7 +358,7 @@ int ovs_vport_send(struct vport *vport, struct sk_buff 
> *skb)
>   if (likely(sent)) {
>   struct vport_percpu_stats *stats;
>  
> - stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
> + stats = this_cpu_ptr(vport->percpu_stats);
>  
>   u64_stats_update_begin(&stats->sync);
>   stats->tx_packets++;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-11-16 Thread Shan Wei
Shan Wei said, at 2012/11/13 9:51:
> From: Shan Wei 
> 
> flush_tasklet is a struct, not a pointer in percpu var.
> so use this_cpu_ptr to get the member pointer.
> 
> Signed-off-by: Shan Wei 
> Reviewed-by: Christoph Lameter 

David Miller,  would you like to pick it up to your net-next tree?

> ---
> no changes vs v3.
> ---
>  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..b0901ee 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);
>  }
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 2/9] net: rds: use this_cpu_* per-cpu helper

2012-11-16 Thread Shan Wei
Shan Wei said, at 2012/11/13 9:52:
> From: Shan Wei 
> 
> 
> Signed-off-by: Shan Wei 
> Reviewed-by: Christoph Lameter 

David Miller,  would you like to pick it up to your net-next tree?


> ---
> v4:
> 1. add missing __percpu annotations.
> 2. [read|write]ing fields of struct rds_ib_cache_head
> using __this_cpu_* operation, drop per_cpu_ptr.
> ---
>  net/rds/ib.h  |2 +-
>  net/rds/ib_recv.c |   24 +---
>  2 files changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/net/rds/ib.h b/net/rds/ib.h
> index 8d2b3d5..7280ab8 100644
> --- a/net/rds/ib.h
> +++ b/net/rds/ib.h
> @@ -50,7 +50,7 @@ struct rds_ib_cache_head {
>  };
>  
>  struct rds_ib_refill_cache {
> - struct rds_ib_cache_head *percpu;
> + struct rds_ib_cache_head __percpu *percpu;
>   struct list_head *xfer;
>   struct list_head *ready;
>  };
> diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
> index 8d19491..8c5bc85 100644
> --- a/net/rds/ib_recv.c
> +++ b/net/rds/ib_recv.c
> @@ -418,20 +418,21 @@ static void rds_ib_recv_cache_put(struct list_head 
> *new_item,
>struct rds_ib_refill_cache *cache)
>  {
>   unsigned long flags;
> - struct rds_ib_cache_head *chp;
>   struct list_head *old;
> + struct list_head __percpu *chpfirst;
>  
>   local_irq_save(flags);
>  
> - chp = per_cpu_ptr(cache->percpu, smp_processor_id());
> - if (!chp->first)
> + chpfirst = __this_cpu_read(cache->percpu->first);
> + if (!chpfirst)
>   INIT_LIST_HEAD(new_item);
>   else /* put on front */
> - list_add_tail(new_item, chp->first);
> - chp->first = new_item;
> - chp->count++;
> + list_add_tail(new_item, chpfirst);
>  
> - if (chp->count < RDS_IB_RECYCLE_BATCH_COUNT)
> + __this_cpu_write(chpfirst, new_item);
> + __this_cpu_inc(cache->percpu->count);
> +
> + if (__this_cpu_read(cache->percpu->count) < RDS_IB_RECYCLE_BATCH_COUNT)
>   goto end;
>  
>   /*
> @@ -443,12 +444,13 @@ static void rds_ib_recv_cache_put(struct list_head 
> *new_item,
>   do {
>   old = xchg(&cache->xfer, NULL);
>   if (old)
> - list_splice_entire_tail(old, chp->first);
> - old = cmpxchg(&cache->xfer, NULL, chp->first);
> + list_splice_entire_tail(old, chpfirst);
> + old = cmpxchg(&cache->xfer, NULL, chpfirst);
>   } while (old);
>  
> - chp->first = NULL;
> - chp->count = 0;
> +
> + __this_cpu_write(chpfirst, NULL);
> + __this_cpu_write(cache->percpu->count, 0);
>  end:
>   local_irq_restore(flags);
>  }
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] trace: use __this_cpu_inc/dec operation instead of __get_cpu_var

2012-11-18 Thread Shan Wei
From: Shan Wei 

__this_cpu_inc_return() or __this_cpu_dec generates a single instruction,
which is faster than __get_cpu_var operation.

Signed-off-by: Shan Wei 
---
 kernel/trace/trace.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 18c0aa8..3795694 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1313,7 +1313,7 @@ static void __ftrace_trace_stack(struct ring_buffer 
*buffer,
 */
preempt_disable_notrace();
 
-   use_stack = ++__get_cpu_var(ftrace_stack_reserve);
+   use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
/*
 * We don't need any atomic variables, just a barrier.
 * If an interrupt comes in, we don't care, because it would
@@ -1367,7 +1367,7 @@ static void __ftrace_trace_stack(struct ring_buffer 
*buffer,
  out:
/* Again, don't let gcc optimize things here */
barrier();
-   __get_cpu_var(ftrace_stack_reserve)--;
+   __this_cpu_dec(ftrace_stack_reserve);
preempt_enable_notrace();
 
 }
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH buf-fix] kernel, range: fix broken mtrr_cleanup

2013-06-09 Thread Shan Wei
From: Samuel Liao 


commit fbe06b7bae7c9cf6ab05168fce5ee93b2f4bae7c broken the mtrr_cleanup
due to return incorrect merged range. this patch remove the empty range
by swapping with the last.

Error messages:
Jun  9 14:06:18 kernel: [0.00] *BAD*gran_size: 64K   chunk_size: 64K
 num_reg: 4  lose cover RAM: -0G
Jun  9 14:06:18 kernel: [0.00] *BAD*gran_size: 64K   chunk_size: 128K   
 num_reg: 4  lose cover RAM: -0G
Jun  9 14:06:18 kernel: [0.00] *BAD*gran_size: 64K   chunk_size: 256K   
 num_reg: 4  lose cover RAM: -0G
Jun  9 14:06:18 kernel: [0.00] *BAD*gran_size: 64K   chunk_size: 512K   
 num_reg: 4  lose cover RAM: -0G


Signed-off-by: Samuel Liao 
---
 kernel/range.c | 15 ++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/kernel/range.c b/kernel/range.c
index eb911db..b723697 100644
--- a/kernel/range.c
+++ b/kernel/range.c
@@ -48,11 +48,18 @@ int add_range_with_merge(struct range *range, int az, int 
nr_range,
final_start = min(range[i].start, start);
final_end = max(range[i].end, end);
 
+   if (final_start == range[i].start && final_end == range[i].end)
+   return nr_range;
+
/* clear it and add it back for further merge */
-   range[i].start = 0;
-   range[i].end =  0;
-   return add_range_with_merge(range, az, nr_range,
-   final_start, final_end);
+   nr_range -= 1;
+   if (i != nr_range) {
+   range[i].start = range[nr_range].start;
+   range[i].end = range[nr_range].end;
+   }
+   range[nr_range].start = 0;
+   range[nr_range].end =  0;
+   i = -1;
}
 
/* Need to add it: */
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] drivers: ddm72xx: remove last usage of NIPQUAD and NIP6

2012-11-22 Thread Shan Wei
From: Shan Wei 

commit cf4ca4874fc45 removed the definition of NIPQUAD and NIPQUAD_FMT,
and NIP6 also is out of date.

Because DEBUG_SDU is not defined in gdm_wimax.h, no error message when compiling
this code.

commit cf4ca4874fc45166198424384275f443a672d0b7
Author: Joe Perches 
Date:   Mon Aug 9 17:20:20 2010 -0700

kernel.h: remove unused NIPQUAD and NIPQUAD_FMT
There are no more uses of NIPQUAD or NIPQUAD_FMT.  Remove the definitions.

Signed-off-by: Shan Wei 
---
 drivers/staging/gdm72xx/gdm_wimax.c |   10 +-
 1 files changed, 1 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c 
b/drivers/staging/gdm72xx/gdm_wimax.c
index 6cb8107..c0ec4d0 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -166,21 +166,13 @@ static void dump_eth_packet(const char *title, u8 *data, 
int len)
get_ip_protocol_name(ip_protocol),
get_port_name(port));
 
-   #if 1
if (!(data[0] == 0xff && data[1] == 0xff)) {
if (protocol == ETH_P_IP) {
-   printk(KERN_DEBUG " src=%u.%u.%u.%u\n",
-   NIPQUAD(ih->saddr));
+   printk(KERN_DEBUG " src=%pI4\n", &ih->saddr);
} else if (protocol == ETH_P_IPV6) {
-   #ifdef NIP6
-   printk(KERN_DEBUG " src=%x:%x:%x:%x:%x:%x:%x:%x\n",
-   NIP6(ih->saddr));
-   #else
printk(KERN_DEBUG " src=%pI6\n", &ih->saddr);
-   #endif
}
}
-   #endif
 
#if (DUMP_PACKET & DUMP_SDU_ALL)
printk_hex(data, len);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] drivers: gdm72xx: remove last usage of NIPQUAD and NIP6

2012-11-22 Thread Shan Wei
From: Shan Wei 

commit cf4ca4874fc45 removed the definition of NIPQUAD and NIPQUAD_FMT,
and NIP6 also is out of date.

Because DEBUG_SDU is not defined in gdm_wimax.h, no error message when compiling
this code.

commit cf4ca4874fc45166198424384275f443a672d0b7
Author: Joe Perches 
Date:   Mon Aug 9 17:20:20 2010 -0700

kernel.h: remove unused NIPQUAD and NIPQUAD_FMT
There are no more uses of NIPQUAD or NIPQUAD_FMT.  Remove the definitions.

Signed-off-by: Shan Wei 
---
 drivers/staging/gdm72xx/gdm_wimax.c |   10 +-
 1 files changed, 1 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c 
b/drivers/staging/gdm72xx/gdm_wimax.c
index 6cb8107..c0ec4d0 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -166,21 +166,13 @@ static void dump_eth_packet(const char *title, u8 *data, 
int len)
get_ip_protocol_name(ip_protocol),
get_port_name(port));
 
-   #if 1
if (!(data[0] == 0xff && data[1] == 0xff)) {
if (protocol == ETH_P_IP) {
-   printk(KERN_DEBUG " src=%u.%u.%u.%u\n",
-   NIPQUAD(ih->saddr));
+   printk(KERN_DEBUG " src=%pI4\n", &ih->saddr);
} else if (protocol == ETH_P_IPV6) {
-   #ifdef NIP6
-   printk(KERN_DEBUG " src=%x:%x:%x:%x:%x:%x:%x:%x\n",
-   NIP6(ih->saddr));
-   #else
printk(KERN_DEBUG " src=%pI6\n", &ih->saddr);
-   #endif
}
}
-   #endif
 
#if (DUMP_PACKET & DUMP_SDU_ALL)
printk_hex(data, len);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] tracing: Use __this_cpu_inc/ dec operation instead of __get_cpu_var

2013-02-03 Thread tip-bot for Shan Wei
Commit-ID:  821465295b36136998ef294fe176fba4e09c1cd9
Gitweb: http://git.kernel.org/tip/821465295b36136998ef294fe176fba4e09c1cd9
Author: Shan Wei 
AuthorDate: Mon, 19 Nov 2012 13:21:01 +0800
Committer:  Steven Rostedt 
CommitDate: Fri, 25 Jan 2013 20:36:54 -0500

tracing: Use __this_cpu_inc/dec operation instead of __get_cpu_var

__this_cpu_inc_return() or __this_cpu_dec generates a single instruction,
which is faster than __get_cpu_var operation.

Link: http://lkml.kernel.org/r/50a9c1bd.1060...@gmail.com

Reviewed-by: Christoph Lameter 
Signed-off-by: Shan Wei 
Signed-off-by: Steven Rostedt 
---
 kernel/trace/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ca9b7df..07888e1 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1344,7 +1344,7 @@ static void __ftrace_trace_stack(struct ring_buffer 
*buffer,
 */
preempt_disable_notrace();
 
-   use_stack = ++__get_cpu_var(ftrace_stack_reserve);
+   use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
/*
 * We don't need any atomic variables, just a barrier.
 * If an interrupt comes in, we don't care, because it would
@@ -1398,7 +1398,7 @@ static void __ftrace_trace_stack(struct ring_buffer 
*buffer,
  out:
/* Again, don't let gcc optimize things here */
barrier();
-   __get_cpu_var(ftrace_stack_reserve)--;
+   __this_cpu_dec(ftrace_stack_reserve);
preempt_enable_notrace();
 
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] tracing: Use this_cpu_ptr per-cpu helper

2013-01-24 Thread tip-bot for Shan Wei
Commit-ID:  d8a0349c0cea477322c66ea9362f10c62fad5f62
Gitweb: http://git.kernel.org/tip/d8a0349c0cea477322c66ea9362f10c62fad5f62
Author: Shan Wei 
AuthorDate: Tue, 13 Nov 2012 09:53:04 +0800
Committer:  Steven Rostedt 
CommitDate: Mon, 21 Jan 2013 13:22:30 -0500

tracing: Use this_cpu_ptr per-cpu helper

typeof(&buffer) is a pointer to array of 1024 char, or char (*)[1024].
But, typeof(&buffer[0]) is a pointer to char which match the return type of 
get_trace_buf().
As well-known, the value of &buffer is equal to &buffer[0].
so return this_cpu_ptr(&percpu_buffer->buffer[0]) can avoid type cast.

Link: http://lkml.kernel.org/r/50a1a800.3020...@gmail.com

Reviewed-by: Christoph Lameter 
Signed-off-by: Shan Wei 
Signed-off-by: Steven Rostedt 
---
 kernel/trace/blktrace.c | 2 +-
 kernel/trace/trace.c| 5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c0bd030..71259e2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const char 
*fmt, ...)
return;
 
local_irq_save(flags);
-   buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
+   buf = this_cpu_ptr(bt->msg_data);
va_start(args, fmt);
n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
va_end(args);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 3c13e46..f8b7c62 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1517,7 +1517,6 @@ static struct trace_buffer_struct 
*trace_percpu_nmi_buffer;
 static char *get_trace_buf(void)
 {
struct trace_buffer_struct *percpu_buffer;
-   struct trace_buffer_struct *buffer;
 
/*
 * If we have allocated per cpu buffers, then we do not
@@ -1535,9 +1534,7 @@ static char *get_trace_buf(void)
if (!percpu_buffer)
return NULL;
 
-   buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
-
-   return buffer->buffer;
+   return this_cpu_ptr(&percpu_buffer->buffer[0]);
 }
 
 static int alloc_percpu_trace_buffer(void)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] tracing: Kill unused and puzzled sample code in ftrace.h

2012-12-09 Thread tip-bot for Shan Wei
Commit-ID:  1c7d66732458dc187008e3f5b2f71e019e320fc2
Gitweb: http://git.kernel.org/tip/1c7d66732458dc187008e3f5b2f71e019e320fc2
Author: Shan Wei 
AuthorDate: Sat, 3 Nov 2012 12:38:33 +0800
Committer:  Steven Rostedt 
CommitDate: Tue, 13 Nov 2012 15:51:21 -0500

tracing: Kill unused and puzzled sample code in ftrace.h

When doing per-cpu helper optimizing work, find that this code is so puzzled.
1. It's mark as comment text, maybe a sample function for guidelines
   or a todo work.
2. But, this sample code is odd where struct perf_trace_buf is nonexistent.
   commit ce71b9 delete struct perf_trace_buf definition.

   Author: Frederic Weisbecker 
   Date:   Sun Nov 22 05:26:55 2009 +0100

   tracing: Use the perf recursion protection from trace event

Is it necessary to keep there?
just compile test.

Link: http://lkml.kernel.org/r/50949fc9.6050...@gmail.com

Signed-off-by: Shan Wei 
Signed-off-by: Steven Rostedt 
---
 include/trace/ftrace.h | 73 --
 1 file changed, 73 deletions(-)

diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 698f2a8..40dc5e8 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -619,79 +619,6 @@ __attribute__((section("_ftrace_events"))) *__event_##call 
= &event_##call
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
-/*
- * Define the insertion callback to perf events
- *
- * The job is very similar to ftrace_raw_event_ except that we don't
- * insert in the ring buffer but in a perf counter.
- *
- * static void ftrace_perf_(proto)
- * {
- * struct ftrace_data_offsets_ __maybe_unused __data_offsets;
- * struct ftrace_event_call *event_call = &event_;
- * extern void perf_tp_event(int, u64, u64, void *, int);
- * struct ftrace_raw_##call *entry;
- * struct perf_trace_buf *trace_buf;
- * u64 __addr = 0, __count = 1;
- * unsigned long irq_flags;
- * struct trace_entry *ent;
- * int __entry_size;
- * int __data_size;
- * int __cpu
- * int pc;
- *
- * pc = preempt_count();
- *
- * __data_size = ftrace_get_offsets_(&__data_offsets, args);
- *
- * // Below we want to get the aligned size by taking into account
- * // the u32 field that will later store the buffer size
- * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
- *  sizeof(u64));
- * __entry_size -= sizeof(u32);
- *
- * // Protect the non nmi buffer
- * // This also protects the rcu read side
- * local_irq_save(irq_flags);
- * __cpu = smp_processor_id();
- *
- * if (in_nmi())
- * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
- * else
- * trace_buf = rcu_dereference_sched(perf_trace_buf);
- *
- * if (!trace_buf)
- * goto end;
- *
- * trace_buf = per_cpu_ptr(trace_buf, __cpu);
- *
- * // Avoid recursion from perf that could mess up the buffer
- * if (trace_buf->recursion++)
- * goto end_recursion;
- *
- * raw_data = trace_buf->buf;
- *
- * // Make recursion update visible before entering perf_tp_event
- * // so that we protect from perf recursions.
- *
- * barrier();
- *
- * //zero dead bytes from alignment to avoid stack leak to userspace:
- * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
- * entry = (struct ftrace_raw_ *)raw_data;
- * ent = &entry->ent;
- * tracing_generic_entry_update(ent, irq_flags, pc);
- * ent->type = event_call->id;
- *
- *  <- do some jobs with dynamic arrays
- *
- *   <- affect our values
- *
- * perf_tp_event(event_call->id, __addr, __count, entry,
- *  __entry_size);  <- submit them to perf counter
- *
- * }
- */
 
 #ifdef CONFIG_PERF_EVENTS
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/