Skip to content

Commit 253a5b7

Browse files
committed
DP: application: switch back to events
Events provide a more natural API when the listener have to wait for several kinds of alarms at once. As the userspace code stabilises initial difficulties with the API got fixed. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent a791d6c commit 253a5b7

File tree

3 files changed

+15
-52
lines changed

3 files changed

+15
-52
lines changed

src/schedule/zephyr_dp_schedule.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,8 @@ static int scheduler_dp_task_stop(void *data, struct task *task)
266266
schedule_task_cancel(&dp_sch->ll_tick_src);
267267

268268
/* if the task is waiting - let it run and self-terminate */
269-
#if CONFIG_SOF_USERSPACE_APPLICATION
270-
k_sem_give(pdata->sem);
271-
#else
272269
k_event_set(pdata->event, DP_TASK_EVENT_CANCEL);
273-
#endif
270+
274271
scheduler_dp_unlock(lock_key);
275272

276273
/* wait till the task has finished, if there was any task created */
@@ -296,12 +293,8 @@ static int scheduler_dp_task_free(void *data, struct task *task)
296293
}
297294

298295
#ifdef CONFIG_USERSPACE
299-
#if CONFIG_SOF_USERSPACE_PROXY
300296
if (pdata->event != &pdata->event_struct)
301297
k_object_free(pdata->event);
302-
#else
303-
k_object_free(pdata->sem);
304-
#endif
305298
if (pdata->thread != &pdata->thread_struct)
306299
k_object_free(pdata->thread);
307300
#endif

src/schedule/zephyr_dp_schedule.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@ struct task_dp_pdata {
4141
struct processing_module *mod; /* the module to be scheduled */
4242
uint32_t ll_cycles_to_start; /* current number of LL cycles till delayed start */
4343
#if CONFIG_SOF_USERSPACE_APPLICATION
44-
struct k_sem *sem; /* pointer to semaphore for task scheduling */
4544
struct ipc4_flat *flat;
46-
unsigned char pend_ipc;
47-
unsigned char pend_proc;
4845
struct k_mem_partition mpart[SOF_DP_PART_TYPE_COUNT];
49-
#else
46+
#endif
5047
struct k_event *event; /* pointer to event for task scheduling */
5148
struct k_event event_struct; /* event for task scheduling for kernel threads */
52-
#endif
5349
};
5450

5551
void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_run);

src/schedule/zephyr_dp_schedule_application.c

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
176176
pdata->flat->ret = -ENOSYS;
177177

178178
ret = ipc_thread_flatten(cmd, param, pdata->flat);
179-
if (!ret) {
180-
pdata->pend_ipc++;
181-
k_sem_give(pdata->sem);
182-
}
179+
if (!ret)
180+
k_event_post(pdata->event, DP_TASK_EVENT_IPC);
183181

184182
scheduler_dp_unlock(lock_key);
185183

@@ -225,8 +223,7 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
225223
/* trigger the task */
226224
curr_task->state = SOF_TASK_STATE_RUNNING;
227225
trigger_task = true;
228-
pdata->pend_proc++;
229-
k_sem_give(pdata->sem);
226+
k_event_post(pdata->event, DP_TASK_EVENT_PROCESS);
230227
}
231228

232229
if (curr_task->state == SOF_TASK_STATE_RUNNING) {
@@ -278,41 +275,18 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
278275
comp_info(pmod->dev, "userspace thread started");
279276

280277
do {
281-
/*
282-
* The thread is started immediately after creation, it stops here and waits
283-
* for the semaphore to be signalled to handle IPC or process audio data.
284-
*/
285-
k_sem_take(task_pdata->sem, K_FOREVER);
286-
287-
lock_key = scheduler_dp_lock(task->core);
288-
289-
unsigned char pend_ipc = task_pdata->pend_ipc,
290-
pend_proc = task_pdata->pend_proc;
291-
292-
task_pdata->pend_proc = 0;
293-
task_pdata->pend_ipc = 0;
294-
295-
scheduler_dp_unlock(lock_key);
296-
297-
/*
298-
* Only 0:1, 1:0 and 1:1 are valid. 0:0 is also possible if IPC and audio
299-
* were signalled in a quick succession before we took the lock above. Any
300-
* value > 1 would mean that we've missed IPCs or LL ticks while in queued /
301-
* idle state, which shouldn't happen.
302-
*/
303-
if (pend_ipc > 1 || pend_proc > 1) {
304-
tr_err(&dp_tr, "Invalid wake up %u:%u", pend_proc, pend_ipc);
305-
continue;
306-
}
278+
uint32_t mask = k_event_wait_safe(task_pdata->event,
279+
DP_TASK_EVENT_PROCESS | DP_TASK_EVENT_CANCEL |
280+
DP_TASK_EVENT_IPC, false, K_FOREVER);
307281

308-
if (pend_ipc) {
282+
if (mask & DP_TASK_EVENT_IPC) {
309283
/* handle IPC */
310284
tr_dbg(&dp_tr, "got IPC wake up for %p state %d", pmod, task->state);
311285
ipc_thread_unflatten_run(pmod, task_pdata->flat);
312286
k_sem_give(&dp_sync[task->core]);
313287
}
314288

315-
if (pend_proc) {
289+
if (mask & DP_TASK_EVENT_PROCESS) {
316290
bool ready;
317291

318292
if (task->state == SOF_TASK_STATE_RUNNING) {
@@ -459,8 +433,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
459433

460434
pdata->flat = &task_memory->flat;
461435

462-
pdata->sem = k_object_alloc(K_OBJ_SEM);
463-
if (!pdata->sem) {
436+
pdata->event = k_object_alloc(K_OBJ_EVENT);
437+
if (!pdata->event) {
464438
tr_err(&dp_tr, "Event object allocation failed");
465439
ret = -ENOMEM;
466440
goto e_stack;
@@ -497,7 +471,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
497471
goto e_thread;
498472
}
499473

500-
k_thread_access_grant(pdata->thread_id, pdata->sem, &dp_sync[core]);
474+
k_thread_access_grant(pdata->thread_id, pdata->event, &dp_sync[core]);
501475
scheduler_dp_grant(pdata->thread_id, core);
502476

503477
unsigned int pidx;
@@ -564,7 +538,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
564538
}
565539

566540
/* start the thread, it should immediately stop at the semaphore */
567-
k_sem_init(pdata->sem, 0, 1);
541+
k_event_init(pdata->event);
568542
k_thread_start(pdata->thread_id);
569543

570544
return 0;
@@ -576,7 +550,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
576550
e_kobj:
577551
/* k_object_free looks for a pointer in the list, any invalid value can be passed */
578552
k_object_free(pdata->thread);
579-
k_object_free(pdata->sem);
553+
k_object_free(pdata->event);
580554
e_stack:
581555
user_stack_free(p_stack);
582556
e_tmem:

0 commit comments

Comments
 (0)