Re: goodness in reschedule idle

Andrea Arcangeli (andrea@e-mind.com)
Thu, 3 Dec 1998 12:57:50 +0100 (CET)


On Thu, 3 Dec 1998, Andrea Arcangeli wrote:

>What do you think about this:

Really it would be better to use goodness FASTCALL, this new patch
return also to the +3 policy and is against 2.1.131:

Index: linux/kernel/sched.c
diff -u linux/kernel/sched.c:1.1.1.2 linux/kernel/sched.c:1.1.1.1.2.22
--- linux/kernel/sched.c:1.1.1.2 Fri Nov 27 11:19:09 1998
+++ linux/kernel/sched.c Thu Dec 3 13:43:51 1998
@@ -91,10 +94,70 @@

void scheduling_functions_start_here(void) { }

-static inline void reschedule_idle(struct task_struct * p)
+/*
+ * This is the function that decides how desirable a process is..
+ * You can weigh different processes against each other depending
+ * on what CPU they've run on lately etc to try to handle cache
+ * and TLB miss penalties.
+ *
+ * Return values:
+ * -1000: never select this
+ * 0: out of time, recalculate counters (but it might still be
+ * selected)
+ * +ve: "goodness" value (the larger, the better)
+ * +1000: realtime process, select this.
+ */
+static int FASTCALL(goodness(struct task_struct * p,
+ struct task_struct * prev, int this_cpu));
+static int goodness(struct task_struct * p,
+ struct task_struct * prev, int this_cpu)
{
+ int policy = p->policy;
+ int weight;

+ if (policy & SCHED_YIELD) {
+ p->policy = policy & ~SCHED_YIELD;
+ return 0;
+ }
+
+ /*
+ * Realtime process, select the first one on the
+ * runqueue (taking priorities within processes
+ * into account).
+ */
+ if (policy != SCHED_OTHER)
+ return 1000 + p->rt_priority;
+
/*
+ * Give the process a first-approximation goodness value
+ * according to the number of clock-ticks it has left.
+ *
+ * Don't do any other calculations if the time slice is
+ * over..
+ */
+ weight = p->counter;
+ if (weight) {
+
+#ifdef __SMP__
+ /* Give a largish advantage to the same processor... */
+ /* (this is equivalent to penalizing other processors) */
+ if (p->processor == this_cpu)
+ weight += PROC_CHANGE_PENALTY;
+#endif
+
+ /* .. and a slight advantage to the current thread */
+ if (p->mm == prev->mm)
+ weight += 1;
+ weight += p->priority;
+ }
+
+ return weight;
+}
+
+static inline void reschedule_idle(struct task_struct * p)
+{
+ struct task_struct * this = current;
+ /*
* For SMP, we try to see if the CPU the task used
* to run on is idle..
*/
@@ -130,8 +193,10 @@
}
#endif
#endif
- if (p->policy != SCHED_OTHER || p->counter > current->counter + 3)
- current->need_resched = 1;
+ if (goodness(p, this, this->processor) >
+ goodness(this, this, this->processor) + 3 ||
+ p->policy != SCHED_OTHER)
+ current->need_resched = 1;
}

/*
@@ -240,63 +305,6 @@
}

/*
- * This is the function that decides how desirable a process is..
- * You can weigh different processes against each other depending
- * on what CPU they've run on lately etc to try to handle cache
- * and TLB miss penalties.
- *
- * Return values:
- * -1000: never select this
- * 0: out of time, recalculate counters (but it might still be
- * selected)
- * +ve: "goodness" value (the larger, the better)
- * +1000: realtime process, select this.
- */
-static inline int goodness(struct task_struct * p, struct task_struct * prev, int this_cpu)
-{
- int policy = p->policy;
- int weight;
-
- if (policy & SCHED_YIELD) {
- p->policy = policy & ~SCHED_YIELD;
- return 0;
- }
-
- /*
- * Realtime process, select the first one on the
- * runqueue (taking priorities within processes
- * into account).
- */
- if (policy != SCHED_OTHER)
- return 1000 + p->rt_priority;
-
- /*
- * Give the process a first-approximation goodness value
- * according to the number of clock-ticks it has left.
- *
- * Don't do any other calculations if the time slice is
- * over..
- */
- weight = p->counter;
- if (weight) {
-
-#ifdef __SMP__
- /* Give a largish advantage to the same processor... */
- /* (this is equivalent to penalizing other processors) */
- if (p->processor == this_cpu)
- weight += PROC_CHANGE_PENALTY;
-#endif
-
- /* .. and a slight advantage to the current thread */
- if (p->mm == prev->mm)
- weight += 1;
- weight += p->priority;
- }
-
- return weight;
-}
-
-/*
* Event timer code
*/
#define TVN_BITS 6

Andrea Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/