LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] small optimization to update_curr_rt
@ 2008-10-31 13:03 Dimitri Sivanich
  2008-10-31 13:10 ` Steven Noonan
  2008-11-03 10:22 ` Peter Zijlstra
  0 siblings, 2 replies; 5+ messages in thread
From: Dimitri Sivanich @ 2008-10-31 13:03 UTC (permalink / raw)
  To: Ingo Molnar, linux-kernel; +Cc: H. Peter Anvin, Thomas Gleixner, Andrew Morton

A very minor improvement, but might it be better to check sched_rt_runtime(rt_rq)
before taking the rt_runtime_lock?

Signed-off-by: Dimitri Sivanich <sivanich@sgi.com>

--

 kernel/sched_rt.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux/kernel/sched_rt.c
===================================================================
--- linux.orig/kernel/sched_rt.c	2008-10-22 16:10:03.000000000 -0500
+++ linux/kernel/sched_rt.c	2008-10-31 07:57:19.000000000 -0500
@@ -537,13 +537,13 @@ static void update_curr_rt(struct rq *rq
 	for_each_sched_rt_entity(rt_se) {
 		rt_rq = rt_rq_of_se(rt_se);
 
-		spin_lock(&rt_rq->rt_runtime_lock);
 		if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
+			spin_lock(&rt_rq->rt_runtime_lock);
 			rt_rq->rt_time += delta_exec;
 			if (sched_rt_runtime_exceeded(rt_rq))
 				resched_task(curr);
+			spin_unlock(&rt_rq->rt_runtime_lock);
 		}
-		spin_unlock(&rt_rq->rt_runtime_lock);
 	}
 }
 

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

* Re: [PATCH] small optimization to update_curr_rt
  2008-10-31 13:03 [PATCH] small optimization to update_curr_rt Dimitri Sivanich
@ 2008-10-31 13:10 ` Steven Noonan
  2008-10-31 13:46   ` Dimitri Sivanich
  2008-11-03 10:22 ` Peter Zijlstra
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Noonan @ 2008-10-31 13:10 UTC (permalink / raw)
  To: Dimitri Sivanich
  Cc: Ingo Molnar, linux-kernel, H. Peter Anvin, Thomas Gleixner,
	Andrew Morton

On Fri, Oct 31, 2008 at 6:03 AM, Dimitri Sivanich <sivanich@sgi.com> wrote:
> A very minor improvement, but might it be better to check sched_rt_runtime(rt_rq)
> before taking the rt_runtime_lock?

Is it possible that the attribute sched_rt_runtime is checking could
change by the time it acquires the lock? If not, should be fine, I
think.

- Steven

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

* Re: [PATCH] small optimization to update_curr_rt
  2008-10-31 13:10 ` Steven Noonan
@ 2008-10-31 13:46   ` Dimitri Sivanich
  0 siblings, 0 replies; 5+ messages in thread
From: Dimitri Sivanich @ 2008-10-31 13:46 UTC (permalink / raw)
  To: Steven Noonan
  Cc: Ingo Molnar, linux-kernel, H. Peter Anvin, Thomas Gleixner,
	Andrew Morton

On Fri, Oct 31, 2008 at 06:10:13AM -0700, Steven Noonan wrote:
> On Fri, Oct 31, 2008 at 6:03 AM, Dimitri Sivanich <sivanich@sgi.com> wrote:
> > A very minor improvement, but might it be better to check sched_rt_runtime(rt_rq)
> > before taking the rt_runtime_lock?
> 
> Is it possible that the attribute sched_rt_runtime is checking could
> change by the time it acquires the lock? If not, should be fine, I
> think.
>

Steve,

While it might be possible for it to change in that instant, I don't know if it matters.

If the runtime value should change to RUNTIME_INF in that instant, it will be caught in sched_rt_runtime_exceeded().  If it changed from RUNTIME_INF to a lower value, I doubt it would matter much, as at most one more rt_rq value wouldn't be checked.  Either way some rt_rq values would have been checked during the loop and some would not.

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

* Re: [PATCH] small optimization to update_curr_rt
  2008-10-31 13:03 [PATCH] small optimization to update_curr_rt Dimitri Sivanich
  2008-10-31 13:10 ` Steven Noonan
@ 2008-11-03 10:22 ` Peter Zijlstra
  2008-11-03 10:29   ` Ingo Molnar
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2008-11-03 10:22 UTC (permalink / raw)
  To: Dimitri Sivanich
  Cc: Ingo Molnar, linux-kernel, H. Peter Anvin, Thomas Gleixner,
	Andrew Morton

On Fri, 2008-10-31 at 08:03 -0500, Dimitri Sivanich wrote:
> A very minor improvement, but might it be better to check sched_rt_runtime(rt_rq)
> before taking the rt_runtime_lock?

Yes, I think its ok to do so.

Like pointed out in the other thread, there are two races:

 - sched_rt_runtime() going to RUNTIME_INF, and that will be handled
   properly by sched_rt_runtime_exceeded()

 - sched_rt_runtime() going to !RUNTIME_INF, and here we can miss an
   accounting cycle, but I don't think that is something to worry too
   much about.

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

> Signed-off-by: Dimitri Sivanich <sivanich@sgi.com>
> 
> --
> 
>  kernel/sched_rt.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Index: linux/kernel/sched_rt.c
> ===================================================================
> --- linux.orig/kernel/sched_rt.c	2008-10-22 16:10:03.000000000 -0500
> +++ linux/kernel/sched_rt.c	2008-10-31 07:57:19.000000000 -0500
> @@ -537,13 +537,13 @@ static void update_curr_rt(struct rq *rq
>  	for_each_sched_rt_entity(rt_se) {
>  		rt_rq = rt_rq_of_se(rt_se);
>  
> -		spin_lock(&rt_rq->rt_runtime_lock);
>  		if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
> +			spin_lock(&rt_rq->rt_runtime_lock);
>  			rt_rq->rt_time += delta_exec;
>  			if (sched_rt_runtime_exceeded(rt_rq))
>  				resched_task(curr);
> +			spin_unlock(&rt_rq->rt_runtime_lock);
>  		}
> -		spin_unlock(&rt_rq->rt_runtime_lock);
>  	}
>  }
>  

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

* Re: [PATCH] small optimization to update_curr_rt
  2008-11-03 10:22 ` Peter Zijlstra
@ 2008-11-03 10:29   ` Ingo Molnar
  0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2008-11-03 10:29 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Dimitri Sivanich, linux-kernel, H. Peter Anvin, Thomas Gleixner,
	Andrew Morton


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Fri, 2008-10-31 at 08:03 -0500, Dimitri Sivanich wrote:
> > A very minor improvement, but might it be better to check sched_rt_runtime(rt_rq)
> > before taking the rt_runtime_lock?
> 
> Yes, I think its ok to do so.
> 
> Like pointed out in the other thread, there are two races:
> 
>  - sched_rt_runtime() going to RUNTIME_INF, and that will be handled
>    properly by sched_rt_runtime_exceeded()
> 
>  - sched_rt_runtime() going to !RUNTIME_INF, and here we can miss an
>    accounting cycle, but I don't think that is something to worry too
>    much about.
> 
> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

applied to tip/sched/rt, thanks guys!

	Ingo

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

end of thread, other threads:[~2008-11-03 10:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-31 13:03 [PATCH] small optimization to update_curr_rt Dimitri Sivanich
2008-10-31 13:10 ` Steven Noonan
2008-10-31 13:46   ` Dimitri Sivanich
2008-11-03 10:22 ` Peter Zijlstra
2008-11-03 10:29   ` Ingo Molnar

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).