Skip to content

Commit

Permalink
net/gnrc_netif: add support for priority queues
Browse files Browse the repository at this point in the history
  • Loading branch information
jia200x committed Aug 22, 2022
1 parent 0b5f270 commit c371ba5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
21 changes: 20 additions & 1 deletion sys/include/net/gnrc/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
18 changes: 14 additions & 4 deletions sys/net/gnrc/netif/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,17 @@ 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)
{
/* 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
*
Expand All @@ -1697,8 +1708,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 (_gnrc_netif_fetch_event(netif)) {
DEBUG("gnrc_netif: event %p\n", (void *)evp);
if (evp->handler) {
evp->handler(evp);
Expand Down Expand Up @@ -1844,7 +1854,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);
Expand Down Expand Up @@ -1957,7 +1967,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);
Expand Down

0 comments on commit c371ba5

Please sign in to comment.