Increase the priority of microdroid_launcher process


When capturing traces inside Microdroid VM (e.g. by using perfetto), the tracing daemons and adbd / sh processes sometimes can prevent the payload from running, which skews the results of the tracing.

This patch attempts to minimize the effect of tracing by increasing the priority of the microdroid_launcher process. This is achieved by setting the nice value to -20 (lowest possible).

Test: boot microdroid & check nice value of microdroid_launcher
Change-Id: I0d1c41a803d41f11c1c58f5b85d3b8aa9eb8bca8
diff --git a/guest/microdroid_manager/src/main.rs b/guest/microdroid_manager/src/main.rs
index 4537834..a95bcb2 100644
--- a/guest/microdroid_manager/src/main.rs
+++ b/guest/microdroid_manager/src/main.rs
@@ -710,7 +710,21 @@
     info!("notifying payload started");
     service.notifyPayloadStarted()?;
 
-    let exit_status = command.spawn()?.wait()?;
+    let mut payload_process = command.spawn().context("failed to spawn payload process")?;
+    info!("payload pid = {:?}", payload_process.id());
+
+    // SAFETY: setpriority doesn't take any pointers
+    unsafe {
+        let ret = libc::setpriority(libc::PRIO_PROCESS, payload_process.id(), -20);
+        if ret != 0 {
+            error!(
+                "failed to adjust priority of the payload: {:#?}",
+                std::io::Error::last_os_error()
+            );
+        }
+    }
+
+    let exit_status = payload_process.wait()?;
     match exit_status.code() {
         Some(exit_code) => Ok(exit_code),
         None => Err(match exit_status.signal() {