Skip to content

Commit d48ffd4

Browse files
committed
Revert "module: generic: remove MEM_API_CHECK_THREAD debug mechanism"
This reverts commit 768faad.
1 parent 0c62a98 commit d48ffd4

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/audio/module_adapter/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ menu "Processing modules"
1313
containers to allocate at once is selected by this
1414
config option.
1515

16+
config MODULE_MEMORY_API_DEBUG
17+
bool "Turn on memory API thread safety checks"
18+
default y if DEBUG
19+
help
20+
The Module Memory API structures are not protected
21+
by locks. This is because the initialization,
22+
allocation, and freeing of resources should always
23+
be done in the same thread. This option adds an
24+
assert to make sure no other thread makes such
25+
operations.
26+
1627
config CADENCE_CODEC
1728
bool "Cadence codec"
1829
help

‎src/audio/module_adapter/module/generic.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
#include <ipc4/pipeline.h>
2727
#endif
2828

29+
/* The __ZEPHYR__ condition is to keep cmocka tests working */
30+
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
31+
#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()); \
34+
} while (0)
35+
#else
36+
#define MEM_API_CHECK_THREAD(res)
37+
#endif
38+
2939
LOG_MODULE_DECLARE(module_adapter, CONFIG_SOF_LOG_LEVEL);
3040

3141
int module_load_config(struct comp_dev *dev, const void *cfg, size_t size)
@@ -114,6 +124,9 @@ int module_init(struct processing_module *mod)
114124
return -EIO;
115125
}
116126

127+
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
128+
mod->priv.resources.rsrc_mngr = k_current_get();
129+
#endif
117130
/* Now we can proceed with module specific initialization */
118131
#if CONFIG_SOF_USERSPACE_APPLICATION
119132
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP)
@@ -179,6 +192,8 @@ void *z_impl_mod_balloc_align(struct processing_module *mod, size_t size, size_t
179192
struct module_resources *res = &mod->priv.resources;
180193
struct module_resource *container;
181194

195+
MEM_API_CHECK_THREAD(res);
196+
182197
k_mutex_lock(&res->lock, K_FOREVER);
183198

184199
container = container_get(mod);
@@ -235,6 +250,8 @@ void *z_impl_mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t
235250
struct module_resources *res = &mod->priv.resources;
236251
struct module_resource *container;
237252

253+
MEM_API_CHECK_THREAD(res);
254+
238255
k_mutex_lock(&res->lock, K_FOREVER);
239256

240257
container = container_get(mod);
@@ -288,6 +305,8 @@ struct comp_data_blob_handler *z_impl_mod_data_blob_handler_new(struct processin
288305
struct comp_data_blob_handler *bhp;
289306
struct module_resource *container;
290307

308+
MEM_API_CHECK_THREAD(res);
309+
291310
k_mutex_lock(&res->lock, K_FOREVER);
292311

293312
container = container_get(mod);
@@ -328,6 +347,8 @@ const void *z_impl_mod_fast_get(struct processing_module *mod, const void * cons
328347
struct module_resource *container;
329348
const void *ptr;
330349

350+
MEM_API_CHECK_THREAD(res);
351+
331352
k_mutex_lock(&res->lock, K_FOREVER);
332353

333354
container = container_get(mod);
@@ -419,6 +440,7 @@ int z_impl_mod_free(struct processing_module *mod, const void *ptr)
419440
{
420441
struct module_resources *res = &mod->priv.resources;
421442

443+
MEM_API_CHECK_THREAD(res);
422444
if (!ptr)
423445
return 0;
424446

@@ -738,6 +760,8 @@ void mod_free_all(struct processing_module *mod)
738760
{
739761
struct module_resources *res = &mod->priv.resources;
740762

763+
MEM_API_CHECK_THREAD(res);
764+
741765
/* Free all contents found in used containers */
742766
struct mod_res_cb_arg cb_arg = {mod, NULL};
743767

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include <sof/ipc/msg.h>
2323
#include "module_interface.h"
2424

25+
/* The __ZEPHYR__ condition is to keep cmocka tests working */
26+
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
27+
#include <zephyr/kernel/thread.h>
28+
#endif
2529
#include <sof/compiler_attributes.h>
2630

2731
/*
@@ -131,6 +135,9 @@ struct module_resources {
131135
size_t heap_usage;
132136
size_t heap_high_water_mark;
133137
struct mod_alloc_ctx *alloc;
138+
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
139+
k_tid_t rsrc_mngr;
140+
#endif
134141
};
135142

136143
enum mod_resource_type {

0 commit comments

Comments
 (0)