Saturday, January 20, 2007

Linux Kernel - Intro

I see it important to give a bit of information regarding the Linux kernel , for whom don't know more than that Linux is power fulled cause of kernel without knowing anything more about it.

We can say that the __Kernel__ is the core of operating system;
it is the program that controls the basic services that are utilized by user programs.

The kernel is responsible for:
-CPU resource scheduling (regarding process management)
-Memory management (including protection implementation)
-Device control (providing the device-file/device-driver interface)
-Security (device, process and user level)
-Accounting services (including CPU usage and disk quotas)
-Inter Process Communication (shared memory, semaphores and message passing)

Kernel does the memory management for all of the running programs (processes) and that they all get a fair share of the processor’s cycles, also provide portable interface for programs to talk to hardware.

It is physically a file that is usually located in the /boot directory. Under Linux, this file is called vmlinuz.

Foo-bar:/home/mina# ls -l /boot/vm*
-rw-r--r-- 1 root root 1231478 Jan 24 2005 /boot/vmlinuz-2.6.8-2-686-smp

-The size of the kernel is Dependant on what features compiled into it, what modifications made to its data structures and what additions made to its code.

-vmlinuz is referred to as the kernel image. At a physical level, this file consists of a small section of machine code followed by a compressed block. At boot time, the program at the start of the kernel is loaded into memory at which point it uncompresses the rest of the kernel.

-/usr/src/linux is a soft link to /usr/src/ within this directory hierarchy are in excess of 1300 files and directories which consists of around 400 C source code files, 370 C header files, 40 Assembler source files and 46 Makefiles. These, when compiled, produce around 300 object files and libraries; large portion of this is driver code.

-Only drivers that are needed on the system are compiled into the kernel, the rest can be placed separately in things called modules.

-Kernel Boot steps:

1) The boot loader program (e.g. grub) starts by loading the vmlinuz from disk into memory, then starts the code executing.
2) After the kernel image is decompressed, the actual kernel is started. This part of the code was produced from assembler source.
Technically at this point the kernel is running. This is the first process (0) and is called swapper. Swapper does some low level checks on the processor, memory and FPU availability, then places the system into protected mode. Paging is enabled.
3) Interrupts are disabled though the interrupt table is set up for later use. The entire kernel is realigned in memory (post paging) and some of the basic memory management structures are created.
4) At this point, a function called start_kernel is called.
start_kernel is physically located in /usr/src/linux-2.x.x../init/main.c and is really the core kernel function.
5) start_kernel sets up the memory, interrupts and scheduling.
In effect, the kernel now has multi-tasking enabled.
The console already has several messages displayed to it.
6) The kernel command line options are parsed (those passed in by the boot loader) and all device driver modules are initialized.
7) Then memory initializations occur, socket/networking is started and bug checking.
8) The final action performed by swapper is the first process creation with fork whereby the init program is launched. Swapper now enters an infinite idle loop.

-The timer interrupts are now set so that the scheduler can step in and pre-empt the running process. However, sections of the kernel will be periodically executed by other processes.

Comment or give some detailed discussion if you do like.

No comments: