Chinaunix首页 | 论坛 | 博客
  • 博客访问: 322478
  • 博文数量: 28
  • 博客积分: 609
  • 博客等级: 中士
  • 技术积分: 925
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-17 13:32
文章分类

全部博文(28)

文章存档

2022年(1)

2016年(1)

2015年(2)

2012年(1)

2011年(23)

分类: LINUX

2011-03-10 11:40:41

进入start_kernel就是进入了kernel启动的主线。其定义在init/main.c里面。start_kernel里面包含了一长串的init代码。看实际代码之前,我来猜一下有哪些需要初始化的:

1. CPU和SMP的初始化的初始化
2. 内存管理的初始化
3. 互斥和同步
4. 进程管理
5. 文件系统
6. 各类总线的初始化
7. 初始化硬件设备

好了,回头看看代码里面到底做了哪些初始化(以下的注解都是望文生义,我会随着以后对于每个模块的源码解读进行更新):
  1. asmlinkage void __init start_kernel(void)
  2. {
  3.     char * command_line;
  4.     extern const struct kernel_param __start___param[], __stop___param[];

  5.     smp_setup_processor_id(); //确定SMP系统中每个CPU的id

  6.     /*
  7.      * Need to run as early as possible, to initialize the
  8.      * lockdep hash:
  9.      */
  10.     lockdep_init(); //初始化互斥锁的dependency。
  11.     debug_objects_early_init(); //初始化debug kernel相关

  12.     /*
  13.      * Set up the the initial canary ASAP:
  14.      */
  15.     boot_init_stack_canary(); //stack_canary的是带防止栈溢出攻击保护的堆栈。

  16.     cgroup_init_early(); //cgroup是什么??有待查找

  17.     local_irq_disable(); //这个太直白了。
  18.     early_boot_irqs_off(); //这个也很直白。

  19. /*
  20.  * Interrupts are still disabled. Do necessary setups, then
  21.  * enable them
  22.  */
  23.     tick_init(); //初始化time ticket,时钟
  24.     boot_cpu_init(); //用以启动的CPU进行初始化。也就是初始化CPU0
  25.     page_address_init();//初始化页面
  26.     printk(KERN_NOTICE "%s", linux_banner);
  27.     setup_arch(&command_line); //CPU架构相关的初始化
  28.     mm_init_owner(&init_mm, &init_task); //初始化内存管理
  29.     setup_command_line(command_line); //处理启动命令行
  30.     setup_nr_cpu_ids(); //nr_cpu_id是什么?
  31.     setup_per_cpu_areas(); //为每个CPU开辟一块区域?
  32.     smp_prepare_boot_cpu();//准备boot_cpu.   /* arch-specific boot-cpu hooks */ 

  33.     build_all_zonelists(NULL); //建立什么样的zone??
  34.     page_alloc_init(); //初始化page allocation相关结构

  35.     printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
  36.     parse_early_param()
  37.     parse_args("Booting kernel", static_command_line, __start___param,
  38.          __stop___param - __start___param,
  39.          &unknown_bootoption);//解析启动参数
  40.     /*
  41.      * These use large bootmem allocations and must precede
  42.      * kmem_cache_init()
  43.      */
  44.     pidhash_init();//初始化process ID hash表
  45.     vfs_caches_init_early(); //文件系统caches预初始化
  46.     sort_main_extable(); //初始化exception table
  47.     trap_init(); //初始化trap,用以处理错误执行代码
  48.     mm_init(); //初始化内存管理
  49.     /*
  50.      * Set up the scheduler prior starting any interrupts (such as the
  51.      * timer interrupt). Full topology setup happens at smp_init()
  52.      * time - but meanwhile we still have a functioning scheduler.
  53.      */
  54.     sched_init(); //进程调度初始化
  55.     /*
  56.      * Disable preemption - early bootup scheduling is extremely
  57.      * fragile until we cpu_idle() for the first time.
  58.      */
  59.     preempt_disable(); //这个是什么东东?
  60.     if (!irqs_disabled()) {
  61.         printk(KERN_WARNING "start_kernel(): bug: interrupts were "
  62.                 "enabled *very* early, fixing it\n");
  63.         local_irq_disable();
  64.     }
  65.     rcu_init(); //Read_Copy_Update机制初始
  66.     radix_tree_init(); //什么是radlx_tree
  67.     /* init some links before init_ISA_irqs() */
  68.     early_irq_init();
  69.     init_IRQ(); //初始化中断
  70.     prio_tree_init(); //这是啥?以后要弄懂
  71.     init_timers(); //初始化时钟
  72.     hrtimers_init();//初始化高精时钟
  73.     softirq_init();//初始化软中断
  74.     timekeeping_init();//初始化时钟源
  75.     time_init();//初始化时间例程
  76.     profile_init(); //Profile?这是什么profile?
  77.     if (!irqs_disabled())
  78.         printk(KERN_CRIT "start_kernel(): bug: interrupts were "
  79.                  "enabled early\n");
  80.     early_boot_irqs_on();
  81.     local_irq_enable();

  82.     /* Interrupts are enabled now so all GFP allocations are safe. */
  83.     gfp_allowed_mask = __GFP_BITS_MASK;

  84.     kmem_cache_init_late();//初始化CPU Cache

  85.     /*
  86.      * HACK ALERT! This is early. We're enabling the console before
  87.      * we've done PCI setups etc, and console_init() must be aware of
  88.      * this. But we do want output early, in case something goes wrong.
  89.      */
  90.     console_init(); //初始化console
  91.     if (panic_later)
  92.         panic(panic_later, panic_param);

  93.     lockdep_info();

  94.     /*
  95.      * Need to run this when irqs are enabled, because it wants
  96.      * to self-test [hard/soft]-irqs on/off lock inversion bugs
  97.      * too:
  98.      */
  99.     locking_selftest(); //自测试锁

  100. #ifdef CONFIG_BLK_DEV_INITRD
  101.     if (initrd_start && !initrd_below_start_ok &&
  102.      page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
  103.         printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
  104.          "disabling it.\n",
  105.          page_to_pfn(virt_to_page((void *)initrd_start)),
  106.          min_low_pfn);
  107.         initrd_start = 0;
  108.     }
  109. #endif
  110.     page_cgroup_init(); //页面初始
  111.     enable_debug_pagealloc(); //页面分配debug启用
  112.     kmemleak_init(); //memory leak 侦测初始化
  113.     debug_objects_mem_init(); //debug object是什么?
  114.     idr_init_cache(); //idr是什么? 
  115.     setup_per_cpu_pageset(); //设置每个CPU的页面集合
  116.     numa_policy_init();// NUMA (Non Uniform Memory Access) policy 
  117.     if (late_time_init)
  118.         late_time_init();
  119.     sched_clock_init();//初始化调度时钟
  120.     calibrate_delay(); //协同不同CPU的时钟
  121.     pidmap_init();//pid是process id还是processor id?
  122.     anon_vma_init();//anonymous page?什么意思?
  123. #ifdef CONFIG_X86
  124.     if (efi_enabled)
  125.         efi_enter_virtual_mode();
  126. #endif
  127.     thread_info_cache_init(); //初始化thread info
  128.     cred_init(); //credential
  129.     fork_init(totalram_pages); //初始化fork
  130.     proc_caches_init(); //初始化/proc的cache?
  131.     buffer_init(); // buffer
  132.     key_init(); //key
  133.     security_init();//security
  134.     dbg_late_init();//debug
  135.     vfs_caches_init(totalram_pages);//文件系统cache初始化
  136.     signals_init();//signal
  137.     /* rootfs populating might need page-writeback */
  138.     page_writeback_init();page_writeback
  139. #ifdef CONFIG_PROC_FS
  140.     proc_root_init();
  141. #endif
  142.     cgroup_init(); //cgroup?
  143.     cpuset_init(); //cpuset
  144.     taskstats_init_early(); //task
  145.     delayacct_init();

  146.     check_bugs(); //检查什么bug?

  147.     acpi_early_init();//acpi /* before LAPIC and SMP init */ 
  148.     sfi_init_late(); //simple firmware interface

  149.     ftrace_init();

  150.     /* Do the rest non-__init'ed, we're now alive */
  151.     rest_init();
  152. }
