File perf-evsel-Override-attr-sample_period-for-non-libpfm4-events.patch of Package perf
93
1
From: German Gomez <german.gomez@arm.com>
2
Date: Tue, 18 Jan 2022 14:40:54 +0000
3
Subject: perf evsel: Override attr->sample_period for non-libpfm4 events
4
MIME-Version: 1.0
5
Content-Type: text/plain; charset=UTF-8
6
Content-Transfer-Encoding: 8bit
7
Git-commit: 3606c0e1a1050d397ad759a62607e419fd8b0ccb
8
Patch-mainline: v5.17-rc1
9
References: git-fixes
10
X-Info: adjust for context, no eb39bf325631f9ae185abd16281079b7b9858737
11
12
13
A previous patch preventing "attr->sample_period" values from being
14
overridden in pfm events changed a related behaviour in arm-spe.
15
16
Before said patch:
17
18
perf record -c 10000 -e arm_spe_0// -- sleep 1
19
20
Would yield an SPE event with period=10000. After the patch, the period
21
in "-c 10000" was being ignored because the arm-spe code initializes
22
sample_period to a non-zero value.
23
24
This patch restores the previous behaviour for non-libpfm4 events.
25
26
Fixes: ae5dcc8abe31 (“perf record: Prevent override of attr->sample_period for libpfm4 events”)
27
Reported-by: Chase Conklin <chase.conklin@arm.com>
28
Signed-off-by: German Gomez <german.gomez@arm.com>
29
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
30
Cc: Ian Rogers <irogers@google.com>
31
Cc: Jiri Olsa <jolsa@redhat.com>
32
Cc: John Fastabend <john.fastabend@gmail.com>
33
Cc: KP Singh <kpsingh@kernel.org>
34
Cc: Mark Rutland <mark.rutland@arm.com>
35
Cc: Martin KaFai Lau <kafai@fb.com>
36
Cc: Namhyung Kim <namhyung@kernel.org>
37
Cc: Song Liu <songliubraving@fb.com>
38
Cc: Stephane Eranian <eranian@google.com>
39
Cc: Yonghong Song <yhs@fb.com>
40
Cc: bpf@vger.kernel.org
41
Cc: netdev@vger.kernel.org
42
Link: http://lore.kernel.org/lkml/20220118144054.2541-1-german.gomez@arm.com
43
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
44
Signed-off-by: Tony Jones <tonyj@suse.de>
45
---
46
tools/perf/util/evsel.c | 25 +++++++++++++++++--------
47
1 file changed, 17 insertions(+), 8 deletions(-)
48
49
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
50
index fb0a2debf015..22d3267ce294 100644
51
--- a/tools/perf/util/evsel.c
52
+++ b/tools/perf/util/evsel.c
53
54
evsel__set_sample_bit(evsel, WEIGHT);
55
}
56
57
+static void evsel__set_default_freq_period(struct record_opts *opts,
58
+ struct perf_event_attr *attr)
59
+{
60
+ if (opts->freq) {
61
+ attr->freq = 1;
62
+ attr->sample_freq = opts->freq;
63
+ } else {
64
+ attr->sample_period = opts->default_interval;
65
+ }
66
+}
67
+
68
/*
69
* The enable_on_exec/disabled value strategy:
70
*
71
72
* We default some events to have a default interval. But keep
73
* it a weak assumption overridable by the user.
74
*/
75
- if (!attr->sample_period) {
76
- if (opts->freq) {
77
- attr->freq = 1;
78
- attr->sample_freq = opts->freq;
79
- } else {
80
- attr->sample_period = opts->default_interval;
81
- }
82
- }
83
+ if ((evsel->is_libpfm_event && !attr->sample_period) ||
84
+ (!evsel->is_libpfm_event && (!attr->sample_period ||
85
+ opts->user_freq != UINT_MAX ||
86
+ opts->user_interval != ULLONG_MAX)))
87
+ evsel__set_default_freq_period(opts, attr);
88
+
89
/*
90
* If attr->freq was set (here or earlier), ask for period
91
* to be sampled.
92
93