Skip to content

Commit 48cdc4d

Browse files
committed
schedule: zephyr_ll: convert pdata->sem into sys_sem
Convert the pdata->sem into a sys_sem to make the code compatible with userspace LL builds. Using sys_sem allows access control to be based on access to zephyr_ll_pdata object and works both from kernel and user-space. Add POSIX no-op stubs for sys_sem to maintain testbench build compatibility. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent d7c254f commit 48cdc4d

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

posix/include/rtos/mutex.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,25 @@ static inline int sys_mutex_unlock(struct sys_mutex *mutex)
6262
return 0;
6363
}
6464

65+
/* provide a no-op implementation for zephyr/sys/sem.h */
66+
67+
struct sys_sem {
68+
};
69+
70+
static inline int sys_sem_init(struct sys_sem *sem, unsigned int initial_count,
71+
unsigned int limit)
72+
{
73+
return 0;
74+
}
75+
76+
static inline int sys_sem_give(struct sys_sem *sem)
77+
{
78+
return 0;
79+
}
80+
81+
static inline int sys_sem_take(struct sys_sem *sem, k_timeout_t timeout)
82+
{
83+
return 0;
84+
}
85+
6586
#endif

src/schedule/zephyr_ll.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <rtos/task.h>
1717
#include <sof/lib/perf_cnt.h>
1818
#include <zephyr/kernel.h>
19+
#include <zephyr/sys/sem.h>
1920
#include <ipc4/base_fw.h>
2021
#include <sof/debug/telemetry/telemetry.h>
2122

@@ -41,7 +42,7 @@ struct zephyr_ll {
4142
struct zephyr_ll_pdata {
4243
bool run;
4344
bool freeing;
44-
struct k_sem sem;
45+
struct sys_sem sem;
4546
};
4647

4748
#if CONFIG_SOF_USERSPACE_LL
@@ -136,7 +137,7 @@ static void zephyr_ll_task_done(struct zephyr_ll *sch,
136137
* zephyr_ll_task_free() is trying to free this task. Complete
137138
* it and signal the semaphore to let the function proceed
138139
*/
139-
k_sem_give(&pdata->sem);
140+
sys_sem_give(&pdata->sem);
140141

141142
tr_info(&ll_tr, "task complete %p %pU", task, task->uid);
142143
tr_info(&ll_tr, "num_tasks %d total_num_tasks %ld",
@@ -505,7 +506,7 @@ static int zephyr_ll_task_free(void *data, struct task *task)
505506

506507
if (must_wait)
507508
/* Wait for up to 100 periods */
508-
k_sem_take(&pdata->sem, K_USEC(LL_TIMER_PERIOD_US * 100));
509+
sys_sem_take(&pdata->sem, K_USEC(LL_TIMER_PERIOD_US * 100));
509510

510511
/* Protect against racing with schedule_task() */
511512
zephyr_ll_lock(sch, &flags);
@@ -691,7 +692,7 @@ int zephyr_ll_task_init(struct task *task,
691692

692693
memset(pdata, 0, sizeof(*pdata));
693694

694-
k_sem_init(&pdata->sem, 0, 1);
695+
sys_sem_init(&pdata->sem, 0, 1);
695696

696697
task->priv_data = pdata;
697698

0 commit comments

Comments
 (0)