start_kernel是linux内核的入口函数,,定义在init/main.c里面。
start_kernel里面包含了一系列的初始化代码。
<span style="color:#666666;">asmlinkage void __init </span><strong style="color: rgb(102, 102, 102);">start_kernel</strong><span style="color:#666666;">(void){char * command_line;extern const struct kernel_param __start___param[], __stop___param[];smp_setup_processor_id(); //确定SMP系统中每个CPU的id/** Need to run as early as possible, to initialize the* lockdep hash:*/lockdep_init(); //初始化互斥锁的dependency。debug_objects_early_init(); //初始化debug kernel相关/** Set up the the initial canary ASAP:*/boot_init_stack_canary(); //stack_canary的是带防止栈溢出攻击保护的堆栈。cgroup_init_early();local_irq_disable(); //这个太直白了。early_boot_irqs_off(); //这个也很直白。/* * Interrupts are still disabled. Do necessary setups, then * enable them */tick_init(); //初始化time ticket,时钟boot_cpu_init(); //用以启动的CPU进行初始化。也就是初始化CPU0page_address_init();//初始化页面printk(KERN_NOTICE "%s", linux_banner);setup_arch(&command_line); //CPU架构相关的初始化mm_init_owner(&init_mm, &init_task); //初始化内存管理setup_command_line(command_line); //处理启动命令行setup_nr_cpu_ids();setup_per_cpu_areas();smp_prepare_boot_cpu();//准备boot_cpu. /* arch-specific boot-cpu hooks */build_all_zonelists(NULL); //建立什么样的zone??page_alloc_init(); //初始化page allocation相关结构printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);parse_early_param();parse_args("Booting kernel", static_command_line, __start___param,__stop___param – __start___param,&unknown_bootoption);//解析启动参数/** These use large bootmem allocations and must precede* kmem_cache_init()*/pidhash_init();//初始化process ID hash表vfs_caches_init_early(); //文件系统caches预初始化sort_main_extable(); //初始化exception tabletrap_init(); //初始化trap,用以处理错误执行代码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.*/</span><strong style="color: rgb(102, 102, 102);">sched_init();</strong><span style="color:#666666;"> //进程调度初始化/** Disable preemption – early bootup scheduling is extremely* fragile until we cpu_idle() for the first time.*/preempt_disable();if (!irqs_disabled()) {printk(KERN_WARNING "start_kernel(): bug: interrupts were ""enabled *very* early, fixing it\n");local_irq_disable();}rcu_init(); //Read_Copy_Update机制初始radix_tree_init();/* init some links before init_ISA_irqs() */early_irq_init();init_IRQ(); //初始化中断prio_tree_init(); //这是啥?以后要弄懂init_timers(); //初始化时钟hrtimers_init();//初始化高精时钟softirq_init();//初始化软中断timekeeping_init();//初始化时钟源time_init();//初始化时间例程profile_init(); //Profile?这是什么profile?if (!irqs_disabled())printk(KERN_CRIT "start_kernel(): bug: interrupts were ""enabled early\n");early_boot_irqs_on();local_irq_enable();/* Interrupts are enabled now so all GFP allocations are safe. */gfp_allowed_mask = __GFP_BITS_MASK;kmem_cache_init_late();//初始化CPU Cache/** 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(); //初始化consoleif (panic_later)panic(panic_later, panic_param);lockdep_info();/** 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(); //自测试锁#ifdef CONFIG_BLK_DEV_INITRDif (initrd_start && !initrd_below_start_ok &&page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) – ""disabling it.\n",page_to_pfn(virt_to_page((void *)initrd_start)),min_low_pfn);initrd_start = 0;}#endifpage_cgroup_init(); //页面初始enable_debug_pagealloc(); //页面分配debug启用kmemleak_init(); //memory leak 侦测初始化debug_objects_mem_init();idr_init_cache();setup_per_cpu_pageset(); //设置每个CPU的页面集合numa_policy_init();if (late_time_init)late_time_init();sched_clock_init();//初始化调度时钟calibrate_delay(); //协同不同CPU的时钟pidmap_init();//pid是process id还是processor id?anon_vma_init();//anonymous page?什么意思?#ifdef CONFIG_X86if (efi_enabled)efi_enter_virtual_mode();#endifthread_info_cache_init(); //初始化thread infocred_init(); //credentialfork_init(totalram_pages); //初始化forkproc_caches_init(); //初始化/proc的cache?buffer_init(); // bufferkey_init(); //keysecurity_init();//securitydbg_late_init();//debugvfs_caches_init(totalram_pages);//文件系统cache初始化signals_init();//signal/* rootfs populating might need page-writeback */page_writeback_init();page_writeback#ifdef CONFIG_PROC_FSproc_root_init();#endifcgroup_init();cpuset_init(); //cpusettaskstats_init_early(); //taskdelayacct_init();check_bugs();acpi_early_init();//acpi /* before LAPIC and SMP init */sfi_init_late(); //simple firmware interfaceftrace_init();/* Do the rest non-__init'ed, we're now alive */ </span><strong><span style="color:#ff0000;"> rest_init();</span></strong><span style="color:#666666;">}</span>
将这些函数归归类,以后就按照类型来读:
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();
用敬业的精神去面对每一份挑战,