Ask about task scheduling Initiation

Source: Internet
Author: User
For more information about how to initiate task scheduling-Linux general technology-Linux programming and kernel, see the following. This is a good place. I am new to linux, so I can't wait to know some problems. I hope Dr. Zhao understands.

First, I want to know under what circumstances will the job scheduling function sched () be called? I have seen uCOS before, and it is like this:

1. handling system clock interruptions

2. When creating a task

3. Any system functions that change the task status, such as semTake () and semGive ()

4. Interrupt return

I don't know how it works in linux?

Second, I heard that the scheduling mechanism in linux is non-preemptive. I also see that in your book, page 22nd mentions that "processes running in the kernel state cannot be preemptible by other processes ." So I am confused. Can a low-priority process not be deprived of by a high-priority process? In addition, you can see on page 79th that "when the clock interruption process determines that the time slice has been used up, the process will be switched in do_timer, the CPU usage of the process will be reluctantly deprived and used by other processes." I understand that other processes here should be high-priority and ready processes. The process with a higher priority will be deprived of the process with a lower priority when the time slice arrives.

In addition, when the interrupt processing is completed, it seems that a scheduling is also conducted. If a high-priority task is ready, will the interrupted low-priority task be denied if it is not.

As a result, I found that I am not clear about the concepts of preemptible scheduling and non-preemptible scheduling. Can you explain this question?


It is basically the same. When creating a task, instead of calling schedule (), you can only set the task to run. For more details, see the following:

1. determine when the time slice is used up in the system call;

2. Check whether the current process is not in the RUNNING status in the system call;

3. process call exit ();

4. The system calls waitpid () and the flag does not have the WNOHANG mark, or the sub-process is in the ZOMBIE state;

5. tty write operation, but the write queue is full;

6. Clock interruption;

7. Call sleep_on () voluntarily because you are waiting for resources ();

8. Wait for any signal and call pause ().

During kernel-state execution, it is not forcibly switched out by the clock interruption process, because there is a judgment Statement on whether to run in the core State during the clock interruption process. As for the process to be switched to after a process time slice is used up, this is completely set by the scheduler's algorithm. In the scheduling program of this kernel, schedule () compares the counter (time slice value) value of each ready task, which is large and the running time is not long, select the task to switch. If all time slices are 0 (or equal ?) Update the counter value of each task based on the priority value of each task, and then compare all tasks.

It can be seen that the switch destination in this kernel is based on the time slice value and then the priority value. Therefore, the next task to be executed is selected based on the priority value only when everyone is on the same starting line. There is no situation where a high-priority process denies the execution of a low-priority task.

Schedule () is also called at the end of the interrupt processing, so the process is exactly the same.

Ask about task scheduling Initiation

Thanks to Dr. Zhao for his explanation. I have always had a question. I feel that the access to global data in the kernel code is not safe. I am worried that the interruption will disrupt the system when it comes back. Now I know it is clear.
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.