【发布时间】:2015-08-12 08:12:09
【问题描述】:
这段代码来自Linux内核:
kernel/init/main.c
static noinline void __init_refok rest_init(void)
{
int pid;
rcu_scheduler_starting();
/*
* We need to spawn init first so that it obtains pid 1, however
* the init task will end up wanting to create kthreads, which, if
* we schedule it before we create kthreadd, will OOPS.
*/
kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
numa_default_policy();
pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
rcu_read_lock();
kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
rcu_read_unlock();
complete(&kthreadd_done);
/*
* The boot idle thread must execute schedule()
* at least once to get things moving:
*/
init_idle_bootup_task(current);
schedule_preempt_disabled();
/* Call into cpu_idle with preempt disabled */
cpu_startup_entry(CPUHP_ONLINE);
}
我从内核启动就知道,内核启动时有一个0进程会初始化所有的东西,直到这个时候,它运行的函数是:rest_init
这里:它会创建我们称之为 1 进程的 init 进程。
kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
运行函数后,现在应该有两个进程0和1。
问题:
此时0和1进程都在同一个cpu中的同一个线程列表(如果有4或8 cpu平台的话)?两个进程是如何调度的?
如果它们在同一个cpu的一个线程列表中,当0个进程调用
schedule_preempt_disabledfunction()时,表示停止调度。那么0进程在空闲时间进入cpu_startup_entry(),哪个进程会设置need_resched标志让idle(0)进程调度呢?我的意思是进程1不会再次运行?或者你可以告诉我详细的0和1过程此时如何调度。
【问题讨论】:
标签: linux-kernel