Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/gnrc_netif: add support for priority queues #18496

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion sys/net/gnrc/link_layer/gomach/gomach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/link_layer/lwmac/lwmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 15 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,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
*
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ void auto_init_kw2xrf(void)
LOG_DEBUG("[auto_init_netif] initializing kw2xrf #%u\n", i);

/* Init Bottom Half Processor (with events module) and radio */
bhp_event_init(&kw2xrf_bhp[i], &_netif[i].evq, &kw2xrf_radio_hal_irq_handler, &kw2xrf_netdev[i].submac.dev);
kw2xrf_init(&kw2xrf_devs[i], (kw2xrf_params_t*) p,&kw2xrf_netdev[i].submac.dev,
bhp_event_init(&kw2xrf_bhp[i], &_netif[i].evq[GNRC_NETIF_EVQ_INDEX_PRIO_HIGH],
&kw2xrf_radio_hal_irq_handler, &kw2xrf_netdev[i].submac.dev);
kw2xrf_init(&kw2xrf_devs[i], p, &kw2xrf_netdev[i].submac.dev,
bhp_event_isr_cb, &kw2xrf_bhp[i]);


netdev_register(&kw2xrf_netdev[i].dev.netdev, NETDEV_KW2XRF, i);
netdev_ieee802154_submac_init(&kw2xrf_netdev[i]);

Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down