现在的位置: 首页 > 综合 > 正文

[译]5.1. System Initialization Overview 系统初始化简介

2011年02月18日 ⁄ 综合 ⁄ 共 3542字 ⁄ 字号 评论关闭

目录: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”这一节;

 

抱歉!评论已关闭.