Skip to content

Commit ed1ebb3

Browse files
clamattiakartben
authored andcommitted
net: tc: Add statistics about dropped packets
Add statistics about packets dropped in net_tc. Signed-off-by: Cla Mattia Galliard <[email protected]>
1 parent 84f6e7a commit ed1ebb3

File tree

5 files changed

+87
-23
lines changed

5 files changed

+87
-23
lines changed

include/zephyr/net/net_stats.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ struct net_stats_tc {
328328
#endif
329329
/** Number of packets sent for this traffic class */
330330
net_stats_t pkts;
331+
/** Number of packets dropped for this traffic class */
332+
net_stats_t dropped;
331333
/** Number of bytes sent for this traffic class */
332334
net_stats_t bytes;
333335
/** Priority of this traffic class */
@@ -345,6 +347,8 @@ struct net_stats_tc {
345347
#endif
346348
/** Number of packets received for this traffic class */
347349
net_stats_t pkts;
350+
/** Number of packets dropped for this traffic class */
351+
net_stats_t dropped;
348352
/** Number of bytes received for this traffic class */
349353
net_stats_t bytes;
350354
/** Priority of this traffic class */

subsys/net/ip/net_core.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,10 @@ void net_process_rx_packet(struct net_pkt *pkt)
467467

468468
static void net_queue_rx(struct net_if *iface, struct net_pkt *pkt)
469469
{
470+
size_t len = net_pkt_get_len(pkt);
470471
uint8_t prio = net_pkt_priority(pkt);
471472
uint8_t tc = net_rx_priority2tc(prio);
472473

473-
#if defined(CONFIG_NET_STATISTICS)
474-
net_stats_update_tc_recv_pkt(iface, tc);
475-
net_stats_update_tc_recv_bytes(iface, tc, net_pkt_get_len(pkt));
476-
net_stats_update_tc_recv_priority(iface, tc, prio);
477-
#endif
478-
479474
#if NET_TC_RX_COUNT > 1
480475
NET_DBG("TC %d with prio %d pkt %p", tc, prio, pkt);
481476
#endif
@@ -488,11 +483,14 @@ static void net_queue_rx(struct net_if *iface, struct net_pkt *pkt)
488483
}
489484
}
490485

486+
net_stats_update_tc_recv_pkt(iface, tc);
487+
net_stats_update_tc_recv_bytes(iface, tc, len);
488+
net_stats_update_tc_recv_priority(iface, tc, prio);
491489
return;
492490

493491
drop:
494492
net_pkt_unref(pkt);
495-
/* TODO add statistics */
493+
net_stats_update_tc_recv_dropped(iface, tc);
496494
return;
497495
}
498496

subsys/net/ip/net_if.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,10 @@ void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
350350
return;
351351
}
352352

353+
size_t len = net_pkt_get_len(pkt);
353354
uint8_t prio = net_pkt_priority(pkt);
354355
uint8_t tc = net_tx_priority2tc(prio);
355356

356-
net_stats_update_tc_sent_pkt(iface, tc);
357-
net_stats_update_tc_sent_bytes(iface, tc, net_pkt_get_len(pkt));
358-
net_stats_update_tc_sent_priority(iface, tc, prio);
359-
360357
#if NET_TC_TX_COUNT > 1
361358
NET_DBG("TC %d with prio %d pkt %p", tc, prio, pkt);
362359
#endif
@@ -379,11 +376,14 @@ void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
379376
#endif
380377
}
381378

379+
net_stats_update_tc_sent_pkt(iface, tc);
380+
net_stats_update_tc_sent_bytes(iface, tc, len);
381+
net_stats_update_tc_sent_priority(iface, tc, prio);
382382
return;
383383

384384
drop:
385385
net_pkt_unref(pkt);
386-
/* TODO add statistics */
386+
net_stats_update_tc_sent_dropped(iface, tc);
387387
return;
388388
}
389389
#endif /* CONFIG_NET_NATIVE */

subsys/net/ip/net_stats.h

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ static inline void net_stats_update_tc_sent_pkt(struct net_if *iface, uint8_t tc
485485
UPDATE_STAT(iface, stats.tc.sent[tc].pkts++);
486486
}
487487

