From patchwork Wed Dec 10 19:40:45 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Detsch X-Patchwork-Id: 13320 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 528C0474E5 for ; Thu, 11 Dec 2008 06:47:27 +1100 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from igw3.br.ibm.com (igw3.br.ibm.com [32.104.18.26]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "igw3.br.ibm.com", Issuer "Equifax" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id E6903DDF9E for ; Thu, 11 Dec 2008 06:40:57 +1100 (EST) Received: from d24relay01.br.ibm.com (unknown [9.8.31.16]) by igw3.br.ibm.com (Postfix) with ESMTP id EBA45390290 for ; Wed, 10 Dec 2008 17:37:19 -0200 (BRDT) Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by d24relay01.br.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id mBAKeNnT3604600 for ; Wed, 10 Dec 2008 17:40:23 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id mBAJen3M017570 for ; Wed, 10 Dec 2008 17:40:49 -0200 Received: from [9.8.13.23] ([9.8.13.23]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id mBAJegsa017084 for ; Wed, 10 Dec 2008 17:40:47 -0200 From: Andre Detsch To: cbe-oss-dev@ozlabs.org Date: Wed, 10 Dec 2008 17:40:45 -0200 User-Agent: KMail/1.9.6 References: <200812101719.42964.adetsch@br.ibm.com> In-Reply-To: <200812101719.42964.adetsch@br.ibm.com> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200812101740.46064.adetsch@br.ibm.com> Subject: [Cbe-oss-dev] [PATCH 14/18] powerpc/spufs: Fix gang deactivation when gang grows or shrinks X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org The gang deactivation must be done in the same critical section as the list_add/list_del operation, otherwise there is no guarantee that the grow/shrink is correctly done. Signed-off-by: Andre Detsch --- arch/powerpc/platforms/cell/spufs/context.c | 19 ------------------- arch/powerpc/platforms/cell/spufs/gang.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/platforms/cell/spufs/context.c b/arch/powerpc/platforms/cell/spufs/context.c index 0e37eff..ef81894 100644 --- a/arch/powerpc/platforms/cell/spufs/context.c +++ b/arch/powerpc/platforms/cell/spufs/context.c @@ -79,17 +79,6 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang) inc_active_gangs(gang); - /* If the gang is running, it needs to be stopped, since we have a - * new context that needs to be gang scheduled. Gangs are allowed - * to grow and shrink over time, but they are unscheduled when it - * happens as the gang may need to migrated to a different node. - */ - if (atomic_read(&gang->nstarted)) { - mutex_lock(&gang->mutex); - spu_deactivate(gang); - mutex_unlock(&gang->mutex); - } - spin_lock_init(&ctx->mmio_lock); mutex_init(&ctx->mapping_lock); kref_init(&ctx->kref); @@ -141,14 +130,6 @@ void destroy_spu_context(struct kref *kref) spu_context_nospu_trace(destroy_spu_context__enter, ctx); - /* - * Deactivate and make it non-runnable while we work on it. - */ - mutex_lock(&gang->mutex); - WARN_ON(ctx->gang != gang); - spu_deactivate(gang); - mutex_unlock(&gang->mutex); - spu_fini_csa(&ctx->csa); spu_gang_remove_ctx(ctx->gang, ctx); if (ctx->prof_priv_kref) diff --git a/arch/powerpc/platforms/cell/spufs/gang.c b/arch/powerpc/platforms/cell/spufs/gang.c index 7b1513d..7e9ab01 100644 --- a/arch/powerpc/platforms/cell/spufs/gang.c +++ b/arch/powerpc/platforms/cell/spufs/gang.c @@ -90,6 +90,15 @@ int put_spu_gang(struct spu_gang *gang) void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx) { mutex_lock(&gang->mutex); + /* + * If the gang is running, it needs to be stopped, since we have a + * new context that needs to be gang scheduled. Gangs are allowed + * to grow and shrink over time, but they are unscheduled when it + * happens as the gang may need to migrated to a different node. + */ + if (atomic_read(&gang->nstarted)) + spu_deactivate(gang); + ctx->gang = get_spu_gang(gang); list_add(&ctx->gang_list, &gang->list); gang->contexts++; @@ -115,7 +124,9 @@ void update_gang_stats(struct spu_gang *gang, struct spu_context *ctx) void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx) { mutex_lock(&gang->mutex); + /* Deactivate and make it non-runnable while we work on it. */ WARN_ON(ctx->gang != gang); + spu_deactivate(gang); if (!list_empty(&ctx->aff_list)) { list_del_init(&ctx->aff_list); gang->aff_flags &= ~AFF_OFFSETS_SET;