@@ -10,16 +10,19 @@ use std::os::arceos::{
1010 api:: task:: { AxCpuMask , ax_wait_queue_wake} ,
1111 modules:: {
1212 axhal:: { self , time:: busy_wait} ,
13- axtask,
13+ axtask:: { self , AxTaskExt } ,
1414 } ,
1515} ;
1616
1717use axaddrspace:: GuestPhysAddr ;
18- use axtask:: { AxTaskRef , TaskExtRef , TaskInner , WaitQueue } ;
18+ use axtask:: { AxTaskRef , TaskInner , WaitQueue } ;
1919use axvcpu:: { AxVCpuExitReason , VCpuState } ;
2020
21- use crate :: vmm:: { VCpuRef , VMRef , sub_running_vm_count} ;
22- use crate :: { hal:: arch:: inject_interrupt, task:: TaskExt } ;
21+ use crate :: { hal:: arch:: inject_interrupt, task:: VCpuTask } ;
22+ use crate :: {
23+ task:: AsVCpuTask ,
24+ vmm:: { VCpuRef , VMRef , sub_running_vm_count} ,
25+ } ;
2326
2427const KERNEL_STACK_SIZE : usize = 0x40000 ; // 256 KiB
2528
@@ -139,7 +142,8 @@ impl VMVCpus {
139142
140143 #[ allow( dead_code) ]
141144 fn notify_one ( & mut self ) {
142- info ! ( "Current wait queue length: {}" , self . wait_queue. len( ) ) ;
145+ // FIXME: `WaitQueue::len` is removed
146+ // info!("Current wait queue length: {}", self.wait_queue.len());
143147 self . wait_queue . notify_one ( false ) ;
144148 }
145149
@@ -250,12 +254,11 @@ pub(crate) fn cleanup_vm_vcpus(vm_id: usize) {
250254 idx,
251255 task. id_name( )
252256 ) ;
253- if let Some ( exit_code) = task. join ( ) {
254- debug ! (
255- "VM[{}] VCpu task[{}] exited with code: {}" ,
256- vm_id, idx, exit_code
257- ) ;
258- }
257+ let exit_code = task. join ( ) ;
258+ debug ! (
259+ "VM[{}] VCpu task[{}] exited with code: {}" ,
260+ vm_id, idx, exit_code
261+ ) ;
259262 }
260263
261264 info ! (
@@ -318,7 +321,7 @@ fn vcpu_on(vm: VMRef, vcpu_id: usize, entry_point: GuestPhysAddr, arg: usize) {
318321 vcpu. set_gpr ( 1 , arg) ;
319322 }
320323
321- let vcpu_task = alloc_vcpu_task ( vm . clone ( ) , vcpu) ;
324+ let vcpu_task = alloc_vcpu_task ( & vm , vcpu) ;
322325
323326 VM_VCPU_TASK_WAIT_QUEUE
324327 . get_mut ( & vm. id ( ) )
@@ -342,7 +345,7 @@ pub fn setup_vm_primary_vcpu(vm: VMRef) {
342345 let primary_vcpu_id = 0 ;
343346
344347 let primary_vcpu = vm. vcpu_list ( ) [ primary_vcpu_id] . clone ( ) ;
345- let primary_vcpu_task = alloc_vcpu_task ( vm . clone ( ) , primary_vcpu) ;
348+ let primary_vcpu_task = alloc_vcpu_task ( & vm , primary_vcpu) ;
346349 vm_vcpus. add_vcpu_task ( primary_vcpu_task) ;
347350
348351 VM_VCPU_TASK_WAIT_QUEUE . insert ( vm_id, vm_vcpus) ;
@@ -383,7 +386,7 @@ pub fn with_vcpu_task<T, F: FnOnce(&AxTaskRef) -> T>(
383386/// * The task associated with the VCpu is created with a kernel stack size of 256 KiB.
384387/// * The task is created in blocked state and added to the wait queue directly,
385388/// instead of being added to the ready queue. It will be woken up by notify_primary_vcpu().
386- fn alloc_vcpu_task ( vm : VMRef , vcpu : VCpuRef ) -> AxTaskRef {
389+ fn alloc_vcpu_task ( vm : & VMRef , vcpu : VCpuRef ) -> AxTaskRef {
387390 info ! ( "Spawning task for VM[{}] VCpu[{}]" , vm. id( ) , vcpu. id( ) ) ;
388391 let mut vcpu_task = TaskInner :: new (
389392 vcpu_run,
@@ -396,7 +399,8 @@ fn alloc_vcpu_task(vm: VMRef, vcpu: VCpuRef) -> AxTaskRef {
396399 }
397400
398401 // Use Weak reference in TaskExt to avoid keeping VM alive
399- vcpu_task. init_task_ext ( TaskExt :: from_vm_ref ( vm. clone ( ) , vcpu) ) ;
402+ let inner = VCpuTask :: new ( vm, vcpu) ;
403+ * vcpu_task. task_ext_mut ( ) = Some ( unsafe { AxTaskExt :: from_impl ( inner) } ) ;
400404
401405 info ! (
402406 "VCpu task {} created {:?}" ,
@@ -414,8 +418,8 @@ fn alloc_vcpu_task(vm: VMRef, vcpu: VCpuRef) -> AxTaskRef {
414418fn vcpu_run ( ) {
415419 let curr = axtask:: current ( ) ;
416420
417- let vm = curr. task_ext ( ) . vm ( ) ;
418- let vcpu = curr. task_ext ( ) . vcpu . clone ( ) ;
421+ let vm = curr. as_vcpu_task ( ) . vm ( ) ;
422+ let vcpu = curr. as_vcpu_task ( ) . vcpu . clone ( ) ;
419423 let vm_id = vm. id ( ) ;
420424 let vcpu_id = vcpu. id ( ) ;
421425
0 commit comments