Linux Kernel development-process scheduling and Linux kernel Process Scheduling

Source: Internet
Author: User

Linux Kernel development-process scheduling and Linux kernel Process Scheduling

This section briefly introduces the knowledge about process scheduling in kernel development.

 

What is process scheduling?

Process Scheduling is to select the most appropriate process execution process from a ready process.

 

Process Scheduling Policy

Real-time Class Scheduling Policy

Non-real-time Class Scheduling Policy

Process Scheduling time
  • Proactive Preemption

The current process voluntarily waives the execution permission because it needs to wait for resources and other reasons, and requests to switch to the next process for execution.

 

Example of voluntarily giving up CPU:

Current-> state = TASK_INTERRUPTIBLE;

Schedule ();

  • Passive Preemption

The current process is forced to grant the CPU execution permission for reasons such as priority and process attributes.

1) User Preemption

When the system call is completed and the user space is returned

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

 

2) kernel preemption

· In a system that does not support kernel preemption, once a process/thread runs in the kernel space, it is not allowed to be preemptible, the CPU will be released only after the kernel thread execution is completed, the CPU is automatically abandoned, or the time slice is exhausted.

· In systems that support kernel preemption, high-priority processes/Threads can seize low-priority processes/threads running in the kernel space.

· However, kernel preemption is not allowed in the following four cases:

  • The kernel is processing the interrupt.
  • The kernel is in the interrupt context.
  • The kernel is executing scheduling.
  • When a process holds resources such as a spin lock, readlock, or writelock

· To ensure that the above four conditions are not preemptible, The preempt_count variable is provided in Linux to record the above States. When the kernel enters the preceding four states, the preempt_count variable will add 1. When the kernel exits from the preceding states, the preempt_count variable will be reduced by 1, and the preempt_count variable will be placed in the thread_info structure.

 

Process Scheduling steps

Clear processes currently running

Select the next program (pick_next_task)

Set the running environment of the new process

Process context switch


Error Message
Linux Kernel Process Scheduling

The Linux kernel executes the corresponding Interrupt Processing Program through hardware interruptions. the Linux kernel uses the interrupt program to analyze and process the task linked list. This naturally includes allocating CPU time slices to Linux systems, the interruption system is a core task. To a large extent, it can affect the entire kernel, because the interruption signal may occur at any time, no matter what the CPU is doing, it will certainly be processed (unless the interruption has not been initialized yet or the interruption is still blocked)

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.