2019-12-12 04:12:38

by Thara Gopinath

[permalink] [raw]
Subject: [Patch v6 1/7] sched/pelt.c: 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 "delta" capacity and is not
binary(util_avg 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.

Signed-off-by: Thara Gopinath <[email protected]>
Reviewed-by: Vincent Guittot <[email protected]>
---

v5->v6:
- added trace support for thermal pressure pelt signal.

include/trace/events/sched.h | 4 ++++
kernel/sched/pelt.c | 22 ++++++++++++++++++++++
kernel/sched/pelt.h | 7 +++++++
kernel/sched/sched.h | 1 +
4 files changed, 34 insertions(+)

diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 420e80e..a8fb667 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -613,6 +613,10 @@ DECLARE_TRACE(pelt_dl_tp,
TP_PROTO(struct rq *rq),
TP_ARGS(rq));

+DECLARE_TRACE(pelt_thermal_tp,
+ TP_PROTO(struct rq *rq),
+ TP_ARGS(rq));
+
DECLARE_TRACE(pelt_irq_tp,
TP_PROTO(struct rq *rq),
TP_ARGS(rq));
diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
index a96db50..9aac3b7 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -353,6 +353,28 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq, int running)
return 0;
}

+/*
+ * thermal:
+ *
+ * load_sum = \Sum se->avg.load_sum
+ *
+ * util_avg and runnable_load_avg are not supported and meaningless.
+ *
+ */
+int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
+{
+ if (___update_load_sum(now, &rq->avg_thermal,
+ capacity,
+ capacity,
+ capacity)) {
+ ___update_load_avg(&rq->avg_thermal, 1, 1);
+ trace_pelt_thermal_tp(rq);
+ return 1;
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
/*
* irq:
diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h
index afff644..c74226d 100644
--- a/kernel/sched/pelt.h
+++ b/kernel/sched/pelt.h
@@ -6,6 +6,7 @@ int __update_load_avg_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se
int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq);
int update_rt_rq_load_avg(u64 now, struct rq *rq, int running);
int update_dl_rq_load_avg(u64 now, struct rq *rq, int running);
+int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity);

#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
int update_irq_load_avg(struct rq *rq, u64 running);
@@ -159,6 +160,12 @@ update_dl_rq_load_avg(u64 now, struct rq *rq, int running)
}

static inline int
+update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity)
+{
+ return 0;
+}
+
+static inline int
update_irq_load_avg(struct rq *rq, u64 running)
{
return 0;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 280a3c7..37bd7ef 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -944,6 +944,7 @@ struct rq {
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
struct sched_avg avg_irq;
#endif
+ struct sched_avg avg_thermal;
u64 idle_stamp;
u64 avg_idle;

--
2.1.4


2019-12-23 17:57:41

by Ionela Voinescu

[permalink] [raw]
Subject: Re: [Patch v6 1/7] sched/pelt.c: Add support to track thermal pressure

On Wednesday 11 Dec 2019 at 23:11:42 (-0500), Thara Gopinath wrote:
[...]
> diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h
> index afff644..c74226d 100644
> --- a/kernel/sched/pelt.h
> +++ b/kernel/sched/pelt.h
> @@ -6,6 +6,7 @@ int __update_load_avg_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se
> int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq);
> int update_rt_rq_load_avg(u64 now, struct rq *rq, int running);
> int update_dl_rq_load_avg(u64 now, struct rq *rq, int running);
> +int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity);
>

I know a lot of people have come with suggestions for this name, but how
about update_th_rq_load_avg :)? Only if you're in the mood to change it
again.

Regards,
Ionela.

2020-01-02 14:41:36

by Thara Gopinath

[permalink] [raw]
Subject: Re: [Patch v6 1/7] sched/pelt.c: Add support to track thermal pressure

On 12/23/2019 12:56 PM, Ionela Voinescu wrote:
> On Wednesday 11 Dec 2019 at 23:11:42 (-0500), Thara Gopinath wrote:
> [...]
>> diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h
>> index afff644..c74226d 100644
>> --- a/kernel/sched/pelt.h
>> +++ b/kernel/sched/pelt.h
>> @@ -6,6 +6,7 @@ int __update_load_avg_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se
>> int __update_load_avg_cfs_rq(u64 now, struct cfs_rq *cfs_rq);
>> int update_rt_rq_load_avg(u64 now, struct rq *rq, int running);
>> int update_dl_rq_load_avg(u64 now, struct rq *rq, int running);
>> +int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity);
>>
>
> I know a lot of people have come with suggestions for this name, but how
> about update_th_rq_load_avg :)? Only if you're in the mood to change it
> again.
Hi!
I am rebasing! So will rename!
>
> Regards,
> Ionela.
>


--
Warm Regards
Thara

2020-01-09 13:14:37

by Dietmar Eggemann

[permalink] [raw]
Subject: Re: [Patch v6 1/7] sched/pelt.c: Add support to track thermal pressure

On 08/01/2020 15:56, Thara Gopinath wrote:
> On Tue, 17 Dec 2019 at 07:54, Dietmar Eggemann <[email protected]>
> wrote:
>
>> On 12/12/2019 05:11, Thara Gopinath wrote:
>>
>> minor: in subject: s/sched/pelt.c/sched/pelt
>>
>> [...]
>>
>>> diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
>>> index a96db50..9aac3b7 100644
>>> --- a/kernel/sched/pelt.c
>>> +++ b/kernel/sched/pelt.c
>>> @@ -353,6 +353,28 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq,
>> int running)
>>> return 0;
>>> }
>>>
>>> +/*
>>> + * thermal:
>>> + *
>>> + * load_sum = \Sum se->avg.load_sum
>>
>> Why not '\Sum rq->avg.load_sum' ?
>>
> Hi Dietmar,
>
> The header for all other update_*_load_avg api use se->avg. and not rq->avg.

True but at least they (rt_rq, dl_rq, irq) also say 'but
se->avg.util_sum is not tracked'.

I guess this comment originally came from the
'__update_load_avg_blocked_se(), __update_load_avg_se(),
__update_load_avg_cfs_rq()' block:

* cfq_rq:
*
* load_sum = \Sum se_weight(se) * se->avg.load_sum

but for rt_rq, dl_rq, irq and thermal we don't have a relationship like
between se and cfs_rq's so that's why this comment confuses me.