From b9a76ea094c84d16e7548d95fcb9fdd7f99f6e18 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 9 Jan 2024 18:59:28 +0100 Subject: [PATCH 1/4] core/init: avoid context switch with !core_thread --- core/lib/init.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/lib/init.c b/core/lib/init.c index cdf7358a4e..0dbbc6971c 100644 --- a/core/lib/init.c +++ b/core/lib/init.c @@ -106,8 +106,11 @@ void kernel_init(void) main_trampoline, NULL, "main"); } else { + /* RIOT without threads */ irq_enable(); main_trampoline(NULL); + while (1) {} + return; } cpu_switch_context_exit(); From 14d0cf5d87ad02ea002a223d8d751db45ae89cf2 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 9 Jan 2024 18:59:58 +0100 Subject: [PATCH 2/4] Makefile.dep: don't include idle thread with !core_thread --- makefiles/features_modules.inc.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefiles/features_modules.inc.mk b/makefiles/features_modules.inc.mk index 77e344a808..2f9792c68e 100644 --- a/makefiles/features_modules.inc.mk +++ b/makefiles/features_modules.inc.mk @@ -83,7 +83,9 @@ USEMODULE += $(filter cortexm_svc, $(FEATURES_USED)) # select core_idle_thread if the feature no_idle_thread is *not* used ifeq (, $(filter no_idle_thread, $(FEATURES_USED))) - USEMODULE += core_idle_thread + ifneq (,$(filter core_thread, $(USEMODULE))) + USEMODULE += core_idle_thread + endif endif # use mpu_stack_guard if the feature is used From 112e378fccf13b091a7f761395d390b2eaabebde Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 9 Jan 2024 19:00:22 +0100 Subject: [PATCH 3/4] cpu/avr8_common: fix build with !core_thread --- cpu/avr8_common/thread_arch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpu/avr8_common/thread_arch.c b/cpu/avr8_common/thread_arch.c index 1806db364b..f6529c9fb4 100644 --- a/cpu/avr8_common/thread_arch.c +++ b/cpu/avr8_common/thread_arch.c @@ -260,6 +260,10 @@ void NORETURN avr8_enter_thread_mode(void) void thread_yield_higher(void) { + if (!IS_USED(MODULE_CORE_THREAD)) { + return; + } + if (irq_is_in() == 0) { avr8_context_save(); sched_run(); @@ -278,7 +282,8 @@ void avr8_exit_isr(void) __asm__ volatile ("" : : : "memory"); /* schedule should switch context when returning from a non nested interrupt */ - if (sched_context_switch_request && avr8_state_irq_count == 0) { + if (sched_context_switch_request && avr8_state_irq_count == 0 && + IS_USED(MODULE_CORE_THREAD)) { avr8_context_save(); sched_run(); avr8_context_restore(); From cb76cc17e9607e9d7c7aa90d01cac4db4ad5522b Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 9 Jan 2024 23:02:01 +0100 Subject: [PATCH 4/4] cpu/native: fix build with !core_thread --- cpu/native/native_cpu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index 5e9e96875a..13fff4e2c4 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -156,7 +156,8 @@ void isr_cpu_switch_context_exit(void) ucontext_t *ctx; DEBUG("isr_cpu_switch_context_exit\n"); - if ((sched_context_switch_request == 1) || (thread_get_active() == NULL)) { + if (((sched_context_switch_request == 1) || (thread_get_active() == NULL)) + && IS_USED(MODULE_CORE_THREAD)) { sched_run(); } @@ -210,7 +211,11 @@ void isr_thread_yield(void) native_irq_handler(); } + if (!IS_USED(MODULE_CORE_THREAD)) { + return; + } sched_run(); + /* Use intermediate cast to uintptr_t to silence -Wcast-align. * stacks are manually word aligned in thread_static_init() */ ucontext_t *ctx = (ucontext_t *)(uintptr_t)(thread_get_active()->sp);