Skip to content

Commit

Permalink
Improve response times
Browse files Browse the repository at this point in the history
When the network interface can't make any progress, it's probably
a good idea to yeild the task so that the wifi task may run and
proceed with actually sending/receiving data.

This seems to greatly improve response times, especially with low
tick_rate_hz values. At 100Hz, ping time goes down from 25ms to
<2ms. A simple http server test saw a response time reduction from
45ms to 6ms. At 1000Hz tick rate the gains are diminishing but
there are some small gains. I ran my tests on esp32s3.

This might also increase throughput. I have not tested that.
It also may have some unforseen adverse effects.

Ideally, we would have a more fine grained return value from
interface.poll() than a bool so we have a better idea if yeilding
is appropriate or not.
  • Loading branch information
karlri committed Jan 12, 2024
1 parent ce42649 commit a530012
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions esp-wifi/src/wifi_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> {
sockets,
)
}) {
crate::timer::yield_task();
break;
}
}
Expand Down Expand Up @@ -713,7 +714,9 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Read for Socket<'s, 'n, MODE> {
use smoltcp::socket::tcp::RecvError;

loop {
interface.poll(timestamp(), device, sockets);
if interface.poll(timestamp(), device, sockets) == false {
crate::timer::yield_task();
}
let socket = sockets.get_mut::<TcpSocket>(self.socket_handle);

match socket.recv_slice(buf) {
Expand All @@ -733,11 +736,14 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Write for Socket<'s, 'n, MODE> {
loop {
let (may_send, is_open, can_send) =
self.network.with_mut(|interface, device, sockets| {
interface.poll(
if interface.poll(
Instant::from_millis((self.network.current_millis_fn)() as i64),
device,
sockets,
);
) == false
{
crate::timer::yield_task();
}

let socket = sockets.get_mut::<TcpSocket>(self.socket_handle);

Expand Down Expand Up @@ -784,6 +790,7 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Write for Socket<'s, 'n, MODE> {
});

if let false = res {
crate::timer::yield_task();
break;
}
}
Expand Down

0 comments on commit a530012

Please sign in to comment.