Skip to content

Commit de721ab

Browse files
committed
schedule: dp: userspace grant IPC thread rights on DP assets
In case of userspace LL scheduling the (also userspace) IPC thread needs access rights to DP assets like the thread itself and its stack and synchronisation primitives. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent f2d4b55 commit de721ab

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/include/sof/ipc/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,9 @@ int ipc_user_forward_cmd(struct ipc4_message_request *ipc4, unsigned int core);
331331
int ipc_user_init_secondary(unsigned int core);
332332
#endif
333333

334+
/**
335+
* \brief get pointer to the userspace IPC thread for core
336+
*/
337+
struct k_thread *ipc_thread_user(unsigned int core);
338+
334339
#endif /* __SOF_DRIVERS_IPC_H__ */

src/ipc/ipc-common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ __cold int ipc_user_init_secondary(unsigned int core)
712712
return 0;
713713
}
714714

715+
struct k_thread *ipc_thread_user(unsigned int core)
716+
{
717+
struct ipc *ipc = ipc_get();
718+
struct ipc_user *ipc_user = ipc->ipc_user_pdata;
719+
720+
return ipc_user->thread[core];
721+
}
722+
715723
/* Primary core only */
716724
__cold static int ipc_user_init(void)
717725
{

src/schedule/zephyr_dp_schedule_application.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sof/audio/module_adapter/module/generic.h>
1111
#include <sof/audio/component.h>
1212
#include <sof/common.h>
13+
#include <sof/ipc/common.h>
1314
#include <sof/list.h>
1415
#include <sof/llext_manager.h>
1516
#include <sof/objpool.h>
@@ -156,6 +157,7 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
156157
const union scheduler_dp_thread_ipc_param *param)
157158
{
158159
struct task_dp_pdata *pdata = pmod->dev->task->priv_data;
160+
unsigned int core = pmod->dev->task->core;
159161
int ret;
160162

161163
if (!pmod) {
@@ -165,14 +167,14 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
165167

166168
if (cmd == SOF_IPC4_MOD_INIT_INSTANCE) {
167169
/* Wait for the DP thread to start */
168-
ret = k_sem_take(&dp_sync[pmod->dev->task->core], DP_THREAD_IPC_TIMEOUT);
170+
ret = k_sem_take(&dp_sync[core], DP_THREAD_IPC_TIMEOUT);
169171
if (ret < 0) {
170172
tr_err(&dp_tr, "Failed waiting for DP thread to start: %d", ret);
171173
return ret;
172174
}
173175
}
174176

175-
unsigned int lock_key = scheduler_dp_lock(pmod->dev->task->core);
177+
unsigned int lock_key = scheduler_dp_lock(core);
176178

177179
/* IPCs are serialised */
178180
pdata->flat->ret = -ENOSYS;
@@ -185,7 +187,7 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
185187

186188
if (!ret) {
187189
/* Wait for completion */
188-
ret = k_sem_take(&dp_sync[cpu_get_id()], DP_THREAD_IPC_TIMEOUT);
190+
ret = k_sem_take(&dp_sync[core], DP_THREAD_IPC_TIMEOUT);
189191
if (ret < 0)
190192
tr_err(&dp_tr, "Failed waiting for DP thread: %d", ret);
191193
else
@@ -524,6 +526,12 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
524526

525527
k_thread_access_grant(pdata->thread_id, pdata->event, &dp_sync[core]);
526528
scheduler_dp_grant(pdata->thread_id, core);
529+
#if CONFIG_SOF_USERSPACE_LL
530+
struct k_thread *thread_ipc = ipc_thread_user(core);
531+
532+
k_thread_access_grant(thread_ipc, pdata->event, pdata->thread_id, p_stack, &dp_sync[core]);
533+
scheduler_dp_grant(thread_ipc, core);
534+
#endif
527535

528536
struct k_mem_domain *mdom = objpool_alloc(&dp_mdom_head, sizeof(*mdom),
529537
SOF_MEM_FLAG_COHERENT);

0 commit comments

Comments
 (0)