Skip to content

feat(smp): add software and vip support for multiple non-coherent cores#277

Draft
ricted98 wants to merge 6 commits into
mainfrom
feat/smp
Draft

feat(smp): add software and vip support for multiple non-coherent cores#277
ricted98 wants to merge 6 commits into
mainfrom
feat/smp

Conversation

@ricted98

@ricted98 ricted98 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR aims at enabling support for baremetal multi-core execution. It rebases #169 on the latest changes.

ricted98 and others added 4 commits June 16, 2026 18:43
* Replace assembly macros in smp.h with C functions (smp_resume, barriers)
* Add explicit _wait_for_ipi in bootrom using call smp_resume
* Add per-hart stack sizing in crt0.S
* Guard ZSL single-hart work behind hart_id == 0, call smp_resume
* Add dual-core testbench config and PLIC target generation script
* Add smp_hello test

Co-authored-by: Enrico Zelioli <ezelioli@iis.ee.ethz.ch>
Co-authored-by: Emanuele Parisi <emanuele.parisi@protonmail.com>
@ricted98 ricted98 requested a review from ezelioli June 17, 2026 09:51
Comment thread sw/lib/smp.c

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.

This barrier implementation is unfortunately not correct. It was wrongly adapted (by me, sorry :')) from the CHERI Litmus tests simple barrier implementation (https://github.com/CTSRD-CHERI/CHERI-Litmus/blob/master/backend/riscv/arch.c). Simply adding a second barrier_target variable and repeating the count up/down + wait on it would suffice to avoid race conditions. This is not an efficient nor elegant implementation, but if intended for bare-metal simple tests it should be fine.

Another simple but slightly better implementation which removes the count up / down alternation requirement would be a sense-reversing centralized barrier (https://www.cs.rochester.edu/~scott/papers/1991_TOCS_synch.pdf). Again, I think that for the Cheshire use case of it would be fine to keep a fixed version of the current implementation.

Comment thread sw/lib/smp.c

static volatile uint64_t _barrier_target = 0;

static void barrier_wait(volatile uint64_t *barrier, uint64_t incr, uint64_t reach) {

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.

Another typo, the incr parameter should probably be int64_t

@ezelioli

Copy link
Copy Markdown
Contributor

One conceptual point which might be worth discussing is whether the current approach of the bootrom of having all cores jumping to the next boot stage is what we want. I think is fine and I personally prefer this over parking secondary harts and exposing an API to resume them, but this could be an option worth considering.
Also, in the current implementation there might be a risk for a race condition on the hart resuming mechanism based on CLINT IPIs. If core 0 is (very) fast and tries to wake up secondary harts (e.g. in a smp_hello test) before the other cores have exited the _wait_for_ipi loop in the bootrom, this could lead to secondary cores being stuck in the second _wait_for_ipi loop. This seems very unlikely in the current software stack but theoretically not impossible, so maybe it would also be worth considering a synchronization mechanism in the bootrom that guarantees all cores having resumed before jumping to the next boot stage.

Comment thread sw/lib/smp.c

#include "smp.h"

void smp_resume(void) {

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.

This implicitly assumes that NONSMP_HART is 0, which is fine as long as the macro in smp.h is not changed. Maybe a comment making this explicit would be helpful, or a modified version which counts from 0 to num_harts - 1 and skips an iteration when i == core_id.

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.

2 participants