Skip to content

Commit 7f5fc11

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 those operations at the same time. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 46d02e3 commit 7f5fc11

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
/* The __ZEPHYR__ condition is to keep cmocka tests working */
3030
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
3131
#define MEM_API_CHECK_THREAD(res) do { \
32-
if ((res)->rsrc_mngr != k_current_get()) \
33-
LOG_WRN("mngr %p != cur %p", (res)->rsrc_mngr, k_current_get()); \
32+
k_tid_t tid = k_current_get(); \
33+
if ((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); \
3435
} while (0)
3536
#else
3637
#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
@@ -139,7 +139,7 @@ struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv
139139
goto emod;
140140
}
141141

142-
struct mod_alloc_ctx *alloc = rmalloc(flags, sizeof(*alloc));
142+
struct mod_alloc_ctx *alloc = rzalloc(flags, sizeof(*alloc));
143143

144144
if (!alloc)
145145
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
#ifdef CONFIG_SCHED_CPU_MASK
508512
/* pin the thread to specific core */
509513
ret = k_thread_cpu_pin(pdata->thread_id, core);

0 commit comments

Comments
 (0)