rp2: Disable the LWIP tick timer when not needed.#17272
Merged
Conversation
|
Code size report: |
|
I did a lot of testing with the current master branch and pull requests #16454 and #17272 applied. All the "early wakeup" scenarios I was experiencing when using machine.lightsleep() are solved --> Great news, many thanks to @projectgus for providing a good solution 😄 So far, I did not encounter any negative side effects. |
dpgeorge
reviewed
May 13, 2025
Member
|
I haven't tested this yet (will do once it's rebased now that #16454 is merged) but the logic looks good! |
f02fa2e to
3b17999
Compare
Contributor
Author
|
Rebased, addressed review comments, re-ran
|
Prevents lightsleep being woken up every 64ms to service LWIP timers, when: 1. No netif is up, and 2. No TCP sockets are active The TCP socket check may not be strictly necessary, but without ticking the tcp timer they won't ever time out by themselves. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
dpgeorge
approved these changes
May 21, 2025
dpgeorge
left a comment
Member
There was a problem hiding this comment.
Tested on RPI_PICO_W and RPI_PICO2_W, running all possible tests:
tests/ports/rp2/rp2_lightsleep_thread.pyfails on both of them, but that's expected (and fails also on master)tests/multi_net/udp_data_multi.pyfails when one of the boards is instance 0, and also fails on master. I was sure this was working when I wrote the test so maybe it's down to local WLAN variability.
All other tests pass for me.
3b17999 to
4545eb8
Compare
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.
Summary
Closes #16181. Prevents lightsleep being woken up every 64ms to service LWIP timers, when:
The TCP socket check may not be strictly necessary, but without ticking the tcp timer they won't ever time out by themselves.
It means that it's possible to do:
... and get the full sleep time, but also possible to do
... and Python will wake up every 64ms if Wi-Fi is active, but power consumption is still lower than it would be otherwise.
(Not massively lower, on RPI_PICO_W I measure 53mA idle at REPL with Wi-Fi associated, and 40mA in a
while True: machine.lightsleep(1000)loop. There is probably potential to make this better by having lightsleep put the CYW43 driver into a lower power mode.)This work was funded through GitHub Sponsors.
Testing
Important: This PR has only been tested cherry-picked onto the branch for #16454. It is marked as a draft until that PR is merged and it can be rebased.
multi_netandmulti_wlantests on RPI_PICO_W and RPI_PICO2_W. Same failures as reported against master.Trade-offs and Alternatives
sys_timeouts_sleeptime()which could be used to have the LWIP timer run at an exact time instead of at a constant tick rate. However, a number of LWIP "cyclic" timers run every 100ms right now so this change seems like it would be of limited benefit, it would add some code size, and the lwip tick callback is also used to poll the wiznet5k driver.