Linux Kernel Learning Summary
Zhu Hengzhi + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000 "
Summarize:
such as fleeting, the semester is half.
The basics of the Linux kernel Analysis course have been learned, though only for half a semester, but have benefited me.
The first week: the work of the computer
Http://www.cnblogs.com/20135314ZHU/p/5222946.html
- A complex and simple computer: A computer can implement many seemingly complex functions, compute and process large amounts of data, but it implements these complex functions by constantly repeating a large number of established simple operations.
- Program: What we typically do is tell the computer what the steps are, what data is entered, and how the processed results are stored. Then, as faithfully as possible, the computer will take the instructions of each operation step out into the machine language and work together with hardware and software in the order of the program.
- Assembly Language: assembly language is actually a translation of machine languages. Now the compiler function optimization of the relatively powerful, learning assembly language is not a lot of real time, but it is our analysis of the problem of an angle. Being able to read the assembly statements is helpful in analyzing the process that the program actually executes, and the steps to debug the program.
Second week: Complete a simple time slice rotation multi-channel program kernel code:
Http://www.cnblogs.com/20135314ZHU/p/5245234.html
- The core function of the operating system is: process scheduling and interrupt mechanism, through the cooperation with the hardware to achieve multitasking, coupled with the support of the upper application software, and eventually become a computer system that can make it easy for users to operate.
- Linux is a multi-process operating system, so other processes must wait until the running process is idle for the CPU to run. When a running process waits for other system resources, the Linux kernel gains control of the CPU and allocates the CPU to other waiting processes, which is the process switch.
- The process switching mechanism includes switching of ESP, switching of stacks. The process descriptor can be found from ESP, and the switch of EBP in the stack determines which process the current variable space belongs to.
Third week: Trace analysis of the boot process of the Linux kernel
Http://www.cnblogs.com/20135314ZHU/p/5269030.html
- Kernel boot process:
rest_init() is a No. 0 process, the start_kernel kernel has been in the start of the existence, and then this process No. 0 created the 1th process kernel_init , followed by the creation of some other service class kernel threads such as Kthreadd. So the whole system starts up.
- Use QEMU to run on your own computer ....?
Week Four: Use the same system call using the Library function API and the embed assembly code in C code two ways
Http://www.cnblogs.com/20135314ZHU/p/5289206.html
1. System calls
- Even the simplest programs, such as input and output, need to invoke the service provided by the operating system, which is called by the system.
- System calls under Linux are implemented by means of interrupts (int 0x80).
2. Passing parameters
- When the int 80 instruction is executed, the function number of the system call is stored in the register eax, and the parameters passed to the system call must be placed in the Register Ebx,ecx,edx,esi,edi in order, and when the system call is complete, the return value can be obtained in the register EAX.
- Linux uses the C-language invocation pattern, which means that all parameters must be stacked in the opposite order, that is, the last parameter is first in the stack, and the first parameter is the last one in the stack.
Week five: Three layers of flap system call (bottom)/Add time and time-asm command to Menuos
Http://www.cnblogs.com/20135314ZHU/p/5318211.html
1. Save the scene
- When the system is called, we need save_all to hold the context of the system call.
- Similarly, the first step in interrupt processing should also be to save the interrupt program site.
- Objective: After the interrupt processing, can return to the original interrupted place, in the original operating environment continue to execute correctly.
2. Determine interrupt information
- In the system call, we need to pass the system call number through EAX, through the
sys_call_table query to the calling system call, and then jump to the appropriate program for processing.
- Similarly, the system needs to have an interrupt number when the interrupt is processed, to understand the type of interrupt and the device by retrieving the interrupt vector table.
3. Processing interrupts
- After jumping to the appropriate interrupt handler, the interrupt is processed.
4. Return
- The system is called at the end of the Restore_all to restore the site when the system calls, and Iret return to the user state.
- Similarly, after executing the interrupt handler, the kernel also executes a specific sequence of instructions, resumes the scene at the time of the outage, and brings the process back to the user state.
Week Six: Process creation
Http://www.cnblogs.com/20135314ZHU/p/5344752.html
Linux creates a new process by replicating the parent process, implements it by calling Do_ Fork, and dynamically assigns a task_ struct structure to each newly created process.
1. The beginning of the new process
-
In Copy_thread ():
p->thread.ip = (unsigned long) ret _from _fork;
-
The IP of the child process is set to the first address of the ret_ form fork, so the child process is executed from ret_ From_ fork.
2. Execution start-up is consistent with kernel stack assurance
-
Before setting the IP of the child process:
*childregs = *current_ pt_ regs();
-
The regs parameter of the parent process is assigned to the child process's kernel stack, and the *childregs type is Pt_regs, which holds the arguments to the stack in save all.
Seventh Week:
Http://www.cnblogs.com/20135314ZHU/p/5365530.html
Week Eighth: Process switching and general execution
Http://www.cnblogs.com/20135314ZHU/p/5386076.html
- The key operations in the process switching are: Switching the address space, switching the kernel stack, switching the kernel control process, and some of the necessary registers to save and restore. These actions are not for user code, and after the switchover is complete, there is no immediate execution in the user space of next. The Save and restore of the user context occurs when the kernel state and the user state switch between the interrupt and the exception mechanism.
- In terms of timing, kernel threads can call schedule () directly for process switching (active), or they can be dispatched (passively) during interrupt processing. The user-state process cannot implement the active scheduling, but can only be dispatched by a point in time after the kernel state, that is, scheduling during interrupt processing.
- Use of the kernel: 32-bit x86 system, each process has an address space of 4G, the user state 0-3g,3g above only the kernel state can be accessed. All processes above 3G are shared, and in the kernel code snippets, stack segments are the same, and return to the user state is different (taxi). Process into the kernel is the same, no process into the kernel to execute the No. No. 0 process. The kernel can be seen as a collection of various interrupt processing and kernel threads.
Linux Reading notes Chapter 1/2:
Http://www.cnblogs.com/20135314ZHU/p/5284870.html
Chapter III Reading notes:
Http://www.cnblogs.com/20135314ZHU/p/5339373.html
The fourth chapter process dispatching reading notes:
Http://www.cnblogs.com/20135314ZHU/p/5387887.html
In-depth understanding of the computer seventh chapter:
Http://www.cnblogs.com/20135314ZHU/p/5362979.html
Teachers sometimes funny way of teaching particularly attractive, especially the teacher's smile, especially cute.
Linux Kernel Learning Summary