Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c213bd2 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller
Browse files

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: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ed1acc8c
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -88,16 +88,10 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)

static int dummy_dev_init(struct net_device *dev)
{
	int i;
	dev->dstats = alloc_percpu(struct pcpu_dstats);
	dev->dstats = netdev_alloc_pcpu_stats(struct pcpu_dstats);
	if (!dev->dstats)
		return -ENOMEM;

	for_each_possible_cpu(i) {
		struct pcpu_dstats *dstats;
		dstats = per_cpu_ptr(dev->dstats, i);
		u64_stats_init(&dstats->syncp);
	}
	return 0;
}

+1 −8
Original line number Diff line number Diff line
@@ -2784,7 +2784,6 @@ static int mvneta_probe(struct platform_device *pdev)
	const char *mac_from;
	int phy_mode;
	int err;
	int cpu;

	/* Our multiqueue support is not complete, so for now, only
	 * allow the usage of the first RX queue
@@ -2845,18 +2844,12 @@ static int mvneta_probe(struct platform_device *pdev)
	}

	/* Alloc per-cpu stats */
	pp->stats = alloc_percpu(struct mvneta_pcpu_stats);
	pp->stats = netdev_alloc_pcpu_stats(struct mvneta_pcpu_stats);
	if (!pp->stats) {
		err = -ENOMEM;
		goto err_unmap;
	}

	for_each_possible_cpu(cpu) {
		struct mvneta_pcpu_stats *stats;
		stats = per_cpu_ptr(pp->stats, cpu);
		u64_stats_init(&stats->syncp);
	}

	dt_mac_addr = of_get_mac_address(dn);
	if (dt_mac_addr) {
		mac_from = "device tree";
+1 −8
Original line number Diff line number Diff line
@@ -136,16 +136,9 @@ static const struct ethtool_ops loopback_ethtool_ops = {

static int loopback_dev_init(struct net_device *dev)
{
	int i;
	dev->lstats = alloc_percpu(struct pcpu_lstats);
	dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
	if (!dev->lstats)
		return -ENOMEM;

	for_each_possible_cpu(i) {
		struct pcpu_lstats *lb_stats;
		lb_stats = per_cpu_ptr(dev->lstats, i);
		u64_stats_init(&lb_stats->syncp);
	}
	return 0;
}

+1 −8
Original line number Diff line number Diff line
@@ -534,7 +534,6 @@ static int macvlan_init(struct net_device *dev)
{
	struct macvlan_dev *vlan = netdev_priv(dev);
	const struct net_device *lowerdev = vlan->lowerdev;
	int i;

	dev->state		= (dev->state & ~MACVLAN_STATE_MASK) |
				  (lowerdev->state & MACVLAN_STATE_MASK);
@@ -546,16 +545,10 @@ static int macvlan_init(struct net_device *dev)

	macvlan_set_lockdep_class(dev);

	vlan->pcpu_stats = alloc_percpu(struct vlan_pcpu_stats);
	vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
	if (!vlan->pcpu_stats)
		return -ENOMEM;

	for_each_possible_cpu(i) {
		struct vlan_pcpu_stats *mvlstats;
		mvlstats = per_cpu_ptr(vlan->pcpu_stats, i);
		u64_stats_init(&mvlstats->syncp);
	}

	return 0;
}

+1 −10
Original line number Diff line number Diff line
@@ -47,16 +47,7 @@ static int nlmon_change_mtu(struct net_device *dev, int new_mtu)

static int nlmon_dev_init(struct net_device *dev)
{
	int i;

	dev->lstats = alloc_percpu(struct pcpu_lstats);

	for_each_possible_cpu(i) {
		struct pcpu_lstats *nlmstats;
		nlmstats = per_cpu_ptr(dev->lstats, i);
		u64_stats_init(&nlmstats->syncp);
	}

	dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
	return dev->lstats == NULL ? -ENOMEM : 0;
}

Loading