Skip to content

CMSIS: share L1 cache maintenance support across A and R profiles - #319

Merged
JonatanAntoni merged 4 commits into
ARM-software:mainfrom
hamtinepeng:l1-cache
Oct 26, 2026
Merged

JonatanAntoni merged 4 commits into
ARM-software:mainfrom
hamtinepeng:l1-cache

Conversation

@hamtinepeng

Copy link
Copy Markdown
Contributor

Extract the common L1 cache maintenance implementation into l1_cache.h and reuse it for Armv7-A, Armv7-R and Armv8-R.

@JonatanAntoni
JonatanAntoni requested a lite review from Copilot September 3, 2026 13:50
@JonatanAntoni

Copy link
Copy Markdown
Member

@Masmiseim36

@JonatanAntoni

JonatanAntoni commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Shall we add some checks to Core tests for the new/changed features?
In fact, L1 cache functions for A-class are tested in CoreValidation https://github.com/ARM-software/CMSIS_6/blob/main/CMSIS/CoreValidation/Source/CV_CAL1Cache.c.
CoreValidation require a fast model for execution which we don't have available for R-class currently. We could invest in running tests using qemu instead of fast models to cover R-class (R5, R52) as well. But we may be able to check for correct compiler output in the static Core tests.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new shared cache helper header contains a functional bug in __log2_up(), and the R-profile CP15 headers include an AArch64-only header that is likely to break AArch32 builds.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors CMSIS Core cache-maintenance support by extracting the common L1 cache maintenance helpers into a shared header and reusing it across Armv7-A, Armv7-R, and Armv8-R profile headers.

Changes:

  • Added CMSIS/Core/Include/a-profile/l1_cache.h to host shared L1 cache enable/disable and cache maintenance helpers.
  • Updated a-profile/armv7a.h to include the shared l1_cache.h instead of defining the helpers inline.
  • Updated R-profile headers (armv7r.h, armv8r.h) and CP15 glue headers to pull in the shared cache-maintenance implementation and required CP15 interfaces.
File summaries
File Description
CMSIS/Core/Include/r-profile/armv8r.h Includes shared L1 cache maintenance header for Armv8-R profile.
CMSIS/Core/Include/r-profile/armv8r_cp15.h Adjusts CP15 include wiring for Armv8-R (but currently pulls in an AArch64-only header).
CMSIS/Core/Include/r-profile/armv7r.h Includes shared L1 cache maintenance header for Armv7-R profile.
CMSIS/Core/Include/r-profile/armv7r_cp15.h Adjusts CP15 include wiring for Armv7-R (but currently pulls in an AArch64-only header).
CMSIS/Core/Include/a-profile/l1_cache.h New shared header containing L1 cache maintenance helpers reused across profiles.
CMSIS/Core/Include/a-profile/armv7a.h Switches to including the new shared L1 cache maintenance header.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread CMSIS/Core/Include/a-profile/l1_cache.h
Comment thread CMSIS/Core/Include/r-profile/armv7r_cp15.h Outdated
Comment thread CMSIS/Core/Include/r-profile/armv8r_cp15.h Outdated
Comment thread CMSIS/Core/Include/a-profile/l1_cache.h Outdated
@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Test Results

   256 files   -    388     256 suites   - 388   0s ⏱️ - 14m 48s
    56 tests +     7      54 ✅ +   10      2 💤  -     3  0 ❌ ±0 
13 860 runs   - 17 696  11 476 ✅  - 8 680  2 384 💤  - 9 016  0 ❌ ±0 

Results for commit 1504a1b. ± Comparison against base commit 07d7306.

This pull request removes 49 and adds 56 tests. Note that renamed tests count towards both.
CMSIS-Core.src ‑ apsr.c
CMSIS-Core.src ‑ basepri.c
CMSIS-Core.src ‑ bkpt.c
CMSIS-Core.src ‑ clrex.c
CMSIS-Core.src ‑ clz.c
CMSIS-Core.src ‑ control.c
CMSIS-Core.src ‑ cp15.c
CMSIS-Core.src ‑ cpsr.c
CMSIS-Core.src ‑ dmb.c
CMSIS-Core.src ‑ dsb.c
…
TC_CML1Cache_CleanDCacheByAddrWhileDisabled
TC_CML1Cache_EnDisableDCache
TC_CML1Cache_EnDisableICache
TC_CoreFunc_APSR
TC_CoreFunc_BASEPRI
TC_CoreFunc_Control
TC_CoreFunc_EnDisIRQ
TC_CoreFunc_EncDecIRQPrio
TC_CoreFunc_FAULTMASK
TC_CoreFunc_FPSCR
…
This pull request removes 5 skipped tests and adds 2 skipped tests. Note that renamed tests count towards both.
CMSIS-Core.src ‑ lda.c
CMSIS-Core.src ‑ ldaex.c
CMSIS-Core.src ‑ stl.c
CMSIS-Core.src ‑ stlex.c
CMSIS-Core.src ‑ systick.c
TC_CoreInstr_WFE
TC_CoreInstr_WFI

