Sound Open Firmware
Loading...
Searching...
No Matches
twb_schedule.h File Reference
Include dependency graph for twb_schedule.h:

Go to the source code of this file.

Macros

#define ZEPHYR_TWB_STACK_SIZE   8192
 Task With Budget (TWB) Scheduler.
#define ZEPHYR_TWB_BUDGET_MAX   (CONFIG_SYS_CLOCK_TICKS_PER_SEC / 1000)
 max budget limit
#define SYS_TICKS_TO_HW_CYCLES(x)
#define HW_CYCLES_TO_SYS_TICKS(x)

Functions

int scheduler_twb_init (void)
 Init the Tasks with Budget scheduler.
int scheduler_twb_task_init (struct task **task, const struct sof_uuid_entry *uid, const struct task_ops *ops, void *data, int32_t core, const char *name, size_t stack_size, int32_t thread_priority, uint32_t cycles_granted)
 initialize a TWB task and add it to scheduling It must be called on core the task is declared to run on

Macro Definition Documentation

◆ HW_CYCLES_TO_SYS_TICKS

#define HW_CYCLES_TO_SYS_TICKS ( x)
Value:
(x * CONFIG_SYS_CLOCK_TICKS_PER_SEC / CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC)

◆ SYS_TICKS_TO_HW_CYCLES

#define SYS_TICKS_TO_HW_CYCLES ( x)
Value:
(x * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / CONFIG_SYS_CLOCK_TICKS_PER_SEC)

◆ ZEPHYR_TWB_BUDGET_MAX

#define ZEPHYR_TWB_BUDGET_MAX   (CONFIG_SYS_CLOCK_TICKS_PER_SEC / 1000)

max budget limit

◆ ZEPHYR_TWB_STACK_SIZE

#define ZEPHYR_TWB_STACK_SIZE   8192

Task With Budget (TWB) Scheduler.

TWB scheduler is a scheduler that creates a separate preemptible Zephyr thread for each SOF task that has a pre-allocated MCPS budget renewed with every system tick. The TWB scheduler assigns either MEDIUM_PRIORITY or LOW_PRIORITY to the task thread based on the budget left in the current system tick. It allows for opportunistic execution if there is no other ready task with a higher priority while the budget is already spent.

Examples of tasks with budget include IPC Task and IDC Task.

The TWB scheduler has two key parameters assigned:

  • cycles granted: the budget per system tick
  • cycles consumed: the number of cycles consumed in a given system tick for task execution

The number of cycles consumed is reset to 0 at the beginning of each system tick, renewing the TWB budget. When the number of cycles consumed exceeds the cycles granted, the task is switchedfrom MEDIUM to LOW priority. When the task with budget thread is created, the MPP Scheduling is responsible for setting the thread time slice equal to the task budget, along with setting a callback on time slice timeout. Thread time slicing guarantees that the Zephyr scheduler will interrupt execution when the budget is spent, so the MPP Scheduling timeout callback can re-evaluate the task priority.

If there is a budget left in some system tick (i.e., the task spent less time or started executing closeto the system tick that preempts execution), it is reset and not carried over to the next tick.

More info: https://thesofproject.github.io/latest/architectures/firmware/sof-zephyr/mpp_layer/mpp_scheduling.html

default static stack size for each TWB thread

Function Documentation

◆ scheduler_twb_init()

int scheduler_twb_init ( void )

Init the Tasks with Budget scheduler.

◆ scheduler_twb_task_init()

int scheduler_twb_task_init ( struct task ** task,
const struct sof_uuid_entry * uid,
const struct task_ops * ops,
void * data,
int32_t core,
const char * name,
size_t stack_size,
int32_t thread_priority,
uint32_t cycles_granted )

initialize a TWB task and add it to scheduling It must be called on core the task is declared to run on

Parameters
[out]taskpointer, pointer to allocated task structure will be return
[in]uidpointer to UUID of the task
[in]opspointer to task functions
[in]datapointer to the task data
[in]coreCPU the thread should run on
[in]namezephyr thread name
[in]stack_sizesize of stack for a zephyr thread
[in]thread_prioritypriority of the zephyr thread
[in]cycles_grantedcycles budget for the zephyr thread