2019-06-02 03:14:06 +08:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2016-09-21 22:57:22 +08:00
|
|
|
*
|
2019-06-02 03:14:06 +08:00
|
|
|
* Copyright(c) 2016 Intel Corporation. All rights reserved.
|
2016-09-21 22:57:22 +08:00
|
|
|
*
|
|
|
|
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2023-02-22 04:01:47 +08:00
|
|
|
#ifndef __ZEPHYR_RTOS_TASK_H__
|
|
|
|
#define __ZEPHYR_RTOS_TASK_H__
|
2016-09-21 22:57:22 +08:00
|
|
|
|
2023-02-21 18:46:31 +08:00
|
|
|
#include <rtos/panic.h>
|
2019-07-19 19:39:22 +08:00
|
|
|
#include <sof/list.h>
|
2019-10-10 17:02:07 +08:00
|
|
|
#include <stdbool.h>
|
2019-07-19 19:39:22 +08:00
|
|
|
#include <stdint.h>
|
2022-08-19 21:10:56 +08:00
|
|
|
#include <rtos/kernel.h>
|
2022-10-12 11:16:05 +08:00
|
|
|
#include <sof/lib/perf_cnt.h>
|
|
|
|
|
2019-10-10 17:02:07 +08:00
|
|
|
struct comp_dev;
|
2018-04-05 07:46:50 +08:00
|
|
|
struct sof;
|
2019-07-19 19:39:22 +08:00
|
|
|
|
2019-12-02 18:53:57 +08:00
|
|
|
/** \brief Predefined LL task priorities. */
|
2019-07-19 19:39:22 +08:00
|
|
|
#define SOF_TASK_PRI_HIGH 0 /* priority level 0 - high */
|
|
|
|
#define SOF_TASK_PRI_MED 4 /* priority level 4 - medium */
|
|
|
|
#define SOF_TASK_PRI_LOW 9 /* priority level 9 - low */
|
|
|
|
|
2019-12-02 18:53:57 +08:00
|
|
|
/** \brief Predefined EDF task deadlines. */
|
2019-11-29 19:37:06 +08:00
|
|
|
#define SOF_TASK_DEADLINE_IDLE UINT64_MAX
|
|
|
|
#define SOF_TASK_DEADLINE_ALMOST_IDLE (SOF_TASK_DEADLINE_IDLE - 1)
|
|
|
|
#define SOF_TASK_DEADLINE_NOW 0
|
|
|
|
|
2021-02-01 23:36:34 +08:00
|
|
|
/** \brief Task counter initial value. */
|
|
|
|
#define SOF_TASK_SKIP_COUNT 0xFFFFu
|
|
|
|
|
2019-12-02 18:53:57 +08:00
|
|
|
/** \brief Task states. */
|
2019-08-02 16:48:56 +08:00
|
|
|
enum task_state {
|
|
|
|
SOF_TASK_STATE_INIT = 0,
|
|
|
|
SOF_TASK_STATE_QUEUED,
|
|
|
|
SOF_TASK_STATE_PENDING,
|
|
|
|
SOF_TASK_STATE_RUNNING,
|
|
|
|
SOF_TASK_STATE_PREEMPTED,
|
|
|
|
SOF_TASK_STATE_COMPLETED,
|
|
|
|
SOF_TASK_STATE_FREE,
|
|
|
|
SOF_TASK_STATE_CANCEL,
|
2019-08-02 17:11:58 +08:00
|
|
|
SOF_TASK_STATE_RESCHEDULE,
|
2019-08-02 16:48:56 +08:00
|
|
|
};
|
2019-07-19 19:39:22 +08:00
|
|
|
|
2019-12-02 18:53:57 +08:00
|
|
|
/** \brief Task operations. */
|
2019-11-29 17:46:33 +08:00
|
|
|
struct task_ops {
|
2019-12-02 18:53:57 +08:00
|
|
|
enum task_state (*run)(void *data); /**< task's main operation */
|
|
|
|
void (*complete)(void *data); /**< executed on completion */
|
|
|
|
uint64_t (*get_deadline)(void *data); /**< returns current deadline */
|
2019-11-29 17:46:33 +08:00
|
|
|
};
|
|
|
|
|
2019-12-02 18:53:57 +08:00
|
|
|
/** \brief Task used by schedulers. */
|
2019-07-19 19:39:22 +08:00
|
|
|
struct task {
|
2020-07-14 02:32:31 +08:00
|
|
|
uint64_t start; /**< start time in [ms] since now (LL only) */
|
2020-09-03 20:07:28 +08:00
|
|
|
const struct sof_uuid_entry *uid; /**< Uuid */
|
2019-12-02 18:53:57 +08:00
|
|
|
uint16_t type; /**< type of the task (LL or EDF) */
|
|
|
|
uint16_t priority; /**< priority of the task (used by LL) */
|
|
|
|
uint16_t core; /**< execution core */
|
|
|
|
uint16_t flags; /**< custom flags */
|
|
|
|
enum task_state state; /**< current state */
|
|
|
|
void *data; /**< custom data passed to all ops */
|
|
|
|
struct list_item list; /**< used by schedulers to hold tasks */
|
2020-03-24 04:44:40 +08:00
|
|
|
void *priv_data; /**< task private data */
|
2019-12-02 18:53:57 +08:00
|
|
|
struct task_ops ops; /**< task operations */
|
2021-05-08 04:26:52 +08:00
|
|
|
struct k_work_delayable z_delayed_work;
|
2021-07-22 21:55:49 +08:00
|
|
|
uint32_t cycles_sum;
|
|
|
|
uint32_t cycles_max;
|
|
|
|
uint32_t cycles_cnt;
|
2022-10-12 11:16:05 +08:00
|
|
|
#if CONFIG_PERFORMANCE_COUNTERS
|
|
|
|
struct perf_cnt_data pcd;
|
|
|
|
#endif
|
2019-07-19 19:39:22 +08:00
|
|
|
};
|
2017-06-06 23:41:07 +08:00
|
|
|
|
2021-11-24 21:14:18 +08:00
|
|
|
static inline bool task_is_active(struct task *task)
|
|
|
|
{
|
|
|
|
switch (task->state) {
|
|
|
|
case SOF_TASK_STATE_QUEUED:
|
|
|
|
case SOF_TASK_STATE_PENDING:
|
|
|
|
case SOF_TASK_STATE_RUNNING:
|
|
|
|
case SOF_TASK_STATE_PREEMPTED:
|
|
|
|
case SOF_TASK_STATE_RESCHEDULE:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-10-10 17:02:07 +08:00
|
|
|
|
2019-11-29 17:46:33 +08:00
|
|
|
static inline enum task_state task_run(struct task *task)
|
|
|
|
{
|
|
|
|
assert(task->ops.run);
|
|
|
|
|
|
|
|
return task->ops.run(task->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void task_complete(struct task *task)
|
|
|
|
{
|
|
|
|
if (task->ops.complete)
|
|
|
|
task->ops.complete(task->data);
|
|
|
|
}
|
|
|
|
|
2019-11-29 18:39:31 +08:00
|
|
|
static inline uint64_t task_get_deadline(struct task *task)
|
|
|
|
{
|
|
|
|
assert(task->ops.get_deadline);
|
|
|
|
|
|
|
|
return task->ops.get_deadline(task->data);
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:22:34 +08:00
|
|
|
int task_main_start(struct sof *sof);
|
2023-01-24 19:25:21 +08:00
|
|
|
int start_complete(void);
|
2018-07-03 00:53:51 +08:00
|
|
|
|
2023-02-22 04:01:47 +08:00
|
|
|
#endif /* __ZEPHYR_RTOS_TASK_H__ */
|