当前位置:网站首页>CPU process priority
CPU process priority
2022-06-24 13:23:00 【Chen Bucheng I】
One . brief introduction
The way process priorities work has not changed much since their invention , Whether it's just one cpu Era , Or multicore cpu Time , Are occupied by the control process cpu The length of time . That is, in the same scheduling cycle , Higher priority processes take longer , Low priority processes take up less time .
The most familiar priority setting method on the system is nice and renice command .
Two .NICE value
nice The value should be familiar Linux/UNIX People know the concept of , We all know that it is a reaction process “ priority ” State value , Its value range is 40-20 to 19-0, altogether 40 A level . The smaller the value , The said process ” priority ” The higher the , And the greater the value “ priority ” The lower the .
We can go through nice Command to execute a command to be executed nice Value settings , The method is :
in addition , Use renice Command can control a running process nice Value adjustment , We can also use, for example top、ps Wait for the command to view the process nice value , I won't say more about the specific method , You can refer to the relevant manpage.
What we need to pay attention to is , I'm using it here nice Worth the title , Not priority (priority) The idea that . Of course ,nice and renice Of man In the manual , It also says priority The concept , But I want to stress that , Please don't confuse these two concepts in the system , One is nice value , One is priority value , They are inextricably linked , But for the current Linux system , They are not the same concept .
Have you figured out PR Values and NI The difference in value ? without , Then we can first figure out what is nice value .
nice Although the value is not priority, But it does affect the priority of the process .
In English , If we describe a person nice, That generally means that this person is more popular . What kind of people have good luck ? Often humility 、 A polite person . such as , You and a nice Go to lunch with people , Ordered two identical meals , I served one first and then ,nice The one who usually says :“ You eat first, you eat first !”, This is good popularity , This man nice! But if the other one comes late , So this nice People are going to be hungry . What does this ? The more nice The worse the ability of people to seize resources , And the less nice The stronger the preemptive ability of people . This is it. nice The meaning of value size ,nice The lower the value , It means that the less the process is nice, preemption cpu The stronger the ability to , The higher the priority . In the original use O1 The scheduling of Linux On , We'll also put nice The value is called static priority , This is basically in line with nice Value characteristics , Namely nice When the value is set , Unless we use renice Change it , Otherwise it will remain unchanged . and priority The value of is in the previous kernel O1 The performance on the scheduler will change , So it's also called dynamic priority .
3、 ... and . priority
Simple understanding nice After the concept of value , Let's see what is priority value , Namely ps As seen in the order PRI Value or top As seen in the order PR value .nice Namely top Medium NI value
In kernel , The value range of process priority is 140 Priority ranges , The value range is from 0-139, The smaller the value , The higher the priority .nice It's worth it 40-20 To 19-0, The priority range mapped to the actual is 100-139.
Under normal circumstances , The priority of any process is this value , Even if we pass nice and renice The command adjusts the priority of the process , Its value range will not exceed 100-139 The scope of the , Unless the process is a real-time process , Then its priority value will become 0-99 One of this range . There's a message here , That is, the current Linux Is an operating system that already supports real-time processes .
Simply speaking , The real-time operating system needs to ensure that the relevant real-time processes respond in a short time , There won't be a long delay , It also requires minimum interrupt delay and process switching delay . For such needs , General process scheduling algorithm , Whether it's O1 still CFS Are insatiable , So when the kernel is designed , The real-time process is mapped separately 100 Priority , These priorities are higher than those of normal processes (nice value ), This ensures that the real-time process has the highest distress record , Always ahead of the line to be dealt with .
The scheduling algorithms of real-time processes are also different , They use simpler scheduling algorithms to reduce scheduling overhead . in general ,Linux The processes running in the system can be divided into two categories :
Four . Real time process
Non real time processes The main difference between them is that they are distinguished by priority . All priority values are in 0-99 Within the scope of , It's all real-time processes , and 100-139 In scope are non real time processes . Can be used in the system chrt Order to see 、 Set the real-time priority state of a process . Let's take a look first chrt Use of commands :
Let's first focus on the Policy options part , You will find that the system provides for a variety of processes 5 Two scheduling strategies . But what is not stated here is , These five scheduling strategies are used for two processes respectively , The scheduling strategy that can be used for real-time processes is :SCHED_FIFO、SCHED_RR, For non real-time processes :SCHED_OTHER、SCHED_OTHER、SCHED_IDLE.
The overall priority strategy of the system is : If there are real-time processes to be executed in the system , Priority is given to the execution of real-time processes . Until the real-time process exits or voluntarily gives up CPU when , Will schedule the execution of non real-time processes . The priority range that real-time processes can specify is 1-99, The method of executing a program to be executed in real time is :
Just said ,SCHED_RR and SCHED_FIFO They are all real-time scheduling strategies , Can only be set for real-time processes . For all real-time processes , High priority ( Namely priority Small number ) The process must ensure that it executes before the process with low priority .SCHED_RR and SCHED_FIFO The scheduling strategy will only work when the priorities of two real-time processes are the same , The difference is as the name suggests :
SCHED_FIFO: Scheduling in a first in first out queue , With the same priority , Whoever executes first will be dispatched first , Unless it quits or actively releases CPU.
SCHED_RR: Multiple processes with the same priority are processed in the way of time slice rotation . The length of the time slice is 100ms.
边栏推荐
- Open source monitoring system Prometheus
- 脚本之美│VBS 入门交互实战
- Implement Domain Driven Design - use ABP framework - create entities
- Opengauss kernel: simple query execution
- 39 - read XML node and attribute values
- Perhaps the greatest romance of programmers is to commemorate their dead mother with a software
- 【数据挖掘】期末复习(样卷题目+少量知识点)
- 敏捷之道 | 敏捷开发真的过时了么?
- ERR AUTH< password> called without anypassword configured for the default user. Ar
- Concept + formula (excluding parameter estimation)
猜你喜欢
线程同步的基石AbstractQueuedSynchronizer详解
Getting started with the lvgl Library - colors and images
[database] final review (planning Edition)
【数据挖掘】期末复习(样卷题目+少量知识点)
CVPR 2022 | 美团技术团队精选论文解读
Brief introduction to cluster analysis
Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
一文讲透研发效能!您关心的问题都在
Use the open source tool k8tz to gracefully set the kubernetes pod time zone
CVPR 2022 | 美团技术团队精选论文解读
随机推荐
39 - read XML node and attribute values
Troubleshooting and optimization of files that cannot be globally searched by ordinary users in easydss video platform customization project
Why is open source technology so popular in the development of audio and video streaming media platform?
Opengauss kernel: simple query execution
The agile way? Is agile development really out of date?
8 lines of code to teach you how to build an intelligent robot platform
Main steps of system test
Common special characters in JS and TS
Experience of IOS interview strategy - App testing and launching
On the difference between process and thread
CVPR 2022 - Interpretation of selected papers of meituan technical team
ERR AUTH< password> called without anypassword configured for the default user. Ar
On the value foam of digital copyright works from the controversial nature of "Meng Hua Lu"
[database] final review (planning Edition)
Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
Attack Science: ARP attack
脚本之美│VBS 入门交互实战
I enlighten a friend and my personal understanding of the six patriarchs' Tan Jing
Use terminal to activate CONDA service in pypharm (the ultimate method is definitely OK)
CVPR 2022 | interprétation de certains documents de l'équipe technique de meituan