Repository navigation
Conversation
Without the fiber scheduler, yield() is an empty inline function, so the compiler assumes that no memory changes while polling. It then hoists the load of non-volatile variables modified in interrupts out of the polling loop, which turns the loop into an endless loop or removes it entirely. The memory clobber emits no code, but forces all memory to be reloaded after yield(), just like for a real context switch.
The mutexes, semaphores, latch, stop token and condition variable only depend on yield() and get_id(), so they also work with the empty yield stub to synchronize the main context with interrupts. The barrier is excluded, since it requires multiple fibers to make progress. The get_id() stub now returns the interrupt number inside interrupts on Cortex-M just like the scheduler does, otherwise the recursive mutex cannot tell the main context apart from an interrupt. The new hosted-no-fiber unit test configuration tests the fiber API without the scheduler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the missing
volatilefixes in #1386. Those were only a symptom: withoutmodm:processing:fibertheyield()function is an empty inline stub, so the compiler assumes that nothing changes while polling and happily hoists the load of the flag out of the loop:So instead of hunting down every non-volatile flag in every driver, the stub now tells the compiler that memory changed, just like a real context switch does.
yield()stub contains an emptyasmwith a memory clobber. Emits no code, but the flag gets reloaded on every iteration.mutex,shared_mutex,semaphore,latch,stop_tokenandcondition_variableare now also available without the scheduler. They only needyield()andget_id(), so they work just fine for synchronizing the main context with interrupts.barrieris not available without the scheduler, since it needs multiple fibers to make any progress.get_id()stub returns the interrupt number inside interrupts on Cortex-M, same as the scheduler. It returned0everywhere before, so the recursive mutex could not tell the main context apart from an interrupt.modm:architecture:fiberdepends onmodm:architecture:atomicfor the recursive mutex.lock(),acquire()orwait()waits in place and only returns if an interrupt releases it.modm-test:test:architecture:fiberunit test that uses the primitives from outside of a fiber, so it runs with and without the scheduler.hosted-no-fiberunit test configuration and CI step for the latter.Tests:
run-hosted-linux-no-fiberin CI, only ran the macOS equivalent locally.This is only the first half: the plan is to then replace the hand-rolled locks in modm (
SpiLock,ResumableMutex, the AMNB node, the STM32 SPI DMA flags) with these primitives in a separate PR.