ppp: reuse ppp_get_stats64() for ioctl stats
Subsystems (3)
PATCH 1/1 ppp: reuse ppp_get_stats64() for ioctl stats
ppp_get_stats() open-codes the per-cpu tstats aggregation even though ppp_get_stats64() already collects the packet, byte and error counters needed by the legacy SIOCGPPPSTATS ioctl path.
Reuse ppp_get_stats64() when filling struct ppp_stats. This keeps the ioctl stats path consistent with the netdev stats64 path and removes the open-coded per-cpu stats aggregation from the ioctl path.
---
This is meant as a small cleanup. The ioctl path and the netdev stats64 path already use the same underlying counters, so this just makes the ioctl path reuse ppp_get_stats64() instead of open-coding the per-cpu aggregation locally.
--- drivers/net/ppp/ppp_generic.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/net/ppp/ppp_generic.c +8 -17
@@ -3303,26 +3303,17 @@ find_compressor(int type)static void ppp_get_stats (struct ppp *ppp,struct ppp_stats *st) { +struct rtnl_link_stats64 stats64 = {};struct slcompress *vj = ppp->vj; -int cpu;memset (st,0 ,sizeof (*st)); -for_each_possible_cpu (cpu) { -struct pcpu_sw_netstats *p =per_cpu_ptr (ppp->dev->tstats, cpu); -u64 rx_packets, rx_bytes, tx_packets, tx_bytes; - - rx_packets =u64_stats_read (&p->rx_packets); - rx_bytes =u64_stats_read (&p->rx_bytes); - tx_packets =u64_stats_read (&p->tx_packets); - tx_bytes =u64_stats_read (&p->tx_bytes); - - st->p.ppp_ipackets += rx_packets; - st->p.ppp_ibytes += rx_bytes; - st->p.ppp_opackets += tx_packets; - st->p.ppp_obytes += tx_bytes; - } - st->p.ppp_ierrors = ppp->dev->stats.rx_errors; - st->p.ppp_oerrors = ppp->dev->stats.tx_errors; +ppp_get_stats64 (ppp->dev, &stats64); + st->p.ppp_ipackets = stats64.rx_packets; + st->p.ppp_ibytes = stats64.rx_bytes; + st->p.ppp_opackets = stats64.tx_packets; + st->p.ppp_obytes = stats64.tx_bytes; + st->p.ppp_ierrors = stats64.rx_errors; + st->p.ppp_oerrors = stats64.tx_errors;if (!vj)return ; st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed;
Signature · 1 line
2.34.1
Hi,
Quoted 8 lines · Zhixing Chen
ppp_get_stats()open-codes the per-cpu tstats aggregation even thoughppp_get_stats64()already collects the packet, byte and error counters needed by the legacy SIOCGPPPSTATS ioctl path.Reuse
ppp_get_stats64()when filling structppp_stats. This keeps the ioctl stats path consistent with the netdev stats64 path and removes the open-coded per-cpu stats aggregation from the ioctl path.
Quoted 7 lines
Signed-off-by Zhixing Chen <[email protected]>---
This is meant as a small cleanup. The ioctl path and the netdev stats64 path already use the same underlying counters, so this just makes the ioctl path reuse
ppp_get_stats64()instead of open-coding the per-cpu aggregation locally.
On a 32-bit architecture, this will introduce unnecessary seqlock overhead to get the upper 32-bit of a counter, which would then be immediately discarded.
Regards,
Qingfang
Hi Qingfang,
Thanks a lot for pointing this out.
Quoted 3 lines
On a 32-bit architecture, this will introduce unnecessary seqlock overhead to get the upper 32-bit of a counter, which would then be immediately discarded.
That makes sense. I missed that reusing ppp_get_stats64() would add unnecessary 64-bit stats read overhead on 32-bit architectures, while the ioctl path only returns 32-bit counters. I agree this is not a good trade-off for a cleanup.
Please ignore this patch.
Thanks again,
Zhixing