From 375cad38df9f548e3bbf59ca6ceae8c6d6f6a57f Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Fri, 15 May 2020 11:16:47 +0200 Subject: [PATCH] gnrc/sixlowpan: Configure queue size with exponent This changes the configuration macro to be the exponent of 2^n, as the message queue size needs to be always power of 2. --- sys/include/net/gnrc/sixlowpan/config.h | 17 ++++++++++++++--- sys/net/gnrc/network_layer/sixlowpan/Kconfig | 10 +++++++--- .../network_layer/sixlowpan/gnrc_sixlowpan.c | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sys/include/net/gnrc/sixlowpan/config.h b/sys/include/net/gnrc/sixlowpan/config.h index 686d48406f..3701d89bb5 100644 --- a/sys/include/net/gnrc/sixlowpan/config.h +++ b/sys/include/net/gnrc/sixlowpan/config.h @@ -43,10 +43,14 @@ extern "C" { #endif /** - * @brief Default message queue size to use for the 6LoWPAN thread. + * @brief Default message queue size to use for the 6LoWPAN thread (as + * exponent of 2^n). + * + * As the queue size ALWAYS needs to be power of two, this option represents the + * exponent of 2^n, which will be used as the size of the queue. */ -#ifndef CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE -#define CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE (8U) +#ifndef CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE_EXP +#define CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE_EXP (3U) #endif /** @@ -307,6 +311,13 @@ extern "C" { #endif /** @} */ +/** + * @brief Message queue size to use for the 6LoWPAN thread. + */ +#ifndef GNRC_SIXLOWPAN_MSG_QUEUE_SIZE +#define GNRC_SIXLOWPAN_MSG_QUEUE_SIZE (1 << CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE_EXP) +#endif + #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/network_layer/sixlowpan/Kconfig b/sys/net/gnrc/network_layer/sixlowpan/Kconfig index d38ae846f9..9aa2776697 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/Kconfig +++ b/sys/net/gnrc/network_layer/sixlowpan/Kconfig @@ -16,8 +16,12 @@ if KCONFIG_MODULE_GNRC_SIXLOWPAN rsource "frag/Kconfig" rsource "nd/Kconfig" -config GNRC_SIXLOWPAN_MSG_QUEUE_SIZE - int "Message queue size for the 6LoWPAN thread" - default 8 +config GNRC_SIXLOWPAN_MSG_QUEUE_SIZE_EXP + int "Exponent for the message queue size for the 6LoWPAN thread (as 2^n)" + default 3 + help + As the queue size ALWAYS needs to be power of two, this option + represents the exponent of 2^n, which will be used as the size of + the queue. endif # KCONFIG_MODULE_GNRC_SIXLOWPAN diff --git a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c index 5ea018b5b7..1ae7027b5c 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c +++ b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c @@ -308,12 +308,12 @@ static void _send(gnrc_pktsnip_t *pkt) static void *_event_loop(void *args) { - msg_t msg, reply, msg_q[CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE]; + msg_t msg, reply, msg_q[GNRC_SIXLOWPAN_MSG_QUEUE_SIZE]; gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, sched_active_pid); (void)args; - msg_init_queue(msg_q, CONFIG_GNRC_SIXLOWPAN_MSG_QUEUE_SIZE); + msg_init_queue(msg_q, GNRC_SIXLOWPAN_MSG_QUEUE_SIZE); /* register interest in all 6LoWPAN packets */ gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &me_reg);