summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-10-10 14:28:35 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-14 23:59:49 +0000
commit8eb944b480c0b1e07ba24e02bb7e1955f3daf584 (patch)
tree7d674a0246dfd2f95c48e06445153666037b2d61
parent1fb6c0d01969ef9d2bd8785e4ad41d56d611fda1 (diff)
downloadcrosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.tar
crosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.tar.gz
crosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.tar.bz2
crosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.tar.lz
crosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.tar.xz
crosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.tar.zst
crosvm-8eb944b480c0b1e07ba24e02bb7e1955f3daf584.zip
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 <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1853970
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
-rw-r--r--devices/src/proxy.rs20
1 files 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<D: BusDevice, F: FnMut(&mut D)>(
             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<D: BusDevice, F: FnMut(&mut D)>(
             } => {
                 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<CommandResult> {
+    /// 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<CommandResult> {
+        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,