aboutsummaryrefslogtreecommitdiffstats
path: root/net/openvswitch
diff options
context:
space:
mode:
authorWANG Cong <xiyou.wangcong@gmail.com>2014-02-13 14:46:28 -0500
committerDavid S. Miller <davem@davemloft.net>2014-02-14 15:49:55 -0500
commit1c213bd24ad04f4430031d20d740d7783162b099 (patch)
treeeb42b8d216e89008065634185fd6a5fcce5ec4e9 /net/openvswitch
parented1acc8cd8c22efa919da8d300bab646e01c2dce (diff)
net: introduce netdev_alloc_pcpu_stats() for drivers
There are many drivers calling alloc_percpu() to allocate pcpu stats and then initializing ->syncp. So just introduce a helper function for them. Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/openvswitch')
-rw-r--r--net/openvswitch/datapath.c8
-rw-r--r--net/openvswitch/vport.c10
2 files changed, 2 insertions, 16 deletions
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index e9a48baf8551..3a954067b6a4 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -1215,18 +1215,12 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
1215 if (err) 1215 if (err)
1216 goto err_free_dp; 1216 goto err_free_dp;
1217 1217
1218 dp->stats_percpu = alloc_percpu(struct dp_stats_percpu); 1218 dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
1219 if (!dp->stats_percpu) { 1219 if (!dp->stats_percpu) {
1220 err = -ENOMEM; 1220 err = -ENOMEM;
1221 goto err_destroy_table; 1221 goto err_destroy_table;
1222 } 1222 }
1223 1223
1224 for_each_possible_cpu(i) {
1225 struct dp_stats_percpu *dpath_stats;
1226 dpath_stats = per_cpu_ptr(dp->stats_percpu, i);
1227 u64_stats_init(&dpath_stats->sync);
1228 }
1229
1230 dp->ports = kmalloc(DP_VPORT_HASH_BUCKETS * sizeof(struct hlist_head), 1224 dp->ports = kmalloc(DP_VPORT_HASH_BUCKETS * sizeof(struct hlist_head),
1231 GFP_KERNEL); 1225 GFP_KERNEL);
1232 if (!dp->ports) { 1226 if (!dp->ports) {
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 208dd9a26dd1..3b4db3220456 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -121,7 +121,6 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops,
121{ 121{
122 struct vport *vport; 122 struct vport *vport;
123 size_t alloc_size; 123 size_t alloc_size;
124 int i;
125 124
126 alloc_size = sizeof(struct vport); 125 alloc_size = sizeof(struct vport);
127 if (priv_size) { 126 if (priv_size) {
@@ -139,19 +138,12 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops,
139 vport->ops = ops; 138 vport->ops = ops;
140 INIT_HLIST_NODE(&vport->dp_hash_node); 139 INIT_HLIST_NODE(&vport->dp_hash_node);
141 140
142 vport->percpu_stats = alloc_percpu(struct pcpu_sw_netstats); 141 vport->percpu_stats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
143 if (!vport->percpu_stats) { 142 if (!vport->percpu_stats) {
144 kfree(vport); 143 kfree(vport);
145 return ERR_PTR(-ENOMEM); 144 return ERR_PTR(-ENOMEM);
146 } 145 }
147 146
148 for_each_possible_cpu(i) {
149 struct pcpu_sw_netstats *vport_stats;
150 vport_stats = per_cpu_ptr(vport->percpu_stats, i);
151 u64_stats_init(&vport_stats->syncp);
152 }
153
154
155 spin_lock_init(&vport->stats_lock); 147 spin_lock_init(&vport->stats_lock);
156 148
157 return vport; 149 return vport;