[Cbe-oss-dev] [PATCH 07/23]MARS/base: kernel cleanup

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


This just removes some unecessary casting in the kernel and minor cosmetic
cleanups in prepartion for following patches.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/src/mpu/kernel/kernel.c |  135 ++++++++++++++++++++-----------------------
 1 file changed, 65 insertions(+), 70 deletions(-)

--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -76,16 +76,13 @@ typedef void (*module_entry)(
 
 static int kernel_memcmp(const void *s1, const void *s2, int size)
 {
-	unsigned char *ptr_1 = (unsigned char *)s1;
-	unsigned char *ptr_2 = (unsigned char *)s2;
-	unsigned char *ptr_e = (unsigned char *)ptr_1 + size;
+	const unsigned char *ptr_1 = (const unsigned char *)s1;
+	const unsigned char *ptr_2 = (const unsigned char *)s2;
+	const unsigned char *ptr_e = ptr_1 + size;
 
-	while (ptr_1 < ptr_e) {
-		if (*ptr_1 != *ptr_2)
+	while (ptr_1 < ptr_e)
+		if (*ptr_1++ != *ptr_2++)
 			return 1;
-		ptr_1++;
-		ptr_2++;
-	}
 
 	return 0;
 }
@@ -93,14 +90,11 @@ static int kernel_memcmp(const void *s1,
 static void kernel_memcpy(void *dst, const void *src, int size)
 {
 	unsigned char *ptr_1 = (unsigned char *)dst;
-	unsigned char *ptr_2 = (unsigned char *)src;
-	unsigned char *ptr_e = (unsigned char *)ptr_1 + size;
+	const unsigned char *ptr_2 = (const unsigned char *)src;
+	const unsigned char *ptr_e = ptr_1 + size;
 
-	while (ptr_1 < ptr_e) {
-		*ptr_1 = *ptr_2;
-		ptr_1++;
-		ptr_2++;
-	}
+	while (ptr_1 < ptr_e)
+		*ptr_1++ = *ptr_2++;
 }
 
 static uint32_t get_ticks(void)
@@ -143,28 +137,13 @@ static struct mars_workload_context *get
 		return &workload;
 
 	/* get the workload context from workload queue */
-	dma_get((void *)&ret_workload, get_workload_ea(id),
+	dma_get(&ret_workload, get_workload_ea(id),
 		sizeof(struct mars_workload_context), MARS_KERNEL_DMA_TAG);
 	dma_wait(MARS_KERNEL_DMA_TAG);
 
 	return &ret_workload;
 }
 
-static void __attribute__((noinline)) save_workload_state(uint8_t state)
-{
-	workload_state = state;
-}
-
-static void workload_exit(uint8_t state)
-{
-	register void *sp asm("$sp");
-
-	save_workload_state(state);
-
-	/* restore kernel stack pointer */
-	sp = __kernel_stack;
-}
-
 static uint64_t get_block_ea(int block)
 {
 	return queue_header.queue_ea +
@@ -272,36 +251,6 @@ static void update_header_bits_counter(i
 			 (struct mars_mutex *)&queue_header);
 }
 
-static int workload_query(uint16_t id, int query)
-{
-	uint64_t bits = get_block_bits(id);
-
-	switch (query) {
-	case MARS_QUERY_IS_CACHED:
-		return (id == workload_id && workload_cached);
-	case MARS_QUERY_IS_INITIALIZED:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) !=
-			MARS_WORKLOAD_STATE_NONE);
-	case MARS_QUERY_IS_READY:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
-			MARS_WORKLOAD_STATE_READY);
-	case MARS_QUERY_IS_WAITING:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
-			MARS_WORKLOAD_STATE_WAITING);
-	case MARS_QUERY_IS_RUNNING:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
-			MARS_WORKLOAD_STATE_RUNNING);
-	case MARS_QUERY_IS_FINISHED:
-		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
-			MARS_WORKLOAD_STATE_FINISHED);
-	case MARS_QUERY_IS_SIGNAL_SET:
-		return (MARS_BITS_GET(&bits, WORKLOAD_SIGNAL) ==
-			MARS_WORKLOAD_SIGNAL_ON);
-	}
-
-	return MARS_ERROR_PARAMS;
-}
-
 static int change_bits(uint16_t id,
 		       int (*check_bits)(uint64_t bits, uint64_t param),
 		       uint64_t check_bits_param,
@@ -379,6 +328,52 @@ static int change_state(uint16_t id,
 		           callback);
 }
 
