Skip to content

DCache: Add __dcacheline_aligned & __dcacheline_exclusive attributes - #98578

Draft
JarmouniA wants to merge 9 commits into
zephyrproject-rtos:mainfrom
JarmouniA:dev_dcache_aligned_unique
Draft

DCache: Add __dcacheline_aligned & __dcacheline_exclusive attributes#98578
JarmouniA wants to merge 9 commits into
zephyrproject-rtos:mainfrom
JarmouniA:dev_dcache_aligned_unique

Conversation

@JarmouniA

@JarmouniA JarmouniA commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

New version of #95888

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

Add __dcacheline_exclusive_noinit & __dcacheline_exclusive_data attributes which make variables aligned to data cache line size and having exclusive data cache line(s).

Usage:
static uint8_t var1 __dcacheline_aligned;
static uint8_t var2 __dcacheline_exclusive_noinit;
__dcacheline_exclusive_data static uint8_t var3 = 5;

@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from 8fc403a to 209a631 Compare October 30, 2025 14:21
Comment thread include/zephyr/linker/common-ram.ld Outdated
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from be55f5d to f42111b Compare October 31, 2025 17:04
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2025

Copy link
Copy Markdown

@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch 4 times, most recently from 532ad3b to d90353e Compare February 3, 2026 23:06
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from d90353e to 3287e93 Compare February 10, 2026 20:34
@JarmouniA JarmouniA changed the title DCache: Add __dcacheline_aligned & __dcacheline_unique tokens DCache: Add __dcacheline_aligned & __dcacheline_exclusive attributes Feb 10, 2026
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch 4 times, most recently from ca0c193 to 21b9e3d Compare February 16, 2026 22:39
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label Mar 29, 2026
@JarmouniA JarmouniA removed the Stale label Mar 29, 2026
@JarmouniA JarmouniA closed this Apr 5, 2026
@JarmouniA JarmouniA reopened this Apr 5, 2026
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch 2 times, most recently from 63530c9 to 4c36d24 Compare April 24, 2026 22:32
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label May 25, 2026
@JarmouniA JarmouniA removed the Stale label May 25, 2026
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from 4c36d24 to 5f919b9 Compare June 17, 2026 18:44
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from 5f919b9 to cb0f6a6 Compare July 1, 2026 13:09
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from cb0f6a6 to ce2a6a3 Compare July 27, 2026 19:20
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from ce2a6a3 to 9a0d80f Compare August 15, 2026 11:37
@sonarqubecloud

Copy link
Copy Markdown

@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from 9a0d80f to bf70584 Compare August 21, 2026 08:14
Setting symbol default value without 'configdefault', or without
explicit 'if' checks of dependencies, results in dependency weakening.
In this case, CACHE_MANAGEMENT is redefined and set to the given
default value even if dependencies D/ICACHE are not enabled.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
(cherry picked from commit f259c8e)
A component should not rely on the API it is implementing.
In this case, the arch layer is implementing the arch cache API
(include/zephyr/arch/cache.h), that is used by the public sys cache
API (include/zephyr/cache.h), so it can't call the latter.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
(cherry picked from commit daacc41)
Across the tree, I/DCACHE_LINE_SIZE is required at compile-time for
macros, compiler attributes, & linker scripts to function correctly
even if run-time cache line detection is available.
So remove the dependency of ICACHE_LINE_SIZE on
ICACHE_LINE_SIZE_DETECT=n, and of DCACHE_LINE_SIZE on
DCACHE_LINE_SIZE_DETECT=n.

DCACHE_LINE_SIZE_DETECT & ICACHE_LINE_SIZE_DETECT Kconfig options
enable querying some SoC register for finding the i/d-cache line size
at the expense of taking more memory and code and a slightly
increased boot time.

Add new hidden options D/ICACHE_LINE_SIZE_DETECT_SUPPORT only selected
by the software component (arch/SoC layer, driver) implementing the system
cache API.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
(cherry picked from commit 7e7c083)
Limit I/DCache line size options' value to
[2, UINT32_MAX] at Kconfig level instead of having
to check the value in code needlessly.
Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
(cherry picked from commit 89aa692)
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch 2 times, most recently from e2d0a75 to 8e47ea1 Compare August 25, 2026 15:04
When cache is enabled, cache line size should not be zero under any
circumstances. The returned value is often used to check address
alignment with 'addr & (size -1)', which obviously cannot work if
size value is 0.
Add asserts to catch invalid values.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
(cherry picked from commit 48f48a6)
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from 8e47ea1 to cac7848 Compare August 25, 2026 16:35
Add __dcacheline_aligned which ensures data cache line alignment.

Add __dcacheline_exclusive_... attributes which puts a static variable
in a section that contains only data cache line aligned variables. This
results in variables being aligned and having exclusive data cache
line(s).

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>
Add tests which checks that variable tagged with __dcacheline_aligned is
correctly aligned,
and that the variables tagged with __dcacheline_exclusive are in the
proper section that gives exclusive data cache line(s) 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>
@JarmouniA
JarmouniA force-pushed the dev_dcache_aligned_unique branch from cac7848 to d028275 Compare August 25, 2026 16:48
Add test scenario to run cache testcases with linker generator
to cover __dcacheline_exclusive_noinit/data attributes CMake code.
Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants