[Cbe-oss-dev] [PATCH 08/22]MARS/base: Move module api implementation to kernel

Yuji Mano yuji.mano at am.sony.com
Wed Jan 21 11:28:29 EST 2009


Move the core implementation of module API inside module.c into the kernel and
provide kernel syscalls for each module API.
Only provide minimal wrappers to kernel system calls inside module.c to keep
binary compatibility easier to maintain.

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

---
 base/src/common/kernel_internal_types.h |   27 +-
 base/src/mpu/kernel/kernel.c            |  350 ++++++++++++++++++++++++++++----
 base/src/mpu/lib/module.c               |  283 +------------------------
 3 files changed, 346 insertions(+), 314 deletions(-)

--- a/base/src/common/kernel_internal_types.h
+++ b/base/src/common/kernel_internal_types.h
@@ -43,21 +43,32 @@
 #define MARS_KERNEL_STATUS_BUSY			0x0
 #define MARS_KERNEL_STATUS_IDLE			0x1
 #define MARS_KERNEL_STATUS_EXIT			0x2
+
 #define MARS_KERNEL_TICKS_FLAG_SYNC_BEGIN	0x1
 #define MARS_KERNEL_TICKS_FLAG_SYNC_END		0x2
+
 #define MARS_KERNEL_PARAMS_ALIGN		128
 #define MARS_KERNEL_PARAMS_SIZE			128
 
 /* mars kernel syscalls */
 struct mars_kernel_syscalls {
-	void				   (*module_exit)(uint8_t state);
-	uint32_t			   (*get_ticks)(void);
-	uint64_t			   (*get_mars_context_ea)(void);
-	uint32_t			   (*get_kernel_id)(void);
-	uint16_t			   (*get_workload_id)(void);
-	struct mars_workload_context *     (*get_workload)(void);
-	struct mars_workload_queue_header *(*get_workload_queue_header)(void);
-	struct mars_workload_queue_block * (*get_workload_queue_block)(void);
+	uint32_t			(*get_ticks)(void);
+	uint64_t			(*get_mars_context_ea)(void);
+	uint32_t			(*get_kernel_id)(void);
+	uint16_t			(*get_workload_id)(void);
+	struct mars_workload_context *	(*get_workload)(void);
+	struct mars_workload_context *	(*get_workload_by_id)(uint16_t id);
+
+	int	(*workload_query)(uint16_t id, int query);
+	int	(*workload_wait_set)(uint16_t id);
+	int	(*workload_wait_reset)(void);
+	int	(*workload_signal_set)(uint16_t id);
+	int	(*workload_signal_reset)(void);
+	int	(*workload_schedule_begin)(uint16_t id, uint8_t priority,
+				struct mars_workload_context **workload);
+	int	(*workload_schedule_end)(uint16_t id);
+	int	(*workload_schedule_cancel)(uint16_t id);
+	void	(*exit)(uint8_t state);
 };
 
 /* mars kernel ticks */
--- a/base/src/mpu/kernel/kernel.c
+++ b/base/src/mpu/kernel/kernel.c
@@ -67,21 +67,14 @@ static uint8_t workload_state;
 static uint16_t workload_id;
 static uint64_t workload_ea;
 
+/* workload to schedule */
+static struct mars_workload_context schedule_workload;
+static uint16_t schedule_workload_id;
+
 /* module entry */
 typedef void (*module_entry)(
 	const struct mars_kernel_syscalls *kernel_syscalls);
 
-static void module_exit(uint8_t state)
-{
-	workload_state = state;
-
-	/* restore kernel stack pointer and goto to exit label */
-	asm volatile (
-		"lqa	$sp, _kernel_stack;"
-		"br	_module_exit;"
-	);
-}
-
 static uint32_t get_ticks(void)
 {
 	return kernel_params.kernel_ticks.offset - spu_read_decrementer();
@@ -107,45 +100,323 @@ static struct mars_workload_context *get
 	return &workload;
 }
 
-static struct mars_workload_queue_header *get_workload_queue_header(void)
+static uint64_t get_workload_ea(uint16_t id)
 {
-	return &queue_header;
+	return queue_header.context_ea +
+	       id * sizeof(struct mars_workload_context);
 }
 
-static struct mars_workload_queue_block *get_workload_queue_block(void)
+static struct mars_workload_context *get_workload_by_id(uint16_t id)
 {
-	return &queue_block;
-}
+	static struct mars_workload_context ret_workload;
 
