From patchwork Mon Feb 17 19:58:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13978607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55FADC021A9 for ; Mon, 17 Feb 2025 20:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DovHiFkS365bHoIydr70YQBU31NNAZaaV/7cicQP0YI=; b=w4gqoPM7o5lpKeBr3v5vtQ0MrM fL5Xv6RkzDLcQttP+0Cs5+X2FXKiaJyEhuMLhfYFOeQkkqqciiirPaeXum7IY7aAgHcG2HqDO5D/i vEIooFcU6Deg6y4vWONXokWTQytZCK8vAiv/z2qLS34U3gnVynZi4IBFy+SFiwECoOE8vWFLoyu2J pkgxjUNOHH0FIVhZQdmJamemPlKSf/1WHmxihUgxv1SZ4lXHzwtFxW9zMy4kGCg3uSJ+7mJr7rWWY aROBmGX4lTM1FeWVeDUBkXBHzIO6xU0kUQU1YtFVy6gsW51b7pR1EHLGK75f7MmR2JFgSBWRv1VgY B0FlXvkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tk7gP-00000005t8l-1Kef; Mon, 17 Feb 2025 20:25:37 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tk7H4-00000005opa-2vsd for linux-arm-kernel@lists.infradead.org; Mon, 17 Feb 2025 19:59:27 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 57CB5152B; Mon, 17 Feb 2025 11:59:45 -0800 (PST) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.2.76.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D40643F6A8; Mon, 17 Feb 2025 11:59:23 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , James Clark , Mike Leach , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , Will Deacon , Graham Woodward , Paschalis.Mpeis@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 03/12] perf script: Separate events from branch types Date: Mon, 17 Feb 2025 19:58:59 +0000 Message-Id: <20250217195908.176207-4-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217195908.176207-1-leo.yan@arm.com> References: <20250217195908.176207-1-leo.yan@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250217_115926_824551_85FA0CFD X-CRM114-Status: GOOD ( 18.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Branch types and events are two different things. A branch type can be a conditional branch, an indirect branch, a procedure call, a return, or an exception taken, etc. The extra event information is provided for what happens during a branch, e.g. if a branch is mispredicted or not taken (specific to conditional branches). To deliver information about branches, this commit separates events from branch types. It parses branch types first, then appends event strings embraced by the '/' character. If multiple events occur, the events is separated with a comma (,). Also add a minor improvement by adding char 'm' in char array for branch mispredict event. Below are extracted sample flags. Before: branch: br miss instructions: br miss After: branch: jmp/miss/ instructions: jmp/miss/ Reviewed-by: Ian Rogers Reviewed-by: James Clark Signed-off-by: Leo Yan --- tools/perf/util/event.h | 5 +++- tools/perf/util/trace-event-scripting.c | 36 ++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index cd75efc09834..962fbc1714cf 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -69,7 +69,7 @@ enum { PERF_IP_FLAG_BRANCH_MISS = 1ULL << 15, }; -#define PERF_IP_FLAG_CHARS "bcrosyiABExghDt" +#define PERF_IP_FLAG_CHARS "bcrosyiABExghDtm" #define PERF_ADDITIONAL_STATE_MASK \ (PERF_IP_FLAG_IN_TX | \ @@ -90,6 +90,9 @@ enum { PERF_IP_FLAG_VMENTRY |\ PERF_IP_FLAG_VMEXIT) +#define PERF_IP_FLAG_BRACH_EVENT_MASK \ + PERF_IP_FLAG_BRANCH_MISS + #define PERF_MEM_DATA_SRC_NONE \ (PERF_MEM_S(OP, NA) |\ PERF_MEM_S(LVL, NA) |\ diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index 712ba3a51bbe..55d7e4e612d5 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -309,7 +309,14 @@ static const struct { {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry"}, {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, + {0, NULL} +}; + +static const struct { + u32 flags; + const char *name; +} branch_events[] = { + {PERF_IP_FLAG_BRANCH_MISS, "miss"}, {0, NULL} }; @@ -317,8 +324,9 @@ static int sample_flags_to_name(u32 flags, char *str, size_t size) { int i; const char *prefix; - int pos = 0, ret; + int pos = 0, ret, ev_idx = 0; u32 xf = flags & PERF_ADDITIONAL_STATE_MASK; + u32 types, events; char xs[16] = { 0 }; /* Clear additional state bits */ @@ -338,8 +346,9 @@ static int sample_flags_to_name(u32 flags, char *str, size_t size) flags &= ~(PERF_IP_FLAG_TRACE_BEGIN | PERF_IP_FLAG_TRACE_END); + types = flags & ~PERF_IP_FLAG_BRACH_EVENT_MASK; for (i = 0; sample_flags[i].name; i++) { - if (sample_flags[i].flags != flags) + if (sample_flags[i].flags != types) continue; ret = snprintf(str + pos, size - pos, "%s", sample_flags[i].name); @@ -349,6 +358,27 @@ static int sample_flags_to_name(u32 flags, char *str, size_t size) break; } + events = flags & PERF_IP_FLAG_BRACH_EVENT_MASK; + for (i = 0; branch_events[i].name; i++) { + if (!(branch_events[i].flags & events)) + continue; + + ret = snprintf(str + pos, size - pos, !ev_idx ? "/%s" : ",%s", + branch_events[i].name); + if (ret < 0) + return ret; + pos += ret; + ev_idx++; + } + + /* Add an end character '/' for events */ + if (ev_idx) { + ret = snprintf(str + pos, size - pos, "/"); + if (ret < 0) + return ret; + pos += ret; + } + if (!xf) return pos;