Skip to content

Commit 262303b

Browse files
committed
[nrf fromtree] net: stats: Make byte counters 64-bit
In high throughput tests it's fairly easy to overflow the current 32-bit byte counters in net statistics (it's just over 4 GB of data). Therefore, make the byte counters 64-bit to prevent overflows. Rearrange some fields to avoid padding. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no> (cherry picked from commit 86244a9c543aed48e5305174c7dd42cb89456009)
1 parent e77bb0e commit 262303b

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

include/zephyr/net/net_stats.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ typedef uint32_t net_stats_t;
4949
*/
5050
struct net_stats_bytes {
5151
/** Number of bytes sent */
52-
net_stats_t sent;
52+
uint64_t sent;
5353
/** Number of bytes received */
54-
net_stats_t received;
54+
uint64_t received;
5555
};
5656

5757
/**
@@ -319,6 +319,8 @@ struct net_stats_rx_time {
319319
struct net_stats_tc {
320320
/** TX statistics for each traffic class */
321321
struct {
322+
/** Number of bytes sent for this traffic class */
323+
uint64_t bytes;
322324
/** Helper for calculating average TX time statistics */
323325
struct net_stats_tx_time tx_time;
324326
#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL)
@@ -330,14 +332,14 @@ struct net_stats_tc {
330332
net_stats_t pkts;
331333
/** Number of packets dropped for this traffic class */
332334
net_stats_t dropped;
333-
/** Number of bytes sent for this traffic class */
334-
net_stats_t bytes;
335335
/** Priority of this traffic class */
336336
uint8_t priority;
337337
} sent[NET_TC_TX_STATS_COUNT];
338338

339339
/** RX statistics for each traffic class */
340340
struct {
341+
/** Number of bytes received for this traffic class */
342+
uint64_t bytes;
341343
/** Helper for calculating average RX time statistics */
342344
struct net_stats_rx_time rx_time;
343345
#if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
@@ -349,8 +351,6 @@ struct net_stats_tc {
349351
net_stats_t pkts;
350352
/** Number of packets dropped for this traffic class */
351353
net_stats_t dropped;
352-
/** Number of bytes received for this traffic class */
353-
net_stats_t bytes;
354354
/** Priority of this traffic class */
355355
uint8_t priority;
356356
} recv[NET_TC_RX_STATS_COUNT];
@@ -404,15 +404,15 @@ struct net_stats_pkt_filter {
404404
* @brief All network statistics in one struct.
405405
*/
406406
struct net_stats {
407-
/** Count of malformed packets or packets we do not have handler for */
408-
net_stats_t processing_error;
409-
410407
/**
411408
* This calculates amount of data transferred through all the
412409
* network interfaces.
413410
*/
414411
struct net_stats_bytes bytes;
415412

413+
/** Count of malformed packets or packets we do not have handler for */
414+
net_stats_t processing_error;
415+
416416
/** IP layer errors */
417417
struct net_stats_ip_errors ip_errors;
418418

samples/net/stats/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void print_stats(struct net_if *iface, struct net_stats *data)
9999
#endif
100100

101101
#if defined(CONFIG_NET_STATISTICS_TCP)
102-
printk("TCP bytes recv %u\tsent\t%u\n",
102+
printk("TCP bytes recv %llu\tsent\t%llu\n",
103103
GET_STAT(iface, tcp.bytes.received),
104104
GET_STAT(iface, tcp.bytes.sent));
105105
printk("TCP seg recv %u\tsent\t%u\tdrop\t%u\n",
@@ -119,8 +119,8 @@ static void print_stats(struct net_if *iface, struct net_stats *data)
119119
GET_STAT(iface, tcp.connrst));
120120
#endif
121121

122-
printk("Bytes received %u\n", GET_STAT(iface, bytes.received));
123-
printk("Bytes sent %u\n", GET_STAT(iface, bytes.sent));
122+
printk("Bytes received %llu\n", GET_STAT(iface, bytes.received));
123+
printk("Bytes sent %llu\n", GET_STAT(iface, bytes.sent));
124124
printk("Processing err %u\n", GET_STAT(iface, processing_error));
125125
}
126126

@@ -141,8 +141,8 @@ static void print_eth_stats(struct net_if *iface, struct net_stats_eth *data)
141141
printk("Statistics for Ethernet interface %p [%d]\n", iface,
142142
net_if_get_by_iface(iface));
143143

144-
printk("Bytes received : %u\n", data->bytes.received);
145-
printk("Bytes sent : %u\n", data->bytes.sent);
144+
printk("Bytes received : %llu\n", data->bytes.received);
145+
printk("Bytes sent : %llu\n", data->bytes.sent);
146146
printk("Packets received : %u\n", data->pkts.rx);
147147
printk("Packets sent : %u\n", data->pkts.tx);
148148
printk("Bcast received : %u\n", data->broadcast.rx);

subsys/net/ip/net_stats.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static inline void stats(struct net_if *iface)
152152
#endif
153153

154154
#if defined(CONFIG_NET_STATISTICS_TCP)
155-
NET_INFO("TCP bytes recv %u\tsent\t%u",
155+
NET_INFO("TCP bytes recv %llu\tsent\t%llu",
156156
GET_STAT(iface, tcp.bytes.received),
157157
GET_STAT(iface, tcp.bytes.sent));
158158
NET_INFO("TCP seg recv %u\tsent\t%u\tdrop\t%u",
@@ -172,8 +172,8 @@ static inline void stats(struct net_if *iface)
172172
GET_STAT(iface, tcp.connrst));
173173
#endif
174174

175-
NET_INFO("Bytes received %u", GET_STAT(iface, bytes.received));
176-
NET_INFO("Bytes sent %u", GET_STAT(iface, bytes.sent));
175+
NET_INFO("Bytes received %llu", GET_STAT(iface, bytes.received));
176+
NET_INFO("Bytes sent %llu", GET_STAT(iface, bytes.sent));
177177
NET_INFO("Processing err %u",
178178
GET_STAT(iface, processing_error));
179179

@@ -183,7 +183,7 @@ static inline void stats(struct net_if *iface)
183183
NET_INFO("TC Priority\tSent pkts\tbytes");
184184

185185
for (i = 0; i < NET_TC_TX_COUNT; i++) {
186-
NET_INFO("[%d] %s (%u)\t%u\t\t%u", i,
186+
NET_INFO("[%d] %s (%u)\t%u\t\t%llu", i,
187187
priority2str(GET_STAT(iface,
188188
tc.sent[i].priority)),
189189
GET_STAT(iface, tc.sent[i].priority),
@@ -197,7 +197,7 @@ static inline void stats(struct net_if *iface)
197197
NET_INFO("TC Priority\tRecv pkts\tbytes");
198198

199199
for (i = 0; i < NET_TC_RX_COUNT; i++) {
200-
NET_INFO("[%d] %s (%u)\t%u\t\t%u", i,
200+
NET_INFO("[%d] %s (%u)\t%u\t\t%llu", i,
201201
priority2str(GET_STAT(iface,
202202
tc.recv[i].priority)),
203203
GET_STAT(iface, tc.recv[i].priority),

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,8 @@ static void print_wifi_stats(struct net_if *iface, struct net_stats_wifi *data,
15621562
PR("Statistics for Wi-Fi interface %p [%d]\n", iface,
15631563
net_if_get_by_iface(iface));
15641564

1565-
PR("Bytes received : %u\n", data->bytes.received);
1566-
PR("Bytes sent : %u\n", data->bytes.sent);
1565+
PR("Bytes received : %llu\n", data->bytes.received);
1566+
PR("Bytes sent : %llu\n", data->bytes.sent);
15671567
PR("Packets received : %u\n", data->pkts.rx);
15681568
PR("Packets sent : %u\n", data->pkts.tx);
15691569
PR("Receive errors : %u\n", data->errors.rx);

subsys/net/lib/shell/stats.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ static void print_eth_stats(struct net_if *iface, struct net_stats_eth *data,
5050
PR("Statistics for Ethernet interface %p [%d]\n", iface,
5151
net_if_get_by_iface(iface));
5252

53-
PR("Bytes received : %u\n", data->bytes.received);
54-
PR("Bytes sent : %u\n", data->bytes.sent);
53+
PR("Bytes received : %llu\n", data->bytes.received);
54+
PR("Bytes sent : %llu\n", data->bytes.sent);
5555
PR("Packets received : %u\n", data->pkts.rx);
5656
PR("Packets sent : %u\n", data->pkts.tx);
5757
PR("Bcast received : %u\n", data->broadcast.rx);
@@ -315,13 +315,13 @@ static void print_tc_tx_stats(const struct shell *sh, struct net_if *iface)
315315
net_stats_t count = GET_STAT(iface,
316316
tc.sent[i].tx_time.count);
317317
if (count == 0) {
318-
PR("[%d] %s (%u)\t%u\t\t%u\t-\n", i,
318+
PR("[%d] %s (%u)\t%u\t\t%llu\t-\n", i,
319319
priority2str(GET_STAT(iface, tc.sent[i].priority)),
320320
GET_STAT(iface, tc.sent[i].priority),
321321
GET_STAT(iface, tc.sent[i].pkts),
322322
GET_STAT(iface, tc.sent[i].bytes));
323323
} else {
324-
PR("[%d] %s (%u)\t%u\t\t%u\t%u us%s\n", i,
324+
PR("[%d] %s (%u)\t%u\t\t%llu\t%u us%s\n", i,
325325
priority2str(GET_STAT(iface, tc.sent[i].priority)),
326326
GET_STAT(iface, tc.sent[i].priority),
327327
GET_STAT(iface, tc.sent[i].pkts),
@@ -336,7 +336,7 @@ static void print_tc_tx_stats(const struct shell *sh, struct net_if *iface)
336336
PR("TC Priority\tSent pkts\tbytes\n");
337337

338338
for (i = 0; i < NET_TC_TX_COUNT; i++) {
339-
PR("[%d] %s (%u)\t%u\t\t%u\n", i,
339+
PR("[%d] %s (%u)\t%u\t\t%llu\n", i,
340340
priority2str(GET_STAT(iface, tc.sent[i].priority)),
341341
GET_STAT(iface, tc.sent[i].priority),
342342
GET_STAT(iface, tc.sent[i].pkts),
@@ -374,14 +374,14 @@ static void print_tc_rx_stats(const struct shell *sh, struct net_if *iface)
374374
net_stats_t count = GET_STAT(iface,
375375
tc.recv[i].rx_time.count);
376376
if (count == 0) {
377-
PR("[%d] %s (%u)\t%u\t%u\t\t%u\t-\n", i,
377+
PR("[%d] %s (%u)\t%u\t%u\t\t%llu\t-\n", i,
378378
priority2str(GET_STAT(iface, tc.recv[i].priority)),
379379
GET_STAT(iface, tc.recv[i].priority),
380380
GET_STAT(iface, tc.recv[i].pkts),
381381
GET_STAT(iface, tc.recv[i].dropped),
382382
GET_STAT(iface, tc.recv[i].bytes));
383383
} else {
384-
PR("[%d] %s (%u)\t%u\t%u\t\t%u\t%u us%s\n", i,
384+
PR("[%d] %s (%u)\t%u\t%u\t\t%llu\t%u us%s\n", i,
385385
priority2str(GET_STAT(iface, tc.recv[i].priority)),
386386
GET_STAT(iface, tc.recv[i].priority),
387387
GET_STAT(iface, tc.recv[i].pkts),
@@ -397,7 +397,7 @@ static void print_tc_rx_stats(const struct shell *sh, struct net_if *iface)
397397
PR("TC Priority\tRecv pkts\tDrop pkts\tbytes\n");
398398

399399
for (i = 0; i < NET_TC_RX_COUNT; i++) {
400-
PR("[%d] %s (%u)\t%u\t%u\t\t%u\n", i,
400+
PR("[%d] %s (%u)\t%u\t%u\t\t%llu\n", i,
401401
priority2str(GET_STAT(iface, tc.recv[i].priority)),
402402
GET_STAT(iface, tc.recv[i].priority),
403403
GET_STAT(iface, tc.recv[i].pkts),
@@ -533,7 +533,7 @@ static void net_shell_print_statistics(struct net_if *iface, void *user_data)
533533
#endif
534534

535535
#if defined(CONFIG_NET_STATISTICS_TCP) && defined(CONFIG_NET_NATIVE_TCP)
536-
PR("TCP bytes recv %u\tsent\t%u\tresent\t%u\n",
536+
PR("TCP bytes recv %llu\tsent\t%llu\tresent\t%u\n",
537537
GET_STAT(iface, tcp.bytes.received),
538538
GET_STAT(iface, tcp.bytes.sent),
539539
GET_STAT(iface, tcp.resent));
@@ -575,8 +575,8 @@ static void net_shell_print_statistics(struct net_if *iface, void *user_data)
575575
GET_STAT(iface, pkt_filter.tx.drop));
576576
#endif /* CONFIG_NET_STATISTICS_DNS */
577577

578-
PR("Bytes received %u\n", GET_STAT(iface, bytes.received));
579-
PR("Bytes sent %u\n", GET_STAT(iface, bytes.sent));
578+
PR("Bytes received %llu\n", GET_STAT(iface, bytes.received));
579+
PR("Bytes sent %llu\n", GET_STAT(iface, bytes.sent));
580580
PR("Processing err %u\n", GET_STAT(iface, processing_error));
581581

582582
print_tc_tx_stats(sh, iface);

0 commit comments

Comments
 (0)