Skip to content

Commit

Permalink
Merge pull request #20450 from benpicco/THREAD_CREATE_STACKTEST-delete
Browse files Browse the repository at this point in the history
core/thread: always use THREAD_CREATE_STACKTEST when DEVELHELP is enabled
  • Loading branch information
benpicco authored Jul 29, 2024
2 parents d2fa0c6 + 0fbc10f commit 41204c8
Show file tree
Hide file tree
Showing 111 changed files with 186 additions and 177 deletions.
29 changes: 20 additions & 9 deletions core/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
* In addition to the priority, flags can be used when creating a thread to
* alter the thread's behavior after creation. The following flags are available:
*
* Flags | Description
* ----------------------------- | --------------------------------------------------
* @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually
* @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation
* @ref THREAD_CREATE_STACKTEST | measures the stack's memory usage
* Flags | Description
* ------------------------------ | --------------------------------------------------
* @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually
* @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation
* @ref THREAD_CREATE_NO_STACKTEST| never measure the stack's memory usage
*
* Thread creation
* ===============
Expand Down Expand Up @@ -83,7 +83,7 @@
* int main(void)
* {
* thread_create(rcv_thread_stack, sizeof(rcv_thread_stack),
* THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
* THREAD_PRIORITY_MAIN - 1, 0,
* rcv_thread, NULL, "rcv_thread");
* }
* ~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -231,10 +231,20 @@ struct _thread {
#define THREAD_CREATE_WOUT_YIELD (4)

/**
* @brief Write markers into the thread's stack to measure stack usage (for
* debugging and profiling purposes)
* @brief Never write markers into the thread's stack to measure stack usage
*
* This flag is ignored when DEVELHELP or SCHED_TEST_STACK is not enabled
*/
#define THREAD_CREATE_NO_STACKTEST (8)

/**
* @brief Legacy flag kept for compatibility.
*
* @deprecated will be removed after 2025.07 release
*
* This is always enabled with `DEVELHELP=1` or `SCHED_TEST_STACK`.
*/
#define THREAD_CREATE_STACKTEST (8)
#define THREAD_CREATE_STACKTEST (0)
/** @} */

/**
Expand Down Expand Up @@ -456,6 +466,7 @@ static inline const char *thread_getname(kernel_pid_t pid)
* Only works if the stack is filled with canaries
* (`*((uintptr_t *)ptr) == (uintptr_t)ptr` for naturally aligned `ptr` within
* the stack).
* This is enabled if `DEVELHELP` or `SCHED_TEST_STACK` is set.
*
* @param[in] stack the stack you want to measure. Try
* `thread_get_stackstart(thread_get_active())`
Expand Down
4 changes: 2 additions & 2 deletions core/lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ void kernel_init(void)
if (IS_USED(MODULE_CORE_IDLE_THREAD)) {
thread_create(idle_stack, sizeof(idle_stack),
THREAD_PRIORITY_IDLE,
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
THREAD_CREATE_WOUT_YIELD,
idle_thread, NULL, "idle");
}

thread_create(main_stack, sizeof(main_stack),
THREAD_PRIORITY_MAIN,
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
THREAD_CREATE_WOUT_YIELD,
main_trampoline, NULL, "main");

cpu_switch_context_exit();
Expand Down
12 changes: 6 additions & 6 deletions core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,

#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
|| defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE)
if (flags & THREAD_CREATE_STACKTEST) {
if (flags & THREAD_CREATE_NO_STACKTEST) {
/* create stack guard. Alignment has been handled above, so silence
* -Wcast-align */
*(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack;
}
else {
/* assign each int of the stack the value of it's address. Alignment
* has been handled above, so silence -Wcast-align */
uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize);
Expand All @@ -276,11 +281,6 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
stackp++;
}
}
else {
/* create stack guard. Alignment has been handled above, so silence
* -Wcast-align */
*(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack;
}
#endif

unsigned state = irq_disable();
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp_common/freertos/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ BaseType_t xTaskCreatePinnedToCore(TaskFunction_t pvTaskCode,
usStackDepth + sizeof(thread_t),
uxPriority,
THREAD_CREATE_WOUT_YIELD |
THREAD_CREATE_STACKTEST,
0,
(void *)pvTaskCode,
pvParameters, pcName);
DEBUG("pid=%d\n", pid);
Expand Down
2 changes: 1 addition & 1 deletion examples/dtls-echo/dtls-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ static void start_server(void)
_dtls_server_pid = thread_create(_dtls_server_stack,
sizeof(_dtls_server_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
0,
_dtls_server_wrapper, NULL, "DTLS_Server");

/* Uncommon but better be sure */
Expand Down
2 changes: 1 addition & 1 deletion examples/dtls-sock/dtls-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void start_server(void)
_dtls_server_pid = thread_create(_dtls_server_stack,
sizeof(_dtls_server_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
0,
dtls_server_wrapper, NULL, "dtls_server");

/* Uncommon but better be sure */
Expand Down
2 changes: 1 addition & 1 deletion examples/ipc_pingpong/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(void)
msg_t m;

kernel_pid_t pid = thread_create(second_thread_stack, sizeof(second_thread_stack),
THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
THREAD_PRIORITY_MAIN - 1, 0,
second_thread, NULL, "pong");

m.content.value = 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/posix_sockets/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static int udp_start_server(char *port_str)
}
/* start server (which means registering pktdump for the chosen port) */
if (thread_create(server_stack, sizeof(server_stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
0,
_server_thread, port_str, "UDP server") <= KERNEL_PID_UNDEF) {
server_socket = -1;
puts("error initializing thread");
Expand Down
2 changes: 1 addition & 1 deletion examples/sniffer/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int main(void)
/* start and register rawdump thread */
puts("Run the rawdump thread and register it");
dump.target.pid = thread_create(rawdmp_stack, sizeof(rawdmp_stack), RAWDUMP_PRIO,
THREAD_CREATE_STACKTEST, rawdump, NULL, "rawdump");
0, rawdump, NULL, "rawdump");
dump.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL;
gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump);

Expand Down
6 changes: 3 additions & 3 deletions examples/thread_duel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ int main(void)
{
static char stack[WORKER_STACKSIZE];
static struct worker_config wc = THREAD_1; /* 0-10 workness */
thread_create(stack, sizeof(stack), 7, THREAD_CREATE_STACKTEST,
thread_create(stack, sizeof(stack), 7, 0,
thread_worker, &wc, "T1");
}
{
static char stack[WORKER_STACKSIZE];
static struct worker_config wc = THREAD_2; /* 0-10 workness */
thread_create(stack, sizeof(stack), 7, THREAD_CREATE_STACKTEST,
thread_create(stack, sizeof(stack), 7, 0,
thread_worker, &wc, "T2");
}
{
static char stack[WORKER_STACKSIZE];
static struct worker_config wc = THREAD_3; /* 0-10 workness */
thread_create(stack, sizeof(stack), 7, THREAD_CREATE_STACKTEST,
thread_create(stack, sizeof(stack), 7, 0,
thread_worker, &wc, "T3");
}
}
2 changes: 1 addition & 1 deletion pkg/lwip/contrib/netdev/lwip_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ err_t lwip_netdev_init(struct netif *netif)
/* start multiplexing thread (only one needed) */
if (_pid <= KERNEL_PID_UNDEF) {
_pid = thread_create(_stack, LWIP_NETDEV_STACKSIZE, LWIP_NETDEV_PRIO,
THREAD_CREATE_STACKTEST, _event_loop, netif,
0, _event_loop, netif,
LWIP_NETDEV_NAME);
if (_pid <= 0) {
return ERR_IF;
Expand Down
2 changes: 1 addition & 1 deletion pkg/lwip/contrib/sys_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
if (stack == NULL) {
return ERR_MEM;
}
if ((res = thread_create(stack, stacksize, prio, THREAD_CREATE_STACKTEST,
if ((res = thread_create(stack, stacksize, prio, 0,
_lwip_thread_wrapper, &params,
name)) <= KERNEL_PID_UNDEF) {
abort();
Expand Down
2 changes: 1 addition & 1 deletion pkg/mynewt-core/contrib/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int os_task_init(struct os_task *t, const char *name, os_task_func_t func,
LOG_DEBUG("[mynewt-core]: starting thread %s\n", name);

kernel_pid_t pid = thread_create(stack_bottom, (int) stack_size,
prio, THREAD_CREATE_STACKTEST,
prio, 0,
func, arg, name);

t->pid = pid;
Expand Down
4 changes: 2 additions & 2 deletions pkg/nimble/contrib/nimble_riot.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void *_host_thread(void *arg)
*/
thread_create(_stack_controller, sizeof(_stack_controller),
NIMBLE_CONTROLLER_PRIO,
THREAD_CREATE_STACKTEST,
0,
(thread_task_func_t)nimble_port_ll_task_func, NULL,
"nimble_ctrl");

Expand Down Expand Up @@ -133,7 +133,7 @@ void nimble_riot_init(void)
/* and finally initialize and run the host */
thread_create(_stack_host, sizeof(_stack_host),
NIMBLE_HOST_PRIO,
THREAD_CREATE_STACKTEST,
0,
_host_thread, NULL,
"nimble_host");

Expand Down
2 changes: 1 addition & 1 deletion pkg/openthread/contrib/netdev/openthread_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void *_openthread_event_loop(void *arg)
int openthread_netdev_init(char *stack, int stacksize, char priority,
const char *name, netdev_t *netdev) {
if (thread_create(stack, stacksize,
priority, THREAD_CREATE_STACKTEST,
priority, 0,
_openthread_event_loop, netdev, name) < 0) {
return -EINVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/openwsn/contrib/openwsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int openwsn_bootstrap(void)

LOG_DEBUG("[openwsn]: network thread\n");
_pid = thread_create(_stack, OPENWSN_SCHED_STACKSIZE, OPENWSN_SCHED_PRIO,
THREAD_CREATE_STACKTEST, _event_loop, NULL,
0, _event_loop, NULL,
OPENWSN_SCHED_NAME);
if (_pid <= 0) {
LOG_ERROR("[openwsn]: couldn't create thread\n");
Expand Down
2 changes: 1 addition & 1 deletion pkg/paho-mqtt/contrib/riot_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ int ThreadStart(Thread *thread, void (*fn)(void *), void *arg)
(void) fn;
thread->pid = thread_create(thread->stack, sizeof(thread->stack),
MQTT_THREAD_PRIORITY,
THREAD_CREATE_STACKTEST, mqtt_riot_run, arg,
0, mqtt_riot_run, arg,
"paho_mqtt_riot");
return thread->pid;
}
2 changes: 1 addition & 1 deletion pkg/semtech-loramac/contrib/semtech_loramac.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ int semtech_loramac_init(semtech_loramac_t *mac)
semtech_loramac_pid = thread_create(_semtech_loramac_stack,
sizeof(_semtech_loramac_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
0,
_semtech_loramac_event_loop, mac,
"recv_thread");

Expand Down
4 changes: 2 additions & 2 deletions pkg/tinyusb/contrib/tinyusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ int tinyusb_setup(void)
sizeof(_tinyusb_thread_stack),
TINYUSB_PRIORITY,
#if MODULE_RIOTBOOT_TINYUSB_DFU
THREAD_CREATE_STACKTEST,
0,
#else
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
THREAD_CREATE_WOUT_YIELD,
#endif
_tinyusb_thread_impl, NULL, "tinyusb")) < 0) {
LOG_ERROR("tinyUSB thread couldn't be created, reason %d\n", res);
Expand Down
2 changes: 1 addition & 1 deletion pkg/uwb-core/contrib/uwb_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void uwb_core_riot_init(void)
#if !IS_USED(MODULE_UWB_CORE_EVENT_THREAD)
thread_create(_stack_uwb_core, sizeof(_stack_uwb_core),
UWB_CORE_PRIO,
THREAD_CREATE_STACKTEST,
0,
_uwb_core_thread, NULL,
"uwb_core_event");
#endif
Expand Down
2 changes: 1 addition & 1 deletion sys/auto_init/wdt_thread/wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void *_wdt_thread(void *ctx)
static void auto_init_wdt_thread(void)
{
thread_create(wdt_stack, sizeof(wdt_stack), THREAD_PRIORITY_MIN,
THREAD_CREATE_STACKTEST, _wdt_thread, NULL, "watchdog");
0, _wdt_thread, NULL, "watchdog");
}

AUTO_INIT(auto_init_wdt_thread, AUTO_INIT_PRIO_WDT_THREAD);
2 changes: 1 addition & 1 deletion sys/can/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ kernel_pid_t can_device_init(char *stack, int stacksize, char priority,
}

/* create new can device thread */
res = thread_create(stack, stacksize, priority, THREAD_CREATE_STACKTEST,
res = thread_create(stack, stacksize, priority, 0,
_can_device_thread, (void *)params, name);
if (res <= 0) {
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion sys/can/isotp/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *n
DEBUG("isotp_init\n");

/* create new can device thread */
res = thread_create(stack, stacksize, priority, THREAD_CREATE_STACKTEST,
res = thread_create(stack, stacksize, priority, 0,
_isotp_thread, NULL, name);
if (res <= 0) {
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion sys/event/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void event_thread_init_multi(event_queue_t *queues, size_t queues_numof,

void *tagged_ptr = ptrtag(queues, queues_numof - 1);

thread_create(stack, stack_size, priority, THREAD_CREATE_STACKTEST,
thread_create(stack, stack_size, priority, 0,
_handler_thread, tagged_ptr, "event");
}

Expand Down
2 changes: 1 addition & 1 deletion sys/fido2/ctap/transport/ctap_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void fido2_ctap_transport_init(void)
#endif

int ret = thread_create(_ctap_stack, sizeof(_ctap_stack), CTAP_TRANSPORT_PRIO,
THREAD_CREATE_STACKTEST, _event_loop, NULL,
0, _event_loop, NULL,
"fido2_ctap_transport_loop");

(void)ret;
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/asymcute/asymcute.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void _on_pkt(sock_udp_t *sock, sock_async_flags_t type, void *arg)
void asymcute_handler_run(void)
{
thread_create(_stack, sizeof(_stack), ASYMCUTE_HANDLER_PRIO,
THREAD_CREATE_STACKTEST, _eventloop, NULL, "asymcute_main");
0, _eventloop, NULL, "asymcute_main");
}

int asymcute_topic_init(asymcute_topic_t *topic, const char *topic_name,
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/cord/ep/cord_ep_standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void *_reg_runner(void *arg)

void cord_ep_standalone_run(void)
{
thread_create(_stack, sizeof(_stack), PRIO, THREAD_CREATE_STACKTEST,
thread_create(_stack, sizeof(_stack), PRIO, 0,
_reg_runner, NULL, TNAME);
}

Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/dhcpv6/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void dhcpv6_client_auto_init(void)
if (_thread_pid <= 0) {
_thread_pid = thread_create(_thread_stack, DHCPV6_CLIENT_STACK_SIZE,
DHCPV6_CLIENT_PRIORITY,
THREAD_CREATE_STACKTEST,
0,
_thread, NULL, "dhcpv6-client");
}
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/dhcpv6/relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void dhcpv6_relay_auto_init(void)
}
else {
thread_create(_auto_init_stack, ARRAY_SIZE(_auto_init_stack),
AUTO_INIT_PRIO, THREAD_CREATE_STACKTEST,
AUTO_INIT_PRIO, 0,
_dhcpv6_relay_auto_init_thread,
(void *)(intptr_t)netif, "dhcpv6_relay");
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ kernel_pid_t gcoap_init(void)
return -EEXIST;
}
_pid = thread_create(_msg_stack, sizeof(_msg_stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST, _event_loop, NULL, "coap");
0, _event_loop, NULL, "coap");

mutex_init(&_coap_state.lock);
/* Blank lists so we know if an entry is available. */
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/nanocoap/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ kernel_pid_t nanocoap_server_start(const sock_udp_ep_t *local)
return _coap_server_pid;
}
_coap_server_pid = thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST, _nanocoap_server_thread,
0, _nanocoap_server_thread,
(void *)local, "nanoCoAP server");
return _coap_server_pid;
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/telnet/telnet_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ int telnet_server_start(void)

/* initiate telnet server */
thread_create(telnet_stack, sizeof(telnet_stack),
THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
THREAD_PRIORITY_MAIN - 1, 0,
telnet_thread, NULL, "telnet");

return 0;
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void gnrc_dhcpv6_client_simple_pd_init(void)
/* start DHCPv6 client thread to request prefix for WPAN */
thread_create(_stack, DHCPV6_CLIENT_STACK_SIZE,
DHCPV6_CLIENT_PRIORITY,
THREAD_CREATE_STACKTEST,
0,
_dhcpv6_cl_simple_pd_thread, NULL, "dhcpv6-client");
}

Expand Down
Loading

0 comments on commit 41204c8

Please sign in to comment.