From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1tzWxz-0007hd-Tv for mharc-qemu-rust@gnu.org; Tue, 01 Apr 2025 04:27:27 -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 1tzWxy-0007hL-7z for qemu-rust@nongnu.org; Tue, 01 Apr 2025 04:27:26 -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 1tzWxt-0000Lm-Ki for qemu-rust@nongnu.org; Tue, 01 Apr 2025 04:27:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743496040; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=3fkN1pYjHsU9EtxFPbRwl9Y3AHoEMyPFV1fhUPfcGF0=; b=KJKQ3auuCcMj4+nB223Jyt552Z3RStvRZStm+0tEweWa5RD9lLk6uf4dUMtj7x5JvEs5Xr lvo5h+us5gASL30AiqfOQ5Ajxs6pZ4ftgbU43jcuojz+3Qh8F05y0DItGCi3yhXUbkLNbk XgC6/THqRcocBfGw737rueXAIsPnqxA= Received: from mx-prod-mc-04.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-688-0bJHg54-O-Gckbp6piClhA-1; Tue, 01 Apr 2025 04:27:17 -0400 X-MC-Unique: 0bJHg54-O-Gckbp6piClhA-1 X-Mimecast-MFC-AGG-ID: 0bJHg54-O-Gckbp6piClhA_1743496036 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 81D351955DC6; Tue, 1 Apr 2025 08:27:15 +0000 (UTC) Received: from redhat.com (unknown [10.42.28.51]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0A1D1956094; Tue, 1 Apr 2025 08:27:11 +0000 (UTC) Date: Tue, 1 Apr 2025 09:27:08 +0100 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= To: saman Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , qemu-rust@nongnu.org, Mads Ynddal , Manos Pitsidianakis Subject: Re: [PATCH] Rust: Add tracing and logging support for Rust code Message-ID: Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= References: <20250401002633.738345-1-saman@enumclass.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20250401002633.738345-1-saman@enumclass.cc> User-Agent: Mutt/2.2.13 (2024-03-09) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.198, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Apr 2025 08:27:27 -0000 On Mon, Mar 31, 2025 at 07:26:33PM -0500, saman wrote: > This change introduces initial support for tracing and logging in Rust-based > QEMU code. As an example, tracing and logging have been implemented in the > pl011 device, which is written in Rust. > > - Updated `rust/wrapper.h` to include the `qemu/log.h` and `hw/char/trace.h` header. > - Added log.rs to wrap `qemu_log_mask` and `qemu_log_mask_and_addr` > - Modified `tracetool` scripts to move C function implementation from > header to .c > - Added log and trace in rust version of PL011 device > > Future enhancements could include generating idiomatic Rust APIs for tracing > using the tracetool scripts > > Signed-off-by: saman > --- > include/qemu/log-for-trace.h | 5 +-- > rust/hw/char/pl011/src/device.rs | 34 +++++++++++++++--- > rust/hw/char/pl011/src/registers.rs | 20 +++++++++++ > rust/qemu-api/meson.build | 1 + > rust/qemu-api/src/lib.rs | 1 + > rust/qemu-api/src/log.rs | 54 +++++++++++++++++++++++++++++ > rust/wrapper.h | 2 ++ > scripts/tracetool/format/c.py | 16 +++++++++ > scripts/tracetool/format/h.py | 11 ++---- > util/log.c | 5 +++ > 10 files changed, 131 insertions(+), 18 deletions(-) > create mode 100644 rust/qemu-api/src/log.rs > > diff --git a/scripts/tracetool/format/c.py b/scripts/tracetool/format/c.py > index 69edf0d588..f2d383f89c 100644 > --- a/scripts/tracetool/format/c.py > +++ b/scripts/tracetool/format/c.py > @@ -43,6 +43,22 @@ def generate(events, backend, group): > sstate = "TRACE_%s_ENABLED" % e.name.upper(), > dstate = e.api(e.QEMU_DSTATE)) > > + cond = "true" > + > + out('', > + 'void %(api)s(%(args)s)', > + '{', > + ' if (%(cond)s) {', > + ' %(api_nocheck)s(%(names)s);', > + ' }', > + '}', > + api=e.api(), > + api_nocheck=e.api(e.QEMU_TRACE_NOCHECK), > + args=e.args, > + names=", ".join(e.args.names()), > + cond=cond > + ) > + > out('TraceEvent *%(group)s_trace_events[] = {', > group = group.lower()) > > diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py > index ea126b07ea..16b360ae49 100644 > --- a/scripts/tracetool/format/h.py > +++ b/scripts/tracetool/format/h.py > @@ -74,17 +74,10 @@ def generate(events, backend, group): > cond = "true" > > out('', > - 'static inline void %(api)s(%(args)s)', > - '{', > - ' if (%(cond)s) {', > - ' %(api_nocheck)s(%(names)s);', > - ' }', > - '}', > + 'void %(api)s(%(args)s);', > api=e.api(), > - api_nocheck=e.api(e.QEMU_TRACE_NOCHECK), > args=e.args, > - names=", ".join(e.args.names()), > - cond=cond) > + ) > > backend.generate_end(events, group) > This is a non-trivial degradation for the tracing code. The code is generated in an inline function in the header so that when a probe point is not active, it has as little overhead as possible - with some backends it will just a 'nop' instruction. With this change every probe is turned into a function call with no possiblity to optimize away this overhead. IMHO tracing in Rust needs to be done by generating native Rust code for the (sub)set of trace backends that we care about, and not attempt to wrap the C trace code from Rust. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|