This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ec18f42f3e97fe418ad7aafa1c7eec55624be148
Author: Bowen Wang <[email protected]>
AuthorDate: Fri May 29 19:45:49 2026 +0800

    ring: apply cache-line alignment at declaration sites
    
    The struct-level aligned_data(CACHELINE_SIZE) attribute on ring_s
    makes some compilers (e.g. TASKING) propagate the alignment to every
    member, inflating sizeof(struct ring_s) from 192 to 640 bytes and
    breaking the cross-core shared memory layout. Move the attribute from
    the type to each declaration/definition site (RING_DECLARE,
    RING_DEFINE_BMP) so it binds to the variable, and use lib_memalign in
    ring_alloc for the dynamic path. The cache-line isolation between
    regions is preserved by the explicit pad0/pad1/pad2 arrays.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 include/nuttx/ring.h | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/nuttx/ring.h b/include/nuttx/ring.h
index cd7cbc1867a..0023a17c6aa 100644
--- a/include/nuttx/ring.h
+++ b/include/nuttx/ring.h
@@ -214,7 +214,7 @@
   {                                                      \
     struct ring_s base;                                  \
     type          buf[cap];                              \
-  } name
+  } name aligned_data(CACHELINE_SIZE)
 
 /* RING_DEFINE - define and initialise a ring (no init call needed).
  *
@@ -435,7 +435,18 @@
  * Public Types
  ****************************************************************************/
 
-struct aligned_data(CACHELINE_SIZE) ring_s
+/* NOTE: The cache-line isolation between the metadata / producer /
+ * consumer regions is provided by the explicit pad0/pad1/pad2 arrays,
+ * not by a type-level aligned attribute.  The aligned_data(CACHELINE_SIZE)
+ * attribute is applied at each declaration/definition site instead (see
+ * RING_DECLARE and ring_alloc), so that it binds to the
+ * variable rather than the type.  Binding it to the type makes some
+ * compilers (e.g. TASKING) propagate the alignment to every member,
+ * inflating sizeof(struct ring_s) and breaking the cross-core shared
+ * memory layout.
+ */
+
+struct ring_s
 {
   /* Read-only metadata - cache-line aligned */
 
@@ -603,7 +614,7 @@ static inline_function FAR struct ring_s 
*ring_alloc(uint32_t cap,
       return NULL;
     }
 
-  r = lib_malloc(sizeof(*r) + cap * elem_size);
+  r = lib_memalign(CACHELINE_SIZE, sizeof(*r) + cap * elem_size);
   if (r == NULL)
     {
       return NULL;

Reply via email to