From 975f8959ceff953b0f9e50c142f59cbca5c9866c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Thu, 19 Oct 2023 17:45:08 +0200 Subject: [PATCH 1/6] gnrc/ipv6: make message queue static --- sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index a70f2e0783..382d2fcc6a 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -50,6 +50,7 @@ #define _MAX_L2_ADDR_LEN (8U) static char _stack[GNRC_IPV6_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; +static msg_t _msg_q[GNRC_IPV6_MSG_QUEUE_SIZE]; #ifdef MODULE_FIB /** @@ -172,12 +173,12 @@ static void _dispatch_next_header(gnrc_pktsnip_t *pkt, unsigned nh, static void *_event_loop(void *args) { - msg_t msg, reply, msg_q[GNRC_IPV6_MSG_QUEUE_SIZE]; + msg_t msg, reply; gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, thread_getpid()); (void)args; - msg_init_queue(msg_q, GNRC_IPV6_MSG_QUEUE_SIZE); + msg_init_queue(_msg_q, GNRC_IPV6_MSG_QUEUE_SIZE); /* initialize fragmentation data-structures */ #ifdef MODULE_GNRC_IPV6_EXT_FRAG From 662f1be5d51bfe0d2e3c1f9493f33815f060b6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Thu, 19 Oct 2023 17:47:24 +0200 Subject: [PATCH 2/6] gnrc/sixlowpan: make message queue static --- sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c index 6083f5adf1..29a82cd40a 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c +++ b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c @@ -36,6 +36,7 @@ static kernel_pid_t _pid = KERNEL_PID_UNDEF; static char _stack[GNRC_SIXLOWPAN_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; +static msg_t _msg_q[GNRC_SIXLOWPAN_MSG_QUEUE_SIZE]; /* handles GNRC_NETAPI_MSG_TYPE_RCV commands */ static void _receive(gnrc_pktsnip_t *pkt); @@ -385,12 +386,12 @@ static void _continue_fragmenting(gnrc_sixlowpan_frag_fb_t *fbuf) static void *_event_loop(void *args) { - msg_t msg, reply, msg_q[GNRC_SIXLOWPAN_MSG_QUEUE_SIZE]; + msg_t msg, reply; gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, thread_getpid()); (void)args; - msg_init_queue(msg_q, 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); From c741fa5fbea751f367bb26c5031914aed7fa4e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Thu, 19 Oct 2023 17:49:25 +0200 Subject: [PATCH 3/6] gnrc/pktdump: make message queue static --- sys/net/gnrc/pktdump/gnrc_pktdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/net/gnrc/pktdump/gnrc_pktdump.c b/sys/net/gnrc/pktdump/gnrc_pktdump.c index 539af12f5a..40e97d56d3 100644 --- a/sys/net/gnrc/pktdump/gnrc_pktdump.c +++ b/sys/net/gnrc/pktdump/gnrc_pktdump.c @@ -44,6 +44,7 @@ kernel_pid_t gnrc_pktdump_pid = KERNEL_PID_UNDEF; * @brief Stack for the pktdump thread */ static char _stack[GNRC_PKTDUMP_STACKSIZE]; +static msg_t _msg_queue[GNRC_PKTDUMP_MSG_QUEUE_SIZE]; static void _dump_snip(gnrc_pktsnip_t *pkt) { @@ -166,10 +167,9 @@ static void *_eventloop(void *arg) { (void)arg; msg_t msg, reply; - msg_t msg_queue[GNRC_PKTDUMP_MSG_QUEUE_SIZE]; /* setup the message queue */ - msg_init_queue(msg_queue, GNRC_PKTDUMP_MSG_QUEUE_SIZE); + msg_init_queue(_msg_queue, GNRC_PKTDUMP_MSG_QUEUE_SIZE); reply.content.value = (uint32_t)(-ENOTSUP); reply.type = GNRC_NETAPI_MSG_TYPE_ACK; From 5aa3baac8ca09036b209e5583dfc0b12c9d4edac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Thu, 19 Oct 2023 17:52:30 +0200 Subject: [PATCH 4/6] gnrc/udp: make message queue static --- sys/net/gnrc/transport_layer/udp/gnrc_udp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/net/gnrc/transport_layer/udp/gnrc_udp.c b/sys/net/gnrc/transport_layer/udp/gnrc_udp.c index ddf3423e32..38c77eeec4 100644 --- a/sys/net/gnrc/transport_layer/udp/gnrc_udp.c +++ b/sys/net/gnrc/transport_layer/udp/gnrc_udp.c @@ -43,6 +43,7 @@ static kernel_pid_t _pid = KERNEL_PID_UNDEF; * @brief Allocate memory for the UDP thread's stack */ static char _stack[GNRC_UDP_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; +static msg_t _msg_queue[GNRC_UDP_MSG_QUEUE_SIZE]; /** * @brief Calculate the UDP checksum dependent on the network protocol @@ -220,14 +221,13 @@ static void *_event_loop(void *arg) { (void)arg; msg_t msg, reply; - msg_t msg_queue[GNRC_UDP_MSG_QUEUE_SIZE]; gnrc_netreg_entry_t netreg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, thread_getpid()); /* preset reply message */ reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)-ENOTSUP; /* initialize message queue */ - msg_init_queue(msg_queue, GNRC_UDP_MSG_QUEUE_SIZE); + msg_init_queue(_msg_queue, GNRC_UDP_MSG_QUEUE_SIZE); /* register UPD at netreg */ gnrc_netreg_register(GNRC_NETTYPE_UDP, &netreg); From 85e39881330eaaaa253830ce1151b332961e6370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Thu, 19 Oct 2023 17:56:40 +0200 Subject: [PATCH 5/6] core/msg: better DEBUG() in queue_msg --- core/msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/msg.c b/core/msg.c index 91919442f3..13d2b4eece 100644 --- a/core/msg.c +++ b/core/msg.c @@ -46,7 +46,8 @@ static int queue_msg(thread_t *target, const msg_t *m) int n = cib_put(&(target->msg_queue)); if (n < 0) { - DEBUG("queue_msg(): message queue is full (or there is none)\n"); + DEBUG("queue_msg(): message queue of thread %" PRIkernel_pid + " is full (or there is none)\n", target->pid); return 0; } From 0cc2bdaf5babd6d2805f8c421d8b6ee0dd98927a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Sun, 3 Dec 2023 17:53:44 +0100 Subject: [PATCH 6/6] sys/include/net/gnrc: reduce stack by previously allocated message queue --- sys/include/net/gnrc/ipv6.h | 6 +++++- sys/include/net/gnrc/pktdump.h | 6 +++++- sys/include/net/gnrc/sixlowpan/config.h | 6 +++++- sys/include/net/gnrc/udp.h | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sys/include/net/gnrc/ipv6.h b/sys/include/net/gnrc/ipv6.h index ecc5f76d9f..7098fc9923 100644 --- a/sys/include/net/gnrc/ipv6.h +++ b/sys/include/net/gnrc/ipv6.h @@ -122,9 +122,13 @@ extern "C" { */ /** * @brief Default stack size to use for the IPv6 thread + * + * @note The message queue was previously allocated on the stack. + * The default number of messages is 2³. + * Given sizeof(msg_t) == 8, the stack size is reduced by 64 bytes. */ #ifndef GNRC_IPV6_STACK_SIZE -#define GNRC_IPV6_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) +#define GNRC_IPV6_STACK_SIZE ((THREAD_STACKSIZE_DEFAULT) - 64) #endif /** diff --git a/sys/include/net/gnrc/pktdump.h b/sys/include/net/gnrc/pktdump.h index bac76cd0e4..5a0498256d 100644 --- a/sys/include/net/gnrc/pktdump.h +++ b/sys/include/net/gnrc/pktdump.h @@ -62,9 +62,13 @@ extern "C" { /** * @brief Stack size used for the pktdump thread + * + * @note The message queue was previously allocated on the stack. + * The default number of messages is 2³. + * Given sizeof(msg_t) == 8, the stack size is reduced by 64 bytes. */ #ifndef GNRC_PKTDUMP_STACKSIZE -#define GNRC_PKTDUMP_STACKSIZE (THREAD_STACKSIZE_MAIN) +#define GNRC_PKTDUMP_STACKSIZE ((THREAD_STACKSIZE_MAIN) - 64) #endif /** diff --git a/sys/include/net/gnrc/sixlowpan/config.h b/sys/include/net/gnrc/sixlowpan/config.h index 6736455278..0588d0b262 100644 --- a/sys/include/net/gnrc/sixlowpan/config.h +++ b/sys/include/net/gnrc/sixlowpan/config.h @@ -30,9 +30,13 @@ extern "C" { /** * @brief Default stack size to use for the 6LoWPAN thread. + * + * @note The message queue was previously allocated on the stack. + * The default number of messages is 2³. + * Given sizeof(msg_t) == 8, the stack size is reduced by 64 bytes. */ #ifndef GNRC_SIXLOWPAN_STACK_SIZE -#define GNRC_SIXLOWPAN_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) +#define GNRC_SIXLOWPAN_STACK_SIZE ((THREAD_STACKSIZE_DEFAULT) - 64) #endif /** diff --git a/sys/include/net/gnrc/udp.h b/sys/include/net/gnrc/udp.h index b3f59ee8e4..8e2da33a7f 100644 --- a/sys/include/net/gnrc/udp.h +++ b/sys/include/net/gnrc/udp.h @@ -57,9 +57,13 @@ extern "C" { /** * @brief Default stack size to use for the UDP thread + * + * @note The message queue was previously allocated on the stack. + * The default number of messages is 2³. + * Given sizeof(msg_t) == 8, the stack size is reduced by 64 bytes. */ #ifndef GNRC_UDP_STACK_SIZE -#define GNRC_UDP_STACK_SIZE (THREAD_STACKSIZE_SMALL) +#define GNRC_UDP_STACK_SIZE ((THREAD_STACKSIZE_SMALL) - 64) #endif /** @} */