坚持也许就是胜利 - Keven
当内核找到文件系统以后(这里已经挂载proc文件系统了),内核的主要启动使命就越来越少了。因为江山基本已经打下了,剩下的就是要坐江山了。来看下面的这段代码。
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);
}
上述代码属于start_kernel的末时了。
rset_init 主要做了以下几件事。
刷新调度系统 - rcu_scheduler_starting
启动1号进程(祖先进程) - kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
启动2号进程 - pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
进程抢占disable - schedule_preempt_disabled();
内核进程等待状态。
配置cpu_idle
..
这里我们只将1号进程,后面我还需要在去透析下cpu_idle.
By: Keven - 点滴积累