diff mbox series

[v3,3/4] perf record: Don't clear event's period if set by a term

Message ID 20200912025655.1337192-4-irogers@google.com
State New
Headers show
Series Fixes for setting event freq/periods | expand

Commit Message

Ian Rogers Sept. 12, 2020, 2:56 a.m. UTC
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(-)

Comments

Adrian Hunter Sept. 14, 2020, 6:02 a.m. UTC | #1
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
>
Arnaldo Carvalho de Melo Sept. 14, 2020, 9:46 p.m. UTC | #2
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 Carvalho de Melo Sept. 14, 2020, 9:51 p.m. UTC | #3
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
Ian Rogers Sept. 14, 2020, 9:52 p.m. UTC | #4
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
Arnaldo Carvalho de Melo Sept. 14, 2020, 10:34 p.m. UTC | #5
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
diff mbox series

Patch

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