Merge tag 'tracing-pull-request' of https://gitlab.com/stefanha/qemu into staging

Pull request

Tanish Desai and Paolo Bonzini's tracing Rust support.

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCgAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmjdSSIACgkQnKSrs4Gr
# c8h8hwf/RXawMzImGn3I2kTOUWAQ97+yY0UgtyO010K71gypBa2EBcPIVH0ZOsy0
# oT5pF2w7k0g83DXqupXiZO3yjSSmeGBXlOw8QS6D+FN0VpsdxrYJnvzVMqCckOrR
# 6wwM+fYYfCk/LwQFvjcMDdd6BSB/wUyMuBnh+fa8X9vxRL6CgMY7RpQd7YZ9JNtL
# PFQscu/K6zUARxwQ/DZTx5jYlW4rE5O4mq80CW2l1pgnyOH5vH/TySTKp0yX8eDO
# 5eoF7ttieOxxt6YobFak7EfWFvFuyp1j5NlWlyWKzhce1oSOAbaXnB1I61admRb3
# 7XrsTU0RjH6kp8ki4SZEoAh/HMw+4w==
# =myWt
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 01 Oct 2025 08:30:42 AM PDT
# gpg:                using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [unknown]
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* tag 'tracing-pull-request' of https://gitlab.com/stefanha/qemu:
  tracetool/syslog: add Rust support
  tracetool/ftrace: add Rust support
  tracetool/log: add Rust support
  log: change qemu_loglevel to unsigned
  tracetool/simple: add Rust support
  rust: pl011: add tracepoints
  rust: qdev: add minimal clock bindings
  rust: add trace crate
  tracetool: Add Rust format support
  tracetool/backend: remove redundant trace event checks
  tracetool: add CHECK_TRACE_EVENT_GET_STATE
  trace/ftrace: move snprintf+write from tracepoints to ftrace.c
  tracetool: add SPDX headers
  treewide: remove unnessary "coding" header
  tracetool: remove dead code
  tracetool: fix usage of try_import()

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson
2025-10-01 15:02:42 -07:00
62 changed files with 720 additions and 223 deletions
-2
View File
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# QEMU documentation build configuration file, created by
# sphinx-quickstart on Thu Jan 31 16:40:14 2019.
#
+1 -2
View File
@@ -1,5 +1,4 @@
/* -*- coding: utf-8; mode: css -*-
*
/*
* Sphinx HTML theme customization: read the doc
* Based on Linux Documentation/sphinx-static/theme_overrides.css
*/
+7 -7
View File
@@ -58,15 +58,15 @@ imx_serial_write(const char *chrname, uint64_t addr, uint64_t value) "%s:[0x%03"
imx_serial_put_data(const char *chrname, uint32_t value) "%s: 0x%" PRIx32
# pl011.c
pl011_irq_state(int level) "irq state %d"
pl011_read(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x value 0x%08x reg %s"
pl011_read_fifo(unsigned rx_fifo_used, size_t rx_fifo_depth) "RX FIFO read, used %u/%zu"
pl011_write(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x value 0x%08x reg %s"
pl011_can_receive(uint32_t lcr, unsigned rx_fifo_used, size_t rx_fifo_depth, unsigned rx_fifo_available) "LCR 0x%02x, RX FIFO used %u/%zu, can_receive %u chars"
pl011_fifo_rx_put(uint32_t c, unsigned read_count, size_t rx_fifo_depth) "RX FIFO push char [0x%02x] %d/%zu depth used"
pl011_irq_state(bool level) "irq state %d"
pl011_read(uint64_t addr, uint32_t value, const char *regname) "addr 0x%03" PRIx64 " value 0x%08x reg %s"
pl011_read_fifo(unsigned rx_fifo_used, unsigned rx_fifo_depth) "RX FIFO read, used %u/%u"
pl011_write(uint64_t addr, uint32_t value, const char *regname) "addr 0x%03" PRIx64 " value 0x%08x reg %s"
pl011_can_receive(uint32_t lcr, unsigned rx_fifo_used, unsigned rx_fifo_depth, unsigned rx_fifo_available) "LCR 0x%02x, RX FIFO used %u/%u, can_receive %u chars"
pl011_fifo_rx_put(uint32_t c, unsigned read_count, unsigned rx_fifo_depth) "RX FIFO push char [0x%02x] %d/%u depth used"
pl011_fifo_rx_full(void) "RX FIFO now full, RXFF set"
pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")"
pl011_receive(int size) "recv %d chars"
pl011_receive(size_t size) "recv %zd chars"
# cmsdk-apb-uart.c
cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
+2 -2
View File
@@ -19,9 +19,9 @@
#define QEMU_LOG_FOR_TRACE_H
/* Private global variable, don't use */
extern int qemu_loglevel;
extern unsigned qemu_loglevel;
#define LOG_TRACE (1 << 15)
#define LOG_TRACE (1u << 15)
/* Returns true if a bit is set in the current loglevel mask */
static inline bool qemu_loglevel_mask(int mask)
+22 -22
View File
@@ -14,30 +14,30 @@ bool qemu_log_enabled(void);
/* Returns true if qemu_log() will write somewhere other than stderr. */
bool qemu_log_separate(void);
#define CPU_LOG_TB_OUT_ASM (1 << 0)
#define CPU_LOG_TB_IN_ASM (1 << 1)
#define CPU_LOG_TB_OP (1 << 2)
#define CPU_LOG_TB_OP_OPT (1 << 3)
#define CPU_LOG_INT (1 << 4)
#define CPU_LOG_EXEC (1 << 5)
#define CPU_LOG_PCALL (1 << 6)
#define CPU_LOG_TB_CPU (1 << 8)
#define CPU_LOG_RESET (1 << 9)
#define LOG_UNIMP (1 << 10)
#define LOG_GUEST_ERROR (1 << 11)
#define CPU_LOG_MMU (1 << 12)
#define CPU_LOG_TB_NOCHAIN (1 << 13)
#define CPU_LOG_PAGE (1 << 14)
#define CPU_LOG_TB_OUT_ASM (1u << 0)
#define CPU_LOG_TB_IN_ASM (1u << 1)
#define CPU_LOG_TB_OP (1u << 2)
#define CPU_LOG_TB_OP_OPT (1u << 3)
#define CPU_LOG_INT (1u << 4)
#define CPU_LOG_EXEC (1u << 5)
#define CPU_LOG_PCALL (1u << 6)
#define CPU_LOG_TB_CPU (1u << 8)
#define CPU_LOG_RESET (1u << 9)
#define LOG_UNIMP (1u << 10)
#define LOG_GUEST_ERROR (1u << 11)
#define CPU_LOG_MMU (1u << 12)
#define CPU_LOG_TB_NOCHAIN (1u << 13)
#define CPU_LOG_PAGE (1u << 14)
/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
#define CPU_LOG_TB_OP_IND (1 << 16)
#define CPU_LOG_TB_FPU (1 << 17)
#define CPU_LOG_PLUGIN (1 << 18)
#define CPU_LOG_TB_OP_IND (1u << 16)
#define CPU_LOG_TB_FPU (1u << 17)
#define CPU_LOG_PLUGIN (1u << 18)
/* LOG_STRACE is used for user-mode strace logging. */
#define LOG_STRACE (1 << 19)
#define LOG_PER_THREAD (1 << 20)
#define CPU_LOG_TB_VPU (1 << 21)
#define LOG_TB_OP_PLUGIN (1 << 22)
#define LOG_INVALID_MEM (1 << 23)
#define LOG_STRACE (1u << 19)
#define LOG_PER_THREAD (1u << 20)
#define CPU_LOG_TB_VPU (1u << 21)
#define LOG_TB_OP_PLUGIN (1u << 22)
#define LOG_INVALID_MEM (1u << 23)
/* Lock/unlock output. */
+8
View File
@@ -159,6 +159,7 @@ dependencies = [
"migration",
"qom",
"system",
"trace",
"util",
]
@@ -258,6 +259,13 @@ dependencies = [
"util",
]
[[package]]
name = "trace"
version = "0.1.0"
dependencies = [
"libc",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
+1
View File
@@ -11,6 +11,7 @@ members = [
"hw/core",
"hw/char/pl011",
"hw/timer/hpet",
"trace",
"util",
"tests",
]
+1
View File
@@ -24,6 +24,7 @@ qom = { path = "../../../qom" }
chardev = { path = "../../../chardev" }
system = { path = "../../../system" }
hwcore = { path = "../../../hw/core" }
trace = { path = "../../../trace" }
[lints]
workspace = true
+1
View File
@@ -40,6 +40,7 @@ _libpl011_rs = static_library(
chardev_rs,
system_rs,
hwcore_rs,
trace_rs
],
)
+40 -17
View File
@@ -21,6 +21,8 @@ use util::{log::Log, log_mask_ln};
use crate::registers::{self, Interrupt, RegisterOffset};
::trace::include_trace!("hw_char");
// TODO: You must disable the UART before any of the control registers are
// reprogrammed. When the UART is disabled in the middle of transmission or
// reception, it completes the current character before stopping
@@ -208,13 +210,7 @@ impl PL011Registers {
(update, result)
}
pub(self) fn write(
&mut self,
offset: RegisterOffset,
value: u32,
char_backend: &CharBackend,
) -> bool {
// eprintln!("write offset {offset} value {value}");
pub(self) fn write(&mut self, offset: RegisterOffset, value: u32, device: &PL011State) -> bool {
use RegisterOffset::*;
match offset {
DR => return self.write_data_register(value),
@@ -229,9 +225,11 @@ impl PL011Registers {
}
IBRD => {
self.ibrd = value;
device.trace_baudrate_change(self.ibrd, self.fbrd);
}
FBRD => {
self.fbrd = value;
device.trace_baudrate_change(self.ibrd, self.fbrd);
}
LCR_H => {
let new_val: registers::LineControl = value.into();
@@ -242,7 +240,7 @@ impl PL011Registers {
}
let update = (self.line_control.send_break() != new_val.send_break()) && {
let break_enable = new_val.send_break();
let _ = char_backend.send_break(break_enable);
let _ = device.char_backend.send_break(break_enable);
self.loopback_break(break_enable)
};
self.line_control = new_val;
@@ -279,12 +277,13 @@ impl PL011Registers {
}
fn read_data_register(&mut self, update: &mut bool) -> u32 {
let depth = self.fifo_depth();
self.flags.set_receive_fifo_full(false);
let c = self.read_fifo[self.read_pos];
if self.read_count > 0 {
self.read_count -= 1;
self.read_pos = (self.read_pos + 1) & (self.fifo_depth() - 1);
self.read_pos = (self.read_pos + 1) & (depth - 1);
}
if self.read_count == 0 {
self.flags.set_receive_fifo_empty(true);
@@ -292,6 +291,7 @@ impl PL011Registers {
if self.read_count + 1 == self.read_trigger {
self.int_level &= !Interrupt::RX;
}
trace::trace_pl011_read_fifo(self.read_count, depth);
self.receive_status_error_clear.set_from_data(c);
*update = true;
u32::from(c)
@@ -447,7 +447,9 @@ impl PL011Registers {
self.read_fifo[slot] = value;
self.read_count += 1;
self.flags.set_receive_fifo_empty(false);
trace::trace_pl011_fifo_rx_put(value.into(), self.read_count, depth);
if self.read_count == depth {
trace::trace_pl011_fifo_rx_full();
self.flags.set_receive_fifo_full(true);
}
@@ -516,8 +518,21 @@ impl PL011State {
uninit_field_mut!(*this, clock).write(clock);
}
const fn clock_update(&self, _event: ClockEvent) {
/* pl011_trace_baudrate_change(s); */
pub fn trace_baudrate_change(&self, ibrd: u32, fbrd: u32) {
let divider = 4.0 / f64::from(ibrd * (FBRD_MASK + 1) + fbrd);
let hz = self.clock.hz();
let rate = if ibrd == 0 {
0
} else {
((hz as f64) * divider) as u32
};
trace::trace_pl011_baudrate_change(rate, hz, ibrd, fbrd);
}
fn clock_update(&self, _event: ClockEvent) {
let regs = self.regs.borrow();
let (ibrd, fbrd) = (regs.ibrd, regs.fbrd);
self.trace_baudrate_change(ibrd, fbrd)
}
pub fn clock_needed(&self) -> bool {
@@ -543,6 +558,7 @@ impl PL011State {
}
Ok(field) => {
let (update_irq, result) = self.regs.borrow_mut().read(field);
trace::trace_pl011_read(offset, result, c"");
if update_irq {
self.update();
self.char_backend.accept_input();
@@ -557,6 +573,7 @@ impl PL011State {
if let Ok(field) = RegisterOffset::try_from(offset) {
// qemu_chr_fe_write_all() calls into the can_receive
// callback, so handle writes before entering PL011Registers.
trace::trace_pl011_write(offset, value as u32, c"");
if field == RegisterOffset::DR {
// ??? Check if transmitter is enabled.
let ch: [u8; 1] = [value as u8];
@@ -565,10 +582,7 @@ impl PL011State {
let _ = self.char_backend.write_all(&ch);
}
update_irq = self
.regs
.borrow_mut()
.write(field, value as u32, &self.char_backend);
update_irq = self.regs.borrow_mut().write(field, value as u32, self);
} else {
log_mask_ln!(
Log::GuestError,
@@ -582,11 +596,19 @@ impl PL011State {
fn can_receive(&self) -> u32 {
let regs = self.regs.borrow();
// trace_pl011_can_receive(s->lcr, s->read_count, r);
regs.fifo_depth() - regs.read_count
let fifo_available = regs.fifo_depth() - regs.read_count;
trace::trace_pl011_can_receive(
regs.line_control.into(),
regs.read_count,
regs.fifo_depth(),
fifo_available,
);
fifo_available
}
fn receive(&self, buf: &[u8]) {
trace::trace_pl011_receive(buf.len());
let mut regs = self.regs.borrow_mut();
if regs.loopback_enabled() {
// In loopback mode, the RX input signal is internally disconnected
@@ -635,6 +657,7 @@ impl PL011State {
fn update(&self) {
let regs = self.regs.borrow();
let flags = regs.int_level & regs.int_enabled;
trace::trace_pl011_irq_state(flags != 0);
for (irq, i) in self.interrupts.iter().zip(IRQMASK) {
irq.set(flags.any_set(i));
}
+33
View File
@@ -411,6 +411,39 @@ where
impl<R: ObjectDeref> DeviceMethods for R where R::Target: IsA<DeviceState> {}
impl Clock {
pub const PERIOD_1SEC: u64 = bindings::CLOCK_PERIOD_1SEC;
pub const fn period_from_ns(ns: u64) -> u64 {
ns * Self::PERIOD_1SEC / 1_000_000_000
}
pub const fn period_from_hz(hz: u64) -> u64 {
if hz == 0 {
0
} else {
Self::PERIOD_1SEC / hz
}
}
pub const fn period_to_hz(period: u64) -> u64 {
if period == 0 {
0
} else {
Self::PERIOD_1SEC / period
}
}
pub const fn period(&self) -> u64 {
// SAFETY: Clock is returned by init_clock_in with zero value for period
unsafe { &*self.0.as_ptr() }.period
}
pub const fn hz(&self) -> u64 {
Self::period_to_hz(self.period())
}
}
unsafe impl ObjectType for Clock {
type Class = ObjectClass;
const TYPE_NAME: &'static CStr =
+1 -1
View File
@@ -34,7 +34,7 @@ subdir('system')
subdir('chardev')
subdir('hw/core')
subdir('tests')
subdir('trace')
subdir('hw')
cargo = find_program('cargo', required: false)
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "trace"
version = "0.1.0"
authors = ["Tanish Desai <tanishdesai37@gmail.com>"]
description = "QEMU tracing infrastructure support"
resolver = "2"
publish = false
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
[dependencies]
libc = { workspace = true }
[lints]
workspace = true
+19
View File
@@ -0,0 +1,19 @@
rust = import('rust')
lib_rs = configure_file(
input: 'src/lib.rs',
output: 'lib.rs',
configuration: {
'MESON_BUILD_ROOT': meson.project_build_root(),
})
_trace_rs = static_library(
'trace', # Library name,
lib_rs,
trace_rs_targets, # List of generated `.rs` custom targets
override_options: ['rust_std=2021', 'build.rust_std=2021'],
dependencies: [libc_rs],
rust_abi: 'rust',
)
trace_rs = declare_dependency(link_with: _trace_rs)
+39
View File
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-2.0-or-later
//! This crate provides macros that aid in using QEMU's tracepoint
//! functionality.
#[doc(hidden)]
/// Re-exported item to avoid adding libc as a dependency everywhere.
pub use libc::{syslog, LOG_INFO};
#[macro_export]
/// Define the trace-points from the named directory (which should have slashes
/// replaced by underscore characters) as functions in a module called `trace`.
///
/// ```ignore
/// ::trace::include_trace!("hw_char");
/// // ...
/// trace::trace_pl011_read_fifo_rx_full();
/// ```
macro_rules! include_trace {
($name:literal) => {
#[allow(
clippy::ptr_as_ptr,
clippy::cast_lossless,
clippy::used_underscore_binding
)]
mod trace {
#[cfg(not(MESON))]
include!(concat!(
env!("MESON_BUILD_ROOT"),
"/trace/trace-",
$name,
".rs"
));
#[cfg(MESON)]
include!(concat!("@MESON_BUILD_ROOT@/trace/trace-", $name, ".rs"));
}
};
}
+1 -1
View File
@@ -142,7 +142,7 @@ macro_rules! log_mask_ln {
let _: $crate::log::Log = $mask;
if unsafe {
($crate::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
($crate::bindings::qemu_loglevel & ($mask as std::os::raw::c_uint)) != 0
} {
_ = $crate::log::LogGuard::log_fmt(
format_args!("{}\n", format_args!($fmt $($args)*)));
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Analyse lock events and compute statistics
#
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This takes a crashing qtest trace and tries to remove superfluous operations

Some files were not shown because too many files have changed in this diff Show More