From patchwork Thu Sep 11 19:34:59 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuji Mano X-Patchwork-Id: 242 X-Patchwork-Delegate: yuji.mano@am.sony.com Return-Path: X-Original-To: patchwork@ozlabs.org Delivered-To: patchwork@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 19FBADE8DD for ; Fri, 12 Sep 2008 06:38:32 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from VA3EHSOBE004.bigfish.com (outbound-va3.frontbridge.com [216.32.180.16]) by ozlabs.org (Postfix) with ESMTP id 49D15DE31A for ; Fri, 12 Sep 2008 06:37:16 +1000 (EST) Received: from mail161-va3-R.bigfish.com (10.7.14.254) by VA3EHSOBE004.bigfish.com (10.7.40.24) with Microsoft SMTP Server id 8.1.291.1; Thu, 11 Sep 2008 20:37:12 +0000 Received: from mail161-va3 (localhost.localdomain [127.0.0.1]) by mail161-va3-R.bigfish.com (Postfix) with ESMTP id F405B7909E7 for ; Thu, 11 Sep 2008 20:37:12 +0000 (UTC) X-BigFish: VS-10(zz3166M936fQzz10c0j10d3izz1497iz2dh6bh62h) X-Spam-TCS-SCL: 1:0 X-FB-SS: 5, Received: by mail161-va3 (MessageSwitch) id 1221165430844719_7667; Thu, 11 Sep 2008 20:37:10 +0000 (UCT) Received: from mail8.fw-bc.sony.com (mail8.fw-bc.sony.com [160.33.98.75]) by mail161-va3.bigfish.com (Postfix) with ESMTP id B96CB510054 for ; Thu, 11 Sep 2008 20:37:10 +0000 (UTC) Received: from mail3.sjc.in.sel.sony.com (mail3.sjc.in.sel.sony.com [43.134.1.211]) by mail8.fw-bc.sony.com (8.14.2/8.14.2) with ESMTP id m8BKbA1o025079 for ; Thu, 11 Sep 2008 20:37:10 GMT Received: from USSDIXIM01.am.sony.com (ussdixim01.am.sony.com [43.130.140.33]) by mail3.sjc.in.sel.sony.com (8.12.11/8.12.11) with ESMTP id m8BKb9gO021764 for ; Thu, 11 Sep 2008 20:37:09 GMT Received: from ussdixms03.am.sony.com ([43.130.140.23]) by USSDIXIM01.am.sony.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 11 Sep 2008 13:37:09 -0700 Received: from [43.135.148.175] ([43.135.148.175]) by ussdixms03.am.sony.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 11 Sep 2008 13:37:09 -0700 Message-ID: <48C972E3.7040507@am.sony.com> Date: Thu, 11 Sep 2008 12:34:59 -0700 From: Yuji Mano User-Agent: Thunderbird 2.0.0.5 (X11/20070719) MIME-Version: 1.0 To: CBE Development X-Enigmail-Version: 0.95.7 X-OriginalArrivalTime: 11 Sep 2008 20:37:09.0194 (UTC) FILETIME=[296F62A0:01C9144E] X-SEL-encryption-scan: scanned Subject: [Cbe-oss-dev] [PATCH 08/11]MARS: Workload queue api add set flag 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=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org This adds a new internal API workload_queue_exit that sets the exit flag inside the workload queue header. Previously this was done inside the workload_queue_finalize function, but since the MARS context must first join all mpu context threads before finalizing the workload queue, a separate function to set the exit flag for those threads is required. Signed-off-by: Yuji Mano Acked-by: Kazunori Asayama --- a/include/common/mars/mars_kernel_types.h +++ b/include/common/mars/mars_kernel_types.h @@ -44,9 +44,6 @@ extern "C" { #include -#define MARS_FLAG_NONE 0x0 -#define MARS_FLAG_EXIT 0x1 - #define MARS_KERNEL_PARAMS_ALIGN 128 /* mars kernel parameters */ --- a/include/common/mars/mars_workload_types.h +++ b/include/common/mars/mars_workload_types.h @@ -64,8 +64,8 @@ extern "C" { #define MARS_WORKLOAD_COUNTER_MIN 0x0000 /* minimum counter */ #define MARS_WORKLOAD_COUNTER_MAX 0xffff /* maximum counter */ -#define MARS_WORKLOAD_SIGNAL_ON 0x1 /* signal set on */ #define MARS_WORKLOAD_SIGNAL_OFF 0x0 /* signal set off */ +#define MARS_WORKLOAD_SIGNAL_ON 0x1 /* signal set on */ #define MARS_WORKLOAD_PER_BLOCK 15 /* wl/block */ #define MARS_WORKLOAD_NUM_BLOCKS 100 /* total blocks */ @@ -73,10 +73,14 @@ extern "C" { #define MARS_WORKLOAD_CONTEXT_SIZE 128 /* size of 128 bytes */ #define MARS_WORKLOAD_CONTEXT_ALIGN 128 /* align to 128 bytes */ + #define MARS_WORKLOAD_QUEUE_ALIGN 128 /* align to 128 bytes */ #define MARS_WORKLOAD_QUEUE_HEADER_ALIGN 128 /* align to 128 bytes */ #define MARS_WORKLOAD_QUEUE_BLOCK_ALIGN 128 /* align to 128 bytes */ +#define MARS_WORKLOAD_QUEUE_FLAG_NONE 0x0 /* no flag set */ +#define MARS_WORKLOAD_QUEUE_FLAG_EXIT 0x1 /* exit flag */ + /* * MARS workload queue block bits * ---------------------------------------------------------------------------- --- a/include/host/mars/mars_workload_queue.h +++ b/include/host/mars/mars_workload_queue.h @@ -46,6 +46,7 @@ extern "C" { int workload_queue_initialize(struct mars_workload_queue *queue); int workload_queue_finalize(struct mars_workload_queue *queue); +int workload_queue_exit(struct mars_workload_queue *queue); int workload_queue_add_begin(struct mars_workload_queue *queue, uint16_t *id, uint8_t type, --- a/src/host/lib/mars_context.c +++ b/src/host/lib/mars_context.c @@ -116,6 +116,10 @@ static int destroy_mpu_contexts(struct m void *p_ret; unsigned int i; + /* shutdown the workload queue so mpu context threads exit */ + ret = workload_queue_exit(mars->workload_queue); + MARS_CHECK_RET(ret == MARS_SUCCESS, ret); + /* join all mpu context threads */ for (i = 0; i < mars->mpu_context_count; i++) { ret = pthread_join(mars->mpu_context_threads[i], &p_ret); @@ -155,16 +159,16 @@ int mars_initialize(struct mars_context MARS_CHECK_CLEANUP_RET(mars->workload_queue, mars_finalize(mars), MARS_ERROR_MEMORY); - /* initialize workload queue */ - ret = workload_queue_initialize(mars->workload_queue); - MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret); - /* allocate mpu context thread array */ mars->mpu_context_threads = (pthread_t *) malloc(sizeof(pthread_t) * num_mpus); MARS_CHECK_CLEANUP_RET(mars->mpu_context_threads, mars_finalize(mars), MARS_ERROR_MEMORY); + /* initialize workload queue */ + ret = workload_queue_initialize(mars->workload_queue); + MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret); + /* create contexts */ ret = create_mpu_contexts(mars, num_mpus); MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret); @@ -178,22 +182,22 @@ int mars_finalize(struct mars_context *m int ret; - /* finalize workload queue */ - if (mars->workload_queue) { - ret = workload_queue_finalize(mars->workload_queue); - MARS_CHECK_RET(ret == MARS_SUCCESS, ret); - } - /* destroy contexts */ if (mars->mpu_context_count) { ret = destroy_mpu_contexts(mars); MARS_CHECK_RET(ret == MARS_SUCCESS, ret); } + /* finalize workload queue */ + if (mars->workload_queue) { + ret = workload_queue_finalize(mars->workload_queue); + MARS_CHECK_RET(ret == MARS_SUCCESS, ret); + } + /* free allocated memory */ - free(mars->kernel_params); - free(mars->workload_queue); free(mars->mpu_context_threads); + free(mars->workload_queue); + free(mars->kernel_params); /* zero context */ memset(mars, 0, sizeof(struct mars_context)); --- a/src/host/lib/mars_workload_queue.c +++ b/src/host/lib/mars_workload_queue.c @@ -51,9 +51,9 @@ int workload_queue_initialize(struct mar int block; int index; + queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_NONE; queue->header.queue_ea = (uint64_t)(uintptr_t)queue; queue->header.context_ea = (uint64_t)(uintptr_t)&queue->context; - queue->header.flag = MARS_FLAG_NONE; /* initialize workload queue blocks */ for (block = 0; block < MARS_WORKLOAD_NUM_BLOCKS; block++) { @@ -109,7 +109,14 @@ int workload_queue_finalize(struct mars_ /* found some task left in workload queue */ MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_STATE); - queue->header.flag = MARS_FLAG_EXIT; + return MARS_SUCCESS; +} + +int workload_queue_exit(struct mars_workload_queue *queue) +{ + MARS_CHECK_RET(queue, MARS_ERROR_NULL); + + queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_EXIT; return MARS_SUCCESS; } --- a/src/mpu/kernel/mars_kernel_scheduler.c +++ b/src/mpu/kernel/mars_kernel_scheduler.c @@ -244,7 +244,7 @@ int scheduler(void) MARS_DMA_TAG); /* return exit status if exit flag is set from host */ - if (queue_header.flag == MARS_FLAG_EXIT) + if (queue_header.flag == MARS_WORKLOAD_QUEUE_FLAG_EXIT) return MARS_KERNEL_STATUS_EXIT; /* reserve next workload to run or return idle status if none found */