-
Notifications
You must be signed in to change notification settings - Fork 109
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
Open
jiangliu
wants to merge
2
commits into
rust-vmm:main
Choose a base branch
from
jiangliu:enhance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,9 +213,12 @@ impl Kvm { | |
/// assert!(kvm.get_max_vcpus() > 0); | ||
/// ``` | ||
pub fn get_max_vcpus(&self) -> usize { | ||
match self.check_extension_int(Cap::MaxVcpus) { | ||
0 => self.get_nr_vcpus(), | ||
x => x as usize, | ||
let v = self.check_extension_int(Cap::MaxVcpus); | ||
|
||
if v <= 0 { | ||
self.get_nr_vcpus() | ||
} else { | ||
v as usize | ||
} | ||
} | ||
|
||
|
@@ -233,9 +236,38 @@ impl Kvm { | |
/// assert!(kvm.get_max_vcpu_id() > 0); | ||
/// ``` | ||
pub fn get_max_vcpu_id(&self) -> usize { | ||
match self.check_extension_int(Cap::MaxVcpuId) { | ||
0 => self.get_max_vcpus(), | ||
x => x as usize, | ||
let v = self.check_extension_int(Cap::MaxVcpuId); | ||
|
||
if v <= 0 { | ||
self.get_max_vcpus() | ||
} else { | ||
v as usize | ||
} | ||
} | ||
|
||
/// 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 | ||
} | ||
} | ||
|
||
|
@@ -542,7 +574,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 +632,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(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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