From 6f390a9d5e2dc17b0cb147f650477cd6e5e5bb20 Mon Sep 17 00:00:00 2001 From: Li Zebin Date: Tue, 1 Aug 2023 00:05:11 +0800 Subject: [PATCH] vsock: Move `iter` outside of loop in `process_tx_queue`. the iter() function is used for produce a queue iterator to iterate over the descriptors. But usually, it shouldn't be in the while loop, which might brings more unnecessary overhead. So move iter outside of the while loop. Signed-off-by: Li Zebin --- crates/vsock/src/vhu_vsock_thread.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/vsock/src/vhu_vsock_thread.rs b/crates/vsock/src/vhu_vsock_thread.rs index 08c10226c..37e50b7bf 100644 --- a/crates/vsock/src/vhu_vsock_thread.rs +++ b/crates/vsock/src/vhu_vsock_thread.rs @@ -607,13 +607,15 @@ impl VhostUserVsockThread { None => return Err(Error::NoMemoryConfigured), }; - while let Some(mut avail_desc) = vring - .get_mut() - .get_queue_mut() + let mut vring_mut = vring.get_mut(); + + let queue = vring_mut.get_queue_mut(); + + let mut queue_iter = queue .iter(atomic_mem.memory()) - .map_err(|_| Error::IterateQueue)? - .next() - { + .map_err(|_| Error::IterateQueue)?; + + while let Some(mut avail_desc) = queue_iter.next() { used_any = true; let mem = atomic_mem.clone().memory();