Re: [PATCH 1/3] sched/tp: Add new tracepoint to track uclamp set from user-space

From: Qais Yousef
Date: Mon Apr 03 2023 - 09:46:16 EST


Hi Lukasz!

On 03/22/23 15:18, Lukasz Luba wrote:
> The user-space can set uclamp value for a given task. It impacts task
> placement decisions made by the scheduler. This is very useful information
> and helps to understand the system behavior or track improvements in
> middleware and applications which start using uclamp mechanisms and report
> better performance in tests.

We do have uclamp trace events in sched_tp, why are they not sufficient?

https://github.com/qais-yousef/sched_tp/blob/main/sched_events.h#L233

Do you really want to know the exact time the value has changed?

Would it make sense to introduce a generic sched_setscheduler tracepoint
instead? Although this might not be necessary as I think we can use
register_kprobe() to register a callback and create a new event without any
additional tracepoint. sched_setscheduler() is not inlined so should be easy to
hook into and create events, no?


Thanks

--
Qais Yousef

>
> Signed-off-by: Lukasz Luba <lukasz.luba@xxxxxxx>
> ---
> include/trace/events/sched.h | 4 ++++
> kernel/sched/core.c | 5 +++++
> 2 files changed, 9 insertions(+)
>
> diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
> index fbb99a61f714..dbfb30809f15 100644
> --- a/include/trace/events/sched.h
> +++ b/include/trace/events/sched.h
> @@ -735,6 +735,10 @@ DECLARE_TRACE(sched_update_nr_running_tp,
> TP_PROTO(struct rq *rq, int change),
> TP_ARGS(rq, change));
>
> +DECLARE_TRACE(uclamp_update_tsk_tp,
> + TP_PROTO(struct task_struct *tsk, int uclamp_id, unsigned int value),
> + TP_ARGS(tsk, uclamp_id, value));
> +
> #endif /* _TRACE_SCHED_H */
>
> /* This part must be outside protection */
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 488655f2319f..882c92e3ccf0 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -110,6 +110,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_overutilized_tp);
> EXPORT_TRACEPOINT_SYMBOL_GPL(sched_util_est_cfs_tp);
> EXPORT_TRACEPOINT_SYMBOL_GPL(sched_util_est_se_tp);
> EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp);
> +EXPORT_TRACEPOINT_SYMBOL_GPL(uclamp_update_tsk_tp);
>
> DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
>
> @@ -1936,12 +1937,16 @@ static void __setscheduler_uclamp(struct task_struct *p,
> attr->sched_util_min != -1) {
> uclamp_se_set(&p->uclamp_req[UCLAMP_MIN],
> attr->sched_util_min, true);
> + trace_uclamp_update_tsk_tp(p, UCLAMP_MIN,
> + attr->sched_util_min);
> }
>
> if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX &&
> attr->sched_util_max != -1) {
> uclamp_se_set(&p->uclamp_req[UCLAMP_MAX],
> attr->sched_util_max, true);
> + trace_uclamp_update_tsk_tp(p, UCLAMP_MAX,
> + attr->sched_util_max);
> }
> }
>
> --
> 2.17.1
>