♻️ This comment has been updated with latest results.

Comment thread CMSIS/Core/Include/r-profile/armv7r.h Outdated
JonatanAntoni
JonatanAntoni previously approved these changes Sep 3, 2026
Comment thread CMSIS/Core/Include/r-profile/armv8r.h Outdated
Comment thread CMSIS/Core/Include/r-profile/armv8r_cp15.h Outdated
Comment thread CMSIS/Core/Include/r-profile/armv8r_cp15.h
JonatanAntoni pushed a commit that referenced this pull request Oct 19, 2026
## Summary

- detect all non-power-of-two inputs when rounding `log2` upward
- extend the Cortex-A cache validation with even non-power-of-two cases

Fixes #320.

## Problem

The loop in `__log2_up()` computes `floor(log2(n))`, but the final
increment only checks whether `n` is odd. Even non-powers of two such as
6 and 10 therefore remain rounded down, which can produce an incorrect
cache-way shift.

The new condition increments for every value that is not a power of two
while preserving the existing behavior for 0, 1, exact powers of two,
and the upper `uint32_t` range.

## Validation

- reproduced the current failures for 6, 10, 12, and 14
- checked the updated function against an independent reference for
inputs 0 through 100000 and seven upper-range edge cases
- compiled the updated header as a freestanding Cortex-A9 object with
Clang targeting `armv7-none-eabi`
- ran `git diff --check`

The CoreValidation FVP suite and physical hardware were not run because
the required `cbuild` and FVP tools are not available locally.

PR #319 moves this helper into a shared header but retains the same
parity check, so this logic fix remains necessary; it may need a
straightforward conflict resolution if that refactor lands first.

LLMs were used for review and code generation in some parts of this pull
request.
@JonatanAntoni

Copy link
Copy Markdown
Member

@hamtinepeng this PR needs attention

@hamtinepeng

hamtinepeng commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@hamtinepeng this PR needs attention

@JonatanAntoni I’m fine rebasing the current branch, but I’d like to wait for a response to this comment first.
Alternatively, I could close this PR, open a dedicated issue instead, and reopen once that’s resolved.
What would you suggest?

@JonatanAntoni

Copy link
Copy Markdown
Member

@Masmiseim36, we are waiting for your feedback.

@Masmiseim36

Copy link
Copy Markdown
Contributor

@Masmiseim36, we are waiting for your feedback.

I honestly lost track of this topic. Thank you for bringing it up again.

Comment thread CMSIS/Core/Include/a-profile/l1_cache.h
Comment thread CMSIS/Core/Include/a-profile/l1_cache.h Outdated
Comment thread CMSIS/Core/Include/a-profile/l1_cache.h Outdated
hamtinepeng and others added 3 commits October 22, 2026 11:23
Extract the common L1 cache maintenance implementation into l1_cache.h
and reuse it for Armv7-A, Armv7-R and Armv8-R.
__L1C_MaintainDCacheSetWay() selects a cache by writing CSSELR and then
reads CCSIDR to get the number of sets, the number of ways and the line
size. An ISB is required between the two so that the new selection is
used by the CCSIDR read (see ARM DDI 0406C.d, section B2.2).
__set_CSSELR() is a bare CP15 MCR and does not imply an ISB.

Co-authored-by: Jonatan Antoni <jonatan.antoni@arm.com>
@JonatanAntoni

Copy link
Copy Markdown
Member

@Masmiseim36, may I ask you to check the latest review comments and resolve the conversations if the responses are sufficient? Having all sorted is our qa gate for getting this merged.

@JonatanAntoni
JonatanAntoni merged commit 65db2ba into ARM-software:main Oct 26, 2026
9 checks passed
@hamtinepeng
hamtinepeng deleted the l1-cache branch October 27, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants