Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app04.tex V1 - 09/04/2008 6:12pm Page 1233

Appendix D: System Startup


The S390 kernel is among the most confident ones, as you can see in the following code:

include/asm-s390/bugs.h
static inline void check_bugs(void)
{
/* s390 has no bugs ... */
}

Idle andinitThread


The last two actions ofstart_kernelare as follows:


  1. rest_initstarts a new thread that, after performing a few more initialization operations as
    described the next step, ultimately calls the userspace initialization program/sbin/init.

  2. The first, and formerly only, kernel thread becomes the idle thread that is called when the
    system has nothing else to do.


rest_initis essentially implemented in just a few lines of code:

init/main.c
static void rest_init(void)
{
kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
kthreadd_task = find_task_by_pid(pid);
unlock_kernel();
...
schedule();
cpu_idle();
}

Once a new kernel thread namedinit(which will start the init task) and another thread named
kthreadd(which will be used by the kernel to start kernel daemons) have been started, the kernel
invokesunlock_kernelto unlock the big kernel lock and makes the existing thread the idle thread by
callingcpu_idle. Prior to this,schedulemust be called at least once to activate the other thread.

The idle thread uses as little system power as possible (this is very important in embedded systems) and
relinquishes the CPU to runnable processes as quickly as possible. In addition, it handles turning off the
periodic tick completely if the CPU is idle and the kernel is compiled with support for dynamic ticks as
discussed in Chapter 15.

Theinitthread, whose code flow diagram is shown in Figure D-3, is in parallel existence with the idle
thread andkthreadd.

First, the current task needs to be registered aschild_reaperfor the global PID namespace. The kernel
makes it very clear what its intentions are:

init/main.c
static int __init kernel_init(void * unused)
{
...
Free download pdf