Diwakar Tundlam | 8 May 2012 23:39
Favicon

[PATCH] sched: Make nr_uninterruptible count a signed value

Declare nr_uninterruptible as a signed long to avoid garbage values
seen in cat /proc/sched_debug when a task is moved to the run queue of
a newly online core. This is part of a global counter where only the
total sum over all CPUs matters.

Signed-off-by: Diwakar Tundlam <dtundlam <at> nvidia.com>
---
 kernel/sched/core.c  |    7 ++++---
 kernel/sched/sched.h |    2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8d5eef6..7a64b5b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
 <at>  <at>  -2114,7 +2114,8  <at>  <at>  unsigned long nr_running(void)

 unsigned long nr_uninterruptible(void)
 {
-	unsigned long i, sum = 0;
+	unsigned long i;
+	long sum = 0;

 	for_each_possible_cpu(i)
 		sum += cpu_rq(i)->nr_uninterruptible;
 <at>  <at>  -2123,7 +2124,7  <at>  <at>  unsigned long nr_uninterruptible(void)
 	 * Since we read the counters lockless, it might be slightly
 	 * inaccurate. Do not allow it to go below zero though:
 	 */
-	if (unlikely((long)sum < 0))
+	if (unlikely(sum < 0))
 		sum = 0;

 	return sum;
 <at>  <at>  -2174,7 +2175,7  <at>  <at>  static long calc_load_fold_active(struct rq *this_rq)
 	long nr_active, delta = 0;

 	nr_active = this_rq->nr_running;
-	nr_active += (long) this_rq->nr_uninterruptible;
+	nr_active += this_rq->nr_uninterruptible;

 	if (nr_active != this_rq->calc_load_active) {
 		delta = nr_active - this_rq->calc_load_active;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index fb3acba..2668b07 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
 <at>  <at>  -385,7 +385,7  <at>  <at>  struct rq {
 	 * one CPU and if it got migrated afterwards it may decrease
 	 * it on another CPU. Always updated under the runqueue lock:
 	 */
-	unsigned long nr_uninterruptible;
+	long nr_uninterruptible;

 	struct task_struct *curr, *idle, *stop;
 	unsigned long next_balance;
--

-- 
1.7.4.1

Gmane