[Cbe-oss-dev] [PATCH] spusched: fix initial timeslice calculation

Christoph Hellwig hch at lst.de
Fri Jul 20 21:45:27 EST 2007


Currently we calculate the first timeslice for every context wrongly. 
alloc_spu_context calls spu_set_timeslice before we set ctx->prio so we
always calculate the longest possible timeslice for the lowest possible
priority.

This patch makes sure to update the schedule-related fields before
calculating the timeslice and also makes sure we update the timeslice for
a non-running context when entering spu_run so a priority change affects
the context as soon as possible.


Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: linux-cell/arch/powerpc/platforms/cell/spufs/context.c
===================================================================
--- linux-cell.orig/arch/powerpc/platforms/cell/spufs/context.c	2007-07-20 12:31:19.000000000 +0200
+++ linux-cell/arch/powerpc/platforms/cell/spufs/context.c	2007-07-20 12:31:46.000000000 +0200
@@ -59,7 +59,8 @@ struct spu_context *alloc_spu_context(st
 	INIT_LIST_HEAD(&ctx->aff_list);
 	if (gang)
 		spu_gang_add_ctx(gang, ctx);
-	ctx->cpus_allowed = current->cpus_allowed;
+
+	__spu_update_sched_info(ctx);
 	spu_set_timeslice(ctx);
 	ctx->stats.util_state = SPUCTX_UTIL_USER;
 
Index: linux-cell/arch/powerpc/platforms/cell/spufs/run.c
===================================================================
--- linux-cell.orig/arch/powerpc/platforms/cell/spufs/run.c	2007-07-20 12:31:19.000000000 +0200
+++ linux-cell/arch/powerpc/platforms/cell/spufs/run.c	2007-07-20 12:31:46.000000000 +0200
@@ -316,6 +316,7 @@ long spufs_run_spu(struct file *file, st
 	spu_acquire(ctx);
 	if (ctx->state == SPU_STATE_SAVED) {
 		__spu_update_sched_info(ctx);
+		spu_set_timeslice(ctx);
 
 		ret = spu_activate(ctx, 0);
 		if (ret) {
@@ -326,6 +327,9 @@ long spufs_run_spu(struct file *file, st
 		/*
 		 * We have to update the scheduling priority under active_mutex
 		 * to protect against find_victim().
+		 *
+		 * No need to update the timeslice ASAP, it will get updated once
+		 * the current one has expired.
 		 */
 		spu_update_sched_info(ctx);
 	}



More information about the cbe-oss-dev mailing list