Skip to content

Commit cddc783

Browse files
committed
io_uring: transfer_monitor: transfer stall detection
1 parent 57e0c3e commit cddc783

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/io_uring.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,18 @@ async fn transfer_monitor(
107107
) -> Result<()> {
108108
let mut usb_bytes_out_last: usize = 0;
109109
let mut tcp_bytes_out_last: usize = 0;
110+
let mut stall_usb_bytes_last: usize = 0;
111+
let mut stall_tcp_bytes_last: usize = 0;
110112
let mut report_time = Instant::now();
113+
let mut stall_check = Instant::now();
111114

112115
loop {
116+
// load current total transfer from AtomicUsize:
117+
let usb_bytes_out = usb_bytes_written.load(Ordering::Relaxed);
118+
let tcp_bytes_out = tcp_bytes_written.load(Ordering::Relaxed);
119+
113120
// Stats printing
114121
if stats_interval.is_some() && report_time.elapsed() > stats_interval.unwrap() {
115-
// load current total transfer from AtomicUsize:
116-
let usb_bytes_out = usb_bytes_written.load(Ordering::Relaxed);
117-
let tcp_bytes_out = tcp_bytes_written.load(Ordering::Relaxed);
118-
119122
// compute USB transfer
120123
usb_bytes_out_last = usb_bytes_out - usb_bytes_out_last;
121124
let usb_transferred_total = ByteSize::b(usb_bytes_out.try_into().unwrap());
@@ -151,6 +154,22 @@ async fn transfer_monitor(
151154
tcp_bytes_out_last = tcp_bytes_out;
152155
}
153156

157+
// transfer stall detection
158+
if stall_check.elapsed() > READ_TIMEOUT {
159+
// compute delta since last check
160+
stall_usb_bytes_last = usb_bytes_out - stall_usb_bytes_last;
161+
stall_tcp_bytes_last = tcp_bytes_out - stall_tcp_bytes_last;
162+
163+
if stall_usb_bytes_last == 0 || stall_tcp_bytes_last == 0 {
164+
return Err("unexpected transfer stall".into());
165+
}
166+
167+
// save values for next iteration
168+
stall_check = Instant::now();
169+
stall_usb_bytes_last = usb_bytes_out;
170+
stall_tcp_bytes_last = tcp_bytes_out;
171+
}
172+
154173
sleep(Duration::from_millis(100)).await;
155174
}
156175
}

0 commit comments

Comments
 (0)