Skip to content

Commit bfc6d3b

Browse files
committed
audio: module: simplify resource allocation context
Flatten struct sof_alloc_api by removing struct dp_heap_user. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent f76f4c9 commit bfc6d3b

6 files changed

Lines changed: 25 additions & 43 deletions

File tree

src/audio/buffers/comp_buffer.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,12 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
163163
struct sof_alloc_api *alloc = buffer->audio_buffer.alloc;
164164

165165
rfree(buffer->stream.addr);
166-
if (alloc && alloc->vreg)
166+
if (alloc && alloc->vreg) {
167167
vregion_free(alloc->vreg, buffer);
168-
else
168+
if (!--alloc->client_count)
169+
vregion_destroy(alloc->vreg);
170+
} else {
169171
sof_heap_free(alloc ? alloc->heap : NULL, buffer);
170-
171-
if (alloc && alloc->client && !--alloc->client->client_count) {
172-
rfree(alloc->client);
173-
alloc->client = NULL;
174-
/* NULL is allowed */
175-
vregion_destroy(alloc->vreg);
176172
}
177173
}
178174

src/audio/module_adapter/module/generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void mod_heap_info(struct processing_module *mod, size_t *size, uintptr_t *start
162162
*size = res->alloc.heap->heap.init_bytes;
163163

164164
if (start)
165-
*start = (uintptr_t)res->alloc.client;
165+
*start = (uintptr_t)res->alloc.heap;
166166
}
167167
#endif
168168

src/audio/module_adapter/module_adapter.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
5757
#define PAGE_SZ HOST_PAGE_SIZE
5858
#endif
5959

60-
static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_config *config,
61-
size_t *heap_size)
60+
static struct k_heap *module_adapter_dp_heap_new(const struct comp_ipc_config *config,
61+
size_t *heap_size)
6262
{
6363
/* src-lite with 8 channels has been seen allocating 14k in one go */
6464
/* FIXME: the size will be derived from configuration */
@@ -71,9 +71,8 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
7171
if (!mod_heap_mem)
7272
return NULL;
7373

74-
struct dp_heap_user *mod_heap_user = (struct dp_heap_user *)mod_heap_mem;
75-
struct k_heap *mod_heap = &mod_heap_user->heap;
76-
const size_t heap_prefix_size = ALIGN_UP(sizeof(*mod_heap_user), 4);
74+
struct k_heap *mod_heap = (struct k_heap *)mod_heap_mem;
75+
const size_t heap_prefix_size = ALIGN_UP(sizeof(*mod_heap), 4);
7776
void *mod_heap_buf = mod_heap_mem + heap_prefix_size;
7877

7978
*heap_size = buf_size - heap_prefix_size;
@@ -83,7 +82,7 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
8382
mod_heap->heap.init_bytes = *heap_size;
8483
#endif
8584

86-
return mod_heap_user;
85+
return mod_heap;
8786
}
8887

8988
static struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
@@ -99,20 +98,17 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
9998
*/
10099
uint32_t flags = config->proc_domain == COMP_PROCESSING_DOMAIN_DP ?
101100
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER;
102-
struct dp_heap_user *mod_heap_user;
103101
size_t heap_size;
104102

105103
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP && IS_ENABLED(CONFIG_USERSPACE) &&
106104
!IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP)) {
107-
mod_heap_user = module_adapter_dp_heap_new(config, &heap_size);
108-
if (!mod_heap_user) {
105+
mod_heap = module_adapter_dp_heap_new(config, &heap_size);
106+
if (!mod_heap) {
109107
comp_cl_err(drv, "Failed to allocate DP module heap");
110108
return NULL;
111109
}
112-
mod_heap = &mod_heap_user->heap;
113110
} else {
114111
mod_heap = drv->user_heap;
115-
mod_heap_user = NULL;
116112
heap_size = 0;
117113
}
118114

@@ -123,9 +119,10 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
123119
goto emod;
124120
}
125121

122+
struct sof_alloc_api *alloc = &mod->priv.resources.alloc;
123+
126124
memset(mod, 0, sizeof(*mod));
127-
mod->priv.resources.alloc.heap = mod_heap;
128-
mod->priv.resources.alloc.client = mod_heap_user;
125+
alloc->heap = mod_heap;
129126
mod_resource_init(mod);
130127

131128
/*
@@ -147,22 +144,23 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
147144
mod->dev = dev;
148145
dev->mod = mod;
149146

150-
if (mod_heap_user)
151-
mod_heap_user->client_count++;
147+
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP)
148+
alloc->client_count++;
152149

153150
return mod;
154151

155152
err:
156153
sof_heap_free(mod_heap, mod);
157154
emod:
158-
rfree(mod_heap_user);
155+
rfree(mod_heap);
159156

160157
return NULL;
161158
}
162159

163160
static void module_adapter_mem_free(struct processing_module *mod)
164161
{
165-
struct k_heap *mod_heap = mod->priv.resources.alloc.heap;
162+
struct sof_alloc_api *alloc = &mod->priv.resources.alloc;
163+
struct k_heap *mod_heap = alloc->heap;
166164
unsigned int domain = mod->dev->ipc_config.proc_domain;
167165

168166
/*
@@ -174,13 +172,8 @@ static void module_adapter_mem_free(struct processing_module *mod)
174172
#endif
175173
sof_heap_free(mod_heap, mod->dev);
176174
sof_heap_free(mod_heap, mod);
177-
if (domain == COMP_PROCESSING_DOMAIN_DP) {
178-
struct dp_heap_user *mod_heap_user = container_of(mod_heap, struct dp_heap_user,
179-
heap);
180-
181-
if (mod_heap && !--mod_heap_user->client_count)
182-
rfree(mod_heap_user);
183-
}
175+
if (domain == COMP_PROCESSING_DOMAIN_DP && mod_heap && !--alloc->client_count)
176+
rfree(mod_heap);
184177
}
185178

186179
/*
@@ -626,7 +619,7 @@ int module_adapter_prepare(struct comp_dev *dev)
626619

627620
if (md->resources.alloc.heap &&
628621
md->resources.alloc.heap != dev->drv->user_heap)
629-
md->resources.alloc.client->client_count++;
622+
md->resources.alloc.client_count++;
630623

631624
irq_local_disable(flags);
632625
list_item_prepend(&buffer->buffers_list, &mod->raw_data_buffers_list);

src/include/sof/audio/component.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,10 @@ struct comp_ops {
580580

581581
struct k_heap;
582582
struct vregion;
583-
struct dp_heap_user;
584583
struct sof_alloc_api {
585584
struct k_heap *heap;
586585
struct vregion *vreg;
587-
struct dp_heap_user *client;
586+
unsigned int client_count; /* devices and buffers */
588587
};
589588

590589
/**

src/include/sof/schedule/dp_schedule.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ union scheduler_dp_thread_ipc_param {
119119
} pipeline_state;
120120
};
121121

122-
struct dp_heap_user {
123-
struct k_heap heap;
124-
/* So far relying on linear processing of serialized IPCs, but might need protection */
125-
unsigned int client_count; /* devices and buffers */
126-
};
127-
128122
#if CONFIG_ZEPHYR_DP_SCHEDULER
129123
int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
130124
const union scheduler_dp_thread_ipc_param *param);

src/ipc/ipc4/helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
739739

740740
#if CONFIG_ZEPHYR_DP_SCHEDULER
741741
if (alloc)
742-
alloc->client->client_count++;
742+
alloc->client_count++;
743743
#endif
744744

745745
/*

0 commit comments

Comments
 (0)