linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] sched/dl: Fix preemption checks
@ 2014-10-21 16:35 Kirill Tkhai
  2014-10-22  9:43 ` Juri Lelli
  2014-10-28 11:03 ` [tip:sched/core] " tip-bot for Kirill Tkhai
  0 siblings, 2 replies; 3+ messages in thread
From: Kirill Tkhai @ 2014-10-21 16:35 UTC (permalink / raw)
  To: Juri Lelli, linux-kernel; +Cc: Peter Zijlstra, Ingo Molnar, Kirill Tkhai


1)switched_to_dl() check is wrong. We reschedule only
if rq->curr is deadline task, and we do not reschedule
if it's a lower priority task. But we must always
preempt a task of other classes.

2)dl_task_timer():
Policy does not change in case of priority inheritance.
rt_mutex_setprio() changes prio, while policy remains old.

So we lose some balancing logic in dl_task_timer() and
switched_to_dl() when we check policy instead of priority.
Boosted task may be rq->curr.

(I didn't change switched_from_dl() because no check is
necessary there at all).

I've looked at this place(switched_to_dl) several times
and even fixed this function, but found just now...
I suppose some performance tests may work better after this.

Completely untested, just RFC.

Juri how about this?

Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
---
 kernel/sched/deadline.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 256e577..937a875 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -532,7 +532,7 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
 	dl_se->dl_yielded = 0;
 	if (task_on_rq_queued(p)) {
 		enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
-		if (task_has_dl_policy(rq->curr))
+		if (dl_task(rq->curr))
 			check_preempt_curr_dl(rq, p, 0);
 		else
 			resched_curr(rq);
@@ -1607,8 +1607,12 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
 			/* Only reschedule if pushing failed */
 			check_resched = 0;
 #endif /* CONFIG_SMP */
-		if (check_resched && task_has_dl_policy(rq->curr))
-			check_preempt_curr_dl(rq, p, 0);
+		if (check_resched) {
+			if (dl_task(rq->curr))
+				check_preempt_curr_dl(rq, p, 0);
+			else
+				resched_curr(rq);
+		}
 	}
 }
 





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC] sched/dl: Fix preemption checks
  2014-10-21 16:35 [RFC] sched/dl: Fix preemption checks Kirill Tkhai
@ 2014-10-22  9:43 ` Juri Lelli
  2014-10-28 11:03 ` [tip:sched/core] " tip-bot for Kirill Tkhai
  1 sibling, 0 replies; 3+ messages in thread
From: Juri Lelli @ 2014-10-22  9:43 UTC (permalink / raw)
  To: Kirill Tkhai, Juri Lelli, linux-kernel
  Cc: Peter Zijlstra, Ingo Molnar, Kirill Tkhai

Hi Kirill,

On 21/10/14 17:35, Kirill Tkhai wrote:
> 
> 1)switched_to_dl() check is wrong. We reschedule only
> if rq->curr is deadline task, and we do not reschedule
> if it's a lower priority task. But we must always
> preempt a task of other classes.
> 
> 2)dl_task_timer():
> Policy does not change in case of priority inheritance.
> rt_mutex_setprio() changes prio, while policy remains old.
> 
> So we lose some balancing logic in dl_task_timer() and
> switched_to_dl() when we check policy instead of priority.
> Boosted task may be rq->curr.
> 
> (I didn't change switched_from_dl() because no check is
> necessary there at all).
> 
> I've looked at this place(switched_to_dl) several times
> and even fixed this function, but found just now...
> I suppose some performance tests may work better after this.
> 
> Completely untested, just RFC.
> 
> Juri how about this?
> 

I'll have to give it a spin, but it looks good.

Thanks,

- Juri

> Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
> ---
>  kernel/sched/deadline.c |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 256e577..937a875 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -532,7 +532,7 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
>  	dl_se->dl_yielded = 0;
>  	if (task_on_rq_queued(p)) {
>  		enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
> -		if (task_has_dl_policy(rq->curr))
> +		if (dl_task(rq->curr))
>  			check_preempt_curr_dl(rq, p, 0);
>  		else
>  			resched_curr(rq);
> @@ -1607,8 +1607,12 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
>  			/* Only reschedule if pushing failed */
>  			check_resched = 0;
>  #endif /* CONFIG_SMP */
> -		if (check_resched && task_has_dl_policy(rq->curr))
> -			check_preempt_curr_dl(rq, p, 0);
> +		if (check_resched) {
> +			if (dl_task(rq->curr))
> +				check_preempt_curr_dl(rq, p, 0);
> +			else
> +				resched_curr(rq);
> +		}
>  	}
>  }
>  
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:sched/core] sched/dl: Fix preemption checks
  2014-10-21 16:35 [RFC] sched/dl: Fix preemption checks Kirill Tkhai
  2014-10-22  9:43 ` Juri Lelli
@ 2014-10-28 11:03 ` tip-bot for Kirill Tkhai
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Kirill Tkhai @ 2014-10-28 11:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: juri.lelli, ktkhai, linux-kernel, hpa, torvalds, tglx, mingo, peterz

Commit-ID:  f3a7e1a9c464a32ee186ab91388313c82e7ce018
Gitweb:     http://git.kernel.org/tip/f3a7e1a9c464a32ee186ab91388313c82e7ce018
Author:     Kirill Tkhai <ktkhai@parallels.com>
AuthorDate: Tue, 21 Oct 2014 20:35:56 +0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 28 Oct 2014 10:46:10 +0100

sched/dl: Fix preemption checks

1) switched_to_dl() check is wrong. We reschedule only
   if rq->curr is deadline task, and we do not reschedule
   if it's a lower priority task. But we must always
   preempt a task of other classes.

2) dl_task_timer():
   Policy does not change in case of priority inheritance.
   rt_mutex_setprio() changes prio, while policy remains old.

So we lose some balancing logic in dl_task_timer() and
switched_to_dl() when we check policy instead of priority. Boosted
task may be rq->curr.

(I didn't change switched_from_dl() because no check is necessary
there at all).

I've looked at this place(switched_to_dl) several times and even fixed
this function, but found just now...  I suppose some performance tests
may work better after this.

Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/1413909356.19914.128.camel@tkhai
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/deadline.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 4616789..5285332 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -540,7 +540,7 @@ again:
 	dl_se->dl_yielded = 0;
 	if (task_on_rq_queued(p)) {
 		enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
-		if (task_has_dl_policy(rq->curr))
+		if (dl_task(rq->curr))
 			check_preempt_curr_dl(rq, p, 0);
 		else
 			resched_curr(rq);
@@ -1626,8 +1626,12 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
 			/* Only reschedule if pushing failed */
 			check_resched = 0;
 #endif /* CONFIG_SMP */
-		if (check_resched && task_has_dl_policy(rq->curr))
-			check_preempt_curr_dl(rq, p, 0);
+		if (check_resched) {
+			if (dl_task(rq->curr))
+				check_preempt_curr_dl(rq, p, 0);
+			else
+				resched_curr(rq);
+		}
 	}
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-28 11:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-21 16:35 [RFC] sched/dl: Fix preemption checks Kirill Tkhai
2014-10-22  9:43 ` Juri Lelli
2014-10-28 11:03 ` [tip:sched/core] " tip-bot for Kirill Tkhai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).