Skip to content

Commit f7cf90e

Browse files
committed
switch to event
Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 39d760f commit f7cf90e

File tree

5 files changed

+26
-107
lines changed

5 files changed

+26
-107
lines changed

src/audio/module_adapter/library/userspace_proxy.c

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <sof/lib_manager.h>
2929
#include <sof/audio/component.h>
30+
#include <sof/schedule/dp_schedule.h>
3031
#include <rtos/userspace_helper.h>
3132
#include <utilities/array.h>
3233
#include <zephyr/sys/sem.h>
@@ -53,8 +54,7 @@ struct user_worker {
5354
uint32_t reference_count; /* module reference count */
5455
void *stack_ptr; /* pointer to worker stack */
5556
struct k_work_user_q work_queue;
56-
struct k_msgq *in_msgq; /* pointer to input message queue */
57-
struct k_msgq *out_msgq; /* pointer to output message queue */
57+
struct k_event event;
5858
};
5959

6060
/*
@@ -84,53 +84,9 @@ uint32_t ptable_size(struct k_mem_domain *domain)
8484

8585
return cnt;
8686
}
87-
#if 0
88-
static int userspace_proxy_msgq_alloc(struct userspace_context *context)
89-
{
90-
char *buffer;
91-
92-
buffer = rzalloc(SOF_MEM_FLAG_USER_SHARED_BUFFER, MAX_PARAM_SIZE * 2);
93-
if (!buffer)
94-
return -ENOMEM;
95-
96-
context->in_msgq = k_object_alloc(K_OBJ_MSGQ);
97-
if (!context->in_msgq) {
98-
rfree(buffer);
99-
return -ENOMEM;
100-
}
101-
102-
context->out_msgq = k_object_alloc(K_OBJ_MSGQ);
103-
if (!context->out_msgq) {
104-
k_object_free(context->in_msgq);
105-
rfree(buffer);
106-
return -ENOMEM;
107-
}
108-
/* k_msgq_alloc_init */
109-
k_msgq_init(context->in_msgq, buffer, MAX_PARAM_SIZE, 1);
110-
k_msgq_init(context->out_msgq, (buffer + MAX_PARAM_SIZE), MAX_PARAM_SIZE, 1);
11187

112-
return 0;
113-
}
114-
115-
static void user_worker_msgq_free()
116-
{
117-
int ret;
118-
/* in_msgq->buffer_start points to whole buffer allocated for message queues */
119-
/* TODO: Assert error code */
120-
ret = k_msgq_cleanup(worker.in_msgq);
121-
assert(!ret);
122-
ret = k_msgq_cleanup(worker.out_msgq);
123-
assert(!ret);
124-
125-
rfree(worker.in_msgq->buffer_start);
126-
k_object_free(worker.in_msgq);
127-
k_object_free(worker.out_msgq);
128-
}
129-
#endif
13088
static int user_worker_create()
13189
{
132-
char *buffer = NULL;
133-
13490
if (worker.reference_count)
13591
return 0;
13692

@@ -142,66 +98,36 @@ static int user_worker_create()
14298
return -ENOMEM;
14399
}
144100

145-
buffer = rzalloc(SOF_MEM_FLAG_USER_SHARED_BUFFER, MAX_PARAM_SIZE * 2);
146-
if (!buffer)
147-
goto error;
148-
149-
worker.in_msgq = k_object_alloc(K_OBJ_MSGQ);
150-
if (!worker.in_msgq)
151-
goto error;
152-
153-
worker.out_msgq = k_object_alloc(K_OBJ_MSGQ);
154-
if (!worker.out_msgq)
155-
goto error;
156-
157-
/* k_msgq_alloc_init */
158-
k_msgq_init(worker.in_msgq, buffer, MAX_PARAM_SIZE, 1);
159-
k_msgq_init(worker.out_msgq, (buffer + MAX_PARAM_SIZE), MAX_PARAM_SIZE, 1);
160-
101+
k_event_init(&worker.event);
161102
k_work_user_queue_start(&worker.work_queue, worker.stack_ptr, CONFIG_SOF_STACK_SIZE, 0,
162103
"Userspace proxy worker");
163104

164105
worker.thread_id = k_work_user_queue_thread_get(&worker.work_queue);
165106

166107
/* Grant a thread access to a kernel object (IPC msg. data). */
167-
k_thread_access_grant(worker.thread_id, worker.in_msgq, worker.out_msgq);
108+
k_thread_access_grant(worker.thread_id, &worker.event);
168109

169110
worker.reference_count++;
170111
return 0;
171-
112+
#if 0
172113
error:
173114
/* TODO: Moze wspolna funckja free? */
174-
k_object_free(worker.in_msgq);
175-
k_object_free(worker.out_msgq);
176-
rfree(buffer);
177115
user_stack_free(worker.stack_ptr);
178116
return -ENOMEM;
117+
#endif
179118
}
180119

181120
static void user_worker_free()
182121
{
183-
int ret;
184-
185122
/* Module removed so decrement counter */
186123
worker.reference_count--;
187124

188125
/* Free worker resources if no more active user space modules */
189126
if (worker.reference_count == 0) {
190127
tr_dbg(&userspace_proxy_tr, "free");
191128

192-
/* in_msgq->buffer_start points to whole buffer allocated for message queues */
193-
/* TODO: Assert error code */
194-
ret = k_msgq_cleanup(worker.in_msgq);
195-
assert(!ret);
196-
ret = k_msgq_cleanup(worker.out_msgq);
197-
assert(!ret);
198-
199129
k_thread_abort(worker.thread_id);
200130
user_stack_free(worker.stack_ptr);
201-
202-
rfree(worker.in_msgq->buffer_start);
203-
k_object_free(worker.in_msgq);
204-
k_object_free(worker.out_msgq);
205131
}
206132
}
207133

