- Notifications
You must be signed in to change notification settings - Fork8.2k
rp2: Disable the LWIP tick timer when not needed.#17272
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
Code size report:
|
madozu commentedMay 9, 2025
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. |
I haven't tested this yet (will do once it's rebased now that#16454 is merged) but the logic looks good! |
f02fa2e
to3b17999
CompareRebased, addressed review comments, re-ran
|
Prevents lightsleep being woken up every 64ms to service LWIP timers, when:1. No netif is up, and2. No TCP sockets are activeThe TCP socket check may not be strictly necessary, but without ticking thetcp 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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Tested on RPI_PICO_W and RPI_PICO2_W, running all possible tests:
tests/ports/rp2/rp2_lightsleep_thread.py
fails on both of them, but that's expected (and fails also on master)tests/multi_net/udp_data_multi.py
fails 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.
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_net
andmulti_wlan
tests 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.