-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Various ports: add support for Timer hard= option #17580
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
Open
arachsys
wants to merge
13
commits into
micropython:master
Choose a base branch
from
arachsys-prs:hardtimer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+286
−90
Conversation
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17580 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 169 169
Lines 21968 21968
=======================================
Hits 21654 21654
Misses 314 314 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
a2b8b69
to
5e3cf0b
Compare
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the stm32 port for a hard= argument to explicitly choose between these, setting the default to True to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the esp2 port for a hard= argument to explicitly choose between these, setting the default to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the esp8266 port for a hard= argument to explicitly choose between these, setting the default to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the zephyr port for a hard= argument to explicitly choose between these, setting the default to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the renesas-ra port for a hard= argument to explicitly choose between these, setting the default to True to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
The Timer initialiser in ports/renesas-ra/timer.c appears to be based on another port, and options that aren't actually available are listed in documentation comments and an error message. Correct these. Signed-off-by: Chris Webb <[email protected]>
Add a flag SOFT_TIMER_HARD_CALLBACK to request that a soft timer's python callback is run directly from the IRQ handler with the scheduler and heap locked, instead of being scheduled via mp_sched_schedule(). Gate support for this flag on MICROPY_SOFT_TIMER_HARD_CALLBACKS so ports that don't use the softtimer for their machine.Timer() implementation don't suffer the small code-size increase. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the generic software timer for a hard= argument to explicitly choose between these, setting the default to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the samd port for a hard= argument to explicitly choose between these. The samd Timer is implemented using the shared software timer, so define MICROPY_SOFT_TIMER_HARD_CALLBACKS to enable hard-IRQ support in shared/runtime/softtimer. This automatically enables the hard= option in extmod/machine_timer, defaulting to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the mimxrt port for a hard= argument to explicitly choose between these. The mimxrt Timer is implemented using the shared software timer, so define MICROPY_SOFT_TIMER_HARD_CALLBACKS to enable hard-IRQ support in shared/runtime/softtimer. This automatically enables the hard= option in extmod/machine_timer, defaulting to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the alif port for a hard= argument to explicitly choose between these. The alif Timer is implemented using the shared software timer, so define MICROPY_SOFT_TIMER_HARD_CALLBACKS to enable hard-IRQ support in shared/runtime/softtimer. This automatically enables the hard= option in extmod/machine_timer, defaulting to False to match the existing behaviour. Signed-off-by: Chris Webb <[email protected]>
Now all ports with machine.Timer except nrf support both hard and soft callbacks, generalise tests/ports/rp2_machine_timer.py into tests/extmod/machine_timer.py. There is an existing machine_soft_timer.py which varies period= and covers the nrf port but skips esp32/esp8266 because they don't support software timers. In our new test, we try varying freq= instead of period=, and cover esp32/esp8266 (with a fixed choice of hardware timer) but skip nrf because it doesn't support hard= or freq=. Add a check that the heap is locked (so allocation fails) in hard callbacks and it is unlocked (so allocation succeeds) in soft callbacks, to ensure we're getting the right kind of callback, not falling back to the default. Signed-off-by: Chris Webb <[email protected]>
Update the main machine.Timer specification, and any references to hard/soft interrupts in port-specific documentation. There is a separate copy of the machine.Timer documentation for the pyboard, so update that too to keep everything consistent. Signed-off-by: Chris Webb <[email protected]>
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.
Summary
7816b1f, 8f85eda and 8162468 (PR #17363) added a
hard=
option to the rp2Timer
constructor and initialiser to allow the callback to be switched between hard-IRQ and soft-IRQ mode.The behaviour of other ports varies: either hard-IRQ only or soft-IRQ only. @dpgeorge suggested that it would be good to make this consistently configurable across all ports, preserving the current default but allowing both behaviours everywhere.
This patch series is an attempt to do that, adding support to every port that has a
machine.Timer
except nrf (see below), ensuring there is cross-port test coverage of both variants, and documenting as appropriate.Notes and issues
nrf is the only port with a
machine.Timer
that isn't covered by this patch series. This port doesn't havemp_sched_schedule()
enabled so I don't think I can supporthard=False
there? I've left it out altogether, assuming that extra code size isn't worth it just to add an ignoredhard=True
option for consistency. (I also note that nrf also doesn't support thefreq=
option to theTimer
constructor/init, justperiod=
, so it's definitely a cut-back timer implementation more generally.)I've added hard IRQ support to
shared/runtime/softtimer
, but have gated it to avoid bloat on platforms which have their own timer infrastructure and don't need hard IRQ support from the software timer. alif, mimxrt and samd are the three ports which turn this on.Testing
Although I have compile tested every patch and every port via the Micropython test infrastructure, I don't have hardware to test ports other than rp2. The generalised test I have written in
tests/extmod/machine_timer.py
would exercise old and new codepaths on every modified platform if run there.I would greatly appreciate help in verifying that this series does indeed work correctly on every port it claims to cover! Obviously I will happily fix any issues that do show up.
For the purposes of writing tests:
machine.Timer
except nrf supports bothhard=True
andhard=False
machine.Timer
except nrf supportsfreq=N
(N
in Hz)machine.Timer
except renesas-ra supportsperiod=N
(N
in ms)id = -1
)To try to cover the various cases a bit more thoroughly, my new test covers all ports with a
machine.Timer
including esp32/esp8266 but excluding nrf, exercising hard and soft timers with varyingfreq=
and explicitly checking that the heap is locked in hard callbacks and unlocked in soft callbacks.