@@ -7,21 +7,26 @@ mod vm_list;
7
7
8
8
use std:: os:: arceos:: api:: task:: { self , AxWaitQueueHandle } ;
9
9
10
- use core:: sync:: atomic:: AtomicUsize ;
11
- use core:: sync:: atomic:: Ordering ;
10
+ use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
12
11
13
12
use crate :: hal:: { AxVCpuHalImpl , AxVMHalImpl } ;
14
13
pub use timer:: init_percpu as init_timer_percpu;
15
14
15
+ /// The instantiated VM type.
16
16
pub type VM = axvm:: AxVM < AxVMHalImpl , AxVCpuHalImpl > ;
17
+ /// The instantiated VM ref type (by `Arc`).
17
18
pub type VMRef = axvm:: AxVMRef < AxVMHalImpl , AxVCpuHalImpl > ;
18
-
19
+ /// The instantiated VCpu ref type (by `Arc`).
19
20
pub type VCpuRef = axvm:: AxVCpuRef < AxVCpuHalImpl > ;
20
21
21
22
static VMM : AxWaitQueueHandle = AxWaitQueueHandle :: new ( ) ;
22
23
24
+ /// The number of running VMs. This is used to determine when to exit the VMM.
23
25
static RUNNING_VM_COUNT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
24
26
27
+ /// Initialize the VMM.
28
+ ///
29
+ /// This function creates the VM structures and sets up the primary VCpu for each VM.
25
30
pub fn init ( ) {
26
31
// Initialize guest VM according to config file.
27
32
config:: init_guest_vms ( ) ;
@@ -33,6 +38,7 @@ pub fn init() {
33
38
}
34
39
}
35
40
41
+ /// Start the VMM.
36
42
pub fn start ( ) {
37
43
info ! ( "VMM starting, booting VMs..." ) ;
38
44
for vm in vm_list:: get_vm_list ( ) {
@@ -47,5 +53,13 @@ pub fn start() {
47
53
}
48
54
49
55
// 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
+ ) ;
51
65
}
0 commit comments