* [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
@ 2012-11-02 16:01 Shan Wei
2012-11-02 17:46 ` Christoph Lameter
0 siblings, 1 reply; 11+ messages in thread
From: Shan Wei @ 2012-11-02 16:01 UTC (permalink / raw)
To: jesse, dev, NetDev, Kernel-Maillist, David Miller, cl, Shan Wei
From: Shan Wei <davidshan@tencent.com>
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 <davidshan@tencent.com>
---
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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-02 16:01 [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper Shan Wei
@ 2012-11-02 17:46 ` Christoph Lameter
2012-11-08 14:22 ` Shan Wei
0 siblings, 1 reply; 11+ messages in thread
From: Christoph Lameter @ 2012-11-02 17:46 UTC (permalink / raw)
To: Shan Wei; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
On Sat, 3 Nov 2012, Shan Wei wrote:
> +++ 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++;
Use this_cpu_inc(vport->percpu_stats->packets) here?
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-02 17:46 ` Christoph Lameter
@ 2012-11-08 14:22 ` Shan Wei
2012-11-08 17:18 ` Christoph Lameter
0 siblings, 1 reply; 11+ messages in thread
From: Shan Wei @ 2012-11-08 14:22 UTC (permalink / raw)
To: Christoph Lameter; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-08 14:22 ` Shan Wei
@ 2012-11-08 17:18 ` Christoph Lameter
2012-11-09 1:39 ` Shan Wei
0 siblings, 1 reply; 11+ messages in thread
From: Christoph Lameter @ 2012-11-08 17:18 UTC (permalink / raw)
To: Shan Wei; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-08 17:18 ` Christoph Lameter
@ 2012-11-09 1:39 ` Shan Wei
0 siblings, 0 replies; 11+ messages in thread
From: Shan Wei @ 2012-11-09 1:39 UTC (permalink / raw)
To: Christoph Lameter; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
@ 2012-10-31 11:22 Shan Wei
2012-10-31 17:39 ` Christoph Lameter
0 siblings, 1 reply; 11+ messages in thread
From: Shan Wei @ 2012-10-31 11:22 UTC (permalink / raw)
To: jesse, dev, NetDev, Kernel-Maillist, David Miller, cl
From: Shan Wei <davidshan@tencent.com>
Signed-off-by: Shan Wei <davidshan@tencent.com>
---
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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-10-31 11:22 Shan Wei
@ 2012-10-31 17:39 ` Christoph Lameter
2012-11-01 10:07 ` Shan Wei
0 siblings, 1 reply; 11+ messages in thread
From: Christoph Lameter @ 2012-10-31 17:39 UTC (permalink / raw)
To: Shan Wei; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-10-31 17:39 ` Christoph Lameter
@ 2012-11-01 10:07 ` Shan Wei
2012-11-01 14:33 ` Christoph Lameter
0 siblings, 1 reply; 11+ messages in thread
From: Shan Wei @ 2012-11-01 10:07 UTC (permalink / raw)
To: Christoph Lameter; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
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()
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-01 10:07 ` Shan Wei
@ 2012-11-01 14:33 ` Christoph Lameter
2012-11-02 1:38 ` Jesse Gross
0 siblings, 1 reply; 11+ messages in thread
From: Christoph Lameter @ 2012-11-01 14:33 UTC (permalink / raw)
To: Shan Wei; +Cc: jesse, dev, NetDev, Kernel-Maillist, David Miller
On Thu, 1 Nov 2012, Shan Wei wrote:
> But for different field in same per-cpu variable, how to guarantee n_missed
> and n_hit are from same cpu?
> this_cpu_read(dp->stats_percpu->n_missed);
> [processor changed]
> this_cpu_read(dp->stats_percpu->n_hit);
What does current guarantee that? If it is guaranteed then you can use the
__this_cpu_xxx ops.
> In addition, following usage of per_cpu_ptr can be replaced by this_cpu_read.
>
> cpu=get_cpu()
> ....
> *per_cpu_ptr(p,cpu)
> ....
> ....
> put_cpu()
Right.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-01 14:33 ` Christoph Lameter
@ 2012-11-02 1:38 ` Jesse Gross
2012-11-02 14:01 ` Christoph Lameter
0 siblings, 1 reply; 11+ messages in thread
From: Jesse Gross @ 2012-11-02 1:38 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Shan Wei, dev, NetDev, Kernel-Maillist, David Miller
On Thu, Nov 1, 2012 at 7:33 AM, Christoph Lameter <cl@linux.com> wrote:
> On Thu, 1 Nov 2012, Shan Wei wrote:
>
>> But for different field in same per-cpu variable, how to guarantee n_missed
>> and n_hit are from same cpu?
>> this_cpu_read(dp->stats_percpu->n_missed);
>> [processor changed]
>> this_cpu_read(dp->stats_percpu->n_hit);
>
> What does current guarantee that? If it is guaranteed then you can use the
> __this_cpu_xxx ops.
Preemption is disabled in all of the places where writes are done and
all of the reads are from foreign CPUs.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper
2012-11-02 1:38 ` Jesse Gross
@ 2012-11-02 14:01 ` Christoph Lameter
0 siblings, 0 replies; 11+ messages in thread
From: Christoph Lameter @ 2012-11-02 14:01 UTC (permalink / raw)
To: Jesse Gross; +Cc: Shan Wei, dev, NetDev, Kernel-Maillist, David Miller
On Thu, 1 Nov 2012, Jesse Gross wrote:
> On Thu, Nov 1, 2012 at 7:33 AM, Christoph Lameter <cl@linux.com> wrote:
> > On Thu, 1 Nov 2012, Shan Wei wrote:
> >
> >> But for different field in same per-cpu variable, how to guarantee n_missed
> >> and n_hit are from same cpu?
> >> this_cpu_read(dp->stats_percpu->n_missed);
> >> [processor changed]
> >> this_cpu_read(dp->stats_percpu->n_hit);
> >
> > What does current guarantee that? If it is guaranteed then you can use the
> > __this_cpu_xxx ops.
>
> Preemption is disabled in all of the places where writes are done and
> all of the reads are from foreign CPUs.
Since preemption is disabled no processor change can occur. So its safe to
use __this_cpu ops throughout and they will operate on the current per cpu
area.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-11-09 1:40 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-02 16:01 [PATCH 4/9] net: openvswitch: use this_cpu_ptr per-cpu helper Shan Wei
2012-11-02 17:46 ` Christoph Lameter
2012-11-08 14:22 ` Shan Wei
2012-11-08 17:18 ` Christoph Lameter
2012-11-09 1:39 ` Shan Wei
-- strict thread matches above, loose matches on Subject: below --
2012-10-31 11:22 Shan Wei
2012-10-31 17:39 ` Christoph Lameter
2012-11-01 10:07 ` Shan Wei
2012-11-01 14:33 ` Christoph Lameter
2012-11-02 1:38 ` Jesse Gross
2012-11-02 14:01 ` Christoph Lameter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox