Commit d3296052 authored by Tejun Heo's avatar Tejun Heo Committed by Peter Zijlstra

sched/fair: set_load_weight() must also call reweight_task() for SCHED_IDLE tasks

When a task's weight is being changed, set_load_weight() is called with
@update_load set. As weight changes aren't trivial for the fair class,
set_load_weight() calls fair.c::reweight_task() for fair class tasks.

However, set_load_weight() first tests task_has_idle_policy() on entry and
skips calling reweight_task() for SCHED_IDLE tasks. This is buggy as
SCHED_IDLE tasks are just fair tasks with a very low weight and they would
incorrectly skip load, vlag and position updates.

Fix it by updating reweight_task() to take struct load_weight as idle weight
can't be expressed with prio and making set_load_weight() call
reweight_task() for SCHED_IDLE tasks too when @update_load is set.

Fixes: 9059393e ("sched/fair: Use reweight_entity() for set_user_nice()")
Suggested-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org # v4.15+
Link: http://lkml.kernel.org/r/20240624102331.GI31592@noisy.programming.kicks-ass.net
parent 0ec208ce
...@@ -1328,27 +1328,24 @@ int tg_nop(struct task_group *tg, void *data) ...@@ -1328,27 +1328,24 @@ int tg_nop(struct task_group *tg, void *data)
void set_load_weight(struct task_struct *p, bool update_load) void set_load_weight(struct task_struct *p, bool update_load)
{ {
int prio = p->static_prio - MAX_RT_PRIO; int prio = p->static_prio - MAX_RT_PRIO;
struct load_weight *load = &p->se.load; struct load_weight lw;
/*
* SCHED_IDLE tasks get minimal weight:
*/
if (task_has_idle_policy(p)) { if (task_has_idle_policy(p)) {
load->weight = scale_load(WEIGHT_IDLEPRIO); lw.weight = scale_load(WEIGHT_IDLEPRIO);
load->inv_weight = WMULT_IDLEPRIO; lw.inv_weight = WMULT_IDLEPRIO;
return; } else {
lw.weight = scale_load(sched_prio_to_weight[prio]);
lw.inv_weight = sched_prio_to_wmult[prio];
} }
/* /*
* SCHED_OTHER tasks have to update their load when changing their * SCHED_OTHER tasks have to update their load when changing their
* weight * weight
*/ */
if (update_load && p->sched_class == &fair_sched_class) { if (update_load && p->sched_class == &fair_sched_class)
reweight_task(p, prio); reweight_task(p, &lw);
} else { else
load->weight = scale_load(sched_prio_to_weight[prio]); p->se.load = lw;
load->inv_weight = sched_prio_to_wmult[prio];
}
} }
#ifdef CONFIG_UCLAMP_TASK #ifdef CONFIG_UCLAMP_TASK
......
...@@ -3835,15 +3835,14 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, ...@@ -3835,15 +3835,14 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
} }
} }
void reweight_task(struct task_struct *p, int prio) void reweight_task(struct task_struct *p, const struct load_weight *lw)
{ {
struct sched_entity *se = &p->se; struct sched_entity *se = &p->se;
struct cfs_rq *cfs_rq = cfs_rq_of(se); struct cfs_rq *cfs_rq = cfs_rq_of(se);
struct load_weight *load = &se->load; struct load_weight *load = &se->load;
unsigned long weight = scale_load(sched_prio_to_weight[prio]);
reweight_entity(cfs_rq, se, weight); reweight_entity(cfs_rq, se, lw->weight);
load->inv_weight = sched_prio_to_wmult[prio]; load->inv_weight = lw->inv_weight;
} }
static inline int throttled_hierarchy(struct cfs_rq *cfs_rq); static inline int throttled_hierarchy(struct cfs_rq *cfs_rq);
......
...@@ -2509,7 +2509,7 @@ extern void init_sched_dl_class(void); ...@@ -2509,7 +2509,7 @@ extern void init_sched_dl_class(void);
extern void init_sched_rt_class(void); extern void init_sched_rt_class(void);
extern void init_sched_fair_class(void); extern void init_sched_fair_class(void);
extern void reweight_task(struct task_struct *p, int prio); extern void reweight_task(struct task_struct *p, const struct load_weight *lw);
extern void resched_curr(struct rq *rq); extern void resched_curr(struct rq *rq);
extern void resched_cpu(int cpu); extern void resched_cpu(int cpu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment