Linux-0.11 kernel source code analysis series: Process Scheduling sleep_on () function analysis, linux-0.11sleep_on

Source: Internet
Author: User

Linux-0.11 kernel source code analysis series: Process Scheduling sleep_on () function analysis, linux-0.11sleep_on

</pre><pre name="code" class="cpp">/*      *Author  : DavidLin      *Date    : 2014-12-10pm      *Email   : linpeng1577@163.com or linpeng1577@gmail.com      *world   : the city of SZ, in China      *Ver     : 000.000.001      *history :     editor      time            do      *          1)LinPeng       2014-12-10      created this file!      *          2)      */  

/* Author: linus */void sleep_on (struct task_struct ** p) {struct task_struct * tmp; if (! P) return; if (current ==& (init_task.task) // The init process cannot sleep panic ("task [0] trying to sleep"); tmp = * p; // tmp points to the previous current process * p = current; // execute the current process current-> state = TASK_UNINTERRUPTIBLE in the chain table header; // The sleep process cannot interrupt schedule (); // process scheduling. The following code continues to run if (tmp) after the process is awakened. // if the chain table next is not empty, tmp-> state = 0; // wake up the next process}

The sleep_on function can be found in the sched. c file. This is a small function. However,

It implies the following knowledge points, so it is more difficult to understand than the schedule () function:

1. Differences between user stack and kernel stack;

2. Where is the kernel stack stored and shared with the user stack?

3. How many processes are sleep_on for the same resource at the same time?

4. How to wake up after sleep?

5. Different processes use the same sleep code and different data.


A: The following is based on the 0.12 kernel. The 2.6 kernel will be different, but the basic concepts are the same.

1. the user stack is saved in the process data segment, and the kernel stack is saved on the physical page of the Process pcb;

Fork. in c, p-> tss. esp0 = PAGE_SIZE + (long) p; // The 2.6 kernel is stored on the physical page where thread_info is located p-> tss. ss0 = 0x10; // The process Kernel stack is stored in the kernel data segment
2. Do not share, for the above reasons;

3. tmp is equivalent to the next pointer of a single-chain table. The process waiting for the same resource is linked together, and the header pointer always points to the latest inserted process;

4. After waking up, it is executed after the schedule () function and awakened through the kernel;

6. Code segments can be the same and executed in different memories.

Related Article

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.