[Cbe-oss-dev] [RFC] [PATCH 8:8] SPU Gang Scheduling - time slicing lazily loaded contexts

Luke Browning lukebr at linux.vnet.ibm.com
Tue Mar 4 06:50:12 EST 2008


Time slice lazily loaded contexts.

All SPUs are stopped.  All contexts are either executing library
code or they have major faulted in spu_run.

Signed-off-by: Luke Browning <lukebrowning at us.ibm.com>

---

Index: spufs/arch/powerpc/platforms/cell/spufs/sched.c
===================================================================
--- spufs.orig/arch/powerpc/platforms/cell/spufs/sched.c
+++ spufs/arch/powerpc/platforms/cell/spufs/sched.c
@@ -1150,7 +1150,7 @@ static noinline int spusched_tick(struct
 					struct spu_context *ctx,
 					int preempt)
 {
-	int best;
+	int best, yield;
 	int npreempted = 0;
 
 	if (test_bit(SPU_SCHED_DEACTIVATED, &gang->sched_flags))
@@ -1167,18 +1167,29 @@ static noinline int spusched_tick(struct
 	if (ctx->flags & SPU_CREATE_NOSCHED)
 		goto out;
 
-	if ((ctx->policy != SCHED_FIFO) && (!--ctx->time_slice)) {
-		best = find_first_bit(spu_prio->bitmap, gang->prio);
-		if (preempt && best <= gang->prio) {
-			spu_context_trace(spusched_tick__preempt,
+	/*
+	 * If nrunnable is zero, then all of the contexts are in user mode
+	 * and by definition nfaulting is zero.  Otherwise if they are
+	 * equal all of the contexts in spu_run have faulted.  In both cases,
+	 * there are no running spus.  Yield assuming there is a gang on rq.
+	 */
+	yield = atomic_read(&gang->nrunnable) == atomic_read(&gang->nfaulting);
+
+	if (yield || ((ctx->policy != SCHED_FIFO) && (!--ctx->time_slice))) {
+		if (spu_prio->nr_waiting) {
+			best = find_first_bit(spu_prio->bitmap, gang->prio);
+			if (yield || (preempt && best <= gang->prio)) {
+				spu_context_trace(spusched_tick__preempt,
 							ctx, ctx->spu);
-			npreempted = gang->contexts;
-			spu_unschedule(gang);
-			spu_add_to_rq(gang);
-		} else {
-			spu_context_nospu_trace(spusched_tick__newslice, ctx);
-			ctx->time_slice++;
+				npreempted = gang->contexts;
+				spu_unschedule(gang);
+				spu_add_to_rq(gang);
+				goto out;
+			}
 		}
+		spu_context_nospu_trace(spusched_tick__newslice, ctx);
+		if (ctx->policy != SCHED_FIFO)
+			ctx->time_slice++;
 	}
 out:
 	mutex_unlock(&gang->mutex);





More information about the cbe-oss-dev mailing list