[Cbe-oss-dev] [RFC] [PATCH 4:8] SPU Gang Scheduling - Add gang structure for standalone ctxts

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


Add gang structure for standalone ctxts

All contexts should have a gang structure to provide a common
data abstraction for scheduling.  Standalone gangs are just gangs
of one. 

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

---

Index: spufs/arch/powerpc/platforms/cell/spufs/context.c
===================================================================
--- spufs.orig/arch/powerpc/platforms/cell/spufs/context.c	2008-02-29 22:22:47.000000000 -0300
+++ spufs/arch/powerpc/platforms/cell/spufs/context.c	2008-03-01 22:20:52.000000000 -0300
@@ -35,14 +35,30 @@
 struct spu_context *alloc_spu_context(struct spu_gang *gang)
 {
 	struct spu_context *ctx;
+	int n, nspus;
+
 	ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
 	if (!ctx)
 		goto out;
+
+	if (!gang) {
+		gang = alloc_spu_gang();
+		if (!gang)
+			goto out_free;
+	}
+
+	for (n = 0, nspus = 0; n < MAX_NUMNODES; n++)
+		nspus += cbe_spu_info[n].n_spus -
+			atomic_read(&cbe_spu_info[n].reserved_spus);
+	if (nspus < gang->contexts + 1)
+		goto out_free_gang;
+
 	/* Binding to physical processor deferred
 	 * until spu_activate().
 	 */
 	if (spu_init_csa(&ctx->csa))
-		goto out_free;
+		goto out_free_gang;
+
 	spin_lock_init(&ctx->mmio_lock);
 	mutex_init(&ctx->mapping_lock);
 	kref_init(&ctx->kref);
@@ -58,8 +74,7 @@
 	ctx->owner = get_task_mm(current);
 	INIT_LIST_HEAD(&ctx->rq);
 	INIT_LIST_HEAD(&ctx->aff_list);
-	if (gang)
-		spu_gang_add_ctx(gang, ctx);
+	spu_gang_add_ctx(gang, ctx);
 
 	__spu_update_sched_info(ctx);
 	spu_set_timeslice(ctx);
@@ -67,6 +82,9 @@
 
 	atomic_inc(&nr_spu_contexts);
 	goto out;
+
+out_free_gang:
+	kfree(gang);
 out_free:
 	kfree(ctx);
 	ctx = NULL;
@@ -76,14 +94,17 @@
 
 void destroy_spu_context(struct kref *kref)
 {
+	struct spu_gang *gang;
 	struct spu_context *ctx;
+
 	ctx = container_of(kref, struct spu_context, kref);
+	gang = ctx->gang;
+
 	mutex_lock(&ctx->state_mutex);
 	spu_deactivate(ctx);
 	mutex_unlock(&ctx->state_mutex);
 	spu_fini_csa(&ctx->csa);
-	if (ctx->gang)
-		spu_gang_remove_ctx(ctx->gang, ctx);
+	spu_gang_remove_ctx(gang, ctx);
 	if (ctx->prof_priv_kref)
 		kref_put(ctx->prof_priv_kref, ctx->prof_priv_release);
 	BUG_ON(!list_empty(&ctx->rq));





More information about the cbe-oss-dev mailing list