+
+static void __attribute__((noinline)) save_workload_state(uint8_t state)
+{
+	workload_state = state;
+}
+
+static void workload_exit(uint8_t state)
+{
+	register void *sp asm("$sp");
+
+	save_workload_state(state);
+
+	/* restore kernel stack pointer */
+	sp = __kernel_stack;
+}
+
+static int workload_query(uint16_t id, int query)
+{
+	uint64_t bits = get_block_bits(id);
+
+	switch (query) {
+	case MARS_QUERY_IS_CACHED:
+		return (id == workload_id && workload_cached);
+	case MARS_QUERY_IS_INITIALIZED:
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) !=
+			MARS_WORKLOAD_STATE_NONE);
+	case MARS_QUERY_IS_READY:
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+			MARS_WORKLOAD_STATE_READY);
+	case MARS_QUERY_IS_WAITING:
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+			MARS_WORKLOAD_STATE_WAITING);
+	case MARS_QUERY_IS_RUNNING:
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+			MARS_WORKLOAD_STATE_RUNNING);
+	case MARS_QUERY_IS_FINISHED:
+		return (MARS_BITS_GET(&bits, WORKLOAD_STATE) ==
+			MARS_WORKLOAD_STATE_FINISHED);
+	case MARS_QUERY_IS_SIGNAL_SET:
+		return (MARS_BITS_GET(&bits, WORKLOAD_SIGNAL) ==
+			MARS_WORKLOAD_SIGNAL_ON);
+	}
+
+	return MARS_ERROR_PARAMS;
+}
+
 static uint64_t set_wait_id_bits(uint64_t bits, uint64_t id)
 {
 	MARS_BITS_SET(&bits, WORKLOAD_WAIT_ID, id);
@@ -449,7 +444,7 @@ static void schedule_begin_callback(uint
 	schedule_workload_id = id;
 
 	/* get the workload context from workload queue */
-	dma_get((void *)&schedule_workload, get_workload_ea(id),
+	dma_get(&schedule_workload, get_workload_ea(id),
 		sizeof(struct mars_workload_context), MARS_KERNEL_DMA_TAG);
 	dma_wait(MARS_KERNEL_DMA_TAG);
 }
@@ -682,7 +677,7 @@ static void notify_host_bits(uint64_t bl
 	host_signal_send(bits_ea);
 }
 
-static int reserve_workload(void)
+static int workload_reserve(void)
 {
 	int i;
 	int block = -1;
@@ -748,7 +743,7 @@ static int reserve_workload(void)
 	return MARS_KERNEL_STATUS_BUSY;
 }
 
-static void release_workload(void)
+static void workload_release(void)
 {
 	int block = workload_id / MARS_WORKLOAD_PER_BLOCK;
 	int index = workload_id % MARS_WORKLOAD_PER_BLOCK;
@@ -776,7 +771,7 @@ static void release_workload(void)
 		notify_host_bits(block_ea, index);
 }
 
-static void __attribute__((noinline)) run_workload(void)
+static void __attribute__((noinline)) workload_run(void)
 {
 	register void *sp asm("$sp");
 
@@ -787,7 +782,7 @@ static void __attribute__((noinline)) ru
 	((module_entry)workload.module.entry)(&kernel_syscalls);
 }
 
-static void load_workload_module(void)
+static void workload_module_load(void)
 {
 	__vector unsigned char *bss_ptr, *bss_end;
 
@@ -820,18 +815,18 @@ static void load_workload_module(void)
 
 static int scheduler(void)
 {
-	int status = reserve_workload();
+	int status = workload_reserve();
 
 	/* workload reserved */
 	if (status == MARS_KERNEL_STATUS_BUSY) {
 		/* load the workload module */
-		load_workload_module();
+		workload_module_load();
 
 		/* run workload */
-		run_workload();
+		workload_run();
 
 		/* release reservation of current workload */
-		release_workload();
+		workload_release();
 	}
 
 	return status;






More information about the cbe-oss-dev mailing list