Skip to content
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

[Gratuitous ARP] Thread-safe LWIP API calls, fix condition for IF #2583

Merged
merged 3 commits into from
Sep 24, 2019

Conversation

mcspr
Copy link
Contributor

@mcspr mcspr commented Aug 30, 2019

Notes:

err_t is substituted via int8_t, because platformio .ino converter will create .cpp as ESPEasy.ino + prototypes + everything else. As the result there's compilation error, because include <lwip/...> only happens after err_t is mentioned.

Continuing from my comment:
xoseperez/espurna#1877 (comment)
I also noticed that current LWIP build for ESP32 already has gratuitous arp timer set up to trigger every 60 seconds after connection was established, but the value seems to be too high and current burst ... to 5 seconds implementation does a better job at notifying other devices about it's MAC.
platformio.ini contains some flags that try to change this behaviour:
1c451bb
But they are ineffective, because lwip is pre-built:
https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/lib/liblwip.a

Perhaps, those CONFIG... flags should be removed?

As stated in LWIP documentation:
https://www.nongnu.org/lwip/2_1_x/multithreading.html

"When running in a multithreaded environment, raw API functions MUST only
be called from the core thread since raw API functions are not protected
from concurrent access (aside from pbuf- and memory management
functions). Application threads using the sequential- or socket API
communicate with this main thread through message passing."

https://www.nongnu.org/lwip/2_1_x/netifapi_8h.html
Is not present in current esp-idf / arduino-esp32 builds.
Using existing "private" TCPIP API, create a minimal struct to pass a message
to the LWIP thread instead of calling etharp_gratuitous directly.
See this comment and further discussion in the issue:
xoseperez/espurna#1877 (comment)

Use the same condition as esp-lwip.
@TD-er
Copy link
Member

TD-er commented Aug 30, 2019

Great!
Thanks for the PR and the additional info.
I will read through the links you provided.

@mcspr
Copy link
Contributor Author

mcspr commented Sep 1, 2019

Might've been to fast on this.... there's a public api for this type of thing, somehow missed that reading through the docs.
https://www.nongnu.org/lwip/2_0_x/tcpip_8h.html#ab1d3ef23817d7703fa75ed67bd45ea1d
(or tcpip_callback / tcpip_try_callback in 2.1.2)

Is it ok to just add new commit with callback() or should I use rebase to eb3cc6c message as well?

@TD-er
Copy link
Member

TD-er commented Sep 1, 2019

Just add it to this PR, it has not yet been merged (due to build issues on some builds, we're approaching max sketch size)

I prefer no have the Gratuitous ARPs to be non blocking, as long as the queue is being processed in order, or at least in order for the 'forced' ARP packets. For example after a detected failed request.

@mcspr
Copy link
Contributor Author

mcspr commented Sep 3, 2019

FWIW, some brief testing shows that it takes around the same time for sendGratuitousARP to finish in either blocking or non-blocking mode: timings screen avg ~0.05s, 0.1s worst case
Initial version from eb3cc6c did afwul, avg 0.5...0.7s, 2s worst case.

Speaking of failed requests, I think I stumbled on another bug. Running c008 with wrong IP or PORT caused the node to have 99% load and webserver became really slow and completely unresponsive to settings changes. Serial terminal sort of working, but extremely slow as well.
Just a basic "System info" vcc/rssi/freestack/freeram, a lot of 708011 : HTTP : C008 Error: could not write to client (0/178) in log.

@TD-er
Copy link
Member

TD-er commented Sep 9, 2019

What is the status of this PR?
And can you make an issue about the found slow down on c008 if the host is unreachable?

@mcspr
Copy link
Contributor Author

mcspr commented Sep 10, 2019

This works as-is. In theory, iterating ifs should probably be inside of the tcp thread too (ref hwaddr check), but it should still work like this too. I have not tested this for very long though.

And can you make an issue about the found slow down on c008 if the host is unreachable?

Yes, sorry, I forgot about it.

@TD-er TD-er merged commit 1e01f36 into letscontrolit:mega Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants