在 kthread_create 的定义中,一个任务被唤醒,有人知道这个任务在做什么吗?
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, ¶m);
set_cpus_allowed_ptr(create.result, cpu_all_mask);
}
return create.result;
}
最佳答案
kthreadd 是一个内核守护进程,它在内核引导期间启动。
init/main.c ---> kernel_thread(kthreadd,...)
(architecture dependent code for e.g arch/arm/kernel/process.c)
正如你在这里看到的,
kernel_thread()
返回 pid
.来自 pid
我们确定task_struct
并将其分配给 kthreadd_task
.因此,每当调用创建内核线程时,即
kthread_create()
, kthreadd_task
被唤醒,反过来调用 kthreadd()
(在 kernel/kthread.c
中定义)。
关于linux-kernel - 什么是 kthreadd_task,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4164429/