aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuji Mano <yuji.mano@am.sony.com>2009-01-20 16:28:01 -0800
committerYuji Mano <yuji.mano@am.sony.com>2009-01-23 10:59:17 -0800
commit0e920b4d794117dc3341eb29bd4cb69db6fc028b (patch)
tree49b5be13468aff98a3a284c8b497dc70f4babc79
parentc427278ba15443f4c699b082792900cc46ddbc05 (diff)
downloadmars-src-0e920b4d794117dc3341eb29bd4cb69db6fc028b.tar.gz
base: Kernel cleanup
Clean up kernel implementation to reduce duplicate code for maintenance ease. Signed-off-by: Yuji Mano <yuji.mano@am.sony.com> Acked-by: Kazunori Asayama <asayama@sm.sony.co.jp>
-rw-r--r--base/src/mpu/kernel/kernel.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/base/src/mpu/kernel/kernel.c b/base/src/mpu/kernel/kernel.c
index 0013909..ebae0ba 100644
--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -129,14 +129,21 @@ static struct mars_kernel_syscalls kernel_syscalls =
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)) reserve_workload(void)
/* 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)) release_workload(void)
/* 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)) scheduler(void)
/* 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)) scheduler(void)
/* 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 (