Skip to content

Commit bb3ac84

Browse files
clamattiakartben
authored andcommitted
net: tc: Add a skip for rx-queues
Add a configuration option to skip the rx-queues for high priority packets analogously to the tx-side. Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
1 parent 4e7ed9d commit bb3ac84

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

include/zephyr/net/net_if.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ struct net_traffic_class {
614614
/** Fifo for handling this Tx or Rx packet */
615615
struct k_fifo fifo;
616616

617-
#if NET_TC_COUNT > 1 || defined(CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO)
617+
#if NET_TC_COUNT > 1 || defined(CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO) \
618+
|| defined(CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO)
618619
/** Semaphore for tracking the available slots in the fifo */
619620
struct k_sem fifo_slot;
620621
#endif

subsys/net/ip/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,19 @@ config NET_TC_SKIP_FOR_HIGH_PRIO
407407
be pushed directly to network driver and will skip the traffic class
408408
queues. This is currently not enabled by default.
409409

410+
config NET_TC_RX_SKIP_FOR_HIGH_PRIO
411+
bool "Push high priority packets directly to the application"
412+
help
413+
If this is set, then high priority (>= NET_PRIORITY_CA) net_pkt will
414+
be pushed directly to the application and will skip the traffic class
415+
queues. If you select this option, then it means that high priority
416+
network traffic is pushed from the driver to the application thread
417+
without any intermediate RX queue. If the network device driver is
418+
running in IRQ context, it will handle the packet all the way to the
419+
application. This might cause other incoming packets to be lost if
420+
the RX processing takes long time.
421+
This is currently not enabled by default.
422+
410423
choice NET_TC_THREAD_TYPE
411424
prompt "How the network RX/TX threads should work"
412425
help

subsys/net/ip/net_core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ static void net_queue_rx(struct net_if *iface, struct net_pkt *pkt)
475475
NET_DBG("TC %d with prio %d pkt %p", tc, prio, pkt);
476476
#endif
477477

478-
if (NET_TC_RX_COUNT == 0) {
478+
if ((IS_ENABLED(CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO) &&
479+
prio >= NET_PRIORITY_CA) || NET_TC_RX_COUNT == 0) {
479480
net_process_rx_packet(pkt);
480481
} else {
481482
if (net_tc_submit_to_rx_queue(tc, pkt) != NET_OK) {

subsys/net/ip/net_tc.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ LOG_MODULE_REGISTER(net_tc, CONFIG_NET_TC_LOG_LEVEL);
1818
#include "net_stats.h"
1919
#include "net_tc_mapping.h"
2020

21-
#if NET_TC_RX_COUNT > 1
22-
#define NET_TC_RX_SLOTS (CONFIG_NET_PKT_RX_COUNT / NET_TC_RX_COUNT)
21+
#define TC_RX_PSEUDO_QUEUE (COND_CODE_1(CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO, (1), (0)))
22+
#define NET_TC_RX_EFFECTIVE_COUNT (NET_TC_RX_COUNT + TC_RX_PSEUDO_QUEUE)
23+
24+
#if NET_TC_RX_EFFECTIVE_COUNT > 1
25+
#define NET_TC_RX_SLOTS (CONFIG_NET_PKT_RX_COUNT / NET_TC_RX_EFFECTIVE_COUNT)
2326
BUILD_ASSERT(NET_TC_RX_SLOTS > 0,
2427
"Misconfiguration: There are more traffic classes then packets, "
2528
"either increase CONFIG_NET_PKT_RX_COUNT or decrease "
26-
"CONFIG_NET_TC_RX_COUNT");
29+
"CONFIG_NET_TC_RX_COUNT or disable CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO");
2730
#endif
2831

2932
#define TC_TX_PSEUDO_QUEUE (COND_CODE_1(CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO, (1), (0)))
@@ -84,7 +87,7 @@ enum net_verdict net_tc_submit_to_rx_queue(uint8_t tc, struct net_pkt *pkt)
8487
#if NET_TC_RX_COUNT > 0
8588
net_pkt_set_rx_stats_tick(pkt, k_cycle_get_32());
8689

87-
#if NET_TC_RX_COUNT > 1
90+
#if NET_TC_RX_EFFECTIVE_COUNT > 1
8891
if (k_sem_take(&rx_classes[tc].fifo_slot, K_NO_WAIT) != 0) {
8992
return NET_DROP;
9093
}
@@ -272,7 +275,7 @@ static void tc_rx_handler(void *p1, void *p2, void *p3)
272275
ARG_UNUSED(p3);
273276

274277
struct k_fifo *fifo = p1;
275-
#if NET_TC_RX_COUNT > 1
278+
#if NET_TC_RX_EFFECTIVE_COUNT > 1
276279
struct k_sem *fifo_slot = p2;
277280
#else
278281
ARG_UNUSED(p2);
@@ -285,7 +288,7 @@ static void tc_rx_handler(void *p1, void *p2, void *p3)
285288
continue;
286289
}
287290

288-
#if NET_TC_RX_COUNT > 1
291+
#if NET_TC_RX_EFFECTIVE_COUNT > 1
289292
k_sem_give(fifo_slot);
290293
#endif
291294

@@ -429,15 +432,15 @@ void net_tc_rx_init(void)
429432

430433
k_fifo_init(&rx_classes[i].fifo);
431434

432-
#if NET_TC_RX_COUNT > 1
435+
#if NET_TC_RX_EFFECTIVE_COUNT > 1
433436
k_sem_init(&rx_classes[i].fifo_slot, NET_TC_RX_SLOTS, NET_TC_RX_SLOTS);
434437
#endif
435438

436439
tid = k_thread_create(&rx_classes[i].handler, rx_stack[i],
437440
K_KERNEL_STACK_SIZEOF(rx_stack[i]),
438441
tc_rx_handler,
439442
&rx_classes[i].fifo,
440-
#if NET_TC_RX_COUNT > 1
443+
#if NET_TC_RX_EFFECTIVE_COUNT > 1
441444
&rx_classes[i].fifo_slot,
442445
#else
443446
NULL,

0 commit comments

Comments
 (0)