Skip to content

Commit 1a4af23

Browse files
Sudan Landgewearyzen
authored andcommitted
chore: make info_vcpu_states be available on x86
Since x86 now has vcpu states printable, make info_vcpu_states available on x86 as well. Signed-off-by: Sudan Landge <[email protected]>
1 parent d34f6d7 commit 1a4af23

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

docs/snapshotting/snapshot-editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Firecracker snapshot consists of 2 files:
9898
> ./snapshot-editor info-vmstate version --vmstate-path ./vmstate_file
9999
> ```
100100
101-
#### `vcpu-states` subcommand (aarch64 only)
101+
#### `vcpu-states` subcommand
102102
103103
> This command is used to print the vCPU states inside vmstate snapshot file.
104104
>

src/snapshot-editor/src/info.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub enum InfoVmStateSubCommand {
2626
vmstate_path: PathBuf,
2727
},
2828
/// Print info about vcpu states.
29-
#[cfg(target_arch = "aarch64")]
3029
VcpuStates {
3130
/// Path to the vmstate file.
3231
#[arg(short, long)]
@@ -43,7 +42,6 @@ pub enum InfoVmStateSubCommand {
4342
pub fn info_vmstate_command(command: InfoVmStateSubCommand) -> Result<(), InfoVmStateError> {
4443
match command {
4544
InfoVmStateSubCommand::Version { vmstate_path } => info(&vmstate_path, info_version)?,
46-
#[cfg(target_arch = "aarch64")]
4745
InfoVmStateSubCommand::VcpuStates { vmstate_path } => {
4846
info(&vmstate_path, info_vcpu_states)?
4947
}
@@ -74,23 +72,10 @@ fn info_version(_: &MicrovmState, version: u16) -> Result<(), InfoVmStateError>
7472
}
7573
}
7674

77-
#[cfg(target_arch = "aarch64")]
7875
fn info_vcpu_states(state: &MicrovmState, _: u16) -> Result<(), InfoVmStateError> {
7976
for (i, state) in state.vcpu_states.iter().enumerate() {
8077
println!("vcpu {i}:");
81-
println!("kvm_mp_state: {:#x}", state.mp_state.mp_state);
82-
println!("mpidr: {:#x}", state.mpidr);
83-
for reg in state.regs.iter() {
84-
println!(
85-
"{:#x} 0x{}",
86-
reg.id,
87-
reg.as_slice()
88-
.iter()
89-
.rev()
90-
.map(|b| format!("{b:x}"))
91-
.collect::<String>()
92-
);
93-
}
78+
println!("{state:#?}");
9479
}
9580
Ok(())
9681
}

src/vmm/src/vstate/vcpu/aarch64.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the THIRD-PARTY file.
77

8+
use std::fmt::Debug;
9+
810
use kvm_bindings::*;
911
use kvm_ioctls::*;
1012
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
@@ -250,7 +252,7 @@ impl KvmVcpu {
250252
}
251253

252254
/// Structure holding VCPU kvm state.
253-
#[derive(Debug, Default, Clone, Versionize)]
255+
#[derive(Default, Clone, Versionize)]
254256
pub struct VcpuState {
255257
/// Multiprocessing state.
256258
pub mp_state: kvm_bindings::kvm_mp_state,
@@ -271,6 +273,26 @@ pub struct VcpuState {
271273
pub kvi: Option<kvm_bindings::kvm_vcpu_init>,
272274
}
273275

276+
impl Debug for VcpuState {
277+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
278+
writeln!(f, "kvm_mp_state: {:#x}", self.mp_state.mp_state)?;
279+
writeln!(f, "mpidr: {:#x}", self.mpidr)?;
280+
for reg in self.regs.iter() {
281+
writeln!(
282+
f,
283+
"{:#x} 0x{}",
284+
reg.id,
285+
reg.as_slice()
286+
.iter()
287+
.rev()
288+
.map(|b| format!("{b:x}"))
289+
.collect::<String>()
290+
)?;
291+
}
292+
Ok(())
293+
}
294+
}
295+
274296
impl VcpuState {
275297
fn default_old_regs(_: u16) -> Vec<Aarch64RegisterOld> {
276298
Vec::default()

0 commit comments

Comments
 (0)