all: add support for multicore scheduler

This commit adds support for a scheduler that runs a scheduler on all
available cores. It is meant to be used on baremetal systems with a
fixed number of cores, such as the RP2040.

The initial implementation adds support for multicore scheduling to the
riscv-qemu target as a convenient testing target. This means that this
new multicore scheduler is tested in CI, including a bunch of standard
library tests (`make tinygo-test-baremetal`). This should ensure the new
scheduler is reasonably well tested before trying to use it on
harder-to-debug targets like the RP2040.
This commit is contained in:
Ayke van Laethem
2025-04-03 13:29:55 +02:00
committed by Ron Evans
parent 0c7c2926f9
commit 60f8a62978
35 changed files with 1237 additions and 160 deletions
+31 -1
View File
@@ -2,7 +2,10 @@
package runtime
import "internal/task"
import (
"internal/task"
"runtime/interrupt"
)
const hasScheduler = false // not using the cooperative scheduler
@@ -127,3 +130,30 @@ func runqueueForGC() *task.Queue {
// There is only a runqueue when using the cooperative scheduler.
return nil
}
// Lock to make sure print calls do not interleave.
var printLock task.Mutex
func printlock() {
printLock.Lock()
}
func printunlock() {
printLock.Unlock()
}
// The atomics lock isn't used as a lock for actual atomics. It is used inside
// internal/task.Stack and internal/task.Queue to make sure their operations are
// actually atomic. (This might not actually be needed, since the use in
// sync.Cond doesn't need atomicity).
var atomicsLock task.Mutex
func lockAtomics() interrupt.State {
atomicsLock.Lock()
return 0
}
func unlockAtomics(mask interrupt.State) {
atomicsLock.Unlock()
}