mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] sched: move update_curr() in check_preempt_wakeup() to avoid redundant call
@ 2009-11-17  9:51 Jupyung Lee
  2009-11-19 22:51 ` Peter Zijlstra
  2009-12-09  9:54 ` [tip:sched/urgent] sched: Move " tip-bot for Jupyung Lee
  0 siblings, 2 replies; 4+ messages in thread
From: Jupyung Lee @ 2009-11-17  9:51 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar, Jupyung Lee

Impact: micro-optimization

If a RT task is woken up while a non-RT task is running, 
check_preempt_wakeup() is called to check whether the new task can 
preempt the old task. The function returns quickly without going deeper 
because it is apparent that a RT task can always preempt a non-RT task.

In this situation, check_preempt_wakeup() always calls update_curr() to
update vruntime value of the currently running task. However, the function
call is unnecessary and redundant at that moment because (1) a non-RT task can 
always be preempted by a RT task regardless of its vruntime value, and
(2) update_curr() will be called shortly when the context switch between two occurs.

By moving update_curr() in check_preempt_wakeup(), we can avoid redundant
call to update_curr(), slightly reducing the time taken to wake up RT tasks.

Signed-off-by: Jupyung Lee <jupyung@gmail.com>
---
 kernel/sched_fair.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 37087a7..32256c0 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1596,8 +1596,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
 	int sync = wake_flags & WF_SYNC;
 	int scale = cfs_rq->nr_running >= sched_nr_latency;
 
