Skip to contentSkip to conversation

ppp: reuse ppp_get_stats64() for ioctl stats

PATCH In review Zhixing Chen 2 participants 3 messages Jul 14 – Jul 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index 57c68efa5ff8..53e6d40193fd 100644
@@ -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
#1 lore raw

Hi,

Quoted 8 lines · Zhixing Chen

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.

Quoted 7 lines

---

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

#2 lore raw

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