Skip to content

Commit e408f4a

Browse files
author
Jyri Sarha
committed
module_adapter: fix memory API debug check for DP modules
Add dp_thread field to module_resources so that the memory API debug check accepts allocations from both the IPC thread (rsrc_mngr) and the DP thread. Update MEM_API_CHECK_THREAD to check both thread IDs. Also change mod_alloc_ctx allocation from rmalloc to rzalloc to zero-initialize the structure. The code assumes the dp_thread member is NULL in case of a non-DP module. Both threads using the memory tracking features is not a problem since the memory operations are synchronized with semaphores and events so that both threads are never doing resource operations at the same time. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 0f9fa75 commit e408f4a

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
/* The __ZEPHYR__ condition is to keep cmocka tests working */
2929
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
3030
#define MEM_API_CHECK_THREAD(res) do { \
31-
if ((res)->rsrc_mngr != k_current_get()) \
32-
LOG_WRN("mngr %p != cur %p", (res)->rsrc_mngr, k_current_get()); \
31+
k_tid_t tid = k_current_get(); \
32+
if (((res)->rsrc_mngr != NULL || (res)->dp_thread != NULL) && \
33+
(res)->rsrc_mngr != tid && (res)->dp_thread != tid) \
34+
LOG_WRN("cur %p != mngr %p or dp %p", tid, (res)->rsrc_mngr, (res)->dp_thread); \
3335
} while (0)
3436
#else
3537
#define MEM_API_CHECK_THREAD(res)

src/audio/module_adapter/module_adapter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
118118
goto emod;
119119
}
120120

121-
struct mod_alloc_ctx *alloc = rmalloc(flags, sizeof(*alloc));
121+
struct mod_alloc_ctx *alloc = rzalloc(flags, sizeof(*alloc));
122122

123123
if (!alloc)
124124
goto ealloc;

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct module_resources {
135135
struct mod_alloc_ctx *alloc;
136136
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
137137
k_tid_t rsrc_mngr;
138+
k_tid_t dp_thread;
138139
#endif
139140
};
140141

src/schedule/zephyr_dp_schedule_application.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
504504
stack_size, dp_thread_fn, ptask, NULL, NULL,
505505
CONFIG_DP_THREAD_PRIORITY, ptask->flags, K_FOREVER);
506506
scheduler_dp_thread_name_set(pdata->thread_id, mod);
507+
#if CONFIG_MODULE_MEMORY_API_DEBUG
508+
/* For a DP module the reource manager can also be the DP thread */
509+
mod->priv.resources.dp_thread = pdata->thread_id;
510+
#endif
507511

508512
unsigned int pidx;
509513
size_t size;

0 commit comments

Comments
 (0)