下面是调试的信息(限于篇幅,只分析几个调试片段):
2
3 [ 0.007812] Before calculate: 0
4
5 [ 0.007812] old_load = 0,this_rq->cpu_load[0] = 0, new_load = 0
6
7 [ 0.007812] old_load = 0,this_rq->cpu_load[1] = 0, new_load = 0
8
9 [ 0.007812] old_load = 0,this_rq->cpu_load[2] = 0, new_load = 0
10
11 [ 0.007812] old_load = 0,this_rq->cpu_load[3] = 0, new_load = 0
12
13 [ 0.007812] old_load = 0,this_rq->cpu_load[4] = 0, new_load = 0
14
15 ...
16
17 [ 0.015625] Before calculate: 7266
18
19 [ 0.015625] old_load = 0,this_rq->cpu_load[0] = 7266, new_load =
20
21 7266
22
23 [ 0.015625] old_load = 0,this_rq->cpu_load[1] = 3633, new_load =
24
25 7267
26
27 [ 0.015625] old_load = 0,this_rq->cpu_load[2] = 1817, new_load =
28
29 7269
30
31 [ 0.015625] old_load = 0,this_rq->cpu_load[3] = 909, new_load =
32
33 7273
34
35 [ 0.015625] old_load = 0,this_rq->cpu_load[4] = 455, new_load =
36
37 7281
38
39 ...
40
41 [ 0.015625] GPIOs setup done
42
43 [ 0.023437] Before calculate: 177522
44
45 [ 0.023437] old_load = 7266,this_rq->cpu_load[0] = 177522, new_load
46
47 = 177522
48
49 [ 0.023437] old_load = 3633,this_rq->cpu_load[1] = 90578, new_load
50
51 = 177523
52
53 [ 0.023437] old_load = 1817,this_rq->cpu_load[2] = 45744, new_load
54
55 = 177525
56
57 [ 0.023437] old_load = 909,this_rq->cpu_load[3] = 22986, new_load =
58
59 177529
60
61 [ 0.023437] old_load = 455,this_rq->cpu_load[4] = 11522, new_load =
62
63 177537
64
65 ...
66
67 [ 0.046875] Before calculate: 355044
68
69 [ 0.046875] old_load = 0,this_rq->cpu_load[0] = 355044, new_load =
70
71 355044
72
73 [ 0.046875] old_load = 22644,this_rq->cpu_load[1] = 188844,
74
75 new_load = 355045
76
77 [ 0.046875] old_load = 25731,this_rq->cpu_load[2] = 108060,
78
79 new_load = 355047
80
81 [ 0.046875] old_load = 17598,this_rq->cpu_load[3] = 59779, new_load
82
83 = 355051
84
85 [ 0.046875] old_load = 10125,this_rq->cpu_load[4] = 31683, new_load
86
87 = 355059
88
89 ...
90
91 [ 0.078125] Before calculate: 0
92
93 [ 0.078125] old_load = 0,this_rq->cpu_load[0] = 0, new_load = 0
94
95 [ 0.078125] old_load = 23605,this_rq->cpu_load[1] = 11802, new_load
96
97 = 0
98
99 [ 0.078125] old_load = 45587,this_rq->cpu_load[2] = 34190, new_load
100
101 = 0
102
103 [ 0.078125] old_load = 40046,this_rq->cpu_load[3] = 35040, new_load
104
105 = 0
106
107 [ 0.078125] old_load = 26104,this_rq->cpu_load[4] = 24472, new_load
108
109 = 0
110
111 [ 0.078125] I think it only execute several times................
112
113 ...
114
115 [ 0.101562] Before calculate: 0
116
117 [ 0.101562] old_load = 0,this_rq->cpu_load[0] = 0, new_load = 0
118
119 [ 0.101562] old_load = 2950,this_rq->cpu_load[1] = 1475, new_load =
120
121 0
122
123 [ 0.101562] old_load = 19231,this_rq->cpu_load[2] = 14423, new_load
124
125 = 0
126
127 [ 0.101562] old_load = 26827,this_rq->cpu_load[3] = 23473, new_load
128
129 = 0
130
131 [ 0.101562] old_load = 21508,this_rq->cpu_load[4] = 20163, new_load
132
133 = 0
134
135 [ 0.132812] Before calculate: 0
136
137 [ 0.132812] old_load = 0,this_rq->cpu_load[0] = 0, new_load = 0
138
139 [ 0.132812] old_load = 184,this_rq->cpu_load[1] = 92, new_load = 0
140
141 [ 0.132812] old_load = 6084,this_rq->cpu_load[2] = 4563, new_load =
142
143 0
144
145 [ 0.132812] old_load = 15723,this_rq->cpu_load[3] = 13757, new_load
146
147 = 0
148
149 [ 0.132812] old_load = 16612,this_rq->cpu_load[4] = 15573, new_load
150
151 = 0
152
153 [ 0.140625] Before calculate: 0
154
155 [ 0.140625] old_load = 0,this_rq->cpu_load[0] = 0, new_load = 0
156
157 [ 0.140625] old_load = 92,this_rq->cpu_load[1] = 46, new_load = 0
158
159 [ 0.140625] old_load = 4563,this_rq->cpu_load[2] = 3422, new_load =
160
161 0
162
163 [ 0.140625] old_load = 13757,this_rq->cpu_load[3] = 12037, new_load
164
165 = 0
166
167 [ 0.140625] old_load = 15573,this_rq->cpu_load[4] = 14599, new_load
168
169 = 0
170
171 [ 0.156250] TCP reno registered
172
173 ........
174
175 [ 79.617187] Before calculate: 360213
176
177 [ 79.617187] old_load = 360213,this_rq->cpu_load[0] = 360213, new_load = 360213
178
179 [ 79.617187] old_load = 360213,this_rq->cpu_load[1] = 360213, new_load = 360213
180
181 [ 79.617187] old_load = 360213,this_rq->cpu_load[2] = 360213, new_load = 360213
182
183 [ 79.617187] old_load = 360213,this_rq->cpu_load[3] = 360213, new_load = 360213
184
185 [ 79.617187] old_load = 360213,this_rq->cpu_load[4] = 360213, new_load = 360213
186
187 [ 79.656250] Before calculate: 360213
188
189 .......
190
为了大家看得方便,我把无关的启动信息用...代替了。
大家只需要看我添加的打印信息即可。
可以明显看到,运行队列的负载在变化 。
this_rq->load.weight的变化规律:
初始化0 -->突然变得很大 -->0---->最终的平衡值(如果没有新的task 加入)
大家可以分析四种特殊情况:
1) 刚启动,运行队列负载为0 -->都是0
2) 一些进程加入,运行队列负载突增 -->按照公式,分导递增
3) 运行队列负载又变成0 -->按照公式,分导递减
4) 运行队列负载逐渐趋于平衡 → 所有层的负载与运行队列负载相同
通过后面的调试发现,cpu_load[]数组的值,总是在尽量地接近运行队列的load值,,随着scale增大,接进得越慢。。。cpu_load[0]总是与运行队列的load值相同。
后面的文章里,我将会总体上分析不同cpu之间调度平衡的原理及代码执行实例.
参考资料:
[PATCH -cfs] Fix cpu_load calculation error
(http://lists.zerezo.com/linux-kernel/msg12735442.html)
CFS-devel, group scheduler, fixes
(http://lists.zerezo.com/linux-kernel/msg13412736.html)
Re: [PATCH] sched: Improve readability in update_cpu_load() code
(http://lkml.indiana.edu/hypermail/linux/kernel/0805.1/3068.html)