您的位置:首页 > 其它

实验三:gdb跟踪调试内核从start_kernel到init进程启动

2016-03-13 13:13 387 查看
原创作品转载请注明出处《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000

如果我写的不好或者有误的地方请留言

题目自拟,内容围绕Linux内核的启动过程,即从start_kernel到init进程启动;

博客中需要使用实验截图

博客内容中需要仔细分析start_kernel函数的执行过程

总结部分需要阐明自己对“Linux系统启动过程”的理解,尤其是idle进程、1号进程是怎么来的。

实验报告:

在实验楼里跑了一下gdb 没有多大印象 印象就是卡 这是卡吗 下面分析换自己的虚拟机

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);
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);
}


rest_init
咱们需要知道的东西如下:

在start_kernel中:

init_task:手工创建的PCB 0号进程即最终的idle进程
trap_init:初始化中断管理模块
mm_init:初始化内存管理模块
sched_init:初始化调度模块

在rest_init中:

run_init_process:linux系统中的1号进程 第一个用户态进程

注意:

1.我们需要首先初始化获得pid=1的进程 如果初始化最终创建了ktheads

我们在创建kthreadd之前调度它 Linux系统将会OOPS

2.启动空闲线程必须至少执行一次schedule()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: