歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux內核 >> Linux內核start_kernel()函數

Linux內核start_kernel()函數

日期:2017/3/1 11:07:52   编辑:Linux內核
Linux內核start_kernel()函數
  1. asmlinkage void __init start_kernel(void)
  2. {
  3. char * command_line;
  4. extern struct kernel_param __start___param[], __stop___param[];
  5. smp_setup_processor_id();
  6. //空函數
  7. /*
  8. * Need to run as early as possible, to initialize the
  9. * lockdep hash:
  10. */
  11. lockdep_init();/*初始化一些數據*/
  12. debug_objects_early_init();
  13. cgroup_init_early();
  14. local_irq_disable(); /*關閉中斷*/
  15. early_boot_irqs_off();
  16. /*
  17. * 每一個中斷都有一個中斷描述符(struct irq_desc)來進行描述,這個函數的
  18. * 作用就是設置所有中斷描述符的鎖
  19. */
  20. early_init_irq_lock_class();
  21. /*
  22. * Interrupts are still disabled. Do necessary setups, then
  23. * enable them
  24. */
  25. lock_kernel(); /*鎖上內核,Linux是支持搶占CPU,放棄啟動被中斷(針對多處理器)*/
  26. tick_init(); /*初始化時鐘*/
  27. boot_cpu_init();/*//這個實際上是在多CPU環境下選擇CPU,這裡直接CPUID選擇的是0號cpu*/
  28. page_address_init(); /* 初始化頁地址,使用鏈表將其鏈接起來 */
  29. printk(KERN_NOTICE);
  30. printk(linux_banner); /*打印Linux版本*/
  31. setup_arch(&command_line); /* 這是一個重量級的函數了,會比較仔細地分析一下,主要完成了4個方面的工作,一個就是取得MACHINE和PROCESSOR的信息然或將他們賦值給kernel相應的全局變量,然後呢是對boot_command_line和tags接行解析,再然後呢就是memory、cach的初始化,最後是為kernel的後續運行請求資源。 */
  32. /*初始化內存*/
  33. mm_init_owner(&init_mm, &init_task);
  34. setup_command_line(command_line); /*保存命令行參數*/
  35. setup_per_cpu_areas();/* 為每個cpu申請內存空間 */
  36. setup_nr_cpu_ids();
  37. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks//設置啟動的CPU為在線狀態.在多CPU架構下 */
  38. /*
  39. * Set up the scheduler prior starting any interrupts (such as the
  40. * timer interrupt). Full topology setup happens at smp_init()
  41. * time - but meanwhile we still have a functioning scheduler.
  42. */
  43. sched_init();/*初始化進程調度器*/
  44. /*
  45. * Disable preemption - early bootup scheduling is extremely
  46. * fragile until we cpu_idle() for the first time.
  47. */
  48. preempt_disable(); /*禁止系統調用,即禁止搶占*/
  49. build_all_zonelists(); /*建立內存區域鏈表*/
  50. page_alloc_init();/*內存頁初始化*/
  51. printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);/*打印Linux命令行啟動參數*/
  52. parse_early_param();/*解析參數*/
  53. parse_args("Booting kernel", static_command_line, __start___param,
  54. __stop___param - __start___param,
  55. &unknown_bootoption); //執行命令行解析,若參數不存在,則調用unknown_bootoption
  56. if (!irqs_disabled()) {
  57. printk(KERN_WARNING "start_kernel(): bug: interrupts were "
  58. "enabled *very* early, fixing it\n");
  59. local_irq_disable();
  60. }/*判斷中斷是否關閉,若打開則關閉中斷*/
  61. sort_main_extable(); /*對異常處理函數排序*/
  62. trap_init();/*空函數*/
  63. rcu_init();/*初始化互斥機制*/
  64. /* init some links before init_ISA_irqs() */
  65. early_irq_init();/*中斷向量的初始化*/
  66. init_IRQ();/*完成其余中斷向量的初始化*/
  67. pidhash_init();/*進程Hash table的初始化*/
  68. init_timers();/*初始化定時器*/
  69. hrtimers_init();/*高精度時鐘初始化*/
  70. softirq_init();/*軟中斷初始化*/
  71. timekeeping_init();/*共用時鐘的初始化*/
  72. time_init();/*初始化系統時鐘*/
  73. sched_clock_init();/*進程調度時鐘初始化*/
  74. profile_init(); /* 對內核的profile(一個內核性能調式工具)功能進行初始化 */
  75. if (!irqs_disabled())
  76. printk(KERN_CRIT "start_kernel(): bug: interrupts were "
  77. "enabled early\n");
  78. early_boot_irqs_on(); /*打開IRQ中斷*/
  79. local_irq_enable();
  80. /*
  81. * HACK ALERT! This is early. We're enabling the console before
  82. * we've done PCI setups etc, and console_init() must be aware of
  83. * this. But we do want output early, in case something goes wrong.
  84. */
  85. console_init();/*打印中斷的初始化*/
  86. if (panic_later)
  87. panic(panic_later, panic_param);
  88. lockdep_info();
  89. /*
  90. * Need to run this when irqs are enabled, because it wants
  91. * to self-test [hard/soft]-irqs on/off lock inversion bugs
  92. * too:
  93. */
  94. locking_selftest();
  95. #ifdef CONFIG_BLK_DEV_INITRD
  96. if (initrd_start && !initrd_below_start_ok &&
  97. page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
  98. printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
  99. "disabling it.\n",
  100. page_to_pfn(virt_to_page((void *)initrd_start)),
  101. min_low_pfn);
  102. initrd_start = 0;
  103. }
  104. #endif
  105. vmalloc_init(); /*內存池的初始化*/
  106. vfs_caches_init_early();/*虛擬文件系統的初始化*/
  107. cpuset_init_early();/*空函數*/
  108. page_cgroup_init();/**/
  109. mem_init();/*對全局的物理頁變量初始化,對沒有分配的頁面初始化*/
  110. enable_debug_pagealloc();
  111. cpu_hotplug_init();/*空函數*/
  112. kmem_cache_init();/*內核內存緩沖池的初始化*/
  113. debug_objects_mem_init();
  114. idr_init_cache();/*idr初始化緩沖*/
  115. setup_per_cpu_pageset();/*空函數*/
  116. numa_policy_init();/*空函數*/
  117. if (late_time_init)
  118. late_time_init();
  119. calibrate_delay(); /*校驗延時函數的精確度*/
  120. pidmap_init();/*進程號位圖初始化,一般用一個page來只是所有的進程PID占用情況*/
  121. pgtable_cache_init();/*空函數*/
  122. prio_tree_init();/*初始化優先級數組*/
  123. anon_vma_init();/*空函數*/
  124. #ifdef CONFIG_X86
  125. if (efi_enabled)
  126. efi_enter_virtual_mode();
  127. #endif
  128. thread_info_cache_init();/*空函數*/
  129. cred_init();
  130. fork_init(num_physpages);/*初始化fork()環境*/
  131. proc_caches_init();/*為proc文件系統創建高速緩存*/
  132. buffer_init();/*空函數*/
  133. key_init();/*沒有鍵盤為空,有鍵盤初始化一個高速緩存*/
  134. security_init();/*空函數*/
  135. vfs_caches_init(num_physpages); /*虛擬文件系統掛載*/
  136. radix_tree_init();/*radix樹的初始化,供頁面查找*/
  137. signals_init();/*初始化信號量*/
  138. /* rootfs populating might need page-writeback */
  139. page_writeback_init();/*CPU在內存中開辟高速緩存,CPU直接訪問高速緩存提以高速度。當cpu更新了高速緩存的數據後,需要定期將高速緩存的數據寫回到存儲介質中,比如磁盤和flash等。這個函數初始化寫回的周期*/
  140. #ifdef CONFIG_PROC_FS
  141. proc_root_init();/*如果配置了proc文件系統,則需初始化並加載proc文件系統。在根目錄的proc文件夾就是proc文件系統,這個文件系統是ram類型的,記錄系統的臨時數據,系統關機後不會寫回到flash中*/
  142. #endif
  143. cgroup_init();/*空函數*/
  144. cpuset_init();/*空函數*/
  145. taskstats_init_early();/*進程狀態初始化,實際上就是分配了一個存儲線程狀態的高速緩存*/
  146. delayacct_init();/*空函數*/
  147. check_bugs();/*測試CPU的缺陷,記錄檢測的缺陷,便於內核其他部分工作��需要*/
  148. acpi_early_init(); /* before LAPIC and SMP init */
  149. ftrace_init();
  150. /* Do the rest non-__init'ed, we're now alive */
  151. rest_init(); /* 創建init進程 */
  152. }
Copyright © Linux教程網 All Rights Reserved