开发者

Init and swapper tasks in Linux

开发者 https://www.devze.com 2023-04-10 05:08 出处:网络
I\'m confused about init and swapper tasks in the Linux kernel. My understanding is that the swapper task is like an idle task - it runs when no other processes are runnable. The init task stays aslee

I'm confused about init and swapper tasks in the Linux kernel. My understanding is that the swapper task is like an idle task - it runs when no other processes are runnable. The init task stays asleep, and wakes up to reap processes when required.

I've added another element to the task control block, which I want to initialize to zero for ALL tasks (开发者_如何转开发including init and swapper)

There is a very confusingly named macro, INIT_TASK, in linux/init_task.h, which, seemingly sets the initial values for the task control block of the swapper task.

Where do I set the initial values for the task control block of init? I'm able to set the initial values for all other tasks in the copy_process function in kernel/fork.c when they fork.


INIT_TASK macro is used to initialise the idle task (p->comm="swapper", so called swapper) structure which will linked into vmlinuz.

the 'init' task with pid = 1 in the system, is forked in the rest_init() in end of the start_kernel().

/kernel-3.0.36/init/main.c

347static noinline void __init_refok rest_init(void)
348{
349 int pid;
350
351 rcu_scheduler_starting();
352 /*
353  * We need to spawn init first so that it obtains pid 1, however
354  * the init task will end up wanting to create kthreads, which, if
355  * we schedule it before we create kthreadd, will OOPS.
356  */
357 kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);

so you can set the initial values for the task control block of init as normal.

0

精彩评论

暂无评论...
验证码 换一张
取 消