Linux kernel Analysis-complete a simple time slice rotation multi-channel program kernel code

Source: Internet
Author: User

---restore content starts---

20135125 Chen Zhiwei

Original works reproduced please indicate the source

"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000 "

Experimental requirements:

Mykernel Experimental Guidance (how the operating system works)

Run and analyze a streamlined operating system kernel to understand how the operating system works

Open the shell with a virtual machine in the lab building

    1. CD linuxkernel/linux-3.9.4
    2. Qemu-kernel Arch/x86/boot/bzimage

Then CD Mykernel you can see the contents of the Qemu window output code MYMAIN.C and myinterrupt.c

Use your own Linux system environment to build the process see Mykernel, which can also find a simple time slice rotation multi-channel program kernel code

Experimental process:

1. Open the shell using the virtual machine in the lab building and enter

    1. cd LinuxKernel/linux-3.9.4
    2. qemu -kernel arch/x86/boot/bzImage

2. Observe the program that the kernel is running:

3. View the files included in the Mykernel:

4. Run mymain.c and view the kernel boot code:

5. Run myinterrupt.c and look at the time interrupt function code:

Experimental Analysis:

This is the kernel code of the startup function, C language, the loop part is executed 100,000 times each, output a statement.

void __init My_start_kernel (void)
{
int i = 0;
while (1)
{
i++;
if (i%100000 = = 0)/* Here are 10,000 times per machine system operating speed can be self-adjusting */
PRINTK (kern_notice "My_start_kernel here%d \ n", i);

}
}

This code is called when the time is interrupted and a statement is output each time it is called.

void My_timer_handler (void)
{
PRINTK (kern_notice "\n>>>>>>>>>>>>>>>>>my_timer_handler here <<<<<<<<<<<<<<<<<<\n\n ");
}

Here we can see more simple than before, every time the output is called PRINTK, only need to interrupt when the interruption of processing can be

Then I added some of my own annotations to the code on GitHub, see:

Finally, here are some tips that I felt necessary to know in the class, see:

Experiment Inspiration:

In this experiment I learned about three very important registers, EBP, ESP, and EIP, and in class we can know that the thread we define is used to save the EIP and esp. For TPCB, I learned that he was used to represent the process, that is, to initialize the stack. Now I know a lot more about the process and principle of time interruption than before. The CPU generates a time interrupt every time it is over a point.

---restore content ends---

Linux kernel Analysis-complete a simple time slice rotation multi-channel program kernel code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.