Skip to content

Commit 4946982

Browse files
committed
pipeline: allocate on specific heap
Add a heap parameter to pipeline allocation functions. This makes it possible to control how allocations are done with pipeline granularity and makes it possible to move pipelines to user-space. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 5267a4b commit 4946982

7 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/audio/pipeline/pipeline-graph.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sof/ipc/msg.h>
1212
#include <rtos/interrupt.h>
1313
#include <rtos/symbol.h>
14+
#include <rtos/alloc.h>
1415
#include <sof/lib/mm_heap.h>
1516
#include <sof/lib/uuid.h>
1617
#include <sof/compiler_attributes.h>
@@ -108,8 +109,8 @@ void pipeline_posn_init(struct sof *sof)
108109
}
109110

110111
/* create new pipeline - returns pipeline id or negative error */
111-
struct pipeline *pipeline_new(uint32_t pipeline_id, uint32_t priority, uint32_t comp_id,
112-
struct create_pipeline_params *pparams)
112+
struct pipeline *pipeline_new(struct k_heap *heap, uint32_t pipeline_id, uint32_t priority,
113+
uint32_t comp_id, struct create_pipeline_params *pparams)
113114
{
114115
struct sof_ipc_stream_posn posn;
115116
struct pipeline *p;
@@ -122,13 +123,16 @@ struct pipeline *pipeline_new(uint32_t pipeline_id, uint32_t priority, uint32_t
122123
heap_trace_all(0);
123124

124125
/* allocate new pipeline */
125-
p = rzalloc(SOF_MEM_FLAG_USER, sizeof(*p));
126+
p = sof_heap_alloc(heap, SOF_MEM_FLAG_USER, sizeof(*p), 0);
126127
if (!p) {
127128
pipe_cl_err("Out of Memory");
128129
return NULL;
129130
}
130131

132+
memset(p, 0, sizeof(*p));
133+
131134
/* init pipeline */
135+
p->heap = heap;
132136
p->comp_id = comp_id;
133137
p->priority = priority;
134138
p->pipeline_id = pipeline_id;
@@ -161,7 +165,7 @@ struct pipeline *pipeline_new(uint32_t pipeline_id, uint32_t priority, uint32_t
161165

162166
return p;
163167
free:
164-
rfree(p);
168+
sof_heap_free(heap, p);
165169
return NULL;
166170
}
167171

@@ -230,15 +234,15 @@ int pipeline_free(struct pipeline *p)
230234
#if !CONFIG_LIBRARY || UNIT_TEST
231235
schedule_task_free(p->pipe_task);
232236
#endif
233-
rfree(p->pipe_task);
237+
sof_heap_free(p->heap, p->pipe_task);
234238
}
235239

236240
ipc_msg_free(p->msg);
237241

238242
pipeline_posn_offset_put(p->posn_offset);
239243

240244
/* now free the pipeline */
241-
rfree(p);
245+
sof_heap_free(p->heap, p);
242246

243247
/* show heap status */
244248
heap_trace_all(0);

src/audio/pipeline/pipeline-schedule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sof/audio/buffer.h>
99
#include <sof/audio/component_ext.h>
1010
#include <sof/audio/pipeline.h>
11+
#include <rtos/alloc.h>
1112
#include <rtos/interrupt.h>
1213
#include <sof/lib/agent.h>
1314
#include <sof/list.h>
@@ -241,15 +242,17 @@ static struct task *pipeline_task_init(struct pipeline *p, uint32_t type)
241242
{
242243
struct pipeline_task *task = NULL;
243244

244-
task = rzalloc(SOF_MEM_FLAG_USER,
245-
sizeof(*task));
245+
task = sof_heap_alloc(p->heap, SOF_MEM_FLAG_USER,
246+
sizeof(*task), 0);
246247
if (!task)
247248
return NULL;
248249

250+
memset(task, 0, sizeof(*task));
251+
249252
if (schedule_task_init_ll(&task->task, SOF_UUID(pipe_task_uuid), type,
250253
p->priority, pipeline_task,
251254
p, p->core, 0) < 0) {
252-
rfree(task);
255+
sof_heap_free(p->heap, task);
253256
return NULL;
254257
}
255258

src/include/sof/audio/pipeline.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct comp_buffer;
2525
struct comp_dev;
2626
struct ipc;
2727
struct ipc_msg;
28+
struct k_heap;
2829

2930
/*
3031
* Pipeline status to stop execution of current path, but to keep the
@@ -52,6 +53,7 @@ struct ipc_msg;
5253
* Audio pipeline.
5354
*/
5455
struct pipeline {
56+
struct k_heap *heap; /**< heap used for allocating this pipeline */
5557
uint32_t comp_id; /**< component id for pipeline */
5658
uint32_t pipeline_id; /**< pipeline id */
5759
uint32_t sched_id; /**< Scheduling component id */
@@ -152,14 +154,15 @@ struct create_pipeline_params {
152154

153155
/**
154156
* \brief Creates a new pipeline.
157+
* \param[in] heap Heap to allocate the pipeline on, or NULL for default.
155158
* \param[in] pipeline_id Pipeline ID number.
156159
* \param[in] priority Pipeline scheduling priority.
157160
* \param[in] comp_id Pipeline component ID number.
158161
* \param[in] pparams Pipeline parameters from IPC payload, maybe NULL.
159162
* \return New pipeline pointer or NULL.
160163
*/
161-
struct pipeline *pipeline_new(uint32_t pipeline_id, uint32_t priority, uint32_t comp_id,
162-
struct create_pipeline_params *pparams);
164+
struct pipeline *pipeline_new(struct k_heap *heap, uint32_t pipeline_id, uint32_t priority,
165+
uint32_t comp_id, struct create_pipeline_params *pparams);
163166

164167
/**
165168
* \brief Free's a pipeline.

src/ipc/ipc3/helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ int ipc_pipeline_new(struct ipc *ipc, ipc_pipe_new *_pipe_desc)
395395
}
396396

397397
/* create the pipeline */
398-
pipe = pipeline_new(pipe_desc->pipeline_id, pipe_desc->priority,
398+
pipe = pipeline_new(NULL, pipe_desc->pipeline_id, pipe_desc->priority,
399399
pipe_desc->comp_id, NULL);
400400
if (!pipe) {
401401
tr_err(&ipc_tr, "pipeline_new() failed");

src/ipc/ipc4/helper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ __cold static int ipc4_create_pipeline(struct ipc4_pipeline_create *pipe_desc,
352352
}
353353

354354
/* create the pipeline */
355-
pipe = pipeline_new(pipe_desc->primary.r.instance_id, pipe_desc->primary.r.ppl_priority, 0,
356-
pparams);
355+
pipe = pipeline_new(NULL, pipe_desc->primary.r.instance_id,
356+
pipe_desc->primary.r.ppl_priority, 0, pparams);
357357
if (!pipe) {
358358
tr_err(&ipc_tr, "ipc: pipeline_new() failed");
359359
return IPC4_OUT_OF_MEMORY;

test/cmocka/src/audio/pipeline/pipeline_free.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#endif
2424

2525
/* mock free() - dont free as we inspect contents */
26-
void rfree(void *ptr)
26+
void sof_heap_free(struct k_heap *heap, void *addr)
2727
{
2828
}
2929

test/cmocka/src/audio/pipeline/pipeline_new.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static void test_audio_pipeline_pipeline_new_creation(void **state)
4949
struct pipeline_new_setup_data *test_data = *state;
5050

5151
/*Testing component*/
52-
struct pipeline *result = pipeline_new(test_data->pipe_id,
52+
struct pipeline *result = pipeline_new(NULL,
53+
test_data->pipe_id,
5354
test_data->priority,
5455
test_data->comp_id,
5556
NULL);

0 commit comments

Comments
 (0)