Skip to content

Commit 4a03699

Browse files
marcinszkudlinskikv2019i
authored andcommitted
buf: remove coherent.h from struct comp_buffer
This commit removes coherent.h from struct comp_buffer As sharing status of a buffer is known at creation time, it is enough to create a buffer in shared (not cached mem alias) when it will be used by several cores Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
1 parent 9ccfbc4 commit 4a03699

19 files changed

Lines changed: 92 additions & 142 deletions

File tree

src/audio/buffer.c

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ DECLARE_SOF_RT_UUID("buffer", buffer_uuid, 0x42544c92, 0x8e92, 0x4e41,
2727
0xb6, 0x79, 0x34, 0x51, 0x9f, 0x1c, 0x1d, 0x28);
2828
DECLARE_TR_CTX(buffer_tr, SOF_UUID(buffer_uuid), LOG_LEVEL_INFO);
2929

30-
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, uint32_t align)
30+
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, uint32_t align,
31+
bool is_shared)
3132
{
3233
struct comp_buffer *buffer;
3334
struct comp_buffer __sparse_cache *buffer_c;
@@ -42,16 +43,17 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u
4243
return NULL;
4344
}
4445

45-
/*
46-
* allocate new buffer, align the allocation size to a cache line for
47-
* the coherent API
48-
*/
49-
buffer = coherent_init_thread(struct comp_buffer, c);
46+
/* allocate new buffer */
47+
enum mem_zone zone = is_shared ? SOF_MEM_ZONE_RUNTIME_SHARED : SOF_MEM_ZONE_RUNTIME;
48+
49+
buffer = rzalloc(zone, 0, SOF_MEM_CAPS_RAM, sizeof(*buffer));
50+
5051
if (!buffer) {
5152
tr_err(&buffer_tr, "buffer_alloc(): could not alloc structure");
5253
return NULL;
5354
}
5455

56+
buffer->is_shared = is_shared;
5557
stream_addr = rballoc_align(0, caps, size, align);
5658
if (!stream_addr) {
5759
rfree(buffer);
@@ -70,18 +72,6 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u
7072

7173
buffer_release(buffer_c);
7274

73-
/*
74-
* The buffer hasn't yet been marked as shared, hence buffer_release()
75-
* hasn't written back and invalidated the cache. Therefore we have to
76-
* do this manually now before adding to the lists. Buffer list
77-
* structures are always accessed uncached and they're never modified at
78-
* run-time, i.e. buffers are never relinked. So we have to make sure,
79-
* that what we have written into buffer's cache is in RAM before
80-
* modifying that RAM bypassing cache, and that after this cache is
81-
* re-loaded again.
82-
*/
83-
dcache_writeback_invalidate_region(uncache_to_cache(buffer), sizeof(*buffer));
84-
8575
list_init(&buffer->source_list);
8676
list_init(&buffer->sink_list);
8777

@@ -303,30 +293,7 @@ void comp_update_buffer_consume(struct comp_buffer __sparse_cache *buffer, uint3
303293
void buffer_attach(struct comp_buffer *buffer, struct list_item *head, int dir)
304294
{
305295
struct list_item *list = buffer_comp_list(buffer, dir);
306-
struct list_item __sparse_cache *needs_sync;
307-
bool further_buffers_exist;
308-
309-
/*
310-
* There can already be buffers on the target list. If we just link this
311-
* buffer, we modify the first buffer's list header via uncached alias,
312-
* so its cached copy can later be written back, overwriting the
313-
* modified header. FIXME: this is still a problem with different cores.
314-
*/
315-
further_buffers_exist = !list_is_empty(head);
316-
needs_sync = uncache_to_cache(head->next);
317-
if (further_buffers_exist)
318-
dcache_writeback_region(needs_sync, sizeof(struct list_item));
319-
/* The cache line can be prefetched here, invalidate it after prepending */
320296
list_item_prepend(list, head);
321-
if (further_buffers_exist)
322-
dcache_invalidate_region(needs_sync, sizeof(struct list_item));
323-
#if CONFIG_INTEL
324-
/*
325-
* Until now the buffer object wasn't in cache, but uncached access to it could have
326-
* triggered a cache prefetch. Drop that cache line to avoid using stale data in it.
327-
*/
328-
dcache_invalidate_region(uncache_to_cache(list), sizeof(*list));
329-
#endif
330297
}
331298

332299
/*
@@ -335,32 +302,6 @@ void buffer_attach(struct comp_buffer *buffer, struct list_item *head, int dir)
335302
*/
336303
void buffer_detach(struct comp_buffer *buffer, struct list_item *head, int dir)
337304
{
338-
struct list_item __sparse_cache *needs_sync_prev, *needs_sync_next;
339-
bool buffers_after_exist, buffers_before_exist;
340305
struct list_item *buf_list = buffer_comp_list(buffer, dir);
341-
342-
/*
343-
* There can be more buffers linked together with this one, that will
344-
* still be staying on their respective pipelines and might get used via
345-
* their cached aliases. If we just unlink this buffer, we modify their
346-
* list header via uncached alias, so their cached copy can later be
347-
* written back, overwriting the modified header. FIXME: this is still a
348-
* problem with different cores.
349-
*/
350-
buffers_after_exist = head != buf_list->next;
351-
buffers_before_exist = head != buf_list->prev;
352-
needs_sync_prev = uncache_to_cache(buf_list->prev);
353-
needs_sync_next = uncache_to_cache(buf_list->next);
354-
if (buffers_after_exist)
355-
dcache_writeback_region(needs_sync_next, sizeof(struct list_item));
356-
if (buffers_before_exist)
357-
dcache_writeback_region(needs_sync_prev, sizeof(struct list_item));
358-
dcache_writeback_region(uncache_to_cache(buf_list), sizeof(*buf_list));
359-
/* buffers before or after can be prefetched here */
360306
list_item_del(buf_list);
361-
dcache_invalidate_region(uncache_to_cache(buf_list), sizeof(*buf_list));
362-
if (buffers_after_exist)
363-
dcache_invalidate_region(needs_sync_next, sizeof(struct list_item));
364-
if (buffers_before_exist)
365-
dcache_invalidate_region(needs_sync_prev, sizeof(struct list_item));
366307
}

src/audio/chain_dma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uint8_t li
588588
}
589589

590590
fifo_size = ALIGN_UP_INTERNAL(fifo_size, addr_align);
591-
592-
cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_CAPS_DMA, 0, addr_align);
591+
/* allocate not shared buffer */
592+
cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_CAPS_DMA, 0, addr_align, false);
593593

