Sound Open Firmware
Loading...
Searching...
No Matches
task.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
4 *
5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6 */
7
14#ifndef __ZEPHYR_RTOS_TASK_H__
15#define __ZEPHYR_RTOS_TASK_H__
16
17#include <rtos/panic.h>
18#include <sof/list.h>
19#include <stdbool.h>
20#include <stdint.h>
21#include <rtos/kernel.h>
23
28struct comp_dev;
29struct sof;
30struct schedule_data;
31
33#define SOF_TASK_PRI_HIGH 0
34#define SOF_TASK_PRI_MED 4
35#define SOF_TASK_PRI_LOW 9
38#define SOF_TASK_DEADLINE_IDLE UINT64_MAX
39#define SOF_TASK_DEADLINE_ALMOST_IDLE (SOF_TASK_DEADLINE_IDLE - 1)
40#define SOF_TASK_DEADLINE_NOW 0
43#define SOF_TASK_SKIP_COUNT 0xFFFFu
44
68
72struct task_ops {
73 enum task_state (*run)(void *data);
74 void (*complete)(void *data);
75 uint64_t (*get_deadline)(void *data);
76};
77
81struct task {
82 uint64_t start;
83 const struct sof_uuid_entry *uid;
84 uint16_t type;
85 int16_t priority;
86 uint16_t core;
87 uint16_t flags;
90 void *data;
91 struct list_item list;
92 void *priv_data;
93 struct task_ops ops;
94 struct k_work_delayable z_delayed_work;
95 uint32_t cycles_sum;
96 uint32_t cycles_max;
97 uint32_t cycles_cnt;
98#if CONFIG_PERFORMANCE_COUNTERS
99 struct perf_cnt_data pcd;
100#endif
101};
102
108static inline bool task_is_active(struct task *task)
109{
110 switch (task->state) {
116 return true;
117 default:
118 return false;
119 }
120}
121
127static inline enum task_state task_run(struct task *task)
128{
129 assert(task->ops.run);
130
131 return task->ops.run(task->data);
132}
133
138static inline void task_complete(struct task *task)
139{
140 if (task->ops.complete)
142}
143
149static inline uint64_t task_get_deadline(struct task *task)
150{
152
153 return task->ops.get_deadline(task->data);
154}
155
162
168
171#endif /* __ZEPHYR_RTOS_TASK_H__ */
task_state
Lifecycle and execution states of an SOF task.
Definition task.h:48
int start_complete(void)
Signal completion of system startup.
int task_main_start(struct sof *sof)
Start the main SOF background task.
static uint64_t task_get_deadline(struct task *task)
Retrieve a task's deadline timestamp.
Definition task.h:149
static bool task_is_active(struct task *task)
Check whether a task is active (queued, running, pending, or rescheduling).
Definition task.h:108
static void task_complete(struct task *task)
Execute a task's complete callback, if registered.
Definition task.h:138
static enum task_state task_run(struct task *task)
Execute a task's run callback.
Definition task.h:127
@ SOF_TASK_STATE_INIT
Task allocated and initialized, not yet scheduled.
Definition task.h:50
@ SOF_TASK_STATE_FREE
Task resources released.
Definition task.h:62
@ SOF_TASK_STATE_RUNNING
Task actively executing in thread or timer/DMA handler.
Definition task.h:56
@ SOF_TASK_STATE_COMPLETED
Task execution finished; removed from active scheduling.
Definition task.h:60
@ SOF_TASK_STATE_PENDING
Task waiting for preconditions, audio data, or buffer space.
Definition task.h:54
@ SOF_TASK_STATE_CANCEL
Task cancelled, pending removal from scheduler.
Definition task.h:64
@ SOF_TASK_STATE_QUEUED
Task queued in scheduler run list awaiting tick or trigger.
Definition task.h:52
@ SOF_TASK_STATE_PREEMPTED
Task preempted by higher priority thread or ISR.
Definition task.h:58
@ SOF_TASK_STATE_RESCHEDULE
Return code from run callback requesting rescheduling in next period.
Definition task.h:66
uint8_t data[0]
Binary byte payload for raw controls.
Definition header.h:5
RTOS kernel threading and privilege helpers.
#define assert(x)
Definition panic.h:19
Performance counter data, without the timer based helpers.
Audio component base device "class" used by all other component types.
Definition component.h:587
Definition list.h:16
Definition perf_cnt_data.h:21
Descriptor container representing a registered scheduler instance.
Definition schedule.h:195
Connects UUID with component description.
Definition uuid.h:77
General firmware context.
Definition sof.h:50
Operations and callbacks associated with a scheduling task.
Definition task.h:72
enum task_state(* run)(void *data)
Task's main execution callback function.
Definition task.h:73
uint64_t(* get_deadline)(void *data)
Optional callback returning current task deadline timestamp.
Definition task.h:75
void(* complete)(void *data)
Optional callback executed on task completion.
Definition task.h:74
Core task structure managed by SOF schedulers.
Definition task.h:81
uint32_t cycles_sum
Cumulative execution cycles.
Definition task.h:95
const struct sof_uuid_entry * uid
UUID identifying the task or associated component.
Definition task.h:83
struct list_item list
List node linking task into scheduler run queue.
Definition task.h:91
struct schedule_data * sch
Pointer to scheduler instance bound to this task.
Definition task.h:88
uint32_t cycles_max
Maximum cycle count recorded in a single run.
Definition task.h:96
uint16_t core
Execution core ID affinity.
Definition task.h:86
enum task_state state
Current task lifecycle state.
Definition task.h:89
uint16_t type
Scheduler type identifier (SOF_SCHEDULE_*).
Definition task.h:84
void * data
Custom context pointer passed to task operations.
Definition task.h:90
struct task_ops ops
Task operations callbacks table.
Definition task.h:93
int16_t priority
Priority of the task (lower values run first).
Definition task.h:85
struct k_work_delayable z_delayed_work
Zephyr delayable work item (used by legacy EDF).
Definition task.h:94
void * priv_data
Scheduler-specific private task context.
Definition task.h:92
uint64_t start
Scheduler/domain-specific start state (e.g.
Definition task.h:82
uint16_t flags
Custom task flags.
Definition task.h:87
uint32_t cycles_cnt
Number of completed execution runs.
Definition task.h:97