[Cbe-oss-dev] [PATCH 18/23]MARS/task: module cleanup

Yuji Mano yuji.mano at am.sony.com
Sat Mar 14 12:19:00 EST 2009


This patch also cleans up the task module implementation to reduce redundant
code and also to prepare for following patches

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/src/mpu/module/task_module.c |  129 +++++++++++++++-----------------------
 1 file changed, 53 insertions(+), 76 deletions(-)

--- a/task/src/mpu/module/task_module.c
+++ b/task/src/mpu/module/task_module.c
@@ -55,7 +55,6 @@ void *__task_stack;
 
 /* global task variables */
 static struct mars_task_context *task;
-static int task_cached;
 
 /* task entry */
 typedef void (*mars_task_entry)(struct mars_task_args *args,
@@ -82,6 +81,33 @@ static struct mars_task_context *get_tas
 		mars_module_get_workload_by_id(task_id->workload_id);
 }
 
+static void dma_wait(void)
+{
+	mars_module_dma_wait(MARS_TASK_MODULE_DMA_TAG);
+}
+
+static void dma(void *ls, uint64_t ea, int size, int put)
+{
+	if (put)
+		mars_module_dma_put(ls, ea, size, MARS_TASK_MODULE_DMA_TAG);
+	else
+		mars_module_dma_get(ls, ea, size, MARS_TASK_MODULE_DMA_TAG);
+}
+
+static void dma_context(uint32_t low_size, uint32_t high_size, int put)
+{
+	/* save or restore text and heap (low address) */
+	dma((void *)MARS_TASK_BASE_ADDR, task->context_save_area_ea,
+	    low_size, put);
+
+	/* save or restore stack (high address) */
+	dma((void *)MARS_TASK_BASE_ADDR + MARS_TASK_CONTEXT_SAVE_SIZE_MAX -
+	    high_size, task->context_save_area_ea + low_size,
+	    high_size, put);
+
+	dma_wait();
+}
+
 static void registers_save(void)
 {
 	/* push non-volatile registers on to the workload stack */
@@ -192,68 +218,6 @@ static void registers_restore(void)
 		: : [ptr] "r" (__task_stack));
 }
 
-static void dma_context(int save, void *task_heap)
-{
-	uint32_t low_size, high_size;
-
-	/* save or restore context */
-	if (save) {
-		/* text, data and heap (low address) */
-		low_size =
-			(((uintptr_t)task_heap -
-			  MARS_TASK_BASE_ADDR +
-			  MARS_TASK_MODULE_DMA_SIZE_MASK) &
-			 ~MARS_TASK_MODULE_DMA_SIZE_MASK);
-
-		/* stack (high address) */
-		high_size =
-			((MARS_TASK_BASE_ADDR +
-			  MARS_TASK_CONTEXT_SAVE_SIZE_MAX -
-			  (uintptr_t)__task_stack +
-			  MARS_TASK_REGISTER_SAVE_AREA_SIZE +
-			  MARS_TASK_MODULE_DMA_SIZE_MASK) &
-			 ~MARS_TASK_MODULE_DMA_SIZE_MASK);
-
-		/* full context save/restore */
-		if (low_size + high_size >= MARS_TASK_CONTEXT_SAVE_SIZE_MAX) {
-			low_size = MARS_TASK_CONTEXT_SAVE_SIZE_MAX;
-			high_size = 0;
-		}
-
-		/* save save sizes to task context */
-		task->context_save_area_low_size = low_size;
-		task->context_save_area_high_size = high_size;
-
-		/* save text and heap (low address) */
-		mars_module_dma_put((void *)MARS_TASK_BASE_ADDR,
-				task->context_save_area_ea,
-				low_size, MARS_TASK_MODULE_DMA_TAG);
-
-		/* save stack (high address) */
-		mars_module_dma_put((void *)(MARS_TASK_BASE_ADDR +
-				MARS_TASK_CONTEXT_SAVE_SIZE_MAX - high_size),
-				task->context_save_area_ea + low_size,
-				high_size, MARS_TASK_MODULE_DMA_TAG);
-	} else {
-		/* restore save sizes from task context */
-		low_size = task->context_save_area_low_size;
-		high_size = task->context_save_area_high_size;
-
-		/* restore text and heap (low address) */
-		mars_module_dma_get((void *)MARS_TASK_BASE_ADDR,
-				task->context_save_area_ea,
-				low_size, MARS_TASK_MODULE_DMA_TAG);
-
-		/* restore stack (high address) */
-		mars_module_dma_get((void *)(MARS_TASK_BASE_ADDR +
-				MARS_TASK_CONTEXT_SAVE_SIZE_MAX - high_size),
-				task->context_save_area_ea + low_size,
-				high_size, MARS_TASK_MODULE_DMA_TAG);
-	}
-
-	mars_module_dma_wait(MARS_TASK_MODULE_DMA_TAG);
-}
-
 static void __attribute__((noinline)) context_save(void *task_heap)
 {
 	/* save registers state */
@@ -263,14 +227,27 @@ static void __attribute__((noinline)) co
 	task->stack = (uint32_t)__task_stack;
 
 	/* save context MPU storage state */
-	dma_context(1, task_heap);
+	task->context_save_area_low_size =
+		((uintptr_t)task_heap -
+		 MARS_TASK_BASE_ADDR + MARS_TASK_MODULE_DMA_SIZE_MASK) &
+		~MARS_TASK_MODULE_DMA_SIZE_MASK;
+
+	task->context_save_area_high_size =
+		(MARS_TASK_BASE_ADDR + MARS_TASK_CONTEXT_SAVE_SIZE_MAX -
+		 (uintptr_t)__task_stack + MARS_TASK_REGISTER_SAVE_AREA_SIZE +
+		 MARS_TASK_MODULE_DMA_SIZE_MASK) &
+		~MARS_TASK_MODULE_DMA_SIZE_MASK;
+
+	dma_context(task->context_save_area_low_size,
+		    task->context_save_area_high_size, 1);
 }
 
