What is kthreadd_task

In the definition of kthread_create, the task wakes up, does anyone know what this task is doing?

struct task_struct *kthread_create { struct kthread_create_info create; create.threadfn = threadfn; create.data = data; init_completion(&create.done); spin_lock(&kthread_create_lock); list_add_tail(&create.list, &kthread_create_list); spin_unlock(&kthread_create_lock); **wake_up_process(kthreadd_task);** wait_for_completion(&create.done); if (!IS_ERR(create.result)) { struct sched_param param = { .sched_priority = 0 }; va_list args; va_start(args, namefmt); vsnprintf(create.result->comm, sizeof(create.result->comm), namefmt, args); va_end(args); /* * root may have changed our (kthreadd's) priority or CPU mask. * The kernel thread should not inherit these properties. */ sched_setscheduler_nocheck(create.result, SCHED_NORMAL, &param); set_cpus_allowed_ptr(create.result, cpu_all_mask); } return create.result; } 
+6
linux-kernel
source share
2 answers

kthreadd_task is a pointer to task_struct the runnind kthreadd() function for the kernel defined in http://lxr.linux.no/#linux+v2.6.36/kernel/kthread.c#L231

kthreadd() is the main function (and main loop) of the kthreadd daemon, which is a kernel thread daemon, the parent of all other kernel threads.

So, in the above code, a request is made to the kthreadd daemons. To fulfill this request, kthreadd will read it and start the kernel thread. Then he will change the flag. In code, you have an expectation of this flag. After changing the flag, your function will check the status of the new kthread creation.

+3
source share

kthreadd is a kernel daemon, it starts when the kernel boots.

 init/main.c ---> kernel_thread(kthreadd,...) (architecture dependent code for eg arch/arm/kernel/process.c) 

As you can see here, kernel_thread() returns pid . From pid we define task_struct and assign it kthreadd_task .

Therefore, whenever a call is made to create a kernel thread, i.e. kthread_create() , kthreadd_task , which inturn calls kthreadd() (defined in kernel/kthread.c ).

+2
source share

All Articles