[Cbe-oss-dev] [PATCH 06/23]MARS/base: kernel shared buffer reduce code size

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


This is patch to share a 128-byte global buffer for use by multiple functions in
the kernel in order to keep code size and stack usage to a minimum.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/src/common/kernel_internal_types.h |   11 +++++++++++
 base/src/mpu/kernel/kernel.c            |   26 ++++++++++++++------------
 base/src/mpu/kernel/mutex.c             |    7 +++----
 3 files changed, 28 insertions(+), 16 deletions(-)

--- a/base/src/common/kernel_internal_types.h
+++ b/base/src/common/kernel_internal_types.h
@@ -42,6 +42,8 @@
 
 #include "mars/mutex_types.h"
 
+#include "workload_internal_types.h"
+
 #define MARS_KERNEL_ID_NONE			0xffff
 
 #define MARS_KERNEL_STATUS_BUSY			0x0
@@ -102,6 +104,15 @@ struct mars_kernel_params {
 	uint8_t pad[MARS_KERNEL_PARAMS_SIZE - 26];
 } __attribute__((aligned(MARS_KERNEL_PARAMS_ALIGN)));
 
+/* mars kernel buffer */
+union mars_kernel_buffer {
+	struct mars_mutex mutex;
+	struct mars_workload_queue_header workload_queue_header;
+	struct mars_workload_queue_block workload_queue_block;
+};
+
+extern union mars_kernel_buffer kernel_buffer;
+
 /* mars kernel mutex */
 int mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex);
 int mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex);
--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -49,6 +49,7 @@
 
 /* kernel */
 void *__kernel_stack;
+union mars_kernel_buffer kernel_buffer;
 static struct mars_kernel_params kernel_params;
 
 /* workload queue */
@@ -67,7 +68,7 @@ static struct mars_workload_context sche
 static uint16_t schedule_workload_id;
 
 /* workload module cached */
-static struct mars_workload_module cached_workload_module = {0, 0, 0, 0};
+static struct mars_workload_module cached_workload_module;
 
 /* workload module entry */
 typedef void (*module_entry)(
@@ -586,8 +587,7 @@ static int search_block(int block, int r
 		} 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;
-				struct mars_workload_queue_block *p_wait_block;
+				struct mars_workload_queue_block *wait_block;
 				uint8_t wait_state;
 
 				int bl = wait_id / MARS_WORKLOAD_PER_BLOCK;
@@ -595,22 +595,23 @@ static int search_block(int block, int r
 
 				/* check if workload id is in the same block */
 				if (block != bl) {
+					/* set pointer to check buffer block */
+					wait_block =
+					    &kernel_buffer.workload_queue_block;
+
 					/* fetch the necessary block */
-					dma_get(&wait_block, get_block_ea(bl),
+					dma_get(wait_block, get_block_ea(bl),
 						sizeof(wait_block),
 						MARS_KERNEL_DMA_TAG);
 					dma_wait(MARS_KERNEL_DMA_TAG);
-
-					/* set pointer to check fetched block */
-					p_wait_block = &wait_block;
 				} else {
 					/* set pointer to check current block */
-					p_wait_block = &queue_block;
+					wait_block = &queue_block;
 				}
 
 				/* get state of workload its waiting for */
 				wait_state =
-					MARS_BITS_GET(&p_wait_block->bits[id],
+					MARS_BITS_GET(&wait_block->bits[id],
 						      WORKLOAD_STATE);
 
 				/* check if workload is finished and reset */
@@ -839,7 +840,8 @@ static int scheduler(void)
 static void scheduler_idle_wait(void)
 {
 	int mask;
-	struct mars_workload_queue_header cur_queue_header;
+	struct mars_workload_queue_header *cur_queue_header =
+		&kernel_buffer.workload_queue_header;
 
 	/* save event mask */
 	mask = spu_read_event_mask();
@@ -848,11 +850,11 @@ static void scheduler_idle_wait(void)
 	spu_write_event_mask(MFC_LLR_LOST_EVENT);
 
 	/* get current atomic state of queue header */
-	mfc_getllar(&cur_queue_header, kernel_params.workload_queue_ea, 0, 0);
+	mfc_getllar(cur_queue_header, kernel_params.workload_queue_ea, 0, 0);
 	mfc_read_atomic_status();
 
 	/* check if queue header has been modified since we last fetched it */
-	if (!kernel_memcmp(&queue_header, &cur_queue_header,
+	if (!kernel_memcmp(&queue_header, cur_queue_header,
 			   sizeof(struct mars_workload_queue_header))) {
 		/* wait until queue header is modified */
 		spu_read_event_status();
--- a/base/src/mpu/kernel/mutex.c
+++ b/base/src/mpu/kernel/mutex.c
@@ -46,8 +46,6 @@
 #define MARS_MUTEX_STATE_NONE	0
 #define MARS_MUTEX_STATE_DONE	2
 
-static struct mars_mutex mutex_buffer;
-
 int mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex)
 {
 	int mask;
@@ -112,6 +110,7 @@ int mutex_lock_get(uint64_t mutex_ea, st
 int mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex)
 {
 	int status, mask;
+	struct mars_mutex *mutex_buffer = &kernel_buffer.mutex;
 
 	/* check function params */
 	if (!mutex_ea)
@@ -134,10 +133,10 @@ int mutex_unlock_put(uint64_t mutex_ea, 
 	spu_write_event_mask(MFC_LLR_LOST_EVENT);
 
 	do {
-		mfc_getllar(&mutex_buffer, mutex_ea, 0, 0);
+		mfc_getllar(mutex_buffer, mutex_ea, 0, 0);
 		mfc_read_atomic_status();
 
-		mutex->status = mutex_buffer.status;
+		mutex->status = mutex_buffer->status;
 		mutex->status.lock = MARS_MUTEX_UNLOCKED;
 
 		spu_dsync();






More information about the cbe-oss-dev mailing list