linux源码分析-/init/main.c/start_kernel

asmlinkage void __init start_kernel(void)
{
    char * command_line;
    extern const struct kernel_param __start___param[], __stop___param[];    //这两个变量为地址指针,指向内核启动参数处理相关结构体段在内存中的位置(虚拟地址)。 声明传入参数的外部参数对于ARM平台,位于 include\asm-generic\vmlinux.lds.h

    /*
     * Need to run as early as possible, to initialize the
     * lockdep hash:
     */
    lockdep_init();    //初始化内核依赖的关系表,初始化hash表
    smp_setup_processor_id();    //获取当前CPU,单处理器为空
    debug_objects_early_init();    //对调试对象进行早期的初始化,其实就是HASH锁和静态对象池进行初始化  
 

    /*
     * Set up the the initial canary ASAP:
     */
    boot_init_stack_canary();    //初始化栈canary值
     canary值的是用于防止栈溢出攻击的堆栈的保护字 。

    cgroup_init_early();    //1.cgroup: 它的全称为control group.即一组进程的行为控制.   2.该函数主要是做数据结构和其中链表的初始化

    local_irq_disable();        //关闭系统总中断(底层调用汇编指令)
    early_boot_irqs_disabled = true;

/*
 * Interrupts are still disabled. Do necessary setups, then
 * enable them
 */
    boot_cpu_init();    //激活当前CPU(在内核全局变量中将当前CPU的状态设为激活状态)
    page_address_init();    //高端内存相关,未定义高端内存的话为空函数
    pr_notice("%s", linux_banner);
    setup_arch(&command_line);    //完成内存映像的初始化,其中command_line是从bootloader中传下来的
    mm_init_owner(&init_mm, &init_task);
    mm_init_cpumask(&init_mm);    //初始化CPU屏蔽字
    setup_command_line(command_line);
    setup_nr_cpu_ids();
    setup_per_cpu_areas();
    smp_prepare_boot_cpu();    /* arch-specific boot-cpu hooks */

    build_all_zonelists(NULL, NULL);    //建立系统内存页区(zone)链表  
    page_alloc_init();    //内存页初始化

    pr_notice("Kernel command line: %s\n", boot_command_line);
    parse_early_param();    //  解析早期格式的内核参数
    /*函数对Linux启动命令行参数进行在分析和处理,
    当不能够识别前面的命令时,所调用的函数。*/  
    parse_args("Booting kernel", static_command_line, __start___param,
           __stop___param - __start___param,
           -1, -1, &unknown_bootoption);

    jump_label_init();

    /*
     * These use large bootmem allocations and must precede
     * kmem_cache_init()
     */
    setup_log_buf(0);
    /*初始化hash表,以便于从进程的PID获得对应的进程描述指针,按照开发办上的物理内存初始化pid hash表
    */
    pidhash_init();
    vfs_caches_init_early();    //建立节点哈希表和数据缓冲哈希表
    sort_main_extable();    //对异常处理函数进行排序  
    trap_init();    //初始化硬件中断
    mm_init();    // 建立了内核的内存分配器  

    /*
     * Set up the scheduler prior starting any interrupts (such as the
     * timer interrupt). Full topology setup happens at smp_init()
     * time - but meanwhile we still have a functioning scheduler.
     */
    sched_init();    //初始化调度
    /*
     * Disable preemption - early bootup scheduling is extremely
     * fragile until we cpu_idle() for the first time.
     */
    preempt_disable();    //禁止调度
     /*先检查中断是否已经打开,若打开,输出信息后则关闭中断。 */
    if (WARN(!irqs_disabled(), "Interrupts were enabled *very* early, fixing it\n"))
        local_irq_disable();
    idr_init_cache();    //创建缓冲区
    rcu_init();    //互斥访问机制
    tick_nohz_init();
    context_tracking_init();
    radix_tree_init();
    /* init some links before init_ISA_irqs() */
    early_irq_init();
    init_IRQ();    //中断向量初始化
    tick_init();
    init_timers();    //定时器初始化
    hrtimers_init();    //高精度时钟初始化
    softirq_init();    //软中断初始化
    timekeeping_init();    //   初始化资源和普通计时器
    time_init();
    sched_clock_postinit();
    perf_event_init();
    profile_init();    //   对内核的一个性能测试工具profile进行初始化.
    call_function_init();
    WARN(!irqs_disabled(), "Interrupts were enabled early\n");
    early_boot_irqs_disabled = false;
    local_irq_enable();        //使能中断

    kmem_cache_init_late();    //kmem_cache_init_late的目的就在于完善slab分配器的缓存机制.

    /*
     * HACK ALERT! This is early. We're enabling the console before
     * we've done PCI setups etc, and console_init() must be aware of
     * this. But we do want output early, in case something goes wrong.
     */
    console_init();    //初始化控制台以显示printk的内容  
    if (panic_later)
        panic("Too many boot %s vars at `%s'", panic_later,
              panic_param);

    lockdep_info();    //   如果定义了CONFIG_LOCKDEP宏,那么就打印锁依赖信息,否则什么也不做  

    /*
     * Need to run this when irqs are enabled, because it wants
     * to self-test [hard/soft]-irqs on/off lock inversion bugs
     * too:
     */
    locking_selftest();
 根据课上老师要求对这一段源代码注释,有兴趣的童鞋可参考http://blog.csdn.net/qing_ping/article/details/17351017,讲得特别详细!!
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值