Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

projectgus
Copy link
Contributor

@projectgusprojectgus commentedMay 9, 2025
edited
Loading

Summary

Closes#16181. 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.

It means that it's possible to do:

wlan.disconnect()machine.lightsleep(5000)wlan.connect(...)

... and get the full sleep time, but also possible to do

whilesome_condition():machine.lightsleep(5000)

... 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 awhile 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.

  • Ranmulti_net andmulti_wlan tests on RPI_PICO_W and RPI_PICO2_W. Same failures as reported against master.

Trade-offs and Alternatives

  • There is some risk that some part of LWIP doesn't like being starved of timeouts for a long period after a network interface goes down. However, it looks like it will be OK - the main thing is TCP/IP socket timeouts and LWIP will keep ticking until these time out.
  • Could make LWIP timer not a wake-up source, but this is quite difficult and does prevent using light sleep effectively with Wi-Fi.
  • Could make LWIP timer wake-ups not return from lightsleep (i.e. the hardware wakes up, services LWIP, then goes back to sleep), but this is also quite fiddly to do (need to check the wake source each time).
  • Semi-related: there is also a LWIP functionsys_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.

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedMay 9, 2025
edited
Loading

Code size report:

   bare-arm:    +0 +0.000% minimal x86:    +0 +0.000%    unix x64:    +0 +0.000% standard      stm32:    +0 +0.000% PYBV10     mimxrt:    +0 +0.000% TEENSY40        rp2:  +112 +0.012% RPI_PICO_W[incl +8(bss)]       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS  qemu rv32:    +0 +0.000% VIRT_RV32

@madozu
Copy link

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.

Josverl and projectgus reacted with heart emoji

@dpgeorge
Copy link
Member

I haven't tested this yet (will do once it's rebased now that#16454 is merged) but the logic looks good!

@dpgeorgedpgeorge added this to therelease-1.26.0 milestoneMay 13, 2025
@projectgusprojectgus marked this pull request as ready for reviewMay 15, 2025 00:55
@projectgus
Copy link
ContributorAuthor

Rebased, addressed review comments, re-ranmulti_net andmulti_wifi tests on RPI_PICO_W & RPI_PICO2_W with same results.

  • On my local setupmulti_net/udp_data.py fails intermittently to packet loss - but I have a mediocre wifi signal here.
  • multi_net/tls_dtls_server_client.py fails when the rp2 is instance 1.
  • multi_wlan I realised has a bug when STA is rp2 and a wifi connection is already active. Will submit separate PR to fix.

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>
Copy link
Member

@dpgeorgedpgeorge left a 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.

@dpgeorgedpgeorgeforce-pushed thebugfix/rp2_lwip_ticks branch from3b17999 to4545eb8CompareMay 21, 2025 13:51
@dpgeorgedpgeorge merged commit4545eb8 intomicropython:masterMay 21, 2025
8 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dpgeorgedpgeorgedpgeorge approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
release-1.26.0
3 participants
@projectgus@madozu@dpgeorge

[8]ページ先頭

©2009-2025 Movatter.jp