Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add smp dual-core support #1135

Merged
merged 31 commits into from
Jan 2, 2025
Merged

✨ add smp dual-core support #1135

merged 31 commits into from
Jan 2, 2025

Conversation

stnolting
Copy link
Owner

@stnolting stnolting commented Dec 30, 2024

Add SMP dual-core option.

  • add rtl infrastructure (two CPU instances + caches + bus arbiter)
  • adjust crt0 boot code
  • add HAL boot functions for secondary core
  • add dual-core example program
  • add dual-core test to CI
  • add dual-core openOCD configuration
  • test dual-core debugging
  • update documentation
  • update bootloader (image)

🧪 Note that the dual-core configuration is still experimental.

⚠️ work in progress!
@stnolting stnolting linked an issue Dec 30, 2024 that may be closed by this pull request
@stnolting stnolting self-assigned this Dec 30, 2024
@stnolting stnolting added enhancement New feature or request HW Hardware-related SW Software-related experimental Experimental feature labels Dec 30, 2024
@stnolting stnolting changed the title ✨ add dual-core support ✨ add smp dual-core support Jan 1, 2025
Copy link
Collaborator

@NikLeberg NikLeberg left a comment

Choose a reason for hiding this comment

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

I left some small remarks. The biggest issue I see is with the L1 data caches. I think we should disable them automatically (and emit a warning) even if the user enabled them.

rtl/core/neorv32_top.vhd Show resolved Hide resolved
rtl/core/neorv32_top.vhd Show resolved Hide resolved
sw/common/crt0.S Show resolved Hide resolved
sw/example/demo_dual_core/main.c Show resolved Hide resolved
Comment on lines +8 to +9
* Private spinlock locked variable. We can only use a single spinlock
* as the processor only features a single reservation set.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If my understanding of this is correct, then we aren't really limited by having only a single reservation set. The hardware doesn't care. We just have to write correct software for it. The only thing that I think might happen is, if both cores try to atomically change anything via lr/sc, they may end up in livelock as they reset the reservation for each other.
But if we design the spinlock with exponential (or random) backoff (on lock failure) then I think we can have more than one spinlock, can't we?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I also racked my brains about that... 😅
I've tried to use two individual spinlock variables based on the same LR/SC primitives and ended up in a livelock.

But if we design the spinlock with exponential (or random) backoff (on lock failure)

How would you do that? 🤔

@stnolting
Copy link
Owner Author

stnolting commented Jan 2, 2025

@NikLeberg Thank you so much for your feedback!

The current design works - at least for a simple dual-core demo program. However, some things are not really efficient and quite hard to handle for a user. But I think this is fine for a first version.

Later, we should perhaps add a special module to avoid the problems (mentioned above). The RP2040 provides a cool block that is used for inter-cpu communication. It provides some nice features:

  • hardware spinlocks
  • FIFOs for passing messages from one CPU to another

grafik

Source: RP2040 data sheet

The rp2040 provides interrupts for the communication FIFOs. I think that is not necessary as we have the software interrupts (and we are running out of interrupt channels anyway).

@stnolting stnolting marked this pull request as ready for review January 2, 2025 13:46
@stnolting stnolting merged commit 2cfd534 into main Jan 2, 2025
10 checks passed
@stnolting stnolting deleted the dual_core branch January 2, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request experimental Experimental feature HW Hardware-related SW Software-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dual-core option? 🤔
2 participants