Skip to content

Commit

Permalink
sched: Simplify sys_sched_rr_get_interval() system call
Browse files Browse the repository at this point in the history
By removing the need for it to know details of scheduling classes.

This allows PlugSched to define orthogonal scheduling classes.

Signed-off-by: Peter Williams <[email protected]>
Acked-by: Peter Zijlstra <[email protected]>
Cc: Mike Galbraith <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
pwil3058 authored and Ingo Molnar committed Sep 21, 2009
1 parent cb5fd13 commit 0d721ce
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
2 changes: 2 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ struct sched_class {
void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
int oldprio, int running);

unsigned int (*get_rr_interval) (struct task_struct *task);

#ifdef CONFIG_FAIR_GROUP_SCHED
void (*moved_group) (struct task_struct *p);
#endif
Expand Down
17 changes: 1 addition & 16 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -6819,23 +6819,8 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
if (retval)
goto out_unlock;

/*
* Time slice is 0 for SCHED_FIFO tasks and for SCHED_OTHER
* tasks that are on an otherwise idle runqueue:
*/
time_slice = 0;
if (p->policy == SCHED_RR) {
time_slice = DEF_TIMESLICE;
} else if (p->policy != SCHED_FIFO) {
struct sched_entity *se = &p->se;
unsigned long flags;
struct rq *rq;
time_slice = p->sched_class->get_rr_interval(p);

rq = task_rq_lock(p, &flags);
if (rq->cfs.load.weight)
time_slice = NS_TO_JIFFIES(sched_slice(&rq->cfs, se));
task_rq_unlock(rq, &flags);
}
read_unlock(&tasklist_lock);
jiffies_to_timespec(time_slice, &t);
retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
Expand Down
21 changes: 21 additions & 0 deletions kernel/sched_fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,25 @@ static void moved_group_fair(struct task_struct *p)
}
#endif

unsigned int get_rr_interval_fair(struct task_struct *task)
{
struct sched_entity *se = &task->se;
unsigned long flags;
struct rq *rq;
unsigned int rr_interval = 0;

/*
* Time slice is 0 for SCHED_OTHER tasks that are on an otherwise
* idle runqueue:
*/
rq = task_rq_lock(task, &flags);
if (rq->cfs.load.weight)
rr_interval = NS_TO_JIFFIES(sched_slice(&rq->cfs, se));
task_rq_unlock(rq, &flags);

return rr_interval;
}

/*
* All the scheduling class methods:
*/
Expand Down Expand Up @@ -1966,6 +1985,8 @@ static const struct sched_class fair_sched_class = {
.prio_changed = prio_changed_fair,
.switched_to = switched_to_fair,

.get_rr_interval = get_rr_interval_fair,

#ifdef CONFIG_FAIR_GROUP_SCHED
.moved_group = moved_group_fair,
#endif
Expand Down
7 changes: 7 additions & 0 deletions kernel/sched_idletask.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ static void prio_changed_idle(struct rq *rq, struct task_struct *p,
check_preempt_curr(rq, p, 0);
}

unsigned int get_rr_interval_idle(struct task_struct *task)
{
return 0;
}

/*
* Simple, special scheduling class for the per-CPU idle tasks:
*/
Expand All @@ -122,6 +127,8 @@ static const struct sched_class idle_sched_class = {
.set_curr_task = set_curr_task_idle,
.task_tick = task_tick_idle,

.get_rr_interval = get_rr_interval_idle,

.prio_changed = prio_changed_idle,
.switched_to = switched_to_idle,

Expand Down
13 changes: 13 additions & 0 deletions kernel/sched_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,17 @@ static void set_curr_task_rt(struct rq *rq)
dequeue_pushable_task(rq, p);
}

unsigned int get_rr_interval_rt(struct task_struct *task)
{
/*
* Time slice is 0 for SCHED_FIFO tasks
*/
if (task->policy == SCHED_RR)
return DEF_TIMESLICE;
else
return 0;
}

static const struct sched_class rt_sched_class = {
.next = &fair_sched_class,
.enqueue_task = enqueue_task_rt,
Expand Down Expand Up @@ -1762,6 +1773,8 @@ static const struct sched_class rt_sched_class = {
.set_curr_task = set_curr_task_rt,
.task_tick = task_tick_rt,

.get_rr_interval = get_rr_interval_rt,

.prio_changed = prio_changed_rt,
.switched_to = switched_to_rt,
};
Expand Down

0 comments on commit 0d721ce

Please sign in to comment.