@@ -184,6 +184,31 @@ impl SleepCpu for SleepCpuNoStd {
184184 }
185185}
186186
187+ fn wakeup_interval ( ) -> Duration {
188+ #[ cfg( target_arch = "x86_64" ) ]
189+ {
190+ if is_virtualized ( ) {
191+ return Duration :: from_millis ( 1 ) ;
192+ }
193+ }
194+
195+ Duration :: from_micros ( 100 )
196+ }
197+
198+ #[ cfg( target_arch = "x86_64" ) ]
199+ fn is_virtualized ( ) -> bool {
200+ use core:: arch:: x86_64:: __cpuid;
201+
202+ if crate :: arch:: x86_64:: kvm:: pvclock:: available ( )
203+ || crate :: arch:: x86_64:: kvm:: cpuid_features ( ) . is_some ( )
204+ {
205+ return true ;
206+ }
207+
208+ let cpuid = unsafe { __cpuid ( 1 ) } ;
209+ ( cpuid. ecx & ( 1 << 31 ) ) != 0
210+ }
211+
187212/// initialize
188213pub ( super ) unsafe fn init ( ) {
189214 use alloc:: boxed:: Box ;
@@ -194,7 +219,7 @@ pub(super) unsafe fn init() {
194219
195220 let timer_callback = Box :: new ( |_irq| {
196221 // Re-enable timer.
197- crate :: timer:: reset ( core :: time :: Duration :: from_micros ( 100 ) ) ;
222+ crate :: timer:: reset ( wakeup_interval ( ) ) ;
198223 } ) ;
199224
200225 if crate :: interrupt:: register_handler ( irq, "local timer" . into ( ) , timer_callback) . is_ok ( ) {
@@ -219,6 +244,6 @@ pub fn reset_wakeup_timer() {
219244 let state = CPU_SLEEP_TAG [ cpu_id] . load ( Ordering :: Relaxed ) ;
220245
221246 if state == SleepTag :: Waiting as u32 || state == SleepTag :: Waking as u32 {
222- crate :: timer:: reset ( core :: time :: Duration :: from_micros ( 100 ) ) ;
247+ crate :: timer:: reset ( wakeup_interval ( ) ) ;
223248 }
224249}
0 commit comments