Skip to content

Commit

Permalink
xtask: allow QEMU tracing to be specified in per-platform config
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacWoods committed Sep 7, 2024
1 parent 36e27bb commit 2f38655
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Poplar.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ user_tasks = [
"virtio_gpu user/virtio_gpu",
"fb_console user/fb_console",
]
# Useful values: `virtio_*`, `usb_ehci_*`, `usb_packet_*`, `usb_*`
qemu_trace = ""

[mq_pro]
release = true
Expand Down
5 changes: 4 additions & 1 deletion tools/xtask/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Config {
pub release: bool,
pub kernel_features: Vec<String>,
pub user_tasks: Vec<UserTask>,
pub qemu_trace: Option<String>,
}

#[derive(Clone, Debug)]
Expand All @@ -36,6 +37,7 @@ pub struct PlatformInfo {
pub release: Option<bool>,
pub kernel_features: Option<Vec<String>>,
pub user_tasks: Option<Vec<String>>,
pub qemu_trace: Option<String>,
}

impl Config {
Expand Down Expand Up @@ -78,8 +80,9 @@ impl Config {
UserTask { name, source_dir }
})
.collect();
let qemu_trace = platform_info.and_then(|info| info.qemu_trace.clone());

Config { platform, release, kernel_features, user_tasks }
Config { platform, release, kernel_features, user_tasks, qemu_trace }
}
}

Expand Down
2 changes: 2 additions & 0 deletions tools/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn main() -> Result<()> {
.debug_int_firehose(flags.debug_int_firehose)
.debug_mmu_firehose(flags.debug_mmu_firehose)
.debug_cpu_firehose(flags.debug_cpu_firehose)
.trace(config.qemu_trace)
.run(),
Platform::Rv64Virt => {
let ramdisk = dist_result.build_ramdisk();
Expand All @@ -67,6 +68,7 @@ fn main() -> Result<()> {
.ramdisk(Some(ramdisk))
.open_display(flags.display)
.debug_int_firehose(flags.debug_int_firehose)
.trace(config.qemu_trace)
.run()
}
_ => {
Expand Down
10 changes: 10 additions & 0 deletions tools/xtask/src/riscv/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct RunQemuRiscV {

pub open_display: bool,
pub debug_int_firehose: bool,
pub trace: Option<String>,
}

impl RunQemuRiscV {
Expand All @@ -21,6 +22,7 @@ impl RunQemuRiscV {
disk_image,
open_display: false,
debug_int_firehose: false,
trace: None,
}
}

Expand All @@ -41,6 +43,10 @@ impl RunQemuRiscV {
Self { debug_int_firehose: enabled, ..self }
}

pub fn trace(self, trace: Option<String>) -> Self {
Self { trace, ..self }
}

pub fn run(self) -> Result<()> {
let mut qemu = Command::new("qemu-system-riscv64");

Expand Down Expand Up @@ -99,6 +105,10 @@ impl RunQemuRiscV {
qemu.args(&["-monitor", "tcp:127.0.0.1:55555,server,nowait"]);
}

if let Some(trace) = self.trace {
qemu.args(&["--trace", &trace]);
}

println!("QEMU command: {:?}", qemu);
qemu.status()
.wrap_err("Failed to invoke qemu-system-riscv")?
Expand Down
10 changes: 10 additions & 0 deletions tools/xtask/src/x64/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct RunQemuX64 {
pub debug_mmu_firehose: bool,
/// Passes `-d cpu` to QEMU. Note that this disables KVM even if `kvm` is set.
pub debug_cpu_firehose: bool,
pub trace: Option<String>,

/*
* Firmware
Expand All @@ -44,6 +45,7 @@ impl RunQemuX64 {
debug_int_firehose: false,
debug_mmu_firehose: false,
debug_cpu_firehose: false,
trace: None,

ovmf_dir: PathBuf::from("bundled/ovmf/"),
ovmf_debugcon_to_file: false,
Expand All @@ -68,6 +70,10 @@ impl RunQemuX64 {
Self { debug_cpu_firehose: enabled, ..self }
}

pub fn trace(self, trace: Option<String>) -> Self {
Self { trace, ..self }
}

fn use_kvm(&self) -> bool {
self.kvm && !(self.debug_int_firehose || self.debug_mmu_firehose || self.debug_cpu_firehose)
}
Expand Down Expand Up @@ -103,6 +109,10 @@ impl RunQemuX64 {
// qemu.args(&["-smp", &self.cpus.to_string()]);
qemu.args(&["-m", &self.ram.to_string()]);

if let Some(trace) = self.trace {
qemu.args(&["--trace", &trace]);
}

// Emit serial on both stdio and to a file
qemu.args(&["-chardev", "stdio,id=char0,logfile=qemu_serial_x64.log"]);
qemu.args(&["-serial", "chardev:char0"]);
Expand Down

0 comments on commit 2f38655

Please sign in to comment.