Skip to content

Commit

Permalink
chore: make info_vcpu_states be available on x86
Browse files Browse the repository at this point in the history
Since x86 now has vcpu states printable, make
info_vcpu_states available on x86 as well.

Signed-off-by: Sudan Landge <sudanl@amazon.com>
  • Loading branch information
Sudan Landge committed Oct 31, 2023
1 parent 4871f0f commit 7941118
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/snapshotting/snapshot-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Firecracker snapshot consists of 2 files:
> ./snapshot-editor info-vmstate version --vmstate-path ./vmstate_file
> ```
#### `vcpu-states` subcommand (aarch64 only)
#### `vcpu-states` subcommand

> This command is used to print the vCPU states inside vmstate snapshot file.
>
Expand Down
17 changes: 1 addition & 16 deletions src/snapshot-editor/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub enum InfoVmStateSubCommand {
vmstate_path: PathBuf,
},
/// Print info about vcpu states.
#[cfg(target_arch = "aarch64")]
VcpuStates {
/// Path to the vmstate file.
#[arg(short, long)]
Expand All @@ -43,7 +42,6 @@ pub enum InfoVmStateSubCommand {
pub fn info_vmstate_command(command: InfoVmStateSubCommand) -> Result<(), InfoVmStateError> {
match command {
InfoVmStateSubCommand::Version { vmstate_path } => info(&vmstate_path, info_version)?,
#[cfg(target_arch = "aarch64")]
InfoVmStateSubCommand::VcpuStates { vmstate_path } => {
info(&vmstate_path, info_vcpu_states)?
}
Expand Down Expand Up @@ -74,23 +72,10 @@ fn info_version(_: &MicrovmState, version: u16) -> Result<(), InfoVmStateError>
}
}

#[cfg(target_arch = "aarch64")]
fn info_vcpu_states(state: &MicrovmState, _: u16) -> Result<(), InfoVmStateError> {
for (i, state) in state.vcpu_states.iter().enumerate() {
println!("vcpu {i}:");
println!("kvm_mp_state: {:#x}", state.mp_state.mp_state);
println!("mpidr: {:#x}", state.mpidr);
for reg in state.regs.iter() {
println!(
"{:#x} 0x{}",
reg.id,
reg.as_slice()
.iter()
.rev()
.map(|b| format!("{b:x}"))
.collect::<String>()
);
}
println!("{state:#?}");

Check warning on line 78 in src/snapshot-editor/src/info.rs

View check run for this annotation

Codecov / codecov/patch

src/snapshot-editor/src/info.rs#L78

Added line #L78 was not covered by tests
}
Ok(())
}
Expand Down
22 changes: 21 additions & 1 deletion src/vmm/src/vstate/vcpu/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.

use std::fmt::Debug;
use kvm_bindings::*;
use kvm_ioctls::*;
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
Expand Down Expand Up @@ -250,7 +251,7 @@ impl KvmVcpu {
}

/// Structure holding VCPU kvm state.
#[derive(Debug, Default, Clone, Versionize)]
#[derive(Default, Clone, Versionize)]
pub struct VcpuState {
/// Multiprocessing state.
pub mp_state: kvm_bindings::kvm_mp_state,
Expand All @@ -271,6 +272,25 @@ pub struct VcpuState {
pub kvi: Option<kvm_bindings::kvm_vcpu_init>,
}

impl Debug for VcpuState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "kvm_mp_state: {:#x}\n", self.mp_state.mp_state)?;
write!(f, "mpidr: {:#x}\n", self.mpidr)?;
for reg in self.regs.iter() {
write!(
f, "{:#x} 0x{}\n",
reg.id,
reg.as_slice()
.iter()
.rev()
.map(|b| format!("{b:x}"))
.collect::<String>()
)?;

Check warning on line 288 in src/vmm/src/vstate/vcpu/aarch64.rs

View check run for this annotation

Codecov / codecov/patch

src/vmm/src/vstate/vcpu/aarch64.rs#L277-L288

Added lines #L277 - L288 were not covered by tests
}
Ok(())
}

Check warning on line 291 in src/vmm/src/vstate/vcpu/aarch64.rs

View check run for this annotation

Codecov / codecov/patch

src/vmm/src/vstate/vcpu/aarch64.rs#L290-L291

Added lines #L290 - L291 were not covered by tests
}

impl VcpuState {
fn default_old_regs(_: u16) -> Vec<Aarch64RegisterOld> {
Vec::default()
Expand Down

0 comments on commit 7941118

Please sign in to comment.