From 8eb944b480c0b1e07ba24e02bb7e1955f3daf584 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 10 Oct 2019 14:28:35 -0700 Subject: devices: proxy: do not acknowledge write commands Write accessess cannot fail (in the CommandResult sense) and the result did not carry any data, so remove the response from the Write command. This should improve the speed of write requests for sandboxed devices. For example, with the sandboxed serial device, boot time with a release build of crosvm on my workstation goes from 1.7 seconds to 1.2 seconds, measured by timing a boot with a missing init so that the kernel panics and shuts down immediately. BUG=None TEST=time crosvm run -p init=bogus vm_kernel Change-Id: I125bb831235ca741ae1cc6c86a02a5d863d1a211 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1853970 Reviewed-by: Zach Reizner Tested-by: kokoro --- devices/src/proxy.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs index 3770779..6be2e21 100644 --- a/devices/src/proxy.rs +++ b/devices/src/proxy.rs @@ -92,7 +92,8 @@ fn child_proc( Command::Write { len, offset, data } => { let len = len as usize; device.write(offset, &data[0..len]); - sock.send(&CommandResult::Ok) + // Command::Write does not have a result. + Ok(()) } Command::ReadConfig(idx) => { let val = device.config_register_read(idx as usize); @@ -106,7 +107,8 @@ fn child_proc( } => { let len = len as usize; device.config_register_write(reg_idx as usize, offset as u64, &data[0..len]); - sock.send(&CommandResult::Ok) + // Command::WriteConfig does not have a result. + Ok(()) } Command::Shutdown => { running = false; @@ -217,14 +219,20 @@ impl ProxyDevice { self.sync_send(Command::RunUserCommand); } - fn sync_send(&self, cmd: Command) -> Option { + /// Send a command that does not expect a response from the child device process. + fn send_no_result(&self, cmd: Command) { let res = self.sock.send(&cmd); if let Err(e) = res { error!( "failed write to child device process {}: {}", self.debug_label, e, ); - }; + } + } + + /// Send a command and read its response from the child device process. + fn sync_send(&self, cmd: Command) -> Option { + self.send_no_result(cmd); match self.sock.recv() { Err(e) => { error!( @@ -249,7 +257,7 @@ impl BusDevice for ProxyDevice { buffer[0..data.len()].clone_from_slice(data); let reg_idx = reg_idx as u32; let offset = offset as u32; - self.sync_send(Command::WriteConfig { + self.send_no_result(Command::WriteConfig { reg_idx, offset, len, @@ -280,7 +288,7 @@ impl BusDevice for ProxyDevice { let mut buffer = [0u8; 8]; let len = data.len() as u32; buffer[0..data.len()].clone_from_slice(data); - self.sync_send(Command::Write { + self.send_no_result(Command::Write { len, offset, data: buffer, -- cgit 1.4.1