Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/457/?format=api
{ "id": 457, "url": "http://patchwork.ozlabs.org/api/patches/457/?format=api", "web_url": "http://patchwork.ozlabs.org/project/cbe-oss-dev/patch/48D15FBE.4050506@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": "<48D15FBE.4050506@am.sony.com>", "list_archive_url": null, "date": "2008-09-17T19:51:26", "name": "[02/11,v2] MARS: Workload queue block replace bit fields", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "c85fd863862261d0715ee140b370ae6826112956", "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/48D15FBE.4050506@am.sony.com/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/457/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/457/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org>", "X-Original-To": [ "patchwork-incoming@ozlabs.org", "cbe-oss-dev@ozlabs.org" ], "Delivered-To": [ "patchwork-incoming@ozlabs.org", "cbe-oss-dev@ozlabs.org" ], "Received": [ "from ozlabs.org (localhost [127.0.0.1])\n\tby ozlabs.org (Postfix) with ESMTP id C47FEDE394\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 18 Sep 2008 05:52:13 +1000 (EST)", "from VA3EHSOBE005.bigfish.com (outbound-va3.frontbridge.com\n\t[216.32.180.16]) by ozlabs.org (Postfix) with ESMTP id 98A16DE219\n\tfor <cbe-oss-dev@ozlabs.org>; Thu, 18 Sep 2008 05:51:36 +1000 (EST)", "from mail38-va3-R.bigfish.com (10.7.14.254) by\n\tVA3EHSOBE005.bigfish.com (10.7.40.25) with Microsoft SMTP Server id\n\t8.1.291.1; Wed, 17 Sep 2008 19:51:33 +0000", "from mail38-va3 (localhost.localdomain [127.0.0.1])\tby\n\tmail38-va3-R.bigfish.com (Postfix) with ESMTP id 750B410A8281\tfor\n\t<cbe-oss-dev@ozlabs.org>; Wed, 17 Sep 2008 19:51:33 +0000 (UTC)", "by mail38-va3 (MessageSwitch) id 1221681088904845_31707;\n\tWed, 17 Sep 2008 19:51:28 +0000 (UCT)", "from mail8.fw-bc.sony.com (mail8.fw-bc.sony.com [160.33.98.75])\tby\n\tmail38-va3.bigfish.com (Postfix) with ESMTP id CFFB5FC805D\tfor\n\t<cbe-oss-dev@ozlabs.org>; Wed, 17 Sep 2008 19:51:28 +0000 (UTC)", "from mail3.sjc.in.sel.sony.com (mail3.sjc.in.sel.sony.com\n\t[43.134.1.211])\tby mail8.fw-bc.sony.com (8.14.2/8.14.2) with ESMTP id\n\tm8HJpSPB020065\tfor <cbe-oss-dev@ozlabs.org>;\n\tWed, 17 Sep 2008 19:51:28 GMT", "from USSDIXIM01.am.sony.com (ussdixim01.am.sony.com\n\t[43.130.140.33])\n\tby mail3.sjc.in.sel.sony.com (8.12.11/8.12.11) with ESMTP id\n\tm8HJpR8W023457\n\tfor <cbe-oss-dev@ozlabs.org>; Wed, 17 Sep 2008 19:51:27 GMT", "from ussdixms03.am.sony.com ([43.130.140.23]) by\n\tUSSDIXIM01.am.sony.com with Microsoft SMTPSVC(5.0.2195.6713);\n\tWed, 17 Sep 2008 12:51:27 -0700", "from [43.135.148.175] ([43.135.148.175]) by ussdixms03.am.sony.com\n\twith Microsoft SMTPSVC(5.0.2195.6713);\n\tWed, 17 Sep 2008 12:51:27 -0700" ], "X-BigFish": "VS4(zzzz10c0j10d3izz1497iz2dh6bh61h)", "X-Spam-TCS-SCL": "0:0", "X-FB-SS": "5,", "Message-ID": "<48D15FBE.4050506@am.sony.com>", "Date": "Wed, 17 Sep 2008 12:51:26 -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>", "References": "<48C972C3.2060906@am.sony.com>", "In-Reply-To": "<48C972C3.2060906@am.sony.com>", "X-Enigmail-Version": "0.95.7", "X-OriginalArrivalTime": "17 Sep 2008 19:51:27.0084 (UTC)\n\tFILETIME=[C57D1AC0:01C918FE]", "X-SEL-encryption-scan": "scanned", "Subject": "[Cbe-oss-dev] [PATCH 02/11 v2]MARS: Workload queue block replace\n\tbit fields", "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-incoming=ozlabs.org@ozlabs.org", "Errors-To": "cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org" }, "content": "This replaces the bit fields usage for the workload queue block bits with\nexplicit bitwise shift/mask operations for better portability.\n\nSigned-off-by: Yuji Mano <yuji.mano@am.sony.com>", "diff": "--- a/include/common/mars/mars_workload_types.h\n+++ b/include/common/mars/mars_workload_types.h\n@@ -76,7 +76,39 @@ extern \"C\" {\n #define MARS_WORKLOAD_QUEUE_ALIGN\t\t128\t/* align to 128 bytes */\n #define MARS_WORKLOAD_QUEUE_HEADER_ALIGN\t128\t/* align to 128 bytes */\n #define MARS_WORKLOAD_QUEUE_BLOCK_ALIGN\t\t128\t/* align to 128 bytes */\n-#define MARS_WORKLOAD_QUEUE_BLOCK_BITS_ALIGN\t8\t/* align to 8 bytes */\n+\n+/*\n+ * MARS workload queue block bits\n+ * ----------------------------------------------------------------------------\n+ * |[63...60]|[59...56]|[55....48]|[ 47 ]|[46....32]|[31.....16]|[15......0]|\n+ * ----------------------------------------------------------------------------\n+ * | 4-bits | 4-bits | 8-bits | 1-bit | 15-bits | 16-bits | 16-bits |\n+ * ----------------------------------------------------------------------------\n+ * | TYPE | STATE | PRIORITY | SIGNAL | RESERVED | WAIT_ID | COUNTER |\n+ * ----------------------------------------------------------------------------\n+ */\n+#define MARS_BITS_SIZE\t\t\t\t64\n+\n+#define MARS_BITS_SHIFT_TYPE\t\t\t60\n+#define MARS_BITS_SHIFT_STATE\t\t\t56\n+#define MARS_BITS_SHIFT_PRIORITY\t\t48\n+#define MARS_BITS_SHIFT_SIGNAL\t\t\t47\n+#define MARS_BITS_SHIFT_WAIT_ID\t\t\t16\n+#define MARS_BITS_SHIFT_COUNTER\t\t\t0\n+\n+#define MARS_BITS_MASK_TYPE\t\t\t0xf000000000000000ULL\n+#define MARS_BITS_MASK_STATE\t\t\t0x0f00000000000000ULL\n+#define MARS_BITS_MASK_PRIORITY\t\t\t0x00ff000000000000ULL\n+#define MARS_BITS_MASK_SIGNAL\t\t\t0x0000800000000000ULL\n+#define MARS_BITS_MASK_WAIT_ID\t\t\t0x00000000ffff0000ULL\n+#define MARS_BITS_MASK_COUNTER\t\t\t0x000000000000ffffULL\n+\n+#define MARS_BITS_GET(bits, name) \\\n+\t((*(bits) & MARS_BITS_MASK_##name) >> MARS_BITS_SHIFT_##name)\n+\n+#define MARS_BITS_SET(bits, name, val) \\\n+\t(*bits) = ((*(bits) & ~MARS_BITS_MASK_##name) | \\\n+\t\t((uint64_t)(val) << MARS_BITS_SHIFT_##name))\n \n /* mars workload context */\n struct mars_workload_context {\n@@ -90,21 +122,11 @@ struct mars_workload_queue_header {\n \tuint8_t flag;\n } __attribute__((aligned(MARS_WORKLOAD_QUEUE_HEADER_ALIGN)));\n \n-/* 8 byte workload queue block bits structure */\n-struct mars_workload_queue_block_bits {\n-\tuint64_t type:4;\n-\tuint64_t state:4;\n-\tuint64_t priority:8;\n-\tuint64_t signal:1;\n-\tuint64_t wait:16;\n-\tuint64_t counter:16;\n-} __attribute__((aligned(MARS_WORKLOAD_QUEUE_BLOCK_BITS_ALIGN)));\n-\n /* 128 byte workload queue block structure */\n struct mars_workload_queue_block {\n \tuint32_t lock;\n \tuint32_t pad;\n-\tstruct mars_workload_queue_block_bits bits[MARS_WORKLOAD_PER_BLOCK];\n+\tuint64_t bits[MARS_WORKLOAD_PER_BLOCK];\n } __attribute__((aligned(MARS_WORKLOAD_QUEUE_BLOCK_ALIGN)));\n \n /* mars workload queue structure */\n--- a/src/host/lib/mars_workload_queue.c\n+++ b/src/host/lib/mars_workload_queue.c\n@@ -63,12 +63,20 @@ int workload_queue_initialize(struct mar\n \t\tmars_mutex_lock((struct mars_mutex *)p);\n \n \t\tfor (index = 0; index < MARS_WORKLOAD_PER_BLOCK; index++) {\n-\t\t\tp->bits[index].type = MARS_WORKLOAD_TYPE_NONE;\n-\t\t\tp->bits[index].state = MARS_WORKLOAD_STATE_NONE;\n-\t\t\tp->bits[index].priority = MARS_WORKLOAD_PRIORITY_MIN;\n-\t\t\tp->bits[index].counter = MARS_WORKLOAD_COUNTER_MIN;\n-\t\t\tp->bits[index].signal = MARS_WORKLOAD_SIGNAL_OFF;\n-\t\t\tp->bits[index].wait = MARS_WORKLOAD_ID_NONE;\n+\t\t\tuint64_t *bits = &p->bits[index];\n+\n+\t\t\tMARS_BITS_SET(bits, TYPE,\n+\t\t\t\tMARS_WORKLOAD_TYPE_NONE);\n+\t\t\tMARS_BITS_SET(bits, STATE,\n+\t\t\t\tMARS_WORKLOAD_STATE_NONE);\n+\t\t\tMARS_BITS_SET(bits, PRIORITY,\n+\t\t\t\tMARS_WORKLOAD_PRIORITY_MIN);\n+\t\t\tMARS_BITS_SET(bits, COUNTER,\n+\t\t\t\tMARS_WORKLOAD_COUNTER_MIN);\n+\t\t\tMARS_BITS_SET(bits, SIGNAL,\n+\t\t\t\tMARS_WORKLOAD_SIGNAL_OFF);\n+\t\t\tMARS_BITS_SET(bits, WAIT_ID,\n+\t\t\t\tMARS_WORKLOAD_ID_NONE);\n \t\t}\n \n \t\tmars_mutex_unlock((struct mars_mutex *)p);\n@@ -91,7 +99,7 @@ int workload_queue_finalize(struct mars_\n \t\tblock = id / MARS_WORKLOAD_PER_BLOCK;\n \t\tindex = id % MARS_WORKLOAD_PER_BLOCK;\n \n-\t\tif (queue->block[block].bits[index].state !=\n+\t\tif (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=\n \t\t\tMARS_WORKLOAD_STATE_NONE)\n \t\t\tbreak;\n \n@@ -117,12 +125,13 @@ int workload_queue_add_begin(struct mars\n \tint block = 0;\n \tint index = 0;\n \n+\tuint64_t *bits = &queue->block[block].bits[index];\n+\n \t*id = 0;\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\twhile (queue->block[block].bits[index].state !=\n-\t\tMARS_WORKLOAD_STATE_NONE) {\n+\twhile (MARS_BITS_GET(bits, STATE) != MARS_WORKLOAD_STATE_NONE) {\n \t\t(*id)++;\n \t\tindex++;\n \t\tif (index == MARS_WORKLOAD_PER_BLOCK) {\n@@ -137,16 +146,17 @@ int workload_queue_add_begin(struct mars\n \t\t\tmars_mutex_lock(\n \t\t\t\t(struct mars_mutex *)&queue->block[block]);\n \t\t}\n+\t\tbits = &queue->block[block].bits[index];\n \t}\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_NONE,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(bits, STATE) == MARS_WORKLOAD_STATE_NONE,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set type and set state to adding */\n-\tqueue->block[block].bits[index].type = type;\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_ADDING;\n+\tMARS_BITS_SET(bits, TYPE, type);\n+\tMARS_BITS_SET(bits, STATE, MARS_WORKLOAD_STATE_ADDING);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -165,15 +175,17 @@ int workload_queue_add_end(struct mars_w\n \tint block = id / MARS_WORKLOAD_PER_BLOCK;\n \tint index = id % MARS_WORKLOAD_PER_BLOCK;\n \n+\tuint64_t *bits = &queue->block[block].bits[index];\n+\n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_ADDING,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(bits, STATE) == MARS_WORKLOAD_STATE_ADDING,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* reset workload queue bits and set state to finished state */\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_FINISHED;\n+\tMARS_BITS_SET(bits, STATE, MARS_WORKLOAD_STATE_FINISHED);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -190,13 +202,15 @@ int workload_queue_add_cancel(struct mar\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_ADDING,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_ADDING,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set state back to none state */\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_NONE;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], STATE,\n+\t\tMARS_WORKLOAD_STATE_NONE);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -214,13 +228,15 @@ int workload_queue_remove_begin(struct m\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_FINISHED,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_FINISHED,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set state to removing */\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_REMOVING;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], STATE,\n+\t\tMARS_WORKLOAD_STATE_REMOVING);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -241,13 +257,15 @@ int workload_queue_remove_end(struct mar\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_REMOVING,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_REMOVING,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set state to none */\n-\tqueue->block[block].bits[index].type = MARS_WORKLOAD_TYPE_NONE;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], TYPE,\n+\t\tMARS_WORKLOAD_TYPE_NONE);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -264,13 +282,15 @@ int workload_queue_remove_cancel(struct \n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_REMOVING,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_REMOVING,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set state back to finished */\n-\tqueue->block[block].bits[index].type = MARS_WORKLOAD_STATE_FINISHED;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], TYPE,\n+\t\tMARS_WORKLOAD_STATE_FINISHED);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -289,17 +309,23 @@ int workload_queue_schedule_begin(struct\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_FINISHED,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_FINISHED,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* reset workload queue bits and set state to scheduling */\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_SCHEDULING;\n-\tqueue->block[block].bits[index].priority = priority;\n-\tqueue->block[block].bits[index].counter = MARS_WORKLOAD_COUNTER_MIN;\n-\tqueue->block[block].bits[index].signal = MARS_WORKLOAD_SIGNAL_OFF;\n-\tqueue->block[block].bits[index].wait = MARS_WORKLOAD_ID_NONE;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], STATE,\n+\t\tMARS_WORKLOAD_STATE_SCHEDULING);\n+\tMARS_BITS_SET(&queue->block[block].bits[index], PRIORITY,\n+\t\tpriority);\n+\tMARS_BITS_SET(&queue->block[block].bits[index], COUNTER,\n+\t\tMARS_WORKLOAD_COUNTER_MIN);\n+\tMARS_BITS_SET(&queue->block[block].bits[index], SIGNAL,\n+\t\tMARS_WORKLOAD_SIGNAL_OFF);\n+\tMARS_BITS_SET(&queue->block[block].bits[index], WAIT_ID,\n+\t\tMARS_WORKLOAD_ID_NONE);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -320,13 +346,15 @@ int workload_queue_schedule_end(struct m\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_SCHEDULING,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_SCHEDULING,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set state to ready */\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_READY;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], STATE,\n+\t\tMARS_WORKLOAD_STATE_READY);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -344,13 +372,15 @@ int workload_queue_schedule_cancel(struc\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state ==\n-\t\tMARS_WORKLOAD_STATE_SCHEDULING,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) ==\n+\t\t\tMARS_WORKLOAD_STATE_SCHEDULING,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n \t/* set state back to finished */\n-\tqueue->block[block].bits[index].state = MARS_WORKLOAD_STATE_FINISHED;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], STATE,\n+\t\tMARS_WORKLOAD_STATE_FINISHED);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n@@ -366,10 +396,11 @@ int workload_queue_wait(struct mars_work\n \tint block = id / MARS_WORKLOAD_PER_BLOCK;\n \tint index = id % MARS_WORKLOAD_PER_BLOCK;\n \n-\twhile (queue->block[block].bits[index].state !=\n+\twhile (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=\n \t\tMARS_WORKLOAD_STATE_FINISHED) {\n-\t\tMARS_CHECK_RET(queue->block[block].bits[index].state !=\n-\t\t\tMARS_WORKLOAD_STATE_NONE,\n+\t\tMARS_CHECK_RET(\n+\t\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE)\n+\t\t\t\t!= MARS_WORKLOAD_STATE_NONE,\n \t\t\tMARS_ERROR_STATE);\n \t\tsched_yield();\n \t}\n@@ -390,11 +421,12 @@ int workload_queue_try_wait(struct mars_\n \tint block = id / MARS_WORKLOAD_PER_BLOCK;\n \tint index = id % MARS_WORKLOAD_PER_BLOCK;\n \n-\tMARS_CHECK_RET(queue->block[block].bits[index].state !=\n-\t\tMARS_WORKLOAD_STATE_NONE,\n+\tMARS_CHECK_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) !=\n+\t\t\tMARS_WORKLOAD_STATE_NONE,\n \t\tMARS_ERROR_STATE);\n \n-\tif (queue->block[block].bits[index].state !=\n+\tif (MARS_BITS_GET(&queue->block[block].bits[index], STATE) !=\n \t\tMARS_WORKLOAD_STATE_FINISHED)\n \t\treturn MARS_ERROR_BUSY;\n \n@@ -415,12 +447,14 @@ int workload_queue_signal_send(struct ma\n \n \tmars_mutex_lock((struct mars_mutex *)&queue->block[block]);\n \n-\tMARS_CHECK_CLEANUP_RET(queue->block[block].bits[index].state !=\n-\t\tMARS_WORKLOAD_STATE_NONE,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue->block[block].bits[index], STATE) !=\n+\t\t\tMARS_WORKLOAD_STATE_NONE,\n \t\tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]),\n \t\tMARS_ERROR_STATE);\n \n-\tqueue->block[block].bits[index].signal = MARS_WORKLOAD_SIGNAL_ON;\n+\tMARS_BITS_SET(&queue->block[block].bits[index], SIGNAL,\n+\t\tMARS_WORKLOAD_SIGNAL_ON);\n \n \tmars_mutex_unlock((struct mars_mutex *)&queue->block[block]);\n \n--- a/src/mpu/kernel/mars_kernel_scheduler.c\n+++ b/src/mpu/kernel/mars_kernel_scheduler.c\n@@ -65,42 +65,54 @@ static int search_block(int block)\n {\n \tint i;\n \tint index = -1;\n-\tint max_count = -1;\n-\tint max_priority = -1;\n+\tuint16_t max_counter;\n+\tuint16_t max_priority;\n \n \t/* search through workload queue for next workload to run\n \t * while incrementing wait counter for all waiting workloads\n \t * and pick the workload that has been waiting the longest\n \t */\n \tfor (i = 0; i < MARS_WORKLOAD_PER_BLOCK; i++) {\n-\t\tstruct mars_workload_queue_block_bits *bits\n-\t\t\t= &queue_block.bits[i];\n+\t\tuint64_t *bits = &queue_block.bits[i];\n+\t\tuint8_t signal = MARS_BITS_GET(bits, SIGNAL);\n+\t\tuint8_t priority = MARS_BITS_GET(bits, PRIORITY);\n+\t\tuint16_t wait_id = MARS_BITS_GET(bits, WAIT_ID);\n+\t\tuint16_t counter = MARS_BITS_GET(bits, COUNTER);\n \n-\t\tswitch (bits->state) {\n+\t\tswitch (MARS_BITS_GET(bits, STATE)) {\n \t\tcase MARS_WORKLOAD_STATE_READY:\n-\t\t\t/* priority greater than max priority so select */\n-\t\t\tif ((int)bits->priority > max_priority) {\n+\t\t\t/* index not set yet so select */\n+\t\t\tif (index < 0) {\n \t\t\t\tindex = i;\n-\t\t\t\tmax_count = bits->counter;\n-\t\t\t\tmax_priority = bits->priority;\n-\t\t\t/* priority equal and wait counter greater so select */\n-\t\t\t} else if ((int)bits->priority == max_priority &&\n-\t\t\t\t(int)bits->counter > max_count) {\n-\t\t\t\tindex = i;\n-\t\t\t\tmax_count = bits->counter;\n+\t\t\t\tmax_counter = counter;\n+\t\t\t\tmax_priority = priority;\n+\t\t\t/* index set so compare priority and counter */\n+\t\t\t} else {\n+\t\t\t\t/* priority > max priority so select */\n+\t\t\t\tif (priority > max_priority) {\n+\t\t\t\t\tindex = i;\n+\t\t\t\t\tmax_counter = counter;\n+\t\t\t\t\tmax_priority = priority;\n+\t\t\t\t/* priority equal & counter greater so select */\n+\t\t\t\t} else if (priority == max_priority &&\n+\t\t\t\t\tcounter > max_counter) {\n+\t\t\t\t\tindex = i;\n+\t\t\t\t\tmax_counter = counter;\n+\t\t\t\t}\n \t\t\t}\n \t\t\t/* increment wait counter without overflowing */\n-\t\t\tif (bits->counter < MARS_WORKLOAD_COUNTER_MAX)\n-\t\t\t\tbits->counter++;\n+\t\t\tif (counter < MARS_WORKLOAD_COUNTER_MAX)\n+\t\t\t\tMARS_BITS_SET(bits, COUNTER, counter + 1);\n \t\t\tbreak;\n \t\tcase MARS_WORKLOAD_STATE_WAITING:\n \t\t\t/* waiting for workload to finish so check status */\n-\t\t\tif (bits->wait != MARS_WORKLOAD_ID_NONE) {\n+\t\t\tif (wait_id != MARS_WORKLOAD_ID_NONE) {\n \t\t\t\tstruct mars_workload_queue_block wait_block;\n \t\t\t\tstruct mars_workload_queue_block *p_wait_block;\n+\t\t\t\tuint8_t wait_state;\n \n-\t\t\t\tint bl = bits->wait / MARS_WORKLOAD_PER_BLOCK;\n-\t\t\t\tint id = bits->wait % MARS_WORKLOAD_PER_BLOCK;\n+\t\t\t\tint bl = wait_id / MARS_WORKLOAD_PER_BLOCK;\n+\t\t\t\tint id = wait_id % MARS_WORKLOAD_PER_BLOCK;\n \n \t\t\t\t/* check if workload id is in the same block */\n \t\t\t\tif (block != bl) {\n@@ -113,16 +125,24 @@ static int search_block(int block)\n \t\t\t\t\tp_wait_block = &queue_block;\n \t\t\t\t}\n \n+\t\t\t\twait_state =\n+\t\t\t\t\tMARS_BITS_GET(&p_wait_block->bits[id],\n+\t\t\t\t\tSTATE);\n+\n \t\t\t\t/* check if workload is finished and reset */\n-\t\t\t\tif (p_wait_block->bits[id].state ==\n+\t\t\t\tif (wait_state ==\n \t\t\t\t\tMARS_WORKLOAD_STATE_FINISHED) {\n-\t\t\t\t\tbits->wait = MARS_WORKLOAD_ID_NONE;\n-\t\t\t\t\tbits->state = MARS_WORKLOAD_STATE_READY;\n+\t\t\t\t\tMARS_BITS_SET(bits, WAIT_ID,\n+\t\t\t\t\t\tMARS_WORKLOAD_ID_NONE);\n+\t\t\t\t\tMARS_BITS_SET(bits, STATE,\n+\t\t\t\t\t\tMARS_WORKLOAD_STATE_READY);\n \t\t\t\t}\n \t\t\t/* waiting for signal so check signal bit and reset */\n-\t\t\t} else if (bits->signal == MARS_WORKLOAD_SIGNAL_ON) {\n-\t\t\t\tbits->signal = MARS_WORKLOAD_SIGNAL_OFF;\n-\t\t\t\tbits->state = MARS_WORKLOAD_STATE_READY;\n+\t\t\t} else if (signal == MARS_WORKLOAD_SIGNAL_ON) {\n+\t\t\t\tMARS_BITS_SET(bits, SIGNAL,\n+\t\t\t\t\tMARS_WORKLOAD_SIGNAL_OFF);\n+\t\t\t\tMARS_BITS_SET(bits, STATE,\n+\t\t\t\t\tMARS_WORKLOAD_STATE_READY);\n \t\t\t\ti--;\n \t\t\t}\n \t\t\tbreak;\n@@ -148,10 +168,12 @@ static int reserve_block(int block)\n \tindex = search_block(block);\n \tif (index >= 0) {\n \t\t/* update the current state of the workload */\n-\t\tqueue_block.bits[index].state = MARS_WORKLOAD_STATE_RUNNING;\n+\t\tMARS_BITS_SET(&queue_block.bits[index], STATE,\n+\t\t\tMARS_WORKLOAD_STATE_RUNNING);\n \n \t\t/* reset the counter for reserved workload */\n-\t\tqueue_block.bits[index].counter = MARS_WORKLOAD_COUNTER_MIN;\n+\t\tMARS_BITS_SET(&queue_block.bits[index], COUNTER,\n+\t\t\tMARS_WORKLOAD_COUNTER_MIN);\n \t}\n \n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n@@ -168,7 +190,7 @@ static void release_block(int block, int\n \tmars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);\n \n \t/* update current workload state in workload queue block */\n-\tqueue_block.bits[index].state = workload_state;\n+\tMARS_BITS_SET(&queue_block.bits[index], STATE, workload_state);\n \n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n }\n@@ -191,15 +213,13 @@ int reserve_workload(void)\n \n \t/* set global workload info based on workload block and index */\n \tworkload_index = MARS_WORKLOAD_PER_BLOCK * block + index;\n-\tworkload_type = queue_block.bits[index].type;\n+\tworkload_type = MARS_BITS_GET(&queue_block.bits[index], TYPE);\n \tworkload_ea = queue_header.context_ea +\n \t\t\tworkload_index * sizeof(struct mars_workload_context);\n \n \t/* dma the workload context code into LS from main memory */\n-\tmars_dma_get_and_wait((void *)&workload,\n-\t\t\t\tworkload_ea,\n-\t\t\t\tsizeof(struct mars_workload_context),\n-\t\t\t\tMARS_DMA_TAG);\n+\tmars_dma_get_and_wait(&workload, workload_ea,\n+\t\t\tsizeof(struct mars_workload_context), MARS_DMA_TAG);\n \n \treturn MARS_WORKLOAD_RESERVED;\n }\n@@ -211,10 +231,8 @@ void release_workload(void)\n \n \t/* dma updated workload context back to main memory if not finished */\n \tif (workload_state != MARS_WORKLOAD_STATE_FINISHED) {\n-\t\tmars_dma_put_and_wait((void *)&workload,\n-\t\t\t\t\tworkload_ea,\n-\t\t\t\t\tsizeof(struct mars_workload_context),\n-\t\t\t\t\tMARS_DMA_TAG);\n+\t\tmars_dma_put_and_wait(&workload, workload_ea,\n+\t\t\tsizeof(struct mars_workload_context), MARS_DMA_TAG);\n \t}\n \n \t/* release block reservation */\n--- a/src/mpu/kernel/mars_kernel_workload.c\n+++ b/src/mpu/kernel/mars_kernel_workload.c\n@@ -139,14 +139,15 @@ int workload_schedule(uint16_t workload_\n \tmars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);\n \n \t/* make sure workload is in the correct state */\n-\tif (queue_block.bits[index].state != MARS_WORKLOAD_STATE_FINISHED) {\n+\tif (MARS_BITS_GET(&queue_block.bits[index], STATE) !=\n+\t\tMARS_WORKLOAD_STATE_FINISHED) {\n \t\tmars_mutex_unlock_put(block_ea,\n \t\t\t(struct mars_mutex *)&queue_block);\n \t\treturn MARS_ERROR_STATE;\n \t}\n \n \t/* get information of workload to schedule */\n-\tschedule_workload_type = queue_block.bits[index].type;\n+\tschedule_workload_type = MARS_BITS_GET(&queue_block.bits[index], TYPE);\n \tschedule_workload_ea = queue_header.context_ea +\n \t\t\tworkload_id * sizeof(struct mars_workload_context);\n \n@@ -170,11 +171,16 @@ int workload_schedule(uint16_t workload_\n \t\t\t\tsizeof(struct mars_workload_context),\n \t\t\t\tMARS_DMA_TAG);\n \n-\tqueue_block.bits[index].state = MARS_WORKLOAD_STATE_READY;\n-\tqueue_block.bits[index].priority = priority;\n-\tqueue_block.bits[index].counter = MARS_WORKLOAD_COUNTER_MIN;\n-\tqueue_block.bits[index].signal = MARS_WORKLOAD_SIGNAL_OFF;\n-\tqueue_block.bits[index].wait = MARS_WORKLOAD_ID_NONE;\n+\tMARS_BITS_SET(&queue_block.bits[index], STATE,\n+\t\tMARS_WORKLOAD_STATE_READY);\n+\tMARS_BITS_SET(&queue_block.bits[index], PRIORITY,\n+\t\tpriority);\n+\tMARS_BITS_SET(&queue_block.bits[index], COUNTER,\n+\t\tMARS_WORKLOAD_COUNTER_MIN);\n+\tMARS_BITS_SET(&queue_block.bits[index], SIGNAL,\n+\t\tMARS_WORKLOAD_SIGNAL_OFF);\n+\tMARS_BITS_SET(&queue_block.bits[index], WAIT_ID,\n+\t\tMARS_WORKLOAD_ID_NONE);\n \n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n \n@@ -196,14 +202,15 @@ int workload_wait(uint16_t workload_id)\n \tmars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);\n \n \t/* make sure workload is initialized */\n-\tif (queue_block.bits[index].state == MARS_WORKLOAD_STATE_NONE) {\n+\tif (MARS_BITS_GET(&queue_block.bits[index], STATE) ==\n+\t\tMARS_WORKLOAD_STATE_NONE) {\n \t\tmars_mutex_unlock_put(block_ea,\n \t\t\t(struct mars_mutex *)&queue_block);\n \t\treturn MARS_ERROR_STATE;\n \t}\n \n \t/* set the workload id to wait for */\n-\tqueue_block.bits[index].wait = workload_id;\n+\tMARS_BITS_SET(&queue_block.bits[index], WAIT_ID, workload_id);\n \n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n \n@@ -224,15 +231,17 @@ int workload_try_wait(uint16_t workload_\n \n \tmars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);\n \n-\tMARS_CHECK_CLEANUP_RET(queue_block.bits[index].state !=\n-\t\tMARS_WORKLOAD_STATE_NONE,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue_block.bits[index], STATE) !=\n+\t\t\tMARS_WORKLOAD_STATE_NONE,\n \t\tmars_mutex_unlock_put(block_ea,\n \t\t\t(struct mars_mutex *)&queue_block),\n \t\tMARS_ERROR_STATE);\n \n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n \n-\tif (queue_block.bits[index].state != MARS_WORKLOAD_STATE_FINISHED)\n+\tif (MARS_BITS_GET(&queue_block.bits[index], STATE) !=\n+\t\tMARS_WORKLOAD_STATE_FINISHED)\n \t\treturn MARS_ERROR_BUSY;\n \n \treturn MARS_SUCCESS;\n@@ -253,14 +262,16 @@ int workload_signal_send(uint16_t worklo\n \tmars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);\n \n \t/* make sure workload is initialized */\n-\tif (queue_block.bits[index].state == MARS_WORKLOAD_STATE_NONE) {\n+\tif (MARS_BITS_GET(&queue_block.bits[index], STATE) ==\n+\t\tMARS_WORKLOAD_STATE_NONE) {\n \t\tmars_mutex_unlock_put(block_ea,\n \t\t\t(struct mars_mutex *)&queue_block);\n \t\treturn MARS_ERROR_STATE;\n \t}\n \n \t/* set the workload signal */\n-\tqueue_block.bits[index].signal = MARS_WORKLOAD_SIGNAL_ON;\n+\tMARS_BITS_SET(&queue_block.bits[index], SIGNAL,\n+\t\tMARS_WORKLOAD_SIGNAL_ON);\n \n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n \n@@ -295,8 +306,9 @@ int workload_signal_try_wait(void)\n \n \tmars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);\n \n-\tMARS_CHECK_CLEANUP_RET(queue_block.bits[index].state !=\n-\t\tMARS_WORKLOAD_STATE_NONE,\n+\tMARS_CHECK_CLEANUP_RET(\n+\t\tMARS_BITS_GET(&queue_block.bits[index], STATE) !=\n+\t\t\tMARS_WORKLOAD_STATE_NONE,\n \t\tmars_mutex_unlock_put(block_ea,\n \t\t\t(struct mars_mutex *)&queue_block),\n \t\tMARS_ERROR_STATE);\n@@ -304,7 +316,8 @@ int workload_signal_try_wait(void)\n \tmars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);\n \n \t/* return busy if task has not received signal */\n-\tif (queue_block.bits[index].signal != MARS_WORKLOAD_SIGNAL_ON)\n+\tif (MARS_BITS_GET(&queue_block.bits[index], SIGNAL) !=\n+\t\tMARS_WORKLOAD_SIGNAL_ON)\n \t\treturn MARS_ERROR_BUSY;\n \n \treturn MARS_SUCCESS;\n", "prefixes": [ "02/11", "v2" ] }