arch/risc-v: assign per-cpu data by logical cpu - #20012
Conversation
acassis
left a comment
There was a problem hiding this comment.
@imeghar2408-max please fix the CI issue: "Blank line precedes right brace at line"
|
Hi @imeghar2408-max please rebase |
393d724 to
5191fb5
Compare
|
@simbit18 Rebased the branch onto the latest upstream/master and pushed the updated history. |
|
@imeghar2408-max please fix |
5191fb5 to
d61aebb
Compare
|
@imeghar2408-max if you used some AI LLM to help you to fix this issue, please add to your commit message: I asked Claude Code to analyze these changes and it reported: |
|
@acassis Regarding point #4, I understand the concern about riscv_hartid_to_cpuid() being used as an array index. Since the in-tree callers currently provide valid CPU mappings, would you recommend keeping the DEBUGASSERT as an invariant check, or is there a preferred way in NuttX to handle an invalid mapping here? |
d61aebb to
f3607ee
Compare
I think it is better to prevent it in the release version too, not only on development/testing build |
Assign the per-CPU area using the HART to CPU mapping instead of the order in which HARTs register. This keeps interrupt stack assignment consistent with the logical CPU and avoids incorrect per-CPU IRQ stack selection when HART boot order differs. Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
f3607ee to
0ac9024
Compare
|
@acassis Addressed point 4 by adding a release-safe bounds check before indexing g_percpu. |
Summary
Fix the assignment of RISC-V per-CPU data so that each HART is assigned
the
g_percpuentry corresponding to its logical CPU ID.Previously,
riscv_percpu_init()initialized interrupt stacks accordingto the
g_percpu[]array index and placed the entries in a FIFO freelist.riscv_percpu_add_hart()then assigned entries according to the order inwhich HARTs registered. When HART boot order differs from logical CPU
order, a HART can therefore be associated with the wrong per-CPU
interrupt stack.
This change uses
riscv_hartid_to_cpuid()to select the correspondingg_percpu[]entry directly and removes the now-unused freelist.Impact
scratch-based per-CPU storage by making per-CPU interrupt-stack
assignment deterministic with respect to logical CPU ID.
Testing
Built and boot-tested with
rv-virt:ksmp64usingriscv-none-elf-gcc 13.2.0on Linux with QEMU 10.2.1.Build Log
Runtime Log:
All four CPUs booted successfully, and the interrupt-stack bases were
spaced by 2048 bytes in the expected CPU-index order.
The rv-virt:ksmp64 SMP exception entry does not read
RISCV_PERCPU_IRQSTACK, so this runtime test verifies normal SMP boot
and the expected per-CPU stack layout but does not exercise the specific
interrupt-stack path affected by this change.
MPFS uses the RISCV_PERCPU_IRQSTACK path, but no in-tree MPFS SMP
configuration is available for runtime validation in this environment.
Fixes: #19875