hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/nlmon.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/module.h>
23 #include <linux/kernel.h>
34 #include <linux/netdevice.h>
....@@ -6,21 +7,9 @@
67 #include <linux/if_arp.h>
78 #include <net/rtnetlink.h>
89
9
-struct pcpu_lstats {
10
- u64 packets;
11
- u64 bytes;
12
- struct u64_stats_sync syncp;
13
-};
14
-
1510 static netdev_tx_t nlmon_xmit(struct sk_buff *skb, struct net_device *dev)
1611 {
17
- int len = skb->len;
18
- struct pcpu_lstats *stats = this_cpu_ptr(dev->lstats);
19
-
20
- u64_stats_update_begin(&stats->syncp);
21
- stats->bytes += len;
22
- stats->packets++;
23
- u64_stats_update_end(&stats->syncp);
12
+ dev_lstats_add(dev, skb->len);
2413
2514 dev_kfree_skb(skb);
2615
....@@ -61,25 +50,9 @@
6150 static void
6251 nlmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6352 {
64
- int i;
65
- u64 bytes = 0, packets = 0;
53
+ u64 packets, bytes;
6654
67
- for_each_possible_cpu(i) {
68
- const struct pcpu_lstats *nl_stats;
69
- u64 tbytes, tpackets;
70
- unsigned int start;
71
-
72
- nl_stats = per_cpu_ptr(dev->lstats, i);
73
-
74
- do {
75
- start = u64_stats_fetch_begin_irq(&nl_stats->syncp);
76
- tbytes = nl_stats->bytes;
77
- tpackets = nl_stats->packets;
78
- } while (u64_stats_fetch_retry_irq(&nl_stats->syncp, start));
79
-
80
- packets += tpackets;
81
- bytes += tbytes;
82
- }
55
+ dev_lstats_read(dev, &packets, &bytes);
8356
8457 stats->rx_packets = packets;
8558 stats->tx_packets = 0;