WIP: A useful SMP threading system
Aim: Improve the SMP module (+ associated OS components) to get it to the state where programs can use standard threading APIs (C11 threads in SharedCLibrary, pthreads in UnixLib) to gain extra performance with minimal fuss (i.e. minimise the number of places where cross-platform code needs RISC OS specific tweaks)
Main changes:
- Thread scheduler rewritten to be less terrible
- First-class mutex & condition variable implementation, and sleeping on timers
- Threads can belong to processes
- This allows the Wimp & TaskWindow to easily suspend/resume them all when switching task
- Allows SWIs which aren't SMP-safe to be called (doing so will temporarily suspend the other threads in the process)
- Aborts, SWI errors, etc. will be handled via the usual environment handlers instead of causing immediate thread termination
- SVC stack handling changed, so that one SVC stack can be shared between multiple threads, allowing for many more threads to be running than the number of SVC stacks (with the limitation that threads may be blocked from running if all the stacks are currently in use)
- OS_ClaimProcessorVector handlers supported via the new MP-safe OS_ClaimProcessorVector API (except for SWI handlers)
- Support for FPA & VFP/NEON use in threads
Related WIP changes to other components (you'll need a ROM containing all of these):
- https://gitlab.riscosopen.org/jlee/Kernel/-/commits/SMP
- https://gitlab.riscosopen.org/jlee/TaskWindow/-/commits/SMP
- https://gitlab.riscosopen.org/jlee/Wimp/-/commits/SMP
- https://gitlab.riscosopen.org/jlee/FPASC/-/commits/SMP
- https://gitlab.riscosopen.org/jlee/VFPSupport/-/commits/SMP
TODO:
- Lots of code tidying, testing, hardening & bug fixing; preferably build a test framework which all the core logic can be tested in
- Lazy task swapping support (currently, lazy task swapping will be disabled when the module starts)
- Other SMP module enhancements necessary to allow language runtimes (SharedCLibrary, UnixLib, etc.) to easily add threading support
- C11 threads support in SCL (initially SMP-only, later on add callback-based scheduler implementation for non-SMP machines/OSes)
- SMP support in UnixLib pthreads
- Finish adding nanosecond timer support to the HAL/kernel so performance metrics can be tracked more easily
- Increase/remove thread limit caps (+ other limits), implement 'nice' prioritisation
- Fix any performance issues
Known issues:
- When run from a task window, Test.load_vfp fails; possibly TaskWindow and SMP are fighting with each other over which VFP context should be active
- Test.bounceswi sometimes hangs, and I think I've seen Test.bounceund hang too
- Titanium & PineA64 platforms need their HALs to be updated in order to allow the SMP module to run