[Cbe-oss-dev] [PATCH 22/28]MARS/task: module wrap syscalls with inline functions

Yuji Mano yuji.mano at am.sony.com
Fri Feb 6 13:32:52 EST 2009


Create static inline function wrappers for calling the task module syscalls
for cleaner and more convenient module API.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/src/mpu/lib/Makefile.am       |    2 
 task/src/mpu/lib/task.c            |   34 +++++++--------
 task/src/mpu/lib/task_barrier.c    |   16 +++----
 task/src/mpu/lib/task_event_flag.c |   10 +---
 task/src/mpu/lib/task_queue.c      |   29 +++++--------
 task/src/mpu/lib/task_semaphore.c  |    7 +--
 task/src/mpu/lib/task_signal.c     |    8 +--
 task/src/mpu/module/task_module.h  |   82 +++++++++++++++++++++++++++++++++----
 8 files changed, 122 insertions(+), 66 deletions(-)

--- a/task/src/mpu/lib/Makefile.am
+++ b/task/src/mpu/lib/Makefile.am
@@ -45,7 +45,7 @@ if DEBUG
  CFLAGS += -O0
 else
  extra_cppflags += "-DNDEBUG"
- CFLAGS += -Os
+ CFLAGS += -Os --param max-inline-insns-single=20
 endif
 
 if MARS_PLATFORM_CELL
--- a/task/src/mpu/lib/task.c
+++ b/task/src/mpu/lib/task.c
@@ -56,13 +56,13 @@ int main(const struct mars_task_args *ar
 	mars_task_module_syscalls = module_syscalls;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* call task main function and store return value in task context */
 	task->exit_code = mars_task_main(args);
 
 	/* exit */
-	(*mars_task_module_syscalls->exit)();
+	mars_task_module_exit();
 
 	return MARS_SUCCESS;
 }
@@ -72,13 +72,13 @@ void mars_task_exit(int32_t exit_code)
 	struct mars_task_context *task;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* store exit code in task context */
 	task->exit_code = exit_code;
 
 	/* exit */
-	(*mars_task_module_syscalls->exit)();
+	mars_task_module_exit();
 }
 
 int mars_task_yield(void)
@@ -86,13 +86,13 @@ int mars_task_yield(void)
 	struct mars_task_context *task;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
 		return MARS_ERROR_FORMAT;
 
-	(*mars_task_module_syscalls->yield)(mars_task_get_heap());
+	mars_task_module_yield(mars_task_module_get_heap());
 
 	return MARS_SUCCESS;
 }
@@ -104,8 +104,7 @@ int mars_task_schedule(struct mars_task_
 	if (!id)
 		return MARS_ERROR_NULL;
 
-	return (*mars_task_module_syscalls->schedule)(id->workload_id, args,
-		priority);
+	return mars_task_module_schedule(id->workload_id, args, priority);
 }
 
 int mars_task_wait(struct mars_task_id *id, int32_t *exit_code)
