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

Performance improvement #430

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Users don't need embedded-svc to control wifi anymore. The wifi trait is optionally implemented now. (#429)
- Better network performance by forced yielding of the task when buffers are full / empty. (#430)

### Removed

Expand Down
8 changes: 4 additions & 4 deletions esp-wifi/examples/embassy_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use examples_util::hal;
use embassy_time::{with_timeout, Duration, Timer};
use esp_backtrace as _;
use esp_println::println;
use esp_wifi::wifi::{ClientConfiguration, Configuration};
use esp_wifi::wifi::{WifiApDevice, WifiController, WifiDevice, WifiEvent, WifiState};
use esp_wifi::wifi::{ClientConfiguration, Configuration, WifiStaDevice};
use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiState};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::clock::ClockControl;
use hal::Rng;
Expand Down Expand Up @@ -60,7 +60,7 @@ async fn main(spawner: Spawner) -> ! {

let wifi = peripherals.WIFI;
let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap();
esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
embassy::init(&clocks, timer_group0);
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn connection(mut controller: WifiController<'static>) {
}

#[embassy_executor::task]
async fn net_task(stack: &'static Stack<WifiDevice<'static, WifiApDevice>>) {
async fn net_task(stack: &'static Stack<WifiDevice<'static, WifiStaDevice>>) {
stack.run().await
}

Expand Down
10 changes: 10 additions & 0 deletions esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,10 @@ mod sealed {
}

fn tx_token(self) -> Option<WifiTxToken<Self>> {
if !self.can_send() {
crate::timer::yield_task();
}

if self.can_send() {
Some(WifiTxToken { mode: self })
} else {
Expand All @@ -1503,6 +1507,12 @@ mod sealed {

fn rx_token(self) -> Option<(WifiRxToken<Self>, WifiTxToken<Self>)> {
let is_empty = critical_section::with(|cs| self.data_queue_rx(cs).is_empty());
if is_empty || !self.can_send() {
crate::timer::yield_task();
}

let is_empty =
is_empty && critical_section::with(|cs| self.data_queue_rx(cs).is_empty());

if !is_empty {
self.tx_token().map(|tx| (WifiRxToken { mode: self }, tx))
Expand Down
Loading