]> git.proxmox.com Git - mirror_ovs.git/commitdiff
datapath: introduce netdev_alloc_pcpu_stats() for drivers
authorWANG Cong <xiyou.wangcong@gmail.com>
Fri, 12 Sep 2014 21:05:11 +0000 (14:05 -0700)
committerPravin B Shelar <pshelar@nicira.com>
Fri, 12 Sep 2014 21:29:00 +0000 (14:29 -0700)
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>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
datapath/datapath.c
datapath/linux/compat/include/linux/netdevice.h
datapath/vport.c

index 61f862f1298f924b2778375723e2bc5de5abd7c9..965f889c9e7b0d2ef6488d3bda5f8b32082835e4 100644 (file)
@@ -1415,18 +1415,12 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
        if (err)
                goto err_free_dp;
 
-       dp->stats_percpu = alloc_percpu(struct dp_stats_percpu);
+       dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
        if (!dp->stats_percpu) {
                err = -ENOMEM;
                goto err_destroy_table;
        }
 
-       for_each_possible_cpu(i) {
-               struct dp_stats_percpu *dpath_stats;
-               dpath_stats = per_cpu_ptr(dp->stats_percpu, i);
-               u64_stats_init(&dpath_stats->sync);
-       }
-
        dp->ports = kmalloc(DP_VPORT_HASH_BUCKETS * sizeof(struct hlist_head),
                            GFP_KERNEL);
        if (!dp->ports) {
index 886c2f83073214c661f1dda0b5e941dd098cf2b1..55022882fc48c4be064e3ff198cb338205034c1a 100644 (file)
@@ -140,4 +140,20 @@ struct pcpu_sw_netstats {
 };
 #endif
 
+#ifndef netdev_alloc_pcpu_stats
+#define netdev_alloc_pcpu_stats(type)                          \
+({                                                             \
+       typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
+       if (pcpu_stats) {                                       \
+               int i;                                          \
+               for_each_possible_cpu(i) {                      \
+                       typeof(type) *stat;                     \
+                       stat = per_cpu_ptr(pcpu_stats, i);      \
+                       u64_stats_init(&stat->syncp);           \
+               }                                               \
+       }                                                       \
+       pcpu_stats;                                             \
+})
+#endif
+
 #endif
index 37e0edc1e3daab9f45d168badfc9c3492a329aa5..cf7f917e8956ff8fcc75bb26945f2059e6230930 100644 (file)
@@ -124,7 +124,6 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops,
 {
        struct vport *vport;
        size_t alloc_size;
-       int i;
 
        alloc_size = sizeof(struct vport);
        if (priv_size) {
@@ -146,18 +145,12 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops,
                return ERR_PTR(-EINVAL);
        }
 
-       vport->percpu_stats = alloc_percpu(struct pcpu_sw_netstats);
+       vport->percpu_stats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
        if (!vport->percpu_stats) {
                kfree(vport);
                return ERR_PTR(-ENOMEM);
        }
 
-       for_each_possible_cpu(i) {
-               struct pcpu_sw_netstats *vport_stats;
-               vport_stats = per_cpu_ptr(vport->percpu_stats, i);
-               u64_stats_init(&vport_stats->syncp);
-       }
-
        spin_lock_init(&vport->stats_lock);
 
        return vport;