In the definition of kthread_create a task is waken up, does any one know what is this task 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(c开发者_JAVA百科reate.result, SCHED_NORMAL, ¶m);
set_cpus_allowed_ptr(create.result, cpu_all_mask);
}
return create.result;
}
kthreadd is a kernel daemon,it is started during kernel boot.
init/main.c ---> kernel_thread(kthreadd,...)
(architecture dependent code for e.g arch/arm/kernel/process.c)
As you can see here, kernel_thread()
returns a pid
. From pid
we determine the task_struct
and assign it to kthreadd_task
.
So whenever a call for creation of kernel thread i.e., kthread_create()
, kthreadd_task
is waken up, which inturn calls kthreadd()
(defined in kernel/kthread.c
).
kthreadd_task
is pointer to task_struct
of kernel thread runnind kthreadd()
function defined at http://lxr.linux.no/#linux+v2.6.36/kernel/kthread.c#L231
kthreadd()
is main function (and main loop) of daemon kthreadd
which is a kernel thread daemon, the parent of all other kernel threads.
So in the code quoted, there is a creation of request to kthreadd daemon. To fulfill this request kthreadd will read it and start a kernel thread. Then it will change the flag. In the code you have a waiting on this flag. After flag changing your function will check the status of new kthread creation.
精彩评论