-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor enhancement and bugfixes #151
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -239,6 +239,32 @@ impl Kvm { | |||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// Returns the "disable idle exiting" capability. | ||||||||||||||
/// | ||||||||||||||
/// The `KVM_CAP_X86_DISABLE_EXITS` capability provides userspace with per-VM capability | ||||||||||||||
/// to not intercept MWAIT/HLT/PAUSE/CSTATE, which means though instructions won't cause | ||||||||||||||
/// vm-exits and helps to improve latency in some workloads. | ||||||||||||||
/// | ||||||||||||||
/// # Example | ||||||||||||||
/// | ||||||||||||||
/// ``` | ||||||||||||||
/// # extern crate kvm_bindings; | ||||||||||||||
/// # use kvm_bindings::{KVM_X86_DISABLE_EXITS_HLT, KVM_X86_DISABLE_EXITS_PAUSE}; | ||||||||||||||
/// # use kvm_ioctls::Kvm; | ||||||||||||||
/// let kvm = Kvm::new().unwrap(); | ||||||||||||||
/// assert!(kvm.get_disable_exits() & KVM_X86_DISABLE_EXITS_HLT != 0); | ||||||||||||||
/// assert!(kvm.get_disable_exits() & KVM_X86_DISABLE_EXITS_PAUSE != 0); | ||||||||||||||
/// ``` | ||||||||||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||||||||||||||
pub fn get_disable_exits(&self) -> u32 { | ||||||||||||||
let x = self.check_extension_int(Cap::DisableExits); | ||||||||||||||
if x > 0 { | ||||||||||||||
x as u32 | ||||||||||||||
} else { | ||||||||||||||
0 | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be slightly simplified.
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||||||||||||||
fn get_cpuid(&self, kind: u64, num_entries: usize) -> Result<CpuId> { | ||||||||||||||
if num_entries > KVM_MAX_CPUID_ENTRIES { | ||||||||||||||
|
@@ -542,7 +568,9 @@ impl FromRawFd for Kvm { | |||||||||||||
mod tests { | ||||||||||||||
use super::*; | ||||||||||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||||||||||||||
use kvm_bindings::KVM_MAX_CPUID_ENTRIES; | ||||||||||||||
use kvm_bindings::{ | ||||||||||||||
KVM_MAX_CPUID_ENTRIES, KVM_X86_DISABLE_EXITS_HLT, KVM_X86_DISABLE_EXITS_PAUSE, | ||||||||||||||
}; | ||||||||||||||
use libc::{fcntl, FD_CLOEXEC, F_GETFD}; | ||||||||||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||||||||||||||
use vmm_sys_util::fam::FamStruct; | ||||||||||||||
|
@@ -598,6 +626,18 @@ mod tests { | |||||||||||||
assert!(kvm.get_nr_memslots() >= 32); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||||||||||||||
#[test] | ||||||||||||||
fn test_kvm_get_disable_exits() { | ||||||||||||||
let kvm = Kvm::new().unwrap(); | ||||||||||||||
let disable_exits = kvm.get_disable_exits(); | ||||||||||||||
|
||||||||||||||
if disable_exits != 0 { | ||||||||||||||
assert!(disable_exits & KVM_X86_DISABLE_EXITS_HLT != 0); | ||||||||||||||
assert!(disable_exits & KVM_X86_DISABLE_EXITS_PAUSE != 0); | ||||||||||||||
Comment on lines
+642
to
+643
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running this test on my laptop fails, should we check here for some capability before doing the asserts? Maybe this way we can also have a test case for |
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[test] | ||||||||||||||
fn test_create_vm() { | ||||||||||||||
let kvm = Kvm::new().unwrap(); | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
these