1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include <mos/misc/setup.h>
4#include <mos/platform/platform.h>
5#include <mos/syslog/printk.h>
6#include <mos/tasks/kthread.h>
7#include <mos_stdio.h>
8
9static void idle_task(void *arg)
10{
11 MOS_UNUSED(arg);
12 platform_interrupt_enable();
13 while (true)
14 platform_cpu_idle();
15}
16
17static void create_idle_task()
18{
19 pr_dinfo2(process, "creating the idle task...");
20
21 for (u32 i = 0; i < platform_info->num_cpus; i++)
22 {
23 char namebuf[32];
24 snprintf(str: namebuf, size: sizeof(namebuf), format: "idle-%u", i);
25 pr_dinfo(process, "creating the idle task for CPU %u", i);
26 thread_t *t = kthread_create_no_sched(entry: idle_task, NULL, name: namebuf);
27 platform_info->cpu.percpu_value[i].idle_thread = t;
28 // ! scheduler will switch to this thread if no other threads are available, thus scheduler_add_thread isn't called
29 // thread_set_cpu(t, i);
30 MOS_UNUSED(t);
31 }
32}
33
34MOS_INIT(KTHREAD, create_idle_task);
35