* [PATCH] net: ethernet: litex: add support for 64 bit stats
@ 2023-06-14 16:20 Jisheng Zhang
2023-06-15 11:54 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jisheng Zhang @ 2023-06-14 16:20 UTC (permalink / raw)
To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Karol Gugala, Mateusz Holenko, Gabriel Somlo, Joel Stanley
Cc: netdev, linux-kernel
Implement 64 bit per cpu stats to fix the overflow of netdev->stats
on 32 bit platforms. To simplify the code, we use net core
pcpu_sw_netstats infrastructure. One small drawback is some memory
overhead because litex uses just one queue, but we allocate the
counters per cpu.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
drivers/net/ethernet/litex/litex_liteeth.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/litex/litex_liteeth.c b/drivers/net/ethernet/litex/litex_liteeth.c
index 35f24e0f0934..ffa96059079c 100644
--- a/drivers/net/ethernet/litex/litex_liteeth.c
+++ b/drivers/net/ethernet/litex/litex_liteeth.c
@@ -78,8 +78,7 @@ static int liteeth_rx(struct net_device *netdev)
memcpy_fromio(data, priv->rx_base + rx_slot * priv->slot_size, len);
skb->protocol = eth_type_trans(skb, netdev);
- netdev->stats.rx_packets++;
- netdev->stats.rx_bytes += len;
+ dev_sw_netstats_rx_add(netdev, len);
return netif_rx(skb);
@@ -185,8 +184,7 @@ static netdev_tx_t liteeth_start_xmit(struct sk_buff *skb,
litex_write16(priv->base + LITEETH_READER_LENGTH, skb->len);
litex_write8(priv->base + LITEETH_READER_START, 1);
- netdev->stats.tx_bytes += skb->len;
- netdev->stats.tx_packets++;
+ dev_sw_netstats_tx_add(netdev, 1, skb->len);
priv->tx_slot = (priv->tx_slot + 1) % priv->num_tx_slots;
dev_kfree_skb_any(skb);
@@ -194,9 +192,17 @@ static netdev_tx_t liteeth_start_xmit(struct sk_buff *skb,
return NETDEV_TX_OK;
}
+static void
+liteeth_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
+{
+ netdev_stats_to_stats64(stats, &netdev->stats);
+ dev_fetch_sw_netstats(stats, netdev->tstats);
+}
+
static const struct net_device_ops liteeth_netdev_ops = {
.ndo_open = liteeth_open,
.ndo_stop = liteeth_stop,
+ .ndo_get_stats64 = liteeth_get_stats64,
.ndo_start_xmit = liteeth_start_xmit,
};
@@ -242,6 +248,11 @@ static int liteeth_probe(struct platform_device *pdev)
priv->netdev = netdev;
priv->dev = &pdev->dev;
+ netdev->tstats = devm_netdev_alloc_pcpu_stats(&pdev->dev,
+ struct pcpu_sw_netstats);
+ if (!netdev->tstats)
+ return -ENOMEM;
+
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: ethernet: litex: add support for 64 bit stats
2023-06-14 16:20 [PATCH] net: ethernet: litex: add support for 64 bit stats Jisheng Zhang
@ 2023-06-15 11:54 ` Simon Horman
2023-06-15 15:51 ` Gabriel L. Somlo
2023-06-16 6:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-06-15 11:54 UTC (permalink / raw)
To: Jisheng Zhang
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Karol Gugala, Mateusz Holenko, Gabriel Somlo, Joel Stanley,
netdev, linux-kernel
On Thu, Jun 15, 2023 at 12:20:35AM +0800, Jisheng Zhang wrote:
> Implement 64 bit per cpu stats to fix the overflow of netdev->stats
> on 32 bit platforms. To simplify the code, we use net core
> pcpu_sw_netstats infrastructure. One small drawback is some memory
> overhead because litex uses just one queue, but we allocate the
> counters per cpu.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: ethernet: litex: add support for 64 bit stats
2023-06-14 16:20 [PATCH] net: ethernet: litex: add support for 64 bit stats Jisheng Zhang
2023-06-15 11:54 ` Simon Horman
@ 2023-06-15 15:51 ` Gabriel L. Somlo
2023-06-16 6:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Gabriel L. Somlo @ 2023-06-15 15:51 UTC (permalink / raw)
To: Jisheng Zhang
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Karol Gugala, Mateusz Holenko, Joel Stanley, netdev, linux-kernel
On Thu, Jun 15, 2023 at 12:20:35AM +0800, Jisheng Zhang wrote:
> Implement 64 bit per cpu stats to fix the overflow of netdev->stats
> on 32 bit platforms. To simplify the code, we use net core
> pcpu_sw_netstats infrastructure. One small drawback is some memory
> overhead because litex uses just one queue, but we allocate the
> counters per cpu.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
Acked-by: Gabriel Somlo <gsomlo@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: ethernet: litex: add support for 64 bit stats
2023-06-14 16:20 [PATCH] net: ethernet: litex: add support for 64 bit stats Jisheng Zhang
2023-06-15 11:54 ` Simon Horman
2023-06-15 15:51 ` Gabriel L. Somlo
@ 2023-06-16 6:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-16 6:10 UTC (permalink / raw)
To: Jisheng Zhang
Cc: davem, edumazet, kuba, pabeni, kgugala, mholenko, gsomlo, joel,
netdev, linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 15 Jun 2023 00:20:35 +0800 you wrote:
> Implement 64 bit per cpu stats to fix the overflow of netdev->stats
> on 32 bit platforms. To simplify the code, we use net core
> pcpu_sw_netstats infrastructure. One small drawback is some memory
> overhead because litex uses just one queue, but we allocate the
> counters per cpu.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
>
> [...]
Here is the summary with links:
- net: ethernet: litex: add support for 64 bit stats
https://git.kernel.org/netdev/net-next/c/18da174d865a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-16 6:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 16:20 [PATCH] net: ethernet: litex: add support for 64 bit stats Jisheng Zhang
2023-06-15 11:54 ` Simon Horman
2023-06-15 15:51 ` Gabriel L. Somlo
2023-06-16 6:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).