-static void __attribute__((noinline)) context_restore(void)
+static void __attribute__((noinline)) context_restore(int task_cached)
 {
 	/* if task not cashed restore context MPU storage state */
 	if (!task_cached)
-		dma_context(0, NULL);
+		dma_context(task->context_save_area_low_size,
+			    task->context_save_area_high_size, 0);
 
 	/* restore workload stack pointer */
 	__task_stack = (void *)task->stack;
@@ -296,12 +273,12 @@ static void __attribute__((noinline)) co
 	mars_module_workload_wait();
 }
 
-static void __attribute__((noinline)) context_resume(void)
+static void __attribute__((noinline)) context_resume(int task_cached)
 {
 	register void *sp asm("$sp");
 
 	/* restore task context */
-	context_restore();
+	context_restore(task_cached);
 
 	/* restore task stack pointer */
 	sp = __task_stack;
@@ -439,18 +416,17 @@ static struct mars_task_module_syscalls 
 	mars_module_dma_wait
 };
 
-static void context_start(void)
+static void context_start(int task_cached)
 {
 	__vector unsigned char *bss_ptr, *bss_end;
 
 	/* only reload the readonly text segment if different from cached */
 	if (!task_cached)
-		mars_module_dma_get((void *)task->text_vaddr, task->text_ea,
-				    task->text_size, MARS_TASK_MODULE_DMA_TAG);
+		dma((void *)task->text_vaddr,
+		    task->text_ea, task->text_size, 0);
 
 	/* load the read-write data segment */
-	mars_module_dma_get((void *)task->data_vaddr, task->data_ea,
-			    task->data_size, MARS_TASK_MODULE_DMA_TAG);
+	dma((void *)task->data_vaddr, task->data_ea, task->data_size, 0);
 
 	/* 0 the bss section */
 	bss_ptr = (__vector unsigned char *)(task->data_vaddr +
@@ -461,7 +437,7 @@ static void context_start(void)
 	while (bss_ptr < bss_end)
 		*bss_ptr++ = spu_splats((unsigned char)0);
 
-	mars_module_dma_wait(MARS_TASK_MODULE_DMA_TAG);
+	dma_wait();
 
 	/* sync before executing loaded code */
 	spu_sync();
@@ -473,6 +449,7 @@ static void context_start(void)
 void mars_module_main(void)
 {
 	register void *sp asm("$sp");
+	int task_cached;
 
 	/* save module stack pointer */
 	__module_stack = sp;
@@ -486,9 +463,9 @@ void mars_module_main(void)
 
 	/* if stack pointer is uninitialized run fresh, otherwise resume */
 	if (!task->stack)
-		context_start();
+		context_start(task_cached);
 	else
-		context_resume();
+		context_resume(task_cached);
 
 	/* we should never reach here */
 }






More information about the cbe-oss-dev mailing list