Sound Open Firmware
Loading...
Searching...
No Matches
schedule.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2019 Intel Corporation. All rights reserved.
4 *
5 * Author: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
6 */
7
8/* Generic schedule api header */
9#ifndef __SOF_SCHEDULE_SCHEDULE_H__
10#define __SOF_SCHEDULE_SCHEDULE_H__
11
12#include <sof/common.h>
13#include <sof/list.h>
14#include <rtos/task.h>
15#include <sof/trace/trace.h>
16#include <user/trace.h>
17#include <errno.h>
18#include <stddef.h>
19#include <stdint.h>
20#include <ipc4/base_fw.h>
21
25
27enum {
46};
47
49#define SOF_SCHEDULER_FREE_IRQ_ONLY BIT(0)
70 int (*schedule_task)(void *data, struct task *task, uint64_t start,
71 uint64_t period);
72
84 int (*schedule_task_before)(void *data, struct task *task, uint64_t start,
85 uint64_t period, struct task *before);
86
98 int (*schedule_task_after)(void *data, struct task *task, uint64_t start,
99 uint64_t period, struct task *after);
100
110 int (*schedule_task_running)(void *data, struct task *task);
111
121 int (*reschedule_task)(void *data, struct task *task, uint64_t start);
122
131 int (*schedule_task_cancel)(void *data, struct task *task);
132
141 int (*schedule_task_free)(void *data, struct task *task);
142
143#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
152 void (*scheduler_free)(void *data, uint32_t flags);
153#endif
154
163 struct k_thread *(*scheduler_init_context)(void *data, struct task *task);
164};
165
169 int type;
170 const struct scheduler_ops *ops;
171 void *data;
172};
173
177};
178
184
186
188
189static inline void *scheduler_list_get_data(struct schedulers *schedulers, uint16_t type)
190{
191 struct schedule_data *sch;
192 struct list_item *slist;
193
194 if (!schedulers)
195 return NULL;
196
197 list_for_item(slist, &schedulers->list) {
198 sch = container_of(slist, struct schedule_data, list);
199 if (type == sch->type)
200 return sch->data;
201 }
202
203 return NULL;
204}
205
211static inline void *scheduler_get_data(uint16_t type)
212{
214}
215
221static inline void *scheduler_get_user_data(uint16_t type)
222{
224}
225
227static inline int schedule_task_running(struct task *task)
228{
229 struct schedule_data *sch;
230
231 assert(task);
232 sch = task->sch;
233
234 if (!sch->ops->schedule_task_running)
235 return 0;
236
237 return sch->ops->schedule_task_running(sch->data, task);
238}
239
241static inline int schedule_task(struct task *task, uint64_t start,
242 uint64_t period)
243{
244 struct schedule_data *sch;
245
246 if (!task)
247 return -EINVAL;
248
249 sch = task->sch;
250
251 return sch->ops->schedule_task(sch->data, task, start, period);
252}
253
255static inline int schedule_task_before(struct task *task, uint64_t start,
256 uint64_t period, struct task *before)
257{
258 struct schedule_data *sch;
259
260 if (!task || !before)
261 return -EINVAL;
262
263 sch = task->sch;
264
265 if (sch->ops->schedule_task_before)
266 return sch->ops->schedule_task_before(sch->data, task, start,
267 period, before);
268
269 return sch->ops->schedule_task(sch->data, task, start, period);
270}
271
273static inline int schedule_task_after(struct task *task, uint64_t start,
274 uint64_t period, struct task *after)
275{
276 struct schedule_data *sch;
277
278 if (!task || !after)
279 return -EINVAL;
280
281 sch = task->sch;
282
283 if (sch->ops->schedule_task_after)
284 return sch->ops->schedule_task_after(sch->data, task, start,
285 period, after);
286
287 return sch->ops->schedule_task(sch->data, task, start, period);
288}
289
291static inline int reschedule_task(struct task *task, uint64_t start)
292{
293 struct schedule_data *sch;
294
295 assert(task);
296 sch = task->sch;
297
298 /* optional operation */
299 if (!sch->ops->reschedule_task)
300 return 0;
301
302 return sch->ops->reschedule_task(sch->data, task, start);
303}
304
306static inline int schedule_task_cancel(struct task *task)
307{
308 struct schedule_data *sch;
309
310 if (!task || !task->sch)
311 return -EINVAL;
312
313 sch = task->sch;
314
315 return sch->ops->schedule_task_cancel(sch->data, task);
316}
317
319static inline int schedule_task_free(struct task *task)
320{
321 struct schedule_data *sch;
322
323 if (!task || !task->sch)
324 return -EINVAL;
325
326 sch = task->sch;
327
328 return sch->ops->schedule_task_free(sch->data, task);
329}
330
331/* Only used in a stand-alone test and in a testbench test */
332#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
334static inline void schedule_free(uint32_t flags)
335{
337 struct schedule_data *sch;
338 struct list_item *slist;
339
340 list_for_item(slist, &schedulers->list) {
341 sch = container_of(slist, struct schedule_data, list);
342 if (sch->ops->scheduler_free)
343 sch->ops->scheduler_free(sch->data, flags);
344 }
345}
346#endif
347
349static inline struct k_thread *scheduler_init_context(struct task *task)
350{
351 struct schedule_data *sch;
352
353 assert(task && task->sch);
354 sch = task->sch;
355
356 if (sch->ops->scheduler_init_context)
357 return sch->ops->scheduler_init_context(sch->data, task);
358
359 return NULL;
360}
361
375 const struct sof_uuid_entry *uid, uint16_t type,
376 int16_t priority, enum task_state (*run)(void *data),
377 void *data, uint16_t core, uint32_t flags);
378
385void scheduler_init(int type, const struct scheduler_ops *ops, void *data);
386
393void scheduler_get_task_info(struct scheduler_props *scheduler_props,
394 uint32_t *data_off_size, struct list_item *tasks);
395
397
398#endif /* __SOF_SCHEDULE_SCHEDULE_H__ */
#define container_of(ptr, type, member)
Definition common.h:119
uint32_t data[]
Definition debug_stream_slot.h:2
static int schedule_task_before(struct task *task, uint64_t start, uint64_t period, struct task *before)
See scheduler_ops::schedule_task_before.
Definition schedule.h:255
static void * scheduler_list_get_data(struct schedulers *schedulers, uint16_t type)
Definition schedule.h:189
void scheduler_init(int type, const struct scheduler_ops *ops, void *data)
Initializes scheduler.
int schedule_task_init(struct task *task, const struct sof_uuid_entry *uid, uint16_t type, int16_t priority, enum task_state(*run)(void *data), void *data, uint16_t core, uint32_t flags)
Initializes scheduling task.
static struct k_thread * scheduler_init_context(struct task *task)
See scheduler_ops::scheduler_init_context.
Definition schedule.h:349
static void * scheduler_get_user_data(uint16_t type)
Retrieves userspace scheduler's data.
Definition schedule.h:221
void scheduler_get_task_info(struct scheduler_props *scheduler_props, uint32_t *data_off_size, struct list_item *tasks)
Extract scheduler's task information from tasks.
static int schedule_task_free(struct task *task)
See scheduler_ops::schedule_task_free.
Definition schedule.h:319
static int reschedule_task(struct task *task, uint64_t start)
See scheduler_ops::reschedule_task.
Definition schedule.h:291
static int schedule_task_cancel(struct task *task)
See scheduler_ops::schedule_task_cancel.
Definition schedule.h:306
static int schedule_task(struct task *task, uint64_t start, uint64_t period)
See scheduler_ops::schedule_task.
Definition schedule.h:241
static int schedule_task_after(struct task *task, uint64_t start, uint64_t period, struct task *after)
See scheduler_ops::schedule_task_after.
Definition schedule.h:273
static void * scheduler_get_data(uint16_t type)
Retrieves scheduler's data.
Definition schedule.h:211
static int schedule_task_running(struct task *task)
See scheduler_ops::schedule_task_running.
Definition schedule.h:227
struct schedulers ** arch_schedulers_get(void)
Retrieves registered schedulers.
struct schedulers ** arch_user_schedulers_get(void)
struct schedulers ** arch_user_schedulers_get_for_core(int core)
@ SOF_SCHEDULE_LL_DMA
Low latency DMA, schedules immediately on scheduling component's DMA interrupt.
Definition schedule.h:32
@ SOF_SCHEDULE_LL_TIMER
Low latency timer, schedules immediately on selected timer's tick.
Definition schedule.h:29
@ SOF_SCHEDULE_COUNT
indicates number of scheduler types
Definition schedule.h:45
@ SOF_SCHEDULE_TWB
Tasks With Budget scheduler based on Zephyr peemptive threads for each SOF task that has pre-allocate...
Definition schedule.h:41
@ SOF_SCHEDULE_EDF
EDF, schedules based on task's deadline.
Definition schedule.h:28
@ SOF_SCHEDULE_DP
DataProcessing scheduler Scheduler based on Zephyr peemptive threads TODO: DP will become the Zephyr ...
Definition schedule.h:35
#define list_item(item, type, member)
Definition list.h:80
#define list_for_item(item, list)
Definition list.h:92
#define assert(x)
Definition panic.h:19
Holds information about scheduler.
Definition schedule.h:167
struct list_item list
list of schedulers
Definition schedule.h:168
int type
SOF_SCHEDULE_ type.
Definition schedule.h:169
void * data
pointer to private data
Definition schedule.h:171
const struct scheduler_ops * ops
scheduler operations
Definition schedule.h:170
Scheduler operations.
Definition schedule.h:59
int(* schedule_task_before)(void *data, struct task *task, uint64_t start, uint64_t period, struct task *before)
Schedules task with given scheduling parameters.
Definition schedule.h:84
int(* schedule_task_after)(void *data, struct task *task, uint64_t start, uint64_t period, struct task *after)
Schedules task with given scheduling parameters.
Definition schedule.h:98
struct k_thread *(* scheduler_init_context)(void *data, struct task *task)
Initializes context.
Definition schedule.h:163
int(* schedule_task)(void *data, struct task *task, uint64_t start, uint64_t period)
Schedules task with given scheduling parameters.
Definition schedule.h:70
int(* schedule_task_cancel)(void *data, struct task *task)
Cancels previously scheduled task.
Definition schedule.h:131
int(* schedule_task_free)(void *data, struct task *task)
Frees task's resources.
Definition schedule.h:141
int(* schedule_task_running)(void *data, struct task *task)
Sets task into running state along with executing additional scheduler specific operations.
Definition schedule.h:110
int(* reschedule_task)(void *data, struct task *task, uint64_t start)
Reschedules already scheduled task with new start time.
Definition schedule.h:121
Holds list of all registered schedulers.
Definition schedule.h:175
struct list_item list
list of schedulers
Definition schedule.h:176
Connects UUID with component description.
Definition uuid.h:77
Task used by schedulers.
Definition task.h:56
struct schedule_data * sch
scheduler bound to task
Definition task.h:63
task_state
Task states.
Definition task.h:36
uint32_t type
Definition tlv.h:0