Skip to content

Commit 623125f

Browse files
committed
Add idle task per hart at boot to prevent panic on no runnable tasks
To prevent kernel panic during startup when some harts may not have any runnable tasks assigned, add an idle task for each hart. The idle task runs an infinite loop calling mo_task_wfi(), ensuring the hart remains in a low-power wait state instead of causing a panic due to lack of tasks. This guarantees that every hart has at least one task to execute immediately after boot, improving system robustness and stability on SMP setups.
1 parent 84dfbc9 commit 623125f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
#include "private/error.h"
77

8+
static void idle_task(void)
9+
{
10+
while (1)
11+
mo_task_wfi();
12+
}
13+
814
static volatile bool finish = false;
915
static spinlock_t finish_lock = SPINLOCK_INITIALIZER;
1016

@@ -47,6 +53,8 @@ int32_t main(int32_t hartid)
4753
}
4854
spin_unlock(&finish_lock);
4955

56+
mo_task_spawn(idle_task, DEFAULT_STACK_SIZE);
57+
5058
/* Verify that the application created at least one task.
5159
* If 'kcb->task_current' is still NULL, it means mo_task_spawn was never
5260
* successfully called.

0 commit comments

Comments
 (0)