From 42ebb348e31fe02c5ed8f168b110504fe3c4da3d Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Thu, 8 Aug 2024 12:01:08 +0200 Subject: [PATCH 1/2] fix: remove cache ops for coherent architectures For cache alignment, PLATFORM_DCACHE_ALIGN is a better macro than DCACHE_LINE_SIZE (for some compilations not even defined) For CONFIG_INCOHERENT=0 compilation, it does not make any sense to call writeback/invalidate operations Signed-off-by: Marcin Szkudlinski --- src/include/sof/coherent.h | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/include/sof/coherent.h b/src/include/sof/coherent.h index 445e8eae9b1c..8e13b661440c 100644 --- a/src/include/sof/coherent.h +++ b/src/include/sof/coherent.h @@ -17,7 +17,7 @@ #include #include -#define __coherent __aligned(DCACHE_LINE_SIZE) +#define __coherent __aligned(PLATFORM_DCACHE_ALIGN) /* * The coherent API allows optimized access to memory by multiple cores, using @@ -332,29 +332,17 @@ static inline void __coherent_shared_thread(struct coherent *c, const size_t siz __must_check static inline struct coherent __sparse_cache *coherent_acquire(struct coherent *c, const size_t size) { - if (c->shared) { - struct coherent __sparse_cache *cc = uncache_to_cache(c); - + if (c->shared) c->key = k_spin_lock(&c->lock); - /* invalidate local copy */ - dcache_invalidate_region(cc, size); - } - return (__sparse_force struct coherent __sparse_cache *)c; } static inline void coherent_release(struct coherent __sparse_cache *c, const size_t size) { - if (c->shared) { - struct coherent *uc = cache_to_uncache(c); - - /* wtb and inv local data to coherent object */ - dcache_writeback_invalidate_region(c, size); - - k_spin_unlock(&uc->lock, uc->key); - } + if (c->shared) + k_spin_unlock(&c->lock, c->key); } static inline void *__coherent_init(size_t offset, const size_t size) From 10f8c6b88145ee0ed160f8cf632cf12f95e7e006 Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Thu, 8 Aug 2024 12:41:07 +0200 Subject: [PATCH 2/2] buf: fixes for CONFIG_INCOHERENT=0 builds there's no point with cache writeback/invalidate for coherent architectures. Also the buffer may be set as "shared" at any moment, not only at creation time Signed-off-by: Marcin Szkudlinski --- src/include/sof/audio/buffer.h | 4 ++++ src/ipc/ipc-helper.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/include/sof/audio/buffer.h b/src/include/sof/audio/buffer.h index db758f3a8ca3..c259b07d5fed 100644 --- a/src/include/sof/audio/buffer.h +++ b/src/include/sof/audio/buffer.h @@ -249,14 +249,18 @@ bool buffer_params_match(struct comp_buffer *buffer, static inline void buffer_stream_invalidate(struct comp_buffer *buffer, uint32_t bytes) { +#if CONFIG_INCOHERENT if (buffer->is_shared) audio_stream_invalidate(&buffer->stream, bytes); +#endif } static inline void buffer_stream_writeback(struct comp_buffer *buffer, uint32_t bytes) { +#if CONFIG_INCOHERENT if (buffer->is_shared) audio_stream_writeback(&buffer->stream, bytes); +#endif } diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index 207645f1dd5b..43926002abe3 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -184,9 +184,12 @@ int comp_buffer_connect(struct comp_dev *comp, uint32_t comp_core, { /* check if it's a connection between cores */ if (buffer->core != comp_core) { +#if CONFIG_INCOHERENT /* buffer must be shared */ assert(buffer->is_shared); - +#else + buffer->is_shared = true; +#endif if (!comp->is_shared) comp_make_shared(comp); }