Kernel rest_init相关
Linux系统里,有些进程只有kernel部分的代码,即由一个kernel函数进入,在sched的时候,将其与用户进程同等对待。
PID为0的叫swapper或sched进程,对应函数为rest_init
init进程PID为1,
kthreadd进程PID为2,
0号进程,即rest_init主体如下
static noinline void __init_refok rest_init(void)
{
int pid; rcu_scheduler_starting();
smpboot_thread_init();
/*
* 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);
先是rcu_scheduler_starting函数,这个函数的作用是
再是smpboot_thread_init函数,这个函数注册smpboot时候的notifier,响应CPU动作
static struct notifier_block smpboot_thread_notifier = {
.notifier_call = smpboot_thread_call,
.priority = CPU_PRI_SMPBOOT,
}; void __cpuinit smpboot_thread_init(void)
{
register_cpu_notifier(&smpboot_thread_notifier);
}
然后调用kernel_thread函数fork init进程
/*
* Create a kernel thread.
*/
pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
return do_fork(flags|CLONE_VM|CLONE_UNTRACED, (unsigned long)fn,
(unsigned long)arg, NULL, NULL);
}
do_fork函数被调用
这里有一点要注意,init进程执行的时候要等kerneladd进程执行后才被complete(&kthreadd_done)唤醒,然后真正执行,不然直接调度到init的话会OOPs
numa_default_policy被调用设置内存numa默认策略
然后调用kernel_thread函数fork kthreadd进程
然后用find_task_by_pid_ns(pid, &init_pid_ns)获取kthreadd的task_struct
最后唤醒complete(&kthreadd_done)进程
最后,0号进程,即空闲进程,要让一切跑起来,调用一次schedule
Kernel rest_init相关的更多相关文章
- Linux kernel驱动相关抽象概念及其实现 之“bus,device,driver”
bus,device,driver三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/642 ...
- Linux kernel驱动相关抽象概念及其实现 之“linux设备模型kobject,kset,ktype”
kobject,kset,ktype三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/64 ...
- linux kernel笔记
文章目录 关于linux内核中的__attribute__关键字 Linux kernel启动参数 gdt / ldt PCB 关于linux内核中的__attribute__关键字 part I: ...
- Linux kernel parameter command line设置
现在CPU2核以上比较普遍了,平时用linux上上网可能用不着双核甚至4核,大部分发行版内核都启用了CPU_HOTPLUG,到/sys/devices/system/cpu下可以看到文件夹cpu0.c ...
- OpenSUSE 内核编译教程 (kernel 2.6.x)
http://cn.opensuse.org/OpenSUSE_%E5%86%85%E6%A0%B8%E7%BC%96%E8%AF%91%E6%95%99%E7%A8%8B_(kernel_2.6.x ...
- LINUX KERNEL启动参数
LINUX KERNEL启动参数 在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时 ...
- Linux kernel启动选项(参数)(转)
Linux kernel启动选项(参数) 转载链接https://www.cnblogs.com/linuxbo/p/4286227.html 在Linux中,给kernel传递参数以控制其行为总共 ...
- Linux kernel启动选项(参数)
在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB ...
- /etc/sysctl.conf 控制内核相关配置文件
/etc/sysctl.conf 用于控制内核相关的配置参数,而且它的内容全部是对应于 /proc/sys/ 这个目录的子目录及文件 [root@MongoDB ~]# ll /proc/sys to ...
随机推荐
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...
- 03.RedisJava客户端Jedis的使用
1.Jedis基本使用 使用Jedis客户端使用Redis服务与在服务器上通过redis-cli使用命令基本一样,关于Redis命令请参考:http://www.redis.cn/commands.h ...
- Linux系统下利用wget命令把整站下载做镜像网站
Linux系统下利用wget命令把整站下载做镜像网站 2011-05-28 18:13:01 | 1次阅读 | 评论:0 条 | itokit 在linux下完整的用wget命令整站采集网站做镜像 ...
- HDU3341 Lost's revenge(AC自动机&&dp)
一看到ACGT就会想起AC自动机上的dp,这种奇怪的联想可能是源于某道叫DNA什么的题的. 题意,给你很多个长度不大于10的小串,小串最多有50个,然后有一个长度<40的串,然后让你将这个这个长 ...
- uva 10817
Problem D: Headmaster's Headache Time limit: 2 seconds The headmaster of Spring Field School is cons ...
- [读]剑指offer
研二的开始找工作了,首先祝愿他们都能够找到自己满意的工作.看着他们的身影,自问明年自己这个时候是否可以从容面对呢?心虚不已,赶紧从老严那儿讨来一本<剑指offer>.在此顺便将自己做题所想 ...
- POJ 3468 A Simple Problem with Integers(线段树)
题目链接 题意 : 给你n个数,进行两种操作,第一种是将a到b上所有元素都加上c,第二种是查询a到b上所有元素之和输出. 思路 : 线段树,以前写过博客,但是现在在重刷,风格改变,,所以重新写一篇.. ...
- java 语法错误 (操作符丢失) 在查询表达式
遇到的详细问题: a[0]="11"; a[1]="2223"; a[2]="333"; sta.executeUpdate("i ...
- Java7编程 高级进阶学习笔记--嵌套类
定义: 在一个类中定义的类叫做嵌套类. 作用: 1.允许对相关类进行逻辑分组 2.增强了代码的封装性 3.使代码具有更强的可读性和维护性 使用方式: package com.cmz.baseTest; ...
- Jquery DataTables warning : Requested unknown from the data source for row 0
昨天在做 Jquery DataTables 的时候,遇到的一个问题,我使用MVC,在tables上加入了一个actionlink的href.但是在运行起来的时候,报错: DataTables war ...