-	update_curr(cfs_rq);
-
 	if (unlikely(rt_prio(p->prio))) {
 		resched_task(curr);
 		return;
@@ -1655,6 +1653,8 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
 
 	BUG_ON(!pse);
 
+	update_curr(cfs_rq);
+
 	if (wakeup_preempt_entity(se, pse) == 1) {
 		resched_task(curr);
 		/*
-- 
1.6.5.GIT


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

* Re: [PATCH 1/1] sched: move update_curr() in check_preempt_wakeup() to avoid redundant call
  2009-11-17  9:51 [PATCH 1/1] sched: move update_curr() in check_preempt_wakeup() to avoid redundant call Jupyung Lee
@ 2009-11-19 22:51 ` Peter Zijlstra
  2009-11-20  8:26   ` jupyung lee
  2009-12-09  9:54 ` [tip:sched/urgent] sched: Move " tip-bot for Jupyung Lee
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2009-11-19 22:51 UTC (permalink / raw)
  To: Jupyung Lee; +Cc: LKML, Ingo Molnar

On Tue, 2009-11-17 at 18:51 +0900, Jupyung Lee wrote:
> Impact: micro-optimization
> 
> If a RT task is woken up while a non-RT task is running, 
> check_preempt_wakeup() is called to check whether the new task can 
> preempt the old task. The function returns quickly without going deeper 
> because it is apparent that a RT task can always preempt a non-RT task.
> 
> In this situation, check_preempt_wakeup() always calls update_curr() to
> update vruntime value of the currently running task. However, the function
> call is unnecessary and redundant at that moment because (1) a non-RT task can 
> always be preempted by a RT task regardless of its vruntime value, and
> (2) update_curr() will be called shortly when the context switch between two occurs.
> 
> By moving update_curr() in check_preempt_wakeup(), we can avoid redundant
> call to update_curr(), slightly reducing the time taken to wake up RT tasks.

So far so good, but then you let me figure out why you placed it where
you did.

Anyway, I think the patch is good and took the patch, thanks!

> Signed-off-by: Jupyung Lee <jupyung@gmail.com>
> ---
>  kernel/sched_fair.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
> index 37087a7..32256c0 100644
> --- a/kernel/sched_fair.c
> +++ b/kernel/sched_fair.c
> @@ -1596,8 +1596,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
>  	int sync = wake_flags & WF_SYNC;
>  	int scale = cfs_rq->nr_running >= sched_nr_latency;
>  
> -	update_curr(cfs_rq);
> -
>  	if (unlikely(rt_prio(p->prio))) {
>  		resched_task(curr);
>  		return;
> @@ -1655,6 +1653,8 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
>  
>  	BUG_ON(!pse);
>  
> +	update_curr(cfs_rq);
> +
>  	if (wakeup_preempt_entity(se, pse) == 1) {
>  		resched_task(curr);
>  		/*



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

* Re: [PATCH 1/1] sched: move update_curr() in check_preempt_wakeup()  to avoid redundant call
  2009-11-19 22:51 ` Peter Zijlstra
@ 2009-11-20  8:26   ` jupyung lee
  0 siblings, 0 replies; 4+ messages in thread
From: jupyung lee @ 2009-11-20  8:26 UTC (permalink / raw)
  To: LKML

Hi Peter,

On Nov 20, 8:00 am, Peter Zijlstra <pet...@infradead.org> wrote:
> On Tue, 2009-11-17 at 18:51 +0900, Jupyung Lee wrote:
> > Impact: micro-optimization
>
> > If a RT task is woken up while a non-RT task is running,
> > check_preempt_wakeup() is called to check whether the new task can
> > preempt the old task. The function returns quickly without going deeper
> > because it is apparent that a RT task can always preempt a non-RT task.
>
> > In this situation, check_preempt_wakeup() always calls update_curr() to
> > update vruntime value of the currently running task. However, the function
> > call is unnecessary and redundant at that moment because (1) a non-RT task can
> > always be preempted by a RT task regardless of its vruntime value, and
> > (2) update_curr() will be called shortly when the context switch between two occurs.
>
> > By moving update_curr() in check_preempt_wakeup(), we can avoid redundant
> > call to update_curr(), slightly reducing the time taken to wake up RT tasks.
>
> So far so good, but then you let me figure out why you placed it where
> you did.
>

Currently, in check_preempt_wakeup(), update_curr(cfs_rq) is located as follows:

-----------------------------------------------------------------------------------------

   update_curr(cfs_rq);

   if (unlikely(rt_prio(p->prio))) {   .... /* A */
       resched_task(curr);
       return;
   }

   if (unlikely(p->sched_class != &fair_sched_class))  .... /* B */
       return;

   if (unlikely(se == pse))  .... /* C */
       return;

   if (sched_feat(NEXT_BUDDY) && scale && !(wake_flags &
WF_FORK)) .... /* D */
       set_next_buddy(pse);

   if (test_tsk_need_resched(curr))  .... /* E */
       return;

   if (unlikely(p->policy != SCHED_NORMAL))  .... /* F */
       return;

   if (unlikely(curr->policy == SCHED_IDLE)) {  .... /* G */
       resched_task(curr);
       return;
   }

   if ((sched_feat(WAKEUP_SYNC) && sync) ||  .... /* H */
       (sched_feat(WAKEUP_OVERLAP) &&
        (se->avg_overlap < sysctl_sched_migration_cost &&
         pse->avg_overlap < sysctl_sched_migration_cost))) {
       resched_task(curr);
       return;
   }

   if (sched_feat(WAKEUP_RUNNING)) {  .... /* I */
       if (pse->avg_running < se->avg_running) {
           set_next_buddy(pse);
           resched_task(curr);
           return;
       }
   }

   if (!sched_feat(WAKEUP_PREEMPT))  .... /* J */
       return;

   find_matching_se(&se, &pse);

   BUG_ON(!pse);

   if (wakeup_preempt_entity(se, pse) == 1) {  .... /* K */
       resched_task(curr);

-----------------------------------------------------------------------------------------

Among operations A to L, only 'K' is dependent on update_curr(), which updates
curr->vruntime; wakeup_preempt_entity() compares curr->vruntime with
se->vruntime.
Thus, it is straightforward to move update_curr() just above 'K'. It
allows us to avoid
unnecessary function call to update_curr() when we do not go up to 'K'.
As I said above, calling the function update_curr() here is
unnecessary and redundant
except the case 'K' because it will be called shortly when the context
switch between two occurs.

> Anyway, I think the patch is good and took the patch, thanks!
>

Thanks.

Jupyung

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

* [tip:sched/urgent] sched: Move update_curr() in check_preempt_wakeup() to avoid redundant call
  2009-11-17  9:51 [PATCH 1/1] sched: move update_curr() in check_preempt_wakeup() to avoid redundant call Jupyung Lee
  2009-11-19 22:51 ` Peter Zijlstra
@ 2009-12-09  9:54 ` tip-bot for Jupyung Lee
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Jupyung Lee @ 2009-12-09  9:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, jupyung, a.p.zijlstra, tglx, mingo

Commit-ID:  a65ac745e47e91f9d98dbf07f22ed0492e34d998
Gitweb:     http://git.kernel.org/tip/a65ac745e47e91f9d98dbf07f22ed0492e34d998
Author:     Jupyung Lee <jupyung@gmail.com>
AuthorDate: Tue, 17 Nov 2009 18:51:40 +0900
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 9 Dec 2009 10:03:06 +0100

sched: Move update_curr() in check_preempt_wakeup() to avoid redundant call

If a RT task is woken up while a non-RT task is running,
check_preempt_wakeup() is called to check whether the new task can
preempt the old task. The function returns quickly without going deeper
because it is apparent that a RT task can always preempt a non-RT task.

In this situation, check_preempt_wakeup() always calls update_curr() to
update vruntime value of the currently running task. However, the
function call is unnecessary and redundant at that moment because (1) a
non-RT task can always be preempted by a RT task regardless of its
vruntime value, and (2) update_curr() will be called shortly when the
context switch between two occurs.

By moving update_curr() in check_preempt_wakeup(), we can avoid
redundant call to update_curr(), slightly reducing the time taken to
wake up RT tasks.

Signed-off-by: Jupyung Lee <jupyung@gmail.com>
[ Place update_curr() right before the wake_preempt_entity() call, which
  is the only thing that relies on the updated vruntime ]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1258451500-6714-1-git-send-email-jupyung@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched_fair.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 44ec80c..4dec185 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1651,8 +1651,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
 	int sync = wake_flags & WF_SYNC;
 	int scale = cfs_rq->nr_running >= sched_nr_latency;
 
-	update_curr(cfs_rq);
-
 	if (unlikely(rt_prio(p->prio))) {
 		resched_task(curr);
 		return;
@@ -1710,6 +1708,8 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
 
 	BUG_ON(!pse);
 
+	update_curr(cfs_rq);
+
 	if (wakeup_preempt_entity(se, pse) == 1) {
 		resched_task(curr);
 		/*

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

end of thread, other threads:[~2009-12-09  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-17  9:51 [PATCH 1/1] sched: move update_curr() in check_preempt_wakeup() to avoid redundant call Jupyung Lee
2009-11-19 22:51 ` Peter Zijlstra
2009-11-20  8:26   ` jupyung lee
2009-12-09  9:54 ` [tip:sched/urgent] sched: Move " tip-bot for Jupyung Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®