Chapter 2 Linux kernel exploration Toolkit. Common Data Types in the kernel (linked list, tree, search), Assembly example, inline assembly, kernel exploration tools (objdump/readelf, hexdump, nm, objcopy, AR), printk, dmesg, var/log/messages, _ init, likely ()/unlikely ().
Chapter 3 process: basic model of Program Execution. Program, process descriptor, Process Creation (Fork ()/vfolk ()/clone ()/do_fork (), process termination (sys_exit ()/do_exit () /sys_wait4 (), the basic architecture of the scheduler, wait queue, and interrupt exceptions.
Chapter 4 Memory Management. The page, page, and memory management area (three: zone_dma/zone_normal/zone_highmem, the reason is to simplify the code unrelated to the architecture, reserve it for unification, and some bus addressing ranges are limited), slab distributor and its lifecycle (solving the problem of external fragmentation, distributed to the partner system for management), Linux Process Memory Structure (process address space is divided into different memory areas for protection, such as read-only and executable, the process address space and all information related to it are stored in the mm_struct descriptor, which appears in the task_strcut, and a memory area is represented by the vm_area_struct descriptor) process image distribution, linear address space, page table, and page missing.
Chapter 5 I/O. Bus/bridge/interface, device (Block device Request queue and IO scheduling, character, network, clock, terminal device, DMA)
Chapter 6 file systems. VFS and its related data structures (fs_struct structure, files_struct structure), page cache (address_space structure, buffer_head structure), VFS System Call and file system layer.
Chapter 7 process scheduling and kernel Synchronization. Linux scheduler, kernel preemption, spin lock, and semaphore.
Chapter 8 kernel boot. Memory initialization, original ramdisk, and start_kernel () function analysis related to the architecture.
Chapter 9 build the Linux kernel. Describes the structures of compilation programs, cross-compilation, linking programs, and ELF binary target files (non-executable (Multiple sections and one node header table), executable (multiple segments, one program header table )).
Chapter 10 Add code to the kernel. The usage and difference between a work queue and a tasklet are discussed.
In order to allow the interrupt to run quickly, it is divided into the upper half (the interrupt handler, which is executed immediately because it is executed when all the interruptions are prohibited) and the lower half (the push post-processing program, which corresponds to the interrupt) there are three different lower half implementation mechanisms: Soft Interrupt, tasklet, and work queue.
Soft Interrupt: The Soft Interrupt is statically allocated during compilation. It can run on multiple CPUs concurrently Without preempting another Soft Interrupt, multiple CPUs use spin lock protection at the same time). Currently, only two subsystems use Soft Interrupt: Network and SCSI. execution time: When the hardware interrupt code is returned and others.
Tasklet: It is implemented by two types of soft interruptions (hi_softirq, tasklet_softirq) and dynamically increases or decreases. The same type of tasklet cannot be executed concurrently, and different types can be executed concurrently, which can save costs when the lower half is short. Run only in the interrupt context.
Working queue: It is executed by the kernel thread, that is, it is always executed in the process context, which can be sleep and blocked.
The upper half of the interrupt processing function registered by request_irq () only performs the most basic management work. The remaining part is inserted into the work queue as a task, waiting for processing.
Processing in the upper half: time sensitive, hardware-related, and not interrupted by other operations. Other operations can be placed in the lower half.
Soft Interrupt occurs with SMP. tasklet makes up for the trouble of its re-entry Programming Based on Soft Interrupt. The previous two run in the interrupt context could not sleep and blocked waiting, so a working Queue (in 2.4, a task queue) was born. It can be executed in a delayed manner and can be switched between different processes.
The core elements that constitute Soft Interrupt include: 1 Soft Interrupt Status Register (irq_stat) 2 Soft Interrupt vector table (softirq_vec) 3 Soft Interrupt daemon ). Soft Interrupt simulates the actual interrupt processing process. When a Soft Interrupt event occurs, set the corresponding interrupt mark, trigger the interrupt transaction, and wake up the daemon thread to detect the interrupt Status Register, call the Soft Interrupt service action () through the soft interrupt vector table (). The hardware interruption process is automatically completed by the hardware, which reflects the simulation of soft interruption. It can be seen that the execution context of Soft Interrupt service programs is Soft Interrupt daemon. In Linux, the Soft Interrupt daemon thread function is do_softirq (). Triggering a Soft Interrupt transaction is implemented through raise_softirq (). This function sets the Soft Interrupt status bit when the interrupt is closed, and then determines that daemon is directly awakened if the interrupt context is not involved.