From patchwork Thu Sep 18 02:52:46 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuji Mano X-Patchwork-Id: 483 X-Patchwork-Delegate: yuji.mano@am.sony.com 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 08C7BDDFCC for ; Thu, 18 Sep 2008 12:53:11 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from SG2EHSOBE001.bigfish.com (outbound-sin.frontbridge.com [207.46.51.80]) by ozlabs.org (Postfix) with ESMTP id 4440FDDEE2 for ; Thu, 18 Sep 2008 12:52:59 +1000 (EST) Received: from mail7-sin-R.bigfish.com (10.3.40.3) by SG2EHSOBE001.bigfish.com (10.3.40.21) with Microsoft SMTP Server id 8.1.291.1; Thu, 18 Sep 2008 02:52:54 +0000 Received: from mail7-sin (localhost.localdomain [127.0.0.1]) by mail7-sin-R.bigfish.com (Postfix) with ESMTP id 842E1E40078 for ; Thu, 18 Sep 2008 02:52:54 +0000 (UTC) X-BigFish: VS-5(zz936fQzz10c0j10d3izz1497iz2dh6bh67h) X-Spam-TCS-SCL: 6:0 Received: by mail7-sin (MessageSwitch) id 122170637115354_31339; Thu, 18 Sep 2008 02:52:51 +0000 (UCT) Received: from mail8.fw-bc.sony.com (mail8.fw-bc.sony.com [160.33.98.75]) by mail7-sin.bigfish.com (Postfix) with ESMTP id 54C9E1300053 for ; Thu, 18 Sep 2008 02:52:50 +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 m8I2qmuV017706 for ; Thu, 18 Sep 2008 02:52:48 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 m8I2qmqY026220 for ; Thu, 18 Sep 2008 02:52:48 GMT Received: from ussdixms03.am.sony.com ([43.130.140.23]) by USSDIXIM01.am.sony.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 17 Sep 2008 19:52:47 -0700 Received: from [43.135.148.175] ([43.135.148.175]) by ussdixms03.am.sony.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 17 Sep 2008 19:52:47 -0700 Message-ID: <48D1C27E.4030404@am.sony.com> Date: Wed, 17 Sep 2008 19:52:46 -0700 From: Yuji Mano User-Agent: Thunderbird 2.0.0.5 (X11/20070719) MIME-Version: 1.0 To: CBE Development References: <48C972DF.4080409@am.sony.com> In-Reply-To: <48C972DF.4080409@am.sony.com> X-Enigmail-Version: 0.95.7 X-OriginalArrivalTime: 18 Sep 2008 02:52:47.0396 (UTC) FILETIME=[A1BA9640:01C91939] X-SEL-encryption-scan: scanned Subject: [Cbe-oss-dev] [PATCH 07/11 v4]MARS: Remove api argument params structs 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 This removes the mars_params and mars_task_params structure previously passed into the mars context and mars task APIs. Parameter arguments are now passed in directly. Signed-off-by: Yuji Mano Acked-by: Kazunori Asayama --- a/include/host/mars/mars_context.h +++ b/include/host/mars/mars_context.h @@ -44,32 +44,17 @@ * \brief [host] MARS Context API */ +#include #include /** * \ingroup group_mars_context - * \brief MARS params structure - * - * This structure is initialized by the user and passed into - * \ref mars_initialize for MARS context initialization. - */ -struct mars_params { - /** number of mpus utilized by each MARS context - * [between 0 and maximum available physical MPUs] - */ - unsigned int num_mpus; -}; - -/** - * \ingroup group_mars_context * \brief MARS context structure * * An instance of this structure must be created and initialized before * using any of the MARS API. */ struct mars_context { - /* parameters for the MARS context */ - struct mars_params *params; /* parameters for the MARS kernel */ struct mars_kernel_params *kernel_params; /* process queue where process requests are added */ @@ -77,7 +62,7 @@ struct mars_context { /* array of mpu context threads */ pthread_t *mpu_context_threads; /* num of mpu context threads */ - unsigned int mpu_context_count; + uint32_t mpu_context_count; }; #if defined(__cplusplus) @@ -98,7 +83,7 @@ extern "C" { * each MARS context will suffer the large over head of MPU context switches. * * \param[out] ctx - address of context instance to initialize - * \param[in] params - pointer to MARS parameters structure + * \param[in] num_mpus - number of mpus utilized by MARS context * \return * MARS_SUCCESS - successfully initialized MARS context * \n MARS_ERROR_NULL - null pointer specified @@ -106,7 +91,7 @@ extern "C" { * \n MARS_ERROR_MEMORY - not enough memory * \n MARS_ERROR_INTERNAL - some internal error occurred */ -int mars_initialize(struct mars_context *ctx, struct mars_params *params); +int mars_initialize(struct mars_context *ctx, uint32_t num_mpus); /** * \ingroup group_mars_context --- a/include/host/mars/mars_task.h +++ b/include/host/mars/mars_task.h @@ -55,24 +55,6 @@ extern "C" { #include "mars/mars_task_signal.h" #include "mars/mars_task_types.h" -struct mars_context; -struct mars_exec_context; - -/** - * \ingroup group_mars_task - * \brief MARS task params structure - * - * This structure is initialized by the user and passed into - * \ref mars_task_initialize for MARS task initialization. - */ -struct mars_task_params { - /** name of task */ - const char *name; - /** address of MPU program elf image */ - const void *elf_image; - /** size of context save area allocated for task */ - uint32_t context_save_size; -}; /** * \ingroup group_mars_task @@ -87,8 +69,7 @@ struct mars_task_params { * The task is in the finished state upon creation and may be finalized by * \ref mars_task_finalize without ever being scheduled for execution. * - * When initializing a MARS task, you must specify its parameters through the - * \ref mars_task_params structure: + * When initializing a MARS task, you must specify its parameters: * \n * - \e name: The name is optional, but if specified to other than NULL its * length must not exceed \ref MARS_TASK_NAME_LEN_MAX. @@ -107,7 +88,9 @@ struct mars_task_params { * * \param[in] mars - pointer to initialized MARS context * \param[out] id - pointer to task id to be initialized - * \param[in] params - pointer to task params of this task + * \param[in] name - name of task + * \param[in] elf_image - address of MPU program elf image + * \param[in] context_save_size - size of context save area allocated for task * \return * MARS_SUCCESS - successfully initialized MARS task * \n MARS_ERROR_NULL - null pointer specified @@ -115,8 +98,11 @@ struct mars_task_params { * \n MARS_ERROR_MEMORY - not enough memory * \n MARS_ERROR_LIMIT - task queue is currently full */ -int mars_task_initialize(struct mars_context *mars, struct mars_task_id *id, - struct mars_task_params *params); +int mars_task_initialize(struct mars_context *mars, + struct mars_task_id *id, + const char *name, + const void *elf_image, + uint32_t context_save_size); /** * \ingroup group_mars_task --- a/src/host/lib/mars_context.c +++ b/src/host/lib/mars_context.c @@ -48,11 +48,6 @@ extern struct spe_program_handle mars_kernel_entry; -static int num_mpus_max(void) -{ - return spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); -} - static void *mpu_context_thread(void *arg) { MARS_ASSERT(arg); @@ -77,7 +72,7 @@ static void *mpu_context_thread(void *ar return (void *)MARS_SUCCESS; } -static int create_mpu_contexts(struct mars_context *mars, int num_mpu_contexts) +static int create_mpu_contexts(struct mars_context *mars, uint32_t num_mpus) { MARS_ASSERT(mars); @@ -85,7 +80,7 @@ static int create_mpu_contexts(struct ma unsigned int i; /* create threads for each mpu context */ - for (i = 0; i < num_mpu_contexts; i++) { + for (i = 0; i < num_mpus; i++) { struct mars_kernel_params *params = &mars->kernel_params[i]; params->id = i; params->mars_context_ea = @@ -120,39 +115,31 @@ static int destroy_mpu_contexts(struct m return MARS_SUCCESS; } -int mars_initialize(struct mars_context *mars, struct mars_params *params) +int mars_initialize(struct mars_context *mars, uint32_t num_mpus) { MARS_CHECK_RET(mars, MARS_ERROR_NULL); MARS_PRINT("Initialize MARS Context (%p)\n", mars); int ret; - unsigned int num_mpu_contexts; + int num_mpus_max; + + /* check max available mpus */ + num_mpus_max = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1); + MARS_CHECK_RET(num_mpus_max > 0, MARS_ERROR_INTERNAL); + MARS_CHECK_RET(num_mpus_max >= (int)num_mpus, MARS_ERROR_PARAMS); + + /* num mpus specified is default max */ + if (!num_mpus) + num_mpus = num_mpus_max; /* zero context */ memset(mars, 0, sizeof(struct mars_context)); - /* allocate and initialize params */ - if (params) { - MARS_CHECK_RET(params->num_mpus <= num_mpus_max(), - MARS_ERROR_PARAMS); - - mars->params = (struct mars_params *) - malloc(sizeof(struct mars_params)); - MARS_CHECK_RET(mars->params, MARS_ERROR_MEMORY); - memcpy(mars->params, params, sizeof(struct mars_params)); - - num_mpu_contexts = mars->params->num_mpus; - } else { - mars->params = NULL; - - num_mpu_contexts = num_mpus_max(); - } - /* allocate kernel params */ mars->kernel_params = (struct mars_kernel_params *) memalign(MARS_KERNEL_PARAMS_ALIGN, - sizeof(struct mars_kernel_params) * num_mpu_contexts); + sizeof(struct mars_kernel_params) * num_mpus); MARS_CHECK_CLEANUP_RET(mars->kernel_params, mars_finalize(mars), MARS_ERROR_MEMORY); @@ -169,12 +156,12 @@ int mars_initialize(struct mars_context /* allocate mpu context thread array */ mars->mpu_context_threads = (pthread_t *) - malloc(sizeof(pthread_t) * num_mpu_contexts); + malloc(sizeof(pthread_t) * num_mpus); MARS_CHECK_CLEANUP_RET(mars->mpu_context_threads, mars_finalize(mars), MARS_ERROR_MEMORY); /* create contexts */ - ret = create_mpu_contexts(mars, num_mpu_contexts); + ret = create_mpu_contexts(mars, num_mpus); MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret); return MARS_SUCCESS; @@ -199,7 +186,6 @@ int mars_finalize(struct mars_context *m } /* free allocated memory */ - free(mars->params); free(mars->kernel_params); free(mars->workload_queue); free(mars->mpu_context_threads); --- a/src/host/lib/mars_task.c +++ b/src/host/lib/mars_task.c @@ -45,17 +45,23 @@ #include "mars/mars_error.h" #include "mars/mars_debug.h" -int mars_task_initialize(struct mars_context *mars, struct mars_task_id *id, - struct mars_task_params *params) +int mars_task_initialize(struct mars_context *mars, + struct mars_task_id *id, + const char *name, + const void *elf_image, + uint32_t context_save_size) { MARS_CHECK_RET(mars, MARS_ERROR_NULL); MARS_CHECK_RET(id, MARS_ERROR_NULL); - MARS_CHECK_RET(params, MARS_ERROR_NULL); - MARS_CHECK_RET(params->elf_image, MARS_ERROR_PARAMS); + MARS_CHECK_RET(elf_image, MARS_ERROR_NULL); + MARS_CHECK_RET(!name || strlen(name) < MARS_TASK_NAME_LEN_MAX, + MARS_ERROR_PARAMS); + MARS_CHECK_RET(context_save_size <= MARS_TASK_CONTEXT_SAVE_SIZE_MAX, + MARS_ERROR_PARAMS); int ret; struct mars_task_context *task; - Elf32_Ehdr *ehdr = (Elf32_Ehdr *)params->elf_image; + Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elf_image; Elf32_Phdr *phdr = (Elf32_Phdr *)((void *)ehdr + ehdr->e_phoff); //MARS_CHECK_RET(ehdr->e_phnum == 1, MARS_ERROR_FORMAT); @@ -67,11 +73,8 @@ int mars_task_initialize(struct mars_con id->mars_context_ea = (uint64_t)(uintptr_t)mars; /* copy the task name into task id */ - if (params->name) { - MARS_CHECK_RET(strlen(params->name) < MARS_TASK_NAME_LEN_MAX, - MARS_ERROR_PARAMS); - strcpy((char *)&id->name, params->name); - } + if (name) + strcpy((char *)&id->name, name); /* begin process to add the task to the workload queue */ ret = workload_queue_add_begin(mars->workload_queue, &id->workload_id, @@ -90,15 +93,8 @@ int mars_task_initialize(struct mars_con task->entry = ehdr->e_entry; /* allocate the task context area if specified */ - if (params->context_save_size) { - MARS_CHECK_CLEANUP_RET(params->context_save_size <= - MARS_TASK_CONTEXT_SAVE_SIZE_MAX, - workload_queue_add_cancel(mars->workload_queue, - id->workload_id), - MARS_ERROR_PARAMS); - - task->context_save_size = - params->context_save_size; + if (context_save_size) { + task->context_save_size = context_save_size; task->context_save_area = (uint64_t)(uintptr_t) memalign(MARS_TASK_CONTEXT_SAVE_ALIGN, task->context_save_size);