@@ -222,8 +148,7 @@ static int user_work_item_init(struct userspace_context *context, struct k_heap
222148

223149
k_work_user_init(&work_item->work_item, userspace_proxy_worker_handler);
224150

225-
work_item->in_msgq = worker.in_msgq;
226-
work_item->out_msgq = worker.out_msgq;
151+
work_item->event = &worker.event;
227152
work_item->params.context = context;
228153
context->work_item = work_item;
229154

@@ -275,23 +200,20 @@ static int userspace_proxy_invoke(struct userspace_context *context, struct proc
275200
return ret;
276201
}
277202

278-
ret = k_msgq_put(worker.in_msgq, params, K_FOREVER);
279-
if (ret < 0) {
280-
comp_err(mod->dev, "k_msgq_put(): error: %d", ret);
281-
return ret;
282-
}
283-
284203
ret = k_work_user_submit_to_queue(&worker.work_queue, &context->work_item->work_item);
285204
if (ret < 0) {
286205
comp_err(mod->dev, "k_work_user_submit_to_queue(): error: %d", ret);
287206
return ret;
288207
}
289208

290-
ret = k_msgq_get(worker.out_msgq, params, K_FOREVER);
291-
if (ret < 0)
292-
comp_err(mod->dev, "k_msgq_get(): error: %d", ret);
209+
/* Timeout value is aligned with the ipc_wait_for_compound_msg function */
210+
if (!k_event_wait_safe(&worker.event, DP_TASK_EVENT_IPC_DONE, false,
211+
Z_TIMEOUT_US(250 * 20))) {
212+
comp_err(mod->dev, "ipc processing timedout.");
213+
return -ETIMEDOUT;
214+
}
293215

294-
return ret;
216+
return 0;
295217
}
296218

297219
extern struct k_mem_partition ipc_partition;

src/audio/module_adapter/library/userspace_proxy_user.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stdint.h>
2323

2424
#include <sof/audio/component.h>
25+
#include <sof/schedule/dp_schedule.h>
2526
#include <utilities/array.h>
2627
#include <zephyr/sys/sem.h>
2728
#include <sof/audio/module_adapter/module/generic.h>
@@ -122,11 +123,8 @@ void userspace_proxy_worker_handler(struct k_work_user *work_item)
122123
{
123124
struct user_work_item *user_work_item = CONTAINER_OF(work_item, struct user_work_item,
124125
work_item);
125-
struct module_params *params = (struct module_params *)user_work_item->ipc_params;
126+
struct module_params *params = &user_work_item->params;
126127

127-
k_msgq_get(user_work_item->in_msgq, params, K_FOREVER);
128128
userspace_proxy_handle_request(params->mod, params);
129-
k_msgq_put(user_work_item->out_msgq, params, K_FOREVER);
130-
131-
k_yield();
129+
k_event_post(user_work_item->event, DP_TASK_EVENT_IPC_DONE);
132130
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#define __SOF_AUDIO_USERSPACE_PROXY_USER_H__
1010

1111
#if CONFIG_SOF_USERSPACE_PROXY
12-
13-
/* IPC works synchronously so single message queue is ok */
14-
#define MSGQ_LEN 1
15-
#define MAX_PARAM_SIZE 0x200
16-
1712
struct module_agent_params {
1813
system_agent_start_fn start_fn;
1914
struct system_agent_params params;
@@ -54,7 +49,6 @@ enum userspace_proxy_cmd {
5449
MODULE_CMD_INIT,
5550
MODULE_CMD_PREPARE,
5651
MODULE_CMD_PROC_READY,
57-
MODULE_CMD_PROCESS,
5852
MODULE_CMD_SET_PROCMOD,
5953
MODULE_CMD_GET_PROCMOD,
6054
MODULE_CMD_SET_CONF,
@@ -84,13 +78,10 @@ struct module_params {
8478

8579
struct user_work_item {
8680
struct k_work_user work_item; /* ipc worker workitem */
87-
struct k_msgq *in_msgq; /* pointer to input message queue owned by worker */
88-
struct k_msgq *out_msgq; /* pointer to output message queue owned by worker*/
89-
uint8_t ipc_params[MAX_PARAM_SIZE]; /* ipc parameter buffer */
81+
struct k_event *event; /* ipc worker done event */
9082
struct module_params params;
9183
};
9284

93-
9485
void userspace_proxy_handle_request(struct processing_module *mod, struct module_params *params);
9586

9687
void userspace_proxy_worker_handler(struct k_work_user *work_item);

src/include/sof/schedule/dp_schedule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ int scheduler_dp_task_init(struct task **task,
8686
void scheduler_get_task_info_dp(struct scheduler_props *scheduler_props,
8787
uint32_t *data_off_size);
8888

89+
enum {
90+
DP_TASK_EVENT_IPC_DONE = BIT(3), /* IPC processing has completed. */
91+
};
92+
8993
#endif /* __SOF_SCHEDULE_DP_SCHEDULE_H__ */

src/schedule/zephyr_dp_schedule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ struct scheduler_dp_data {
2222

2323
};
2424

25+
enum {
26+
DP_EVENT_IPC_DONE = BIT(3),
27+
};
28+
2529
struct task_dp_pdata {
2630
k_tid_t thread_id; /* zephyr thread ID */
2731
struct k_thread *thread; /* pointer to the kernels' thread object */

0 commit comments

Comments
 (0)