Re: [PATCH 04/39] sched: Add sched_class->reweight_task()

Tejun Heo
2024-06-24T23:59:04Z

Hello, Peter.

On Mon, Jun 24, 2024 at 12:23:31PM +0200, Peter Zijlstra wrote:
> This reminds me, I think we have a bug here...
>
> https://lkml.kernel.org/r/20240422094157.GA34453@noisy.programming.kicks-ass.net
>
> I *think* we want something like the below, hmm?
>
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 0935f9d4bb7b..32a40d85c0b1 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1328,15 +1328,15 @@ int tg_nop(struct task_group *tg, void *data)
> void set_load_weight(struct task_struct *p, bool update_load)
> {
> int prio = p->static_prio - MAX_RT_PRIO;
> - struct load_weight *load = &p->se.load;
> + unsigned long weight;
> + u32 inv_weight;
>
> - /*
> - * SCHED_IDLE tasks get minimal weight:
> - */
> if (task_has_idle_policy(p)) {
> - load->weight = scale_load(WEIGHT_IDLEPRIO);
> - load->inv_weight = WMULT_IDLEPRIO;
> - return;
> + weight = scale_load(WEIGHT_IDLEPRIO);
> + inv_weight = WMULT_IDLEPRIO;
> + } else {
> + weight = scale_load(sched_prio_to_weight[prio]);
> + inv_weight = sched_prio_to_wmult[prio];

Hmmm... sorry but I'm a bit confused again. Isn't the code doing the same
thing before and after?

Before, if @p is SCHED_IDLE, @p->se.load is set to idle values and the
function returns. If @update_load && fair, calls reweight_task(). Otherwise,
update @p->se.load is updated according to @prio. After the patch, @weight
and @inv_weight calcuations are moved to set_load_weight() but it ends up
with the same result for all three cases.

Were you trying to say that if the idle policy were to implement
->reweight_task(), it wouldn't be called?

Thanks.

--
tejun