Skip to content

Commit b8d5999

Browse files
lyakhkv2019i
authored andcommitted
schedule: dp: call directly instead of a notifier
scheduler_dp_ll_tick() is currently registered as a notifier callback, but it's always triggered deterministically, always with the same-core-only flag, which leads to it being called immediately. So the notifier only adds a layer of indirection and reduces clarity. Replace it with a direct function call. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent edcdedb commit b8d5999

9 files changed

Lines changed: 31 additions & 35 deletions

File tree

src/include/sof/lib/notifier.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ enum notify_id {
2828
NOTIFIER_ID_KPB_CLIENT_EVT, /* struct kpb_event_data * */
2929
NOTIFIER_ID_DMA_DOMAIN_CHANGE, /* struct dma_chan_data * */
3030
NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */
31-
NOTIFIER_ID_LL_POST_RUN, /* NULL */
3231
NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */
3332
NOTIFIER_ID_DAI_TRIGGER, /* struct dai_group * */
3433
NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, /* struct mic_privacy_settings * */

src/include/sof/schedule/dp_schedule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ int scheduler_dp_task_init(struct task **task,
7878
uint16_t core,
7979
size_t stack_size,
8080
uint32_t options);
81+
void scheduler_dp_ll_tick(void);
8182

8283
/**
8384
* \brief Extract information about scheduler's tasks

src/schedule/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ graph TD
5050
DMADomain --> |Wakeup| LL
5151
LL -->|Runs tasks| Threads
5252
53-
LL -->|NOTIFIER_ID_LL_POST_RUN| DP
53+
LL -->|LL Tick Source| DP
5454
DP -->|Recalculate Deadlines| DPThread
5555
DPThread -->|Update Thread Deadlines| Threads
5656
@@ -69,7 +69,7 @@ The LL scheduler (`zephyr_ll.c`) is designed for extreme low-latency processing.
6969
- **Domain Threads**: The LL scheduler runs within a dedicated high-priority Zephyr thread (`ll_thread0`, etc.) pinned to each core (`zephyr_domain.c`).
7070
- **Triggers**: It is woken up by a hardware timer (e.g., a 1ms tick) or directly by hardware DMA interrupts (`zephyr_dma_domain.c`).
7171
- **Execution**: Once woken up, it locks the domain, iterates through all scheduled tasks in priority order, moves them to a temporary list, and calls their `.run()` functions.
72-
- **Post-Run**: After all tasks execute, it triggers a `NOTIFIER_ID_LL_POST_RUN` event. This event cascades to wake up other dependent schedulers like DP and TWB. Event not run on LL userspace configuration.
72+
- **Post-Run**: After all tasks execute, it triggers the DP scheduler for task deadline recalculation.
7373

7474
### Task State Diagram
7575

src/schedule/ll_schedule_xtos.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sof/lib/uuid.h>
2121
#include <sof/list.h>
2222
#include <sof/platform.h>
23+
#include <sof/schedule/dp_schedule.h>
2324
#include <sof/schedule/ll_schedule.h>
2425
#include <sof/schedule/ll_schedule_domain.h>
2526
#include <sof/schedule/schedule.h>
@@ -317,8 +318,9 @@ static void schedule_ll_tasks_run(void *data)
317318
if (schedule_ll_is_pending(sch))
318319
schedule_ll_tasks_execute(sch);
319320

320-
notifier_event(sch, NOTIFIER_ID_LL_POST_RUN,
321-
NOTIFIER_TARGET_CORE_LOCAL, NULL, 0);
321+
#ifdef CONFIG_ZEPHYR_DP_SCHEDULER
322+
scheduler_dp_ll_tick();
323+
#endif
322324

323325
perf_cnt_stamp(&sch->pcd, perf_ll_sched_trace, 0 /* ignored */);
324326
perf_cnt_average(&sch->pcd, perf_avg_ll_sched_trace, 0 /* ignored */);

src/schedule/zephyr_dp_schedule.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <zephyr/sys/sem.h>
2323
#include <zephyr/sys/mutex.h>
2424
#include <sof/lib/memory.h>
25-
#include <sof/lib/notifier.h>
2625
#include <ipc4/base_fw.h>
2726

2827
#include "zephyr_dp_schedule.h"
@@ -223,19 +222,19 @@ static enum task_state scheduler_dp_ll_tick_dummy(void *data)
223222
* needed 1.2ms for processing - but the example would be too complicated)
224223
*/
225224

226-
void scheduler_dp_ll_tick(void *receiver_data, enum notify_id event_type, void *caller_data)
225+
void scheduler_dp_ll_tick(void)
227226
{
228-
(void)receiver_data;
229-
(void)event_type;
230-
(void)caller_data;
231227
unsigned int lock_key;
232228
struct scheduler_dp_data *dp_sch = scheduler_get_data(SOF_SCHEDULE_DP);
233229

230+
if (!dp_sch)
231+
return;
232+
234233
/* remember current timestamp as "NOW" */
235234
dp_sch->last_ll_tick_timestamp = k_cycle_get_32();
236235

237236
lock_key = scheduler_dp_lock(cpu_get_id());
238-
scheduler_dp_recalculate(dp_sch, event_type == NOTIFIER_ID_LL_POST_RUN);
237+
scheduler_dp_recalculate(dp_sch);
239238
scheduler_dp_unlock(lock_key);
240239
}
241240

