Linux kernel development-process scheduling

Source: Internet
Author: User

This section provides a brief introduction to the relevant knowledge points for process scheduling in kernel development.

What is process scheduling

Process scheduling is the process of selecting the most appropriate process to execute in a process that is already ready.

Process scheduling Policy

Real-time class scheduling strategy

Scheduling strategies for non-real-time classes

Timing of process scheduling
    • Proactive preemption

The current process proactively discards execution permissions because of the need to wait for resources, and proactively switches to the next process execution.

Examples of active abandonment of CPUs:

current->state = task_interruptible;

Schedule ();

    • Passive preemption

The current process is forced to give up CPU execution permissions due to priority, process properties, and so on.

1) User preemption

When the system call is finished returning user space

When the user space is returned after the interrupt processing has completed

2) Kernel preemption

• In a system that does not support kernel preemption, the process/thread is not allowed to be preempted once it is running in kernel space, it must wait until the kernel thread finishes executing, the CPU is actively discarded, or the time slice is exhausted before the CPU is freed.

• In systems that support kernel preemption, high-priority processes/threads can preempt low-priority processes/threads that are running in kernel space.

• However, in the supported kernel preemption system, the following four scenarios are not allowed for kernel preemption:

  • The kernel is processing interrupts
  • The kernel is in the interrupt context
  • The kernel is executing the dispatch
  • When a process holds resources such as spin locks or readlock/writelock

· To ensure that the above four scenarios are not preempted, the preemptive kernel provides a variable (preempt_count) to record the above state. When the kernel enters the above four states, the Preempt_count variable will be added 1, and when exiting the above states Preempt_count the 1,preempt_count variable is placed in the THREAD_INFO structure.

Process scheduling steps

Clean up the current running process

Select the next program to run (Pick_next_task)

Set the run environment for a new process

Process Context Switch

Linux kernel development-process scheduling

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.