[{"id":1037,"web_url":"http://patchwork.ozlabs.org/comment/1037/","msgid":"<48D1C10A.5070302@sm.sony.co.jp>","list_archive_url":null,"date":"2008-09-18T02:46:34","subject":"Re: [Cbe-oss-dev] [PATCH 02/11 v2]MARS: Workload queue block\n\treplace bit fields","submitter":{"id":39,"url":"http://patchwork.ozlabs.org/api/people/39/","name":"Kazunori Asayama","email":"asayama@sm.sony.co.jp"},"content":"Yuji Mano wrote:\n> This replaces the bit fields usage for the workload queue block bits with\n> explicit bitwise shift/mask operations for better portability.\n> \n> Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>\n> \n> ---\n> v2:\n>  - remove explicit cast from MARS_BITS_GET macro\n>  - avoid casting max_priority and max_counter to int inside scheduler\n>  - remove unnecessary casting to void *\n> \n>  include/common/mars/mars_workload_types.h |   46 +++++++---\n>  src/host/lib/mars_workload_queue.c        |  134 ++++++++++++++++++------------\n>  src/mpu/kernel/mars_kernel_scheduler.c    |   92 ++++++++++++--------\n>  src/mpu/kernel/mars_kernel_workload.c     |   47 ++++++----\n>  4 files changed, 203 insertions(+), 116 deletions(-)\n> \n(snip)\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\nSo you can simply say:\n\n\tif (index < 0 ||\n\t\tpriority > max_priority ||\n\t\t(priority == max_priority && counter > max_counter)) {\n\t\tindex = i;\n\t\tmax_counter = counter;\n\t\tmax_priority = priority;\n\t}","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 D8830DDF3F\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 18 Sep 2008 12:47:16 +1000 (EST)","from ms5.sony.co.jp (ms5.Sony.CO.JP [211.125.136.201])\n\t(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\n\t(Client did not present a certificate)\n\tby ozlabs.org (Postfix) with ESMTPS id 63710DDED7\n\tfor <cbe-oss-dev@ozlabs.org>; Thu, 18 Sep 2008 12:46:49 +1000 (EST)","from mta8.sony.co.jp (mta8.Sony.CO.JP [137.153.71.15])\n\tby ms5.sony.co.jp (R8/Sony) with ESMTP id m8I2kdKs015488\n\tfor <cbe-oss-dev@ozlabs.org>; Thu, 18 Sep 2008 11:46:39 +0900 (JST)","from mta8.sony.co.jp (localhost [127.0.0.1])\n\tby mta8.sony.co.jp (R8/Sony) with ESMTP id m8I2kdTW022533\n\tfor <cbe-oss-dev@ozlabs.org>; Thu, 18 Sep 2008 11:46:39 +0900 (JST)","from ibex.sm.sony.co.jp ([43.4.142.104])\n\tby mta8.sony.co.jp (R8/Sony) with ESMTP id m8I2kdAL022528\n\tfor <cbe-oss-dev@ozlabs.org>; Thu, 18 Sep 2008 11:46:39 +0900 (JST)","from [192.168.99.230] ([43.24.196.155]) (authenticated bits=0)\n\tby ibex.sm.sony.co.jp (8.13.1/8.13.1) with ESMTP id m8I2kavJ019210;\n\tThu, 18 Sep 2008 11:46:37 +0900"],"Message-ID":"<48D1C10A.5070302@sm.sony.co.jp>","Date":"Thu, 18 Sep 2008 11:46:34 +0900","From":"Kazunori Asayama <asayama@sm.sony.co.jp>","User-Agent":"Thunderbird 2.0.0.16 (Windows/20080708)","MIME-Version":"1.0","To":"Yuji Mano <yuji.mano@am.sony.com>","References":"<48C972C3.2060906@am.sony.com> <48D15FBE.4050506@am.sony.com>","In-Reply-To":"<48D15FBE.4050506@am.sony.com>","Cc":"CBE Development <cbe-oss-dev@ozlabs.org>","Subject":"Re: [Cbe-oss-dev] [PATCH 02/11 v2]MARS: Workload queue block\n\treplace bit 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"}}]