From nobody Thu Nov 20 12:22:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1763585582; cv=none; d=zohomail.com; s=zohoarc; b=cwADTCL3v4jpNG80udCgufU5ZpuOc/orBFmPo29mN25WsuLzYUQKtGV06DNXh/G3uU001BgNLtl8YN0TVNLDfDu4X2cb6L7pQ1YbS6/Fnhc5F3FLoyI9wfHZ5pP7m1TwwaJk84Nm+p2tdXxH69joCWLAVnrtALzDxGRRgDKPNpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763585582; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v4QLZ0wocEbh/vect8t4Ip3APFKkZMxf5onqifsOVDY=; b=VC56lvVB+tD+WIqDlxo7kkW0b+T6gRFX8eOU5UZIbgz8ECkBTQlxEuRQioNIveT3mW9V9gTtYexEZ7jZjml+OrWFN3ddN/8TX9903zAxDRWgdwdnLmpmNAhzYoN8BTQNvCb4uNLPfZYECwbB2uoxB57CT+UI+ifN+LhT11HrW7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1763585582439734.794802865379; Wed, 19 Nov 2025 12:53:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLp9x-0007sp-G0; Wed, 19 Nov 2025 15:52:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLp9v-0007rs-4Z for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLp9t-000235-Fx for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:10 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-zAJFcfKkOLq-3hg4o0CB3A-1; Wed, 19 Nov 2025 15:52:06 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D843E19560A7; Wed, 19 Nov 2025 20:52:04 +0000 (UTC) Received: from localhost (unknown [10.2.16.175]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E36D919540E7; Wed, 19 Nov 2025 20:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763585527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v4QLZ0wocEbh/vect8t4Ip3APFKkZMxf5onqifsOVDY=; b=F6n3E9+88IsyXWxB3X2e4Ubsm39ydfWTRWDm4H/ABFutjAPKRP3Udbxk6xEzgmNQ7hygyp 56zjJe6JaYjY5LUFAjflkMCeGXZFjSWopHfHS+ngeBVmcPKyyD37lSu48DgH6HdyVqmmXt csLeFYS0pr7Xp5/w3/42VLVGeyvBxCI= X-MC-Unique: zAJFcfKkOLq-3hg4o0CB3A-1 X-Mimecast-MFC-AGG-ID: zAJFcfKkOLq-3hg4o0CB3A_1763585525 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-rust@nongnu.org, Mads Ynddal , Thomas Huth , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Josh Stone , Stefan Hajnoczi Subject: [PATCH v2 1/4] hpet: remove unused trace events Date: Wed, 19 Nov 2025 15:51:57 -0500 Message-ID: <20251119205200.173170-2-stefanha@redhat.com> In-Reply-To: <20251119205200.173170-1-stefanha@redhat.com> References: <20251119205200.173170-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1763585586220019100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Hajnoczi --- hw/timer/trace-events | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/timer/trace-events b/hw/timer/trace-events index 2bb51f95ea..f3fca6fc9b 100644 --- a/hw/timer/trace-events +++ b/hw/timer/trace-events @@ -112,7 +112,6 @@ sh_timer_write(uint64_t offset, uint64_t value) "tmu012= _write 0x%" PRIx64 " 0x%0 =20 # hpet.c hpet_timer_id_out_of_range(uint8_t timer_id) "timer id out of range: 0x%" = PRIx8 -hpet_invalid_hpet_cfg(uint8_t reg_off) "invalid HPET_CFG + %u" PRIx8 hpet_ram_read(uint64_t addr) "enter hpet_ram_readl at 0x%" PRIx64 hpet_ram_read_reading_counter(uint8_t reg_off, uint64_t cur_tick) "reading= counter + %" PRIu8 " =3D 0x%" PRIx64 hpet_ram_read_invalid(void) "invalid hpet_ram_readl" @@ -123,4 +122,3 @@ hpet_ram_write_tn_cmp(uint8_t reg_off) "hpet_ram_writel= HPET_TN_CMP + %" PRIu8 hpet_ram_write_invalid_tn_cmp(void) "invalid HPET_TN_CMP + 4 write" hpet_ram_write_invalid(void) "invalid hpet_ram_writel" hpet_ram_write_counter_write_while_enabled(void) "Writing counter while HP= ET enabled!" -hpet_ram_write_counter_written(uint8_t reg_off, uint64_t value, uint64_t c= ounter) "HPET counter + %" PRIu8 "written. crt =3D 0x%" PRIx64 " -> 0x%" PR= Ix64 --=20 2.51.1 From nobody Thu Nov 20 12:22:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1763585565; cv=none; d=zohomail.com; s=zohoarc; b=RdvkwnJ2JYFnOzO44hcfaWHHHCVztdDCdLu4f9shbf/V/chdENEzs02DepnG7FCwxOzw4QX6UNifC3Kajws13CyMABF04VevIuyxdP6HeerXBh4PZTG+TvhFtzy3q66/50/u0EhH52sgiBHDVAJI4RCumHbEyi3GmFijMOSOLkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763585565; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s4NQAtf7TbdXclJV1DiwxB4R+oO7azwdGGte+itj1sw=; b=U0MXs7Ws0YIE7s0TYo9nMItl1yOU9DGTtmfnusa/c9XCkPrA0lvsQatjnCciIhsKbDGGYE2Y6F30Dgz4DhADFILAH6N+FuMGMfmw6OAcW/HIEMd596ZopCIN+2HcLvJhqGeDbv9FpSxu5yh/LfnDf60lAE90STbuw4frjqIWQxk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1763585565304750.9691552014693; Wed, 19 Nov 2025 12:52:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLpA0-0007wT-JR; Wed, 19 Nov 2025 15:52:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLp9z-0007uo-7o for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLp9x-00023x-GD for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:15 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54--GV5gDRJOi2_06dSrp_rdw-1; Wed, 19 Nov 2025 15:52:09 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 07BEF19560AF; Wed, 19 Nov 2025 20:52:07 +0000 (UTC) Received: from localhost (unknown [10.2.16.175]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 75B5219540E7; Wed, 19 Nov 2025 20:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763585532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s4NQAtf7TbdXclJV1DiwxB4R+oO7azwdGGte+itj1sw=; b=iDMwddBE67SMgnGCwkHpJATZGH8pxr4tREz6hWGkF//XrHXe0ld7yQjy4XB28cYZaUhCJi 1C44JAxlNfUDn8aJ4CbNWKU0B5OEaXHrvD2T8XlLtl4YQyNL/UcdV4X18iKsyLm6OeEpJT YVFFE+5RqtFFEDq9EmQRDIlj/g+dJsY= X-MC-Unique: -GV5gDRJOi2_06dSrp_rdw-1 X-Mimecast-MFC-AGG-ID: -GV5gDRJOi2_06dSrp_rdw_1763585527 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-rust@nongnu.org, Mads Ynddal , Thomas Huth , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Josh Stone , Stefan Hajnoczi Subject: [PATCH v2 2/4] rust/hpet: add trace events Date: Wed, 19 Nov 2025 15:51:58 -0500 Message-ID: <20251119205200.173170-3-stefanha@redhat.com> In-Reply-To: <20251119205200.173170-1-stefanha@redhat.com> References: <20251119205200.173170-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1763585568245019100 Content-Type: text/plain; charset="utf-8" Implement the same trace events as the C implementation. Notes: - Keep order of hpet_ram_write_invalid_tn_cmp and hpet_ram_write_tn_cmp the same as the C implementation. - Put hpet_ram_write_timer_id in HPETTimer::write() instead of HPETState::decode() so that reads can be excluded. Signed-off-by: Stefan Hajnoczi --- rust/hw/timer/hpet/Cargo.toml | 1 + rust/hw/timer/hpet/meson.build | 1 + rust/hw/timer/hpet/src/device.rs | 45 +++++++++++++++++++------------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/rust/hw/timer/hpet/Cargo.toml b/rust/hw/timer/hpet/Cargo.toml index f781b28d8b..5567eefda4 100644 --- a/rust/hw/timer/hpet/Cargo.toml +++ b/rust/hw/timer/hpet/Cargo.toml @@ -18,6 +18,7 @@ bql =3D { path =3D "../../../bql" } qom =3D { path =3D "../../../qom" } system =3D { path =3D "../../../system" } hwcore =3D { path =3D "../../../hw/core" } +trace =3D { path =3D "../../../trace" } =20 [lints] workspace =3D true diff --git a/rust/hw/timer/hpet/meson.build b/rust/hw/timer/hpet/meson.build index bb64b96672..465995bb5a 100644 --- a/rust/hw/timer/hpet/meson.build +++ b/rust/hw/timer/hpet/meson.build @@ -11,6 +11,7 @@ _libhpet_rs =3D static_library( qom_rs, system_rs, hwcore_rs, + trace_rs ], ) =20 diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index 3564aa79c6..90b0ae927c 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -32,6 +32,8 @@ =20 use crate::fw_cfg::HPETFwConfig; =20 +::trace::include_trace!("hw_timer"); + /// Register space for each timer block (`HPET_BASE` is defined in hpet.h). const HPET_REG_SPACE_LEN: u64 =3D 0x400; // 1024 bytes =20 @@ -402,7 +404,8 @@ fn del_timer(&mut self) { =20 /// Configuration and Capability Register fn set_tn_cfg_reg(&mut self, shift: u32, len: u32, val: u64) { - // TODO: Add trace point - trace_hpet_ram_write_tn_cfg(addr & 4) + trace::trace_hpet_ram_write_tn_cfg((shift / 8).try_into().unwrap()= ); + let old_val: u64 =3D self.config; let mut new_val: u64 =3D old_val.deposit(shift, len, val); new_val =3D hpet_fixup_reg(new_val, old_val, HPET_TN_CFG_WRITE_MAS= K); @@ -435,17 +438,18 @@ fn set_tn_cmp_reg(&mut self, shift: u32, len: u32, va= l: u64) { let mut length =3D len; let mut value =3D val; =20 - // TODO: Add trace point - trace_hpet_ram_write_tn_cmp(addr & 4) if self.is_32bit_mod() { // High 32-bits are zero, leave them untouched. if shift !=3D 0 { - // TODO: Add trace point - trace_hpet_ram_write_invalid_tn= _cmp() + trace::trace_hpet_ram_write_invalid_tn_cmp(); return; } length =3D 64; value =3D u64::from(value as u32); // truncate! } =20 + trace::trace_hpet_ram_write_tn_cmp((shift / 8).try_into().unwrap()= ); + if !self.is_periodic() || self.is_valset_enabled() { self.cmp =3D self.cmp.deposit(shift, length, value); } @@ -512,6 +516,9 @@ const fn read(&self, reg: TimerRegister) -> u64 { =20 fn write(&mut self, reg: TimerRegister, value: u64, shift: u32, len: u= 32) { use TimerRegister::*; + + trace::trace_hpet_ram_write_timer_id(self.index as u64); + match reg { CFG =3D> self.set_tn_cfg_reg(shift, len, value), CMP =3D> self.set_tn_cmp_reg(shift, len, value), @@ -689,15 +696,13 @@ fn set_int_status_reg(&self, shift: u32, _len: u32, v= al: u64) { /// Main Counter Value Register fn set_counter_reg(&self, shift: u32, len: u32, val: u64) { if self.is_hpet_enabled() { - // TODO: Add trace point - - // trace_hpet_ram_write_counter_write_while_enabled() - // // HPET spec says that writes to this register should only be // done while the counter is halted. So this is an undefined // behavior. There's no need to forbid it, but when HPET is // enabled, the changed counter value will not affect the // tick count (i.e., the previously calculated offset will // not be changed as well). + trace::trace_hpet_ram_write_counter_write_while_enabled(); } self.counter .set(self.counter.get().deposit(shift, len, val)); @@ -787,11 +792,10 @@ fn decode(&self, mut addr: hwaddr, size: u32) -> HPET= AddrDecode<'_> { } else { let timer_id: usize =3D ((addr - 0x100) / 0x20) as usize; if timer_id < self.num_timers { - // TODO: Add trace point - trace_hpet_ram_[read|write]_tim= er_id(timer_id) TimerRegister::try_from(addr & 0x18) .map(|reg| HPETRegister::Timer(&self.timers[timer_id],= reg)) } else { - // TODO: Add trace point - trace_hpet_timer_id_out_of_ran= ge(timer_id) + trace::trace_hpet_timer_id_out_of_range(timer_id.try_into(= ).unwrap()); Err(addr) } }; @@ -803,7 +807,8 @@ fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAd= drDecode<'_> { } =20 fn read(&self, addr: hwaddr, size: u32) -> u64 { - // TODO: Add trace point - trace_hpet_ram_read(addr) + trace::trace_hpet_ram_read(addr); + let HPETAddrDecode { shift, reg, .. } =3D self.decode(addr, size); =20 use GlobalRegister::*; @@ -814,16 +819,21 @@ fn read(&self, addr: hwaddr, size: u32) -> u64 { Global(CFG) =3D> self.config.get(), Global(INT_STATUS) =3D> self.int_status.get(), Global(COUNTER) =3D> { - // TODO: Add trace point - // trace_hpet_ram_read_reading_counter(addr & 4, cur_tick) - if self.is_hpet_enabled() { + let cur_tick =3D if self.is_hpet_enabled() { self.get_ticks() } else { self.counter.get() - } + }; + + trace::trace_hpet_ram_read_reading_counter( + (addr & 4) as u8, + cur_tick + ); + + cur_tick } Unknown(_) =3D> { - // TODO: Add trace point- trace_hpet_ram_read_invalid() + trace::trace_hpet_ram_read_invalid(); 0 } }) >> shift @@ -832,7 +842,8 @@ fn read(&self, addr: hwaddr, size: u32) -> u64 { fn write(&self, addr: hwaddr, value: u64, size: u32) { let HPETAddrDecode { shift, len, reg } =3D self.decode(addr, size); =20 - // TODO: Add trace point - trace_hpet_ram_write(addr, value) + trace::trace_hpet_ram_write(addr, value); + use GlobalRegister::*; use HPETRegister::*; match reg { @@ -841,9 +852,7 @@ fn write(&self, addr: hwaddr, value: u64, size: u32) { Global(CFG) =3D> self.set_cfg_reg(shift, len, value), Global(INT_STATUS) =3D> self.set_int_status_reg(shift, len, va= lue), Global(COUNTER) =3D> self.set_counter_reg(shift, len, value), - Unknown(_) =3D> { - // TODO: Add trace point - trace_hpet_ram_write_invalid() - } + Unknown(_) =3D> trace::trace_hpet_ram_write_invalid(), } } =20 --=20 2.51.1 From nobody Thu Nov 20 12:22:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1763585577; cv=none; d=zohomail.com; s=zohoarc; b=ZWMo2GcAv3AvPtdq21mcDYjuSIioMIavGZ52vrlXfrU1IqWA42fcQfMD5ex7veaCsgO2R7yRLGiLfUv6nmpiNp2Mt/8UggcslFxDCkfB19oNqyDB3XBFO9lKBvp5UFne0pRN1crH8woswBzpPG7ijlSi/8lFacODi82Eao7j8KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763585577; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vcOebe0Iu/lIHqeur69z3jxy/Az6bB+SgVoQoceCf5o=; b=Jx0VhMDQ3PQEjifxlfrdG1d+wIBbVgBXKKHEZnM3YQA9KELPikBRrV9cp7O4JRPSDzUPzCpbGH5Jletm1eeCQk1i44Y/6MYa7/dZnXJfwjVOQVszw190gNgAX0s8ctxzf3a+XXtIi+0U+UGaboVhnfBUW1fi8x58YIs1hmsn2yU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1763585577255948.5178416644211; Wed, 19 Nov 2025 12:52:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLpA3-0007xc-8F; Wed, 19 Nov 2025 15:52:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLpA1-0007wz-Sh for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLpA0-00024r-5K for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:17 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-235-M3mthLefNmWmEIbJz38P6A-1; Wed, 19 Nov 2025 15:52:10 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 07B731800250; Wed, 19 Nov 2025 20:52:09 +0000 (UTC) Received: from localhost (unknown [10.2.16.175]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BB39180049F; Wed, 19 Nov 2025 20:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763585535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vcOebe0Iu/lIHqeur69z3jxy/Az6bB+SgVoQoceCf5o=; b=fXO7OF1ZKvwi7mubmE5k6eiNi7Bz2N0PVw6toDjQOoZisXLTNNmplcv8lrDjLdKgxAUMLi cKX48bx5pqvDZR0l/PMa3G43FYqceKxMPBk+eatY0d3h67whwkI6zzaCC+tvxJI5gXyhbT AA3tcwKB+dcXXEUjGurp3FiXXPCfjeY= X-MC-Unique: M3mthLefNmWmEIbJz38P6A-1 X-Mimecast-MFC-AGG-ID: M3mthLefNmWmEIbJz38P6A_1763585529 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-rust@nongnu.org, Mads Ynddal , Thomas Huth , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Josh Stone , Stefan Hajnoczi Subject: [PATCH v2 3/4] subprojects: add probe crate Date: Wed, 19 Nov 2025 15:51:59 -0500 Message-ID: <20251119205200.173170-4-stefanha@redhat.com> In-Reply-To: <20251119205200.173170-1-stefanha@redhat.com> References: <20251119205200.173170-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1763585578567018900 Content-Type: text/plain; charset="utf-8" The probe crate (https://crates.io/crates/probe) provides a probe!() macro that defines SystemTap SDT probes on Linux hosts or does nothing on other host OSes. This crate will be used to implement DTrace support for Rust. Signed-off-by: Stefan Hajnoczi --- rust/meson.build | 2 ++ scripts/archive-source.sh | 1 + scripts/make-release | 2 +- subprojects/.gitignore | 1 + .../packagefiles/probe-0.5-rs/meson.build | 22 +++++++++++++++++++ subprojects/probe-0.5-rs.wrap | 7 ++++++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/probe-0.5-rs/meson.build create mode 100644 subprojects/probe-0.5-rs.wrap diff --git a/rust/meson.build b/rust/meson.build index 76e10699b3..afbeeeb47a 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -4,6 +4,7 @@ subproject('bilge-impl-0.2-rs', required: true) subproject('foreign-0.3-rs', required: true) subproject('glib-sys-0.21-rs', required: true) subproject('libc-0.2-rs', required: true) +subproject('probe-0.5-rs', required: true) =20 anyhow_rs =3D dependency('anyhow-1-rs') bilge_rs =3D dependency('bilge-0.2-rs') @@ -11,6 +12,7 @@ bilge_impl_rs =3D dependency('bilge-impl-0.2-rs') foreign_rs =3D dependency('foreign-0.3-rs') glib_sys_rs =3D dependency('glib-sys-0.21-rs') libc_rs =3D dependency('libc-0.2-rs') +probe_rs =3D dependency('probe-0.5-rs') =20 subproject('proc-macro2-1-rs', required: true) subproject('quote-1-rs', required: true) diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index 8f97b19a08..a37acab524 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -41,6 +41,7 @@ subprojects=3D( keycodemapdb libc-0.2-rs libvfio-user + probe-0.5-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs proc-macro2-1-rs diff --git a/scripts/make-release b/scripts/make-release index bc1b43caa2..5f54b0e793 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -42,7 +42,7 @@ fi SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softfloat-3 berkeley-testfloat-3 anyhow-1-rs arbitrary-int-1-rs attrs-0.2-rs bilge-0= .2-rs bilge-impl-0.2-rs either-1-rs foreign-0.3-rs itertools-0.11-rs - libc-0.2-rs proc-macro2-1-rs + libc-0.2-rs probe-0.5-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" =20 diff --git a/subprojects/.gitignore b/subprojects/.gitignore index c00c847837..011ce4dc3b 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -16,6 +16,7 @@ /glib-sys-* /itertools-* /libc-* +/probe-* /proc-macro-error-* /proc-macro-error-attr-* /proc-macro* diff --git a/subprojects/packagefiles/probe-0.5-rs/meson.build b/subproject= s/packagefiles/probe-0.5-rs/meson.build new file mode 100644 index 0000000000..e6ea69533b --- /dev/null +++ b/subprojects/packagefiles/probe-0.5-rs/meson.build @@ -0,0 +1,22 @@ +project('probe-0.5-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '0.5.2', + license: 'Apache-2.0 OR MIT', + default_options: []) + +_probe_rs =3D static_library( + 'probe', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi: 'rust', + rust_args: [ + '--cap-lints', 'allow', + ], +) + +probe_deps =3D declare_dependency( + link_with: _probe_rs, +) + +meson.override_dependency('probe-0.5-rs', probe_deps) diff --git a/subprojects/probe-0.5-rs.wrap b/subprojects/probe-0.5-rs.wrap new file mode 100644 index 0000000000..73229ee1c2 --- /dev/null +++ b/subprojects/probe-0.5-rs.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory =3D probe-0.5.2 +source_url =3D https://crates.io/api/v1/crates/probe/0.5.2/download +source_filename =3D probe-0.5.2.tar.gz +source_hash =3D 136558b6e1ebaecc92755d0ffaf9421f519531bed30cc2ad23b22cb009= 65cc5e +#method =3D cargo +patch_directory =3D probe-0.5-rs --=20 2.51.1 From nobody Thu Nov 20 12:22:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1763585559; cv=none; d=zohomail.com; s=zohoarc; b=Z9T9GfRjp4VQjJtpi8PKERnvPJVYBx48k/RFeCRDORvhpc+SsLHitnk/HkPKDHb6S3S+TIDeroPj8aMNMXTD7dmFN+0rHxqHPRUVDpUYglHkmaJIqv5hmwWxvSp+WTV9vUPgus1TtNYgqCAm16nySVid4N2fyTt9Kn8cVqvlJxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763585559; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=inJHY2mpT+t2Kxjje60f2B/u2frM4y4WcLTs+HH+0ts=; b=mD8T4PJrQmbWqekAb56fC7TrpyzdLDtcGCZ/0d0wmObhVBlg+YnqSJwxHoXtyDxmIZgUerINt15aLgTIrkt/cOJobO+8ze63MpE2VhsTvtrJaALwvQnVzZ0JfvBvtJhKjfc4yy4YFZBTQCeZzYLusPeACufbC2f/FAlCPIrdDM4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1763585559355398.13890935394204; Wed, 19 Nov 2025 12:52:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLpA5-0007yg-B4; Wed, 19 Nov 2025 15:52:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLpA4-0007xw-B0 for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLpA2-00025O-1L for qemu-devel@nongnu.org; Wed, 19 Nov 2025 15:52:20 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-S6oWsReUPuCHqRRSu_RpWg-1; Wed, 19 Nov 2025 15:52:12 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 54F851801233; Wed, 19 Nov 2025 20:52:11 +0000 (UTC) Received: from localhost (unknown [10.2.16.175]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 57E3230001A4; Wed, 19 Nov 2025 20:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763585537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=inJHY2mpT+t2Kxjje60f2B/u2frM4y4WcLTs+HH+0ts=; b=YO7qNFmuRarzj0kdNLBfyn/+VFzSsIJK8LidhlinddPXbKSFovTI3Xg0WgIwdKchhYrdYo butUl5wKdJYpmVeLkCXF2deILq5XnRrLmVp3X4Mbo1hVyDtaxZj28buUlulL6uvdLXvNhN ZwKq8tGzu4KhzR78MtxpS3fE9wvkkfM= X-MC-Unique: S6oWsReUPuCHqRRSu_RpWg-1 X-Mimecast-MFC-AGG-ID: S6oWsReUPuCHqRRSu_RpWg_1763585531 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-rust@nongnu.org, Mads Ynddal , Thomas Huth , Manos Pitsidianakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Josh Stone , Stefan Hajnoczi Subject: [PATCH v2 4/4] tracetool: add Rust DTrace/SystemTap SDT support Date: Wed, 19 Nov 2025 15:52:00 -0500 Message-ID: <20251119205200.173170-5-stefanha@redhat.com> In-Reply-To: <20251119205200.173170-1-stefanha@redhat.com> References: <20251119205200.173170-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1763585563522019100 Content-Type: text/plain; charset="utf-8" Implement DTrace/SystemTap SDT by emitting the following: - The probe crate's probe!() macro is used to emit a DTrace/SystemTap SDT probe. - Every trace event gets a corresponding trace__enabled() -> bool generated function that Rust code can use to avoid expensive computation when a trace event is disabled. This API works for other trace backends too. `#[allow(dead_code)]` additions are necessary for QEMU's dstate in generated trace-.rs files since they are unused by the dtrace backend. `./configure --enable-trace-backends=3D` can enable multiple backends, so keep it simple and just silence the warning instead of trying to detect the condition when generating the dstate code can be skipped. The tracetool tests are updated. Take a look at tests/tracetool/dtrace.rs to see what the new generated code looks like. Signed-off-by: Stefan Hajnoczi --- rust/Cargo.lock | 6 +++ rust/trace/Cargo.toml | 1 + rust/trace/meson.build | 2 +- rust/trace/src/lib.rs | 4 ++ scripts/tracetool/__init__.py | 1 + scripts/tracetool/backend/dtrace.py | 31 ++++++++++++++ scripts/tracetool/format/rs.py | 27 ++++++++++-- tests/tracetool/dtrace.rs | 65 +++++++++++++++++++++++++++++ tests/tracetool/ftrace.rs | 21 ++++++++++ tests/tracetool/log.rs | 21 ++++++++++ tests/tracetool/simple.rs | 21 ++++++++++ tests/tracetool/syslog.rs | 21 ++++++++++ tests/tracetool/tracetool-test.py | 2 +- 13 files changed, 217 insertions(+), 6 deletions(-) create mode 100644 tests/tracetool/dtrace.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 0c1df625df..5bd768cb0d 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -144,6 +144,7 @@ dependencies =3D [ "migration", "qom", "system", + "trace", "util", ] =20 @@ -229,6 +230,10 @@ dependencies =3D [ "util", ] =20 +[[package]] +name =3D "probe" +version =3D "0.5.2" + [[package]] name =3D "proc-macro-error" version =3D "1.0.4" @@ -429,6 +434,7 @@ name =3D "trace" version =3D "0.1.0" dependencies =3D [ "libc", + "probe", ] =20 [[package]] diff --git a/rust/trace/Cargo.toml b/rust/trace/Cargo.toml index fc81bce580..11e27f8d28 100644 --- a/rust/trace/Cargo.toml +++ b/rust/trace/Cargo.toml @@ -14,6 +14,7 @@ rust-version.workspace =3D true =20 [dependencies] libc =3D { workspace =3D true } +probe =3D "0.5" =20 [lints] workspace =3D true diff --git a/rust/trace/meson.build b/rust/trace/meson.build index adca57e550..cf6b0355a8 100644 --- a/rust/trace/meson.build +++ b/rust/trace/meson.build @@ -12,7 +12,7 @@ _trace_rs =3D static_library( lib_rs, trace_rs_targets, # List of generated `.rs` custom targets override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], - dependencies: [libc_rs], + dependencies: [libc_rs, probe_rs], rust_abi: 'rust', ) =20 diff --git a/rust/trace/src/lib.rs b/rust/trace/src/lib.rs index e03bce43c4..49331f07c6 100644 --- a/rust/trace/src/lib.rs +++ b/rust/trace/src/lib.rs @@ -7,6 +7,10 @@ /// Re-exported item to avoid adding libc as a dependency everywhere. pub use libc::{syslog, LOG_INFO}; =20 +#[doc(hidden)] +/// Re-exported item to avoid adding probe as a dependency everywhere. +pub use probe::probe; + #[macro_export] /// Define the trace-points from the named directory (which should have sl= ashes /// replaced by underscore characters) as functions in a module called `tr= ace`. diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index 74062d21a7..61ba6f1ba8 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -461,6 +461,7 @@ def formats(self): =20 QEMU_TRACE =3D "trace_%(name)s" QEMU_TRACE_TCG =3D QEMU_TRACE + "_tcg" + QEMU_RUST_DSTATE =3D "trace_%(name)s_enabled" QEMU_DSTATE =3D "_TRACE_%(NAME)s_DSTATE" QEMU_BACKEND_DSTATE =3D "TRACE_%(NAME)s_BACKEND_DSTATE" QEMU_EVENT =3D "_TRACE_%(NAME)s_EVENT" diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backen= d/dtrace.py index b4af403025..f0b58cc158 100644 --- a/scripts/tracetool/backend/dtrace.py +++ b/scripts/tracetool/backend/dtrace.py @@ -70,3 +70,34 @@ def generate_h(event, group): def generate_h_backend_dstate(event, group): out(' QEMU_%(uppername)s_ENABLED() || \\', uppername=3Devent.name.upper()) + + +def generate_rs_begin(events, group): + out('use std::cell::UnsafeCell;', + '', + 'extern "C" {') + # These are the Rust declarations of the .probes section semaphores + # generated by dtrace(1) in its .o file output. + for e in events: + if 'disable' in e.properties: + continue + out(' #[allow(dead_code)]', + f' static qemu_{e.name}_semaphore: UnsafeCell;') + out('}', + '') + + +def generate_rs(event, group): + args =3D event.args.rust_call_extern() + if args: + args =3D ', ' + args + + out(f' ::trace::probe!(qemu, {event.name}{args});') + + +def generate_rs_backend_dstate(event, group): + # Rust does not have access to the __ENABLED() macro f= rom + # the dtrace(1) generated .h file. Use the matching semaphore declarat= ions + # generated by generate_rs_begin() instead. + out(' (unsafe {qemu_%(n)s_semaphore.get().read_volatile()}) !=3D 0 = ||', + n=3Devent.name) diff --git a/scripts/tracetool/format/rs.py b/scripts/tracetool/format/rs.py index 32ac4e5977..7d9af7edfe 100644 --- a/scripts/tracetool/format/rs.py +++ b/scripts/tracetool/format/rs.py @@ -24,25 +24,43 @@ def generate(events, backend, group): '#[allow(unused_imports)]', 'use util::bindings;', '', + '#[allow(dead_code)]', '#[inline(always)]', 'fn trace_event_state_is_enabled(dstate: u16) -> bool {', ' (unsafe { trace_events_enabled_count }) !=3D 0 && dstate !=3D= 0', '}', '', 'extern "C" {', + ' #[allow(dead_code)]', ' static mut trace_events_enabled_count: u32;', '}',) =20 out('extern "C" {') =20 for e in events: - out(' static mut %s: u16;' % e.api(e.QEMU_DSTATE)) - out('}') + out(' #[allow(dead_code)]', + ' static mut %s: u16;' % e.api(e.QEMU_DSTATE)) + out('}', + '') =20 backend.generate_begin(events, group) =20 for e in events: - out('', + out('#[inline(always)]', + '#[allow(dead_code)]', + 'pub fn %(api)s() -> bool', + '{', + api=3De.api(e.QEMU_RUST_DSTATE)) + + if "disable" not in e.properties: + backend.generate_backend_dstate(e, group) + if backend.check_trace_event_get_state: + out(' trace_event_state_is_enabled(unsafe { _%(event_id= )s_DSTATE}) ||', + event_id =3D 'TRACE_' + e.name.upper()) + + out(' false', + '}', + '', '#[inline(always)]', '#[allow(dead_code)]', 'pub fn %(api)s(%(args)s)', @@ -59,6 +77,7 @@ def generate(events, backend, group): api=3De.api()) backend.generate(e, group, check_trace_event_get_state=3DT= rue) out(' }') - out('}') + out('}', + '') =20 backend.generate_end(events, group) diff --git a/tests/tracetool/dtrace.rs b/tests/tracetool/dtrace.rs new file mode 100644 index 0000000000..233c2ef159 --- /dev/null +++ b/tests/tracetool/dtrace.rs @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// This file is @generated by tracetool, do not edit. + +#[allow(unused_imports)] +use std::ffi::c_char; +#[allow(unused_imports)] +use util::bindings; + +#[allow(dead_code)] +#[inline(always)] +fn trace_event_state_is_enabled(dstate: u16) -> bool { + (unsafe { trace_events_enabled_count }) !=3D 0 && dstate !=3D 0 +} + +extern "C" { + #[allow(dead_code)] + static mut trace_events_enabled_count: u32; +} +extern "C" { + #[allow(dead_code)] + static mut _TRACE_TEST_BLAH_DSTATE: u16; + #[allow(dead_code)] + static mut _TRACE_TEST_WIBBLE_DSTATE: u16; +} + +use probe::probe; +use std::cell::UnsafeCell; + +extern "C" { + #[allow(dead_code)] + static qemu_test_blah_semaphore: UnsafeCell; + #[allow(dead_code)] + static qemu_test_wibble_semaphore: UnsafeCell; +} + +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah_enabled() -> bool +{ + (unsafe {qemu_test_blah_semaphore.get().read_volatile()}) !=3D 0 || + false +} + +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah(_context: *mut (), _filename: &std::ffi::CStr) +{ + probe!(qemu, test_blah, _context, _filename.as_ptr()); +} + +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble_enabled() -> bool +{ + (unsafe {qemu_test_wibble_semaphore.get().read_volatile()}) !=3D 0 || + false +} + +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble(_context: *mut (), _value: std::ffi::c_int) +{ + probe!(qemu, test_wibble, _context, _value); +} + diff --git a/tests/tracetool/ftrace.rs b/tests/tracetool/ftrace.rs index 07b9259cf2..34f6600490 100644 --- a/tests/tracetool/ftrace.rs +++ b/tests/tracetool/ftrace.rs @@ -6,19 +6,31 @@ #[allow(unused_imports)] use util::bindings; =20 +#[allow(dead_code)] #[inline(always)] fn trace_event_state_is_enabled(dstate: u16) -> bool { (unsafe { trace_events_enabled_count }) !=3D 0 && dstate !=3D 0 } =20 extern "C" { + #[allow(dead_code)] static mut trace_events_enabled_count: u32; } extern "C" { + #[allow(dead_code)] static mut _TRACE_TEST_BLAH_DSTATE: u16; + #[allow(dead_code)] static mut _TRACE_TEST_WIBBLE_DSTATE: u16; } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_BLAH_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_blah(_context: *mut (), _filename: &std::ffi::CStr) @@ -29,6 +41,14 @@ pub fn trace_test_blah(_context: *mut (), _filename: &st= d::ffi::CStr) } } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_WIBBLE_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_wibble(_context: *mut (), _value: std::ffi::c_int) @@ -38,3 +58,4 @@ pub fn trace_test_wibble(_context: *mut (), _value: std::= ffi::c_int) unsafe {bindings::ftrace_write(format_string.as_ptr() as *const c_= char, _context /* as *mut () */, _value /* as std::ffi::c_int */);} } } + diff --git a/tests/tracetool/log.rs b/tests/tracetool/log.rs index c191895c8f..770758611d 100644 --- a/tests/tracetool/log.rs +++ b/tests/tracetool/log.rs @@ -6,19 +6,31 @@ #[allow(unused_imports)] use util::bindings; =20 +#[allow(dead_code)] #[inline(always)] fn trace_event_state_is_enabled(dstate: u16) -> bool { (unsafe { trace_events_enabled_count }) !=3D 0 && dstate !=3D 0 } =20 extern "C" { + #[allow(dead_code)] static mut trace_events_enabled_count: u32; } extern "C" { + #[allow(dead_code)] static mut _TRACE_TEST_BLAH_DSTATE: u16; + #[allow(dead_code)] static mut _TRACE_TEST_WIBBLE_DSTATE: u16; } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_BLAH_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_blah(_context: *mut (), _filename: &std::ffi::CStr) @@ -31,6 +43,14 @@ pub fn trace_test_blah(_context: *mut (), _filename: &st= d::ffi::CStr) } } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_WIBBLE_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_wibble(_context: *mut (), _value: std::ffi::c_int) @@ -42,3 +62,4 @@ pub fn trace_test_wibble(_context: *mut (), _value: std::= ffi::c_int) } } } + diff --git a/tests/tracetool/simple.rs b/tests/tracetool/simple.rs index 9ee39495e3..92f896ef17 100644 --- a/tests/tracetool/simple.rs +++ b/tests/tracetool/simple.rs @@ -6,19 +6,31 @@ #[allow(unused_imports)] use util::bindings; =20 +#[allow(dead_code)] #[inline(always)] fn trace_event_state_is_enabled(dstate: u16) -> bool { (unsafe { trace_events_enabled_count }) !=3D 0 && dstate !=3D 0 } =20 extern "C" { + #[allow(dead_code)] static mut trace_events_enabled_count: u32; } extern "C" { + #[allow(dead_code)] static mut _TRACE_TEST_BLAH_DSTATE: u16; + #[allow(dead_code)] static mut _TRACE_TEST_WIBBLE_DSTATE: u16; } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_BLAH_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_blah(_context: *mut (), _filename: &std::ffi::CStr) @@ -29,6 +41,14 @@ pub fn trace_test_blah(_context: *mut (), _filename: &st= d::ffi::CStr) } } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_WIBBLE_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_wibble(_context: *mut (), _value: std::ffi::c_int) @@ -38,3 +58,4 @@ pub fn trace_test_wibble(_context: *mut (), _value: std::= ffi::c_int) unsafe { _simple_trace_test_wibble(_context, _value); } } } + diff --git a/tests/tracetool/syslog.rs b/tests/tracetool/syslog.rs index 9d3675a0b5..378d03d34b 100644 --- a/tests/tracetool/syslog.rs +++ b/tests/tracetool/syslog.rs @@ -6,19 +6,31 @@ #[allow(unused_imports)] use util::bindings; =20 +#[allow(dead_code)] #[inline(always)] fn trace_event_state_is_enabled(dstate: u16) -> bool { (unsafe { trace_events_enabled_count }) !=3D 0 && dstate !=3D 0 } =20 extern "C" { + #[allow(dead_code)] static mut trace_events_enabled_count: u32; } extern "C" { + #[allow(dead_code)] static mut _TRACE_TEST_BLAH_DSTATE: u16; + #[allow(dead_code)] static mut _TRACE_TEST_WIBBLE_DSTATE: u16; } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_BLAH_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_blah(_context: *mut (), _filename: &std::ffi::CStr) @@ -29,6 +41,14 @@ pub fn trace_test_blah(_context: *mut (), _filename: &st= d::ffi::CStr) } } =20 +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble_enabled() -> bool +{ + trace_event_state_is_enabled(unsafe { _TRACE_TEST_WIBBLE_DSTATE}) || + false +} + #[inline(always)] #[allow(dead_code)] pub fn trace_test_wibble(_context: *mut (), _value: std::ffi::c_int) @@ -38,3 +58,4 @@ pub fn trace_test_wibble(_context: *mut (), _value: std::= ffi::c_int) unsafe {::trace::syslog(::trace::LOG_INFO, format_string.as_ptr() = as *const c_char, _context /* as *mut () */, _value /* as std::ffi::c_int *= /);} } } + diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool-= test.py index 786083ad7f..30006a9919 100755 --- a/tests/tracetool/tracetool-test.py +++ b/tests/tracetool/tracetool-test.py @@ -14,7 +14,7 @@ def get_formats(backend): "c", "h", ] - if backend in {"ftrace", "log", "simple", "syslog"}: + if backend in {"dtrace", "ftrace", "log", "simple", "syslog"}: formats +=3D ["rs"] if backend =3D=3D "dtrace": formats +=3D [ --=20 2.51.1