From: "tip-bot2 for Yabin Cui" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Namhyung Kim <namhyung@kernel.org>, Yabin Cui <yabinc@google.com>,
Ingo Molnar <mingo@kernel.org>, Ian Rogers <irogers@google.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: perf/core] perf/core: Check sample_type in perf_sample_save_brstack
Date: Tue, 19 Nov 2024 08:48:48 -0000 [thread overview]
Message-ID: <173200612891.412.3701761326460054209.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20240515193610.2350456-4-yabinc@google.com>
The following commit has been merged into the perf/core branch of tip:
Commit-ID: faac6f105ef169e2e5678c14e1ffebf2a7d780b6
Gitweb: https://git.kernel.org/tip/faac6f105ef169e2e5678c14e1ffebf2a7d780b6
Author: Yabin Cui <yabinc@google.com>
AuthorDate: Wed, 15 May 2024 12:36:09 -07:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 19 Nov 2024 09:23:42 +01:00
perf/core: Check sample_type in perf_sample_save_brstack
Check sample_type in perf_sample_save_brstack() to prevent
saving branch stack data when it isn't required.
Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Yabin Cui <yabinc@google.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240515193610.2350456-4-yabinc@google.com
---
arch/x86/events/amd/core.c | 3 +--
arch/x86/events/core.c | 3 +--
arch/x86/events/intel/ds.c | 3 +--
include/linux/perf_event.h | 15 ++++++++++-----
4 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index b4a1a25..30d6ceb 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -1001,8 +1001,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
if (!x86_perf_event_set_period(event))
continue;
- if (has_branch_stack(event))
- perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
+ perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
if (perf_event_overflow(event, &data, regs))
x86_pmu_stop(event, 0);
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index c75c482..8f218ac 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1707,8 +1707,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs)
perf_sample_data_init(&data, 0, event->hw.last_period);
- if (has_branch_stack(event))
- perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
+ perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
if (perf_event_overflow(event, &data, regs))
x86_pmu_stop(event, 0);
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 4990a24..acfd872 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -1888,8 +1888,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,
if (x86_pmu.intel_cap.pebs_format >= 3)
setup_pebs_time(event, data, pebs->tsc);
- if (has_branch_stack(event))
- perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL);
+ perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL);
}
static void adaptive_pebs_save_regs(struct pt_regs *regs,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 3ac202d..bf831b1 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1320,6 +1320,11 @@ static inline void perf_sample_save_raw_data(struct perf_sample_data *data,
data->sample_flags |= PERF_SAMPLE_RAW;
}
+static inline bool has_branch_stack(struct perf_event *event)
+{
+ return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
+}
+
static inline void perf_sample_save_brstack(struct perf_sample_data *data,
struct perf_event *event,
struct perf_branch_stack *brs,
@@ -1327,6 +1332,11 @@ static inline void perf_sample_save_brstack(struct perf_sample_data *data,
{
int size = sizeof(u64); /* nr */
+ if (!has_branch_stack(event))
+ return;
+ if (WARN_ON_ONCE(data->sample_flags & PERF_SAMPLE_BRANCH_STACK))
+ return;
+
if (branch_sample_hw_index(event))
size += sizeof(u64);
size += brs->nr * sizeof(struct perf_branch_entry);
@@ -1716,11 +1726,6 @@ static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
# define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs)
#endif
-static inline bool has_branch_stack(struct perf_event *event)
-{
- return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
-}
-
static inline bool needs_branch_stack(struct perf_event *event)
{
return event->attr.branch_sample_type != 0;
next prev parent reply other threads:[~2024-11-19 8:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 19:36 [PATCH v5 0/3] perf/core: Check sample_type in sample data saving helper functions Yabin Cui
2024-05-15 19:36 ` [PATCH v5 1/3] perf/core: Save raw sample data conditionally based on sample type Yabin Cui
2024-11-19 8:48 ` [tip: perf/core] " tip-bot2 for Yabin Cui
2024-05-15 19:36 ` [PATCH v5 2/3] perf/core: Check sample_type in perf_sample_save_callchain Yabin Cui
2024-11-19 8:48 ` [tip: perf/core] " tip-bot2 for Yabin Cui
2024-05-15 19:36 ` [PATCH v5 3/3] perf/core: Check sample_type in perf_sample_save_brstack Yabin Cui
2024-11-19 8:48 ` tip-bot2 for Yabin Cui [this message]
2024-05-22 16:26 ` [PATCH v5 0/3] perf/core: Check sample_type in sample data saving helper functions Namhyung Kim
2024-05-28 17:59 ` Yabin Cui
2024-06-11 20:33 ` Yabin Cui
2024-11-19 8:27 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=173200612891.412.3701761326460054209.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=x86@kernel.org \
--cc=yabinc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®