Chapter 2: Process Management and Scheduling
/* 5 */ 335, 272, 215, 172, 137,
/* 10 */ 110, 87, 70, 56, 45,
/* 15 */ 36, 29, 23, 18, 15,
};
The array contains one entry for each nice level in the range [0, 39] as used by the kernel. The multiplier
between the entries is 1.25. To see why this is required, consider the following example. Two processes
AandBrun at nice level 0, so each one gets the same share of the CPU, namely, 50 percent. The weight
for a nice 0 task is 1,024 as can be deduced from the table. The share for each task is 10241024 + 1024 = 0 .5, that
is, 50 percent as expected.
If taskBis re-niced by one priority level, it is supposed to get 10 percent less CPU share. In other words,
this means thatAwill get 55 percent and B will get 45 percent of the total CPU time. Increasing the
priority by 1 leads to a decrease of its weight, which is then 1, 024/ 1. 25 ≈820. The CPU shareAwill
get now is therefore 10241024 + 820 ≈ 0 .55, whereasBwill have 1024820 + 820 ≈ 0 .45 — a 10 percent difference as
required.
0
20000
40000
60000
80000
100000
120000
140000
160000
180000
80 90 100 110 120 130 140
Weight
Priority
Regular task
Realtime task
0
200
400
600
800
1000
1200
120 125 130 135 140
10
100
1000
10000
100000
80 90100110120130140
Figure 2-15: Relation between static priority and load for regular and real-time processes.
The code that performs the conversion also needs to account for real-time tasks. These will get double
of the weight of a normal task.SCHED_IDLEtasks, on the other hand, will always receive a very small
weight:
kernel/sched.c
#define WEIGHT_IDLEPRIO 2
#define WMULT_IDLEPRIO (1 << 31)