-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ports/*: increase LWIP timers for ports with mDNS support #16623
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
Conversation
a440899
to
6a8367e
Compare
Code size report:
|
Thanks for the contribution.
Can you point to where the comment says one is sufficient? I could not find it.
Yes, that looks correct, I can see 3 independent timers in those functions.
I don't follow this bit, because
And it definitely looks possible to have all 5 of those running at once. But then there are also additional calls to
I'm not sure how to work out which of those can be running together... and in fact those calls could start an arbitrary number of timers if they are called over and over again. But, since there are only two independent callbacks (namely (Also, please check the CI code formatting failure.) |
Thanks for checking my work and the quick response.
Line 11 of
Sorry, yes I mis-pasted the function name when writing the message. Those are the same 5 timers I identified.
I missed these, thank you. It looks like these are used in rarer circumstances, but I agree with your assessment that these could take arbitrary numbers of timers. It is unfortunate that each callback could be queued several times and use up the timer slots for the other processes. I think upstream might need to put some attention here. I could send an inquiry to their list but I don't think I have bandwidth to fix it up at this time.
I will increase the number of timers and address the failure and test again. |
53dbc9a
to
c6cfe57
Compare
Okay, took a few tries but I think we are good now! |
Thanks for updating. In order to eliminate code duplication, I made PR #16647 which factors out the common lwIP configuration for these four ports. I think we should merge that first, then this PR becomes simpler, it's just changing one location. |
@tpwrules are you able to update this PR and just make a single change in the consolidated file at |
c6cfe57
to
75ca40c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #16623 +/- ##
=======================================
Coverage 98.53% 98.53%
=======================================
Files 169 169
Lines 21806 21806
=======================================
Hits 21487 21487
Misses 319 319 ☔ View full report in Codecov by Sentry. |
Not sure what to do about the CI failure? |
I reran it, it now passes. |
CircuitPython has had similar problems with static memory pool allocations in lwIP. Our solution was to configure lwIP to allocate all of its memory dynamically from our top-level tlsf heap. See adafruit#9837. |
ef5f1fb
to
015d927
Compare
Despite the code comments claiming one is sufficient, the mDNS application is capable of using up to twelve timers. Three per IP protocol are started at once in `mdns_start_multicast_timeouts_ipvX`, then another two per protocol can be started in `mdns_handle_question`. Further timers can be started for two additional callbacks. Having certain timers, such as `MDNS_MULTICAST_TIMEOUT`, fail to start due to none being free will break mDNS forever as the app will never realize it's safe to transmit a packet. Therefore, this commit goes somewhat overkill and allocates the maximal amount of timers; it's uncertain if all can run simultaneously, or how many callback timers are needed. Each timer struct is 16 bytes on standard 32 bit builds. Plus, say, 8 bytes of allocater overhead, that's 288 more bytes of RAM used which shouldn't be too horrible. Users who don't need mDNS can manually disable it to recover the RAM if necessary. This fixes mDNS on W5500_EVB_PICO (among other boards). Before, mDNS would work for a bit after connection until the host's cache expired a minute or two later. Then the board would never respond to further queries. With this patch, all works well. Signed-off-by: Thomas Watson <twatson52@icloud.com>
015d927
to
aef6705
Compare
Thanks for updating, now merged. |
Summary
Despite the code comments claiming one is sufficient, the mDNS application is capable of using up to twelve timers. Three per IP protocol are started at once in
mdns_start_multicast_timeouts_ipvX
, then another two per protocol can be started inmdns_handle_question
. Further timers can be started for two additional callbacks.Having certain timers, such as
MDNS_MULTICAST_TIMEOUT
, fail to start due to none being free will break mDNS forever as the app will never realize it's safe to transmit a packet.Testing
This fixes mDNS on W5500_EVB_PICO. Before, mDNS would work for a bit after connection until the host's cache expired a minute or two later. Then the board would never respond to further queries. With this patch, all works well.
Trade-offs and Alternatives
This PR goes somewhat overkill and allocates the maximal amount of timers; it's uncertain if all can run simultaneously, or how many callback timers are needed.
Each timer struct is 16 bytes on standard 32 bit builds. Plus 8 bytes of allocater overhead, that's 288 more bytes of RAM used which shouldn't be too horrible. Users who don't need mDNS can manually disable it to recover the RAM if necessary.