-static struct mars_kernel_syscalls kernel_syscalls =
-{
-	module_exit,
-	get_ticks,
-	get_mars_context_ea,
-	get_kernel_id,
-	get_workload_id,
-	get_workload,
-	get_workload_queue_header,
-	get_workload_queue_block
-};
+	/* id is caller workload's id so return current workload */
+	if (id == workload_id)
+		return &workload;
 
-static inline uint64_t get_block_ea(int block)
+	/* get the workload context from workload queue */
+	mars_dma_get_and_wait((void *)&ret_workload, get_workload_ea(id),
+		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+
+	return &ret_workload;
+}
+
+static 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)
+static uint64_t get_block_bits(uint16_t id)
 {
-	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);
+	int block;
+	int index;
+	uint64_t block_ea;
+	uint64_t block_bits;
+
+	/* check function params */
+	if (id >= MARS_WORKLOAD_MAX)
+		return 0;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = get_block_ea(block);
+
+	/* lock the queue block */
+	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
+
+	block_bits = queue_block.bits[index];
+
+	/* unlock the queue block */
+	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);
+
+	return block_bits;
 }
 
+static int module_workload_query(uint16_t id, int query)
+{
+	uint64_t bits = get_block_bits(id);
+
+	switch (query) {
+	case MARS_QUERY_IS_INITIALIZED:
+		return (MARS_BITS_GET(&bits, STATE) !=
+			MARS_WORKLOAD_STATE_NONE);
+	case MARS_QUERY_IS_READY:
+		return (MARS_BITS_GET(&bits, STATE) ==
+			MARS_WORKLOAD_STATE_READY);
+	case MARS_QUERY_IS_WAITING:
+		return (MARS_BITS_GET(&bits, STATE) ==
+			MARS_WORKLOAD_STATE_WAITING);
+	case MARS_QUERY_IS_RUNNING:
+		return (MARS_BITS_GET(&bits, STATE) ==
+			MARS_WORKLOAD_STATE_RUNNING);
+	case MARS_QUERY_IS_FINISHED:
+		return (MARS_BITS_GET(&bits, STATE) ==
+			MARS_WORKLOAD_STATE_FINISHED);
+	case MARS_QUERY_IS_SIGNAL_SET:
+		return (MARS_BITS_GET(&bits, 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,
+		       uint64_t (*set_bits)(uint64_t bits, uint64_t param),
+		       uint64_t set_bits_param,
+		       void (*callback)(uint16_t id))
+{
+	int block;
+	int index;
+	uint64_t block_ea;
+	uint64_t bits;
+
+	/* check function params */
+	if (id >= MARS_WORKLOAD_MAX)
+		return MARS_ERROR_PARAMS;
+
+	/* calculate block/index from id */
+	block = id / MARS_WORKLOAD_PER_BLOCK;
+	index = id % MARS_WORKLOAD_PER_BLOCK;
+
+	/* calculate block ea */
+	block_ea = get_block_ea(block);
+
+	/* lock the queue block */
+	mars_mutex_lock_get(block_ea, (struct mars_mutex *)&queue_block);
+
+	/* check for valid state */
+	if (check_bits &&
+	    !(*check_bits)(queue_block.bits[index], check_bits_param)) {
+		mars_mutex_unlock_put(block_ea,
+				      (struct mars_mutex *)&queue_block);
+		return MARS_ERROR_STATE;
+	}
+
+	/* reset workload queue bits and set state to new state */
+	bits = (*set_bits)(queue_block.bits[index], set_bits_param);
+
+	/* store new bits into queue block */
+	queue_block.bits[index] = bits;
+
+	/* if callback requested call it */
+	if (callback)
+		(*callback)(id);
+
+	/* unlock the queue block */
+	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)&queue_block);
+
+	return MARS_SUCCESS;
+}
+
+static int check_state_bits(uint64_t bits, uint64_t state)
+{
+	return (MARS_BITS_GET(&bits, STATE) == state);
+}
+
+static uint64_t set_state_bits(uint64_t bits, uint64_t state)
+{
+	MARS_BITS_SET(&bits, STATE, state);
+
+	return bits;
+}
+
+static int change_state(uint16_t id,
+			unsigned int old_state,
+			unsigned int new_state,
+			void (*callback)(uint16_t id))
+{
+	return change_bits(id,
+			   check_state_bits, old_state,
+			   set_state_bits, new_state,
+		           callback);
+}
+
+static uint64_t set_wait_id_bits(uint64_t bits, uint64_t id)
+{
+	MARS_BITS_SET(&bits, WAIT_ID, id);
+
+	return bits;
+}
+
+static int module_workload_wait_set(uint16_t id)
+{
+	if (id == workload_id)
+		return MARS_ERROR_PARAMS;
+
+	return change_bits(workload_id,
+			   NULL, 0,
+			   set_wait_id_bits, id,
+			   NULL);
+}
+
+static int module_workload_wait_reset(void)
+{
+	return change_bits(workload_id,
+			   NULL, 0,
+			   set_wait_id_bits, MARS_WORKLOAD_ID_NONE,
+			   NULL);
+}
+
+static uint64_t set_signal_bits(uint64_t bits, uint64_t signal)
+{
+	MARS_BITS_SET(&bits, SIGNAL, signal);
+
+	return bits;
+}
+
+static int module_workload_signal_set(uint16_t id)
+{
+	if (id == workload_id)
+		return MARS_ERROR_PARAMS;
+
+	return change_bits(id,
+			   NULL, 0,
+			   set_signal_bits, MARS_WORKLOAD_SIGNAL_ON,
+			   NULL);
+}
+
+static int module_workload_signal_reset(void)
+{
+	return change_bits(workload_id,
+			   NULL, 0,
+			   set_signal_bits, MARS_WORKLOAD_SIGNAL_OFF,
+			   NULL);
+}
+
+static uint64_t set_schedule_bits(uint64_t bits, uint64_t priority)
+{
+	MARS_BITS_SET(&bits, STATE, MARS_WORKLOAD_STATE_SCHEDULING);
+	MARS_BITS_SET(&bits, PRIORITY, priority);
+	MARS_BITS_SET(&bits, COUNTER, MARS_WORKLOAD_COUNTER_MIN);
+	MARS_BITS_SET(&bits, SIGNAL, MARS_WORKLOAD_SIGNAL_OFF);
+	MARS_BITS_SET(&bits, WAIT_ID, MARS_WORKLOAD_ID_NONE);
+
+	return bits;
+}
+
+static void schedule_begin_callback(uint16_t id)
+{
+	/* get id of workload to schedule */
+	schedule_workload_id = id;
+
+	/* get the workload context from workload queue */
+	mars_dma_get_and_wait((void *)&schedule_workload, get_workload_ea(id),
+		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+}
+
+static int module_workload_schedule_begin(uint16_t id, uint8_t priority,
+					struct mars_workload_context **workload)
+{
+	int ret;
+
+	/* check function params */
+	if (id == workload_id)
+		return MARS_ERROR_PARAMS;
+
+	/* change bits necessary to begin scheduling */
+	ret = change_bits(id,
+			  check_state_bits, MARS_WORKLOAD_STATE_FINISHED,
+			  set_schedule_bits, priority,
+			  schedule_begin_callback);
+	if (ret != MARS_SUCCESS)
+		return ret;
+
+	/* if requested set workload context pointer to return */
+	if (workload)
+		*workload = &schedule_workload;
+
+	return MARS_SUCCESS;
+}
+
+static void schedule_end_callback(uint16_t id)
+{
+	/* get id of workload to schedule */
+	schedule_workload_id = MARS_WORKLOAD_ID_NONE;
+
+	/* put the workload context into workload queue */
+	mars_dma_put_and_wait((void *)&schedule_workload, get_workload_ea(id),
+		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+}
+
+static int module_workload_schedule_end(uint16_t id)
+{
+	if (id != schedule_workload_id)
+		return MARS_ERROR_PARAMS;
+
+	return change_state(id,
+			    MARS_WORKLOAD_STATE_SCHEDULING,
+			    MARS_WORKLOAD_STATE_READY,
+			    schedule_end_callback);
+}
+
+static int module_workload_schedule_cancel(uint16_t id)
+{
+	if (id != schedule_workload_id)
+		return MARS_ERROR_PARAMS;
+
+	return change_state(id,
+			    MARS_WORKLOAD_STATE_SCHEDULING,
+			    MARS_WORKLOAD_STATE_FINISHED,
+			    NULL);
+}
+
+static void module_exit(uint8_t state)
+{
+	workload_state = state;
+
+	/* restore kernel stack pointer and goto to exit label */
+	asm volatile (
+		"lqa	$sp, _kernel_stack;"
+		"br	_module_exit;"
+	);
+}
+
+static struct mars_kernel_syscalls kernel_syscalls =
+{
+	get_ticks,
+	get_mars_context_ea,
+	get_kernel_id,
+	get_workload_id,
+	get_workload,
+	get_workload_by_id,
+	module_workload_query,
+	module_workload_wait_set,
+	module_workload_wait_reset,
+	module_workload_signal_set,
+	module_workload_signal_reset,
+	module_workload_schedule_begin,
+	module_workload_schedule_end,
+	module_workload_schedule_cancel,
+	module_exit
+};
+
 static int search_block(int block)
 {
 	int i;
@@ -190,7 +461,11 @@ static int search_block(int block)
 				/* check if workload id is in the same block */
 				if (block != bl) {
 					/* fetch the necessary block */
-					get_block(bl, &wait_block);
+					mars_dma_get_and_wait(&wait_block,
+							get_block_ea(bl),
+							sizeof(wait_block),
+							MARS_DMA_TAG);
+
 					/* set pointer to check fetched block */
 					p_wait_block = &wait_block;
 				} else {
@@ -282,8 +557,7 @@ static int __attribute__((noinline)) res
 
 	/* 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_ea = get_workload_ea(workload_id);
 
 	/* get the workload context code from workload queue */
 	mars_dma_get_and_wait(&workload, workload_ea,
--- a/base/src/mpu/lib/module.c
+++ b/base/src/mpu/lib/module.c
@@ -39,28 +39,17 @@
 
 #include "config.h"
 
-#include "mars/dma.h"
-#include "mars/error.h"
 #include "mars/module.h"
-#include "mars/mutex.h"
 
 #include "kernel_internal_types.h"
 #include "workload_internal_types.h"
 
 static struct mars_kernel_syscalls *kernel_syscalls;
-static struct mars_workload_queue_header *queue_header;
-static struct mars_workload_queue_block *queue_block;
-static struct mars_workload_context schedule_workload;
-static uint16_t schedule_workload_id;
-static uint64_t schedule_workload_ea;
 
 void mars_module_entry(struct mars_kernel_syscalls *syscalls)
 {
 	kernel_syscalls = syscalls;
 
-	queue_header = (*kernel_syscalls->get_workload_queue_header)();
-	queue_block = (*kernel_syscalls->get_workload_queue_block)();
-
 	asm volatile (
 		/* switch to module stack */
 		"ila	$sp, __stack;"
@@ -84,7 +73,7 @@ void mars_module_entry(struct mars_kerne
 
 	mars_module_main();
 
-	(*kernel_syscalls->module_exit)(MARS_WORKLOAD_STATE_FINISHED);
+	(*kernel_syscalls->exit)(MARS_WORKLOAD_STATE_FINISHED);
 }
 
 uint32_t mars_module_get_ticks(void)
@@ -114,305 +103,63 @@ struct mars_workload_context *mars_modul
 
 struct mars_workload_context *mars_module_get_workload_by_id(uint16_t id)
 {
-	static struct mars_workload_context workload;
-	uint64_t workload_ea;
-
-	/* id is caller workload's id so return current workload */
-	if (id == mars_module_get_workload_id())
-		return mars_module_get_workload();
-
-	/* calculate workload ea */
-	workload_ea = queue_header->context_ea +
-		id * sizeof(struct mars_workload_context);
-
-	/* get the workload context from workload queue */
-	mars_dma_get_and_wait((void *)&workload, workload_ea,
-		sizeof(struct mars_workload_context), MARS_DMA_TAG);
-
-	return &workload;
-}
-
-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 uint64_t get_block_bits(uint16_t id)
-{
-	int block;
-	int index;
-	uint64_t block_ea;
-	uint64_t block_bits;
-
-	/* check function params */
-	if (id >= MARS_WORKLOAD_MAX)
-		return 0;
-
-	/* calculate block/index from id */
-	block = id / MARS_WORKLOAD_PER_BLOCK;
-	index = id % MARS_WORKLOAD_PER_BLOCK;
-
-	/* calculate block ea */
-	block_ea = get_block_ea(block);
-
-	/* lock the queue block */
-	mars_mutex_lock_get(block_ea, (struct mars_mutex *)queue_block);
-
-	block_bits = queue_block->bits[index];
-
-	/* unlock the queue block */
-	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)queue_block);
-
-	return block_bits;
+	return (*kernel_syscalls->get_workload_by_id)(id);
 }
 
 int mars_module_workload_query(uint16_t id, int query)
 {
-	uint64_t bits = get_block_bits(id);
-
-	switch (query) {
-	case MARS_QUERY_IS_INITIALIZED:
-		return (MARS_BITS_GET(&bits, STATE) !=
-			MARS_WORKLOAD_STATE_NONE);
-	case MARS_QUERY_IS_READY:
-		return (MARS_BITS_GET(&bits, STATE) ==
-			MARS_WORKLOAD_STATE_READY);
-	case MARS_QUERY_IS_WAITING:
-		return (MARS_BITS_GET(&bits, STATE) ==
-			MARS_WORKLOAD_STATE_WAITING);
-	case MARS_QUERY_IS_RUNNING:
-		return (MARS_BITS_GET(&bits, STATE) ==
-			MARS_WORKLOAD_STATE_RUNNING);
-	case MARS_QUERY_IS_FINISHED:
-		return (MARS_BITS_GET(&bits, STATE) ==
-			MARS_WORKLOAD_STATE_FINISHED);
-	case MARS_QUERY_IS_SIGNAL_SET:
-		return (MARS_BITS_GET(&bits, 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,
-		       uint64_t (*set_bits)(uint64_t bits, uint64_t param),
-		       uint64_t set_bits_param,
-		       void (*callback)(uint16_t id))
-{
-	int block;
-	int index;
-	uint64_t block_ea;
-	uint64_t bits;
-
-	/* check function params */
-	if (id >= MARS_WORKLOAD_MAX)
-		return MARS_ERROR_PARAMS;
-
-	/* calculate block/index from id */
-	block = id / MARS_WORKLOAD_PER_BLOCK;
-	index = id % MARS_WORKLOAD_PER_BLOCK;
-
-	/* calculate block ea */
-	block_ea = get_block_ea(block);
-
-	/* lock the queue block */
-	mars_mutex_lock_get(block_ea, (struct mars_mutex *)queue_block);
-
-	/* check for valid state */
-	if (check_bits &&
-	    !(*check_bits)(queue_block->bits[index], check_bits_param)) {
-		mars_mutex_unlock_put(block_ea,
-				      (struct mars_mutex *)queue_block);
-		return MARS_ERROR_STATE;
-	}
-
-	/* reset workload queue bits and set state to new state */
-	bits = (*set_bits)(queue_block->bits[index], set_bits_param);
-
-	/* store new bits into queue block */
-	queue_block->bits[index] = bits;
-
-	/* if callback requested call it */
-	if (callback)
-		(*callback)(id);
-
-	/* unlock the queue block */
-	mars_mutex_unlock_put(block_ea, (struct mars_mutex *)queue_block);
-
-	return MARS_SUCCESS;
-}
-
-static int check_state_bits(uint64_t bits, uint64_t state)
-{
-	return (MARS_BITS_GET(&bits, STATE) == state);
-}
-
-static uint64_t set_state_bits(uint64_t bits, uint64_t state)
-{
-	MARS_BITS_SET(&bits, STATE, state);
-
-	return bits;
-}
-
-static int change_state(uint16_t id,
-			unsigned int old_state,
-			unsigned int new_state,
-			void (*callback)(uint16_t id))
-{
-	return change_bits(id,
-			   check_state_bits, old_state,
-			   set_state_bits, new_state,
-		           callback);
-}
-
-static uint64_t set_wait_id_bits(uint64_t bits, uint64_t id)
-{
-	MARS_BITS_SET(&bits, WAIT_ID, id);
-
-	return bits;
+	return (*kernel_syscalls->workload_query)(id, query);
 }
 
 int mars_module_workload_wait_set(uint16_t id)
 {
-	if (id == mars_module_get_workload_id())
-		return MARS_ERROR_PARAMS;
-
-	return change_bits(mars_module_get_workload_id(),
-			   NULL, 0,
-			   set_wait_id_bits, id,
-			   NULL);
+	return (*kernel_syscalls->workload_wait_set)(id);
 }
 
 int mars_module_workload_wait_reset(void)
 {
-	return change_bits(mars_module_get_workload_id(),
-			   NULL, 0,
-			   set_wait_id_bits, MARS_WORKLOAD_ID_NONE,
-			   NULL);
-}
-
-static uint64_t set_signal_bits(uint64_t bits, uint64_t signal)
-{
-	MARS_BITS_SET(&bits, SIGNAL, signal);
-
-	return bits;
+	return (*kernel_syscalls->workload_wait_reset)();
 }
 
 int mars_module_workload_signal_set(uint16_t id)
 {
-	if (id == mars_module_get_workload_id())
-		return MARS_ERROR_PARAMS;
-
-	return change_bits(id,
-			   NULL, 0,
-			   set_signal_bits, MARS_WORKLOAD_SIGNAL_ON,
-			   NULL);
+	return (*kernel_syscalls->workload_signal_set)(id);
 }
 
 int mars_module_workload_signal_reset(void)
 {
-	return change_bits(mars_module_get_workload_id(),
-			   NULL, 0,
-			   set_signal_bits, MARS_WORKLOAD_SIGNAL_OFF,
-			   NULL);
-}
-
-static uint64_t set_schedule_bits(uint64_t bits, uint64_t priority)
-{
-	MARS_BITS_SET(&bits, STATE, MARS_WORKLOAD_STATE_SCHEDULING);
-	MARS_BITS_SET(&bits, PRIORITY, priority);
-	MARS_BITS_SET(&bits, COUNTER, MARS_WORKLOAD_COUNTER_MIN);
-	MARS_BITS_SET(&bits, SIGNAL, MARS_WORKLOAD_SIGNAL_OFF);
-	MARS_BITS_SET(&bits, WAIT_ID, MARS_WORKLOAD_ID_NONE);
-
-	return bits;
-}
-
-static void schedule_begin_callback(uint16_t id)
-{
-	/* get information of workload to schedule */
-	schedule_workload_id = id;
-	schedule_workload_ea = queue_header->context_ea +
-		id * sizeof(struct mars_workload_context);
-
-	/* get the workload context from workload queue */
-	mars_dma_get_and_wait((void *)&schedule_workload, schedule_workload_ea,
-		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+	return (*kernel_syscalls->workload_signal_reset)();
 }
 
 int mars_module_workload_schedule_begin(uint16_t id, uint8_t priority,
 					struct mars_workload_context **workload)
 {
-	int ret;
-
-	/* check function params */
-	if (id == mars_module_get_workload_id())
-		return MARS_ERROR_PARAMS;
-
-	/* change bits necessary to begin scheduling */
-	ret = change_bits(id,
-			  check_state_bits, MARS_WORKLOAD_STATE_FINISHED,
-			  set_schedule_bits, priority,
-			  schedule_begin_callback);
-	if (ret != MARS_SUCCESS)
-		return ret;
-
-	/* if requested set workload context pointer to return */
-	if (workload)
-		*workload = &schedule_workload;
-
-	return MARS_SUCCESS;
-}
-
-static void schedule_end_callback(uint16_t id)
-{
-	/* get information of workload to schedule */
-	schedule_workload_id = MARS_WORKLOAD_ID_NONE;
-	schedule_workload_ea = queue_header->context_ea +
-		id * sizeof(struct mars_workload_context);
-
-	/* put the workload context into workload queue */
-	mars_dma_put_and_wait((void *)&schedule_workload, schedule_workload_ea,
-		sizeof(struct mars_workload_context), MARS_DMA_TAG);
+	return (*kernel_syscalls->workload_schedule_begin)(id,
+							   priority,
+							   workload);
 }
 
 int mars_module_workload_schedule_end(uint16_t id)
 {
-	if (id != schedule_workload_id)
-		return MARS_ERROR_PARAMS;
-
-	return change_state(id,
-			    MARS_WORKLOAD_STATE_SCHEDULING,
-			    MARS_WORKLOAD_STATE_READY,
-			    schedule_end_callback);
+	return (*kernel_syscalls->workload_schedule_end)(id);
 }
 
 int mars_module_workload_schedule_cancel(uint16_t id)
 {
-	if (id != schedule_workload_id)
-		return MARS_ERROR_PARAMS;
-
-	return change_state(id,
-			    MARS_WORKLOAD_STATE_SCHEDULING,
-			    MARS_WORKLOAD_STATE_FINISHED,
-			    NULL);
+	return (*kernel_syscalls->workload_schedule_cancel)(id);
 }
 
 void mars_module_workload_wait(void)
 {
-	(*kernel_syscalls->module_exit)(MARS_WORKLOAD_STATE_WAITING);
+	(*kernel_syscalls->exit)(MARS_WORKLOAD_STATE_WAITING);
 }
 
 void mars_module_workload_yield(void)
 {
-	(*kernel_syscalls->module_exit)(MARS_WORKLOAD_STATE_READY);
+	(*kernel_syscalls->exit)(MARS_WORKLOAD_STATE_READY);
 }
 
 void mars_module_workload_finish(void)
 {
-	(*kernel_syscalls->module_exit)(MARS_WORKLOAD_STATE_FINISHED);
+	(*kernel_syscalls->exit)(MARS_WORKLOAD_STATE_FINISHED);
 }






More information about the cbe-oss-dev mailing list