Skip to content

Commit ff779df

Browse files
committed
wip
1 parent bb97220 commit ff779df

4 files changed

Lines changed: 68 additions & 10 deletions

File tree

src/audio/module_adapter/library/userspace_proxy.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ static const struct module_interface userspace_proxy_interface;
5151

5252
#if IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
5353
#include <sof/audio/module_adapter/iadk/system_agent.h>
54+
#include <sof/schedule/dp_schedule.h>
55+
56+
static inline int user_worker_get(void)
57+
{
58+
return 0;
59+
}
60+
static inline void user_worker_put(void) { }
61+
62+
struct k_work_user *userspace_proxy_register_ipc_handler(struct processing_module *mod,
63+
struct k_event *event)
64+
{
65+
struct userspace_context * const user_ctx = mod->user_ctx;
66+
if (user_ctx) {
67+
user_ctx->dp_event = event;
68+
assert(user_ctx->work_item);
69+
return &user_ctx->work_item->work_item;
70+
}
71+
72+
return NULL;
73+
}
5474
#else
5575
/* IPC requests targeting userspace modules are handled through a user work queue.
5676
* Each userspace module provides its own work item that carries the IPC request parameters.
@@ -109,6 +129,7 @@ static void user_worker_put(void)
109129
user_stack_free(worker.stack_ptr);
110130
}
111131
}
132+
#endif
112133

113134
static int user_work_item_init(struct userspace_context *user_ctx, struct k_heap *user_heap)
114135
{
@@ -131,7 +152,9 @@ static int user_work_item_init(struct userspace_context *user_ctx, struct k_heap
131152

132153
k_work_user_init(&work_item->work_item, userspace_proxy_worker_handler);
133154

155+
#if !IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
134156
work_item->event = &worker.event;
157+
#endif
135158
work_item->params.context = user_ctx;
136159
user_ctx->work_item = work_item;
137160

@@ -143,7 +166,6 @@ static void user_work_item_free(struct userspace_context *user_ctx, struct k_hea
143166
sof_heap_free(user_heap, user_ctx->work_item);
144167
user_worker_put();
145168
}
146-
#endif
147169

148170
static inline struct module_params *user_work_get_params(struct userspace_context *user_ctx)
149171
{
@@ -159,6 +181,11 @@ BUILD_ASSERT(IS_ALIGNED(MAILBOX_HOSTBOX_SIZE, CONFIG_MMU_PAGE_SIZE),
159181
static int userspace_proxy_invoke(struct userspace_context *user_ctx, uint32_t cmd,
160182
bool ipc_payload_access)
161183
{
184+
#if IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
185+
struct k_event * const event = user_ctx->dp_event;
186+
#else
187+
struct k_event * const event = &worker.event;
188+
#endif
162189
struct module_params *params = user_work_get_params(user_ctx);
163190
const uintptr_t ipc_req_buf = (uintptr_t)MAILBOX_HOSTBOX_BASE;
164191
struct k_mem_partition ipc_part = {
@@ -198,10 +225,13 @@ static int userspace_proxy_invoke(struct userspace_context *user_ctx, uint32_t c
198225
tr_err(&userspace_proxy_tr, "Submit to queue error: %d", ret);
199226
goto done;
200227
}
228+
#else
229+
assert(event);
230+
k_event_post(event, DP_TASK_EVENT_IPC);
201231
#endif
202232

203233
/* Timeout value is aligned with the ipc_wait_for_compound_msg function */
204-
if (!k_event_wait_safe(&worker.event, DP_TASK_EVENT_IPC_DONE, false,
234+
if (!k_event_wait_safe(event, DP_TASK_EVENT_IPC_DONE, false,
205235
Z_TIMEOUT_US(250 * 20))) {
206236
tr_err(&userspace_proxy_tr, "IPC processing timedout.");
207237
ret = -ETIMEDOUT;
@@ -319,7 +349,6 @@ static int userspace_proxy_start_agent(struct userspace_context *user_ctx,
319349
{
320350
const byte_array_t * const mod_cfg = (byte_array_t *)agent_params->mod_cfg;
321351
struct module_params *params = user_work_get_params(user_ctx);
322-
int ret;
323352

324353
params->ext.agent.start_fn = start_fn;
325354

@@ -332,7 +361,7 @@ static int userspace_proxy_start_agent(struct userspace_context *user_ctx,
332361
* init function. At this point the DP thread does not exist yet.
333362
*/
334363
#if !IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
335-
ret = userspace_proxy_invoke(user_ctx, USER_PROXY_MOD_CMD_AGENT_START, true);
364+
int ret = userspace_proxy_invoke(user_ctx, USER_PROXY_MOD_CMD_AGENT_START, true);
336365
if (ret)
337366
return ret;
338367

src/include/sof/audio/module_adapter/library/userspace_proxy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct userspace_context {
3131
struct k_mem_domain *comp_dom; /* Module specific memory domain */
3232
const struct module_interface *interface; /* Userspace module interface */
3333
struct user_work_item *work_item; /* work item for user worker thread */
34+
struct k_event *dp_event; /* DP thread event */
3435
};
3536
#endif /* CONFIG_USERSPACE */
3637

@@ -63,6 +64,11 @@ int userspace_proxy_create(struct userspace_context **user_ctx, const struct com
6364
*/
6465
void userspace_proxy_destroy(const struct comp_driver *drv, struct userspace_context *user_ctx);
6566

67+
#if IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
68+
struct k_work_user *userspace_proxy_register_ipc_handler(struct processing_module *mod,
69+
struct k_event *event);
70+
#endif
71+
6672
#endif /* CONFIG_SOF_USERSPACE_PROXY */
6773

6874
#endif /* __SOF_AUDIO_USERSPACE_PROXY_H__ */

src/schedule/zephyr_dp_schedule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum sof_dp_part_type {
3232
};
3333

3434
struct ipc4_flat;
35+
3536
struct task_dp_pdata {
3637
k_tid_t thread_id; /* zephyr thread ID */
3738
struct k_thread *thread; /* pointer to the kernels' thread object */
@@ -49,6 +50,9 @@ struct task_dp_pdata {
4950
#else
5051
struct k_event *event; /* pointer to event for task scheduling */
5152
struct k_event event_struct; /* event for task scheduling for kernel threads */
53+
#if IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
54+
struct k_work_user *ipc_work_item; /* work item for IPC handling */
55+
#endif
5256
#endif
5357
};
5458

src/schedule/zephyr_dp_schedule_thread.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* Copyright(c) 2025 Intel Corporation. All rights reserved.
44
*
55
* Author: Marcin Szkudlinski
6+
* Adrian Warecki
67
*/
78

89
#include <rtos/task.h>
910

1011
#include <sof/audio/module_adapter/module/generic.h>
12+
#include <sof/audio/module_adapter/library/userspace_proxy.h>
13+
#include <sof/audio/module_adapter/library/userspace_proxy_user.h>
14+
1115
#include <sof/common.h>
1216
#include <sof/list.h>
1317
#include <sof/schedule/ll_schedule_domain.h>
@@ -114,6 +118,7 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
114118
unsigned int lock_key;
115119
enum task_state state;
116120
bool task_stop;
121+
uint32_t event;
117122

118123
if (!(task->flags & K_USER))
119124
dp_sch = scheduler_get_data(SOF_SCHEDULE_DP);
@@ -123,13 +128,22 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
123128
* the thread is started immediately after creation, it will stop on event.
124129
* Event will be signalled once the task is ready to process.
125130
*/
126-
k_event_wait_safe(task_pdata->event, DP_TASK_EVENT_PROCESS | DP_TASK_EVENT_CANCEL,
127-
false, K_FOREVER);
131+
event = k_event_wait_safe(task_pdata->event, DP_TASK_EVENT_PROCESS |
132+
DP_TASK_EVENT_CANCEL | DP_TASK_EVENT_IPC, false,
133+
K_FOREVER);
128134

129-
if (task->state == SOF_TASK_STATE_RUNNING)
130-
state = task_run(task);
131-
else
132-
state = task->state; /* to avoid undefined variable warning */
135+
state = task->state; /* to avoid undefined variable warning */
136+
if (task->state == SOF_TASK_STATE_RUNNING) {
137+
switch (event) {
138+
case DP_TASK_EVENT_PROCESS:
139+
state = task_run(task);
140+
break;
141+
case DP_TASK_EVENT_IPC:
142+
assert(task_pdata->ipc_work_item);
143+
userspace_proxy_worker_handler(task_pdata->ipc_work_item);
144+
continue;
145+
}
146+
}
133147

134148
lock_key = scheduler_dp_lock(task->core);
135149
/*
@@ -293,6 +307,11 @@ int scheduler_dp_task_init(struct task **task,
293307
k_event_init(pdata->event);
294308
k_thread_start(pdata->thread_id);
295309

310+
#if IS_ENABLED(CONFIG_SOF_USERSPACE_PROXY) && \
311+
IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
312+
pdata->ipc_work_item = userspace_proxy_register_ipc_handler(mod, pdata->event);
313+
#endif
314+
296315
return 0;
297316

298317
e_thread:

0 commit comments

Comments
 (0)