488+
static inline void net_stats_update_tc_sent_dropped(struct net_if *iface, uint8_t tc)
489+
{
490+
UPDATE_STAT(iface, stats.tc.sent[tc].dropped++);
491+
}
492+
488493
static inline void net_stats_update_tc_sent_bytes(struct net_if *iface,
489494
uint8_t tc, size_t bytes)
490495
{
@@ -586,6 +591,11 @@ static inline void net_stats_update_tc_recv_pkt(struct net_if *iface, uint8_t tc
586591
UPDATE_STAT(iface, stats.tc.recv[tc].pkts++);
587592
}
588593

594+
static inline void net_stats_update_tc_recv_dropped(struct net_if *iface, uint8_t tc)
595+
{
596+
UPDATE_STAT(iface, stats.tc.recv[tc].dropped++);
597+
}
598+
589599
static inline void net_stats_update_tc_recv_bytes(struct net_if *iface,
590600
uint8_t tc, size_t bytes)
591601
{
@@ -598,12 +608,61 @@ static inline void net_stats_update_tc_recv_priority(struct net_if *iface,
598608
UPDATE_STAT(iface, stats.tc.recv[tc].priority = priority);
599609
}
600610
#else
601-
#define net_stats_update_tc_sent_pkt(iface, tc)
602-
#define net_stats_update_tc_sent_bytes(iface, tc, bytes)
603-
#define net_stats_update_tc_sent_priority(iface, tc, priority)
604-
#define net_stats_update_tc_recv_pkt(iface, tc)
605-
#define net_stats_update_tc_recv_bytes(iface, tc, bytes)
606-
#define net_stats_update_tc_recv_priority(iface, tc, priority)
611+
static inline void net_stats_update_tc_sent_pkt(struct net_if *iface, uint8_t tc)
612+
{
613+
ARG_UNUSED(iface);
614+
ARG_UNUSED(tc);
615+
}
616+
617+
static inline void net_stats_update_tc_sent_dropped(struct net_if *iface, uint8_t tc)
618+
{
619+
ARG_UNUSED(iface);
620+
ARG_UNUSED(tc);
621+
}
622+
623+
static inline void net_stats_update_tc_sent_bytes(struct net_if *iface,
624+
uint8_t tc, size_t bytes)
625+
{
626+
ARG_UNUSED(iface);
627+
ARG_UNUSED(tc);
628+
ARG_UNUSED(bytes);
629+
}
630+
631+
static inline void net_stats_update_tc_sent_priority(struct net_if *iface,
632+
uint8_t tc, uint8_t priority)
633+
{
634+
ARG_UNUSED(iface);
635+
ARG_UNUSED(tc);
636+
ARG_UNUSED(priority);
637+
}
638+
639+
static inline void net_stats_update_tc_recv_pkt(struct net_if *iface, uint8_t tc)
640+
{
641+
ARG_UNUSED(iface);
642+
ARG_UNUSED(tc);
643+
}
644+
645+
static inline void net_stats_update_tc_recv_dropped(struct net_if *iface, uint8_t tc)
646+
{
647+
ARG_UNUSED(iface);
648+
ARG_UNUSED(tc);
649+
}
650+
651+
static inline void net_stats_update_tc_recv_bytes(struct net_if *iface,
652+
uint8_t tc, size_t bytes)
653+
{
654+
ARG_UNUSED(iface);
655+
ARG_UNUSED(tc);
656+
ARG_UNUSED(bytes);
657+
}
658+
659+
static inline void net_stats_update_tc_recv_priority(struct net_if *iface,
660+
uint8_t tc, uint8_t priority)
661+
{
662+
ARG_UNUSED(iface);
663+
ARG_UNUSED(tc);
664+
ARG_UNUSED(priority);
665+
}
607666

608667
#if defined(CONFIG_NET_PKT_TXTIME_STATS) && \
609668
defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_NATIVE)

subsys/net/lib/shell/stats.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,22 +368,24 @@ static void print_tc_rx_stats(const struct shell *sh, struct net_if *iface)
368368
PR("RX traffic class statistics:\n");
369369

370370
#if defined(CONFIG_NET_PKT_RXTIME_STATS)
371-
PR("TC Priority\tRecv pkts\tbytes\ttime\n");
371+
PR("TC Priority\tRecv pkts\tDrop pkts\tbytes\ttime\n");
372372

373373
for (i = 0; i < NET_TC_RX_COUNT; i++) {
374374
net_stats_t count = GET_STAT(iface,
375375
tc.recv[i].rx_time.count);
376376
if (count == 0) {
377-
PR("[%d] %s (%d)\t%d\t\t%d\t-\n", i,
377+
PR("[%d] %s (%d)\t%d\t%d\t\t%d\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),
381+
GET_STAT(iface, tc.recv[i].dropped),
381382
GET_STAT(iface, tc.recv[i].bytes));
382383
} else {
383-
PR("[%d] %s (%d)\t%d\t\t%d\t%u us%s\n", i,
384+
PR("[%d] %s (%d)\t%d\t%d\t\t%d\t%u us%s\n", i,
384385
priority2str(GET_STAT(iface, tc.recv[i].priority)),
385386
GET_STAT(iface, tc.recv[i].priority),
386387
GET_STAT(iface, tc.recv[i].pkts),
388+
GET_STAT(iface, tc.recv[i].dropped),
387389
GET_STAT(iface, tc.recv[i].bytes),
388390
(uint32_t)(GET_STAT(iface,
389391
tc.recv[i].rx_time.sum) /
@@ -392,13 +394,14 @@ static void print_tc_rx_stats(const struct shell *sh, struct net_if *iface)
392394
}
393395
}
394396
#else
395-
PR("TC Priority\tRecv pkts\tbytes\n");
397+
PR("TC Priority\tRecv pkts\tDrop pkts\tbytes\n");
396398

397399
for (i = 0; i < NET_TC_RX_COUNT; i++) {
398-
PR("[%d] %s (%d)\t%d\t\t%d\n", i,
400+
PR("[%d] %s (%d)\t%d\t%d\t\t%d\n", i,
399401
priority2str(GET_STAT(iface, tc.recv[i].priority)),
400402
GET_STAT(iface, tc.recv[i].priority),
401403
GET_STAT(iface, tc.recv[i].pkts),
404+
GET_STAT(iface, tc.recv[i].dropped),
402405
GET_STAT(iface, tc.recv[i].bytes));
403406
}
404407
#endif /* CONFIG_NET_PKT_RXTIME_STATS */

0 commit comments

Comments
 (0)