Skip to contentSkip to conversation

small optimization to update_curr_rt

PATCH Applied Dimitri Sivanich 4 participants 5 messages Oct 31, 2008 – Nov 3, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 small optimization to update_curr_rt

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

--

 kernel/sched_rt.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched_rt.c +2 -2
Index: linux/kernel/sched_rt.c
===================================================================
@@ -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);
 	}
 }
 
#1 lore raw
Quoted 2 lines · Dimitri Sivanich

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

#2 lore raw
Quoted 8 lines · Steven Noonan
Quoted 2 lines · Dimitri Sivanich

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.

Acked-by on v1 1/1
#3 lore raw
In reply to Dimitri Sivanich
Quoted 2 lines · Dimitri Sivanich

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.

Quoted 27 lines

--

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

Index: linux/kernel/sched_rt.c
===================================================================

kernel/sched_rt.c +2 -2
@@ -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);
 	}
 }
 
Applied
#4 lore raw
Quoted 8 lines · Peter Zijlstra
Quoted 2 lines · Dimitri Sivanich

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:

Quoted 8 lines

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

applied to tip/sched/rt, thanks guys!

Ingo