Skip to content

Commit 495600f

Browse files
committed
perf(executor): Catch up on network work before returning
When the point in time that smoltcp thinks the interface should be polled again is in the past, we should try to poll it immediately to avoid lagging behind. Signed-off-by: Jens Reidel <[email protected]>
1 parent 0ebae3f commit 495600f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/executor/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,28 @@ where
169169
{
170170
if let Some(mut guard) = crate::executor::network::NIC.try_lock() {
171171
let delay = if let Ok(nic) = guard.as_nic_mut() {
172+
let mut delay_micros = nic
173+
.poll_delay(Instant::from_micros_const(now.try_into().unwrap()))
174+
.map(|d| d.total_micros());
175+
176+
// Under heavy workloads, we may be lagging behind, in which case we
177+
// need to try to catch up immediately
178+
while delay_micros == Some(0) {
179+
nic.poll_common(crate::executor::network::now());
180+
delay_micros = nic
181+
.poll_delay(crate::executor::network::now())
182+
.map(|d| d.total_micros());
183+
}
184+
185+
// We will yield back to userspace and may not have an opportunity to handle
186+
// network traffic unless we enable interrupts
172187
nic.set_polling_mode(false);
173188

174-
nic.poll_delay(Instant::from_micros_const(now.try_into().unwrap()))
175-
.map(|d| d.total_micros())
189+
delay_micros
176190
} else {
177191
None
178192
};
193+
179194
core_local::core_scheduler().add_network_timer(
180195
delay.map(|d| crate::arch::processor::get_timer_ticks() + d),
181196
);

0 commit comments

Comments
 (0)