[Cbe-oss-dev] [PATCH 09/10]MARS/modules: Task update implementation

Yuji Mano yuji.mano at am.sony.com
Fri Nov 21 11:06:59 EST 2008


This updates the task source implementation inside the new task module library.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 modules/task/include/common/mars/task_types.h |    6 +-
 modules/task/src/common/task_internal_types.h |   27 +++++-----
 modules/task/src/host/lib/task.c              |   69 +++++++++++++++-----------
 modules/task/src/host/lib/task_barrier.c      |    9 +--
 modules/task/src/host/lib/task_event_flag.c   |   12 ++--
 modules/task/src/host/lib/task_queue.c        |   12 ++--
 modules/task/src/host/lib/task_semaphore.c    |    9 +--
 modules/task/src/host/lib/task_signal.c       |   10 +--
 modules/task/src/mpu/lib/task.c               |   68 +++++++++++++++----------
 modules/task/src/mpu/lib/task_barrier.c       |   26 +++++----
 modules/task/src/mpu/lib/task_event_flag.c    |   27 ++++------
 modules/task/src/mpu/lib/task_queue.c         |   38 +++++++-------
 modules/task/src/mpu/lib/task_semaphore.c     |   24 ++++-----
 modules/task/src/mpu/lib/task_signal.c        |   18 +++---
 14 files changed, 190 insertions(+), 165 deletions(-)

--- a/modules/task/include/common/mars/task_types.h
+++ b/modules/task/include/common/mars/task_types.h
@@ -48,15 +48,15 @@
 
 /**
  * \ingroup group_mars_task
- * \brief Base address of task elf
+ * \brief Virtual Address of task elf
  */
-#define MARS_TASK_BASE_ADDR			0x10000
+#define MARS_TASK_ELF_VADDR			0x20000
 
 /**
  * \ingroup group_mars_task
  * \brief Max size of context save area
  */
-#define MARS_TASK_CONTEXT_SAVE_SIZE_MAX		0x30000
+#define MARS_TASK_CONTEXT_SAVE_SIZE_MAX		0x20000
 
 /**
  * \ingroup group_mars_task
--- a/modules/task/src/common/task_internal_types.h
+++ b/modules/task/src/common/task_internal_types.h
@@ -40,6 +40,8 @@
 
 #include <stdint.h>
 
+#include "mars/workload_types.h"
+
 #define MARS_TASK_CONTEXT_SIZE				128
 #define MARS_TASK_CONTEXT_ALIGN				16
 #define MARS_TASK_CONTEXT_SAVE_ALIGN			128
@@ -49,18 +51,19 @@
 #define MARS_TASK_CONTEXT_SAVE_UNIT_SIZE_ALIGN_MASK	0xf
 
 struct mars_task_context {
-	struct mars_task_id id;		/* task id */
-	struct mars_task_args args;	/* task args */
-	uint64_t exec_ea;		/* ea of exec */
-	uint32_t exec_size;		/* size of text and data of exec */
-	uint32_t bss_size;		/* size of bss in memory of exec */
-	uint32_t vaddr;			/* vaddr address of exec */
-	uint32_t entry;			/* entry address of exec */
-	uint32_t stack;			/* stack pointer of exec */
-	int32_t exit_code;		/* exit code */
-	uint64_t context_save_area_ea;	/* ea of context save area */
-	uint64_t context_save_unit_ea;	/* ea of context save unit list */
-	uint8_t pad[16];		/* padding */
+	struct mars_workload_module module;	/* workload module */
+	struct mars_task_id id;			/* task id */
+	struct mars_task_args args;		/* task args */
+	uint64_t exec_ea;			/* ea of exec */
+	uint16_t exec_size;			/* text/data size of exec */
+	uint16_t bss_size;			/* bss size of exec */
+	uint32_t vaddr;				/* vaddr address of exec */
+	uint32_t entry;				/* entry address of exec */
+	uint32_t stack;				/* stack pointer of exec */
+	uint64_t context_save_area_ea;		/* context save area */
+	uint64_t context_save_unit_ea;		/* context save unit list */
+	int32_t exit_code;			/* exit code */
+	uint8_t pad[4];				/* padding */
 } __attribute__((aligned(MARS_TASK_CONTEXT_ALIGN)));
 
 #endif
