Linux-0.11 Kernel Source Analysis series: Process scheduling sleep_on () function analysis

Source: Internet
Author: User

</pre><pre name= "code" class= "CPP" >/*      *author  : Davidlin      *date    : 2014-12-10pm      * Email   : [email protected] or [email protected]      *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))    //init process cannot sleep        panic ("task[0] trying to sleep");    TMP = *p;   TMP points to the previous process    *p  = current;    The list header executes the current process    current->state = task_uninterruptible;    Sleep process Non    -interruptible schedule ();    Process scheduling, the following code process is awakened before continuing if    (TMP)  //If the list next is not empty        tmp->state = 0;  Wake next Process}

The sleep_on function can be found in the Sched.c file, which is a small function, however,

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

1. The difference between the user stack and the kernel stack;

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

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

How do I wake up after 4.sleep?

5. Different processes use the same sleep code, while different data, this concept of understanding.


A: The following are based on the 0.12 kernel, 2.6 cores will be different, but the basic concept is consistent

1. The user stack is saved in the process data segment, and the kernel stack is stored on the physical page where the process PCB resides;

Fork.c in p->tss.esp0 = Page_size + (long) p;    The 2.6 kernel is saved on the physical page where Thread_info is located p->tss.ss0   = 0x10;    Process kernel stack saved in kernel data segment
2. Not shared, for reasons such as above;

The 3.tmp corresponds to the single-linked table next pointer, which links the process waiting for the same resource, and the head pointer always points to the newly inserted process;

4. After wake-up from the schedule () function after execution, wake through the kernel;

6. Code snippets can be identical and executed in different memory.

Linux-0.11 Kernel Source Analysis series: Process scheduling sleep_on () function analysis

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.