Spy on kernel---process scheduling targets, nice value, static priority, dynamic priority, real-time priority

Source: Internet
Author: User

Http://blog.chinaunix.net/uid-24227137-id-3595610.html

Spy on kernel---process scheduling targets, nice value, static priority, dynamic priority, real-time priority

This series of articles written by Zhang Tonghao, reproduced please indicate the source: http://blog.csdn.net/muge0913/article/details/7562133

Email: [Email protected]

Target of process scheduling:

1, high efficiency: high efficiency means that more tasks should be done at the same time. The scheduler is executed frequently, so the scheduler needs to be as efficient as possible.

2, enhance the interactive performance (interactivity): Under the system equivalent load, but also to ensure that the system response time.

3, to ensure fairness and avoid hunger and thirst.

4, SMP scheduling: The scheduler must support the multi-processing system. The system must track which processes are running on which CPU. Make sure that one process cannot run more than 1 CPUs at the same time.

5, soft real-time scheduling (soft real-timescheduling): The system must effectively invoke the real-time process.

Linustorvalds in the CFS into 2.6.23 said: "I think any time the dispatcher is not perfect, the right is not either either, the choice is a balance." Before I change the scheduler I'm 100% sure I'll change it in the future. The scheduler is not as important as it is imagined, it is only part of the kernel. ”

Nice value of the process:

The nice value is a property of each process. It is not a process priority, but a number that can affect the priority.

The NI column shows the nice value of each process, and the PRI is the priority of the process.

Nice is an integer between -20~~19, which defaults to an intermediate value of 0.

The current kernel no longer stores nice values. Instead, the Static_prio (static priority). Nice value the user is visible, static priority is hidden in the kernel, nice and static priority can be transformed by a certain relationship process. So the nice value just affects the static priority. For normal processes, the dynamic priority is calculated based on the static priority level.

Priority level:

Normal processes are: static priority and dynamic priority. Real-time processes add real-time priority.

Note: The priority of a process is just an integer, which is the basis for the scheduler selection process to run.

1, static priority: The static priority: because it does not change over time, the kernel does not modify it, only through the system call nice to modify. Static precedence is represented by Static_prio in the process descriptor. Its relationship with nice

The relationship between Nice and Static_prio is as follows:

[CPP]View Plaincopyprint?
    1. static_prio= Max_rt_prio + nice + 20

Max_rt_prio value is 100

The kernel defines two macros to complete this conversion: Prio_to_nice (), Nice_to_prio ().

In the KERNEL/SCHED.C:

[CPP]View Plaincopyprint?
  1. /*
  2. * Convert User-nice values [-20 ... 0 ... 19]
  3. * to-static priority [Max_rt_prio. Max_prio-1],
  4. * and back.
  5. */
  6. #defineNICE_TO_PRIO (Nice) (Max_rt_prio + (Nice) + 20)
  7. #definePRIO_TO_NICE (Prio) ((prio)-max_rt_prio-20)

2. Dynamic Priority: The Scheduler rewards the IO small sizes process or punishes the CPU-consuming process by increasing or decreasing the value of the process's static priority. The adjusted priority is called the dynamic priority. In the process descriptor, it is indicated by Prio, which is usually referred to as the dynamic priority level. The value between 0~max_prio-1 (Max_prio is defined as 140), where 0~MAX_RT_PRIO-1 (Max_rt_prio defined as 100) belongs to the real-time process scope, and max_rt_prio~mx_prio-1 belongs to the non-real-time process. A higher value indicates a smaller process priority.

The priority of a normal process is calculated by a relationship between the static priority and the process interaction function. The actual operation of the task is obtained. The real-time priority and its real-time priority are linear and do not change with the process running.

3, real-time priority:

Real-time prioritization is only meaningful for real-time processes. In the process descriptor rt_priority. Value 0~max_rt_prio-1.

[CPP]View Plaincopyprint?
    1. Prio=max_rt_prio-1–rt_priority

Time slices:

Time slices are an important concept for various schedulers before the full Fair Scheduler CFS is incorporated into the kernel. It specifies the time at which the process can run before it is preempted. An important goal of the caller is to effectively allocate the time slices to provide a good user experience. Too long a time slice can cause the interactive process to respond poorly. The length of time slices can lead to the consumption of process switching. To solve this contradiction, the kernel uses:

1, improve the priority of the interaction process, while assigning the default time slice

2, do not need a process to run out of time slices, can be used multiple times.

High priority guarantees frequent calls to the interactive process, and long time slices ensure they can be executed for long periods of time

Spy on kernel---process scheduling targets, nice value, static priority, dynamic priority, real-time priority

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.