--- a/modules/task/src/host/lib/task.c
+++ b/modules/task/src/host/lib/task.c
@@ -36,15 +36,19 @@
  */
 
 #include <elf.h>
+#include <libspe2.h>
 #include <string.h>
 
+#include <mars/context.h>
+#include <mars/core.h>
+#include <mars/error.h>
+#include <mars/workload_queue.h>
+
 #include "mars/task.h"
-#include "mars/core.h"
-#include "mars/error.h"
 
 #include "task_internal_types.h"
-#include "context_internal_types.h"
-#include "workload_queue.h"
+
+extern struct spe_program_handle mars_task_module_entry;
 
 const struct mars_task_context_save_unit mars_task_context_save_all[] =
 {
@@ -58,15 +62,17 @@ int mars_task_create(struct mars_context
 		const struct mars_task_context_save_unit *context_save_unit)
 {
 	int ret;
-	Elf32_Ehdr *ehdr;
-	Elf32_Phdr *phdr;
+
+	Elf32_Ehdr *ehdr_module, *ehdr_task;
+	Elf32_Phdr *phdr_module, *phdr_task;
+
 	uint16_t workload_id;
-	struct mars_task_context *task;
 	struct mars_workload_context *workload;
+	struct mars_task_context *task;
 
+	const struct mars_task_context_save_unit *p = context_save_unit;
 	int context_save_area_size = 0;
 	int context_save_unit_count = 1;
-	const struct mars_task_context_save_unit *p = context_save_unit;
 
 	/* check function params */
 	if (!mars)
@@ -79,12 +85,17 @@ int mars_task_create(struct mars_context
 		return MARS_ERROR_PARAMS;
 
 	/* process elf header information */
-	ehdr = (Elf32_Ehdr *)elf_image;
-	phdr = (Elf32_Phdr *)((void *)ehdr + ehdr->e_phoff);
-
-	if (phdr->p_type != PT_LOAD)
-		return MARS_ERROR_FORMAT;
-	if (phdr->p_vaddr != MARS_TASK_BASE_ADDR)
+	ehdr_module = (Elf32_Ehdr *)mars_task_module_entry.elf_image;
+	phdr_module = (Elf32_Phdr *)
+		((void *)ehdr_module + ehdr_module->e_phoff);
+
+	ehdr_task = (Elf32_Ehdr *)elf_image;
+	phdr_task = (Elf32_Phdr *)
+		((void *)ehdr_task + ehdr_task->e_phoff);
+
+	if (phdr_module->p_type != PT_LOAD || phdr_task->p_type != PT_LOAD ||
+		phdr_module->p_vaddr != MARS_WORKLOAD_MODULE_ELF_VADDR ||
+		phdr_task->p_vaddr != MARS_TASK_ELF_VADDR)
 		return MARS_ERROR_FORMAT;
 
 	/* begin process to add the task to the workload queue */
@@ -96,6 +107,21 @@ int mars_task_create(struct mars_context
 	/* cast workload context to task context */
 	task = (struct mars_task_context *)workload;
 
+	/* initialize the module elf parameters */
+	task->module.exec_ea =
+		mars_ptr_to_ea((void *)ehdr_module + phdr_module->p_offset);
+	task->module.exec_size = phdr_module->p_filesz;
+	task->module.bss_size = phdr_module->p_memsz - phdr_module->p_filesz;
+	task->module.entry = ehdr_module->e_entry;
+
+	/* initialize the task elf parameters */
+	task->exec_ea =
+		mars_ptr_to_ea((void *)ehdr_task + phdr_task->p_offset);
+	task->exec_size = phdr_task->p_filesz;
+	task->bss_size = phdr_task->p_memsz - phdr_task->p_filesz;
+	task->vaddr = phdr_task->p_vaddr;
+	task->entry = ehdr_task->e_entry;
+
 	/* initialize task id */
 	task->id.mars_context_ea = mars_ptr_to_ea(mars);
 	task->id.workload_id = workload_id;
@@ -104,13 +130,6 @@ int mars_task_create(struct mars_context
 	else
 		task->id.name[0] = 0;
 
-	/* initialize the elf parameters */
-	task->exec_ea = mars_ptr_to_ea((void *)ehdr + phdr->p_offset);
-	task->exec_size = phdr->p_filesz;
-	task->bss_size = phdr->p_memsz - phdr->p_filesz;
-	task->vaddr = phdr->p_vaddr;
-	task->entry = ehdr->e_entry;
-
 	/* no context save - run complete */
 	if (!context_save_unit) {
 		task->context_save_unit_ea = 0;
@@ -190,8 +209,6 @@ int mars_task_destroy(struct mars_task_i
 		return MARS_ERROR_NULL;
 	if (!id->mars_context_ea)
 		return MARS_ERROR_PARAMS;
-	if (!id->workload_id >= MARS_WORKLOAD_MAX)
-		return MARS_ERROR_PARAMS;
 
 	/* get mars context pointer from task id */
 	mars = mars_ea_to_ptr(id->mars_context_ea);
@@ -234,8 +251,6 @@ int mars_task_schedule(struct mars_task_
 		return MARS_ERROR_NULL;
 	if (!id->mars_context_ea)
 		return MARS_ERROR_PARAMS;
-	if (!id->workload_id >= MARS_WORKLOAD_MAX)
-		return MARS_ERROR_PARAMS;
 
 	/* get mars context pointer from task id */
 	mars = mars_ea_to_ptr(id->mars_context_ea);
@@ -274,8 +289,6 @@ int mars_task_wait(struct mars_task_id *
 		return MARS_ERROR_NULL;
 	if (!id->mars_context_ea)
 		return MARS_ERROR_PARAMS;
-	if (!id->workload_id >= MARS_WORKLOAD_MAX)
-		return MARS_ERROR_PARAMS;
 
 	/* get mars context pointer from task id */
 	mars = mars_ea_to_ptr(id->mars_context_ea);
@@ -307,8 +320,6 @@ int mars_task_try_wait(struct mars_task_
 		return MARS_ERROR_NULL;
 	if (!id->mars_context_ea)
 		return MARS_ERROR_PARAMS;
-	if (!id->workload_id >= MARS_WORKLOAD_MAX)
-		return MARS_ERROR_PARAMS;
 
 	/* get mars context pointer from task id */
 	mars = mars_ea_to_ptr(id->mars_context_ea);
--- a/modules/task/src/host/lib/task_barrier.c
+++ b/modules/task/src/host/lib/task_barrier.c
@@ -35,14 +35,13 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <mars/core.h>
+#include <mars/error.h>
+#include <mars/mutex.h>
+
 #include "mars/task_barrier.h"
-#include "mars/core.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
 
 #include "task_barrier_internal_types.h"
-#include "context_internal_types.h"
-#include "mutex_internal_types.h"
 
 int mars_task_barrier_create(struct mars_context *mars,
 				struct mars_task_barrier **barrier_ret,
--- a/modules/task/src/host/lib/task_event_flag.c
+++ b/modules/task/src/host/lib/task_event_flag.c
@@ -38,15 +38,15 @@
 #include <sched.h>
 #include <string.h>
 
+#include <mars/context.h>
+#include <mars/core.h>
+#include <mars/error.h>
+#include <mars/mutex.h>
+#include <mars/workload_queue.h>
+
 #include "mars/task_event_flag.h"
-#include "mars/core.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
 
 #include "task_event_flag_internal_types.h"
-#include "context_internal_types.h"
-#include "mutex_internal_types.h"
-#include "workload_queue.h"
 
 int mars_task_event_flag_create(struct mars_context *mars,
 				struct mars_task_event_flag **event_flag_ret,
--- a/modules/task/src/host/lib/task_queue.c
+++ b/modules/task/src/host/lib/task_queue.c
@@ -38,15 +38,15 @@
 #include <sched.h>
 #include <string.h>
 
+#include <mars/context.h>
+#include <mars/core.h>
+#include <mars/error.h>
+#include <mars/mutex.h>
+#include <mars/workload_queue.h>
+
 #include "mars/task_queue.h"
-#include "mars/core.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
 
 #include "task_queue_internal_types.h"
-#include "context_internal_types.h"
-#include "mutex_internal_types.h"
-#include "workload_queue.h"
 
 int mars_task_queue_create(struct mars_context *mars,
 				struct mars_task_queue **queue_ret,
--- a/modules/task/src/host/lib/task_semaphore.c
+++ b/modules/task/src/host/lib/task_semaphore.c
@@ -37,14 +37,13 @@
 
 #include <stdlib.h>
 
+#include <mars/core.h>
+#include <mars/error.h>
+#include <mars/mutex.h>
+
 #include "mars/task_semaphore.h"
-#include "mars/core.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
 
 #include "task_semaphore_internal_types.h"
-#include "context_internal_types.h"
-#include "mutex_internal_types.h"
 
 int mars_task_semaphore_create(struct mars_context *mars,
 				struct mars_task_semaphore **semaphore_ret,
--- a/modules/task/src/host/lib/task_signal.c
+++ b/modules/task/src/host/lib/task_signal.c
@@ -35,12 +35,12 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
-#include "mars/task_signal.h"
-#include "mars/core.h"
-#include "mars/error.h"
+#include <mars/context.h>
+#include <mars/core.h>
+#include <mars/error.h>
+#include <mars/workload_queue.h>
 
-#include "context_internal_types.h"
-#include "workload_queue.h"
+#include "mars/task_signal.h"
 
 int mars_task_signal_send(struct mars_task_id *id)
 {
--- a/modules/task/src/mpu/lib/task.c
+++ b/modules/task/src/mpu/lib/task.c
@@ -35,25 +35,44 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
-#include <stdlib.h>
-
 #include "mars/task.h"
-#include "mars/task_types.h"
-#include "mars/error.h"
 
-#include "task_internal_types.h"
-#include "syscalls.h"
+#include "task_module.h"
+
+const struct mars_task_module_syscalls *mars_task_module_syscalls;
+
+int main(const struct mars_task_args *args,
+	const struct mars_task_module_syscalls *module_syscalls)
+{
+	struct mars_task_context *task;
+
+	/* save the module syscalls pointer */
+	mars_task_module_syscalls = module_syscalls;
+
+	/* get task context */
+	task = (*mars_task_module_syscalls->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)();
+
+	return MARS_SUCCESS;
+}
 
 void mars_task_exit(int32_t exit_code)
 {
 	struct mars_task_context *task;
 
-	task = (struct mars_task_context *)mars_get_workload();
+	/* get task context */
+	task = (*mars_task_module_syscalls->get_task)();
 
-	/* save the exit code in the task context */
+	/* store exit code in task context */
 	task->exit_code = exit_code;
 
-	mars_exit();
+	/* exit */
+	(*mars_task_module_syscalls->exit)();
 }
 
 int mars_task_yield(void)
@@ -61,13 +80,13 @@ int mars_task_yield(void)
 	struct mars_task_context *task;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
 		return MARS_ERROR_FORMAT;
 
-	mars_yield();
+	(*mars_task_module_syscalls->yield)();
 
 	return MARS_SUCCESS;
 }
@@ -79,12 +98,12 @@ int mars_task_schedule(struct mars_task_
 	if (!id)
 		return MARS_ERROR_NULL;
 
-	return mars_schedule(id->workload_id, args, priority);
+	return (*mars_task_module_syscalls->schedule)(id->workload_id, args,
+		priority);
 }
 
 int mars_task_wait(struct mars_task_id *id, int32_t *exit_code)
 {
-	int ret;
 	struct mars_task_context *task;
 
 	/* check function params */
@@ -92,22 +111,18 @@ int mars_task_wait(struct mars_task_id *
 		return MARS_ERROR_NULL;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
 		return MARS_ERROR_FORMAT;
 
-	ret = mars_wait(id->workload_id);
-	if (ret != MARS_SUCCESS)
-		return ret;
-
-	mars_signal_wait();
+	(*mars_task_module_syscalls->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_get_workload_by_id(id->workload_id);
+			(*mars_task_module_syscalls->get_task_by_id)(id);
 		if (!task)
 			return MARS_ERROR_INTERNAL;
 
@@ -119,21 +134,18 @@ int mars_task_wait(struct mars_task_id *
 
 int mars_task_try_wait(struct mars_task_id *id, int32_t *exit_code)
 {
-	int ret;
 	struct mars_task_context *task;
 
 	/* check function params */
 	if (!id)
 		return MARS_ERROR_NULL;
 
-	ret = mars_try_wait(id->workload_id);
-	if (ret != MARS_SUCCESS)
-		return ret;
+	(*mars_task_module_syscalls->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_get_workload_by_id(id->workload_id);
+			(*mars_task_module_syscalls->get_task_by_id)(id);
 		if (!task)
 			return MARS_ERROR_INTERNAL;
 
@@ -145,14 +157,14 @@ int mars_task_try_wait(struct mars_task_
 
 uint32_t mars_task_get_kernel_id(void)
 {
-	return mars_get_kernel_id();
+	return (*mars_task_module_syscalls->get_kernel_id)();
 }
 
 const struct mars_task_id *mars_task_get_id(void)
 {
 	struct mars_task_context *task;
 
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	return &task->id;
 }
@@ -161,7 +173,7 @@ const char *mars_task_get_name(void)
 {
 	struct mars_task_context *task;
 
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	return task->id.name[0] ? (const char *)task->id.name : NULL;
 }
--- a/modules/task/src/mpu/lib/task_barrier.c
+++ b/modules/task/src/mpu/lib/task_barrier.c
@@ -35,15 +35,15 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <mars/error.h>
+#include <mars/mutex.h>
+
 #include "mars/task_barrier.h"
 #include "mars/task_types.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
 
 #include "task_barrier_internal_types.h"
 #include "task_internal_types.h"
-#include "mutex_internal_types.h"
-#include "syscalls.h"
+#include "task_module.h"
 
 static struct mars_task_barrier barrier;
 
@@ -59,7 +59,7 @@ static int notify(uint64_t barrier_ea, i
 		return MARS_ERROR_ALIGN;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -85,14 +85,14 @@ static int notify(uint64_t barrier_ea, i
 
 		/* add id to wait list */
 		barrier.notify_wait_id[barrier.notify_wait_count] =
-			mars_get_workload_id();
+			task->id.workload_id;
 		barrier.notify_wait_count++;
 
 		mars_mutex_unlock_put(barrier_ea,
 			(struct mars_mutex *)&barrier);
 
 		/* wait for signal */
-		mars_signal_wait();
+		(*mars_task_module_syscalls->signal_wait)();
 
 		mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 	}
@@ -104,7 +104,8 @@ 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_signal_send(barrier.wait_id[i]);
+			(*mars_task_module_syscalls->signal_send)
+				(barrier.wait_id[i]);
 		barrier.wait_count = 0;
 	}
 
@@ -135,7 +136,7 @@ static int wait(uint64_t barrier_ea, int
 		return MARS_ERROR_ALIGN;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
@@ -160,14 +161,14 @@ static int wait(uint64_t barrier_ea, int
 		}
 
 		/* add id to wait list */
-		barrier.wait_id[barrier.wait_count] = mars_get_workload_id();
+		barrier.wait_id[barrier.wait_count] = task->id.workload_id;
 		barrier.wait_count++;
 
 		mars_mutex_unlock_put(barrier_ea,
 			(struct mars_mutex *)&barrier);
 
 		/* wait for signal */
-		mars_signal_wait();
+		(*mars_task_module_syscalls->signal_wait)();
 
 		mars_mutex_lock_get(barrier_ea, (struct mars_mutex *)&barrier);
 	}
@@ -182,7 +183,8 @@ 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_signal_send(barrier.notify_wait_id[i]);
+			(*mars_task_module_syscalls->signal_send)
+				(barrier.notify_wait_id[i]);
 		barrier.notify_wait_count = 0;
 	}
 
--- a/modules/task/src/mpu/lib/task_event_flag.c
+++ b/modules/task/src/mpu/lib/task_event_flag.c
@@ -37,15 +37,15 @@
 
 #include <string.h>
 
+#include <mars/error.h>
+#include <mars/mutex.h>
+
 #include "mars/task_event_flag.h"
 #include "mars/task_types.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
 
 #include "task_event_flag_internal_types.h"
 #include "task_internal_types.h"
-#include "mutex_internal_types.h"
-#include "syscalls.h"
+#include "task_module.h"
 
 static struct mars_task_event_flag event_flag;
 
@@ -109,7 +109,8 @@ int mars_task_event_flag_set(uint64_t ev
 		}
 
 		/* signal the waiting tasks */
-		mars_signal_send(event_flag.wait_id[i]);
+		(*mars_task_module_syscalls->signal_send)
+			(event_flag.wait_id[i]);
 
 		/* flush id from wait list */
 		event_flag.wait_count--;
@@ -146,7 +147,7 @@ static int wait(uint64_t event_flag_ea,u
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -191,21 +192,19 @@ static int wait(uint64_t event_flag_ea,u
 
 		/* add id to wait list */
 		event_flag.wait_id[event_flag.wait_count]
-				= mars_get_workload_id();
-		event_flag.wait_mask[event_flag.wait_count]
-				= mask;
-		event_flag.wait_mask_mode[event_flag.wait_count]
-				= mask_mode;
+			= task->id.workload_id;
+		event_flag.wait_mask[event_flag.wait_count] = mask;
+		event_flag.wait_mask_mode[event_flag.wait_count] = mask_mode;
 		event_flag.wait_count++;
 
 		mars_mutex_unlock_put(event_flag_ea,
-				(struct mars_mutex *)&event_flag);
+			(struct mars_mutex *)&event_flag);
 
 		/* wait for signal */
-		mars_signal_wait();
+		(*mars_task_module_syscalls->signal_wait)();
 
 		mars_mutex_lock_get(event_flag_ea,
-				(struct mars_mutex *)&event_flag);
+			(struct mars_mutex *)&event_flag);
 	}
 
 	/* return bits if requested */
--- a/modules/task/src/mpu/lib/task_queue.c
+++ b/modules/task/src/mpu/lib/task_queue.c
@@ -37,16 +37,16 @@
 
 #include <string.h>
 
-#include "mars/task_queue.h"
+#include <mars/dma.h>
+#include <mars/error.h>
+#include <mars/mutex.h>
+
 #include "mars/task_types.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
+#include "mars/task_queue.h"
 
-#include "task_queue_internal_types.h"
 #include "task_internal_types.h"
-#include "mutex_internal_types.h"
-#include "syscalls.h"
-#include "dma.h"
+#include "task_queue_internal_types.h"
+#include "task_module.h"
 
 static struct mars_task_queue queue;
 
@@ -84,7 +84,8 @@ int mars_task_queue_clear(uint64_t queue
 
 	/* signal all waiting tasks that queue is ready for push */
 	for (i = 0; i < queue.push_wait_count; i++)
-		mars_signal_send(queue.push_wait_id[i]);
+		(*mars_task_module_syscalls->signal_send)
+			(queue.push_wait_id[i]);
 
 	/* flush all ids from push wait list */
 	queue.push_wait_count = 0;
@@ -104,7 +105,8 @@ static void push_update(void)
 	/* signal waiting task that queue is ready for pop */
 	if (queue.pop_wait_count) {
 		/* signal waiting task */
-		mars_signal_send(queue.pop_wait_id[0]);
+		(*mars_task_module_syscalls->signal_send)
+			(queue.pop_wait_id[0]);
 
 		/* flush id from pop wait list */
 		queue.pop_wait_count--;
@@ -139,7 +141,7 @@ static int push(uint64_t queue_ea, const
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -171,14 +173,14 @@ static int push(uint64_t queue_ea, const
 		}
 
 		/* add id to push wait list */
-		queue.push_wait_id[queue.push_wait_count]
-			= mars_get_workload_id();
+		queue.push_wait_id[queue.push_wait_count] =
+			task->id.workload_id;
 		queue.push_wait_count++;
 
 		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
 		/* wait for signal */
-		mars_signal_wait();
+		(*mars_task_module_syscalls->signal_wait)();
 
 		mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 	}
@@ -249,7 +251,8 @@ static void pop_update(void)
 	/* signal waiting task that queue is ready for push */
 	if (queue.push_wait_count) {
 		/* signal waiting task */
-		mars_signal_send(queue.push_wait_id[0]);
+		(*mars_task_module_syscalls->signal_send)
+			(queue.push_wait_id[0]);
 
 		/* flush id from push wait list */
 		queue.push_wait_count--;
@@ -284,7 +287,7 @@ static int pop(uint64_t queue_ea, void *
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea && !try)
@@ -316,14 +319,13 @@ static int pop(uint64_t queue_ea, void *
 		}
 
 		/* add id to pop wait list */
-		queue.pop_wait_id[queue.pop_wait_count]
-			= mars_get_workload_id();
+		queue.pop_wait_id[queue.pop_wait_count] = task->id.workload_id;
 		queue.pop_wait_count++;
 
 		mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
 		/* wait for signal */
-		mars_signal_wait();
+		(*mars_task_module_syscalls->signal_wait)();
 
 		mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 	}
--- a/modules/task/src/mpu/lib/task_semaphore.c
+++ b/modules/task/src/mpu/lib/task_semaphore.c
@@ -38,15 +38,15 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "mars/task_semaphore.h"
+#include <mars/error.h>
+#include <mars/mutex.h>
+
 #include "mars/task_types.h"
-#include "mars/mutex.h"
-#include "mars/error.h"
+#include "mars/task_semaphore.h"
 
-#include "task_semaphore_internal_types.h"
 #include "task_internal_types.h"
-#include "mutex_internal_types.h"
-#include "syscalls.h"
+#include "task_semaphore_internal_types.h"
+#include "task_module.h"
 
 static struct mars_task_semaphore semaphore;
 
@@ -61,7 +61,7 @@ int mars_task_semaphore_acquire(uint64_t
 		return MARS_ERROR_ALIGN;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
@@ -78,15 +78,14 @@ int mars_task_semaphore_acquire(uint64_t
 
 	if (semaphore.count <= 0) {
 		/* add id to wait list */
-		semaphore.wait_id[semaphore.wait_count] =
-			mars_get_workload_id();
+		semaphore.wait_id[semaphore.wait_count] = task->id.workload_id;
 		semaphore.wait_count++;
 
 		mars_mutex_unlock_put(semaphore_ea,
-				(struct mars_mutex *)&semaphore);
+			(struct mars_mutex *)&semaphore);
 
 		/* wait for signal */
-		mars_signal_wait();
+		(*mars_task_module_syscalls->signal_wait)();
 
 		return MARS_SUCCESS;
 	}
@@ -118,7 +117,8 @@ int mars_task_semaphore_release(uint64_t
 		semaphore.count--;
 
 		/* signal waiting task */
-		mars_signal_send(semaphore.wait_id[0]);
+		(*mars_task_module_syscalls->signal_send)
+			(semaphore.wait_id[0]);
 
 		/* flush id from wait list */
 		semaphore.wait_count--;
--- a/modules/task/src/mpu/lib/task_signal.c
+++ b/modules/task/src/mpu/lib/task_signal.c
@@ -35,12 +35,12 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
-#include "mars/task_signal.h"
+#include <mars/error.h>
+
 #include "mars/task_types.h"
-#include "mars/error.h"
+#include "mars/task_signal.h"
 
-#include "task_internal_types.h"
-#include "syscalls.h"
+#include "task_module.h"
 
 int mars_task_signal_send(struct mars_task_id *id)
 {
@@ -48,7 +48,7 @@ int mars_task_signal_send(struct mars_ta
 	if (!id)
 		return MARS_ERROR_NULL;
 
-	return mars_signal_send(id->workload_id);
+	return (*mars_task_module_syscalls->signal_send)(id->workload_id);
 }
 
 int mars_task_signal_wait(void)
@@ -56,18 +56,16 @@ int mars_task_signal_wait(void)
 	struct mars_task_context *task;
 
 	/* get task context */
-	task = (struct mars_task_context *)mars_get_workload();
+	task = (*mars_task_module_syscalls->get_task)();
 
 	/* make sure task context has a context save area */
 	if (!task->context_save_area_ea)
 		return MARS_ERROR_FORMAT;
 
-	mars_signal_wait();
-
-	return MARS_SUCCESS;
+	return (*mars_task_module_syscalls->signal_wait)();
 }
 
 int mars_task_signal_try_wait(void)
 {
-	return mars_signal_try_wait();
+	return (*mars_task_module_syscalls->signal_try_wait)();
 }






More information about the cbe-oss-dev mailing list