[譯]5.1. System Initialization Overview 系統初始化簡介

來源:互聯網
上載者:User

目錄:http://www.cnblogs.com/WuCountry/archive/2008/11/15/1333960.html
 
[不提供插圖,讀者最好從網上下載源書]

5.1. System Initialization Overview 系統初始化簡介
It's important to know where and how the main network-related subsystems are initialized, including device drivers. However, because this book is concerned only with the networking aspect of such initializations, I will not cover device drivers in general, or generic kernel services (e.g., memory management). For an understanding of that background, I recommend that you read Linux Device Drivers and Understanding the Linux Kernel, both published by O'Reilly.
對於瞭解網路相關的子系統以及裝置驅動是在什麼時候,什麼地方進行初始化的是很重要的。然而,因為本書只涉及網路初始化的特性,我不會覆蓋到通用的裝置驅動,或者核心服務(例如記憶體管理)。為了理解這些背景知識,我推薦你去讀一讀另兩本書:Linux裝置驅動和深入理解Linux核心。

Figure 5-1 shows briefly where, and in what sequence, some of the kernel subsystems are initialized at boot time (see init/main.c).
圖5-1簡單的展示了核心在啟動時,在哪裡,以及以什麼順序初始化它的子系統:

When the kernel boots up, it executes start_kernel, which initializes a bunch of subsystems, as partially shown in Figure 5-1. Before start_kernel terminates, it invokes the init kernel thread, which takes care of the rest of the initializations. Most of the initialization activities related to this chapter happen to be inside do_basic_setup.
當核心啟動時,它從start_kernel開始執行,這個函數初始化一些子系統分支,就5-1所示的那樣。在start_kernel終止以前,它會調用init這個核心線程,這個線程來管理接下來的初始化工作。很多在do_basic_setup函數中的初始化工作都與本章相關。(譯註:在這個函數中添加一下列印,運行一下核心,你就會有很大的收穫。核心中的所有內建模組都是在這裡函數裡添加的,通過輸出順序你就可以知道核心是怎樣載入核心模組的了。)

Among the various initialization tasks, we are mainly interested in three:
在大量的初始化任務中,我們主要對以下三個感興趣:

Boot-time options:啟動選項

Two calls to parse_args, one direct and one indirect via parse_early_param, handle configuration parameters that a boot loader such as LILO or GRUB has passed to the kernel at boot time. We will see how this task is handled in the section "Boot-Time Kernel Options."
有兩次調用parse_args函數,一個是直接調用,另一個通過parse_early_param間接調用,這個函數用於處理核心的配置參數,這些參數由類似LILO或者GRUB這樣的啟動程序載入程式在啟動時來傳給核心。我們會在“Boot-Time Kernel Options”中看到這個任務是如何處理的。

Interrupts and timers 中斷和時鐘

Hardware and software interrupts are initialized with init_IRQ and softirq_init, respectively. Interrupts are covered in Chapter 9. In this chapter, we will see just how device drivers register a handler with an IRQ and how IRQ handlers are organized in memory. Timers are also initialized early in the boot process so that later tasks can use them.
硬體中斷和軟體中斷是通過init_IRQ和softirq_init分別來初始化的。中斷會在第9章中介紹,這一章,我們只涉及裝置驅動是如何註冊IRQ控制代碼的,以及IRQ控制代碼在記憶體中是如何管理的。計時器同樣是在啟動進程的早期初始化的,這樣後面的任務就可以使用它們。

Initialization routines 初始化常規常式(程式)

Kernel subsystems and built-in device drivers are initialized by do_initcalls. free_init_mem frees a piece of memory that holds unneeded code. This optimization is possible thanks to smart routine tagging. See Chapter 7 for more details.
核心子系統以及內建裝置驅動是通過do_initcalls來初始化的。在初始化完成以後,free_init_mem用於釋放那些不在使用的代碼所佔用的記憶體。這一最佳化應該感謝智能常式標記(譯註:smart routine tagging,不明日是什麼,就先這樣翻譯了)。第7章詳細說明。

run_init_process determines the first process run on the system, the parent of all other processes; it has a PID of 1 and never halts until the system is done. Normally the program run is init, part of the SysVinit package. However, the administrator can specify a different program through the init= boot time option. When no such option is provided, the kernel tries to execute the init command from a set of well-known locations, and panics if it cannot find any. The user can also provide boot-time options that will be passed to init (see the section "Boot-Time Kernel Options").

run_init_process 來決定第一個在系統上啟動並執行進程,這也是系統中所有其它進程的父進程;它的PID為1,而且在系統結束以前不會中止;(譯註:PID為0的進程就是前面講start_kernel,它以啟動了1號進程以後,就進入idle)。通常一些SysVinit程式包在init中運行。然而,管理員可以在啟動選項中通過“init=”來指定一些不同的程式來運行。當不提供這一選項時,系統會試著從幾個已知的地方執行init命令(譯註:這裡的幾個已知地方就是bin,sbin等一些用於存放應用程式的地方),如果找不到,系統就panics。(譯註:系統停止啟動,列印一句:"No init found.  Try passing init= option to kernel.";然後就只有重啟了,當然一般情況重啟也是會走到這裡,再panics一次,應該指定啟動程式,或者在已知的目錄下放init程式。)
使用者也通過提供啟動選項給init進程,參見“Boot-Time Kernel Options”這一節;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.