From 2c9f3072fb40cd3ea932449c9af55476e2f398d0 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Mon, 22 Aug 2022 01:03:43 +0200 Subject: [PATCH] net/gnrc_netif: add support for priority queues --- sys/include/net/gnrc/netif.h | 21 ++++++++++++++++++- sys/net/gnrc/link_layer/gomach/gomach.c | 2 +- sys/net/gnrc/link_layer/lwmac/lwmac.c | 2 +- sys/net/gnrc/netif/gnrc_netif.c | 19 +++++++++++++---- .../gnrc/netif/lorawan/gnrc_netif_lorawan.c | 2 +- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h index 9247e00f45..923a745539 100644 --- a/sys/include/net/gnrc/netif.h +++ b/sys/include/net/gnrc/netif.h @@ -76,6 +76,25 @@ extern "C" { #endif +/** + * @brief Index of the high priority queue + */ +#define GNRC_NETIF_EVQ_INDEX_PRIO_HIGH (0) + +/** + * @brief Index of the low priority queue + */ +#if IS_USED(MODULE_BHP_EVENT) +#define GNRC_NETIF_EVQ_INDEX_PRIO_LOW (GNRC_NETIF_EVQ_INDEX_PRIO_HIGH + 1) +#else +#define GNRC_NETIF_EVQ_INDEX_PRIO_LOW GNRC_NETIF_EVQ_INDEX_PRIO_HIGH +#endif + +/** + * @brief Number of event queues + */ +#define GNRC_NETIF_EVQ_NUMOF (GNRC_NETIF_EVQ_INDEX_PRIO_LOW + 1) + /** * @brief Per-Interface Event Message Buses */ @@ -142,7 +161,7 @@ typedef struct { /** * @brief Event queue for asynchronous events */ - event_queue_t evq; + event_queue_t evq[GNRC_NETIF_EVQ_NUMOF]; /** * @brief ISR event for the network device */ diff --git a/sys/net/gnrc/link_layer/gomach/gomach.c b/sys/net/gnrc/link_layer/gomach/gomach.c index e4ceaf8c63..90ab50bb13 100644 --- a/sys/net/gnrc/link_layer/gomach/gomach.c +++ b/sys/net/gnrc/link_layer/gomach/gomach.c @@ -2030,7 +2030,7 @@ static void _gomach_event_cb(netdev_t *dev, netdev_event_t event) gnrc_netif_t *netif = (gnrc_netif_t *) dev->context; if (event == NETDEV_EVENT_ISR) { - event_post(&netif->evq, &netif->event_isr); + event_post(&netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW], &netif->event_isr); } else { DEBUG("gnrc_netdev: event triggered -> %i\n", event); diff --git a/sys/net/gnrc/link_layer/lwmac/lwmac.c b/sys/net/gnrc/link_layer/lwmac/lwmac.c index fd5461335f..786ec394d9 100644 --- a/sys/net/gnrc/link_layer/lwmac/lwmac.c +++ b/sys/net/gnrc/link_layer/lwmac/lwmac.c @@ -795,7 +795,7 @@ static void _lwmac_event_cb(netdev_t *dev, netdev_event_t event) gnrc_netif_t *netif = (gnrc_netif_t *) dev->context; if (event == NETDEV_EVENT_ISR) { - event_post(&netif->evq, &netif->event_isr); + event_post(&netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW], &netif->event_isr); } else { DEBUG("gnrc_netdev: event triggered -> %i\n", event); diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 408417c23d..211a02716c 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1675,6 +1675,18 @@ static void _process_receive_stats(gnrc_netif_t *netdev, gnrc_pktsnip_t *pkt) netstats_nb_update_rx(&netdev->netif, src, src_len, hdr->rssi, hdr->lqi); } +static event_t *_gnrc_netif_fetch_event(gnrc_netif_t *netif) +{ + event_t *ev; + /* Iterate from highest priority to lowest priority */ + for (int i = 0; i < GNRC_NETIF_EVQ_NUMOF; i++) { + if ((ev = event_get(&netif->evq[i]))) { + return ev; + } + } + return NULL; +} + /** * @brief Process any pending events and wait for IPC messages * @@ -1697,8 +1709,7 @@ static void _process_events_await_msg(gnrc_netif_t *netif, msg_t *msg) event_t *evp; /* We can not use event_loop() or event_wait() because then we would not * wake up when a message arrives */ - event_queue_t *evq = &netif->evq; - while ((evp = event_get(evq))) { + while ((evp = _gnrc_netif_fetch_event(netif))) { DEBUG("gnrc_netif: event %p\n", (void *)evp); if (evp->handler) { evp->handler(evp); @@ -1844,7 +1855,7 @@ static void *_gnrc_netif_thread(void *args) netif->event_isr.handler = _event_handler_isr, /* set up the event queue */ - event_queue_init(&netif->evq); + event_queues_init(netif->evq, GNRC_NETIF_EVQ_NUMOF); /* setup the link-layer's message queue */ msg_init_queue(msg_queue, GNRC_NETIF_MSG_QUEUE_SIZE); @@ -1957,7 +1968,7 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) gnrc_netif_t *netif = (gnrc_netif_t *) dev->context; if (event == NETDEV_EVENT_ISR) { - event_post(&netif->evq, &netif->event_isr); + event_post(&netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW], &netif->event_isr); } else { DEBUG("gnrc_netif: event triggered -> %i\n", event); diff --git a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c index d0cf4df17e..8bbdbf4882 100644 --- a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c +++ b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c @@ -200,7 +200,7 @@ static void _driver_cb(netdev_t *dev, netdev_event_t event) gnrc_lorawan_t *mac = &netif->lorawan.mac; if (event == NETDEV_EVENT_ISR) { - event_post(&netif->evq, &netif->event_isr); + event_post(&netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW], &netif->event_isr); } else { DEBUG("gnrc_netif: event triggered -> %i\n", event);