task: remove edf specific elements from context switching layer

The context switching layer is a common mechanism for all
pre-emptive schedulers and should not depend on data types
defined for any specific one.

Signed-off-by: Marcin Maka <marcin.maka@linux.intel.com>
This commit is contained in:
Marcin Maka 2019-09-12 11:00:47 +02:00 committed by Daniel Baluta
parent e01c696337
commit 94733aa588
3 changed files with 51 additions and 38 deletions

View File

@ -18,8 +18,6 @@
#ifndef __ARCH_SCHEDULE_TASK_H__
#define __ARCH_SCHEDULE_TASK_H__
struct task;
/**
* \brief Returns main task data.
* \return Pointer to pointer of main task data.
@ -33,23 +31,32 @@ volatile void *task_context_get(void);
/**
* \brief Switches system context.
* \param[in,out] task Task context to be set.
* \param[in,out] task_ctx Task context to be set.
*/
void task_context_set(void *task_ctx);
/**
* \brief Initializes task context.
* \param[in,out] task Task with context to be initialized.
* \param[in,out] entry Entry point for task execution.
* \param[in,out] data Parameter data for entry point.
* \brief Allocates task context.
* \param[in,out] task_ctx Assigned to allocated structure on return.
*/
int task_context_init(struct task *task, void *entry, void *data);
int task_context_alloc(void **task_ctx);
/**
* \brief Initializes task context.
* \param[in,out] task_ctx Task context to be initialized.
* \param[in] entry Entry point for task execution.
* \param[in] arg0 First argument to be passed to entry function.
* \param[in] arg1 Second argument to be passed to entry function.
* \param[in] task_core Id of the core that task will be executed on.
*/
int task_context_init(void *task_ctx, void *entry, void *arg0, void *arg1,
int task_core);
/**
* \brief Frees task context.
* \param[in,out] task Task with context to be freed.
* \param[in,out] task_ctx Task with context to be freed.
*/
void task_context_free(struct task *task);
void task_context_free(void *task_ctx);
/**
* \brief Performs cache operation on task's context.

View File

@ -62,23 +62,26 @@ void task_context_set(void *task_ctx)
ctx->td.xtos_active_task = task_ctx;
}
int task_context_init(struct task *task, void *entry, void *data)
int task_context_alloc(void **task_ctx)
{
struct edf_task_pdata *edf_pdata = edf_sch_get_pdata(task);
xtos_task_context *ctx;
UserFrame *sp;
/* allocate task context */
ctx = rzalloc(RZONE_SYS_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*ctx));
if (!ctx)
*task_ctx = rzalloc(RZONE_SYS_RUNTIME, SOF_MEM_CAPS_RAM,
sizeof(xtos_task_context));
if (!*task_ctx)
return -ENOMEM;
return 0;
}
int task_context_init(void *task_ctx, void *entry, void *arg0, void *arg1,
int task_core)
{
xtos_task_context *ctx = task_ctx;
UserFrame *sp;
/* allocate stack */
ctx->stack_base = rballoc(RZONE_BUFFER, SOF_MEM_CAPS_RAM,
SOF_TASK_DEFAULT_STACK_SIZE);
if (!ctx->stack_base)
return -ENOMEM;
ctx->stack_size = SOF_TASK_DEFAULT_STACK_SIZE;
bzero(ctx->stack_base, ctx->stack_size);
@ -98,31 +101,27 @@ int task_context_init(struct task *task, void *entry, void *data)
sp->ps = PS_WOECALL4_ABI | PS_UM;
/* a6 and a7 are the first parameters */
sp->a6 = (uint32_t)task;
sp->a7 = (uint32_t)data;
sp->a6 = (uint32_t)arg0;
sp->a7 = (uint32_t)arg1;
ctx->stack_pointer = sp;
/* flush for slave core */
if (cpu_is_slave(task->core))
if (cpu_is_slave(task_core))
task_context_cache(ctx, CACHE_WRITEBACK_INV);
edf_pdata->ctx = ctx;
return 0;
}
void task_context_free(struct task *task)
void task_context_free(void *task_ctx)
{
struct edf_task_pdata *edf_pdata = edf_sch_get_pdata(task);
xtos_task_context *ctx = edf_pdata->ctx;
xtos_task_context *ctx = task_ctx;
rfree(ctx->stack_base);
ctx->stack_size = 0;
ctx->stack_pointer = NULL;
rfree(ctx);
edf_pdata->ctx = NULL;
}
void task_context_cache(void *task_ctx, int cmd)

View File

@ -155,7 +155,7 @@ static void schedule_edf_task(void *data, struct task *task, uint64_t start,
static int schedule_edf_task_init(void *data, struct task *task)
{
struct edf_task_pdata *edf_pdata;
struct edf_task_pdata *edf_pdata = NULL;
if (edf_sch_get_pdata(task))
return -EEXIST;
@ -170,20 +170,26 @@ static int schedule_edf_task_init(void *data, struct task *task)
edf_sch_set_pdata(task, edf_pdata);
if (task_context_init(task, &schedule_edf_task_run, data) < 0) {
trace_edf_sch_error("schedule_edf_task_init() error: init "
"context failed");
rfree(edf_pdata);
edf_sch_set_pdata(task, NULL);
return -EINVAL;
}
if (task_context_alloc(&edf_pdata->ctx) < 0)
goto error;
if (task_context_init(edf_pdata->ctx, &schedule_edf_task_run,
task, data, task->core) < 0)
goto error;
/* flush for slave core */
if (cpu_is_slave(task->core))
dcache_writeback_invalidate_region(edf_pdata,
sizeof(*edf_pdata));
return 0;
error:
trace_edf_sch_error("schedule_edf_task_init() error: init "
"context failed");
if (edf_pdata->ctx)
task_context_free(edf_pdata->ctx);
rfree(edf_pdata);
edf_sch_set_pdata(task, NULL);
return -EINVAL;
}
static void schedule_edf_task_running(void *data, struct task *task)
@ -241,7 +247,8 @@ static void schedule_edf_task_free(void *data, struct task *task)
task->state = SOF_TASK_STATE_FREE;
task_context_free(task);
task_context_free(edf_pdata->ctx);
edf_pdata->ctx = NULL;
rfree(edf_pdata);
edf_sch_set_pdata(task, NULL);