Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched/fair: Move effective_cpu_util() and effective_cpu_util() in fair.c

Move effective_cpu_util() and sched_cpu_util() functions in fair.c file
with others utilization related functions.

No functional change.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20240904092417.20660-1-vincent.guittot@linaro.org

authored by

Vincent Guittot and committed by
Peter Zijlstra
5d871a63 3dcac251

+99 -101
+99
kernel/sched/fair.c
··· 8085 8085 } 8086 8086 8087 8087 /* 8088 + * This function computes an effective utilization for the given CPU, to be 8089 + * used for frequency selection given the linear relation: f = u * f_max. 8090 + * 8091 + * The scheduler tracks the following metrics: 8092 + * 8093 + * cpu_util_{cfs,rt,dl,irq}() 8094 + * cpu_bw_dl() 8095 + * 8096 + * Where the cfs,rt and dl util numbers are tracked with the same metric and 8097 + * synchronized windows and are thus directly comparable. 8098 + * 8099 + * The cfs,rt,dl utilization are the running times measured with rq->clock_task 8100 + * which excludes things like IRQ and steal-time. These latter are then accrued 8101 + * in the IRQ utilization. 8102 + * 8103 + * The DL bandwidth number OTOH is not a measured metric but a value computed 8104 + * based on the task model parameters and gives the minimal utilization 8105 + * required to meet deadlines. 8106 + */ 8107 + unsigned long effective_cpu_util(int cpu, unsigned long util_cfs, 8108 + unsigned long *min, 8109 + unsigned long *max) 8110 + { 8111 + unsigned long util, irq, scale; 8112 + struct rq *rq = cpu_rq(cpu); 8113 + 8114 + scale = arch_scale_cpu_capacity(cpu); 8115 + 8116 + /* 8117 + * Early check to see if IRQ/steal time saturates the CPU, can be 8118 + * because of inaccuracies in how we track these -- see 8119 + * update_irq_load_avg(). 8120 + */ 8121 + irq = cpu_util_irq(rq); 8122 + if (unlikely(irq >= scale)) { 8123 + if (min) 8124 + *min = scale; 8125 + if (max) 8126 + *max = scale; 8127 + return scale; 8128 + } 8129 + 8130 + if (min) { 8131 + /* 8132 + * The minimum utilization returns the highest level between: 8133 + * - the computed DL bandwidth needed with the IRQ pressure which 8134 + * steals time to the deadline task. 8135 + * - The minimum performance requirement for CFS and/or RT. 8136 + */ 8137 + *min = max(irq + cpu_bw_dl(rq), uclamp_rq_get(rq, UCLAMP_MIN)); 8138 + 8139 + /* 8140 + * When an RT task is runnable and uclamp is not used, we must 8141 + * ensure that the task will run at maximum compute capacity. 8142 + */ 8143 + if (!uclamp_is_used() && rt_rq_is_runnable(&rq->rt)) 8144 + *min = max(*min, scale); 8145 + } 8146 + 8147 + /* 8148 + * Because the time spend on RT/DL tasks is visible as 'lost' time to 8149 + * CFS tasks and we use the same metric to track the effective 8150 + * utilization (PELT windows are synchronized) we can directly add them 8151 + * to obtain the CPU's actual utilization. 8152 + */ 8153 + util = util_cfs + cpu_util_rt(rq); 8154 + util += cpu_util_dl(rq); 8155 + 8156 + /* 8157 + * The maximum hint is a soft bandwidth requirement, which can be lower 8158 + * than the actual utilization because of uclamp_max requirements. 8159 + */ 8160 + if (max) 8161 + *max = min(scale, uclamp_rq_get(rq, UCLAMP_MAX)); 8162 + 8163 + if (util >= scale) 8164 + return scale; 8165 + 8166 + /* 8167 + * There is still idle time; further improve the number by using the 8168 + * IRQ metric. Because IRQ/steal time is hidden from the task clock we 8169 + * need to scale the task numbers: 8170 + * 8171 + * max - irq 8172 + * U' = irq + --------- * U 8173 + * max 8174 + */ 8175 + util = scale_irq_capacity(util, irq, scale); 8176 + util += irq; 8177 + 8178 + return min(scale, util); 8179 + } 8180 + 8181 + unsigned long sched_cpu_util(int cpu) 8182 + { 8183 + return effective_cpu_util(cpu, cpu_util_cfs(cpu), NULL, NULL); 8184 + } 8185 + 8186 + /* 8088 8187 * energy_env - Utilization landscape for energy estimation. 8089 8188 * @task_busy_time: Utilization contribution by the task for which we test the 8090 8189 * placement. Given by eenv_task_busy_time().
-101
kernel/sched/syscalls.c
··· 258 258 259 259 #endif 260 260 261 - #ifdef CONFIG_SMP 262 - /* 263 - * This function computes an effective utilization for the given CPU, to be 264 - * used for frequency selection given the linear relation: f = u * f_max. 265 - * 266 - * The scheduler tracks the following metrics: 267 - * 268 - * cpu_util_{cfs,rt,dl,irq}() 269 - * cpu_bw_dl() 270 - * 271 - * Where the cfs,rt and dl util numbers are tracked with the same metric and 272 - * synchronized windows and are thus directly comparable. 273 - * 274 - * The cfs,rt,dl utilization are the running times measured with rq->clock_task 275 - * which excludes things like IRQ and steal-time. These latter are then accrued 276 - * in the IRQ utilization. 277 - * 278 - * The DL bandwidth number OTOH is not a measured metric but a value computed 279 - * based on the task model parameters and gives the minimal utilization 280 - * required to meet deadlines. 281 - */ 282 - unsigned long effective_cpu_util(int cpu, unsigned long util_cfs, 283 - unsigned long *min, 284 - unsigned long *max) 285 - { 286 - unsigned long util, irq, scale; 287 - struct rq *rq = cpu_rq(cpu); 288 - 289 - scale = arch_scale_cpu_capacity(cpu); 290 - 291 - /* 292 - * Early check to see if IRQ/steal time saturates the CPU, can be 293 - * because of inaccuracies in how we track these -- see 294 - * update_irq_load_avg(). 295 - */ 296 - irq = cpu_util_irq(rq); 297 - if (unlikely(irq >= scale)) { 298 - if (min) 299 - *min = scale; 300 - if (max) 301 - *max = scale; 302 - return scale; 303 - } 304 - 305 - if (min) { 306 - /* 307 - * The minimum utilization returns the highest level between: 308 - * - the computed DL bandwidth needed with the IRQ pressure which 309 - * steals time to the deadline task. 310 - * - The minimum performance requirement for CFS and/or RT. 311 - */ 312 - *min = max(irq + cpu_bw_dl(rq), uclamp_rq_get(rq, UCLAMP_MIN)); 313 - 314 - /* 315 - * When an RT task is runnable and uclamp is not used, we must 316 - * ensure that the task will run at maximum compute capacity. 317 - */ 318 - if (!uclamp_is_used() && rt_rq_is_runnable(&rq->rt)) 319 - *min = max(*min, scale); 320 - } 321 - 322 - /* 323 - * Because the time spend on RT/DL tasks is visible as 'lost' time to 324 - * CFS tasks and we use the same metric to track the effective 325 - * utilization (PELT windows are synchronized) we can directly add them 326 - * to obtain the CPU's actual utilization. 327 - */ 328 - util = util_cfs + cpu_util_rt(rq); 329 - util += cpu_util_dl(rq); 330 - 331 - /* 332 - * The maximum hint is a soft bandwidth requirement, which can be lower 333 - * than the actual utilization because of uclamp_max requirements. 334 - */ 335 - if (max) 336 - *max = min(scale, uclamp_rq_get(rq, UCLAMP_MAX)); 337 - 338 - if (util >= scale) 339 - return scale; 340 - 341 - /* 342 - * There is still idle time; further improve the number by using the 343 - * IRQ metric. Because IRQ/steal time is hidden from the task clock we 344 - * need to scale the task numbers: 345 - * 346 - * max - irq 347 - * U' = irq + --------- * U 348 - * max 349 - */ 350 - util = scale_irq_capacity(util, irq, scale); 351 - util += irq; 352 - 353 - return min(scale, util); 354 - } 355 - 356 - unsigned long sched_cpu_util(int cpu) 357 - { 358 - return effective_cpu_util(cpu, cpu_util_cfs(cpu), NULL, NULL); 359 - } 360 - #endif /* CONFIG_SMP */ 361 - 362 261 /** 363 262 * find_process_by_pid - find a process with a matching PID value. 364 263 * @pid: the pid in question.