linux 性能调节指南
性能调节指南Red Hat Enterprise Linux 7
A complete guide to Linux process scheduling
Linux Doc
CFS Scheduler
Code Go Through
RT linux source Code - sched_class identifier
Elements in the Task Structure
sched_class Struct Reference 3.7.1
#define SCHED_NORMAL 0 #define SCHED_FIFO 1 #define SCHED_RR 2 #define SCHED_BATCH 3 #define SCHED_IDLE 5
Processes under SCHED_NORMAL, SCHED_BATCH and SCHED_IDLE are mapped to fair_sched_class, provided by CFS. SCHED_RR and SCHED_FIFO associate with rt_sched_class, real-time scheduler. (A complete guide to Linux process scheduling)
awk '/policy/ {print $NF}' /proc/*/sched |sort | uniq
PID=2911 awk '/policy/ {print $NF}' /proc/$PID/sched
chrt -ap $PID
what is the use of .next field in sched_class structure?
Linux Scheduler
How to find scheduling policy and active processes' priority?
- TS is SCHED_OTHER
- RR is SCHED_RR
- FF is SCHED_FIFO
ps -e -o s,pid,cls,pri | grep ^R | awk -v sq="'" '{print "pid",$2,sq,"s current scheduling policy:",$3,"\npid",$2,sq,"s current priority:",$4}' ps -e -o s,pid | grep ^R | awk '{system("chrt -p " $2)}' ls /proc | grep -e ^[0-9] | awk '{system("chrt -p " $0)}'|more
How to change scheduling algorithm and priority used by a process?
PID=7861 tuna --threads $PID --priority=RR:40 # <<-- sets a policy of RR (round-robin) and a priority of 40 for PID 7861.
How to check the process scheduling policy other than `ps` output
PID=25 awk '/policy/ {print $NF}' /proc/$PID/sched
Linux Kernel Development
It will be added a new scheduling policy to the CISTER framework. The scheduling algorithm is the well known Last-In First-Out (LIFO). According to LIFO scheduling algorithm, the last task ready for execution execution will be selected to be executed. That is, whenever a task arrives (become ready for execution) the currently executing is preempted and the recently arrived task is selected for execution.
A set of steps is required to add a new scheduling policy. REF: http://www.cister.isep.ipp.pt/summer2017/w1/S3_Lab.pdf
Note that, almost all functions have as arguments pointers of struct task_struct and struct rq. The lf_sched_class scheduling policy it is positioned between the RT and CFS scheduling classes.
stop_sched_class
The stop_sched_class is to stop cpu, using on SMP system, for load balancing and cpu hotplug. This class have the highest scheduling priority.
The Linux Kernel Scheduler
linux-kernel-hacking
ch 04. Process Scheduling
process-scheduling-in-linux
Linux kernel scheduler