[PATCH 19/23] Subject: SCHED - Optimize out cpu_clears

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <mingo@...>
Cc: <rostedt@...>, <ghaskins@...>, <linux-rt-users@...>, <linux-kernel@...>
Date: Tuesday, December 4, 2007 - 4:46 pm

From: Steven Rostedt <srostedt@redhat.com>

This patch removes several cpumask operations by keeping track
of the first of the CPUS that is of the lowest priority. When
the search for the lowest priority runqueue is completed, all
the bits up to the first CPU with the lowest priority runqueue
is cleared.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---

 kernel/sched_rt.c |   49 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index 0514b27..039be04 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -294,29 +294,36 @@ static struct task_struct *pick_next_highest_task_rt(struct rq *rq,
 }
 
 static DEFINE_PER_CPU(cpumask_t, local_cpu_mask);
-static DEFINE_PER_CPU(cpumask_t, valid_cpu_mask);
 
 static int find_lowest_cpus(struct task_struct *task, cpumask_t *lowest_mask)
 {
-	int       cpu;
-	cpumask_t *valid_mask = &__get_cpu_var(valid_cpu_mask);
 	int       lowest_prio = -1;
+	int       lowest_cpu  = -1;
 	int       count       = 0;
+	int       cpu;
 
-	cpus_clear(*lowest_mask);
-	cpus_and(*valid_mask, cpu_online_map, task->cpus_allowed);
+	cpus_and(*lowest_mask, cpu_online_map, task->cpus_allowed);
 
 	/*
 	 * Scan each rq for the lowest prio.
 	 */
-	for_each_cpu_mask(cpu, *valid_mask) {
+	for_each_cpu_mask(cpu, *lowest_mask) {
 		struct rq *rq = cpu_rq(cpu);
 
 		/* We look for lowest RT prio or non-rt CPU */
 		if (rq->rt.highest_prio >= MAX_RT_PRIO) {
-			if (count)
+			/*
+			 * if we already found a low RT queue
+			 * and now we found this non-rt queue
+			 * clear the mask and set our bit.
+			 * Otherwise just return the queue as is
+			 * and the count==1 will cause the algorithm
+			 * to use the first bit found.
+			 */
+			if (lowest_cpu != -1) {
 				cpus_clear(*lowest_mask);
-			cpu_set(rq->cpu, *lowest_mask);
+				cpu_set(rq->cpu, *lowest_mask);
+			}
 			return 1;
 		}
 
@@ -326,13 +333,29 @@ static int find_lowest_cpus(struct task_struct *task, cpumask_t *lowest_mask)
 			if (rq->rt.highest_prio > lowest_prio) {
 				/* new low - clear old data */
 				lowest_prio = rq->rt.highest_prio;
-				if (count) {
-					cpus_clear(*lowest_mask);
-					count = 0;
-				}
+				lowest_cpu = cpu;
+				count = 0;
 			}
-			cpu_set(rq->cpu, *lowest_mask);
 			count++;
+		} else
+			cpu_clear(cpu, *lowest_mask);
+	}
+
+	/*
+	 * Clear out all the set bits that represent
+	 * runqueues that were of higher prio than
+	 * the lowest_prio.
+	 */
+	if (lowest_cpu > 0) {
+		/*
+		 * Perhaps we could add another cpumask op to
+		 * zero out bits. Like cpu_zero_bits(cpumask, nrbits);
+		 * Then that could be optimized to use memset and such.
+		 */
+		for_each_cpu_mask(cpu, *lowest_mask) {
+			if (cpu >= lowest_cpu)
+				break;
+			cpu_clear(cpu, *lowest_mask);
 		}
 	}
 

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/23] RT balance v7, Gregory Haskins, (Tue Dec 4, 4:44 pm)
Re: [PATCH 00/23] RT balance v7, Ingo Molnar, (Tue Dec 4, 5:27 pm)
[PATCH 0/3] RT balance v7a, Gregory Haskins, (Tue Dec 4, 10:55 pm)
[PATCH 1/3] Subject: SCHED - Add sched-domain roots, Gregory Haskins, (Tue Dec 4, 10:55 pm)
Re: [PATCH 00/23] RT balance v7, Gregory Haskins, (Tue Dec 4, 5:35 pm)
[PATCH 21/23] Subject: SCHED - Add sched-domain roots, Gregory Haskins, (Tue Dec 4, 4:46 pm)
[PATCH 16/23] Subject: SCHED - Avoid overload, Gregory Haskins, (Tue Dec 4, 4:45 pm)
[PATCH 19/23] Subject: SCHED - Optimize out cpu_clears, Gregory Haskins, (Tue Dec 4, 4:46 pm)
[PATCH 15/23] Subject: SCHED - Optimize rebalancing, Gregory Haskins, (Tue Dec 4, 4:45 pm)
[PATCH 03/23] Subject: SCHED - push RT tasks, Gregory Haskins, (Tue Dec 4, 4:44 pm)
[PATCH 06/23] Subject: SCHED - wake up balance RT, Gregory Haskins, (Tue Dec 4, 4:44 pm)
[PATCH 05/23] Subject: SCHED - pull RT tasks, Gregory Haskins, (Tue Dec 4, 4:44 pm)