Skip to contentSkip to conversation

sched/deadline: reduce overhead if there are no scheduling parameters changed

PATCH In review Wanpeng Li 2 participants 5 messages Nov 19, 2014 – Nov 25, 2014 Scheduler

lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 1/2 sched/deadline: reduce overhead if there are no scheduling parameters changed

There is no need to dequeue/enqueue and push/pull if there are no scheduling parameters changed for dl class, actually both fair and rt class have already check if parameters changed for them to avoid unnecessary overhead. This patch add the parameters changed verify for dl class in order to reduce overhead.

---
 kernel/sched/core.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
kernel/sched/core.c +16 -1
index 603c462..f361867 100644
@@ -3402,6 +3402,21 @@ static bool check_same_owner(struct task_struct *p)
 	return match;
 }
 
+static bool dl_param_changed(struct task_struct *p,
+			const struct sched_attr *attr)
+{
+	struct sched_dl_entity *dl_se = &p->dl;
+
+	if (dl_se->dl_runtime != attr->sched_runtime ||
+		dl_se->dl_deadline != attr->sched_deadline ||
+		dl_se->dl_period != attr->sched_period ||
+		dl_se->flags != attr->sched_flags ||
+		p->rt_priority != attr->sched_priority)
+		return true;
+
+	return false;
+}
+
 static int __sched_setscheduler(struct task_struct *p,
 				const struct sched_attr *attr,
 				bool user)
@@ -3530,7 +3545,7 @@ recheck:
 			goto change;
 		if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
 			goto change;
-		if (dl_policy(policy))
+		if (dl_policy(policy) && dl_param_changed(p, attr))
 			goto change;
 
 		p->sched_reset_on_fork = reset_on_fork;
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 2/2 sched/deadline: fix pull if dl task who's prio changed is not on queue

Dl task who is not on queue and it is also the curr task simultaneously can not happen. In addition, pull since the priority of a not on queue dl task doesn't make any sense.

This patch fix it by don't pull if dl task who's prio changed is not on queue.

---
 kernel/sched/deadline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/deadline.c +4 -1
index b9e44ae..4eaf55c 100644
@@ -1678,7 +1678,10 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
 static void prio_changed_dl(struct rq *rq, struct task_struct *p,
 			    int oldprio)
 {
-	if (task_on_rq_queued(p) || rq->curr == p) {
+	if (!task_on_rq_queued(p))
+		return;
+
+	if (rq->curr == p) {
 #ifdef CONFIG_SMP
 		/*
 		 * This might be too much, but unfortunately
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 2/2] sched/deadline: fix pull if dl task who's prio changed is not on queue

Hi,

Quoted 17 lines · Wanpeng Li

Dl task who is not on queue and it is also the curr task simultaneously can not happen. In addition, pull since the priority of a not on queue dl task doesn't make any sense.

This patch fix it by don't pull if dl task who's prio changed is not on queue.

---
 kernel/sched/deadline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/deadline.c +0 -0
index b9e44ae..4eaf55c 100644

kernel/sched/deadline.c static void switched_to_dl(struct rq *rq, struct task_struct *p) · line 1684

Quoted 8 lines
kernel/sched/deadline.c +4 -1
@@ -1678,7 +1678,10 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
 static void prio_changed_dl(struct rq *rq, struct task_struct *p,
 			    int oldprio)
 {
-	if (task_on_rq_queued(p) || rq->curr == p) {
+	if (!task_on_rq_queued(p))
+		return;
+
+	if (rq->curr == p) {

Yeah. I already posted a patches for this, that I forgot to properly post again :/. I'll do it soon.

Thanks,

- Juri

Quoted 4 lines
kernel/sched/deadline.c +0 -0
 #ifdef CONFIG_SMP
 		/*
 		 * This might be too much, but unfortunately
author
#3 lore raw

Re: [PATCH 2/2] sched/deadline: fix pull if dl task who's prio changed is not on queue

Hi Juri,

Quoted 15 lines · Juri Lelli

Hi,

Quoted 12 lines · Wanpeng Li

Dl task who is not on queue and it is also the curr task simultaneously can not happen. In addition, pull since the priority of a not on queue dl task doesn't make any sense.

This patch fix it by don't pull if dl task who's prio changed is not on queue.

---
 kernel/sched/deadline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 16 lines

kernel/sched/deadline.c static void switched_to_dl(struct rq *rq, struct task_struct *p) · line 1684

Quoted 13 lines
kernel/sched/deadline.c +4 -1
index b9e44ae..4eaf55c 100644
@@ -1678,7 +1678,10 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
 static void prio_changed_dl(struct rq *rq, struct task_struct *p,
 			    int oldprio)
 {
-	if (task_on_rq_queued(p) || rq->curr == p) {
+	if (!task_on_rq_queued(p))
+		return;
+
+	if (rq->curr == p) {

Yeah. I already posted a patches for this, that I forgot to properly post again :/. I'll do it soon.

Cool, so we can ignore this patch from me, and you can move forward. ;-) I will resend the recent posted patches in one patchset so you can review them easily.

Regards,
Wanpeng Li

Quoted 9 lines

Thanks,

- Juri

Quoted 4 lines
kernel/sched/deadline.c +0 -0
 #ifdef CONFIG_SMP
 		/*
 		 * This might be too much, but unfortunately
#4 lore raw
In reply to Wanpeng Li

Hi,

Quoted 16 lines · Wanpeng Li

There is no need to dequeue/enqueue and push/pull if there are no scheduling parameters changed for dl class, actually both fair and rt class have already check if parameters changed for them to avoid unnecessary overhead. This patch add the parameters changed verify for dl class in order to reduce overhead.

---
 kernel/sched/core.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
kernel/sched/core.c +0 -0
index 603c462..f361867 100644

kernel/sched/core.c static bool check_same_owner(struct task_struct *p) · line 3406

Quoted 5 lines
kernel/sched/core.c +2 -0
@@ -3402,6 +3402,21 @@ static bool check_same_owner(struct task_struct *p)
 	return match;
 }
 
+static bool dl_param_changed(struct task_struct *p,
+			const struct sched_attr *attr)

Please check alignment.

kernel/sched/core.c static bool check_same_owner(struct task_struct *p) · line 3414

Quoted 8 lines
kernel/sched/core.c +8 -0
+{
+	struct sched_dl_entity *dl_se = &p->dl;
+
+	if (dl_se->dl_runtime != attr->sched_runtime ||
+		dl_se->dl_deadline != attr->sched_deadline ||
+		dl_se->dl_period != attr->sched_period ||
+		dl_se->flags != attr->sched_flags ||
+		p->rt_priority != attr->sched_priority)

This last one is useless, as we fail above if attr->sched_priority != 0 when task has !rt_policy.

Thanks,

- Juri

Quoted 18 lines
kernel/sched/core.c +6 -1
+		return true;
+
+	return false;
+}
+
 static int __sched_setscheduler(struct task_struct *p,
 				const struct sched_attr *attr,
 				bool user)
@@ -3530,7 +3545,7 @@ recheck:
 			goto change;
 		if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
 			goto change;
-		if (dl_policy(policy))
+		if (dl_policy(policy) && dl_param_changed(p, attr))
 			goto change;
 
 		p->sched_reset_on_fork = reset_on_fork;