From nobody Sat Nov 15 00:06:34 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=1759161416; cv=none; d=zohomail.com; s=zohoarc; b=RMFp5PF2/zdJpOD1Shb/OR2i46bHHiq90EsH2B0pkcbpZZwK7VJafF8gyAC7rc7bxfmWYSMCCq8HiA9eLFW+Fq5MFPCaq00KCULBOdUl5Xm7AUYX2XrNOd+MlHpFa2ZmjZSceRiZV1wUMciE88sohkEq9MqUWoEbBCLjxEe9/tY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759161416; 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=IbFiXIH/TncCeyWIaeOv4wWWiHN6wH4wF+ui7m2Sv3c=; b=TsRGGKPNMIlAvqnzwhDTKPCby2v8x5P0+qS9FQQDQfwTk3SitnS2qgLCNRyViT5kzmLRBQRgCRH1jTA996xzi6LfJjx8DjkOjpNrexcznY+S4Kzg5C4y3br962jimrncR8qhHLN+O1iQ0FA/0VR7ZlyjAq7FzBmzIWj/JhBhd2g= 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 1759161416928540.474809796761; Mon, 29 Sep 2025 08:56:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v3G9h-0001Vd-Bv; Mon, 29 Sep 2025 11:51:13 -0400 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 1v3G8z-0000yc-Qz for qemu-devel@nongnu.org; Mon, 29 Sep 2025 11:50:30 -0400 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 1v3G8i-0000aE-Hw for qemu-devel@nongnu.org; Mon, 29 Sep 2025 11:50:29 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-dW1V3gpTPc-3uOfbnSzM9A-1; Mon, 29 Sep 2025 11:50:06 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-b3afaf5defdso180328666b.0 for ; Mon, 29 Sep 2025 08:50:06 -0700 (PDT) Received: from [192.168.10.48] ([176.206.127.188]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b353f87511dsm958113866b.43.2025.09.29.08.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Sep 2025 08:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759161009; 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=IbFiXIH/TncCeyWIaeOv4wWWiHN6wH4wF+ui7m2Sv3c=; b=Sl6HnoyyZuBJyz2ZCFhbMA0+Fa6Uws8ETtiCnbmmK3Xy7YixN8S8Ay1StWEH/kytibKLOF igngfr2+dbYoukzV7RC9Df5P25Ou/6OO8yq06dyjaHTILl6apGJyhKW29kdMvpZpFBdZQv oDGv0qqm8oHnEO67pCG7QK4n8Muo3UE= X-MC-Unique: dW1V3gpTPc-3uOfbnSzM9A-1 X-Mimecast-MFC-AGG-ID: dW1V3gpTPc-3uOfbnSzM9A_1759161006 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759161005; x=1759765805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IbFiXIH/TncCeyWIaeOv4wWWiHN6wH4wF+ui7m2Sv3c=; b=B5L1sb5cvW3a0BLnx0X6pW81Iz4INGPcCq6Yh+AQe4ayizvCd7ozBod7Xe+UflJVLp gpGKk1T8vhUNto3JXewU/N/90KJpd50JzR911ukGx3Qwll/jxcB/ScB+XgNQZ/de4gDo qVuDlcqz75cy1aIyOoU3RHekikz+FQMV2taWrzuX099jRubKaw0jmyBcLW4q9DeQA9Jn JcnFHk/hwZQBd8hZqPich2ckJ5xGXyvT7l1WBCpK5vKEvVQGEAuzD7uBftAopdZ7q9es edL7TYdlLn+Bm+EzDhm6e/NTW95JJgcl9HdtBGlXkCfe1RzufG97c4rC3hxKMKXIZPfD X3hg== X-Gm-Message-State: AOJu0Yzvg5IrH9A3AB1ToI33DtLaL190Ymz5H9BqLqsgKgP8tONhPfhj CLnfnAz4LmRqM5gMgwbMkIroZ/1WiuCf47MuqhqLnVVg0l6PnbuVGbKX6Gn0tm9dlBXrcySThJt 1GheisqmFJ1t8vIOQolba2rvrtCN0F1VR+Kemi2J8TRV9n1WrXI4nrZ5IQlSWvqCm+NJ3wkFmM9 t2VfiJOqFWpzdXKLAsDnVfH6l7BY8lJ+Yn6tXLkYH2 X-Gm-Gg: ASbGncvaqUBU392gdguKetfHoFUMsnEEswkP6LSk3Cwn1EnwwhQaEHOui7jFpcYf13H 7m8+dwZ56LiFxzjyqnuKbd7Elwf3hMYPkbT0p+2srw5ZBECqcQZ3JvB3gVwFO2TW0KIMo4f1QFt gNpmuMCdsmZbP1UbopAadt9pbNlOgeXXkXMeOyN/kyqiUK7ThfPZkDebtGmSmTRuMpoYKIKzqjc rmB/hsw5bzKqQ1UeOalgKDLTii9VIelLJXrz9CKEx4fhCYxB/9b/hzEtK3RKsBLdSyomzdcwb95 vL5Dsq3wtXrEvEWsDUn9CvzjIx47L1WBnfvEweprjWH+NZZg+ukHFJusp0rsIjMY0AoTVB+E2LZ Z8WYgM3fxTMj9QVykQG1KdE4qesO9Jb/mnj+bVj4nk7O1jQ== X-Received: by 2002:a17:906:f584:b0:b3f:a960:e057 with SMTP id a640c23a62f3a-b3fa960e50amr376782066b.31.1759161004769; Mon, 29 Sep 2025 08:50:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRoaXuYL4gcyhKRHpI3i0qEJMtO/jk05ODIibiVsx+0CR4Oz5jXPNGxLhRR9GcKEGfVJ+8Xg== X-Received: by 2002:a17:906:f584:b0:b3f:a960:e057 with SMTP id a640c23a62f3a-b3fa960e50amr376778566b.31.1759161004297; Mon, 29 Sep 2025 08:50:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Tanish Desai , Stefan Hajnoczi , Manos Pitsidianakis , Mads Ynddal , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Zhao Liu , qemu-rust@nongnu.org Subject: [PATCH 09/16] rust: add trace crate Date: Mon, 29 Sep 2025 17:49:31 +0200 Message-ID: <20250929154938.594389-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250929154938.594389-1-pbonzini@redhat.com> References: <20250929154938.594389-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.513, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1759161418408116602 Content-Type: text/plain; charset="utf-8" From: Tanish Desai The trace crate is a minimal container for dependencies of tracepoints (so that they do not have to be imported in all the crates that use tracepoints); it also contains a macro called "include_trace!" that is able to find the right include file from the trace/ directory. Signed-off-by: Tanish Desai [Write commit message, add #[allow()]. - Paolo] Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- rust/Cargo.lock | 4 ++++ rust/Cargo.toml | 1 + rust/meson.build | 2 +- rust/trace/Cargo.toml | 16 ++++++++++++++++ rust/trace/meson.build | 19 +++++++++++++++++++ rust/trace/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ trace/meson.build | 8 +++++++- 7 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 rust/trace/Cargo.toml create mode 100644 rust/trace/meson.build create mode 100644 rust/trace/src/lib.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 8315f98c46f..3428dbaf0b3 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -258,6 +258,10 @@ dependencies =3D [ "util", ] =20 +[[package]] +name =3D "trace" +version =3D "0.1.0" + [[package]] name =3D "unicode-ident" version =3D "1.0.12" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index d8183c614d4..f372d7dbf70 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,6 +11,7 @@ members =3D [ "hw/core", "hw/char/pl011", "hw/timer/hpet", + "trace", "util", "tests", ] diff --git a/rust/meson.build b/rust/meson.build index b3ac3a71970..695d5a62de9 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -34,7 +34,7 @@ subdir('system') subdir('chardev') subdir('hw/core') subdir('tests') - +subdir('trace') subdir('hw') =20 cargo =3D find_program('cargo', required: false) diff --git a/rust/trace/Cargo.toml b/rust/trace/Cargo.toml new file mode 100644 index 00000000000..13ac0b33d6f --- /dev/null +++ b/rust/trace/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name =3D "trace" +version =3D "0.1.0" +authors =3D ["Tanish Desai "] +description =3D "QEMU tracing infrastructure support" +resolver =3D "2" +publish =3D false + +edition.workspace =3D true +homepage.workspace =3D true +license.workspace =3D true +repository.workspace =3D true +rust-version.workspace =3D true + +[lints] +workspace =3D true diff --git a/rust/trace/meson.build b/rust/trace/meson.build new file mode 100644 index 00000000000..adca57e5507 --- /dev/null +++ b/rust/trace/meson.build @@ -0,0 +1,19 @@ +rust =3D import('rust') + +lib_rs =3D configure_file( + input: 'src/lib.rs', + output: 'lib.rs', + configuration: { + 'MESON_BUILD_ROOT': meson.project_build_root(), + }) + +_trace_rs =3D static_library( + 'trace', # Library name, + lib_rs, + trace_rs_targets, # List of generated `.rs` custom targets + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + dependencies: [libc_rs], + rust_abi: 'rust', +) + +trace_rs =3D declare_dependency(link_with: _trace_rs) diff --git a/rust/trace/src/lib.rs b/rust/trace/src/lib.rs new file mode 100644 index 00000000000..0955461573d --- /dev/null +++ b/rust/trace/src/lib.rs @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +//! This crate provides macros that aid in using QEMU's tracepoint +//! functionality. + +#[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`. +/// +/// ```ignore +/// ::trace::include_trace!("hw_char"); +/// // ... +/// trace::trace_pl011_read_fifo_rx_full(); +/// ``` +macro_rules! include_trace { + ($name:literal) =3D> { + #[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, ".r= s")); + } + }; +} diff --git a/trace/meson.build b/trace/meson.build index 9c42a57a053..d89a0db82a1 100644 --- a/trace/meson.build +++ b/trace/meson.build @@ -1,5 +1,5 @@ system_ss.add(files('control-target.c', 'trace-hmp-cmds.c')) - +trace_rs_targets =3D [] trace_events_files =3D [] foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events if item in qapi_trace_events @@ -24,6 +24,11 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_tra= ce_events input: trace_events_file, command: [ tracetool, group, '--format=3Dc', '@I= NPUT@', '@OUTPUT@' ], depend_files: tracetool_depends) + trace_rs =3D custom_target(fmt.format('trace', 'rs'), + output: fmt.format('trace', 'rs'), + input: trace_events_file, + command: [ tracetool, group, '--format=3Drs', '@= INPUT@', '@OUTPUT@' ], + depend_files: tracetool_depends) if 'ust' in get_option('trace_backends') trace_ust_h =3D custom_target(fmt.format('trace-ust', 'h'), output: fmt.format('trace-ust', 'h'), @@ -34,6 +39,7 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trac= e_events genh +=3D trace_ust_h endif trace_ss.add(trace_h, trace_c) + trace_rs_targets +=3D trace_rs if 'dtrace' in get_option('trace_backends') trace_dtrace =3D custom_target(fmt.format('trace-dtrace', 'dtrace'), output: fmt.format('trace-dtrace', 'dtrac= e'), --=20 2.51.0