get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/246/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 246,
    "url": "http://patchwork.ozlabs.org/api/patches/246/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/cbe-oss-dev/patch/48C972C9.9040106@am.sony.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.ozlabs.org/api/projects/1/?format=api",
        "name": "Cell Broadband Engine development",
        "link_name": "cbe-oss-dev",
        "list_id": "cbe-oss-dev.ozlabs.org",
        "list_email": "cbe-oss-dev@ozlabs.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<48C972C9.9040106@am.sony.com>",
    "list_archive_url": null,
    "date": "2008-09-11T19:34:33",
    "name": "MARS: Add mars context header source",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "fc2b217879caaa02f17e486d0c056b0209fa614e",
    "submitter": {
        "id": 127,
        "url": "http://patchwork.ozlabs.org/api/people/127/?format=api",
        "name": "Yuji Mano",
        "email": "yuji.mano@am.sony.com"
    },
    "delegate": {
        "id": 26,
        "url": "http://patchwork.ozlabs.org/api/users/26/?format=api",
        "username": "ymano",
        "first_name": "Yuji",
        "last_name": "Mano",
        "email": "yuji.mano@am.sony.com"
    },
    "mbox": "http://patchwork.ozlabs.org/project/cbe-oss-dev/patch/48C972C9.9040106@am.sony.com/mbox/",
    "series": [],
    "comments": "http://patchwork.ozlabs.org/api/patches/246/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/246/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org>",
        "X-Original-To": [
            "patchwork@ozlabs.org",
            "cbe-oss-dev@ozlabs.org"
        ],
        "Delivered-To": [
            "patchwork@ozlabs.org",
            "cbe-oss-dev@ozlabs.org"
        ],
        "Received": [
            "from ozlabs.org (localhost [127.0.0.1])\n\tby ozlabs.org (Postfix) with ESMTP id 6071CDEA90\n\tfor <patchwork@ozlabs.org>; Fri, 12 Sep 2008 06:39:26 +1000 (EST)",
            "from IE1EHSOBE003.bigfish.com (outbound-dub.frontbridge.com\n\t[213.199.154.16]) by ozlabs.org (Postfix) with ESMTP id 43712DE365\n\tfor <cbe-oss-dev@ozlabs.org>; Fri, 12 Sep 2008 06:37:22 +1000 (EST)",
            "from mail15-dub-R.bigfish.com (10.5.252.3) by\n\tIE1EHSOBE003.bigfish.com (10.5.252.23) with Microsoft SMTP Server id\n\t8.1.291.1; Thu, 11 Sep 2008 20:37:17 +0000",
            "from mail15-dub (localhost.localdomain [127.0.0.1])\tby\n\tmail15-dub-R.bigfish.com (Postfix) with ESMTP id 81B1811D013F\tfor\n\t<cbe-oss-dev@ozlabs.org>; Thu, 11 Sep 2008 20:37:17 +0000 (UTC)",
            "by mail15-dub (MessageSwitch) id 1221165429362158_10488;\n\tThu, 11 Sep 2008 20:37:09 +0000 (UCT)",
            "from mail8.fw-sd.sony.com (mail8.fw-sd.sony.com [160.33.66.75])\tby\n\tmail15-dub.bigfish.com (Postfix) with ESMTP id C3FF91A5009B\tfor\n\t<cbe-oss-dev@ozlabs.org>; Thu, 11 Sep 2008 20:37:07 +0000 (UTC)",
            "from mail3.sjc.in.sel.sony.com (mail3.sjc.in.sel.sony.com\n\t[43.134.1.211])\tby mail8.fw-sd.sony.com (8.14.2/8.14.2) with ESMTP id\n\tm8BKb6gi021119\tfor <cbe-oss-dev@ozlabs.org>;\n\tThu, 11 Sep 2008 20:37:06 GMT",
            "from USSDIXIM02.am.sony.com (ussdixim02.am.sony.com\n\t[43.130.140.34])\n\tby mail3.sjc.in.sel.sony.com (8.12.11/8.12.11) with ESMTP id\n\tm8BKb6tS021717\n\tfor <cbe-oss-dev@ozlabs.org>; Thu, 11 Sep 2008 20:37:06 GMT",
            "from ussdixms03.am.sony.com ([43.130.140.23]) by\n\tUSSDIXIM02.am.sony.com with Microsoft SMTPSVC(5.0.2195.6713);\n\tThu, 11 Sep 2008 13:37:06 -0700",
            "from [43.135.148.175] ([43.135.148.175]) by ussdixms03.am.sony.com\n\twith Microsoft SMTPSVC(5.0.2195.6713);\n\tThu, 11 Sep 2008 13:37:05 -0700"
        ],
        "X-BigFish": "VS-4(zz541L936fQ34f5jzz10c0j10d3izz2b68k1497iz2dh6bh61h)",
        "X-Spam-TCS-SCL": "0:0",
        "Message-ID": "<48C972C9.9040106@am.sony.com>",
        "Date": "Thu, 11 Sep 2008 12:34:33 -0700",
        "From": "Yuji Mano <yuji.mano@am.sony.com>",
        "User-Agent": "Thunderbird 2.0.0.5 (X11/20070719)",
        "MIME-Version": "1.0",
        "To": "CBE Development <cbe-oss-dev@ozlabs.org>",
        "X-Enigmail-Version": "0.95.7",
        "X-OriginalArrivalTime": "11 Sep 2008 20:37:05.0850 (UTC)\n\tFILETIME=[277121A0:01C9144E]",
        "X-SEL-encryption-scan": "scanned",
        "Subject": "[Cbe-oss-dev] [PATCH 03/11]MARS: Add mars context header source",
        "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\n\t<cbe-oss-dev.ozlabs.org>",
        "List-Unsubscribe": "<https://ozlabs.org/mailman/options/cbe-oss-dev>,\n\t<mailto:cbe-oss-dev-request@ozlabs.org?subject=unsubscribe>",
        "List-Archive": "<http://ozlabs.org/pipermail/cbe-oss-dev>",
        "List-Post": "<mailto:cbe-oss-dev@ozlabs.org>",
        "List-Help": "<mailto:cbe-oss-dev-request@ozlabs.org?subject=help>",
        "List-Subscribe": "<https://ozlabs.org/mailman/listinfo/cbe-oss-dev>,\n\t<mailto:cbe-oss-dev-request@ozlabs.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Sender": "cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org",
        "Errors-To": "cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org"
    },
    "content": "This adds a new header specifically for all MARS context types and API for the\nhost-side library, and removes them from the general \"mars/mars.h\" header.\n\nSigned-off-by: Yuji Mano <yuji.mano@am.sony.com>",
    "diff": "--- a/include/Makefile.am\n+++ b/include/Makefile.am\n@@ -50,6 +50,7 @@ host_HEADERS = \\\n \tcommon/mars/mars_task_queue_types.h \\\n \tcommon/mars/mars_task_semaphore_types.h \\\n \thost/mars/mars.h \\\n+\thost/mars/mars_context.h \\\n \thost/mars/mars_mutex.h \\\n \thost/mars/mars_task.h \\\n \thost/mars/mars_task_barrier.h \\\n--- a/include/host/mars/mars.h\n+++ b/include/host/mars/mars.h\n@@ -44,92 +44,9 @@\n  * \\brief [host] MARS API\n  */\n \n-#if defined(__cplusplus)\n-extern \"C\" {\n-#endif\n-\n-#include <pthread.h>\n+#include \"mars/mars_context.h\"\n #include \"mars/mars_error.h\"\n #include \"mars/mars_mutex.h\"\n #include \"mars/mars_task.h\"\n \n-/**\n- * \\ingroup group_mars_context\n- * \\brief MARS params structure\n- *\n- * This structure is initialized by the user and passed into\n- * \\ref mars_initialize for MARS context initialization.\n- */\n-struct mars_params {\n-\t/** number of mpus utilized by each MARS context\n-\t * [between 0 and maximum available physical MPUs]\n-\t */\n-\tunsigned int num_mpus;\n-};\n-\n-/**\n- * \\ingroup group_mars_context\n- * \\brief MARS context structure\n- *\n- * An instance of this structure must be created and initialized before\n- * using any of the MARS API.\n- */\n-struct mars_context {\n-\t/* parameters for the MARS context */\n-\tstruct mars_params *params;\n-\t/* parameters for the MARS kernel */\n-\tstruct mars_kernel_params *kernel_params;\n-\t/* process queue where process requests are added */\n-\tstruct mars_workload_queue *workload_queue;\n-\t/* array of mpu context threads */\n-\tpthread_t *mpu_context_threads;\n-\t/* num of mpu context threads */\n-\tunsigned int mpu_context_count;\n-};\n-\n-/**\n- * \\ingroup group_mars_context\n- * \\brief [host] Initializes a single MARS context.\n- *\n- * This function initializes a single MARS context. A MARS context must be\n- * initialized before any of the MARS functionality can be used. This will\n- * create the MPU contexts that are each loaded with and run the MARS kernel.\n- * The MARS kernel on each MPU will continue to run until the MARS context\n- * is finalized through \\ref mars_finalize.\n- *\n- * \\note If there are multiple MARS contexts initialized in the system, then\n- * each MARS context will suffer the large over head of MPU context switches.\n- *\n- * \\param[out] ctx\t\t- address of context instance to initialize\n- * \\param[in] params\t\t- pointer to MARS parameters structure\n- * \\return\n- *\tMARS_SUCCESS\t\t- successfully initialized MARS context\n- * \\n\tMARS_ERROR_NULL\t\t- null pointer specified\n- * \\n\tMARS_ERROR_PARAMS\t- bad MARS params specified\n- * \\n\tMARS_ERROR_MEMORY\t- not enough memory\n- * \\n\tMARS_ERROR_INTERNAL\t- some internal error occurred\n- */\n-int mars_initialize(struct mars_context *ctx, struct mars_params *params);\n-\n-/**\n- * \\ingroup group_mars_context\n- * \\brief [host] Finalizes a single MARS context.\n- *\n- * This function finalizes a single MARS context that was previously\n- * initialized by \\ref mars_initialize. In order to successfully finalize\n- * a MARS context, all workloads added to the workload queue must be\n- * completed and finalized so that the workload queue is empty.\n- *\n- * \\param[in] ctx\t\t- address of context instance to finalize\n- * \\return\n- *\tMARS_SUCCESS\t\t- successfully finalized MARS context\n- * \\n\tMARS_ERROR_NULL\t\t- null pointer specified\n- * \\n\tMARS_ERROR_STATE\t- workload queue is not empty\n- */\n-int mars_finalize(struct mars_context *ctx);\n-\n-#if defined(__cplusplus)\n-}\n-#endif\n-\n #endif\n--- /dev/null\n+++ b/include/host/mars/mars_context.h\n@@ -0,0 +1,132 @@\n+/*\n+ * Copyright 2008 Sony Corporation of America\n+ *\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining\n+ * a copy of this Library and associated documentation files (the\n+ * \"Library\"), to deal in the Library without restriction, including\n+ * without limitation the rights to use, copy, modify, merge, publish,\n+ * distribute, sublicense, and/or sell copies of the Library, and to\n+ * permit persons to whom the Library is furnished to do so, subject to\n+ * the following conditions:\n+ *\n+ *  The above copyright notice and this permission notice shall be\n+ *  included in all copies or substantial portions of the Library.\n+ *\n+ *  If you modify the Library, you may copy and distribute your modified\n+ *  version of the Library in object code or as an executable provided\n+ *  that you also do one of the following:\n+ *\n+ *   Accompany the modified version of the Library with the complete\n+ *   corresponding machine-readable source code for the modified version\n+ *   of the Library; or,\n+ *\n+ *   Accompany the modified version of the Library with a written offer\n+ *   for a complete machine-readable copy of the corresponding source\n+ *   code of the modified version of the Library.\n+ *\n+ *\n+ * THE LIBRARY IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n+ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.\n+ */\n+\n+#ifndef MARS_CONTEXT_H\n+#define MARS_CONTEXT_H\n+\n+/**\n+ * \\file\n+ * \\ingroup group_mars_context\n+ * \\brief [host] MARS Context API\n+ */\n+\n+#include <pthread.h>\n+\n+/**\n+ * \\ingroup group_mars_context\n+ * \\brief MARS params structure\n+ *\n+ * This structure is initialized by the user and passed into\n+ * \\ref mars_initialize for MARS context initialization.\n+ */\n+struct mars_params {\n+\t/** number of mpus utilized by each MARS context\n+\t * [between 0 and maximum available physical MPUs]\n+\t */\n+\tunsigned int num_mpus;\n+};\n+\n+/**\n+ * \\ingroup group_mars_context\n+ * \\brief MARS context structure\n+ *\n+ * An instance of this structure must be created and initialized before\n+ * using any of the MARS API.\n+ */\n+struct mars_context {\n+\t/* parameters for the MARS context */\n+\tstruct mars_params *params;\n+\t/* parameters for the MARS kernel */\n+\tstruct mars_kernel_params *kernel_params;\n+\t/* process queue where process requests are added */\n+\tstruct mars_workload_queue *workload_queue;\n+\t/* array of mpu context threads */\n+\tpthread_t *mpu_context_threads;\n+\t/* num of mpu context threads */\n+\tunsigned int mpu_context_count;\n+};\n+\n+#if defined(__cplusplus)\n+extern \"C\" {\n+#endif\n+\n+/**\n+ * \\ingroup group_mars_context\n+ * \\brief [host] Initializes a single MARS context.\n+ *\n+ * This function initializes a single MARS context. A MARS context must be\n+ * initialized before any of the MARS functionality can be used. This will\n+ * create the MPU contexts that are each loaded with and run the MARS kernel.\n+ * The MARS kernel on each MPU will continue to run until the MARS context\n+ * is finalized through \\ref mars_finalize.\n+ *\n+ * \\note If there are multiple MARS contexts initialized in the system, then\n+ * each MARS context will suffer the large over head of MPU context switches.\n+ *\n+ * \\param[out] ctx\t\t- address of context instance to initialize\n+ * \\param[in] params\t\t- pointer to MARS parameters structure\n+ * \\return\n+ *\tMARS_SUCCESS\t\t- successfully initialized MARS context\n+ * \\n\tMARS_ERROR_NULL\t\t- null pointer specified\n+ * \\n\tMARS_ERROR_PARAMS\t- bad MARS params specified\n+ * \\n\tMARS_ERROR_MEMORY\t- not enough memory\n+ * \\n\tMARS_ERROR_INTERNAL\t- some internal error occurred\n+ */\n+int mars_initialize(struct mars_context *ctx, struct mars_params *params);\n+\n+/**\n+ * \\ingroup group_mars_context\n+ * \\brief [host] Finalizes a single MARS context.\n+ *\n+ * This function finalizes a single MARS context that was previously\n+ * initialized by \\ref mars_initialize. In order to successfully finalize\n+ * a MARS context, all workloads added to the workload queue must be\n+ * completed and finalized so that the workload queue is empty.\n+ *\n+ * \\param[in] ctx\t\t- address of context instance to finalize\n+ * \\return\n+ *\tMARS_SUCCESS\t\t- successfully finalized MARS context\n+ * \\n\tMARS_ERROR_NULL\t\t- null pointer specified\n+ * \\n\tMARS_ERROR_STATE\t- workload queue is not empty\n+ */\n+int mars_finalize(struct mars_context *ctx);\n+\n+#if defined(__cplusplus)\n+}\n+#endif\n+\n+#endif\n--- a/src/host/lib/Makefile.am\n+++ b/src/host/lib/Makefile.am\n@@ -69,7 +69,7 @@ libmars_la_LDFLAGS = \\\n \t-Wl,../../mpu/kernel/mars_kernel.eo\n \n libmars_la_SOURCES = \\\n-\tmars.c \\\n+\tmars_context.c \\\n \tmars_mutex.c \\\n \tmars_workload_queue.c \\\n \tmars_task.c \\\n--- a/src/host/lib/mars.c\n+++ /dev/null\n@@ -1,214 +0,0 @@\n-/*\n- * Copyright 2008 Sony Corporation of America\n- *\n- *\n- * Permission is hereby granted, free of charge, to any person obtaining\n- * a copy of this Library and associated documentation files (the\n- * \"Library\"), to deal in the Library without restriction, including\n- * without limitation the rights to use, copy, modify, merge, publish,\n- * distribute, sublicense, and/or sell copies of the Library, and to\n- * permit persons to whom the Library is furnished to do so, subject to\n- * the following conditions:\n- *\n- *  The above copyright notice and this permission notice shall be\n- *  included in all copies or substantial portions of the Library.\n- *\n- *  If you modify the Library, you may copy and distribute your modified\n- *  version of the Library in object code or as an executable provided\n- *  that you also do one of the following:\n- *\n- *   Accompany the modified version of the Library with the complete\n- *   corresponding machine-readable source code for the modified version\n- *   of the Library; or,\n- *\n- *   Accompany the modified version of the Library with a written offer\n- *   for a complete machine-readable copy of the corresponding source\n- *   code of the modified version of the Library.\n- *\n- *\n- * THE LIBRARY IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n- * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.\n- */\n-\n-#include <malloc.h>\n-#include <string.h>\n-#include <pthread.h>\n-#include <libspe2.h>\n-\n-#include \"mars/mars.h\"\n-#include \"mars/mars_workload_queue.h\"\n-#include \"mars/mars_kernel_types.h\"\n-#include \"mars/mars_error.h\"\n-#include \"mars/mars_debug.h\"\n-\n-extern struct spe_program_handle mars_kernel_entry;\n-\n-static unsigned int num_mpus_max(void)\n-{\n-\treturn spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);\n-}\n-\n-static void *mpu_context_thread(void *arg)\n-{\n-\tMARS_ASSERT(arg);\n-\n-\tint ret;\n-\tunsigned int entry = SPE_DEFAULT_ENTRY;\n-\tstruct mars_kernel_params *params = (struct mars_kernel_params *)arg;\n-\tstruct spe_context *spe;\n-\n-\tspe = spe_context_create(0, NULL);\n-\tMARS_CHECK_RET(spe, (void *)MARS_ERROR_INTERNAL);\n-\n-\tret = spe_program_load(spe, &mars_kernel_entry);\n-\tMARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);\n-\n-\tret = spe_context_run(spe, &entry, 0, params, NULL, NULL);\n-\tMARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);\n-\n-\tret = spe_context_destroy(spe);\n-\tMARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);\n-\n-\treturn (void *)MARS_SUCCESS;\n-}\n-\n-static int create_mpu_contexts(struct mars_context *mars,\n-\t\t\t\tunsigned int num_mpu_contexts)\n-{\n-\tMARS_ASSERT(mars);\n-\n-\tint ret;\n-\tunsigned int i;\n-\n-\t/* create threads for each mpu context */\n-\tfor (i = 0; i < num_mpu_contexts; i++) {\n-\t\tstruct mars_kernel_params *params = &mars->kernel_params[i];\n-\t\tparams->id = i;\n-\t\tparams->mars_context_ea =\n-\t\t\t\t(uint64_t)(uintptr_t)mars;\n-\t\tparams->workload_queue_ea =\n-\t\t\t\t(uint64_t)(uintptr_t)mars->workload_queue;\n-\n-\t\tret = pthread_create(&mars->mpu_context_threads[i], NULL,\n-\t\t\t\tmpu_context_thread, params);\n-\t\tMARS_CHECK_RET(!ret, MARS_ERROR_INTERNAL);\n-\n-\t\tmars->mpu_context_count++;\n-\t}\n-\n-\treturn MARS_SUCCESS;\n-}\n-\n-static int destroy_mpu_contexts(struct mars_context *mars)\n-{\n-\tMARS_ASSERT(mars);\n-\n-\tint ret;\n-\tvoid *p_ret;\n-\tunsigned int i;\n-\n-\t/* join all mpu context threads */\n-\tfor (i = 0; i < mars->mpu_context_count; i++) {\n-\t\tret = pthread_join(mars->mpu_context_threads[i], &p_ret);\n-\t\tMARS_CHECK_RET(!ret && !p_ret, MARS_ERROR_INTERNAL);\n-\t}\n-\n-\treturn MARS_SUCCESS;\n-}\n-\n-int mars_initialize(struct mars_context *mars, struct mars_params *params)\n-{\n-\tMARS_CHECK_RET(mars, MARS_ERROR_NULL);\n-\n-\tMARS_PRINT(\"Initialize MARS Context (%p)\\n\", mars);\n-\n-\tint ret;\n-\tunsigned int num_mpu_contexts;\n-\n-\t/* zero context */\n-\tmemset(mars, 0, sizeof(struct mars_context));\n-\n-\t/* allocate and initialize params */\n-\tif (params) {\n-\t\tMARS_CHECK_RET(params->num_mpus <= num_mpus_max(),\n-\t\t\t\tMARS_ERROR_PARAMS);\n-\n-\t\tmars->params = (struct mars_params *)\n-\t\t\tmalloc(sizeof(struct mars_params));\n-\t\tMARS_CHECK_RET(mars->params, MARS_ERROR_MEMORY);\n-\t\tmemcpy(mars->params, params, sizeof(struct mars_params));\n-\n-\t\tnum_mpu_contexts = mars->params->num_mpus;\n-\t} else {\n-\t\tmars->params = NULL;\n-\n-\t\tnum_mpu_contexts = num_mpus_max();\n-\t}\n-\n-\t/* allocate kernel params */\n-\tmars->kernel_params = (struct mars_kernel_params *)\n-\t\tmemalign(MARS_KERNEL_PARAMS_ALIGN,\n-\t\t\tsizeof(struct mars_kernel_params) * num_mpu_contexts);\n-\tMARS_CHECK_CLEANUP_RET(mars->kernel_params, mars_finalize(mars),\n-\t\t\t\tMARS_ERROR_MEMORY);\n-\n-\t/* allocate workload queue */\n-\tmars->workload_queue = (struct mars_workload_queue *)\n-\t\tmemalign(MARS_WORKLOAD_QUEUE_ALIGN,\n-\t\t\tsizeof(struct mars_workload_queue));\n-\tMARS_CHECK_CLEANUP_RET(mars->workload_queue, mars_finalize(mars),\n-\t\t\t\tMARS_ERROR_MEMORY);\n-\n-\t/* initialize workload queue */\n-\tret = workload_queue_initialize(mars->workload_queue);\n-\tMARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);\n-\n-\t/* allocate mpu context thread array */\n-\tmars->mpu_context_threads = (pthread_t *)\n-\t\tmalloc(sizeof(pthread_t) * num_mpu_contexts);\n-\tMARS_CHECK_CLEANUP_RET(mars->mpu_context_threads, mars_finalize(mars),\n-\t\t\t\tMARS_ERROR_MEMORY);\n-\n-\t/* create contexts */\n-\tret = create_mpu_contexts(mars, num_mpu_contexts);\n-\tMARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);\n-\n-\treturn MARS_SUCCESS;\n-}\n-\n-int mars_finalize(struct mars_context *mars)\n-{\n-\tMARS_CHECK_RET(mars, MARS_ERROR_NULL);\n-\n-\tint ret;\n-\n-\t/* finalize workload queue */\n-\tif (mars->workload_queue) {\n-\t\tret = workload_queue_finalize(mars->workload_queue);\n-\t\tMARS_CHECK_RET(ret == MARS_SUCCESS, ret);\n-\t}\n-\n-\t/* destroy contexts */\n-\tif (mars->mpu_context_count) {\n-\t\tret = destroy_mpu_contexts(mars);\n-\t\tMARS_CHECK_RET(ret == MARS_SUCCESS, ret);\n-\t}\n-\n-\t/* free allocated memory */\n-\tfree(mars->params);\n-\tfree(mars->kernel_params);\n-\tfree(mars->workload_queue);\n-\tfree(mars->mpu_context_threads);\n-\n-\t/* zero context */\n-\tmemset(mars, 0, sizeof(struct mars_context));\n-\n-\tMARS_PRINT(\"Finalize MARS Context (%p)\\n\", mars);\n-\n-\treturn MARS_SUCCESS;\n-}\n--- /dev/null\n+++ b/src/host/lib/mars_context.c\n@@ -0,0 +1,213 @@\n+/*\n+ * Copyright 2008 Sony Corporation of America\n+ *\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining\n+ * a copy of this Library and associated documentation files (the\n+ * \"Library\"), to deal in the Library without restriction, including\n+ * without limitation the rights to use, copy, modify, merge, publish,\n+ * distribute, sublicense, and/or sell copies of the Library, and to\n+ * permit persons to whom the Library is furnished to do so, subject to\n+ * the following conditions:\n+ *\n+ *  The above copyright notice and this permission notice shall be\n+ *  included in all copies or substantial portions of the Library.\n+ *\n+ *  If you modify the Library, you may copy and distribute your modified\n+ *  version of the Library in object code or as an executable provided\n+ *  that you also do one of the following:\n+ *\n+ *   Accompany the modified version of the Library with the complete\n+ *   corresponding machine-readable source code for the modified version\n+ *   of the Library; or,\n+ *\n+ *   Accompany the modified version of the Library with a written offer\n+ *   for a complete machine-readable copy of the corresponding source\n+ *   code of the modified version of the Library.\n+ *\n+ *\n+ * THE LIBRARY IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n+ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.\n+ */\n+\n+#include <malloc.h>\n+#include <string.h>\n+#include <pthread.h>\n+#include <libspe2.h>\n+\n+#include \"mars/mars_context.h\"\n+#include \"mars/mars_workload_queue.h\"\n+#include \"mars/mars_kernel_types.h\"\n+#include \"mars/mars_error.h\"\n+#include \"mars/mars_debug.h\"\n+\n+extern struct spe_program_handle mars_kernel_entry;\n+\n+static int num_mpus_max(void)\n+{\n+\treturn spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);\n+}\n+\n+static void *mpu_context_thread(void *arg)\n+{\n+\tMARS_ASSERT(arg);\n+\n+\tint ret;\n+\tunsigned int entry = SPE_DEFAULT_ENTRY;\n+\tstruct mars_kernel_params *params = (struct mars_kernel_params *)arg;\n+\tstruct spe_context *spe;\n+\n+\tspe = spe_context_create(0, NULL);\n+\tMARS_CHECK_RET(spe, (void *)MARS_ERROR_INTERNAL);\n+\n+\tret = spe_program_load(spe, &mars_kernel_entry);\n+\tMARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);\n+\n+\tret = spe_context_run(spe, &entry, 0, params, NULL, NULL);\n+\tMARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);\n+\n+\tret = spe_context_destroy(spe);\n+\tMARS_CHECK_RET(!ret, (void *)MARS_ERROR_INTERNAL);\n+\n+\treturn (void *)MARS_SUCCESS;\n+}\n+\n+static int create_mpu_contexts(struct mars_context *mars, int num_mpu_contexts)\n+{\n+\tMARS_ASSERT(mars);\n+\n+\tint ret;\n+\tunsigned int i;\n+\n+\t/* create threads for each mpu context */\n+\tfor (i = 0; i < num_mpu_contexts; i++) {\n+\t\tstruct mars_kernel_params *params = &mars->kernel_params[i];\n+\t\tparams->id = i;\n+\t\tparams->mars_context_ea =\n+\t\t\t\t(uint64_t)(uintptr_t)mars;\n+\t\tparams->workload_queue_ea =\n+\t\t\t\t(uint64_t)(uintptr_t)mars->workload_queue;\n+\n+\t\tret = pthread_create(&mars->mpu_context_threads[i], NULL,\n+\t\t\t\tmpu_context_thread, params);\n+\t\tMARS_CHECK_RET(!ret, MARS_ERROR_INTERNAL);\n+\n+\t\tmars->mpu_context_count++;\n+\t}\n+\n+\treturn MARS_SUCCESS;\n+}\n+\n+static int destroy_mpu_contexts(struct mars_context *mars)\n+{\n+\tMARS_ASSERT(mars);\n+\n+\tint ret;\n+\tvoid *p_ret;\n+\tunsigned int i;\n+\n+\t/* join all mpu context threads */\n+\tfor (i = 0; i < mars->mpu_context_count; i++) {\n+\t\tret = pthread_join(mars->mpu_context_threads[i], &p_ret);\n+\t\tMARS_CHECK_RET(!ret && !p_ret, MARS_ERROR_INTERNAL);\n+\t}\n+\n+\treturn MARS_SUCCESS;\n+}\n+\n+int mars_initialize(struct mars_context *mars, struct mars_params *params)\n+{\n+\tMARS_CHECK_RET(mars, MARS_ERROR_NULL);\n+\n+\tMARS_PRINT(\"Initialize MARS Context (%p)\\n\", mars);\n+\n+\tint ret;\n+\tunsigned int num_mpu_contexts;\n+\n+\t/* zero context */\n+\tmemset(mars, 0, sizeof(struct mars_context));\n+\n+\t/* allocate and initialize params */\n+\tif (params) {\n+\t\tMARS_CHECK_RET(params->num_mpus <= num_mpus_max(),\n+\t\t\t\tMARS_ERROR_PARAMS);\n+\n+\t\tmars->params = (struct mars_params *)\n+\t\t\tmalloc(sizeof(struct mars_params));\n+\t\tMARS_CHECK_RET(mars->params, MARS_ERROR_MEMORY);\n+\t\tmemcpy(mars->params, params, sizeof(struct mars_params));\n+\n+\t\tnum_mpu_contexts = mars->params->num_mpus;\n+\t} else {\n+\t\tmars->params = NULL;\n+\n+\t\tnum_mpu_contexts = num_mpus_max();\n+\t}\n+\n+\t/* allocate kernel params */\n+\tmars->kernel_params = (struct mars_kernel_params *)\n+\t\tmemalign(MARS_KERNEL_PARAMS_ALIGN,\n+\t\t\tsizeof(struct mars_kernel_params) * num_mpu_contexts);\n+\tMARS_CHECK_CLEANUP_RET(mars->kernel_params, mars_finalize(mars),\n+\t\t\t\tMARS_ERROR_MEMORY);\n+\n+\t/* allocate workload queue */\n+\tmars->workload_queue = (struct mars_workload_queue *)\n+\t\tmemalign(MARS_WORKLOAD_QUEUE_ALIGN,\n+\t\t\tsizeof(struct mars_workload_queue));\n+\tMARS_CHECK_CLEANUP_RET(mars->workload_queue, mars_finalize(mars),\n+\t\t\t\tMARS_ERROR_MEMORY);\n+\n+\t/* initialize workload queue */\n+\tret = workload_queue_initialize(mars->workload_queue);\n+\tMARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);\n+\n+\t/* allocate mpu context thread array */\n+\tmars->mpu_context_threads = (pthread_t *)\n+\t\tmalloc(sizeof(pthread_t) * num_mpu_contexts);\n+\tMARS_CHECK_CLEANUP_RET(mars->mpu_context_threads, mars_finalize(mars),\n+\t\t\t\tMARS_ERROR_MEMORY);\n+\n+\t/* create contexts */\n+\tret = create_mpu_contexts(mars, num_mpu_contexts);\n+\tMARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);\n+\n+\treturn MARS_SUCCESS;\n+}\n+\n+int mars_finalize(struct mars_context *mars)\n+{\n+\tMARS_CHECK_RET(mars, MARS_ERROR_NULL);\n+\n+\tint ret;\n+\n+\t/* finalize workload queue */\n+\tif (mars->workload_queue) {\n+\t\tret = workload_queue_finalize(mars->workload_queue);\n+\t\tMARS_CHECK_RET(ret == MARS_SUCCESS, ret);\n+\t}\n+\n+\t/* destroy contexts */\n+\tif (mars->mpu_context_count) {\n+\t\tret = destroy_mpu_contexts(mars);\n+\t\tMARS_CHECK_RET(ret == MARS_SUCCESS, ret);\n+\t}\n+\n+\t/* free allocated memory */\n+\tfree(mars->params);\n+\tfree(mars->kernel_params);\n+\tfree(mars->workload_queue);\n+\tfree(mars->mpu_context_threads);\n+\n+\t/* zero context */\n+\tmemset(mars, 0, sizeof(struct mars_context));\n+\n+\tMARS_PRINT(\"Finalize MARS Context (%p)\\n\", mars);\n+\n+\treturn MARS_SUCCESS;\n+}\n--- a/src/host/lib/mars_task.c\n+++ b/src/host/lib/mars_task.c\n@@ -41,7 +41,7 @@\n \n #include \"mars/mars_task.h\"\n #include \"mars/mars_workload_queue.h\"\n-#include \"mars/mars.h\"\n+#include \"mars/mars_context.h\"\n #include \"mars/mars_error.h\"\n #include \"mars/mars_debug.h\"\n \n--- a/src/host/lib/mars_task_event_flag.c\n+++ b/src/host/lib/mars_task_event_flag.c\n@@ -40,7 +40,7 @@\n \n #include \"mars/mars_task_event_flag.h\"\n #include \"mars/mars_workload_queue.h\"\n-#include \"mars/mars.h\"\n+#include \"mars/mars_context.h\"\n #include \"mars/mars_mutex.h\"\n #include \"mars/mars_error.h\"\n #include \"mars/mars_debug.h\"\n--- a/src/host/lib/mars_task_queue.c\n+++ b/src/host/lib/mars_task_queue.c\n@@ -40,7 +40,7 @@\n \n #include \"mars/mars_task_queue.h\"\n #include \"mars/mars_workload_queue.h\"\n-#include \"mars/mars.h\"\n+#include \"mars/mars_context.h\"\n #include \"mars/mars_mutex.h\"\n #include \"mars/mars_error.h\"\n #include \"mars/mars_debug.h\"\n--- a/src/host/lib/mars_task_signal.c\n+++ b/src/host/lib/mars_task_signal.c\n@@ -36,7 +36,8 @@\n  */\n \n #include \"mars/mars_task_signal.h\"\n-#include \"mars/mars.h\"\n+#include \"mars/mars_workload_queue.h\"\n+#include \"mars/mars_context.h\"\n #include \"mars/mars_error.h\"\n #include \"mars/mars_debug.h\"\n #include \"mars/mars_workload_queue.h\"\n",
    "prefixes": []
}