Skip to content

Conversation

@JarmouniA
Copy link
Contributor

New version of #95888

Add __dcacheline_aligned macro which ensures data cache line alignment for variables.

Add __dcacheline_unique macro which puts a static variable in a linker section that contains only data cache line aligned variables. This results in those variables being aligned and in a unique data cache line each.

Usage:
static uint8_t var1 __dcacheline_aligned;
static uint8_t var2 __dcacheline_unique;

@JarmouniA JarmouniA force-pushed the dev_dcache_aligned_unique branch from 8fc403a to 209a631 Compare October 30, 2025 14:21
Comment on lines +155 to +163
#if defined(CONFIG_DCACHE_LINE_SIZE)
SECTION_DATA_PROLOGUE(data_cache,,SUBALIGN(CONFIG_DCACHE_LINE_SIZE))
{
PLACE_SYMBOL_HERE(__data_cache_start);
KEEP(*(SORT_BY_NAME(".data_cache*")))
. = ALIGN(CONFIG_DCACHE_LINE_SIZE);
PLACE_SYMBOL_HERE(__data_cache_end);
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
#endif /* CONFIG_DCACHE_LINE_SIZE */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this automatically means, that all variables with this attribute land in the data section. That means that variables, are initialized with zero, will no longer land in the bss section. That leads to increase in size in flash, as they now can't be optimized out.

Add __dcacheline_aligned which ensures data cache line alignment. Add __dcacheline_unique which puts a static variable in a section that contains only data cache line aligned variables. This results in variables being aligned and in a unique data cache line each. Co-authored-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no> Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no> Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Add test which checks that variable tagged with __dcacheline_aligned is correctly aligned, and that the variables tagged with __dcacheline_unique are in the proper section that gives a unique data cache line for each. Co-authored-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no> Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no> Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Replace __aligned(CONFIG_DCACHE_LINE_SIZE) with __dcacheline_aligned across Zephyr Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
@JarmouniA JarmouniA force-pushed the dev_dcache_aligned_unique branch from be55f5d to f42111b Compare October 31, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants