[PATCH 2/2] sched: Let sched_class handle effective_prio calculation

From: Henrik Austad
Date: Tue Apr 07 2009 - 09:50:45 EST


Instead of testing for sched_class in the core scheduler, the calculation of the
class-specific effective priority should be handled by the scheduling class.

Signed-off-by: Henrik Austad <henrik@xxxxxxxxx>
Acked-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
---
include/linux/sched.h | 1 +
kernel/sched.c | 11 +++--------
kernel/sched_fair.c | 1 +
kernel/sched_idletask.c | 1 +
kernel/sched_rt.c | 6 ++++++
5 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 6dc6591..c98e912 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1015,6 +1015,7 @@ struct sched_class {
void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
int oldprio, int running);
int (*normal_prio) (struct task_struct *task);
+ int (*effective_prio) (struct task_struct *task);

#ifdef CONFIG_FAIR_GROUP_SCHED
void (*moved_group) (struct task_struct *p);
diff --git a/kernel/sched.c b/kernel/sched.c
index da13af5..5a6d4bd 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1814,15 +1814,10 @@ static inline int normal_prio(struct task_struct *p)
*/
static int effective_prio(struct task_struct *p)
{
+ /* update normal prio */
p->normal_prio = normal_prio(p);
- /*
- * If we are RT tasks or we were boosted to RT priority,
- * keep the priority unchanged. Otherwise, update priority
- * to the normal priority:
- */
- if (!rt_prio(p->prio))
- return p->normal_prio;
- return p->prio;
+
+ return p->sched_class->effective_prio(p);
}

/*
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index c94519a..42af406 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1822,6 +1822,7 @@ static const struct sched_class fair_sched_class = {

.prio_changed = prio_changed_fair,
.normal_prio = normal_prio_fair,
+ .effective_prio = normal_prio_fair,
.switched_to = switched_to_fair,

#ifdef CONFIG_FAIR_GROUP_SCHED
diff --git a/kernel/sched_idletask.c b/kernel/sched_idletask.c
index e52ae7c..675de4e 100644
--- a/kernel/sched_idletask.c
+++ b/kernel/sched_idletask.c
@@ -128,6 +128,7 @@ static const struct sched_class idle_sched_class = {

.prio_changed = prio_changed_idle,
.normal_prio = normal_prio_idle,
+ .effective_prio = normal_prio_idle,
.switched_to = switched_to_idle,

/* no .task_new for idle tasks */
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index ec966b7..6426ced 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -1676,6 +1676,11 @@ static int normal_prio_rt(struct task_struct *p)
return MAX_RT_PRIO-1 - p->rt_priority;
}

+static int effective_prio_rt(struct task_struct *p)
+{
+ return p->prio;
+}
+
static void watchdog(struct rq *rq, struct task_struct *p)
{
unsigned long soft, hard;
@@ -1765,6 +1770,7 @@ static const struct sched_class rt_sched_class = {

.prio_changed = prio_changed_rt,
.normal_prio = normal_prio_rt,
+ .effective_prio = effective_prio_rt,
.switched_to = switched_to_rt,
};

--
1.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/