Skip to content

Commit

Permalink
Performance improvement (#430)
Browse files Browse the repository at this point in the history
* Improve response times

* Revert "Improve response times"

This reverts commit 77c437a.

* Fix embassy_bench

* Yield from tx_token/rx_token if no progress can be made otherwise

* CHANGELOG.md entry

---------

Co-authored-by: Karl Rikte <[email protected]>
  • Loading branch information
bjoernQ and karlri authored Feb 8, 2024
1 parent e8042d5 commit e6c58b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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

0 comments on commit e6c58b6

Please sign in to comment.