[Cbe-oss-dev] [PATCH 1/5]base: kernel code size reduction

Yuji Mano yuji.mano at am.sony.com
Wed Mar 25 12:48:15 EST 2009


This patch further reduces the kernel code size by removing some unnecessary
error checks and also using logical bitwise operators for checking states and
flags.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/src/common/kernel_internal_types.h   |    2 
 base/src/common/workload_internal_types.h |   36 +++++++--------
 base/src/mpu/kernel/kernel.c              |   72 ++++++++----------------------
 base/src/mpu/lib/module.S                 |    6 +-
 4 files changed, 42 insertions(+), 74 deletions(-)

--- a/base/src/common/workload_internal_types.h
+++ b/base/src/common/workload_internal_types.h
@@ -46,11 +46,11 @@
 #define MARS_WORKLOAD_STATE_NONE		0x00	/* workload undefined */
 #define MARS_WORKLOAD_STATE_ADDING		0x01	/* adding now */
 #define MARS_WORKLOAD_STATE_REMOVING		0x02	/* removing now */
-#define MARS_WORKLOAD_STATE_SCHEDULING		0x03	/* scheduling now */
-#define MARS_WORKLOAD_STATE_READY		0x04	/* ready to schedule */
-#define MARS_WORKLOAD_STATE_WAITING		0x05	/* waiting for sync */
-#define MARS_WORKLOAD_STATE_RUNNING		0x06	/* currently running */
-#define MARS_WORKLOAD_STATE_FINISHED		0x07	/* not allow schedule */
+#define MARS_WORKLOAD_STATE_SCHEDULING		0x04	/* scheduling now */
+#define MARS_WORKLOAD_STATE_READY		0x08	/* ready to schedule */
+#define MARS_WORKLOAD_STATE_WAITING		0x10	/* waiting for sync */
+#define MARS_WORKLOAD_STATE_RUNNING		0x20	/* currently running */
+#define MARS_WORKLOAD_STATE_FINISHED		0x40	/* not allow schedule */
 
 #define MARS_WORKLOAD_PRIORITY_MIN		0x00	/* minimum priority */
 #define MARS_WORKLOAD_PRIORITY_MAX		0xff	/* maximum priority */
@@ -111,24 +111,24 @@
 
 /*
  * MARS workload queue block workload bits (64-bits)
- * ----------------------------------------------------------------------------
- * |[63...60]|[59....52]|[51....36]|[35...33]|[  32  ]|[31.....16]|[15......0]|
- * ----------------------------------------------------------------------------
- * |  4-bits |  8-bits  |  16-bits |  3-bits |  1-bit |  16-bits  |  16-bits  |
- * ----------------------------------------------------------------------------
- * |  STATE  | PRIORITY |  COUNTER |   PAD   | SIGNAL |  WAIT_ID  | KERNEL_ID |
- * ----------------------------------------------------------------------------
+ * ------------------------------------------------------------------
+ * |[63...57]|[56....49]|[48....33]|[  32  ]|[31.....16]|[15......0]|
+ * ------------------------------------------------------------------
+ * |  7-bits |  8-bits  |  16-bits |  1-bit |  16-bits  |  16-bits  |
+ * ------------------------------------------------------------------
+ * |  STATE  | PRIORITY |  COUNTER | SIGNAL |  WAIT_ID  | KERNEL_ID |
+ * ------------------------------------------------------------------
  */
-#define MARS_BITS_SHIFT_WORKLOAD_STATE		60
-#define MARS_BITS_SHIFT_WORKLOAD_PRIORITY	52
-#define MARS_BITS_SHIFT_WORKLOAD_COUNTER	36
+#define MARS_BITS_SHIFT_WORKLOAD_STATE		57
+#define MARS_BITS_SHIFT_WORKLOAD_PRIORITY	49
+#define MARS_BITS_SHIFT_WORKLOAD_COUNTER	33
 #define MARS_BITS_SHIFT_WORKLOAD_SIGNAL		32
 #define MARS_BITS_SHIFT_WORKLOAD_WAIT_ID	16
 #define MARS_BITS_SHIFT_WORKLOAD_KERNEL_ID	0
 
-#define MARS_BITS_MASK_WORKLOAD_STATE		0xf000000000000000ULL
-#define MARS_BITS_MASK_WORKLOAD_PRIORITY	0x0ff0000000000000ULL
-#define MARS_BITS_MASK_WORKLOAD_COUNTER		0x000ffff000000000ULL
+#define MARS_BITS_MASK_WORKLOAD_STATE		0xfe00000000000000ULL
+#define MARS_BITS_MASK_WORKLOAD_PRIORITY	0x01fe000000000000ULL
+#define MARS_BITS_MASK_WORKLOAD_COUNTER		0x0001fffe00000000ULL
 #define MARS_BITS_MASK_WORKLOAD_SIGNAL		0x0000000100000000ULL
 #define MARS_BITS_MASK_WORKLOAD_WAIT_ID		0x00000000ffff0000ULL
 #define MARS_BITS_MASK_WORKLOAD_KERNEL_ID	0x000000000000ffffULL
