Skip to content

Commit 49bd21e

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/core: Fix set_user_nice()
Almost all scheduler functions update state with the following pattern: if (queued) dequeue_task(rq, p, DEQUEUE_SAVE); if (running) put_prev_task(rq, p); /* update state */ if (queued) enqueue_task(rq, p, ENQUEUE_RESTORE); if (running) set_curr_task(rq, p); set_user_nice() however misses the running part, cure this. This was found by asserting we never enqueue 'current'. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b2bf6c3 commit 49bd21e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/sched/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3724,7 +3724,8 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
37243724

37253725
void set_user_nice(struct task_struct *p, long nice)
37263726
{
3727-
int old_prio, delta, queued;
3727+
bool queued, running;
3728+
int old_prio, delta;
37283729
struct rq_flags rf;
37293730
struct rq *rq;
37303731

@@ -3746,8 +3747,11 @@ void set_user_nice(struct task_struct *p, long nice)
37463747
goto out_unlock;
37473748
}
37483749
queued = task_on_rq_queued(p);
3750+
running = task_current(rq, p);
37493751
if (queued)
37503752
dequeue_task(rq, p, DEQUEUE_SAVE);
3753+
if (running)
3754+
put_prev_task(rq, p);
37513755

37523756
p->static_prio = NICE_TO_PRIO(nice);
37533757
set_load_weight(p);
@@ -3764,6 +3768,8 @@ void set_user_nice(struct task_struct *p, long nice)
37643768
if (delta < 0 || (delta > 0 && task_running(rq, p)))
37653769
resched_curr(rq);
37663770
}
3771+
if (running)
3772+
set_curr_task(rq, p);
37673773
out_unlock:
37683774
task_rq_unlock(rq, p, &rf);
37693775
}

0 commit comments

Comments
 (0)