@@ -31,64 +31,20 @@ static BIOS_BLOB: &'static [u8] = include_bytes!("blob/bios.bin");
3131/// The location of the local apic in the guest address space
3232pub const GUEST_LOCAL_APIC_ADDR : GuestPhysAddr = GuestPhysAddr :: new ( 0xfee00000 ) ;
3333
34- static VIRTUAL_MACHINES : RoAfterInit < VirtualMachines > =
34+ static VIRTUAL_MACHINES : RoAfterInit < VirtualMachineSet > =
3535 RoAfterInit :: uninitialized ( ) ;
3636
3737/// The maximum numer of cores that can be assigned to a single VM
3838pub const MAX_PER_VM_CORE_COUNT : usize = 32 ;
3939
4040const MAX_PENDING_MSG : usize = 100 ;
4141
42- pub unsafe fn init_virtual_machines ( machines : VirtualMachines ) {
42+ pub unsafe fn init_virtual_machines ( machines : VirtualMachineSet ) {
4343 RoAfterInit :: init ( & VIRTUAL_MACHINES , machines) ;
4444}
4545
46- /// Get the virtual machine that owns the core with the given core id
47- ///
48- /// This method is unsafe as it should almost certainly not be used (use message
49- /// passing instead of directly accessing the remote VM).
50- pub unsafe fn get_vm_for_core_id (
51- core_id : percore:: CoreId ,
52- ) -> Option < Arc < VirtualMachine > > {
53- VIRTUAL_MACHINES . get_by_core_id ( core_id)
54- }
55-
56- pub fn send_vm_msg (
57- msg : VirtualMachineMsg ,
58- vmid : u32 ,
59- notify : bool ,
60- ) -> Result < ( ) > {
61- VIRTUAL_MACHINES . send_msg ( msg, vmid, notify)
62- }
63-
64- pub fn get_vm_bsp_core_id ( vmid : u32 ) -> Option < percore:: CoreId > {
65- VIRTUAL_MACHINES
66- . get_by_vm_id ( vmid)
67- . map ( |vm| vm. config . bsp_id ( ) )
68- }
69-
70- pub fn send_vm_msg_core (
71- msg : VirtualMachineMsg ,
72- core_id : percore:: CoreId ,
73- notify : bool ,
74- ) -> Result < ( ) > {
75- VIRTUAL_MACHINES . send_msg_core ( msg, core_id, notify)
76- }
77-
78- pub fn recv_msg ( ) -> Option < VirtualMachineMsg > {
79- VIRTUAL_MACHINES . resv_msg ( )
80- }
81-
82- pub fn recv_all_msgs ( ) -> impl Iterator < Item = VirtualMachineMsg > {
83- VIRTUAL_MACHINES . resv_all_msgs ( )
84- }
85-
86- pub fn max_vm_id ( ) -> u32 {
87- VIRTUAL_MACHINES . count ( )
88- }
89-
90- pub fn is_assigned_core_id ( core_id : percore:: CoreId ) -> bool {
91- VIRTUAL_MACHINES . is_assigned_core_id ( core_id)
46+ pub fn virtual_machines ( ) -> & ' static VirtualMachineSet {
47+ & * VIRTUAL_MACHINES
9248}
9349
9450pub enum VirtualMachineMsg {
@@ -106,12 +62,12 @@ struct VirtualMachineContext {
10662 msgqueue : RwLock < ArrayDeque < [ VirtualMachineMsg ; MAX_PENDING_MSG ] > > ,
10763}
10864
109- pub struct VirtualMachines {
65+ pub struct VirtualMachineSet {
11066 machine_count : u32 ,
11167 map : BTreeMap < percore:: CoreId , VirtualMachineContext > ,
11268}
11369
114- impl VirtualMachines {
70+ impl VirtualMachineSet {
11571 fn context_by_core_id (
11672 & self ,
11773 core_id : percore:: CoreId ,
@@ -140,7 +96,11 @@ impl VirtualMachines {
14096 self . map . contains_key ( & core_id)
14197 }
14298
143- pub fn get_by_core_id (
99+ /// Get the virtual machine that owns the core with the given core id
100+ ///
101+ /// This method is unsafe as it should almost certainly not be used (use message
102+ /// passing instead of directly accessing the remote VM).
103+ pub unsafe fn get_by_core_id (
144104 & self ,
145105 core_id : percore:: CoreId ,
146106 ) -> Option < Arc < VirtualMachine > > {
@@ -152,6 +112,10 @@ impl VirtualMachines {
152112 self . context_by_vm_id ( id) . map ( |context| context. vm . clone ( ) )
153113 }
154114
115+ pub fn bsp_core_id ( & self , vmid : u32 ) -> Option < percore:: CoreId > {
116+ self . get_by_vm_id ( vmid) . map ( |vm| vm. config . bsp_id ( ) )
117+ }
118+
155119 /// Send the given message to a specific core
156120 ///
157121 /// If 'notify' is true, an interrupt will be sent to the recipient.
@@ -204,7 +168,7 @@ impl VirtualMachines {
204168 vm_id : u32 ,
205169 notify : bool ,
206170 ) -> Result < ( ) > {
207- let vm_bsp = get_vm_bsp_core_id ( vm_id) . ok_or_else ( || {
171+ let vm_bsp = self . bsp_core_id ( vm_id) . ok_or_else ( || {
208172 Error :: InvalidValue ( format ! (
209173 "Unable to find BSP for VM id '{}'" ,
210174 vm_id
@@ -214,15 +178,15 @@ impl VirtualMachines {
214178 }
215179
216180 /// Receive any pending message for the current core
217- pub fn resv_msg ( & self ) -> Option < VirtualMachineMsg > {
181+ pub fn recv_msg ( & self ) -> Option < VirtualMachineMsg > {
218182 let context = self
219183 . context_by_core_id ( percore:: read_core_id ( ) )
220184 . expect ( "No VirtualMachineContext for apic id" ) ;
221185 context. msgqueue . write ( ) . pop_front ( )
222186 }
223187
224188 /// Receive all pending messages for the current core
225- pub fn resv_all_msgs ( & self ) -> impl Iterator < Item = VirtualMachineMsg > {
189+ pub fn recv_all_msgs ( & self ) -> impl Iterator < Item = VirtualMachineMsg > {
226190 let context = self
227191 . context_by_core_id ( percore:: read_core_id ( ) )
228192 . expect ( "No VirtualMachineContext for apic id" ) ;
@@ -262,8 +226,8 @@ impl VirtualMachineBuilder {
262226 self . map . get ( & core_id) . map ( |vm| vm. clone ( ) )
263227 }
264228
265- pub fn finalize ( self ) -> VirtualMachines {
266- VirtualMachines {
229+ pub fn finalize ( self ) -> VirtualMachineSet {
230+ VirtualMachineSet {
267231 machine_count : self . machine_count ,
268232 map : self
269233 . map
0 commit comments