@@ -117,19 +116,18 @@ int mars_task_wait(struct mars_task_id *
 		return MARS_ERROR_NULL;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
 		return MARS_ERROR_FORMAT;
 
-	(*mars_task_module_syscalls->wait)(id->workload_id,
-					   mars_task_get_heap());
+	mars_task_module_wait(id->workload_id, mars_task_module_get_heap());
 
 	/* exit code requested so get it from the task context and return it */
 	if (exit_code) {
 		task = (struct mars_task_context *)
-			(*mars_task_module_syscalls->get_task_by_id)(id);
+			mars_task_module_get_task_by_id(id);
 		if (!task)
 			return MARS_ERROR_INTERNAL;
 
@@ -147,12 +145,12 @@ int mars_task_try_wait(struct mars_task_
 	if (!id)
 		return MARS_ERROR_NULL;
 
-	(*mars_task_module_syscalls->try_wait)(id->workload_id);
+	mars_task_module_try_wait(id->workload_id);
 
 	/* exit code requested so get it from the task context and return it */
 	if (exit_code) {
 		task = (struct mars_task_context *)
-			(*mars_task_module_syscalls->get_task_by_id)(id);
+			mars_task_module_get_task_by_id(id);
 		if (!task)
 			return MARS_ERROR_INTERNAL;
 
@@ -164,19 +162,19 @@ int mars_task_try_wait(struct mars_task_
 
 uint32_t mars_task_get_ticks(void)
 {
-	return (*mars_task_module_syscalls->get_ticks)();
+	return mars_task_module_get_ticks();
 }
 
 uint32_t mars_task_get_kernel_id(void)
 {
-	return (*mars_task_module_syscalls->get_kernel_id)();
+	return mars_task_module_get_kernel_id();
 }
 
 const struct mars_task_id *mars_task_get_id(void)
 {
 	struct mars_task_context *task;
 
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	return &task->id;
 }
@@ -185,7 +183,7 @@ const char *mars_task_get_name(void)
 {
 	struct mars_task_context *task;
 
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	return task->id.name[0] ? (const char *)task->id.name : NULL;
 }
--- a/task/src/mpu/lib/task_barrier.c
+++ b/task/src/mpu/lib/task_barrier.c
@@ -61,7 +61,7 @@ static int notify(uint64_t barrier_ea, i
 		return MARS_ERROR_ALIGN;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -91,10 +91,10 @@ static int notify(uint64_t barrier_ea, i
 		barrier.notify_wait_count++;
 
 		mars_mutex_unlock_put(barrier_ea,
-			(struct mars_mutex *)&barrier);
+				      (struct mars_mutex *)&barrier);
 
 		/* wait for signal */
-		(*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+		mars_task_module_signal_wait(mars_task_module_get_heap());
 
 		mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 	}
@@ -106,8 +106,7 @@ static int notify(uint64_t barrier_ea, i
 	if (barrier.notified_count == barrier.total) {
 		/* signal all task ids in wait list */
 		for (i = 0; i < barrier.wait_count; i++)
-			(*mars_task_module_syscalls->signal_send)
-				(barrier.wait_id[i]);
+			mars_task_module_signal_send(barrier.wait_id[i]);
 		barrier.wait_count = 0;
 	}
 
@@ -138,7 +137,7 @@ static int wait(uint64_t barrier_ea, int
 		return MARS_ERROR_ALIGN;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
@@ -170,7 +169,7 @@ static int wait(uint64_t barrier_ea, int
 				      (struct mars_mutex *)&barrier);
 
 		/* wait for signal */
-		(*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+		mars_task_module_signal_wait(mars_task_module_get_heap());
 
 		mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 	}
@@ -185,8 +184,7 @@ static int wait(uint64_t barrier_ea, int
 
 		/* signal all task ids in notify wait list */
 		for (i = 0; i < barrier.notify_wait_count; i++)
-			(*mars_task_module_syscalls->signal_send)
-				(barrier.notify_wait_id[i]);
+			mars_task_module_signal_send(barrier.notify_wait_id[i]);
 		barrier.notify_wait_count = 0;
 	}
 
--- a/task/src/mpu/lib/task_event_flag.c
+++ b/task/src/mpu/lib/task_event_flag.c
@@ -99,8 +99,7 @@ int mars_task_event_flag_set(uint64_t ev
 	/* signal the waiting host */
 	if (event_flag.direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU &&
 	    event_flag.direction != MARS_TASK_EVENT_FLAG_MPU_TO_MPU)
-		(*mars_task_module_syscalls->signal_host)(
-			event_flag_ea +
+		mars_task_module_signal_host(event_flag_ea +
 			offsetof(struct mars_task_event_flag, bits));
 
 	/* search through wait list for tasks to be signalled */
@@ -119,8 +118,7 @@ int mars_task_event_flag_set(uint64_t ev
 		}
 
 		/* signal the waiting tasks */
-		(*mars_task_module_syscalls->signal_send)
-			(event_flag.wait_id[i]);
+		mars_task_module_signal_send(event_flag.wait_id[i]);
 
 		/* flush id from wait list */
 		event_flag.wait_count--;
@@ -157,7 +155,7 @@ static int wait(uint64_t event_flag_ea,u
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -211,7 +209,7 @@ static int wait(uint64_t event_flag_ea,u
 				      (struct mars_mutex *)&event_flag);
 
 		/* wait for signal */
-		(*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+		mars_task_module_signal_wait(mars_task_module_get_heap());
 
 		mars_mutex_lock_get(event_flag_ea,
 				    (struct mars_mutex *)&event_flag);
--- a/task/src/mpu/lib/task_queue.c
+++ b/task/src/mpu/lib/task_queue.c
@@ -89,13 +89,12 @@ int mars_task_queue_clear(uint64_t queue
 	if (queue.count == queue.depth &&
 	    queue.direction != MARS_TASK_QUEUE_MPU_TO_HOST &&
 	    queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU)
-		(*mars_task_module_syscalls->signal_host)(
-			queue_ea + offsetof(struct mars_task_queue, count));
+		mars_task_module_signal_host(queue_ea +
+			offsetof(struct mars_task_queue, count));
 
 	/* signal all waiting tasks that queue is ready for push */
 	for (i = 0; i < queue.push_wait_count; i++)
-		(*mars_task_module_syscalls->signal_send)
-			(queue.push_wait_id[i]);
+		mars_task_module_signal_send(queue.push_wait_id[i]);
 
 	/* flush all ids from push wait list */
 	queue.push_wait_count = 0;
@@ -116,14 +115,13 @@ static void push_update(uint64_t queue_e
 	if (queue.count == 0 &&
 	    queue.direction != MARS_TASK_QUEUE_HOST_TO_MPU &&
 	    queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU)
-		(*mars_task_module_syscalls->signal_host)(
-			queue_ea + offsetof(struct mars_task_queue, count));
+		mars_task_module_signal_host(queue_ea +
+			offsetof(struct mars_task_queue, count));
 
 	/* signal waiting task that queue is ready for pop */
 	if (queue.pop_wait_count) {
 		/* signal waiting task */
-		(*mars_task_module_syscalls->signal_send)
-			(queue.pop_wait_id[0]);
+		mars_task_module_signal_send(queue.pop_wait_id[0]);
 
 		/* flush id from pop wait list */
 		queue.pop_wait_count--;
@@ -159,7 +157,7 @@ static int push(uint64_t queue_ea, const
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -198,7 +196,7 @@ static int push(uint64_t queue_ea, const
 		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
 		/* wait for signal */
-		(*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+		mars_task_module_signal_wait(mars_task_module_get_heap());
 
 		mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 	}
@@ -270,14 +268,13 @@ static void pop_update(uint64_t queue_ea
 	if (queue.count == queue.depth &&
 	    queue.direction != MARS_TASK_QUEUE_MPU_TO_HOST &&
 	    queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU)
-		(*mars_task_module_syscalls->signal_host)(
-			queue_ea + offsetof(struct mars_task_queue, count));
+		mars_task_module_signal_host(queue_ea +
+			offsetof(struct mars_task_queue, count));
 
 	/* signal waiting task that queue is ready for push */
 	if (queue.push_wait_count) {
 		/* signal waiting task */
-		(*mars_task_module_syscalls->signal_send)
-			(queue.push_wait_id[0]);
+		mars_task_module_signal_send(queue.push_wait_id[0]);
 
 		/* flush id from push wait list */
 		queue.push_wait_count--;
@@ -313,7 +310,7 @@ static int pop(uint64_t queue_ea, void *
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -351,7 +348,7 @@ static int pop(uint64_t queue_ea, void *
 		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
 		/* wait for signal */
-		(*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+		mars_task_module_signal_wait(mars_task_module_get_heap());
 
 		mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 	}
--- a/task/src/mpu/lib/task_semaphore.c
+++ b/task/src/mpu/lib/task_semaphore.c
@@ -63,7 +63,7 @@ int mars_task_semaphore_acquire(uint64_t
 		return MARS_ERROR_ALIGN;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
@@ -87,7 +87,7 @@ int mars_task_semaphore_acquire(uint64_t
 				      (struct mars_mutex *)&semaphore);
 
 		/* wait for signal */
-		(*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+		mars_task_module_signal_wait(mars_task_module_get_heap());
 
 		return MARS_SUCCESS;
 	}
@@ -119,8 +119,7 @@ int mars_task_semaphore_release(uint64_t
 		semaphore.count--;
 
 		/* signal waiting task */
-		(*mars_task_module_syscalls->signal_send)
-			(semaphore.wait_id[0]);
+		mars_task_module_signal_send(semaphore.wait_id[0]);
 
 		/* flush id from wait list */
 		semaphore.wait_count--;
--- a/task/src/mpu/lib/task_signal.c
+++ b/task/src/mpu/lib/task_signal.c
@@ -50,7 +50,7 @@ int mars_task_signal_send(struct mars_ta
 	if (!id)
 		return MARS_ERROR_NULL;
 
-	return (*mars_task_module_syscalls->signal_send)(id->workload_id);
+	return mars_task_module_signal_send(id->workload_id);
 }
 
 int mars_task_signal_wait(void)
@@ -58,16 +58,16 @@ int mars_task_signal_wait(void)
 	struct mars_task_context *task;
 
 	/* get task context */
-	task = (*mars_task_module_syscalls->get_task)();
+	task = mars_task_module_get_task();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
 		return MARS_ERROR_FORMAT;
 
-	return (*mars_task_module_syscalls->signal_wait)(mars_task_get_heap());
+	return mars_task_module_signal_wait(mars_task_module_get_heap());
 }
 
 int mars_task_signal_try_wait(void)
 {
-	return (*mars_task_module_syscalls->signal_try_wait)();
+	return mars_task_module_signal_try_wait();
 }
--- a/task/src/mpu/module/task_module.h
+++ b/task/src/mpu/module/task_module.h
@@ -65,20 +65,86 @@ struct mars_task_module_syscalls {
 	int	(*signal_try_wait)(void);
 };
 
-/* This function must be linked not with 'task module' but with 'task'
- * to return task's heap.
- */
-static inline void *mars_task_get_heap(void)
-{
-	return sbrk(0);
-}
-
 #if defined(__cplusplus)
 extern "C" {
 #endif
 
 extern const struct mars_task_module_syscalls *mars_task_module_syscalls;
 
+static inline void *mars_task_module_get_heap(void)
+{
+	return sbrk(0);
+}
+
+static inline uint32_t mars_task_module_get_ticks(void)
+{
+	return (*mars_task_module_syscalls->get_ticks)();
+}
+
+static inline uint32_t mars_task_module_get_kernel_id(void)
+{
+	return (*mars_task_module_syscalls->get_kernel_id)();
+}
+
+static inline struct mars_task_context *mars_task_module_get_task(void)
+{
+	return (*mars_task_module_syscalls->get_task)();
+}
+
+static inline struct mars_task_context *mars_task_module_get_task_by_id
+						(struct mars_task_id *task_id)
+{
+	return (*mars_task_module_syscalls->get_task_by_id)(task_id);
+}
+
+static inline void mars_task_module_exit(void)
+{
+	(*mars_task_module_syscalls->exit)();
+}
+
+static inline void mars_task_module_yield(void *task_heap)
+{
+	(*mars_task_module_syscalls->yield)(task_heap);
+}
+
+static inline int mars_task_module_schedule(uint16_t workload_id,
+					    struct mars_task_args *args,
+					    uint8_t priority)
+{
+	return (*mars_task_module_syscalls->schedule)(workload_id, args,
+						      priority);
+}
+
+static inline int mars_task_module_wait(uint16_t workload_id, void *task_heap)
+{
+	return (*mars_task_module_syscalls->wait)(workload_id, task_heap);
+}
+
+static inline int mars_task_module_try_wait(uint16_t workload_id)
+{
+	return (*mars_task_module_syscalls->try_wait)(workload_id);
+}
+
+static inline int mars_task_module_signal_host(uint64_t watch_point_ea)
+{
+	return (*mars_task_module_syscalls->signal_host)(watch_point_ea);
+}
+
+static inline int mars_task_module_signal_send(uint16_t workload_id)
+{
+	return (*mars_task_module_syscalls->signal_send)(workload_id);
+}
+
+static inline int mars_task_module_signal_wait(void *task_heap)
+{
+	return (*mars_task_module_syscalls->signal_wait)(task_heap);
+}
+
+static inline int mars_task_module_signal_try_wait(void)
+{
+	return (*mars_task_module_syscalls->signal_try_wait)();
+}
+
 #if defined(__cplusplus)
 }
 #endif







More information about the cbe-oss-dev mailing list