[Cbe-oss-dev] [PATCH 20/23]MARS/task: optimize context switch

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


This patch optimizes the task context switch by only loading the task elf's
text segment only if it's not cached in MPU storage. Also the text segment is no
longer saved during a context switch as it is readonly and does not change.

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

--- a/task/src/mpu/module/task_module.c
+++ b/task/src/mpu/module/task_module.c
@@ -96,8 +96,8 @@ static void dma(void *ls, uint64_t ea, i
 
 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,
+	/* save or restore data segment and heap (low address) */
+	dma((void *)task->data_vaddr, task->context_save_area_ea,
 	    low_size, put);
 
 	/* save or restore stack (high address) */
@@ -229,7 +229,7 @@ static void __attribute__((noinline)) co
 	/* save context MPU storage state */
 	task->context_save_area_low_size =
 		((uintptr_t)task_heap -
-		 MARS_TASK_BASE_ADDR + MARS_TASK_MODULE_DMA_SIZE_MASK) &
+		 task->data_vaddr + MARS_TASK_MODULE_DMA_SIZE_MASK) &
 		~MARS_TASK_MODULE_DMA_SIZE_MASK;
 
 	task->context_save_area_high_size =
@@ -416,15 +416,10 @@ static struct mars_task_module_syscalls 
 	mars_module_dma_wait
 };
 
-static void context_start(int task_cached)
+static void context_start(void)
 {
 	__vector unsigned char *bss_ptr, *bss_end;
 
-	/* only reload the readonly text segment if different from cached */
-	if (!task_cached)
-		dma((void *)task->text_vaddr,
-		    task->text_ea, task->text_size, 0);
-
 	/* load the read-write data segment */
 	dma((void *)task->data_vaddr, task->data_ea, task->data_size, 0);
 
@@ -461,9 +456,14 @@ void mars_module_main(void)
 	task_cached = mars_module_workload_query(mars_module_get_workload_id(),
 						 MARS_QUERY_IS_CACHED);
 
+	/* only reload the readonly text segment if different from cached */
+	if (!task_cached)
+		dma((void *)MARS_TASK_BASE_ADDR,
+		    task->text_ea, task->text_size, 0);
+
 	/* if stack pointer is uninitialized run fresh, otherwise resume */
 	if (!task->stack)
-		context_start(task_cached);
+		context_start();
 	else
 		context_resume(task_cached);
 






More information about the cbe-oss-dev mailing list