NetEase Cloud Classroom Linux kernel analysis second week
20135103 Allan H.N. Wang
"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
The core function of the operating system is: process scheduling and interrupt mechanism, through the cooperation with the hardware to achieve multi-tasking, coupled with the support of the upper application software, and eventually become a computer system that can make it easy for users to operate,
The My_timer_handler function is called by the kernel periodically, 1000 times per call, to change the value of the global variable my_need_sched to 1, notifying the executing process that the scheduler My_schedule is executing. In the My_schedule function, complete the switchover of the process. There are two situations in which a process can be switched, in which case the next process is not passed, and the next process is passed over and the state of the next process is known. Process switching is still implemented through inline assembly code, which is nothing more than an EIP and stack that holds the old process, and the EIP and stack values of the new process are stored in the corresponding registers. The original mypcb.h defines the thread struct, which stores the IP and the fields in the SP,PCB structure of the thread being executed in the current process, meaning the following
PID: Process number
State: The status of the process, in the simulation system, all process control block information will be created, its initialization value is 1, if it is scheduled to run, its value will become 0
Stack: The stacks used by the process
Thread: currently executing threading information
Task_entry: Process Entry function
Next: Point to the next PCB, all the PCB in the simulation system is organized in the form of a chain list.
The main number of the core code
First, read the core code of the program
void __init My_start_kernel (void)
{
int i = 0;
while (1)
{
i++;
if (i%100000 = = 0)
PRINTK (kern_notice "My_start_kernel here%d", i);
}
}
This is the kernel code of the startup function, C language, the loop part is executed 100,000 times each, output a statement.
void My_timer_handler (void)
{
PRINTK (Kern_notice ">>>>>>>>6666>>>>>>>>>my_timer_handler here<<<<<<<<<<<<<<<<<< ");
}
This code is called when the time is interrupted and a statement is output each time it is called.
It then consolidates the code that was written and then consolidates it into the Linux Kernel-3.9.4.
Download Mykernel_for_linux3.9.4sc.patch, then download Linux kernel-3.9.4,make finally install QEMU, run kernel.
Linux Kernel Analysis second week