Skip to contentSkip to conversation

Fix posix-cpu-timer breakage caused by stale p->last_ran value

PATCH In review Thomas Gleixner 5 participants 6 messages Feb 22, 2007 – Mar 2, 2007 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 Fix posix-cpu-timer breakage caused by stale p->last_ran value

Problem description at:
http://bugzilla.kernel.org/show_bug.cgi?id=8048

Commit b18ec80396834497933d77b81ec0918519f4e2a7
[PATCH] sched: improve migration accuracy
optimized the scheduler time calculations, but broke posix-cpu-timers.

The problem is that the p->last_ran value is not updated after a context switch. So a subsequent call to current_sched_time() calculates with a stale p->last_ran value, i.e. accounts the full time, which the task was scheduled away.

kernel/sched.c +1 -1
Index: linux-2.6/kernel/sched.c
===================================================================
@@ -3566,7 +3566,7 @@ switch_tasks:
 
 	sched_info_switch(prev, next);
 	if (likely(prev != next)) {
-		next->timestamp = now;
+		next->timestamp = next->last_ran = now;
 		rq->nr_switches++;
 		rq->curr = next;
 		++*switch_count;
Acked-by on v1 1/1
#2 lore raw

kernel/sched.c switch_tasks: · line 3569

Quoted 11 lines · Thomas Gleixner

The problem is that the p->last_ran value is not updated after a context switch. So a subsequent call to current_sched_time() calculates with a stale p->last_ran value, i.e. accounts the full time, which the task was scheduled away.

kernel/sched.c +1 -1
 	sched_info_switch(prev, next);
 	if (likely(prev != next)) {
-		next->timestamp = now;
+		next->timestamp = next->last_ran = now;

ouch! nice catch. Also for v2.6.20.2 i think. 2.6.19 should be unaffected.

Ingo

#3 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Thomas Gleixner

The problem is that the p->last_ran value is not updated after a context switch. So a subsequent call to current_sched_time() calculates with a stale p->last_ran value, i.e. accounts the full time, which the task was scheduled away.

Quoted 7 lines

kernel/sched.c switch_tasks: · line 3569

Quoted 4 lines
kernel/sched.c +1 -1
 	sched_info_switch(prev, next);
 	if (likely(prev != next)) {
-		next->timestamp = now;
+		next->timestamp = next->last_ran = now;

ouch! nice catch. Also for v2.6.20.2 i think. 2.6.19 should be unaffected.

Yes, was introduced in 2.6.20 and definitely should hit the stable tree.

tglx

#4 lore raw
In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner

Problem description at:
http://bugzilla.kernel.org/show_bug.cgi?id=8048

Commit b18ec80396834497933d77b81ec0918519f4e2a7
[PATCH] sched: improve migration accuracy
optimized the scheduler time calculations, but broke posix-cpu-timers.

The problem is that the p->last_ran value is not updated after a context switch. So a subsequent call to current_sched_time() calculates with a stale p->last_ran value, i.e. accounts the full time, which the task was scheduled away.

Oops, missed that. You could also remove the prev->last_ran assignment just above your addition, and turn this into a negative cost bugfix :)

-Mike

#5 lore raw
In reply to Thomas Gleixner
Quoted 20 lines · Thomas Gleixner

Problem description at:
http://bugzilla.kernel.org/show_bug.cgi?id=8048

Commit b18ec80396834497933d77b81ec0918519f4e2a7
[PATCH] sched: improve migration accuracy
optimized the scheduler time calculations, but broke posix-cpu-timers.

The problem is that the p->last_ran value is not updated after a context switch. So a subsequent call to current_sched_time() calculates with a stale p->last_ran value, i.e. accounts the full time, which the task was scheduled away.

Index: linux-2.6/kernel/sched.c
===================================================================

kernel/sched.c switch_tasks: · line 3572

Quoted 8 lines
kernel/sched.c +1 -1
@@ -3566,7 +3566,7 @@ switch_tasks:
 
 	sched_info_switch(prev, next);
 	if (likely(prev != next)) {
-		next->timestamp = now;
+		next->timestamp = next->last_ran = now;
 		rq->nr_switches++;
 		rq->curr = next;
 		++*switch_count;

Is this going to be merged or not??

#6 lore raw
Quoted 21 lines · On Thu, 01 Mar 2007 18:45:14 -0500 Chuck Ebbert <[email protected]> wrote:
Quoted 20 lines · Thomas Gleixner

Problem description at:
http://bugzilla.kernel.org/show_bug.cgi?id=8048

Commit b18ec80396834497933d77b81ec0918519f4e2a7
[PATCH] sched: improve migration accuracy
optimized the scheduler time calculations, but broke posix-cpu-timers.

The problem is that the p->last_ran value is not updated after a context switch. So a subsequent call to current_sched_time() calculates with a stale p->last_ran value, i.e. accounts the full time, which the task was scheduled away.

Index: linux-2.6/kernel/sched.c
===================================================================

kernel/sched.c +0 -0
@@ -3566,7 +3566,7 @@ switch_tasks:
 
Quoted 10 lines

kernel/sched.c switch_tasks: · line 3572

Quoted 8 lines
kernel/sched.c +1 -1
 	sched_info_switch(prev, next);
 	if (likely(prev != next)) {
-		next->timestamp = now;
+		next->timestamp = next->last_ran = now;
 		rq->nr_switches++;
 		rq->curr = next;
 		++*switch_count;

Is this going to be merged or not??

It just hit mainline.