@@ -347,10 +346,9 @@ static struct scheduler_ops schedule_dp_ops = {
347346
.schedule_task_free = scheduler_dp_task_free,
348347
};
349348

349+
/* Runs on each core */
350350
__cold int scheduler_dp_init(void)
351351
{
352-
int ret;
353-
354352
assert_can_be_cold();
355353

356354
struct scheduler_dp_data *dp_sch = rzalloc(SOF_MEM_FLAG_KERNEL,
@@ -364,18 +362,11 @@ __cold int scheduler_dp_init(void)
364362
scheduler_init(SOF_SCHEDULE_DP, &schedule_dp_ops, dp_sch);
365363

366364
/* init src of DP tick */
367-
ret = schedule_task_init_ll(&dp_sch->ll_tick_src,
368-
SOF_UUID(dp_sched_uuid),
369-
SOF_SCHEDULE_LL_TIMER,
370-
0, scheduler_dp_ll_tick_dummy, dp_sch,
371-
cpu_get_id(), 0);
372-
373-
if (ret)
374-
return ret;
375-
376-
notifier_register(NULL, NULL, NOTIFIER_ID_LL_POST_RUN, scheduler_dp_ll_tick, 0);
377-
378-
return 0;
365+
return schedule_task_init_ll(&dp_sch->ll_tick_src,
366+
SOF_UUID(dp_sched_uuid),
367+
SOF_SCHEDULE_LL_TIMER,
368+
0, scheduler_dp_ll_tick_dummy, dp_sch,
369+
cpu_get_id(), 0);
379370
}
380371

381372
void scheduler_get_task_info_dp(struct scheduler_props *scheduler_props, uint32_t *data_off_size)

src/schedule/zephyr_dp_schedule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct task_dp_pdata {
5252
#endif
5353
};
5454

55-
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_run);
55+
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch);
5656
void dp_thread_fn(void *p1, void *p2, void *p3);
5757
unsigned int scheduler_dp_lock(uint16_t core);
5858
void scheduler_dp_unlock(unsigned int key);

src/schedule/zephyr_dp_schedule_application.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
197197
/* Go through all DP tasks and recalculate their readiness and deadlines
198198
* NOT REENTRANT, called with scheduler_dp_lock() held
199199
*/
200-
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_run)
200+
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch)
201201
{
202202
struct list_item *tlist;
203203
struct task *curr_task;
@@ -210,7 +210,7 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
210210
bool trigger_task = false;
211211

212212
/* decrease number of LL ticks/cycles left till the module reaches its deadline */
213-
if (mod->dp_startup_delay && is_ll_post_run && pdata->ll_cycles_to_start) {
213+
if (mod->dp_startup_delay && pdata->ll_cycles_to_start) {
214214
pdata->ll_cycles_to_start--;
215215
if (!pdata->ll_cycles_to_start)
216216
/* delayed start complete, clear startup delay flag.

src/schedule/zephyr_dp_schedule_thread.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern struct tr_ctx dp_tr;
3030
/* Go through all DP tasks and recalculate their readiness and deadlines
3131
* NOT REENTRANT, should be called with scheduler_dp_lock()
3232
*/
33-
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_run)
33+
static void scheduler_dp_recalculate_thread(struct scheduler_dp_data *dp_sch, bool is_ll_post_run)
3434
{
3535
struct list_item *tlist;
3636
struct task *curr_task;
@@ -106,6 +106,11 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
106106
}
107107
}
108108

109+
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch)
110+
{
111+
scheduler_dp_recalculate_thread(dp_sch, true);
112+
}
113+
109114
/* Thread function called in component context, on target core */
110115
void dp_thread_fn(void *p1, void *p2, void *p3)
111116
{
@@ -177,7 +182,7 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
177182
* currently its limited to current core only
178183
*/
179184
if (dp_sch)
180-
scheduler_dp_recalculate(dp_sch, false);
185+
scheduler_dp_recalculate_thread(dp_sch, false);
181186

182187
scheduler_dp_unlock(lock_key);
183188
}

src/schedule/zephyr_ll.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <sof/audio/component.h>
1111
#include <rtos/interrupt.h>
1212
#include <sof/lib/memory.h>
13-
#include <sof/lib/notifier.h>
13+
#include <sof/schedule/dp_schedule.h>
1414
#include <sof/schedule/ll_schedule_domain.h>
1515
#include <sof/schedule/schedule.h>
1616
#include <rtos/task.h>
@@ -325,10 +325,8 @@ static void zephyr_ll_run(void *data)
325325

326326
zephyr_ll_unlock(sch, &flags);
327327

328-
#ifndef CONFIG_SOF_USERSPACE_LL
329-
/* TODO: to be replaced with direct function calls */
330-
notifier_event(sch, NOTIFIER_ID_LL_POST_RUN,
331-
NOTIFIER_TARGET_CORE_LOCAL, NULL, 0);
328+
#ifdef CONFIG_ZEPHYR_DP_SCHEDULER
329+
scheduler_dp_ll_tick();
332330
#endif
333331
}
334332

0 commit comments

Comments
 (0)