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
14#ifndef __SOF_SCHEDULE_SCHEDULE_H__
15#define __SOF_SCHEDULE_SCHEDULE_H__
16
17#include <sof/common.h>
18#include <sof/list.h>
19#include <rtos/task.h>
20#include <sof/trace/trace.h>
21#include <user/trace.h>
22#include <errno.h>
23#include <stddef.h>
24#include <stdint.h>
25#include <ipc4/base_fw.h>
26
31enum {
73};
74
76#define SOF_SCHEDULER_FREE_IRQ_ONLY BIT(0)
98 int (*schedule_task)(void *data, struct task *task, uint64_t start,
99 uint64_t period);
100
112 int (*schedule_task_before)(void *data, struct task *task, uint64_t start,
113 uint64_t period, struct task *before);
114
126 int (*schedule_task_after)(void *data, struct task *task, uint64_t start,
127 uint64_t period, struct task *after);
128
137 int (*schedule_task_running)(void *data, struct task *task);
138
148 int (*reschedule_task)(void *data, struct task *task, uint64_t start);
149
158 int (*schedule_task_cancel)(void *data, struct task *task);
159
168 int (*schedule_task_free)(void *data, struct task *task);
169
170#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
178 void (*scheduler_free)(void *data, uint32_t flags);
179#endif
180
189 struct k_thread *(*scheduler_init_context)(void *data, struct task *task);
190};
191
197 int type;
198 const struct scheduler_ops *ops;
199 void *data;
200};
201
207};
208
217
227
237
244static inline void *scheduler_list_get_data(struct schedulers *schedulers, uint16_t type)
245{
246 struct schedule_data *sch;
247 struct list_item *slist;
248
249 if (!schedulers)
250 return NULL;
251
252 list_for_item(slist, &schedulers->list) {
253 sch = container_of(slist, struct schedule_data, list);
254 if (type == sch->type)
255 return sch->data;
256 }
257
258 return NULL;
259}
260
266static inline void *scheduler_get_data(uint16_t type)
267{
269}
270
276static inline void *scheduler_get_user_data(uint16_t type)
277{
279}
280
286static inline int schedule_task_running(struct task *task)
287{
288 struct schedule_data *sch;
289
290 assert(task);
291 sch = task->sch;
292
293 if (!sch->ops->schedule_task_running)
294 return 0;
295
296 return sch->ops->schedule_task_running(sch->data, task);
297}
298
306static inline int schedule_task(struct task *task, uint64_t start,
307 uint64_t period)
308{
309 struct schedule_data *sch;
310
311 if (!task)
312 return -EINVAL;
313
314 sch = task->sch;
315
316 return sch->ops->schedule_task(sch->data, task, start, period);
317}
318
332static inline int schedule_task_before(struct task *task, uint64_t start,
333 uint64_t period, struct task *before)
334{
335 struct schedule_data *sch;
336
337 if (!task || !before)
338 return -EINVAL;
339
340 sch = task->sch;
341
342 if (sch->ops->schedule_task_before)
343 return sch->ops->schedule_task_before(sch->data, task, start,
344 period, before);
345
346 return sch->ops->schedule_task(sch->data, task, start, period);
347}
348
362static inline int schedule_task_after(struct task *task, uint64_t start,
363 uint64_t period, struct task *after)
364{
365 struct schedule_data *sch;
366
367 if (!task || !after)
368 return -EINVAL;
369
370 sch = task->sch;
371
372 if (sch->ops->schedule_task_after)
373 return sch->ops->schedule_task_after(sch->data, task, start,
374 period, after);
375
376 return sch->ops->schedule_task(sch->data, task, start, period);
377}
378
385static inline int reschedule_task(struct task *task, uint64_t start)
386{
387 struct schedule_data *sch;
388
389 assert(task);
390 sch = task->sch;
391
392 /* optional operation */
393 if (!sch->ops->reschedule_task)
394 return 0;
395
396 return sch->ops->reschedule_task(sch->data, task, start);
397}
398
404static inline int schedule_task_cancel(struct task *task)
405{
406 struct schedule_data *sch;
407
408 if (!task || !task->sch)
409 return -EINVAL;
410
411 sch = task->sch;
412
413 return sch->ops->schedule_task_cancel(sch->data, task);
414}
415
421static inline int schedule_task_free(struct task *task)
422{
423 struct schedule_data *sch;
424
425 if (!task || !task->sch)
426 return -EINVAL;
427
428 sch = task->sch;
429
430 return sch->ops->schedule_task_free(sch->data, task);
431}
432
433/* Only used in a stand-alone test and in a testbench test */
434#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
439static inline void schedule_free(uint32_t flags)
440{
442 struct schedule_data *sch;
443 struct list_item *slist;
444
445 list_for_item(slist, &schedulers->list) {
446 sch = container_of(slist, struct schedule_data, list);
447 if (sch->ops->scheduler_free)
448 sch->ops->scheduler_free(sch->data, flags);
449 }
450}
451#endif
452
458static inline struct k_thread *scheduler_init_context(struct task *task)
459{
460 struct schedule_data *sch;
461
462 assert(task && task->sch);
463 sch = task->sch;
464
465 if (sch->ops->scheduler_init_context)
466 return sch->ops->scheduler_init_context(sch->data, task);
467
468 return NULL;
469}
470
491 const struct sof_uuid_entry *uid, uint16_t type,
492 int16_t priority, enum task_state (*run)(void *data),
493 void *data, uint16_t core, uint32_t flags);
494
505void scheduler_init(int type, const struct scheduler_ops *ops, void *data);
506
518 uint32_t *data_off_size, struct list_item *tasks);
519
522#endif /* __SOF_SCHEDULE_SCHEDULE_H__ */
IPC4 Base Firmware parameters, memory configuration, and status definitions.
#define container_of(ptr, type, member)
Definition common.h:117
static int schedule_task_before(struct task *task, uint64_t start, uint64_t period, struct task *before)
Schedule a task to execute before a specified reference task.
Definition schedule.h:332
static void * scheduler_list_get_data(struct schedulers *schedulers, uint16_t type)
Lookup scheduler private context data by scheduler type from a schedulers container.
Definition schedule.h:244
void scheduler_init(int type, const struct scheduler_ops *ops, void *data)
Register a scheduler type instance with its operations table and private context data.
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)
Initialize a scheduling task and bind it to the registered scheduler for its type and core.
static struct k_thread * scheduler_init_context(struct task *task)
Initialize thread execution context for a task.
Definition schedule.h:458
static void * scheduler_get_user_data(uint16_t type)
Retrieve private data of a registered user-space scheduler on the current core.
Definition schedule.h:276
task_state
Lifecycle and execution states of an SOF task.
Definition task.h:48
void scheduler_get_task_info(struct scheduler_props *scheduler_props, uint32_t *data_off_size, struct list_item *tasks)
Extract scheduler task telemetry and properties for IPC4 base firmware.
static int schedule_task_free(struct task *task)
Free scheduler resources associated with a task.
Definition schedule.h:421
static int reschedule_task(struct task *task, uint64_t start)
Reschedule an already scheduled task with an updated start time.
Definition schedule.h:385
static int schedule_task_cancel(struct task *task)
Cancel a scheduled or queued task.
Definition schedule.h:404
static int schedule_task(struct task *task, uint64_t start, uint64_t period)
Schedule a task for execution with start delay and period.
Definition schedule.h:306
static int schedule_task_after(struct task *task, uint64_t start, uint64_t period, struct task *after)
Schedule a task to execute after a specified reference task.
Definition schedule.h:362
static void * scheduler_get_data(uint16_t type)
Retrieve private data of a registered kernel scheduler on the current core.
Definition schedule.h:266
static int schedule_task_running(struct task *task)
Notify the scheduler that a task is transitioning to the running state.
Definition schedule.h:286
struct schedulers ** arch_schedulers_get(void)
Retrieve the array of registered kernel-space schedulers for the current core.
struct schedulers ** arch_user_schedulers_get(void)
Retrieve registered schedulers for user-space threads on the current core.
struct schedulers ** arch_user_schedulers_get_for_core(int core)
Retrieve registered schedulers for user-space threads on a specific core.
@ SOF_SCHEDULE_LL_DMA
Low Latency DMA interrupt domain scheduler.
Definition schedule.h:53
@ SOF_SCHEDULE_LL_TIMER
Low Latency timer domain scheduler.
Definition schedule.h:47
@ SOF_SCHEDULE_COUNT
Indicates total number of scheduler types.
Definition schedule.h:72
@ SOF_SCHEDULE_TWB
Tasks With Budget (TWB) scheduler.
Definition schedule.h:68
@ SOF_SCHEDULE_EDF
Earliest Deadline First (EDF) scheduler.
Definition schedule.h:41
@ SOF_SCHEDULE_DP
Data Processing (DP) worker thread scheduler.
Definition schedule.h:60
uint8_t data[0]
Binary byte payload for raw controls.
Definition header.h:5
uint32_t type
Message type, symmetric to the incoming request.
Definition header.h:8
#define list_for_item(item, list)
Definition list.h:92
#define assert(x)
Definition panic.h:19
User-space ABI log levels and binary trace packet header definitions.
Definition list.h:16
Descriptor container representing a registered scheduler instance.
Definition schedule.h:195
struct list_item list
List node linking this scheduler into the per-core schedulers list.
Definition schedule.h:196
int type
Scheduler type identifier (SOF_SCHEDULE_*).
Definition schedule.h:197
void * data
Pointer to scheduler-specific private context data.
Definition schedule.h:199
const struct scheduler_ops * ops
Pointer to scheduler operations table.
Definition schedule.h:198
Scheduler operations interface table.
Definition schedule.h:85
int(* schedule_task_before)(void *data, struct task *task, uint64_t start, uint64_t period, struct task *before)
Schedule a task to execute before a specified reference task.
Definition schedule.h:112
int(* schedule_task_after)(void *data, struct task *task, uint64_t start, uint64_t period, struct task *after)
Schedule a task to execute after a specified reference task.
Definition schedule.h:126
struct k_thread *(* scheduler_init_context)(void *data, struct task *task)
Initialize execution thread context for a scheduled task.
Definition schedule.h:189
int(* schedule_task)(void *data, struct task *task, uint64_t start, uint64_t period)
Schedule a task with the given timing parameters.
Definition schedule.h:98
int(* schedule_task_cancel)(void *data, struct task *task)
Cancel a previously scheduled task.
Definition schedule.h:158
int(* schedule_task_free)(void *data, struct task *task)
Free scheduler resources associated with a task.
Definition schedule.h:168
int(* schedule_task_running)(void *data, struct task *task)
Transition a task to running state and perform scheduler-specific execution hooks.
Definition schedule.h:137
int(* reschedule_task)(void *data, struct task *task, uint64_t start)
Reschedule an already scheduled task with an updated start delay.
Definition schedule.h:148
Core scheduler properties and scheduled tasks.
Definition base_fw.h:685
Container holding the linked list of all registered schedulers on a core.
Definition schedule.h:205
struct list_item list
Head of the linked list of registered schedulers.
Definition schedule.h:206
Connects UUID with component description.
Definition uuid.h:77
Core task structure managed by SOF schedulers.
Definition task.h:81
struct schedule_data * sch
Pointer to scheduler instance bound to this task.
Definition task.h:88
Core task descriptor, task operations, and task execution state machine.