All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Miquel Raynal <miquel.raynal@free-electrons.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Antoine Tenart <antoine.tenart@free-electrons.com>,
	Gregory Clement <gregory.clement@free-electrons.com>,
	Nadav Haklai <nadavh@marvell.com>,
	netdev@vger.kernel.org, Stefan Chulski <stefanc@marvell.com>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH net-next v2] net: mvpp2: add ethtool GOP statistics
Date: Fri, 3 Nov 2017 16:19:06 +0100	[thread overview]
Message-ID: <20171103151906.GQ24320@lunn.ch> (raw)
In-Reply-To: <20171103110425.16097-1-miquel.raynal@free-electrons.com>

> @@ -817,6 +856,12 @@ struct mvpp2 {
>  
>  	/* Maximum number of RXQs per port */
>  	unsigned int max_port_rxqs;
> +
> +	/* Workqueue to gather hardware statistics with its lock */
> +	struct mutex gather_stats_lock;
> +	struct delayed_work stats_work;
> +	char queue_name[20];
> +	struct workqueue_struct *stats_queue;
>  };
  
> +static u64 mvpp2_read_count(struct mvpp2_port *port,
> +			    const struct mvpp2_ethtool_counter *counter)
> +{
> +	void __iomem *base;
> +	u64 val;
> +
> +	if (port->priv->hw_version == MVPP21)
> +		base = port->priv->lms_base + MVPP21_MIB_COUNTERS_OFFSET +
> +		       port->gop_id * MVPP21_MIB_COUNTERS_PORT_SZ;
> +	else
> +		base = port->priv->iface_base + MVPP22_MIB_COUNTERS_OFFSET +
> +		       port->gop_id * MVPP22_MIB_COUNTERS_PORT_SZ;

This seems like something which could be calculated once and then
stored away, e.g. next to stats_queue.

> +static void mvpp2_ethtool_get_stats(struct net_device *dev,
> +				    struct ethtool_stats *stats, u64 *data)
> +{
> +	struct mvpp2_port *port = netdev_priv(dev);
> +
> +	/* Update statistics for all ports, copy only those actually needed */
> +	mvpp2_gather_hw_statistics(&port->priv->stats_work.work);
> +
> +	memcpy(data, port->ethtool_stats,
> +	       sizeof(u64) * ARRAY_SIZE(mvpp2_ethtool_regs));

Thanks for adding the mutex in mvpp2_gather_hw_statistics(). However,
should we be holding the mutex while performing this copy? There is no
snapshot support, so the statistics are not guaranteed to be
consistent. However, since a statistics is a u64, it is possible the
copy will get the new lower 32 bits and the old 32 bits if the copy
happens while mvpp2_gather_hw_statistics() is running.

> +	port->ethtool_stats = devm_kcalloc(&pdev->dev,
> +					   ARRAY_SIZE(mvpp2_ethtool_regs),
> +					   sizeof(u64), GFP_KERNEL);
> +	if (!port->ethtool_stats) {
> +		err = -ENOMEM;
> +		goto err_free_stats;
> +	}
> +
>  	mvpp2_port_copy_mac_addr(dev, priv, port_node, &mac_from);
>  
>  	port->tx_ring_size = MVPP2_MAX_TXD;
> @@ -7707,6 +7904,7 @@ static void mvpp2_port_remove(struct mvpp2_port *port)
>  	of_node_put(port->phy_node);
>  	free_percpu(port->pcpu);
>  	free_percpu(port->stats);
> +	kfree(port->ethtool_stats);

You allocate the memory using devm_. You should not use plain kfree()
on it. You might want to spend some time reading about devm_

> +	mutex_init(&priv->gather_stats_lock);
> +	index = ida_simple_get(&engine_index_ida, 0, 0, GFP_KERNEL);
> +	if (index < 0)
> +		goto err_mg_clk;
> +
> +	snprintf(priv->queue_name, sizeof(priv->queue_name),
> +		 "mvpp2_stats_%d", index);

I know Florian asked for unique names, which IDA will give you. But
could you derive the name from device tree? It then becomes a name you
can actually map back to the hardware, rather than being semi-random.

    Thanks
	Andrew

  parent reply	other threads:[~2017-11-03 15:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03 11:04 [PATCH net-next v2] net: mvpp2: add ethtool GOP statistics Miquel Raynal
2017-11-03 11:26 ` Miquel RAYNAL
2017-11-03 15:19 ` Andrew Lunn [this message]
2017-11-06 10:06   ` Miquel RAYNAL
2017-11-06 14:25     ` Andrew Lunn
2017-11-06 21:02       ` Miquel RAYNAL
     [not found] ` <09d456be927a46c0970bd677651a4098@IL-EXCH01.marvell.com>
2017-11-06 22:45   ` Miquel RAYNAL
2017-11-07  8:22     ` [EXT] " Stefan Chulski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171103151906.GQ24320@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=antoine.tenart@free-electrons.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.clement@free-electrons.com \
    --cc=miquel.raynal@free-electrons.com \
    --cc=nadavh@marvell.com \
    --cc=netdev@vger.kernel.org \
    --cc=stefanc@marvell.com \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.