From ce4326d2752fd51726be50e94b750d3f74670ae3 Mon Sep 17 00:00:00 2001 From: David Sharp Date: Fri, 11 Sep 2020 19:56:52 -0700 Subject: perf record: Set PERF_RECORD_PERIOD if attr->freq is set. 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. Signed-off-by: David Sharp Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexei Starovoitov Cc: Andi Kleen Cc: Andrii Nakryiko Cc: Athira Jajeev Cc: Daniel Borkmann Cc: Ian Rogers Cc: Jiri Olsa Cc: John Fastabend Cc: KP Singh Cc: Mark Rutland Cc: Martin KaFai Lau Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Stephane Eranian Cc: Yonghong Song Cc: david sharp Link: http://lore.kernel.org/lkml/20200912025655.1337192-2-irogers@google.com Signed-off-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/perf/util/evsel.c') diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index fd865002cbbd..3e985016da7e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -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; -- cgit v1.2.3 From ae5dcc8abe311ceafd8753fb488e38c4f5e8e699 Mon Sep 17 00:00:00 2001 From: Stephane Eranian Date: Fri, 11 Sep 2020 19:56:53 -0700 Subject: perf record: Prevent override of attr->sample_period for libpfm4 events Before: $ perf record -c 10000 --pfm-events=cycles:period=77777 Would yield a cycles event with period=10000, instead of 77777. the event string and perf record initializing the event. This was due to an ordering issue between libpfm4 parsing events with attr->sample_period != 0 by the time intent of the author. perf_evsel__config() is invoked. This seems to have been the This patch fixes the problem by preventing override for Signed-off-by: Stephane Eranian Reviewed-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexei Starovoitov Cc: Andi Kleen Cc: Andrii Nakryiko Cc: Athira Jajeev Cc: Daniel Borkmann Cc: Jiri Olsa Cc: John Fastabend Cc: KP Singh Cc: Mark Rutland Cc: Martin KaFai Lau Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Yonghong Song Link: http://lore.kernel.org/lkml/20200912025655.1337192-3-irogers@google.com Signed-off-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tools/perf/util/evsel.c') diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3e985016da7e..459b51e90063 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -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; -- cgit v1.2.3