[Cbe-oss-dev] [PATCH 02/11 v2]MARS: Workload queue block replace bit fields

Kazunori Asayama asayama at sm.sony.co.jp
Thu Sep 18 12:46:34 EST 2008


Yuji Mano wrote:
> This replaces the bit fields usage for the workload queue block bits with
> explicit bitwise shift/mask operations for better portability.
> 
> Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
> 
> ---
> v2:
>  - remove explicit cast from MARS_BITS_GET macro
>  - avoid casting max_priority and max_counter to int inside scheduler
>  - remove unnecessary casting to void *
> 
>  include/common/mars/mars_workload_types.h |   46 +++++++---
>  src/host/lib/mars_workload_queue.c        |  134 ++++++++++++++++++------------
>  src/mpu/kernel/mars_kernel_scheduler.c    |   92 ++++++++++++--------
>  src/mpu/kernel/mars_kernel_workload.c     |   47 ++++++----
>  4 files changed, 203 insertions(+), 116 deletions(-)
> 
(snip)
> --- a/src/mpu/kernel/mars_kernel_scheduler.c
> +++ b/src/mpu/kernel/mars_kernel_scheduler.c
> @@ -65,42 +65,54 @@ static int search_block(int block)
>  {
>  	int i;
>  	int index = -1;
> -	int max_count = -1;
> -	int max_priority = -1;
> +	uint16_t max_counter;
> +	uint16_t max_priority;
>  
>  	/* search through workload queue for next workload to run
>  	 * while incrementing wait counter for all waiting workloads
>  	 * and pick the workload that has been waiting the longest
>  	 */
>  	for (i = 0; i < MARS_WORKLOAD_PER_BLOCK; i++) {
> -		struct mars_workload_queue_block_bits *bits
> -			= &queue_block.bits[i];
> +		uint64_t *bits = &queue_block.bits[i];
> +		uint8_t signal = MARS_BITS_GET(bits, SIGNAL);
> +		uint8_t priority = MARS_BITS_GET(bits, PRIORITY);
> +		uint16_t wait_id = MARS_BITS_GET(bits, WAIT_ID);
> +		uint16_t counter = MARS_BITS_GET(bits, COUNTER);
>  
> -		switch (bits->state) {
> +		switch (MARS_BITS_GET(bits, STATE)) {
>  		case MARS_WORKLOAD_STATE_READY:
> -			/* priority greater than max priority so select */
> -			if ((int)bits->priority > max_priority) {
> +			/* index not set yet so select */
> +			if (index < 0) {
>  				index = i;
> -				max_count = bits->counter;
> -				max_priority = bits->priority;
> -			/* priority equal and wait counter greater so select */
> -			} else if ((int)bits->priority == max_priority &&
> -				(int)bits->counter > max_count) {
> -				index = i;
> -				max_count = bits->counter;
> +				max_counter = counter;
> +				max_priority = priority;
> +			/* index set so compare priority and counter */
> +			} else {
> +				/* priority > max priority so select */
> +				if (priority > max_priority) {
> +					index = i;
> +					max_counter = counter;
> +					max_priority = priority;
> +				/* priority equal & counter greater so select */
> +				} else if (priority == max_priority &&
> +					counter > max_counter) {
> +					index = i;
> +					max_counter = counter;
> +				}
>  			}

So you can simply say:

	if (index < 0 ||
		priority > max_priority ||
		(priority == max_priority && counter > max_counter)) {
		index = i;
		max_counter = counter;
		max_priority = priority;
	}

-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t



More information about the cbe-oss-dev mailing list