From nobody Mon Feb 9 16:19:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501593662447329.41557739393375; Tue, 1 Aug 2017 06:21:02 -0700 (PDT) Received: from localhost ([::1]:42533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcX6a-0004oT-H6 for importer@patchew.org; Tue, 01 Aug 2017 09:21:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcX2O-0001bF-VN for qemu-devel@nongnu.org; Tue, 01 Aug 2017 09:16:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcX2M-0005Sm-VS for qemu-devel@nongnu.org; Tue, 01 Aug 2017 09:16:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58528) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dcX2M-0005SL-LU for qemu-devel@nongnu.org; Tue, 01 Aug 2017 09:16:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BB2A139858; Tue, 1 Aug 2017 13:16:37 +0000 (UTC) Received: from localhost (ovpn-117-109.ams2.redhat.com [10.36.117.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id E23535C888; Tue, 1 Aug 2017 13:16:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9BB2A139858 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=stefanha@redhat.com From: Stefan Hajnoczi To: Date: Tue, 1 Aug 2017 14:16:13 +0100 Message-Id: <20170801131618.27332-5-stefanha@redhat.com> In-Reply-To: <20170801131618.27332-1-stefanha@redhat.com> References: <20170801131618.27332-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 01 Aug 2017 13:16:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/9] trace: add trace_event_get_state_backends() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Code that checks dstate is unaware of SystemTap and LTTng UST dstate, so the following trace event will not fire when solely enabled by SystemTap or LTTng UST: if (trace_event_get_state(TRACE_MY_EVENT)) { str =3D g_strdup_printf("Expensive string to generate ...", ...); trace_my_event(str); g_free(str); } Add trace_event_get_state_backends() to fetch backend dstate. Those backends that use QEMU dstate fetch it as part of generate_h_backend_dstate(). Update existing trace_event_get_state() callers to use trace_event_get_state_backends() instead. Signed-off-by: Stefan Hajnoczi Message-id: 20170731140718.22010-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- docs/devel/tracing.txt | 2 +- trace/control.h | 18 +++++++++++++++++- hw/usb/hcd-ohci.c | 13 +++++-------- net/colo-compare.c | 11 ++++++----- net/filter-rewriter.c | 4 ++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/docs/devel/tracing.txt b/docs/devel/tracing.txt index 5768a0b7a2..07abbb345c 100644 --- a/docs/devel/tracing.txt +++ b/docs/devel/tracing.txt @@ -353,7 +353,7 @@ guard such computations and avoid its compilation when = the event is disabled: } =20 You can check both if the event has been disabled and is dynamically enabl= ed at -the same time using the 'trace_event_get_state' routine (see header +the same time using the 'trace_event_get_state_backends' routine (see head= er "trace/control.h" for more information). =20 =3D=3D=3D "tcg" =3D=3D=3D diff --git a/trace/control.h b/trace/control.h index b931824d60..1903e22975 100644 --- a/trace/control.h +++ b/trace/control.h @@ -96,7 +96,7 @@ static const char * trace_event_get_name(TraceEvent *ev); * trace_event_get_state: * @id: Event identifier name. * - * Get the tracing state of an event (both static and dynamic). + * Get the tracing state of an event, both static and the QEMU dynamic sta= te. * * If the event has the disabled property, the check will have no performa= nce * impact. @@ -105,6 +105,22 @@ static const char * trace_event_get_name(TraceEvent *e= v); ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id)) =20 /** + * trace_event_get_state_backends: + * @id: Event identifier name. + * + * Get the tracing state of an event, both static and dynamic state from a= ll + * compiled-in backends. + * + * If the event has the disabled property, the check will have no performa= nce + * impact. + * + * Returns: true if at least one backend has the event enabled and the eve= nt + * does not have the disabled property. + */ +#define trace_event_get_state_backends(id) \ + ((id ##_ENABLED) && id ##_BACKEND_DSTATE()) + +/** * trace_event_get_vcpu_state: * @vcpu: Target vCPU. * @id: Event identifier name. diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 3ada35e954..267982e160 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -936,16 +936,18 @@ static int ohci_service_iso_td(OHCIState *ohci, struc= t ohci_ed *ed, return 1; } =20 -#ifdef trace_event_get_state static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len) { - bool print16 =3D !!trace_event_get_state(TRACE_USB_OHCI_TD_PKT_SHORT); - bool printall =3D !!trace_event_get_state(TRACE_USB_OHCI_TD_PKT_FULL); + bool print16; + bool printall; const int width =3D 16; int i; char tmp[3 * width + 1]; char *p =3D tmp; =20 + print16 =3D !!trace_event_get_state_backends(TRACE_USB_OHCI_TD_PKT_SHO= RT); + printall =3D !!trace_event_get_state_backends(TRACE_USB_OHCI_TD_PKT_FU= LL); + if (!printall && !print16) { return; } @@ -967,11 +969,6 @@ static void ohci_td_pkt(const char *msg, const uint8_t= *buf, size_t len) p +=3D sprintf(p, " %.2x", buf[i]); } } -#else -static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len) -{ -} -#endif =20 /* Service a transport descriptor. Returns nonzero to terminate processing of this endpoint. */ diff --git a/net/colo-compare.c b/net/colo-compare.c index ca67c68615..5fe8e3fad9 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -188,7 +188,7 @@ static int packet_enqueue(CompareState *s, int mode) */ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offs= et) { - if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { + if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) { char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20= ]; =20 strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -274,7 +274,8 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet= *ppkt) res =3D -1; } =20 - if (res !=3D 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)= ) { + if (res !=3D 0 && + trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) { char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20= ]; =20 strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -334,7 +335,7 @@ static int colo_packet_compare_udp(Packet *spkt, Packet= *ppkt) if (ret) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size= ); - if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { + if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))= { qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt= ", ppkt->size); qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt= ", @@ -371,7 +372,7 @@ static int colo_packet_compare_icmp(Packet *spkt, Packe= t *ppkt) ppkt->size); trace_colo_compare_icmp_miscompare("Secondary pkt size", spkt->size); - if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { + if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))= { qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt= ", ppkt->size); qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt= ", @@ -390,7 +391,7 @@ static int colo_packet_compare_icmp(Packet *spkt, Packe= t *ppkt) static int colo_packet_compare_other(Packet *spkt, Packet *ppkt) { trace_colo_compare_main("compare other"); - if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { + if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) { char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20= ]; =20 strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index 55a6cf56fd..98120095de 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -69,7 +69,7 @@ static int handle_primary_tcp_pkt(NetFilterState *nf, struct tcphdr *tcp_pkt; =20 tcp_pkt =3D (struct tcphdr *)pkt->transport_header; - if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) { + if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) { trace_colo_filter_rewriter_pkt_info(__func__, inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst), ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack), @@ -115,7 +115,7 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf, =20 tcp_pkt =3D (struct tcphdr *)pkt->transport_header; =20 - if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) { + if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) { trace_colo_filter_rewriter_pkt_info(__func__, inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst), ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack), --=20 2.13.3