From nobody Sat Nov 15 17:45:27 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1748460423; cv=none; d=zohomail.com; s=zohoarc; b=gcvlFg13JeVzcmrbHqn75Slzf+xWDyhYEoBSGwQH9XAh30RyKS7m9VHnzjbWvyLSi5x7fSzrhShRTQLgDnAUTOvTtrF9AGIz5zSt261R/rLADLTSUy5buazRMzrr8Tma5p5jqwMGAUgM1YKy6ITVm1IDnUUEsgGOlRch+NKMtBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748460423; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p8XQsIys0bjXBF6Rjgp0AQXhuEMtKRZMh2pOpwp/DPs=; b=UHH+r04Za1dpeBQ7++qrPw9IsuupwSzAl2VBlbIqqTbNvntKWoaosSW7gY0rp3Zj5JJdOGxo8Z+pMEqLG7L/c3Ve5XmIUs3Idq2AacdAIdXei5SkAYgJuzCT38vbpX/9Pg7tniOP+CZ4SQc8E5rSMx6dkoQSh3A0nkQ/3Dw+9XA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748460423020523.3889843219281; Wed, 28 May 2025 12:27:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKMPb-0002tC-2Y; Wed, 28 May 2025 15:26:03 -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 1uKMPX-0002sD-3P for qemu-devel@nongnu.org; Wed, 28 May 2025 15:25:59 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uKMPR-0007qE-HH for qemu-devel@nongnu.org; Wed, 28 May 2025 15:25:57 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2349282084bso2643885ad.1 for ; Wed, 28 May 2025 12:25:49 -0700 (PDT) Received: from ubuntu.. ([49.207.62.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-234d2fd22d4sm15522765ad.4.2025.05.28.12.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 12:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748460346; x=1749065146; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p8XQsIys0bjXBF6Rjgp0AQXhuEMtKRZMh2pOpwp/DPs=; b=C/JBq3XRT4S52D3vl3/LxyJA1bqqxvr8T5HBSZODVM6SV0LlQ8JHwKqVAJdCqvAgbT 10EPuYZRoY/kG2fFkV5dEOz0N+IkFa/cPqFfLykgD8Q5cRbYhZQGoRWjMXIOyJfkZGT4 S4+7/aT2S5kVNG2T1lcn6T06gDSHriG8d3KD4+TDjheK2D2MXt5Z1wcaE5Efg8HWZZ6K IzAAv6IqRLh9HyOBYLiB4+MNdV7ndYUisM6gQrKIWeiRtHoovqe/dI4sd3Bw2TB/30wL pMcXFuZL2cZ5u3A/Xo21vZ6SMIKyU+EtLm4hw+AAsNaLXwuc56QQ7JOd8hWc3Hew2F40 kMdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748460346; x=1749065146; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p8XQsIys0bjXBF6Rjgp0AQXhuEMtKRZMh2pOpwp/DPs=; b=l9s3gKZvqC44i75Ql4URbvhSyhcN3ZuVgnvJlBn4Fk0qaETf74McrARVAHVZ07i6QE v8sIt3XyFmOAS6rDRIg2iov+C7noUw+xvL0Hk2xCDZzgnOmd7/idZDb7NAUhId4Ki5Lo 94lQfPsoXhVZTTzNnmCbZr8NRyopS4F3J6yVUpk2eiTPlacrnrohg+7KflW5JAfsxeBX 4hkkz21fqU/32dCSfgiwF4Jjp2veoVQebgoYcAd3U4Trh6/kgEMes/oFQebU9iHgx58A iGS/jQNf3IqROPsaYvKsixKBqYl7S2qOhmOTNMtgN7CYzkCBEYcU5azYxX1UxkM3Pg5X CQag== X-Gm-Message-State: AOJu0YwAfnWZM3LRu50KCzdqAfmE/1VKc7pgEu0RSvIgrNlA2iZEzu3k 5Kvz064maYCdhRee+Yox5RJm/7J/Poh8dIXiirMtMk9nuRe/1svJZj3yZnN/3eCQJphX0g== X-Gm-Gg: ASbGnct7L6vFjE7Y9fC7Wn+t/gtyWKAKcKMlkV0tGYEcX0NrdokMG0o9ZgGY29df9TT PnjFfEYKOfDfvGJ5eTQ0KKfZkHp35WWpcQuWzxnLrguh/FYdqwyisrI0xjIvx3svHRUJVG0KIsl HCX5Gs4bjh2y8h+akjnRZUnCMXWqptSAKWlT6d4rjaFu8BozNc0KiTM3X0EaKW7NfsxykNUaYo8 RpYX3LNcsWIIiVdiLD7fWh2gv/lT7IAaFsBbsKKcQOKxZh8XZ1OCkIRdgQLISrmcY/gUA+9FXp5 WYgEQNH15ZFAeku3qvMOybsnE1Uw8DL8DOXhhWsnO3cxIZ1H1p0SUR3fk6aEaQ== X-Google-Smtp-Source: AGHT+IGWap/Yd0Jj7I4I6jYJ8OdX5B9WHnbpr2XZCTR1PPXgPjGTfURdBjfUbAYuOsu/ZWNucRS5vg== X-Received: by 2002:a17:902:f645:b0:234:c5c1:9b84 with SMTP id d9443c01a7336-234c5d0e07emr62053125ad.37.1748460346383; Wed, 28 May 2025 12:25:46 -0700 (PDT) From: Tanish Desai To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, stefanha@gmail.com, mads@ynddal.dk, Tanish Desai Subject: [PATCH] trace/simple: seperate hot paths of tracing fucntions Date: Wed, 28 May 2025 19:25:28 +0000 Message-Id: <20250528192528.3968-1-tanishdesai37@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2607:f8b0:4864:20::629; envelope-from=tanishdesai37@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1748460424680116600 This change improves performance by moving the hot path of the trace_vhost_= commit()(or any other trace function) logic to the header file. Previously, even when the trace event was disabled, the function call chain= :- trace_vhost_commit()(Or any other trace function) =E2=86=92 _nocheck__tra= ce_vhost_commit() =E2=86=92 _simple_trace_vhost_commit() incurred a significant function prologue overhead before checking the trac= e state. Disassembly of _simple_trace_vhost_commit() (from the .c file) showed that = 11 out of the first 14 instructions were prologue-related, including: 0x10 stp x29, x30, [sp, #-64]! Prologue: allocates 64-byte frame and saves = old FP (x29) & LR (x30) 0x14 adrp x3, trace_events_enabled_count Prologue: computes page-base of th= e trace-enable counter 0x18 adrp x2, __stack_chk_guard Important (maybe prolog don't know?)(stack-= protector): starts up the stack-canary load 0x1c mov x29, sp Prologue: sets new frame pointer 0x20 ldr x3, [x3] Prologue: loads the actual trace-enabled count 0x24 stp x19, x20, [sp, #16] Prologue: spills callee-saved regs used by thi= s function (x19, x20) 0x28 and w20, w0, #0xff Tracepoint setup: extracts the low-8 bits of arg0 a= s the =E2=80=9Cevent boolean=E2=80=9D 0x2c ldr x2, [x2] Prologue (cont=E2=80=99d): completes loading of the stack= -canary value 0x30 and w19, w1, #0xff Tracepoint setup: extracts low-8 bits of arg1 0x34 ldr w0, [x3] Important: loads the current trace-enabled flag from memo= ry 0x38 ldr x1, [x2] Prologue (cont=E2=80=99d): reads the canary 0x3c str x1, [sp, #56] Prologue (cont=E2=80=99d): writes the canary into th= e new frame 0x40 mov x1, #0 Prologue (cont=E2=80=99d): zeroes out x1 for the upcoming b= ranch test 0x44 cbnz w0, 0x88 Important: if tracing is disabled (w0=3D=3D0) skip the h= eavy path entirely The trace-enabled check happens after the prologue. This is wasteful when t= racing is disabled, which is often the case in production. To optimize this: _nocheck__trace_vhost_commit() is now fully inlined in the .h file with the hot path.It checks trace_event_get_state() before calling into _simple_= trace_vhost_commit(), which remains in .c. This avoids calling into the .c function altogether when the tracepoint is = disabled, thereby skipping unnecessary prologue instructions. This results in better performance by removing redundant instructions in th= e tracing fast path. Signed-off-by: Tanish Desai --- scripts/tracetool/backend/simple.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backen= d/simple.py index a74d61fcd6..2688d4b64b 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -36,8 +36,17 @@ def generate_h_begin(events, group): =20 =20 def generate_h(event, group): - out(' _simple_%(api)s(%(args)s);', + event_id =3D 'TRACE_' + event.name.upper() + if "vcpu" in event.properties: + # already checked on the generic format code + cond =3D "true" + else: + cond =3D "trace_event_get_state(%s)" % event_id + out(' if (%(cond)s) {', + ' _simple_%(api)s(%(args)s);', + ' }', api=3Devent.api(), + cond=3Dcond, args=3D", ".join(event.args.names())) =20 =20 @@ -72,22 +81,10 @@ def generate_c(event, group): if len(event.args) =3D=3D 0: sizestr =3D '0' =20 - event_id =3D 'TRACE_' + event.name.upper() - if "vcpu" in event.properties: - # already checked on the generic format code - cond =3D "true" - else: - cond =3D "trace_event_get_state(%s)" % event_id - out('', - ' if (!%(cond)s) {', - ' return;', - ' }', - '', ' if (trace_record_start(&rec, %(event_obj)s.id, %(size_str)s))= {', ' return; /* Trace Buffer Full, Event Dropped ! */', ' }', - cond=3Dcond, event_obj=3Devent.api(event.QEMU_EVENT), size_str=3Dsizestr) =20 --=20 2.34.1