@@ -239,6 +239,32 @@ impl Kvm {
239
239
}
240
240
}
241
241
242
+ /// Returns the "disable idle exiting" capability.
243
+ ///
244
+ /// The `KVM_CAP_X86_DISABLE_EXITS` capability provides userspace with per-VM capability
245
+ /// to not intercept MWAIT/HLT/PAUSE/CSTATE, which means though instructions won't cause
246
+ /// vm-exits and helps to improve latency in some workloads.
247
+ ///
248
+ /// # Example
249
+ ///
250
+ /// ```
251
+ /// # extern crate kvm_bindings;
252
+ /// # use kvm_bindings::{KVM_X86_DISABLE_EXITS_HLT, KVM_X86_DISABLE_EXITS_PAUSE};
253
+ /// # use kvm_ioctls::Kvm;
254
+ /// let kvm = Kvm::new().unwrap();
255
+ /// assert!(kvm.get_disable_exits() & KVM_X86_DISABLE_EXITS_HLT != 0);
256
+ /// assert!(kvm.get_disable_exits() & KVM_X86_DISABLE_EXITS_PAUSE != 0);
257
+ /// ```
258
+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
259
+ pub fn get_disable_exits ( & self ) -> u32 {
260
+ let x = self . check_extension_int ( Cap :: DisableExits ) ;
261
+ if x > 0 {
262
+ x as u32
263
+ } else {
264
+ 0
265
+ }
266
+ }
267
+
242
268
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
243
269
fn get_cpuid ( & self , kind : u64 , num_entries : usize ) -> Result < CpuId > {
244
270
if num_entries > KVM_MAX_CPUID_ENTRIES {
@@ -542,7 +568,9 @@ impl FromRawFd for Kvm {
542
568
mod tests {
543
569
use super :: * ;
544
570
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
545
- use kvm_bindings:: KVM_MAX_CPUID_ENTRIES ;
571
+ use kvm_bindings:: {
572
+ KVM_MAX_CPUID_ENTRIES , KVM_X86_DISABLE_EXITS_HLT , KVM_X86_DISABLE_EXITS_PAUSE ,
573
+ } ;
546
574
use libc:: { fcntl, FD_CLOEXEC , F_GETFD } ;
547
575
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
548
576
use vmm_sys_util:: fam:: FamStruct ;
@@ -598,6 +626,18 @@ mod tests {
598
626
assert ! ( kvm. get_nr_memslots( ) >= 32 ) ;
599
627
}
600
628
629
+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
630
+ #[ test]
631
+ fn test_kvm_get_disable_exits ( ) {
632
+ let kvm = Kvm :: new ( ) . unwrap ( ) ;
633
+ let disable_exits = kvm. get_disable_exits ( ) ;
634
+
635
+ if disable_exits != 0 {
636
+ assert ! ( disable_exits & KVM_X86_DISABLE_EXITS_HLT != 0 ) ;
637
+ assert ! ( disable_exits & KVM_X86_DISABLE_EXITS_PAUSE != 0 ) ;
638
+ }
639
+ }
640
+
601
641
#[ test]
602
642
fn test_create_vm ( ) {
603
643
let kvm = Kvm :: new ( ) . unwrap ( ) ;
0 commit comments