--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -66,7 +66,6 @@ static uint8_t workload_is_cached;

 /* workload to schedule */
 static struct mars_workload_context schedule_workload;
-static uint16_t schedule_workload_id;

 /* workload module */
 static struct mars_workload_module cached_workload_module;
@@ -204,7 +203,7 @@ static void update_header_bits(int block
 		uint8_t state = MARS_BITS_GET(bits, WORKLOAD_STATE);
 
 		/* workload state is ready so check priority */
-		if (state == MARS_WORKLOAD_STATE_READY) {
+		if (state & MARS_WORKLOAD_STATE_READY) {
 			uint8_t priority = MARS_BITS_GET(bits,
 							 WORKLOAD_PRIORITY);
 
@@ -214,7 +213,7 @@ static void update_header_bits(int block
 
 			/* set block ready bit in header bits for block */
 			block_ready = MARS_WORKLOAD_BLOCK_READY_ON;
-		} else if (state == MARS_WORKLOAD_STATE_WAITING) {
+		} else if (state & MARS_WORKLOAD_STATE_WAITING) {
 			/* set block waiting bit in header bits for block */
 			block_waiting = MARS_WORKLOAD_BLOCK_WAITING_ON;
 		}
@@ -348,22 +347,21 @@ static int workload_query(uint16_t id, i
 	case MARS_WORKLOAD_QUERY_IS_CONTEXT_CACHED:
 		return (id == workload_id && workload_is_cached);
 	case MARS_WORKLOAD_QUERY_IS_INITIALIZED:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) !=
-			MARS_WORKLOAD_STATE_NONE);
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE));
 	case MARS_WORKLOAD_QUERY_IS_READY:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) &
 			MARS_WORKLOAD_STATE_READY);
 	case MARS_WORKLOAD_QUERY_IS_WAITING:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) &
 			MARS_WORKLOAD_STATE_WAITING);
 	case MARS_WORKLOAD_QUERY_IS_RUNNING:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) &
 			MARS_WORKLOAD_STATE_RUNNING);
 	case MARS_WORKLOAD_QUERY_IS_FINISHED:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) &
 			MARS_WORKLOAD_STATE_FINISHED);
 	case MARS_WORKLOAD_QUERY_IS_SIGNAL_SET:
-		return (MARS_BITS_GET(&bits, WORKLOAD_SIGNAL) ==
+		return (MARS_BITS_GET(&bits, WORKLOAD_SIGNAL) &
 			MARS_WORKLOAD_SIGNAL_ON);
 	}
 
