diff options
author | Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> | 2020-02-12 21:58:47 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-19 10:38:04 +0000 |
commit | 546f01cb96b0b2c688257371608c64db78b5d31a (patch) | |
tree | a47c679e7cfff5977b99af7b7444c05f30ebaccb /src/linux.rs | |
parent | 80a8d52fac83f5f6cd0187ebcbab6e1e5bd8586f (diff) | |
download | crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.gz crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.bz2 crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.lz crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.xz crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.zst crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.zip |
acpipm: implement suspend and resume mechanism
For suspend request from VM, will write suspend event and notify crosvm main process to pause VCPUs. For resume request, it is not from VM itself but by the resume command through crosvm socket. Resume request will notify the PM device to fill its wakeup registers with wakeup event so that when VCPUs start to run, VM can know there is wakeup from outside. BUG=chromium:1018674 TEST=cargo test -p devices Change-Id: I4724ffee10150065a62bf520076c16cbc70b7749 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035169 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r-- | src/linux.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/linux.rs b/src/linux.rs index ab6c64c..0f8a848 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -1638,6 +1638,7 @@ fn run_control( #[derive(PollToken)] enum Token { Exit, + Suspend, ChildSignal, CheckAvailableMemory, LowMemory, @@ -1652,6 +1653,7 @@ fn run_control( let poll_ctx = PollContext::build_with(&[ (&linux.exit_evt, Token::Exit), + (&linux.suspend_evt, Token::Suspend), (&sigchld_fd, Token::ChildSignal), ]) .map_err(Error::PollContextAdd)?; @@ -1744,6 +1746,14 @@ fn run_control( info!("vcpu requested shutdown"); break 'poll; } + Token::Suspend => { + info!("VM requested suspend"); + linux.suspend_evt.read().unwrap(); + run_mode_arc.set_and_notify(VmRunMode::Suspending); + for handle in &vcpu_handles { + let _ = handle.kill(SIGRTMIN() + 0); + } + } Token::ChildSignal => { // Print all available siginfo structs, then exit the loop. while let Some(siginfo) = sigchld_fd.read().map_err(Error::SignalFd)? { @@ -1879,6 +1889,17 @@ fn run_control( VmRunMode::Exiting => { break 'poll; } + VmRunMode::Running => { + if let VmRunMode::Suspending = + *run_mode_arc.mtx.lock() + { + linux.io_bus.notify_resume(); + } + run_mode_arc.set_and_notify(VmRunMode::Running); + for handle in &vcpu_handles { + let _ = handle.kill(SIGRTMIN() + 0); + } + } other => { run_mode_arc.set_and_notify(other); for handle in &vcpu_handles { @@ -1937,6 +1958,7 @@ fn run_control( for event in events.iter_hungup() { match event.token() { Token::Exit => {} + Token::Suspend => {} Token::ChildSignal => {} Token::CheckAvailableMemory => {} Token::LowMemory => {} |