Skip to content

Commit 12d7962

Browse files
committed
pipeline: protect component connections with a mutex
In userspace LL builds, use a mutex to protect component connections. This code should work in kernel builds as well, but start with an incremental change that only affects LL builds, in which mutex use is mandatory. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 3db6d48 commit 12d7962

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/audio/pipeline/pipeline-graph.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,45 +178,55 @@ static void buffer_set_comp(struct comp_buffer *buffer, struct comp_dev *comp,
178178
comp_buffer_set_sink_component(buffer, comp);
179179
}
180180

181+
#ifdef CONFIG_SOF_USERSPACE_LL
182+
#define PPL_LOCK_DECLARE
183+
#define PPL_LOCK() sys_mutex_lock(&comp->list_mutex, K_FOREVER)
184+
#define PPL_UNLOCK() sys_mutex_unlock(&comp->list_mutex)
185+
#else
186+
#define PPL_LOCK_DECLARE uint32_t flags
187+
#define PPL_LOCK() irq_local_disable(flags)
188+
#define PPL_UNLOCK() irq_local_enable(flags)
189+
#endif
190+
181191
int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,
182192
int dir)
183193
{
184194
struct list_item *comp_list;
185-
uint32_t flags;
195+
PPL_LOCK_DECLARE;
186196

187197
if (dir == PPL_CONN_DIR_COMP_TO_BUFFER)
188198
comp_info(comp, "connect buffer %d as sink", buf_get_id(buffer));
189199
else
190200
comp_info(comp, "connect buffer %d as source", buf_get_id(buffer));
191201

192-
irq_local_disable(flags);
202+
PPL_LOCK();
193203

194204
comp_list = comp_buffer_list(comp, dir);
195205
buffer_attach(buffer, comp_list, dir);
196206
buffer_set_comp(buffer, comp, dir);
197207

198-
irq_local_enable(flags);
208+
PPL_UNLOCK();
199209

200210
return 0;
201211
}
202212

203213
void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer, int dir)
204214
{
205215
struct list_item *comp_list;
206-
uint32_t flags;
216+
PPL_LOCK_DECLARE;
207217

208218
if (dir == PPL_CONN_DIR_COMP_TO_BUFFER)
209219
comp_dbg(comp, "disconnect buffer %d as sink", buf_get_id(buffer));
210220
else
211221
comp_dbg(comp, "disconnect buffer %d as source", buf_get_id(buffer));
212222

213-
irq_local_disable(flags);
223+
PPL_LOCK();
214224

215225
comp_list = comp_buffer_list(comp, dir);
216226
buffer_detach(buffer, comp_list, dir);
217227
buffer_set_comp(buffer, NULL, dir);
218228

219-
irq_local_enable(flags);
229+
PPL_UNLOCK();
220230
}
221231

222232
/* pipelines must be inactive */

src/include/sof/audio/component.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sof/audio/pipeline.h>
2222
#include <sof/debug/telemetry/telemetry.h>
2323
#include <rtos/idc.h>
24+
#include <rtos/mutex.h>
2425
#include <rtos/userspace_helper.h>
2526
#include <sof/lib/dai.h>
2627
#include <sof/schedule/schedule.h>
@@ -679,6 +680,10 @@ struct comp_dev {
679680
struct list_item bsource_list; /**< list of source buffers */
680681
struct list_item bsink_list; /**< list of sink buffers */
681682

683+
#ifdef CONFIG_SOF_USERSPACE_LL
684+
struct sys_mutex list_mutex; /**< protect lists of source/sinks */
685+
#endif
686+
682687
/* performance data*/
683688
struct comp_perf_data perf_data;
684689
/* Input Buffer Size for pin 0, add array for other pins if needed */
@@ -863,6 +868,9 @@ static inline void comp_init(const struct comp_driver *drv,
863868
dev->state = COMP_STATE_INIT;
864869
list_init(&dev->bsink_list);
865870
list_init(&dev->bsource_list);
871+
#ifdef CONFIG_SOF_USERSPACE_LL
872+
sys_mutex_init(&dev->list_mutex);
873+
#endif
866874
memcpy_s(&dev->tctx, sizeof(dev->tctx),
867875
trace_comp_drv_get_tr_ctx(dev->drv), sizeof(struct tr_ctx));
868876
}

0 commit comments

Comments
 (0)