594594
if (!cd->dma_buffer) {
595595
comp_err(dev, "chain_task_init(): failed to alloc dma buffer");

src/audio/copier/copier_generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ int create_endpoint_buffer(struct comp_dev *dev,
204204
ipc_buf.size = buf_size;
205205
ipc_buf.comp.pipeline_id = config->pipeline_id;
206206
ipc_buf.comp.core = config->core;
207-
208-
buffer = buffer_new(&ipc_buf);
207+
/* allocate not shared buffer */
208+
buffer = buffer_new(&ipc_buf, false);
209209
if (!buffer)
210210
return -ENOMEM;
211211

src/audio/dai-legacy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ int dai_common_params(struct dai_data *dd, struct comp_dev *dev,
600600
}
601601
} else {
602602
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
603-
addr_align);
603+
addr_align, false);
604604
if (!dd->dma_buffer) {
605605
comp_err(dev, "dai_params(): failed to alloc dma buffer");
606606
return -ENOMEM;

src/audio/dai-zephyr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,9 @@ int dai_common_params(struct dai_data *dd, struct comp_dev *dev,
977977
return err;
978978
}
979979
} else {
980+
/* allocate not shared buffer */
980981
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
981-
addr_align);
982+
addr_align, false);
982983
if (!dd->dma_buffer) {
983984
comp_err(dev, "dai_common_params(): failed to alloc dma buffer");
984985
return -ENOMEM;

src/audio/host-legacy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
788788
}
789789
} else {
790790
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
791-
addr_align);
791+
addr_align, false);
792792
if (!hd->dma_buffer) {
793793
comp_err(dev, "host_params(): failed to alloc dma buffer");
794794
err = -ENOMEM;

src/audio/host-zephyr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,9 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
857857
goto out;
858858
}
859859
} else {
860+
/* allocate not shared buffer */
860861
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
861-
addr_align);
862+
addr_align, false);
862863
if (!hd->dma_buffer) {
863864
comp_err(dev, "host_params(): failed to alloc dma buffer");
864865
err = -ENOMEM;

src/audio/module_adapter/module_adapter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ int module_adapter_prepare(struct comp_dev *dev)
448448
/* allocate buffer for all sinks */
449449
if (list_is_empty(&mod->sink_buffer_list)) {
450450
for (i = 0; i < mod->num_output_buffers; i++) {
451+
/* allocate not shared buffer */
451452
struct comp_buffer *buffer = buffer_alloc(buff_size, SOF_MEM_CAPS_RAM,
452-
0, PLATFORM_DCACHE_ALIGN);
453+
0, PLATFORM_DCACHE_ALIGN, false);
453454
uint32_t flags;
454455

455456
if (!buffer) {

src/audio/pipeline/pipeline-graph.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ static void buffer_set_comp(struct comp_buffer *buffer, struct comp_dev *comp,
176176
buffer_c->sink = comp;
177177

178178
buffer_release(buffer_c);
179-
180-
/* The buffer might be marked as shared later, write back the cache */
181-
if (!buffer->c.shared)
182-
dcache_writeback_invalidate_region(uncache_to_cache(buffer), sizeof(*buffer));
183179
}
184180

185181
int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,

src/include/sof/audio/buffer.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ extern struct tr_ctx buffer_tr;
133133
* 5) write back cached data and release lock using uncache pointer.
134134
*/
135135
struct comp_buffer {
136-
struct coherent c;
137-
138136
/* data buffer */
139137
struct audio_stream stream;
140138

@@ -144,6 +142,7 @@ struct comp_buffer {
144142
uint32_t caps;
145143
uint32_t core;
146144
struct tr_ctx tctx; /* trace settings */
145+
bool is_shared; /* buffer structure is shared between 2 cores */
147146

148147
/* connected components */
149148
struct comp_dev *source; /* source component */
@@ -188,8 +187,9 @@ struct buffer_cb_free {
188187
} while (0)
189188

190189
/* pipeline buffer creation and destruction */
191-
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, uint32_t align);
192-
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc);
190+
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, uint32_t align,
191+
bool is_shared);
192+
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared);
193193
int buffer_set_size(struct comp_buffer __sparse_cache *buffer, uint32_t size, uint32_t alignment);
194194
void buffer_free(struct comp_buffer *buffer);
195195
void buffer_zero(struct comp_buffer __sparse_cache *buffer);
@@ -209,32 +209,27 @@ bool buffer_params_match(struct comp_buffer __sparse_cache *buffer,
209209
static inline void buffer_stream_invalidate(struct comp_buffer __sparse_cache *buffer,
210210
uint32_t bytes)
211211
{
212-
if (!is_coherent_shared(buffer, c))
213-
return;
214-
215-
audio_stream_invalidate(&buffer->stream, bytes);
212+
if (buffer->is_shared)
213+
audio_stream_invalidate(&buffer->stream, bytes);
216214
}
217215

218216
static inline void buffer_stream_writeback(struct comp_buffer __sparse_cache *buffer,
219217
uint32_t bytes)
220218
{
221-
if (!is_coherent_shared(buffer, c))
222-
return;
223-
224-
audio_stream_writeback(&buffer->stream, bytes);
219+
if (buffer->is_shared)
220+
audio_stream_writeback(&buffer->stream, bytes);
225221
}
226222

223+
/* stubs for acquire/release for compilation, to be removed at last step */
227224
__must_check static inline struct comp_buffer __sparse_cache *buffer_acquire(
228225
struct comp_buffer *buffer)
229226
{
230-
struct coherent __sparse_cache *c = coherent_acquire_thread(&buffer->c, sizeof(*buffer));
231-
232-
return attr_container_of(c, struct comp_buffer __sparse_cache, c, __sparse_cache);
227+
return (struct comp_buffer __sparse_cache *)buffer;
233228
}
234229

235230
static inline void buffer_release(struct comp_buffer __sparse_cache *buffer)
236231
{
237-
coherent_release_thread(&buffer->c, sizeof(*buffer));
232+
(void)buffer;
238233
}
239234

240235
/*

0 commit comments

Comments
 (0)