Skip to content

Commit 3b0a18c

Browse files
captain5050acmel
authored andcommitted
perf record: Don't clear event's period if set by a term
If events in a group explicitly set a frequency or period with leader sampling, don't disable the samples on those events. Prior to 5.8: perf record -e '{cycles/period=12345000/,instructions/period=6789000/}:S' would clear the attributes then apply the config terms. In commit 5f34278 leader sampling configuration was moved to after applying the config terms, in the example, making the instructions' event have its period cleared. This change makes it so that sampling is only disabled if configuration terms aren't present. Committer testing: Before: # perf record -e '{cycles/period=1/,instructions/period=2/}:S' sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.051 MB perf.data (6 samples) ] # # perf evlist -v cycles/period=1/: size: 120, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, disabled: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 instructions/period=2/: size: 120, config: 0x1, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, sample_id_all: 1, exclude_guest: 1 # After: # perf record -e '{cycles/period=1/,instructions/period=2/}:S' sleep 0.0001 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.052 MB perf.data (4 samples) ] # perf evlist -v cycles/period=1/: size: 120, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, disabled: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 instructions/period=2/: size: 120, config: 0x1, { sample_period, sample_freq }: 2, sample_type: IP|TID|TIME|READ|ID, read_format: ID|GROUP, sample_id_all: 1, exclude_guest: 1 # Fixes: 5f34278 ("perf evlist: Move leader-sampling configuration") Signed-off-by: Ian Rogers <[email protected]> Acked-by: Adrian Hunter <[email protected]> Acked-by: Jiri Olsa <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Athira Jajeev <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: John Fastabend <[email protected]> Cc: KP Singh <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Yonghong Song <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2fa3fc9 commit 3b0a18c

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

tools/perf/util/record.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "debug.h"
33
#include "evlist.h"
44
#include "evsel.h"
5+
#include "evsel_config.h"
56
#include "parse-events.h"
67
#include <errno.h>
78
#include <limits.h>
@@ -33,11 +34,24 @@ static struct evsel *evsel__read_sampler(struct evsel *evsel, struct evlist *evl
3334
return leader;
3435
}
3536

37+
static u64 evsel__config_term_mask(struct evsel *evsel)
38+
{
39+
struct evsel_config_term *term;
40+
struct list_head *config_terms = &evsel->config_terms;
41+
u64 term_types = 0;
42+
43+
list_for_each_entry(term, config_terms, list) {
44+
term_types |= 1 << term->type;
45+
}
46+
return term_types;
47+
}
48+
3649
static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *evlist)
3750
{
3851
struct perf_event_attr *attr = &evsel->core.attr;
3952
struct evsel *leader = evsel->leader;
4053
struct evsel *read_sampler;
54+
u64 term_types, freq_mask;
4155

4256
if (!leader->sample_read)
4357
return;
@@ -47,16 +61,20 @@ static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *ev
4761
if (evsel == read_sampler)
4862
return;
4963

64+
term_types = evsel__config_term_mask(evsel);
5065
/*
51-
* Disable sampling for all group members other than the leader in
52-
* case the leader 'leads' the sampling, except when the leader is an
53-
* AUX area event, in which case the 2nd event in the group is the one
54-
* that 'leads' the sampling.
66+
* Disable sampling for all group members except those with explicit
67+
* config terms or the leader. In the case of an AUX area event, the 2nd
68+
* event in the group is the one that 'leads' the sampling.
5569
*/
56-
attr->freq = 0;
57-
attr->sample_freq = 0;
58-
attr->sample_period = 0;
59-
attr->write_backward = 0;
70+
freq_mask = (1 << EVSEL__CONFIG_TERM_FREQ) | (1 << EVSEL__CONFIG_TERM_PERIOD);
71+
if ((term_types & freq_mask) == 0) {
72+
attr->freq = 0;
73+
attr->sample_freq = 0;
74+
attr->sample_period = 0;
75+
}
76+
if ((term_types & (1 << EVSEL__CONFIG_TERM_OVERWRITE)) == 0)
77+
attr->write_backward = 0;
6078

6179
/*
6280
* We don't get a sample for slave events, we make them when delivering

0 commit comments

Comments
 (0)