Skip to content

Conversation

@gschorcht
Copy link
Contributor

Backport of #10862

Contribution description

This PR increases the performance and the stability of the esp_wifi netdev driver. These are in detail:

  • Since the _esp_wifi_recv_cb callback on frame receiption is not executed in interrupt context but in the context of the ets thread, it is not necessary to pass theNETDEV_EVENT_ISR event first. Instead, the receive function _recv can be called directly which leads to a much faster handling, a lower frame lost rate and more robustness.

  • Since _recv function and _esp_wifi_recv_cb are called in a deterministic order, there is no need for a mutex anymore to synchronize the access to the receive buffer between the _esp_wifi_recv_cb and the recv function.

  • The Espressif SDK includes its own lwIP version. Since lwIP is not required for RIOT, the lwIP library from Espressif SDK is not used anymore. To satisfy symbol dependencies of the SDK libraries to the lwIP library, a number of dummy functions are defined without real functionality. Using these dummy functions instead of real lwIP functions saves about 4 kbytes of RAM.

  • The auto reconnect mechanism from SDK is used now since it seems to be more stable and less memory consuming.

  • Removes timeout handling and disconnecting in send function when the lwIP buffer is exhausted. This PR solves problems 2 and 4 in issue cpu/esp8266: Tracking open problems of esp_wifi netdev driver #10861. Waiting that the frame allocated in lwIP packet buffer is freed by MAC layer led to the complete blockage of send function on heavy network load. Disconnecting from AP is counterproductive since reconnecting usually fails on heavy network load.

  • Human readable disconnect reasons.

  • Generation of NETDEV_EVENT_LINK_DOWN and NETDEV_EVENT_LINK_DOWN on disconnect and connect to the AP.

Testing procedure

With this PR, the performance of pinging an esp8266 node should be noticeably better than before.

  • Compile and flash example/gnrc_networking to at least one ESP8266 node using your AP configuration, e.g.,
    CFLAGS='-DESP_WIFI_SSID=\"<your SSID>\" -DESP_WIFI_PASS=\"your passphrase\"' USEMODULE="esp_wifi" make BOARD=esp8266-esp-12x -C examples/gnrc_networking flash
    
  • Stress test from LAN with sudo ping6 fe80::<ESP_IID> -Ieth0 -s1392 -i 0 should be stable. The packet loss rate should be 0. This should be also the case, if ping is executed on two nodes or in both directions.

Issues/PRs references

This PR solves the problems 2 and 4 as described in #10861. It improves the stability and the performance a lot.

@gschorcht gschorcht added Process: release backport Integration Process: The PR is a release backport of a change previously provided to master Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking Area: drivers Area: Device drivers Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Jan 30, 2019
@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 30, 2019
@aabadie
Copy link
Contributor

aabadie commented Jan 30, 2019

@gschorcht, the branch must be updated on the lastest version of 2019.01-branch, so can you rebase one last time ? thanks

Since _esp_wifi_recv_cb is not executed in interrupt context but in the context of the `ets` thread, the receive function can be called directly. There is no need for a mutex anymore to synchronize the access to the receive buffer between _esp_wifi_recv_cb and _recv function.
Since _esp_wifi_recv_cb is not executed in interrupt context but in the context of the `ets` thread, it is not necessary to pass the`NETDEV_EVENT_ISR` event first. Instead, the receive function can be called directly which result in much faster handling, a less frame lost rate and more robustness.
Defines a number of lwIP functions that are required as symbols by Espressif's SDK libraries. These functions are only dummies without real functionality. Using these functions instead of real lwIP functions provided with the SDK saves arround 4 kBytes of RAM.
It seems to be more stable and less memory consuming to use auto reconnect policy.
Disconnecting from the AP in the send function if the lwIP packet buffer is exhausted is counterproductive since reconnecting usually fails on heavy network load. A better strategy is to slow down the sending of MAC frames from netif a bit to wait for flushing the buffer in the MAC layer.
It is not necessary to realize timeout handling in send function or to disconnect from AP if lwIP packet buffer is exhausted. Waiting that the frame allocated in lwIP packet buffer is freed by MAC layer led to the complete blockage of send function on heavy network load. Disconnecting from AP is counterproductive since reconnecting usually fails on heavy network load.
The situation where the firmware `lwIP` packet buffer is exhausted is an important indication that the traffic sent to and sent from the esp8266 is more than the esp8266 is able to handle. Therefore, it should be an error message.
Checking by the send function that at least two maximum size Ethernet frames fit in the remaining heap before the LwIP packet buffer is allocated seems to increase stability. This can be caused by the fact that WLAN hardware interrupts allocate additional memory when receiving a frame during the send attempt.
@gschorcht gschorcht force-pushed the esp8266_esp_wifi_netdev_bp branch from d724eef to fa93fb3 Compare January 30, 2019 16:12
@gschorcht
Copy link
Contributor Author

@aabadie Rebased

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff is exactly the same as original PR.

ACK and go!

@aabadie aabadie merged commit ab370aa into RIOT-OS:2019.01-branch Jan 30, 2019
@gschorcht
Copy link
Contributor Author

Thanks

@gschorcht gschorcht deleted the esp8266_esp_wifi_netdev_bp branch January 30, 2019 17:59
@aabadie aabadie added this to the Release 2019.01 milestone Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms Process: release backport Integration Process: The PR is a release backport of a change previously provided to master Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants