linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Fixes for setting event freq/periods
@ 2020-09-12  2:56 Ian Rogers
  2020-09-12  2:56 ` [PATCH v3 1/4] perf record: Set PERF_RECORD_PERIOD if attr->freq is set Ian Rogers
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Ian Rogers @ 2020-09-12  2:56 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	Adrian Hunter, Andi Kleen, Athira Rajeev, linux-kernel, netdev,
	bpf
  Cc: Stephane Eranian, Ian Rogers

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

-- 
2.28.0.618.gf4bc123cb7-goog


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/4] perf record: Set PERF_RECORD_PERIOD if attr->freq is set.
  2020-09-12  2:56 [PATCH v3 0/4] Fixes for setting event freq/periods Ian Rogers
@ 2020-09-12  2:56 ` Ian Rogers
  2020-09-12  2:56 ` [PATCH v3 2/4] perf record: Prevent override of attr->sample_period for libpfm4 events Ian Rogers
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2020-09-12  2:56 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	Adrian Hunter, Andi Kleen, Athira Rajeev, linux-kernel, netdev,
	bpf
  Cc: Stephane Eranian, David Sharp, Ian Rogers

From: David Sharp <dhsharp@google.com>

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 <dhsharp@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/evsel.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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;
-- 
2.28.0.618.gf4bc123cb7-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/4] perf record: Prevent override of attr->sample_period for libpfm4 events
  2020-09-12  2:56 [PATCH v3 0/4] Fixes for setting event freq/periods Ian Rogers
  2020-09-12  2:56 ` [PATCH v3 1/4] perf record: Set PERF_RECORD_PERIOD if attr->freq is set Ian Rogers
@ 2020-09-12  2:56 ` Ian Rogers
  2020-09-12  2:56 ` [PATCH v3 3/4] perf record: Don't clear event's period if set by a term Ian Rogers
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Ian Rogers @ 2020-09-12  2:56 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	Adrian Hunter, Andi Kleen, Athira Rajeev, linux-kernel, netdev,
	bpf
  Cc: Stephane Eranian, Ian Rogers

From: Stephane Eranian <eranian@google.com>

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.

Signed-off-by: Stephane Eranian <eranian@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/evsel.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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;
-- 
2.28.0.618.gf4bc123cb7-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
  2020-09-12  2:56 [PATCH v3 0/4] Fixes for setting event freq/periods Ian Rogers
  2020-09-12  2:56 ` [PATCH v3 1/4] perf record: Set PERF_RECORD_PERIOD if attr->freq is set Ian Rogers
  2020-09-12  2:56 ` [PATCH v3 2/4] perf record: Prevent override of attr->sample_period for libpfm4 events Ian Rogers
@ 2020-09-12  2:56 ` Ian Rogers
  2020-09-14  6:02   ` Adrian Hunter
  2020-09-14 21:46   ` Arnaldo Carvalho de Melo
  2020-09-12  2:56 ` [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period Ian Rogers
  2020-09-12 20:49 ` [PATCH v3 0/4] Fixes for setting event freq/periods Jiri Olsa
  4 siblings, 2 replies; 12+ messages in thread
From: Ian Rogers @ 2020-09-12  2:56 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	Adrian Hunter, Andi Kleen, Athira Rajeev, linux-kernel, netdev,
	bpf
  Cc: Stephane Eranian, 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 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.

Fixes: 5f34278867b7 ("perf evlist: Move leader-sampling configuration")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/record.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index a4cc11592f6b..ea9aa1d7cf50 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -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 *evl
 	return 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 *ev
 	if (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
-- 
2.28.0.618.gf4bc123cb7-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period
  2020-09-12  2:56 [PATCH v3 0/4] Fixes for setting event freq/periods Ian Rogers
                   ` (2 preceding siblings ...)
  2020-09-12  2:56 ` [PATCH v3 3/4] perf record: Don't clear event's period if set by a term Ian Rogers
@ 2020-09-12  2:56 ` Ian Rogers
  2020-09-14 22:36   ` Arnaldo Carvalho de Melo
  2020-09-12 20:49 ` [PATCH v3 0/4] Fixes for setting event freq/periods Jiri Olsa
  4 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2020-09-12  2:56 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	Adrian Hunter, Andi Kleen, Athira Rajeev, linux-kernel, netdev,
	bpf
  Cc: Stephane Eranian, Ian Rogers

Add test that a sibling with leader sampling doesn't have its period
cleared.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 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

diff --git a/tools/perf/tests/attr/README b/tools/perf/tests/attr/README
index 6cd408108595..a36f49fb4dbe 100644
--- a/tools/perf/tests/attr/README
+++ b/tools/perf/tests/attr/README
@@ -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)
diff --git a/tools/perf/tests/attr/test-record-group2 b/tools/perf/tests/attr/test-record-group2
new file mode 100644
index 000000000000..6b9f8d182ce1
--- /dev/null
+++ b/tools/perf/tests/attr/test-record-group2
@@ -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
-- 
2.28.0.618.gf4bc123cb7-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/4] Fixes for setting event freq/periods
  2020-09-12  2:56 [PATCH v3 0/4] Fixes for setting event freq/periods Ian Rogers
                   ` (3 preceding siblings ...)
  2020-09-12  2:56 ` [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period Ian Rogers
@ 2020-09-12 20:49 ` Jiri Olsa
  4 siblings, 0 replies; 12+ messages in thread
From: Jiri Olsa @ 2020-09-12 20:49 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Namhyung Kim,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	Adrian Hunter, Andi Kleen, Athira Rajeev, linux-kernel, netdev,
	bpf, Stephane Eranian

On Fri, Sep 11, 2020 at 07:56:51PM -0700, Ian Rogers wrote:
> 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

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> 
>  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
> 
> -- 
> 2.28.0.618.gf4bc123cb7-goog
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
  2020-09-12  2:56 ` [PATCH v3 3/4] perf record: Don't clear event's period if set by a term Ian Rogers
@ 2020-09-14  6:02   ` Adrian Hunter
  2020-09-14 21:46   ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 12+ messages in thread
From: Adrian Hunter @ 2020-09-14  6:02 UTC (permalink / raw)
  To: Ian Rogers, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, Andi Kleen, Athira Rajeev,
	linux-kernel, netdev, bpf
  Cc: Stephane Eranian

On 12/09/20 5:56 am, Ian Rogers wrote:
> 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
> 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.
> 
> Fixes: 5f34278867b7 ("perf evlist: Move leader-sampling configuration")
> Signed-off-by: Ian Rogers <irogers@google.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/util/record.c | 34 ++++++++++++++++++++++++++--------
>  1 file changed, 26 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
> index a4cc11592f6b..ea9aa1d7cf50 100644
> --- a/tools/perf/util/record.c
> +++ b/tools/perf/util/record.c
> @@ -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 *evl
>  	return 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 *ev
>  	if (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
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
  2020-09-12  2:56 ` [PATCH v3 3/4] perf record: Don't clear event's period if set by a term Ian Rogers
  2020-09-14  6:02   ` Adrian Hunter
@ 2020-09-14 21:46   ` Arnaldo Carvalho de Melo
  2020-09-14 21:51     ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-14 21:46 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, Adrian Hunter, Andi Kleen,
	Athira Rajeev, linux-kernel, netdev, bpf, Stephane Eranian

Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
> 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
> 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.

Adrian, Jiri, can you please take a look a this and provide Reviewed-by
or Acked-by tags?

- Arnaldo
 
> Fixes: 5f34278867b7 ("perf evlist: Move leader-sampling configuration")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/record.c | 34 ++++++++++++++++++++++++++--------
>  1 file changed, 26 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
> index a4cc11592f6b..ea9aa1d7cf50 100644
> --- a/tools/perf/util/record.c
> +++ b/tools/perf/util/record.c
> @@ -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 *evl
>  	return 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 *ev
>  	if (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
> -- 
> 2.28.0.618.gf4bc123cb7-goog
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
  2020-09-14 21:46   ` Arnaldo Carvalho de Melo
@ 2020-09-14 21:51     ` Arnaldo Carvalho de Melo
  2020-09-14 21:52       ` Ian Rogers
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-14 21:51 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, Adrian Hunter, Andi Kleen,
	Athira Rajeev, linux-kernel, netdev, bpf, Stephane Eranian

Em Mon, Sep 14, 2020 at 06:46:55PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
> > 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
> > 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.
> 
> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
  2020-09-14 21:51     ` Arnaldo Carvalho de Melo
@ 2020-09-14 21:52       ` Ian Rogers
  2020-09-14 22:34         ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2020-09-14 21:52 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, Adrian Hunter, Andi Kleen,
	Athira Rajeev, LKML, Networking, bpf, Stephane Eranian

On Mon, Sep 14, 2020 at 2:51 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Mon, Sep 14, 2020 at 06:46:55PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
> > > 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
> > > 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.
> >
> > 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

Thanks Arnaldo and Adrian! Adrian's acked-by is here:
https://lore.kernel.org/lkml/77df85d3-a50c-d6aa-1d60-4fc9ea90dc44@intel.com/
Let me know if anything is missing.

Ian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/4] perf record: Don't clear event's period if set by a term
  2020-09-14 21:52       ` Ian Rogers
@ 2020-09-14 22:34         ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-14 22:34 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, Adrian Hunter, Andi Kleen,
	Athira Rajeev, LKML, Networking, bpf, Stephane Eranian

Em Mon, Sep 14, 2020 at 02:52:57PM -0700, Ian Rogers escreveu:
> On Mon, Sep 14, 2020 at 2:51 PM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > Em Mon, Sep 14, 2020 at 06:46:55PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Fri, Sep 11, 2020 at 07:56:54PM -0700, Ian Rogers escreveu:
> > > > 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
> > > > 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.
> > >
> > > 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
> 
> Thanks Arnaldo and Adrian! Adrian's acked-by is here:
> https://lore.kernel.org/lkml/77df85d3-a50c-d6aa-1d60-4fc9ea90dc44@intel.com/
> Let me know if anything is missing.

Thanks, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period
  2020-09-12  2:56 ` [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period Ian Rogers
@ 2020-09-14 22:36   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-14 22:36 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, Adrian Hunter, Andi Kleen,
	Athira Rajeev, linux-kernel, netdev, bpf, Stephane Eranian

Em Fri, Sep 11, 2020 at 07:56:55PM -0700, Ian Rogers escreveu:
> 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
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  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
> 
> diff --git a/tools/perf/tests/attr/README b/tools/perf/tests/attr/README
> index 6cd408108595..a36f49fb4dbe 100644
> --- a/tools/perf/tests/attr/README
> +++ b/tools/perf/tests/attr/README
> @@ -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)
> diff --git a/tools/perf/tests/attr/test-record-group2 b/tools/perf/tests/attr/test-record-group2
> new file mode 100644
> index 000000000000..6b9f8d182ce1
> --- /dev/null
> +++ b/tools/perf/tests/attr/test-record-group2
> @@ -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
> -- 
> 2.28.0.618.gf4bc123cb7-goog
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-09-14 22:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-12  2:56 [PATCH v3 0/4] Fixes for setting event freq/periods Ian Rogers
2020-09-12  2:56 ` [PATCH v3 1/4] perf record: Set PERF_RECORD_PERIOD if attr->freq is set Ian Rogers
2020-09-12  2:56 ` [PATCH v3 2/4] perf record: Prevent override of attr->sample_period for libpfm4 events Ian Rogers
2020-09-12  2:56 ` [PATCH v3 3/4] perf record: Don't clear event's period if set by a term Ian Rogers
2020-09-14  6:02   ` Adrian Hunter
2020-09-14 21:46   ` Arnaldo Carvalho de Melo
2020-09-14 21:51     ` Arnaldo Carvalho de Melo
2020-09-14 21:52       ` Ian Rogers
2020-09-14 22:34         ` Arnaldo Carvalho de Melo
2020-09-12  2:56 ` [PATCH v3 4/4] perf test: Leader sampling shouldn't clear sample period Ian Rogers
2020-09-14 22:36   ` Arnaldo Carvalho de Melo
2020-09-12 20:49 ` [PATCH v3 0/4] Fixes for setting event freq/periods Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).