Fixes for setting event freq/periods
Subsystems (4)
Ian Rogers
reviewerv3 cover Fixes for setting event freq/periods
Some fixes that address issues for regular and pfm4 events with 2 additional perf_event_attr tests. Various authors, David Sharp isn't currently at Google.
v3. moved a loop into a helper following Adrian Hunter's suggestion. v2. corrects the commit message following Athira Rajeev's suggestion.
David Sharp (1):
perf record: Set PERF_RECORD_PERIOD if attr->freq is set.
Ian Rogers (2):
perf record: Don't clear event's period if set by a term perf test: Leader sampling shouldn't clear sample period
Stephane Eranian (1):
perf record: Prevent override of attr->sample_period for libpfm4
events
tools/perf/tests/attr/README | 1 + tools/perf/tests/attr/test-record-group2 | 29 ++++++++++++++++++++ tools/perf/util/evsel.c | 10 ++++--- tools/perf/util/record.c | 34 ++++++++++++++++++------ 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tools/perf/tests/attr/test-record-group2
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Ian Rogers
reviewerPATCH v3 1/4 perf record: Set PERF_RECORD_PERIOD if attr->freq is set.
From: David Sharp <[email protected]>
evsel__config() would only set PERF_RECORD_PERIOD if it set attr->freq from perf record options. When it is set by libpfm events, it would not get set. This changes evsel__config to see if attr->freq is set outside of whether or not it changes attr->freq itself.
--- tools/perf/util/evsel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +6 -1
@@ -979,13 +979,18 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,if (!attr->sample_period || (opts->user_freq !=UINT_MAX || opts->user_interval !=ULLONG_MAX )) {if (opts->freq) { -evsel__set_sample_bit (evsel,PERIOD ); attr->freq =1 ; attr->sample_freq = opts->freq; }else { attr->sample_period = opts->default_interval; } } +/* +* If attr->freq was set (here or earlier), ask for period +* to be sampled. +*/ +if (attr->freq) +evsel__set_sample_bit (evsel,PERIOD );if (opts->no_samples) attr->sample_freq =0 ;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Ian Rogers
reviewerPATCH v3 2/4 perf record: Prevent override of attr->sample_period for libpfm4 events
In reply to Ian RogersFrom: Stephane Eranian <[email protected]>
Before:
$ perf record -c 10000 --pfm-events=cycles:period=77777
Would yield a cycles event with period=10000, instead of 77777.
This was due to an ordering issue between libpfm4 parsing the event string and perf record initializing the event.
This patch fixes the problem by preventing override for events with attr->sample_period != 0 by the time perf_evsel__config() is invoked. This seems to have been the intent of the author.
--- tools/perf/util/evsel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/evsel.c +1 -2
@@ -976,8 +976,7 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,* We default some events to have a default interval. But keep * it a weak assumption overridable by the user. */ -if (!attr->sample_period || (opts->user_freq !=UINT_MAX || - opts->user_interval !=ULLONG_MAX )) { +if (!attr->sample_period) {if (opts->freq) { attr->freq =1 ; attr->sample_freq = opts->freq;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Ian Rogers
reviewerPATCH v3 3/4 perf record: Don't clear event's period if set by a term
In reply to Ian RogersIf 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 5f34278867b7 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.
--- tools/perf/util/record.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
tools/perf/util/record.c +26 -8
@@ -2,6 +2,7 @@#include "debug.h" #include "evlist.h" #include "evsel.h" +#include "evsel_config.h" #include "parse-events.h" #include <errno.h> #include <limits.h>
@@ -33,11 +34,24 @@ static struct evsel *evsel__read_sampler(struct evsel *evsel, struct evlist *evlreturn leader; } +static u64 evsel__config_term_mask (struct evsel *evsel) +{ +struct evsel_config_term *term; +struct list_head *config_terms = &evsel->config_terms; +u64 term_types =0 ; + +list_for_each_entry (term, config_terms, list) { + term_types |=1 << term->type; + } +return term_types; +} +static void evsel__config_leader_sampling (struct evsel *evsel,struct evlist *evlist) {struct perf_event_attr *attr = &evsel->core.attr;struct evsel *leader = evsel->leader;struct evsel *read_sampler; +u64 term_types, freq_mask;if (!leader->sample_read)return ;
@@ -47,16 +61,20 @@ static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *evif (evsel == read_sampler)return ; + term_types =evsel__config_term_mask (evsel);/* -* Disable sampling for all group members other than the leader in -* case the leader 'leads' the sampling, except when the leader is an -* AUX area event, in which case the 2nd event in the group is the one -* that 'leads' the sampling. +* Disable sampling for all group members except those with explicit +* config terms or the leader. In the case of an AUX area event, the 2nd +* event in the group is the one that 'leads' the sampling. */ - attr->freq =0 ; - attr->sample_freq =0 ; - attr->sample_period =0 ; - attr->write_backward =0 ; + freq_mask = (1 <<EVSEL__CONFIG_TERM_FREQ ) | (1 <<EVSEL__CONFIG_TERM_PERIOD ); +if ((term_types & freq_mask) ==0 ) { + attr->freq =0 ; + attr->sample_freq =0 ; + attr->sample_period =0 ; + } +if ((term_types & (1 <<EVSEL__CONFIG_TERM_OVERWRITE )) ==0 ) + attr->write_backward =0 ;/* * We don't get a sample for slave events, we make them when delivering
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
Quoted 12 lines · Ian Rogers
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 commit5f34278867b7leader 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.
Quoted 2 lines
Fixes 5f34278867b7 ("perf evlist: Move leader-sampling configuration")Signed-off-by Ian Rogers <[email protected]>
Quoted 71 lines
--- tools/perf/util/record.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)tools/perf/util/record.c +26
-8@@ -2,6 +2,7 @@#include "debug.h" #include "evlist.h" #include "evsel.h" +#include "evsel_config.h" #include "parse-events.h" #include <errno.h> #include <limits.h> @@ -33,11 +34,24 @@ static struct evsel *evsel__read_sampler(struct evsel *evsel, struct evlist *evlreturn leader; } +static u64 evsel__config_term_mask (struct evsel *evsel) +{ +struct evsel_config_term *term; +struct list_head *config_terms = &evsel->config_terms; +u64 term_types =0 ; + +list_for_each_entry (term, config_terms, list) { + term_types |=1 << term->type; + } +return term_types; +} +static void evsel__config_leader_sampling (struct evsel *evsel,struct evlist *evlist) {struct perf_event_attr *attr = &evsel->core.attr;struct evsel *leader = evsel->leader;struct evsel *read_sampler; +u64 term_types, freq_mask;if (!leader->sample_read)return ;@@ -47,16 +61,20 @@ static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *evif (evsel == read_sampler)return ; + term_types =evsel__config_term_mask (evsel);/* -* Disable sampling for all group members other than the leader in -* case the leader 'leads' the sampling, except when the leader is an -* AUX area event, in which case the 2nd event in the group is the one -* that 'leads' the sampling. +* Disable sampling for all group members except those with explicit +* config terms or the leader. In the case of an AUX area event, the 2nd +* event in the group is the one that 'leads' the sampling. */ - attr->freq =0 ; - attr->sample_freq =0 ; - attr->sample_period =0 ; - attr->write_backward =0 ; + freq_mask = (1 <<EVSEL__CONFIG_TERM_FREQ ) | (1 <<EVSEL__CONFIG_TERM_PERIOD ); +if ((term_types & freq_mask) ==0 ) { + attr->freq =0 ; + attr->sample_freq =0 ; + attr->sample_period =0 ; + } +if ((term_types & (1 <<EVSEL__CONFIG_TERM_OVERWRITE )) ==0 ) + attr->write_backward =0 ;/* * We don't get a sample for slave events, we make them when delivering
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
In reply to Ian RogersEm Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
Quoted 11 lines
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 commit5f34278867b7leader 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.
Adrian, Jiri, can you please take a look a this and provide Reviewed-by or Acked-by tags?
- Arnaldo
Quoted 75 lines
Fixes 5f34278867b7 ("perf evlist: Move leader-sampling configuration")Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/record.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)tools/perf/util/record.c +26
-8@@ -2,6 +2,7 @@#include "debug.h" #include "evlist.h" #include "evsel.h" +#include "evsel_config.h" #include "parse-events.h" #include <errno.h> #include <limits.h> @@ -33,11 +34,24 @@ static struct evsel *evsel__read_sampler(struct evsel *evsel, struct evlist *evlreturn leader; } +static u64 evsel__config_term_mask (struct evsel *evsel) +{ +struct evsel_config_term *term; +struct list_head *config_terms = &evsel->config_terms; +u64 term_types =0 ; + +list_for_each_entry (term, config_terms, list) { + term_types |=1 << term->type; + } +return term_types; +} +static void evsel__config_leader_sampling (struct evsel *evsel,struct evlist *evlist) {struct perf_event_attr *attr = &evsel->core.attr;struct evsel *leader = evsel->leader;struct evsel *read_sampler; +u64 term_types, freq_mask;if (!leader->sample_read)return ;@@ -47,16 +61,20 @@ static void evsel__config_leader_sampling(struct evsel *evsel, struct evlist *evif (evsel == read_sampler)return ; + term_types =evsel__config_term_mask (evsel);/* -* Disable sampling for all group members other than the leader in -* case the leader 'leads' the sampling, except when the leader is an -* AUX area event, in which case the 2nd event in the group is the one -* that 'leads' the sampling. +* Disable sampling for all group members except those with explicit +* config terms or the leader. In the case of an AUX area event, the 2nd +* event in the group is the one that 'leads' the sampling. */ - attr->freq =0 ; - attr->sample_freq =0 ; - attr->sample_period =0 ; - attr->write_backward =0 ; + freq_mask = (1 <<EVSEL__CONFIG_TERM_FREQ ) | (1 <<EVSEL__CONFIG_TERM_PERIOD ); +if ((term_types & freq_mask) ==0 ) { + attr->freq =0 ; + attr->sample_freq =0 ; + attr->sample_period =0 ; + } +if ((term_types & (1 <<EVSEL__CONFIG_TERM_OVERWRITE )) ==0 ) + attr->write_backward =0 ;/* * We don't get a sample for slave events, we make them when delivering Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Signature · 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
Em Mon, Sep 14, 2020 at 06:46:55PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 13 lines
Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
Quoted 11 lines
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 commit5f34278867b7leader 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.
Quoted 2 lines
Adrian, Jiri, can you please take a look a this and provide Reviewed-by or Acked-by tags?
Without this patch we have:
# 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
#So indeed the period=2 is being cleared for the second event in that group.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
Quoted 29 lines · Arnaldo Carvalho de Melo
Em Mon, Sep 14, 2020 at 06:46:55PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 13 lines
Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
Quoted 11 lines
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 commit5f34278867b7leader 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.Quoted 2 lines
Adrian, Jiri, can you please take a look a this and provide Reviewed-by or Acked-by tags?
Without this patch we have:
# 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 #
Quoted 4 lines
So indeed the period=2 is being cleared for the second event in that group.
- Arnaldo
Thanks Arnaldo and Adrian! Adrian's acked-by is here:
https://lore.kernel.org/lkml/[email protected]/
Let me know if anything is missing.
Ian
Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
Em Mon, Sep 14, 2020 at 02:52:57PM -0700, Ian Rogers escreveu:
Quoted 31 lines
Quoted 29 lines · Arnaldo Carvalho de Melo
Em Mon, Sep 14, 2020 at 06:46:55PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 13 lines
Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
Quoted 11 lines
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 commit5f34278867b7leader 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.Quoted 2 lines
Adrian, Jiri, can you please take a look a this and provide Reviewed-by or Acked-by tags?
Without this patch we have:
# 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 #
Quoted 8 lines
Quoted 4 lines
So indeed the period=2 is being cleared for the second event in that group.
- Arnaldo
Thanks Arnaldo and Adrian! Adrian's acked-by is here:
https://lore.kernel.org/lkml/[email protected]/
Let me know if anything is missing.
Thanks, applied.
- Arnaldo
Ian Rogers
reviewerPATCH v3 4/4 perf test: Leader sampling shouldn't clear sample period
In reply to Ian RogersAdd test that a sibling with leader sampling doesn't have its period cleared.
--- tools/perf/tests/attr/README | 1 + tools/perf/tests/attr/test-record-group2 | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tools/perf/tests/attr/test-record-group2
tools/perf/tests/attr/README +1 -0
@@ -49,6 +49,7 @@ Following tests are defined (with perf commands): perf record --call-graph fp kill (test-record-graph-fp) perf record --group -e cycles,instructions kill (test-record-group) perf record -e '{cycles,instructions}' kill (test-record-group1) + perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2) perf record -D kill (test-record-no-delay) perf record -i kill (test-record-no-inherit) perf record -n kill (test-record-no-samples)
tools/perf/tests/attr/test-record-group2 new file +29 -0
@@ -0,0 +1,29 @@ +[config] +command = record +args = --no-bpf-event -e '{cycles/period=1234000/,instructions/period=6789000/}:S' kill >/dev/null 2>&1 +ret = 1 + +[event-1:base-record] +fd=1 +group_fd=-1 +config=0|1 +sample_period=1234000 +sample_type=87 +read_format=12 +inherit=0 +freq=0 + +[event-2:base-record] +fd=2 +group_fd=1 +config=0|1 +sample_period=6789000 +sample_type=87 +read_format=12 +disabled=0 +inherit=0 +mmap=0 +comm=0 +freq=0 +enable_on_exec=0 +task=0
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Re: [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period
Em Fri, Sep 11, 2020 at 07:56:55PM -0700, Ian Rogers escreveu:
Quoted 2 lines
Add test that a sibling with leader sampling doesn't have its period cleared.
Thanks, applied and collected Jiri's Acks for [34]/4 and Adrian's for 3/4.
- Arnaldo
Quoted 57 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/tests/attr/README | 1 + tools/perf/tests/attr/test-record-group2 | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tools/perf/tests/attr/test-record-group2tools/perf/tests/attr/README +1
-0@@ -49,6 +49,7 @@ Following tests are defined (with perf commands): perf record --call-graph fp kill (test-record-graph-fp) perf record --group -e cycles,instructions kill (test-record-group) perf record -e '{cycles,instructions}' kill (test-record-group1) + perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2) perf record -D kill (test-record-no-delay) perf record -i kill (test-record-no-inherit) perf record -n kill (test-record-no-samples)tools/perf/tests/attr/test-record-group2 new file +29
-0@@ -0,0 +1,29 @@ +[config] +command = record +args = --no-bpf-event -e '{cycles/period=1234000/,instructions/period=6789000/}:S' kill >/dev/null 2>&1 +ret = 1 + +[event-1:base-record] +fd=1 +group_fd=-1 +config=0|1 +sample_period=1234000 +sample_type=87 +read_format=12 +inherit=0 +freq=0 + +[event-2:base-record] +fd=2 +group_fd=1 +config=0|1 +sample_period=6789000 +sample_type=87 +read_format=12 +disabled=0 +inherit=0 +mmap=0 +comm=0 +freq=0 +enable_on_exec=0 +task=0Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Signature · 1 line
- Arnaldo
Quoted 10 lines · Ian Rogers
Some fixes that address issues for regular and pfm4 events with 2 additional
perf_event_attrtests. Various authors, David Sharp isn't currently at Google.v3. moved a loop into a helper following Adrian Hunter's suggestion. v2. corrects the commit message following Athira Rajeev's suggestion.
David Sharp (1):
perf record: SetPERF_RECORD_PERIODifattr->freqis set.
Quoted 7 lines
Ian Rogers (2):
perf record: Don't clear event's period if set by a term perf test: Leader sampling shouldn't clear sample periodStephane Eranian (1):
perf record: Prevent override ofattr->sample_periodfor libpfm4
events
thanks,
jirka
Quoted 11 lines
tools/perf/tests/attr/README | 1 + tools/perf/tests/attr/test-record-group2 | 29 ++++++++++++++++++++ tools/perf/util/evsel.c | 10 ++++--- tools/perf/util/record.c | 34 ++++++++++++++++++------ 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tools/perf/tests/attr/test-record-group2Signature · 1 line
2.28.0.618.gf4bc123cb7-goog