您的位置:首页 > 运维架构 > Linux

全面解析Linux 内核 3.10.x - 启动1号进程

2016-01-14 21:09 671 查看
From: 全面解析Linux 内核 3.10.x - 本文章完全基于MIPS架构

坚持也许就是胜利 - 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 - 点滴积累
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: