• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifdef CONFIG_SMP
2 #include "sched-pelt.h"
3 
4 int __update_load_avg_blocked_se(u64 now, struct sched_entity *se);
5 int __update_load_avg_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se);
6 int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq);
7 int update_rt_rq_load_avg(u64 now, struct rq *rq, int running);
8 int update_dl_rq_load_avg(u64 now, struct rq *rq, int running);
9 
10 #ifdef CONFIG_SCHED_THERMAL_PRESSURE
11 int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity);
12 
thermal_load_avg(struct rq * rq)13 static inline u64 thermal_load_avg(struct rq *rq)
14 {
15 	return READ_ONCE(rq->avg_thermal.load_avg);
16 }
17 #else
18 static inline int
update_thermal_load_avg(u64 now,struct rq * rq,u64 capacity)19 update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
20 {
21 	return 0;
22 }
23 
thermal_load_avg(struct rq * rq)24 static inline u64 thermal_load_avg(struct rq *rq)
25 {
26 	return 0;
27 }
28 #endif
29 
30 #ifdef CONFIG_HAVE_SCHED_AVG_IRQ
31 int update_irq_load_avg(struct rq *rq, u64 running);
32 #else
33 static inline int
update_irq_load_avg(struct rq * rq,u64 running)34 update_irq_load_avg(struct rq *rq, u64 running)
35 {
36 	return 0;
37 }
38 #endif
39 
40 #define PELT_MIN_DIVIDER	(LOAD_AVG_MAX - 1024)
41 
get_pelt_divider(struct sched_avg * avg)42 static inline u32 get_pelt_divider(struct sched_avg *avg)
43 {
44 	return PELT_MIN_DIVIDER + avg->period_contrib;
45 }
46 
cfs_se_util_change(struct sched_avg * avg)47 static inline void cfs_se_util_change(struct sched_avg *avg)
48 {
49 	unsigned int enqueued;
50 
51 	if (!sched_feat(UTIL_EST))
52 		return;
53 
54 	/* Avoid store if the flag has been already reset */
55 	enqueued = avg->util_est.enqueued;
56 	if (!(enqueued & UTIL_AVG_UNCHANGED))
57 		return;
58 
59 	/* Reset flag to report util_avg has been updated */
60 	enqueued &= ~UTIL_AVG_UNCHANGED;
61 	WRITE_ONCE(avg->util_est.enqueued, enqueued);
62 }
63 
rq_clock_task_mult(struct rq * rq)64 static inline u64 rq_clock_task_mult(struct rq *rq)
65 {
66 	lockdep_assert_rq_held(rq);
67 	assert_clock_updated(rq);
68 
69 	return rq->clock_task_mult;
70 }
71 
rq_clock_pelt(struct rq * rq)72 static inline u64 rq_clock_pelt(struct rq *rq)
73 {
74 	lockdep_assert_rq_held(rq);
75 	assert_clock_updated(rq);
76 
77 	return rq->clock_pelt - rq->lost_idle_time;
78 }
79 
80 /* The rq is idle, we can sync to clock_task */
_update_idle_rq_clock_pelt(struct rq * rq)81 static inline void _update_idle_rq_clock_pelt(struct rq *rq)
82 {
83 	rq->clock_pelt = rq_clock_task_mult(rq);
84 
85 	u64_u32_store(rq->clock_idle, rq_clock(rq));
86 	/* Paired with smp_rmb in migrate_se_pelt_lag() */
87 	smp_wmb();
88 	u64_u32_store(rq->clock_pelt_idle, rq_clock_pelt(rq));
89 }
90 
91 /*
92  * The clock_pelt scales the time to reflect the effective amount of
93  * computation done during the running delta time but then sync back to
94  * clock_task when rq is idle.
95  *
96  *
97  * absolute time   | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16
98  * @ max capacity  ------******---------------******---------------
99  * @ half capacity ------************---------************---------
100  * clock pelt      | 1| 2|    3|    4| 7| 8| 9|   10|   11|14|15|16
101  *
102  */
update_rq_clock_pelt(struct rq * rq,s64 delta)103 static inline void update_rq_clock_pelt(struct rq *rq, s64 delta)
104 {
105 	if (unlikely(is_idle_task(rq->curr))) {
106 		_update_idle_rq_clock_pelt(rq);
107 		return;
108 	}
109 
110 	/*
111 	 * When a rq runs at a lower compute capacity, it will need
112 	 * more time to do the same amount of work than at max
113 	 * capacity. In order to be invariant, we scale the delta to
114 	 * reflect how much work has been really done.
115 	 * Running longer results in stealing idle time that will
116 	 * disturb the load signal compared to max capacity. This
117 	 * stolen idle time will be automatically reflected when the
118 	 * rq will be idle and the clock will be synced with
119 	 * rq_clock_task.
120 	 */
121 
122 	/*
123 	 * Scale the elapsed time to reflect the real amount of
124 	 * computation
125 	 */
126 	delta = cap_scale(delta, arch_scale_cpu_capacity(cpu_of(rq)));
127 	delta = cap_scale(delta, arch_scale_freq_capacity(cpu_of(rq)));
128 
129 	rq->clock_pelt += delta;
130 }
131 
132 extern unsigned int sched_pelt_lshift;
133 
134 /*
135  * absolute time   |1      |2      |3      |4      |5      |6      |
136  * @ mult = 1      --------****************--------****************-
137  * @ mult = 2      --------********----------------********---------
138  * @ mult = 4      --------****--------------------****-------------
139  * clock task mult
140  * @ mult = 2      |   |   |2  |3  |   |   |   |   |5  |6  |   |   |
141  * @ mult = 4      | | | | |2|3| | | | | | | | | | |5|6| | | | | | |
142  *
143  */
update_rq_clock_task_mult(struct rq * rq,s64 delta)144 static inline void update_rq_clock_task_mult(struct rq *rq, s64 delta)
145 {
146 	delta <<= READ_ONCE(sched_pelt_lshift);
147 
148 	rq->clock_task_mult += delta;
149 
150 	update_rq_clock_pelt(rq, delta);
151 }
152 
153 /*
154  * When rq becomes idle, we have to check if it has lost idle time
155  * because it was fully busy. A rq is fully used when the /Sum util_sum
156  * is greater or equal to:
157  * (LOAD_AVG_MAX - 1024 + rq->cfs.avg.period_contrib) << SCHED_CAPACITY_SHIFT;
158  * For optimization and computing rounding purpose, we don't take into account
159  * the position in the current window (period_contrib) and we use the higher
160  * bound of util_sum to decide.
161  */
update_idle_rq_clock_pelt(struct rq * rq)162 static inline void update_idle_rq_clock_pelt(struct rq *rq)
163 {
164 	u32 divider = ((LOAD_AVG_MAX - 1024) << SCHED_CAPACITY_SHIFT) - LOAD_AVG_MAX;
165 	u32 util_sum = rq->cfs.avg.util_sum;
166 	util_sum += rq->avg_rt.util_sum;
167 	util_sum += rq->avg_dl.util_sum;
168 
169 	/*
170 	 * Reflecting stolen time makes sense only if the idle
171 	 * phase would be present at max capacity. As soon as the
172 	 * utilization of a rq has reached the maximum value, it is
173 	 * considered as an always running rq without idle time to
174 	 * steal. This potential idle time is considered as lost in
175 	 * this case. We keep track of this lost idle time compare to
176 	 * rq's clock_task.
177 	 */
178 	if (util_sum >= divider)
179 		rq->lost_idle_time += rq_clock_task_mult(rq) - rq->clock_pelt;
180 
181 	_update_idle_rq_clock_pelt(rq);
182 }
183 
184 #ifdef CONFIG_CFS_BANDWIDTH
update_idle_cfs_rq_clock_pelt(struct cfs_rq * cfs_rq)185 static inline void update_idle_cfs_rq_clock_pelt(struct cfs_rq *cfs_rq)
186 {
187 	u64 throttled;
188 
189 	if (unlikely(cfs_rq->throttle_count))
190 		throttled = U64_MAX;
191 	else
192 		throttled = cfs_rq->throttled_clock_pelt_time;
193 
194 	u64_u32_store(cfs_rq->throttled_pelt_idle, throttled);
195 }
196 
197 /* rq->task_clock normalized against any time this cfs_rq has spent throttled */
cfs_rq_clock_pelt(struct cfs_rq * cfs_rq)198 static inline u64 cfs_rq_clock_pelt(struct cfs_rq *cfs_rq)
199 {
200 	if (unlikely(cfs_rq->throttle_count))
201 		return cfs_rq->throttled_clock_pelt - cfs_rq->throttled_clock_pelt_time;
202 
203 	return rq_clock_pelt(rq_of(cfs_rq)) - cfs_rq->throttled_clock_pelt_time;
204 }
205 #else
update_idle_cfs_rq_clock_pelt(struct cfs_rq * cfs_rq)206 static inline void update_idle_cfs_rq_clock_pelt(struct cfs_rq *cfs_rq) { }
cfs_rq_clock_pelt(struct cfs_rq * cfs_rq)207 static inline u64 cfs_rq_clock_pelt(struct cfs_rq *cfs_rq)
208 {
209 	return rq_clock_pelt(rq_of(cfs_rq));
210 }
211 #endif
212 
213 #else
214 
215 static inline int
update_cfs_rq_load_avg(u64 now,struct cfs_rq * cfs_rq)216 update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
217 {
218 	return 0;
219 }
220 
221 static inline int
update_rt_rq_load_avg(u64 now,struct rq * rq,int running)222 update_rt_rq_load_avg(u64 now, struct rq *rq, int running)
223 {
224 	return 0;
225 }
226 
227 static inline int
update_dl_rq_load_avg(u64 now,struct rq * rq,int running)228 update_dl_rq_load_avg(u64 now, struct rq *rq, int running)
229 {
230 	return 0;
231 }
232 
233 static inline int
update_thermal_load_avg(u64 now,struct rq * rq,u64 capacity)234 update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
235 {
236 	return 0;
237 }
238 
thermal_load_avg(struct rq * rq)239 static inline u64 thermal_load_avg(struct rq *rq)
240 {
241 	return 0;
242 }
243 
244 static inline int
update_irq_load_avg(struct rq * rq,u64 running)245 update_irq_load_avg(struct rq *rq, u64 running)
246 {
247 	return 0;
248 }
249 
rq_clock_task_mult(struct rq * rq)250 static inline u64 rq_clock_task_mult(struct rq *rq)
251 {
252 	return rq_clock_task(rq);
253 }
254 
rq_clock_pelt(struct rq * rq)255 static inline u64 rq_clock_pelt(struct rq *rq)
256 {
257 	return rq_clock_task_mult(rq);
258 }
259 
260 static inline void
update_rq_clock_task_mult(struct rq * rq,s64 delta)261 update_rq_clock_task_mult(struct rq *rq, s64 delta) { }
262 
263 static inline void
update_idle_rq_clock_pelt(struct rq * rq)264 update_idle_rq_clock_pelt(struct rq *rq) { }
265 
update_idle_cfs_rq_clock_pelt(struct cfs_rq * cfs_rq)266 static inline void update_idle_cfs_rq_clock_pelt(struct cfs_rq *cfs_rq) { }
267 #endif
268 
269 
270