Data Structures | |
struct | mars_task_id |
MARS task id structure. More... | |
struct | mars_task_args |
MARS task argument structure. More... | |
Files | |
file | task_types.h |
[host/MPU] MARS Task Types | |
file | task.h |
[host] MARS Task API | |
file | task.h |
[MPU] MARS Task API | |
Defines | |
#define | MARS_TASK_BASE_ADDR 0x4000 |
Base address of task. | |
#define | MARS_TASK_CONTEXT_SAVE_SIZE_MAX 0x3c000 |
Max size of context save area. | |
#define | MARS_TASK_NAME_LEN_MAX 21 |
Max length of task name. | |
Functions | |
int | mars_task_create (struct mars_context *mars, struct mars_task_id *id, const char *name, const void *elf_image, uint32_t context_save_size) |
[host] Creates a MARS task. | |
int | mars_task_destroy (struct mars_task_id *id) |
[host] Destroys a MARS task. | |
int | mars_task_schedule (const struct mars_task_id *id, const struct mars_task_args *args, uint8_t priority) |
[host/MPU] Schedules a MARS task for execution. | |
int | mars_task_unschedule (const struct mars_task_id *id, int32_t exit_code) |
[host/MPU] Unschedules a MARS task from being executed. | |
int | mars_task_wait (const struct mars_task_id *id, int32_t *exit_code) |
[host/MPU] Waits for task completion. (Task Switch Call) | |
int | mars_task_try_wait (const struct mars_task_id *id, int32_t *exit_code) |
[host/MPU] Waits for a task completion. | |
uint32_t | mars_task_get_ticks (void) |
[host/MPU] Gets tick counter value. | |
int | mars_task_main (const struct mars_task_args *args) |
[MPU] Entry point for task. | |
void | mars_task_exit (int32_t exit_code) |
[MPU] Exits and terminates task. | |
int | mars_task_yield (void) |
[MPU] Yields caller task so other workloads can run. (Task Switch Call) | |
int | mars_task_call_host (uint64_t callback_ea, const struct mars_callback_args *in, struct mars_callback_args *out) |
[MPU] Calls the specified host callback. (Task Switch Call) | |
uint16_t | mars_task_get_kernel_id (void) |
[MPU] Gets id of kernel that the task is being executed on. | |
struct mars_task_id * | mars_task_get_id (void) |
[MPU] Gets id of caller task. | |
const char * | mars_task_get_name (void) |
[MPU] Gets name of caller task. |
Tasks can be used to run a small MPU program many times. However the primary usage of the task model is for large grained programs that take long amounts of time to process. Since tasks may occupy the MPU for a long time and prevent other workloads to be executed on that MPU, it has the ability to yield the MPU to other workloads.
The MARS task synchronization API also provides various methods that when used to wait for certain events, allows it to enter a wait state. When tasks have yielded or are waiting, the task state is saved into host storage and the MPU is freed up to process other available workloads.
int mars_task_create | ( | struct mars_context * | mars, | |
struct mars_task_id * | id, | |||
const char * | name, | |||
const void * | elf_image, | |||
uint32_t | context_save_size | |||
) |
[host] Creates a MARS task.
This function creates a single task and adds it the MARS context's workload queue. Upon success, a valid task id will be returned. You must call mars_task_schedule in order for it to be scheduled for execution by the kernel. The task is in the finished state upon creation and may be destroyed by mars_task_destroy without ever being scheduled for execution.
Key Parameters:
name
elf_image
context_save_size
[in] | mars | - pointer to MARS context |
[out] | id | - address of pointer to task id instance |
[in] | name | - name of task |
[in] | elf_image | - address of MPU program elf image |
[in] | context_save_size | - [ 0 ~ MARS_TASK_CONTEXT_SAVE_SIZE_MAX ] |
int mars_task_destroy | ( | struct mars_task_id * | id | ) |
[host] Destroys a MARS task.
This function destroys a task created by mars_task_create. The task will only be destroyed if the task is in the finished state. Once this function returns successfully and the task is destroyed, the task id is no longer valid. To guarantee the task has finished before calling this function, you should wait for task completion by calling mars_task_wait or mars_task_try_wait.
[in] | id | - pointer to task id instance |
int mars_task_schedule | ( | const struct mars_task_id * | id, | |
const struct mars_task_args * | args, | |||
uint8_t | priority | |||
) |
[host/MPU] Schedules a MARS task for execution.
This function schedules the task specified for execution. The actual time of execution is determined by the scheduler. Once the task is scheduled for execution by this function, it may not be scheduled for execution until previous execution has finished. You can wait for task completion by calling mars_task_wait or mars_task_try_wait.
You can call this function with a valid task id returned by mars_task_create as many times as you want after each scheduled execution has completed. The task id is valid until the task is destroyed by mars_task_destroy.
Key Parameters:
args
priority
[in] | id | - pointer to task id to schedule |
[in] | args | - pointer to task args to pass into task main |
[in] | priority | - priority of scheduling for the task |
int mars_task_unschedule | ( | const struct mars_task_id * | id, | |
int32_t | exit_code | |||
) |
[host/MPU] Unschedules a MARS task from being executed.
This function unschedules a previously scheduled task.
When a task is unscheduled, it will behave as if the task has completed execution. The user is responsible for specifying a unique exit code when unscheduling tasks to handle the condition accordingly.
If a scheduled task is unscheduled before execution, the workload will not be executed until a subsequent scheduling request is made.
If the task is currently in a waiting state, calling unschedule will finish the workload and will not be resumed from the waiting state.
If the task is currently in a running state, calling unschedule will immediately put the task into a finished state. However, execution of the task will only be suspended when the task yields, waits, or exits.
[in] | id | - pointer to task id to abort |
[out] | exit_code | - value to be returned to the task wait call |
int mars_task_wait | ( | const struct mars_task_id * | id, | |
int32_t * | exit_code | |||
) |
[host/MPU] Waits for task completion. (Task Switch Call)
Any number of host threads or tasks can wait for a specific task to complete execution as long as it holds the task's id. However, the task being waited on should not be re-scheduled until all wait calls for the task have returned. Otherwise it is not guaranteed that all wait calls will return after the completion of the initial schedule call.
Key Parameters:
exit_code
[in] | id | - pointer to task id to wait for |
[out] | exit_code | - pointer to variable to store task exit code |
int mars_task_try_wait | ( | const struct mars_task_id * | id, | |
int32_t * | exit_code | |||
) |
[host/MPU] Waits for a task completion.
This function will check whether the scheduled task specified is finished or not and return immediately without blocking.
Key Parameters:
exit_code
[in] | id | - pointer to task id to wait for |
[out] | exit_code | - pointer to variable to store task exit code |
uint32_t mars_task_get_ticks | ( | void | ) |
[host/MPU] Gets tick counter value.
int mars_task_main | ( | const struct mars_task_args * | args | ) |
[MPU] Entry point for task.
This function is the main entry point for the task program. All task programs will need to have a definition of this function. The arguments passed into this function are specified during task scheduling through the call to mars_task_schedule.
[in] | args | - pointer to task args structure in MPU storage |
void mars_task_exit | ( | int32_t | exit_code | ) |
[MPU] Exits and terminates task.
This function causes the task to exit and terminate execution. Calling this function will cause the task to enter the finished state, and will no longer be scheduled to run. This function does not need to be called when returning from mars_task_main since it is called automatically.
[out] | exit_code | - value to be returned to the task wait call |
int mars_task_yield | ( | void | ) |
[MPU] Yields caller task so other workloads can run. (Task Switch Call)
int mars_task_call_host | ( | uint64_t | callback_ea, | |
const struct mars_callback_args * | in, | |||
struct mars_callback_args * | out | |||
) |
[MPU] Calls the specified host callback. (Task Switch Call)
Key Parameters:
callback_ea
in
out
[in] | callback_ea | - ea of host callback of type mars_callback |
[in] | in | - pointer to args, passed into to host callback |
[out] | out | - pointer to args, initialized by host callback |
uint16_t mars_task_get_kernel_id | ( | void | ) |
[MPU] Gets id of kernel that the task is being executed on.
struct mars_task_id* mars_task_get_id | ( | void | ) | [read] |
[MPU] Gets id of caller task.
const char* mars_task_get_name | ( | void | ) |
[MPU] Gets name of caller task.