Presentation is loading. Please wait.

Presentation is loading. Please wait.

Getting Started with the Kernel

Similar presentations


Presentation on theme: "Getting Started with the Kernel"— Presentation transcript:

1 Getting Started with the Kernel
國立中正大學 資訊工程研究所 羅習五 老師

2 Obtaining the Kernel Source

3 The Kernel Source Tree Directory Description
arch Architecture-specific source crypto Crypto API Documentation Kernel source documentation drivers Device drivers fs The VFS and the individual file systems include Kernel headers init Kernel boot and initialization ipc Interprocess communication code kernel Core subsystems, such as the scheduler lib Helper routines mm Memory management subsystem and the VM net Networking subsystem scripts Scripts used to build the kernel security Linux Security Module sound Sound subsystem usr Early user-space code (called initramfs)

4 Lines of code

5 Different Natures The kernel does not have access to the C library.
The kernel is coded in GNU C. (not in ANSI C) The kernel lacks memory protection like user-space. The kernel cannot easily use floating point. The kernel has a small fixed-size stack. Because the kernel has asynchronous interrupts, is preemptive, and supports SMP, synchronization and concurrency are major concerns within the kernel. Portability is important.

6 Different Natures NO libc support
There are multiple reasons for this, including some chicken-and-the-egg situations, but the primary reason is speed and size (upcall?). Many of the usual libc functions have been implemented inside the kernel. For example <linux/string.h>

7 Different Natures Inline Assembly Branch Annotation
The asm() compiler directive is used to inline assembly code. Branch Annotation Small, Fixed-Size Stack Historically, the kernel stack is two pages. Recently, the size of kernel stack is one page only!!! if (unlikely(foo)) { /* ... */ } if (likely(foo)) { /* ... */ }

8 Different Natures No (Easy) Use of Floating Point
Supporting FPU is very expensive for kernel developers Using floating point inside the kernel requires manually saving and restoring the floating point registers It is very hard to use the technique called “lazy context switch” to speedup FPU context switching

9 Note: “DO” have some floating-point computations
Recompile GNU‘s libc with option “--without-fp” to avoid using floating-point hardware while providing floating-point computations Compile the module's .c files with gcc's "-msoft-float" option and "-D__NO_MATH_INLINES".

10 Different Natures Synchronization and Concurrency
“Linux” is a preemptive multi-tasking “operating system.” The Linux kernel supports multiprocessing. For example, Linux can use more than one core/processor to decode TCP/IP packets (named softirq) Interrupts occur asynchronously The “Linux kernel” is preemptive.


Download ppt "Getting Started with the Kernel"

Similar presentations


Ads by Google