-
Notifications
You must be signed in to change notification settings - Fork 353
Requesting feedback: Improve async wifi performance #3670
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
Before going into low power sleep, yield to the wifi task. This should cause it to send outbound packets before sleeping. It should also cause inbound packets to be processed earlier since if we wake from waiti because of a wifi interrupt we will repoll without progress and then run the wifi stack which will generate work for the executor.
|
Interesting idea! I believe what you want can be implemented in user-code by creating a task that is always ready to run: #[embassy_executor::task]
async fn force_run_esp_wifi() {
loop {
yield_task(); // force an esp-wifi context switch
embassy_futures::yield_now().await; // keep the task ready to run
}
} |
|
I think it would result in busy polling since that future is always ready to run if i understand correctly. That, again if I understand correctly, would prevent the executor from ever attempting to wait (low power sleep waiting for interrupt with the waiti instruction). The key idea about my proposal is both improving performance and improving power consumption by reducing the context switching rate when there is little I/O. I believe there is no place a user can fix this using the public API but again I might be wrong. If there was an api like |
We don't know if there is something to do, or not. That information is encoded in the
Because this would be called after every single poll, it would hurt performance a bit. Yielding to esp-wifi also hurts performance in the same way. The amount of work done for each poll should be kept to the absolute minimum. This isn't a big problem if users need to opt-in to the feature, but I'm hoping we can do something cheaper that benefits everyone. |
| } | ||
|
|
||
| #[cfg(low_power_wait_wifi_perf_opt)] | ||
| if cpu == 0 { |
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.
Don't know if it's a good idea to introduce more places where esp-wifi is hard coded to run on core 0.
|
I'm thinking that if we added a |
|
With #3737 merged, it should now be possible to implement this in user code. Maybe we should make the yield function public in esp-wifi, if the builtin scheduler is used, so that people aren't forced to reimplement it. |
|
Closing in favour of using the hook mechanic implemented in #3737. |
This change seems to increase async wifi performance quite nicely. It helps with http response times and with ping times. I do not know of any adverse effects. I'm requesting that someone test this on xtensa. It would be very interesting to hear what results others get with this. If it seems promising we could refine this further. Think of this as a request for testing and comments on the approach for now. It could probably be improved if we could know:
Test program:
controller .set_power_saving(esp_wifi::config::PowerSaveMode::None) .unwrap(); loop { let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); let mut buf = [0; 512]; let local_endpoint = (config.address.address(), 80); socket.accept(local_endpoint).await.unwrap(); socket.read(&mut buf).await.unwrap(); socket .write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 6\r\nConnection: close\r\n\r\nhi m8\n") .await .unwrap(); socket.flush().await.unwrap(); }All tests performed on esp32s3. All tests with 1m between AP and esp32s3 in STA mode.
.cargo/config.toml esp32s3
Results:
.cargo/config.toml esp32s3 1KHz optimization disabled for comparison
Results:
Keep in mind that tie curl timing includes loading the curl executable so the improvement is bigger than it might seem.
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packagescommand to ensure that all changed code is formatted correctly.CHANGELOG.mdin the proper section.Extra:
Pull Request Details 📖
Description
Please provide a clear and concise description of your changes, including the motivation behind these changes. The context is crucial for the reviewers.
Testing
Describe how you tested your changes.