Skip to content

Commit 4f39a7c

Browse files
lyakhlgirdwood
authored andcommitted
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 027a13f commit 4f39a7c

3 files changed

Lines changed: 16 additions & 49 deletions

File tree

src/schedule/zephyr_dp_schedule.c

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

266266
/* if the task is waiting - let it run and self-terminate */
267-
#if CONFIG_SOF_USERSPACE_APPLICATION
268-
k_sem_give(pdata->sem);
269-
#else
270267
k_event_set(pdata->event, DP_TASK_EVENT_CANCEL);
271-
#endif
268+
272269
scheduler_dp_unlock(lock_key);
273270

274271
/* wait till the task has finished, if there was any task created */

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: 14 additions & 40 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) {
@@ -411,7 +385,7 @@ void scheduler_dp_internal_free(struct task *task)
411385
{
412386
struct task_dp_pdata *pdata = task->priv_data;
413387

414-
k_object_free(pdata->sem);
388+
k_object_free(pdata->event);
415389
k_object_free(pdata->thread);
416390
scheduler_dp_domain_free(pdata);
417391

@@ -471,8 +445,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
471445

472446
pdata->flat = &task_memory->flat;
473447

474-
pdata->sem = k_object_alloc(K_OBJ_SEM);
475-
if (!pdata->sem) {
448+
pdata->event = k_object_alloc(K_OBJ_EVENT);
449+
if (!pdata->event) {
476450
tr_err(&dp_tr, "Event object allocation failed");
477451
ret = -ENOMEM;
478452
goto e_stack;
@@ -509,7 +483,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
509483
goto e_thread;
510484
}
511485

512-
k_thread_access_grant(pdata->thread_id, pdata->sem, &dp_sync[core]);
486+
k_thread_access_grant(pdata->thread_id, pdata->event, &dp_sync[core]);
513487
scheduler_dp_grant(pdata->thread_id, core);
514488

515489
unsigned int pidx;
@@ -579,7 +553,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
579553
}
580554

581555
/* start the thread, it should immediately stop at the semaphore */
582-
k_sem_init(pdata->sem, 0, 1);
556+
k_event_init(pdata->event);
583557
k_thread_start(pdata->thread_id);
584558

585559
return 0;
@@ -591,7 +565,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
591565
e_kobj:
592566
/* k_object_free looks for a pointer in the list, any invalid value can be passed */
593567
k_object_free(pdata->thread);
594-
k_object_free(pdata->sem);
568+
k_object_free(pdata->event);
595569
e_stack:
596570
user_stack_free(p_stack);
597571
e_tmem:

0 commit comments

Comments
 (0)