Description
We need to support multi core systems some day:
- Some microcontrollers have more than one core that we'd like to use (RP2040, ESP32)
- Most operating systems have multiple cores.
At the same time, support for multi core shouldn't (significantly) regress single-core performance on microcontrollers, because almost all microcontrollers are single core.
To support multi core, there need to be changes to:
- the scheduler, to schedule over more than one core
- channels (implemented in the runtime)
- the garbage collector (it needs to stop all goroutines to scan their stacks)
- wrappers for atomic instructions (see runtime: implement __sync libcalls as critical sections #2307)
- packages like sync
- ... probably more
I propose we add a new unicore
(or singlecore
, singlethread
, ...) build tag for single core chips and schedulers, so that we can know at build time whether a configuration can assume it's only running in a single (hardware) thread and optimize accordingly.
I suspect it's easiest to not add multi core support first to a chip (RP2040, ESP32) but to an operating system. Operating system threads are already well defined and require the vast majority of changes that are also required for multi core support on a chip (see the list above). I propose we add a -scheduler=threads
for that, where each goroutine is running in a separate OS thread. This is much simpler to implement than Go runtime style green threads because it doesn't require special handling of blocking system calls.