[Cbe-oss-dev] [PATCH 05/22]MARS/base: Kernel cleanup

Yuji Mano yuji.mano at am.sony.com
Wed Jan 21 11:28:01 EST 2009


Clean up kernel implementation to reduce duplicate code for maintenance ease.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 base/src/mpu/kernel/kernel.c |   67 ++++++++++++++++++++++---------------------
 1 file changed, 35 insertions(+), 32 deletions(-)

--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -129,14 +129,21 @@ static struct mars_kernel_syscalls kerne
 	get_workload_queue_block
 };
 
-static void get_block(int block, struct mars_workload_queue_block *dst)
+static inline uint64_t get_block_ea(int block)
+{
+	return queue_header.queue_ea +
+	       offsetof(struct mars_workload_queue, block) +
+	       sizeof(struct mars_workload_queue_block) * block;
+}
+
+static inline void get_block(int block, struct mars_workload_queue_block *dst)
 {
 	mars_dma_get_and_wait(dst,
-		queue_header.queue_ea +
-		offsetof(struct mars_workload_queue, block) +
-		sizeof(struct mars_workload_queue_block) * block,
-		sizeof(struct mars_workload_queue_block),
-		MARS_DMA_TAG);
+			      queue_header.queue_ea +
+			      offsetof(struct mars_workload_queue, block) +
+			      sizeof(struct mars_workload_queue_block) * block,
+			      sizeof(struct mars_workload_queue_block),
+			      MARS_DMA_TAG);
 }
 
 static int search_block(int block)
@@ -193,22 +200,22 @@ static int search_block(int block)
 
 				wait_state =
 					MARS_BITS_GET(&p_wait_block->bits[id],
-					STATE);
+						      STATE);
 
 				/* check if workload is finished and reset */
 				if (wait_state ==
 					MARS_WORKLOAD_STATE_FINISHED) {
 					MARS_BITS_SET(bits, WAIT_ID,
-						MARS_WORKLOAD_ID_NONE);
+					     MARS_WORKLOAD_ID_NONE);
 					MARS_BITS_SET(bits, STATE,
-						MARS_WORKLOAD_STATE_READY);
+					     MARS_WORKLOAD_STATE_READY);
 				}
 			/* waiting for signal so check signal bit and reset */
 			} else if (signal == MARS_WORKLOAD_SIGNAL_ON) {
 				MARS_BITS_SET(bits, SIGNAL,
-					MARS_WORKLOAD_SIGNAL_OFF);
+					      MARS_WORKLOAD_SIGNAL_OFF);
 				MARS_BITS_SET(bits, STATE,
-					MARS_WORKLOAD_STATE_READY);
+					      MARS_WORKLOAD_STATE_READY);
 				i--;
 			}
 			break;
@@ -224,12 +231,7 @@ static int search_block(int block)
 static int reserve_block(int block)
 {
 	int index;
-	uint64_t block_ea;
-
-	/* calculate block ea */
-	block_ea = queue_header.queue_ea +
-		offsetof(struct mars_workload_queue, block) +
-		sizeof(struct mars_workload_queue_block) * block;
+	uint64_t block_ea = get_block_ea(block);
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -238,11 +240,11 @@ static int reserve_block(int block)
 	if (index >= 0) {
 		/* update the current state of the workload */
 		MARS_BITS_SET(&queue_block.bits[index], STATE,
-			MARS_WORKLOAD_STATE_RUNNING);
+			      MARS_WORKLOAD_STATE_RUNNING);
 
 		/* reset the counter for reserved workload */
 		MARS_BITS_SET(&queue_block.bits[index], COUNTER,
-			MARS_WORKLOAD_COUNTER_MIN);
+			      MARS_WORKLOAD_COUNTER_MIN);
 	}
 
 	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);
@@ -252,9 +254,7 @@ static int reserve_block(int block)
 
 static void release_block(int block, int index)
 {
-	uint64_t block_ea = queue_header.queue_ea +
-		offsetof(struct mars_workload_queue, block) +
-		sizeof(struct mars_workload_queue_block) * block;
+	uint64_t block_ea = get_block_ea(block);
 
 	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
 
@@ -283,11 +283,12 @@ static int __attribute__((noinline)) res
 	/* set global workload info based on workload block and index */
 	workload_id = MARS_WORKLOAD_PER_BLOCK * block + index;
 	workload_ea = queue_header.context_ea +
-		workload_id * sizeof(struct mars_workload_context);
+		      workload_id * sizeof(struct mars_workload_context);
 
 	/* get the workload context code from workload queue */
 	mars_dma_get_and_wait(&workload, workload_ea,
-		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+			      sizeof(struct mars_workload_context),
+			      MARS_DMA_TAG);
 
 	return MARS_WORKLOAD_RESERVED;
 }
@@ -299,7 +300,8 @@ static void __attribute__((noinline)) re
 
 	/* put the workload context into workload queue */
 	mars_dma_put_and_wait(&workload, workload_ea,
-		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+			      sizeof(struct mars_workload_context),
+			      MARS_DMA_TAG);
 
 	/* release block reservation */
 	release_block(block, index);
@@ -311,10 +313,10 @@ static int __attribute__((noinline)) sch
 
 	/* get the workload queue header */
 	mars_dma_get_and_wait(&queue_header,
-		kernel_params.workload_queue_ea +
-		offsetof(struct mars_workload_queue, header),
-		sizeof(struct mars_workload_queue_header),
-		MARS_DMA_TAG);
+			      kernel_params.workload_queue_ea +
+			      offsetof(struct mars_workload_queue, header),
+			      sizeof(struct mars_workload_queue_header),
+			      MARS_DMA_TAG);
 
 	/* return exit status if exit flag is set from host */
 	if (queue_header.flag == MARS_WORKLOAD_QUEUE_FLAG_EXIT)
@@ -329,12 +331,13 @@ static int __attribute__((noinline)) sch
 
 	/* load the exec code into mpu storage from host storage */
 	mars_dma_get_and_wait((void *)MARS_WORKLOAD_MODULE_BASE_ADDR,
-		workload.module.exec_ea, workload.module.exec_size,
-		MARS_DMA_TAG);
+			      workload.module.exec_ea,
+			      workload.module.exec_size,
+			      MARS_DMA_TAG);
 
 	/* 0 the bss section */
 	memset((void *)MARS_WORKLOAD_MODULE_BASE_ADDR +
-		workload.module.exec_size, 0, workload.module.bss_size);
+	       workload.module.exec_size, 0, workload.module.bss_size);
 
 	/* save kernel stack pointer */
 	asm volatile (






More information about the cbe-oss-dev mailing list