Skip to content

Commit 0c9b89a

Browse files
aarkegzCopilot
andauthored
Support graceful single VM exit (#130)
* support graceful single vm exit * update axvm and x86_vcpu * fix doc typo in src/vmm/vcpus.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * update comment for clarity --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 44b0b6c commit 0c9b89a

File tree

5 files changed

+145
-65
lines changed

5 files changed

+145
-65
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::vmm::{VCpuRef, VMRef};
66
pub struct TaskExt {
77
/// The VM.
88
pub vm: VMRef,
9-
/// The virtual memory address space.
9+
/// The virtual CPU.
1010
pub vcpu: VCpuRef,
1111
}
1212

src/vmm/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn init_guest_vms() {
3030
AxVMCrateConfig::from_toml(raw_cfg_str).expect("Failed to resolve VM config");
3131
let vm_config = AxVMConfig::from(vm_create_config.clone());
3232

33-
info!("Creating VM [{}] {:?}", vm_config.id(), vm_config.name());
33+
info!("Creating VM[{}] {:?}", vm_config.id(), vm_config.name());
3434

3535
// Create VM.
3636
let vm = VM::new(vm_config).expect("Failed to create VM");

src/vmm/mod.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@ mod vm_list;
77

88
use std::os::arceos::api::task::{self, AxWaitQueueHandle};
99

10-
use core::sync::atomic::AtomicUsize;
11-
use core::sync::atomic::Ordering;
10+
use core::sync::atomic::{AtomicUsize, Ordering};
1211

1312
use crate::hal::{AxVCpuHalImpl, AxVMHalImpl};
1413
pub use timer::init_percpu as init_timer_percpu;
1514

15+
/// The instantiated VM type.
1616
pub type VM = axvm::AxVM<AxVMHalImpl, AxVCpuHalImpl>;
17+
/// The instantiated VM ref type (by `Arc`).
1718
pub type VMRef = axvm::AxVMRef<AxVMHalImpl, AxVCpuHalImpl>;
18-
19+
/// The instantiated VCpu ref type (by `Arc`).
1920
pub type VCpuRef = axvm::AxVCpuRef<AxVCpuHalImpl>;
2021

2122
static VMM: AxWaitQueueHandle = AxWaitQueueHandle::new();
2223

24+
/// The number of running VMs. This is used to determine when to exit the VMM.
2325
static RUNNING_VM_COUNT: AtomicUsize = AtomicUsize::new(0);
2426

27+
/// Initialize the VMM.
28+
///
29+
/// This function creates the VM structures and sets up the primary VCpu for each VM.
2530
pub fn init() {
2631
// Initialize guest VM according to config file.
2732
config::init_guest_vms();
@@ -33,6 +38,7 @@ pub fn init() {
3338
}
3439
}
3540

41+
/// Start the VMM.
3642
pub fn start() {
3743
info!("VMM starting, booting VMs...");
3844
for vm in vm_list::get_vm_list() {
@@ -47,5 +53,13 @@ pub fn start() {
4753
}
4854

4955
// Do not exit until all VMs are stopped.
50-
task::ax_wait_queue_wait_until(&VMM, || RUNNING_VM_COUNT.load(Ordering::Acquire) == 0, None);
56+
task::ax_wait_queue_wait_until(
57+
&VMM,
58+
|| {
59+
let vm_count = RUNNING_VM_COUNT.load(Ordering::Acquire);
60+
info!("a VM exited, current running VM count: {}", vm_count);
61+
vm_count == 0
62+
},
63+
None,
64+
);
5165
}

0 commit comments

Comments
 (0)