将这些函数归归类,以后就按照类型来读:

CPU初始化
smp_setup_processor_id()
boot_cpu_init()
setup_arch(&command_line);
setup_nr_cpu_ids()
setup_per_cpu_areas()
smp_prepare_boot_cpu()
setup_per_cpu_pageset(); 
calibrate_delay();
cpuset_init();
内存管理初始化
boot_init_stack_canary()
page_address_init();
mm_init_owner();
page_alloc_init(); 
mm_init();
rcu_init();
kmem_cache_init_late();
page_cgroup_init(); 
kmemleak_init(); 
numa_policy_init();
anon_vma_init();
page_writeback_init();
进程管理
pidhash_init();
sched_init(); 
sched_clock_init()
pidmap_init();
fork_init(totalram_pages); 
taskstats_init_early();
文件系统
vfs_caches_init_early(); 
thread_info_cache_init();
vfs_caches_init(totalram_pages);
中断
early_irq_init();
init_IRQ(); 
softirq_init();
同步互斥
lockdep_init();
lockdep_info();
locking_selftest(); 
时钟
tick_init(); 
init_timers(); 
hrtimers_init();
timekeeping_init();
time_init();
调试
debug_objects_early_init();
console_init();
enable_debug_pagealloc(); 
debug_objects_mem_init();
dbg_late_init();
其他
sort_main_extable();
trap_init(); 
efi_enter_virtual_mode();
cred_init(); 
proc_caches_init(); 
buffer_init();
key_init(); 
security_init();
signals_init();
proc_root_init();
delayacct_init();
check_bugs();
acpi_early_init();
sfi_init_late(); 
未知
cgroup_init_early();
build_all_zonelists(NULL); 
preempt_disable();
radix_tree_init();
prio_tree_init(); 
profile_init();
idr_init_cache(); 
cgroup_init();
ftrace_init();
阅读(7927) | 评论(0) | 转发(5) |
给主人留下些什么吧!~~