Skip to content

Commit 7650479

Browse files
tharagopinathingomolnar
authored andcommitted
sched/pelt: Add support to track thermal pressure
Extrapolating on the existing framework to track rt/dl utilization using pelt signals, add a similar mechanism to track thermal pressure. The difference here from rt/dl utilization tracking is that, instead of tracking time spent by a CPU running a RT/DL task through util_avg, the average thermal pressure is tracked through load_avg. This is because thermal pressure signal is weighted time "delta" capacity unlike util_avg which is binary. "delta capacity" here means delta between the actual capacity of a CPU and the decreased capacity a CPU due to a thermal event. In order to track average thermal pressure, a new sched_avg variable avg_thermal is introduced. Function update_thermal_load_avg can be called to do the periodic bookkeeping (accumulate, decay and average) of the thermal pressure. Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lkml.kernel.org/r/20200222005213.3873-2-thara.gopinath@linaro.org
1 parent f1dfdab commit 7650479

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎include/trace/events/sched.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ DECLARE_TRACE(pelt_dl_tp,
618618
TP_PROTO(struct rq *rq),
619619
TP_ARGS(rq));
620620

621+
DECLARE_TRACE(pelt_thermal_tp,
622+
TP_PROTO(struct rq *rq),
623+
TP_ARGS(rq));
624+
621625
DECLARE_TRACE(pelt_irq_tp,
622626
TP_PROTO(struct rq *rq),
623627
TP_ARGS(rq));

‎init/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ config HAVE_SCHED_AVG_IRQ
451451
depends on IRQ_TIME_ACCOUNTING || PARAVIRT_TIME_ACCOUNTING
452452
depends on SMP
453453

454+
config SCHED_THERMAL_PRESSURE
455+
bool "Enable periodic averaging of thermal pressure"
456+
depends on SMP
457+
454458
config BSD_PROCESS_ACCT
455459
bool "BSD Process Accounting"
456460
depends on MULTIUSER

‎kernel/sched/pelt.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,37 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq, int running)
368368
return 0;
369369
}
370370

371+
#ifdef CONFIG_SCHED_THERMAL_PRESSURE
372+
/*
373+
* thermal:
374+
*
375+
* load_sum = \Sum se->avg.load_sum but se->avg.load_sum is not tracked
376+
*
377+
* util_avg and runnable_load_avg are not supported and meaningless.
378+
*
379+
* Unlike rt/dl utilization tracking that track time spent by a cpu
380+
* running a rt/dl task through util_avg, the average thermal pressure is
381+
* tracked through load_avg. This is because thermal pressure signal is
382+
* time weighted "delta" capacity unlike util_avg which is binary.
383+
* "delta capacity" = actual capacity -
384+
* capped capacity a cpu due to a thermal event.
385+
*/
386+
387+
int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
388+
{
389+
if (___update_load_sum(now, &rq->avg_thermal,
390+
capacity,
391+
capacity,
392+
capacity)) {
393+
___update_load_avg(&rq->avg_thermal, 1);
394+
trace_pelt_thermal_tp(rq);
395+
return 1;
396+
}
397+
398+
return 0;
399+
}
400+
#endif
401+
371402
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
372403
/*
373404
* irq:

‎kernel/sched/pelt.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq);
77
int update_rt_rq_load_avg(u64 now, struct rq *rq, int running);
88
int update_dl_rq_load_avg(u64 now, struct rq *rq, int running);
99

10+
#ifdef CONFIG_SCHED_THERMAL_PRESSURE
11+
int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity);
12+
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
19+
update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
20+
{
21+
return 0;
22+
}
23+
24+
static inline u64 thermal_load_avg(struct rq *rq)
25+
{
26+
return 0;
27+
}
28+
#endif
29+
1030
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
1131
int update_irq_load_avg(struct rq *rq, u64 running);
1232
#else
@@ -158,6 +178,17 @@ update_dl_rq_load_avg(u64 now, struct rq *rq, int running)
158178
return 0;
159179
}
160180

181+
static inline int
182+
update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
183+
{
184+
return 0;
185+
}
186+
187+
static inline u64 thermal_load_avg(struct rq *rq)
188+
{
189+
return 0;
190+
}
191+
161192
static inline int
162193
update_irq_load_avg(struct rq *rq, u64 running)
163194
{

‎kernel/sched/sched.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ struct rq {
960960
struct sched_avg avg_dl;
961961
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
962962
struct sched_avg avg_irq;
963+
#endif
964+
#ifdef CONFIG_SCHED_THERMAL_PRESSURE
965+
struct sched_avg avg_thermal;
963966
#endif
964967
u64 idle_stamp;
965968
u64 avg_idle;

0 commit comments

Comments
 (0)