The kernel Directory

Most of the critical kernel functions are implemented in this directory. The most important of the source files here is sched.c, which deserves special treatment.

sched.c

As the source itself states, this is ``the main kernel file.'' It consists of the scheduler and related operations, such as putting processes to sleep and waking them up, as well as management of the kernel timers (see Section 6.5 in Chapter 6), the interval timers (which are related to accounting and profiling), and the predefined task queues (see Section 6.4.2 in Chapter 6).

If you are interested in the real-time policies of the Linux scheduler, you’ll find the low-level information in the schedule function and its relatives. One such relative is goodness, which assigns preference values to processes, to help the scheduler choose the next process to run.

The functions (and system calls) related to scheduler control are also defined in this file. This includes the code for setting and retrieving scheduling policies and priorities. The nice system call is also found in this source file for every architecture except the Alpha.

In addition, the short system calls to get and set user and group ids are defined in sched.c (except on the Alpha), as well as the alarm call.[42]

Additional goodies found in sched.c include the show_tasks and show_state functions, which implement two of the ``magic'' keys described in "Section 4.4.2,” in Chapter 4.

Process Control

Most of the rest of the directory is in charge of processes. The fork and exit system calls are implemented in two source files named after the calls, and signal control is implemented in signal.c. Most of the signal-handling calls are implemented in a different way for the Alpha, to keep the Alpha port binary-compatible with Digital Unix.

The implementation of fork includes the code for the clone system call, and fork.c shows how the clone flags are used. It should be noted that sys_fork is not defined in fork.c, as the Sparc implementation is slightly different from other versions; most sys_fork implementations, however, just call do_fork, which is defined in fork.c. Providing a default implementation (usually called do_ fnct), while declaring the actual system call (sys_ fnct) within each port, is a technique often used in Linux, and it will probably be extended to other system calls as new ports are made available.

exit.c implements sys_exit and the various wait functions, as well as the actual sending of signals. (signal.c is devoted to signal handling, not to sending.)

Modularization

The files module.c and ksyms.c contain the code that implements the mechanisms described in Chapter 2. module.c holds the system calls used by insmod and related programs, while ksyms.c declares the public symbols of the kernel that do not belong to a specific subsystem. Other public symbols are declared by the initialization function of specific kernel subsystems, using register_symtab. For example, fs/proc/procfs_syms.c declares the /proc interface for registering new files.

Other Operations

The remaining source files in the directory provide the software interface for some low-level operations. time.c reads and writes kernel time values from user programs, resource.c implements the request and free mechanisms for I/O ports, and dma.c does the same for DMA channels. softirq.c deals with bottom halves (see Section 9.4 in Chapter 9) and itimer.c defines the system calls to set and get interval timer values.

To see how kernel messaging works, you can look at printk.c, which shows the details of several concepts that were introduced in Chapter 4 (i.e., it contains the code for both printk and sys_syslog).

exec_domain.c includes code needed to achieve binary compatibility with other flavors of Unix and info.c defines sys_info. panic.c does what its name implies; it also supports automatic reboot of the system when a panic occurs. The reboot takes place after a delay that can be set in /proc/sys/kernel/panic. The delay is implemented with repeated calls to udelay(1000), because after a panic, the scheduler no longer runs, and udelay can be used for delays no longer than one millisecond (see the section "Section 6.3.1" in Chapter 6).

sys.c implements several system-configuration and permission-handling functions, such as uname, setsid, and similar calls. sysctl.c contains the implementation of the sysctl call and the entry points for registering and deregistering sysctl tables (lists of entry points for system control). This file also provides the ability to access /proc/sys files, according to the registered tables.



[42] This call is no longer used by current versions of libc, which implement the function by means of timers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.120.204