@@ -379,9 +377,6 @@ static uint64_t set_wait_id_bits(uint64_
 
 static int workload_wait_set(uint16_t id)
 {
-	if (id == workload_id)
-		return MARS_ERROR_PARAMS;
-
 	return change_bits(workload_id,
 			   check_state_bits_not, MARS_WORKLOAD_STATE_NONE,
 			   set_wait_id_bits, id,
@@ -405,9 +400,6 @@ static uint64_t set_signal_bits(uint64_t
 
 static int workload_signal_set(uint16_t id)
 {
-	if (id == workload_id)
-		return MARS_ERROR_PARAMS;
-
 	return change_bits(id,
 			   check_state_bits_not, MARS_WORKLOAD_STATE_NONE,
 			   set_signal_bits, MARS_WORKLOAD_SIGNAL_ON,
@@ -436,9 +428,6 @@ static uint64_t set_schedule_bits(uint64
 
 static void schedule_begin_callback(uint16_t id)
 {
-	/* get id of workload to schedule */
-	schedule_workload_id = id;
-
 	/* get the workload context from workload queue */
 	dma_get(&schedule_workload, get_workload_ea(id),
 		MARS_WORKLOAD_CONTEXT_SIZE, MARS_KERNEL_DMA_TAG);
@@ -450,10 +439,6 @@ static int workload_schedule_begin(uint1
 {
 	int ret;
 
-	/* check function params */
-	if (id == workload_id)
-		return MARS_ERROR_PARAMS;
-
 	/* change bits necessary to begin scheduling */
 	ret = change_bits(id,
 			  check_state_bits, MARS_WORKLOAD_STATE_FINISHED,
@@ -471,9 +456,6 @@ static int workload_schedule_begin(uint1
 
 static void schedule_end_callback(uint16_t id)
 {
-	/* get id of workload to schedule */
-	schedule_workload_id = MARS_WORKLOAD_ID_NONE;
-
 	/* put the workload context into workload queue */
 	dma_put((void *)&schedule_workload, get_workload_ea(id),
 		MARS_WORKLOAD_CONTEXT_SIZE, MARS_KERNEL_DMA_TAG);
@@ -485,9 +467,6 @@ static void schedule_end_callback(uint16
 
 static int workload_schedule_end(uint16_t id)
 {
-	if (id != schedule_workload_id)
-		return MARS_ERROR_PARAMS;
-
 	return change_state(id,
 			    MARS_WORKLOAD_STATE_SCHEDULING,
 			    MARS_WORKLOAD_STATE_READY,
@@ -496,9 +475,6 @@ static int workload_schedule_end(uint16_
 
 static int workload_schedule_cancel(uint16_t id)
 {
-	if (id != schedule_workload_id)
-		return MARS_ERROR_PARAMS;
-
 	return change_state(id,
 			    MARS_WORKLOAD_STATE_SCHEDULING,
 			    MARS_WORKLOAD_STATE_FINISHED,
@@ -652,7 +628,7 @@ static int search_block(int block, int r
 		uint16_t counter = MARS_BITS_GET(bits, WORKLOAD_COUNTER);
 
 		/* found workload in ready state */
-		if (ready && state == MARS_WORKLOAD_STATE_READY) {
+		if (ready && (state & MARS_WORKLOAD_STATE_READY)) {
 			/* compare priority and counter with previous ones */
 			if (index < 0 || priority > max_priority ||
 			  (priority == max_priority && counter > max_counter)) {
@@ -666,7 +642,7 @@ static int search_block(int block, int r
 				MARS_BITS_SET(bits, WORKLOAD_COUNTER,
 					      counter + 1);
 		/* found workload in waiting state */
-		} else if (!ready && state == MARS_WORKLOAD_STATE_WAITING) {
+		} else if (!ready && (state & MARS_WORKLOAD_STATE_WAITING)) {
 			/* waiting for workload to finish so check status */
 			if (wait_id != MARS_WORKLOAD_ID_NONE) {
 				struct mars_workload_queue_block *wait_block;
@@ -697,8 +673,7 @@ static int search_block(int block, int r
 						      WORKLOAD_STATE);
 
 				/* check if workload is finished and reset */
-				if (wait_state ==
-				    MARS_WORKLOAD_STATE_FINISHED) {
+				if (wait_state & MARS_WORKLOAD_STATE_FINISHED) {
 					MARS_BITS_SET(bits, WORKLOAD_WAIT_ID,
 						MARS_WORKLOAD_ID_NONE);
 					MARS_BITS_SET(bits, WORKLOAD_STATE,
@@ -707,7 +682,7 @@ static int search_block(int block, int r
 					index = i;
 				}
 			/* waiting for signal so check signal bit and reset */
-			} else if (signal == MARS_WORKLOAD_SIGNAL_ON) {
+			} else if (signal & MARS_WORKLOAD_SIGNAL_ON) {
 				MARS_BITS_SET(bits, WORKLOAD_SIGNAL,
 					      MARS_WORKLOAD_SIGNAL_OFF);
 				MARS_BITS_SET(bits, WORKLOAD_STATE,
@@ -784,7 +759,7 @@ static int workload_reserve(void)
 	dma_wait(MARS_KERNEL_DMA_TAG);
 
 	/* return exit status if exit flag is set from host */
-	if (queue_header.flag == MARS_WORKLOAD_QUEUE_FLAG_EXIT)
+	if (queue_header.flag & MARS_WORKLOAD_QUEUE_FLAG_EXIT)
 		return MARS_KERNEL_STATUS_EXIT;
 
 	/* search workload queue header for highest priority ready block that
@@ -862,7 +837,7 @@ static void workload_release(void)
 	mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);
 
 	/* workload state is finished so notify host */
-	if (workload_state == MARS_WORKLOAD_STATE_FINISHED)
+	if (workload_state & MARS_WORKLOAD_STATE_FINISHED)
 		notify_host_bits(block_ea, index);
 }
 
@@ -989,7 +964,7 @@ static void get_params(void)
 		mfc_read_atomic_status();
 
 		/* host set the sync end flag so finish */
-		if (kernel_params.kernel_ticks.flag ==
+		if (kernel_params.kernel_ticks.flag &
 		    MARS_KERNEL_TICKS_FLAG_SYNC_END)
 			break;
 
--- a/base/src/mpu/lib/module.S
+++ b/base/src/mpu/lib/module.S
@@ -62,9 +62,9 @@
 #define dma_wait			88
 
 /* NOTE: Value of defines must equal defines in workload_internal_types.h */
-#define WORKLOAD_EXIT_STATE_READY	0x04 /* MARS_WORKLOAD_STATE_READY */
-#define WORKLOAD_EXIT_STATE_WAITING	0x05 /* MARS_WORKLOAD_STATE_WAITING */
-#define WORKLOAD_EXIT_STATE_FINISHED	0x07 /* MARS_WORKLOAD_STATE_FINISHED */
+#define WORKLOAD_EXIT_STATE_READY	0x08 /* MARS_WORKLOAD_STATE_READY */
+#define WORKLOAD_EXIT_STATE_WAITING	0x10 /* MARS_WORKLOAD_STATE_WAITING */
+#define WORKLOAD_EXIT_STATE_FINISHED	0x40 /* MARS_WORKLOAD_STATE_FINISHED */
 
 
 .section .bss






More information about the cbe-oss-dev mailing list