Skip to content

Commit

Permalink
sched: Extend enqueue_task to allow head queueing
Browse files Browse the repository at this point in the history
The ability of enqueueing a task to the head of a SCHED_FIFO priority
list is required to fix some violations of POSIX scheduling policy.

Extend the related functions with a "head" argument.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Tested-by: Carsten Emde <cbe@osadl.org>
Tested-by: Mathias Weber <mathias.weber.mw1@roche.com>
LKML-Reference: <20100120171629.734886007@linutronix.de>
  • Loading branch information
Thomas Gleixner committed Jan 22, 2010
1 parent 7c94143 commit ea87bb7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ struct sched_domain;
struct sched_class {
const struct sched_class *next;

void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup,
bool head);
void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
void (*yield_task) (struct rq *rq);

Expand Down
13 changes: 7 additions & 6 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,13 +1856,14 @@ static void update_avg(u64 *avg, u64 sample)
*avg += diff >> 3;
}

static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
static void
enqueue_task(struct rq *rq, struct task_struct *p, int wakeup, bool head)
{
if (wakeup)
p->se.start_runtime = p->se.sum_exec_runtime;

sched_info_queued(p);
p->sched_class->enqueue_task(rq, p, wakeup);
p->sched_class->enqueue_task(rq, p, wakeup, head);
p->se.on_rq = 1;
}

Expand Down Expand Up @@ -1892,7 +1893,7 @@ static void activate_task(struct rq *rq, struct task_struct *p, int wakeup)
if (task_contributes_to_load(p))
rq->nr_uninterruptible--;

enqueue_task(rq, p, wakeup);
enqueue_task(rq, p, wakeup, false);
inc_nr_running(rq);
}

Expand Down Expand Up @@ -4236,7 +4237,7 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
if (running)
p->sched_class->set_curr_task(rq);
if (on_rq) {
enqueue_task(rq, p, 0);
enqueue_task(rq, p, 0, false);

check_class_changed(rq, p, prev_class, oldprio, running);
}
Expand Down Expand Up @@ -4280,7 +4281,7 @@ void set_user_nice(struct task_struct *p, long nice)
delta = p->prio - old_prio;

if (on_rq) {
enqueue_task(rq, p, 0);
enqueue_task(rq, p, 0, false);
/*
* If the task increased its priority or is running and
* lowered its priority, then reschedule its CPU:
Expand Down Expand Up @@ -8230,7 +8231,7 @@ void sched_move_task(struct task_struct *tsk)
if (unlikely(running))
tsk->sched_class->set_curr_task(rq);
if (on_rq)
enqueue_task(rq, tsk, 0);
enqueue_task(rq, tsk, 0, false);

task_rq_unlock(rq, &flags);
}
Expand Down
3 changes: 2 additions & 1 deletion kernel/sched_fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,8 @@ static inline void hrtick_update(struct rq *rq)
* increased. Here we update the fair scheduling stats and
* then put the task into the rbtree:
*/
static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
static void
enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head)
{
struct cfs_rq *cfs_rq;
struct sched_entity *se = &p->se;
Expand Down
3 changes: 2 additions & 1 deletion kernel/sched_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ static void dequeue_rt_entity(struct sched_rt_entity *rt_se)
/*
* Adding/removing a task to/from a priority array:
*/
static void enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup)
static void
enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup, bool head)
{
struct sched_rt_entity *rt_se = &p->rt;

Expand Down

0 comments on commit ea87bb7

Please sign in to comment.