Skip to contentSkip to conversation

sched: reassign prev and switch_count when reacquire_kernel_lock() fail

PATCH In review Yong Zhang 2 participants 3 messages Jan 11, 2010 – Jan 21, 2010

lore
Share & tools
lore

Yong Zhang

author
#0 lore raw

PATCH 1/1 sched: reassign prev and switch_count when reacquire_kernel_lock() fail

Quoted 1 line

From 4c04fbbd43f3fef7a3b9471a0000c399c2e045ed Mon Sep 17 00:00:00 2001

From: Yong Zhang <[email protected]>
Date: Mon, 11 Jan 2010 14:21:25 +0800
Subject: [PATCH] sched: reassign prev and switch_count when reacquire_kernel_lock() fail

Assume A->B schedule is processing, if B have acquired BKL before and it need reschedule this time. Then on B's context, it will go to need_resched_nonpreemptible for reschedule. But at this time, prev and switch_count are related to A. It's wrong and will lead to incorrect scheduler statistics.

---
 kernel/sched.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/sched.c +4 -1
index c535cc4..4508fe7 100644
@@ -5530,8 +5530,11 @@ need_resched_nonpreemptible:
 
 	post_schedule(rq);
 
-	if (unlikely(reacquire_kernel_lock(current) < 0))
+	if (unlikely(reacquire_kernel_lock(current) < 0)) {
+		prev = rq->curr;
+		switch_count = &prev->nivcsw;
 		goto need_resched_nonpreemptible;
+	}
 
 	preempt_enable_no_resched();
 	if (need_resched())
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 6 lines · Yong Zhang

From 4c04fbbd43f3fef7a3b9471a0000c399c2e045ed Mon Sep 17 00:00:00 2001
From: Yong Zhang <[email protected]>
Date: Mon, 11 Jan 2010 14:21:25 +0800
Subject: [PATCH] sched: reassign prev and switch_count when reacquire_kernel_lock() fail

Quoted 7 lines

Assume A->B schedule is processing, if B have acquired BKL before and it need reschedule this time. Then on B's context, it will go to need_resched_nonpreemptible for reschedule. But at this time, prev and switch_count are related to A. It's wrong and will lead to incorrect scheduler statistics.

Looks good, picked it up, thanks!

Quoted 21 lines
---
 kernel/sched.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/sched.c +4 -1
index c535cc4..4508fe7 100644
@@ -5530,8 +5530,11 @@ need_resched_nonpreemptible:
 
 	post_schedule(rq);
 
-	if (unlikely(reacquire_kernel_lock(current) < 0))
+	if (unlikely(reacquire_kernel_lock(current) < 0)) {
+		prev = rq->curr;
+		switch_count = &prev->nivcsw;
 		goto need_resched_nonpreemptible;
+	}
 
 	preempt_enable_no_resched();
 	if (need_resched())
#2 lore raw

[tip:sched/urgent] sched: Reassign prev and switch_count when reacquire_kernel_lock() fail

In reply to Yong Zhang
Commit-ID:  6d558c3ac9b6508d26fd5cadccce51fc9d726b1c
Gitweb:     http://git.kernel.org/tip/6d558c3ac9b6508d26fd5cadccce51fc9d726b1c
Author:     Yong Zhang <[email protected]>
AuthorDate: Mon, 11 Jan 2010 14:21:25 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 21 Jan 2010 13:39:04 +0100

sched: Reassign prev and switch_count when reacquire_kernel_lock() fail

Assume A->B schedule is processing, if B have acquired BKL before and it need reschedule this time. Then on B's context, it will go to need_resched_nonpreemptible for reschedule. But at this time, prev and switch_count are related to A. It's wrong and will lead to incorrect scheduler statistics.

LKML-Reference: <[email protected]>

---
 kernel/sched.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/sched.c +4 -1
index c535cc4..4508fe7 100644
@@ -5530,8 +5530,11 @@ need_resched_nonpreemptible:
 
 	post_schedule(rq);
 
-	if (unlikely(reacquire_kernel_lock(current) < 0))
+	if (unlikely(reacquire_kernel_lock(current) < 0)) {
+		prev = rq->curr;
+		switch_count = &prev->nivcsw;
 		goto need_resched_nonpreemptible;
+	}
 
 	preempt_enable_no_resched();
 	if (need_resched())