linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf stat: Support --all-kernel/--all-user
@ 2019-10-11  5:05 Jin Yao
  2019-10-14 14:42 ` Jiri Olsa
  2019-10-21 23:19 ` [tip: perf/core] " tip-bot2 for Jin Yao
  0 siblings, 2 replies; 7+ messages in thread
From: Jin Yao @ 2019-10-11  5:05 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

perf record has supported --all-kernel / --all-user to configure all
used events to run in kernel space or run in user space. But perf
stat doesn't support these options.

It would be useful to support these options in perf-stat too to keep
the same semantics.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/Documentation/perf-stat.txt |  6 ++++++
 tools/perf/builtin-stat.c              |  6 ++++++
 tools/perf/util/stat.c                 | 10 ++++++++++
 tools/perf/util/stat.h                 |  2 ++
 4 files changed, 24 insertions(+)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 930c51c01201..a9af4e440e80 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
 
 Users who wants to get the actual value can apply --no-metric-only.
 
+--all-kernel::
+Configure all used events to run in kernel space.
+
+--all-user::
+Configure all used events to run in user space.
+
 EXAMPLES
 --------
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 468fc49420ce..c88d4e118409 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -803,6 +803,12 @@ static struct option stat_options[] = {
 	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
 		     "monitor specified metrics or metric groups (separated by ,)",
 		     parse_metric_groups),
+	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
+			 "Configure all used events to run in kernel space.",
+			 PARSE_OPT_EXCLUSIVE),
+	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
+			 "Configure all used events to run in user space.",
+			 PARSE_OPT_EXCLUSIVE),
 	OPT_END()
 };
 
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index ebdd130557fb..6822e4ffe224 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
 	if (config->identifier)
 		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
 
+	if (config->all_user) {
+		attr->exclude_kernel = 1;
+		attr->exclude_user   = 0;
+	}
+
+	if (config->all_kernel) {
+		attr->exclude_kernel = 0;
+		attr->exclude_user   = 1;
+	}
+
 	/*
 	 * Disabling all counters initially, they will be enabled
 	 * either manually by us or by kernel via enable_on_exec
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index edbeb2f63e8d..081c4a5113c6 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -106,6 +106,8 @@ struct perf_stat_config {
 	bool			 big_num;
 	bool			 no_merge;
 	bool			 walltime_run_table;
+	bool			 all_kernel;
+	bool			 all_user;
 	FILE			*output;
 	unsigned int		 interval;
 	unsigned int		 timeout;
-- 
2.17.1


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

* Re: [PATCH] perf stat: Support --all-kernel/--all-user
  2019-10-11  5:05 [PATCH] perf stat: Support --all-kernel/--all-user Jin Yao
@ 2019-10-14 14:42 ` Jiri Olsa
  2019-10-14 16:23   ` Arnaldo Carvalho de Melo
  2019-10-21 23:19 ` [tip: perf/core] " tip-bot2 for Jin Yao
  1 sibling, 1 reply; 7+ messages in thread
From: Jiri Olsa @ 2019-10-14 14:42 UTC (permalink / raw)
  To: Jin Yao
  Cc: acme, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin

On Fri, Oct 11, 2019 at 01:05:45PM +0800, Jin Yao wrote:
> perf record has supported --all-kernel / --all-user to configure all
> used events to run in kernel space or run in user space. But perf
> stat doesn't support these options.
> 
> It would be useful to support these options in perf-stat too to keep
> the same semantics.
> 
> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/Documentation/perf-stat.txt |  6 ++++++
>  tools/perf/builtin-stat.c              |  6 ++++++
>  tools/perf/util/stat.c                 | 10 ++++++++++
>  tools/perf/util/stat.h                 |  2 ++
>  4 files changed, 24 insertions(+)
> 
> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
> index 930c51c01201..a9af4e440e80 100644
> --- a/tools/perf/Documentation/perf-stat.txt
> +++ b/tools/perf/Documentation/perf-stat.txt
> @@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
>  
>  Users who wants to get the actual value can apply --no-metric-only.
>  
> +--all-kernel::
> +Configure all used events to run in kernel space.
> +
> +--all-user::
> +Configure all used events to run in user space.
> +
>  EXAMPLES
>  --------
>  
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 468fc49420ce..c88d4e118409 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -803,6 +803,12 @@ static struct option stat_options[] = {
>  	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
>  		     "monitor specified metrics or metric groups (separated by ,)",
>  		     parse_metric_groups),
> +	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
> +			 "Configure all used events to run in kernel space.",
> +			 PARSE_OPT_EXCLUSIVE),
> +	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
> +			 "Configure all used events to run in user space.",
> +			 PARSE_OPT_EXCLUSIVE),
>  	OPT_END()
>  };
>  
> diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
> index ebdd130557fb..6822e4ffe224 100644
> --- a/tools/perf/util/stat.c
> +++ b/tools/perf/util/stat.c
> @@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
>  	if (config->identifier)
>  		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
>  
> +	if (config->all_user) {
> +		attr->exclude_kernel = 1;
> +		attr->exclude_user   = 0;
> +	}
> +
> +	if (config->all_kernel) {
> +		attr->exclude_kernel = 0;
> +		attr->exclude_user   = 1;
> +	}
> +
>  	/*
>  	 * Disabling all counters initially, they will be enabled
>  	 * either manually by us or by kernel via enable_on_exec
> diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
> index edbeb2f63e8d..081c4a5113c6 100644
> --- a/tools/perf/util/stat.h
> +++ b/tools/perf/util/stat.h
> @@ -106,6 +106,8 @@ struct perf_stat_config {
>  	bool			 big_num;
>  	bool			 no_merge;
>  	bool			 walltime_run_table;
> +	bool			 all_kernel;
> +	bool			 all_user;
>  	FILE			*output;
>  	unsigned int		 interval;
>  	unsigned int		 timeout;
> -- 
> 2.17.1
> 

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

* Re: [PATCH] perf stat: Support --all-kernel/--all-user
  2019-10-14 14:42 ` Jiri Olsa
@ 2019-10-14 16:23   ` Arnaldo Carvalho de Melo
  2019-10-15  1:57     ` Jin, Yao
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-14 16:23 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jin Yao, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel,
	ak, kan.liang, yao.jin

Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
> On Fri, Oct 11, 2019 at 01:05:45PM +0800, Jin Yao wrote:
> > perf record has supported --all-kernel / --all-user to configure all
> > used events to run in kernel space or run in user space. But perf
> > stat doesn't support these options.
> > 
> > It would be useful to support these options in perf-stat too to keep
> > the same semantics.
> > 
> > Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

What happens if one asks for both? From the patch only the --all-kernel
will stick, right? Is that the behaviour for 'perf record'? Lemme see,
as I recall having this discussion at that time...

Yeah, same thing, and looking at that I wonder why we dong use
perf_evsel__config() in 'perf stat'...

Ok, I'm going to apply it.
 
> thanks,
> jirka
> 
> > ---
> >  tools/perf/Documentation/perf-stat.txt |  6 ++++++
> >  tools/perf/builtin-stat.c              |  6 ++++++
> >  tools/perf/util/stat.c                 | 10 ++++++++++
> >  tools/perf/util/stat.h                 |  2 ++
> >  4 files changed, 24 insertions(+)
> > 
> > diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
> > index 930c51c01201..a9af4e440e80 100644
> > --- a/tools/perf/Documentation/perf-stat.txt
> > +++ b/tools/perf/Documentation/perf-stat.txt
> > @@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
> >  
> >  Users who wants to get the actual value can apply --no-metric-only.
> >  
> > +--all-kernel::
> > +Configure all used events to run in kernel space.
> > +
> > +--all-user::
> > +Configure all used events to run in user space.
> > +
> >  EXAMPLES
> >  --------
> >  
> > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> > index 468fc49420ce..c88d4e118409 100644
> > --- a/tools/perf/builtin-stat.c
> > +++ b/tools/perf/builtin-stat.c
> > @@ -803,6 +803,12 @@ static struct option stat_options[] = {
> >  	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
> >  		     "monitor specified metrics or metric groups (separated by ,)",
> >  		     parse_metric_groups),
> > +	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
> > +			 "Configure all used events to run in kernel space.",
> > +			 PARSE_OPT_EXCLUSIVE),
> > +	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
> > +			 "Configure all used events to run in user space.",
> > +			 PARSE_OPT_EXCLUSIVE),
> >  	OPT_END()
> >  };
> >  
> > diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
> > index ebdd130557fb..6822e4ffe224 100644
> > --- a/tools/perf/util/stat.c
> > +++ b/tools/perf/util/stat.c
> > @@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
> >  	if (config->identifier)
> >  		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
> >  
> > +	if (config->all_user) {
> > +		attr->exclude_kernel = 1;
> > +		attr->exclude_user   = 0;
> > +	}
> > +
> > +	if (config->all_kernel) {
> > +		attr->exclude_kernel = 0;
> > +		attr->exclude_user   = 1;
> > +	}
> > +
> >  	/*
> >  	 * Disabling all counters initially, they will be enabled
> >  	 * either manually by us or by kernel via enable_on_exec
> > diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
> > index edbeb2f63e8d..081c4a5113c6 100644
> > --- a/tools/perf/util/stat.h
> > +++ b/tools/perf/util/stat.h
> > @@ -106,6 +106,8 @@ struct perf_stat_config {
> >  	bool			 big_num;
> >  	bool			 no_merge;
> >  	bool			 walltime_run_table;
> > +	bool			 all_kernel;
> > +	bool			 all_user;
> >  	FILE			*output;
> >  	unsigned int		 interval;
> >  	unsigned int		 timeout;
> > -- 
> > 2.17.1
> > 

-- 

- Arnaldo

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

* Re: [PATCH] perf stat: Support --all-kernel/--all-user
  2019-10-14 16:23   ` Arnaldo Carvalho de Melo
@ 2019-10-15  1:57     ` Jin, Yao
  2019-10-15 15:11       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 7+ messages in thread
From: Jin, Yao @ 2019-10-15  1:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin



On 10/15/2019 12:23 AM, Arnaldo Carvalho de Melo wrote:
> Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
>> On Fri, Oct 11, 2019 at 01:05:45PM +0800, Jin Yao wrote:
>>> perf record has supported --all-kernel / --all-user to configure all
>>> used events to run in kernel space or run in user space. But perf
>>> stat doesn't support these options.
>>>
>>> It would be useful to support these options in perf-stat too to keep
>>> the same semantics.
>>>
>>> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
>>
>> Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> What happens if one asks for both? From the patch only the --all-kernel
> will stick, right? Is that the behaviour for 'perf record'? Lemme see,
> as I recall having this discussion at that time...
> 
> Yeah, same thing, and looking at that I wonder why we dong use
> perf_evsel__config() in 'perf stat'...
> 
> Ok, I'm going to apply it.
>

Hi Arnaldo,

If we specify both, we will see the error.

root@kbl:~# perf stat --all-kernel --all-user -a -- sleep 1
  Error: option `all-user' cannot be used with all-kernel

root@kbl:~# perf record --all-kernel --all-user -a -- sleep 1
  Error: option `all-user' cannot be used with all-kernel

For why I don't set them in perf_evsel__config, because 
perf_evsel__config is called in record but not called in stat.

Thanks for reviewing and applying this patch.

Thanks
Jin Yao

>> thanks,
>> jirka
>>
>>> ---
>>>   tools/perf/Documentation/perf-stat.txt |  6 ++++++
>>>   tools/perf/builtin-stat.c              |  6 ++++++
>>>   tools/perf/util/stat.c                 | 10 ++++++++++
>>>   tools/perf/util/stat.h                 |  2 ++
>>>   4 files changed, 24 insertions(+)
>>>
>>> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
>>> index 930c51c01201..a9af4e440e80 100644
>>> --- a/tools/perf/Documentation/perf-stat.txt
>>> +++ b/tools/perf/Documentation/perf-stat.txt
>>> @@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
>>>   
>>>   Users who wants to get the actual value can apply --no-metric-only.
>>>   
>>> +--all-kernel::
>>> +Configure all used events to run in kernel space.
>>> +
>>> +--all-user::
>>> +Configure all used events to run in user space.
>>> +
>>>   EXAMPLES
>>>   --------
>>>   
>>> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
>>> index 468fc49420ce..c88d4e118409 100644
>>> --- a/tools/perf/builtin-stat.c
>>> +++ b/tools/perf/builtin-stat.c
>>> @@ -803,6 +803,12 @@ static struct option stat_options[] = {
>>>   	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
>>>   		     "monitor specified metrics or metric groups (separated by ,)",
>>>   		     parse_metric_groups),
>>> +	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
>>> +			 "Configure all used events to run in kernel space.",
>>> +			 PARSE_OPT_EXCLUSIVE),
>>> +	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
>>> +			 "Configure all used events to run in user space.",
>>> +			 PARSE_OPT_EXCLUSIVE),
>>>   	OPT_END()
>>>   };
>>>   
>>> diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
>>> index ebdd130557fb..6822e4ffe224 100644
>>> --- a/tools/perf/util/stat.c
>>> +++ b/tools/perf/util/stat.c
>>> @@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
>>>   	if (config->identifier)
>>>   		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
>>>   
>>> +	if (config->all_user) {
>>> +		attr->exclude_kernel = 1;
>>> +		attr->exclude_user   = 0;
>>> +	}
>>> +
>>> +	if (config->all_kernel) {
>>> +		attr->exclude_kernel = 0;
>>> +		attr->exclude_user   = 1;
>>> +	}
>>> +
>>>   	/*
>>>   	 * Disabling all counters initially, they will be enabled
>>>   	 * either manually by us or by kernel via enable_on_exec
>>> diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
>>> index edbeb2f63e8d..081c4a5113c6 100644
>>> --- a/tools/perf/util/stat.h
>>> +++ b/tools/perf/util/stat.h
>>> @@ -106,6 +106,8 @@ struct perf_stat_config {
>>>   	bool			 big_num;
>>>   	bool			 no_merge;
>>>   	bool			 walltime_run_table;
>>> +	bool			 all_kernel;
>>> +	bool			 all_user;
>>>   	FILE			*output;
>>>   	unsigned int		 interval;
>>>   	unsigned int		 timeout;
>>> -- 
>>> 2.17.1
>>>
> 

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

* Re: [PATCH] perf stat: Support --all-kernel/--all-user
  2019-10-15  1:57     ` Jin, Yao
@ 2019-10-15 15:11       ` Arnaldo Carvalho de Melo
  2019-10-16  0:43         ` Jin, Yao
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-15 15:11 UTC (permalink / raw)
  To: Jin, Yao
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, jolsa, peterz, mingo,
	alexander.shishkin, Linux-kernel, ak, kan.liang, yao.jin

Em Tue, Oct 15, 2019 at 09:57:33AM +0800, Jin, Yao escreveu:
> 
> 
> On 10/15/2019 12:23 AM, Arnaldo Carvalho de Melo wrote:
> > Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
> > > On Fri, Oct 11, 2019 at 01:05:45PM +0800, Jin Yao wrote:
> > > > perf record has supported --all-kernel / --all-user to configure all
> > > > used events to run in kernel space or run in user space. But perf
> > > > stat doesn't support these options.
> > > > 
> > > > It would be useful to support these options in perf-stat too to keep
> > > > the same semantics.
> > > > 
> > > > Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
> > > 
> > > Acked-by: Jiri Olsa <jolsa@kernel.org>
> > 
> > What happens if one asks for both? From the patch only the --all-kernel
> > will stick, right? Is that the behaviour for 'perf record'? Lemme see,
> > as I recall having this discussion at that time...
> > 
> > Yeah, same thing, and looking at that I wonder why we dong use
> > perf_evsel__config() in 'perf stat'...
> > 
> > Ok, I'm going to apply it.
> > 
> 
> Hi Arnaldo,
> 
> If we specify both, we will see the error.

Cool, I looked for this code and couldn't quickly spot it nor tried
running with both to see what happened, my bad, thanks for replying and
making sure that that is the behaviour.
 
> root@kbl:~# perf stat --all-kernel --all-user -a -- sleep 1
>  Error: option `all-user' cannot be used with all-kernel
> 
> root@kbl:~# perf record --all-kernel --all-user -a -- sleep 1
>  Error: option `all-user' cannot be used with all-kernel
> 
> For why I don't set them in perf_evsel__config, because perf_evsel__config
> is called in record but not called in stat.

Ok, at some point we should try and check if we could make 'perf stat'
use perf_evsel__config(), even if we have to separate what is shared
into some __perf_evsel__config() that then gets called by 'perf stat'
while the preexisting perf_evsel__config() calls it and does things
that don't make sense for 'perf stat'.
 
> Thanks for reviewing and applying this patch.

You're welcome!

- Arnaldo
 
> Thanks
> Jin Yao
> 
> > > thanks,
> > > jirka
> > > 
> > > > ---
> > > >   tools/perf/Documentation/perf-stat.txt |  6 ++++++
> > > >   tools/perf/builtin-stat.c              |  6 ++++++
> > > >   tools/perf/util/stat.c                 | 10 ++++++++++
> > > >   tools/perf/util/stat.h                 |  2 ++
> > > >   4 files changed, 24 insertions(+)
> > > > 
> > > > diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
> > > > index 930c51c01201..a9af4e440e80 100644
> > > > --- a/tools/perf/Documentation/perf-stat.txt
> > > > +++ b/tools/perf/Documentation/perf-stat.txt
> > > > @@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
> > > >   Users who wants to get the actual value can apply --no-metric-only.
> > > > +--all-kernel::
> > > > +Configure all used events to run in kernel space.
> > > > +
> > > > +--all-user::
> > > > +Configure all used events to run in user space.
> > > > +
> > > >   EXAMPLES
> > > >   --------
> > > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> > > > index 468fc49420ce..c88d4e118409 100644
> > > > --- a/tools/perf/builtin-stat.c
> > > > +++ b/tools/perf/builtin-stat.c
> > > > @@ -803,6 +803,12 @@ static struct option stat_options[] = {
> > > >   	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
> > > >   		     "monitor specified metrics or metric groups (separated by ,)",
> > > >   		     parse_metric_groups),
> > > > +	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
> > > > +			 "Configure all used events to run in kernel space.",
> > > > +			 PARSE_OPT_EXCLUSIVE),
> > > > +	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
> > > > +			 "Configure all used events to run in user space.",
> > > > +			 PARSE_OPT_EXCLUSIVE),
> > > >   	OPT_END()
> > > >   };
> > > > diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
> > > > index ebdd130557fb..6822e4ffe224 100644
> > > > --- a/tools/perf/util/stat.c
> > > > +++ b/tools/perf/util/stat.c
> > > > @@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
> > > >   	if (config->identifier)
> > > >   		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
> > > > +	if (config->all_user) {
> > > > +		attr->exclude_kernel = 1;
> > > > +		attr->exclude_user   = 0;
> > > > +	}
> > > > +
> > > > +	if (config->all_kernel) {
> > > > +		attr->exclude_kernel = 0;
> > > > +		attr->exclude_user   = 1;
> > > > +	}
> > > > +
> > > >   	/*
> > > >   	 * Disabling all counters initially, they will be enabled
> > > >   	 * either manually by us or by kernel via enable_on_exec
> > > > diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
> > > > index edbeb2f63e8d..081c4a5113c6 100644
> > > > --- a/tools/perf/util/stat.h
> > > > +++ b/tools/perf/util/stat.h
> > > > @@ -106,6 +106,8 @@ struct perf_stat_config {
> > > >   	bool			 big_num;
> > > >   	bool			 no_merge;
> > > >   	bool			 walltime_run_table;
> > > > +	bool			 all_kernel;
> > > > +	bool			 all_user;
> > > >   	FILE			*output;
> > > >   	unsigned int		 interval;
> > > >   	unsigned int		 timeout;
> > > > -- 
> > > > 2.17.1
> > > > 
> > 

-- 

- Arnaldo

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

* Re: [PATCH] perf stat: Support --all-kernel/--all-user
  2019-10-15 15:11       ` Arnaldo Carvalho de Melo
@ 2019-10-16  0:43         ` Jin, Yao
  0 siblings, 0 replies; 7+ messages in thread
From: Jin, Yao @ 2019-10-16  0:43 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, jolsa, peterz, mingo, alexander.shishkin,
	Linux-kernel, ak, kan.liang, yao.jin



On 10/15/2019 11:11 PM, Arnaldo Carvalho de Melo wrote:
> Em Tue, Oct 15, 2019 at 09:57:33AM +0800, Jin, Yao escreveu:
>>
>>
>> On 10/15/2019 12:23 AM, Arnaldo Carvalho de Melo wrote:
>>> Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
>>>> On Fri, Oct 11, 2019 at 01:05:45PM +0800, Jin Yao wrote:
>>>>> perf record has supported --all-kernel / --all-user to configure all
>>>>> used events to run in kernel space or run in user space. But perf
>>>>> stat doesn't support these options.
>>>>>
>>>>> It would be useful to support these options in perf-stat too to keep
>>>>> the same semantics.
>>>>>
>>>>> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
>>>>
>>>> Acked-by: Jiri Olsa <jolsa@kernel.org>
>>>
>>> What happens if one asks for both? From the patch only the --all-kernel
>>> will stick, right? Is that the behaviour for 'perf record'? Lemme see,
>>> as I recall having this discussion at that time...
>>>
>>> Yeah, same thing, and looking at that I wonder why we dong use
>>> perf_evsel__config() in 'perf stat'...
>>>
>>> Ok, I'm going to apply it.
>>>
>>
>> Hi Arnaldo,
>>
>> If we specify both, we will see the error.
> 
> Cool, I looked for this code and couldn't quickly spot it nor tried
> running with both to see what happened, my bad, thanks for replying and
> making sure that that is the behaviour.
>   
>> root@kbl:~# perf stat --all-kernel --all-user -a -- sleep 1
>>   Error: option `all-user' cannot be used with all-kernel
>>
>> root@kbl:~# perf record --all-kernel --all-user -a -- sleep 1
>>   Error: option `all-user' cannot be used with all-kernel
>>
>> For why I don't set them in perf_evsel__config, because perf_evsel__config
>> is called in record but not called in stat.
> 
> Ok, at some point we should try and check if we could make 'perf stat'
> use perf_evsel__config(), even if we have to separate what is shared
> into some __perf_evsel__config() that then gets called by 'perf stat'
> while the preexisting perf_evsel__config() calls it and does things
> that don't make sense for 'perf stat'.
>   

Yes, fully agree, that should be better. If we reconstruct the 
perf_evsel__config() and make it be shared by perf stat, perf record and 
others, that would be nice. :)

Thanks
Jin Yao

>> Thanks for reviewing and applying this patch.
> 
> You're welcome!
> 
> - Arnaldo
>   
>> Thanks
>> Jin Yao
>>
>>>> thanks,
>>>> jirka
>>>>
>>>>> ---
>>>>>    tools/perf/Documentation/perf-stat.txt |  6 ++++++
>>>>>    tools/perf/builtin-stat.c              |  6 ++++++
>>>>>    tools/perf/util/stat.c                 | 10 ++++++++++
>>>>>    tools/perf/util/stat.h                 |  2 ++
>>>>>    4 files changed, 24 insertions(+)
>>>>>
>>>>> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
>>>>> index 930c51c01201..a9af4e440e80 100644
>>>>> --- a/tools/perf/Documentation/perf-stat.txt
>>>>> +++ b/tools/perf/Documentation/perf-stat.txt
>>>>> @@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
>>>>>    Users who wants to get the actual value can apply --no-metric-only.
>>>>> +--all-kernel::
>>>>> +Configure all used events to run in kernel space.
>>>>> +
>>>>> +--all-user::
>>>>> +Configure all used events to run in user space.
>>>>> +
>>>>>    EXAMPLES
>>>>>    --------
>>>>> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
>>>>> index 468fc49420ce..c88d4e118409 100644
>>>>> --- a/tools/perf/builtin-stat.c
>>>>> +++ b/tools/perf/builtin-stat.c
>>>>> @@ -803,6 +803,12 @@ static struct option stat_options[] = {
>>>>>    	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
>>>>>    		     "monitor specified metrics or metric groups (separated by ,)",
>>>>>    		     parse_metric_groups),
>>>>> +	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
>>>>> +			 "Configure all used events to run in kernel space.",
>>>>> +			 PARSE_OPT_EXCLUSIVE),
>>>>> +	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
>>>>> +			 "Configure all used events to run in user space.",
>>>>> +			 PARSE_OPT_EXCLUSIVE),
>>>>>    	OPT_END()
>>>>>    };
>>>>> diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
>>>>> index ebdd130557fb..6822e4ffe224 100644
>>>>> --- a/tools/perf/util/stat.c
>>>>> +++ b/tools/perf/util/stat.c
>>>>> @@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
>>>>>    	if (config->identifier)
>>>>>    		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
>>>>> +	if (config->all_user) {
>>>>> +		attr->exclude_kernel = 1;
>>>>> +		attr->exclude_user   = 0;
>>>>> +	}
>>>>> +
>>>>> +	if (config->all_kernel) {
>>>>> +		attr->exclude_kernel = 0;
>>>>> +		attr->exclude_user   = 1;
>>>>> +	}
>>>>> +
>>>>>    	/*
>>>>>    	 * Disabling all counters initially, they will be enabled
>>>>>    	 * either manually by us or by kernel via enable_on_exec
>>>>> diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
>>>>> index edbeb2f63e8d..081c4a5113c6 100644
>>>>> --- a/tools/perf/util/stat.h
>>>>> +++ b/tools/perf/util/stat.h
>>>>> @@ -106,6 +106,8 @@ struct perf_stat_config {
>>>>>    	bool			 big_num;
>>>>>    	bool			 no_merge;
>>>>>    	bool			 walltime_run_table;
>>>>> +	bool			 all_kernel;
>>>>> +	bool			 all_user;
>>>>>    	FILE			*output;
>>>>>    	unsigned int		 interval;
>>>>>    	unsigned int		 timeout;
>>>>> -- 
>>>>> 2.17.1
>>>>>
>>>
> 

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

* [tip: perf/core] perf stat: Support --all-kernel/--all-user
  2019-10-11  5:05 [PATCH] perf stat: Support --all-kernel/--all-user Jin Yao
  2019-10-14 14:42 ` Jiri Olsa
@ 2019-10-21 23:19 ` tip-bot2 for Jin Yao
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Jin Yao @ 2019-10-21 23:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Jin Yao, Jiri Olsa, Alexander Shishkin, Andi Kleen, Kan Liang,
	Peter Zijlstra, Arnaldo Carvalho de Melo, Ingo Molnar,
	Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     dd071024bf52156eed31deaf511c6e7a82a6f57b
Gitweb:        https://git.kernel.org/tip/dd071024bf52156eed31deaf511c6e7a82a6f57b
Author:        Jin Yao <yao.jin@linux.intel.com>
AuthorDate:    Fri, 11 Oct 2019 13:05:45 +08:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 15 Oct 2019 08:39:42 -03:00

perf stat: Support --all-kernel/--all-user

'perf record' has supported --all-kernel / --all-user to configure all
used events to run in kernel space or run in user space. But 'perf stat'
doesn't support these options.

It would be useful to support these options in 'perf stat' too to keep
the same semantics available in both tools.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20191011050545.3899-1-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-stat.txt |  6 ++++++
 tools/perf/builtin-stat.c              |  6 ++++++
 tools/perf/util/stat.c                 | 10 ++++++++++
 tools/perf/util/stat.h                 |  2 ++
 4 files changed, 24 insertions(+)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 930c51c..a9af4e4 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
 
 Users who wants to get the actual value can apply --no-metric-only.
 
+--all-kernel::
+Configure all used events to run in kernel space.
+
+--all-user::
+Configure all used events to run in user space.
+
 EXAMPLES
 --------
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 468fc49..c88d4e1 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -803,6 +803,12 @@ static struct option stat_options[] = {
 	OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
 		     "monitor specified metrics or metric groups (separated by ,)",
 		     parse_metric_groups),
+	OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel,
+			 "Configure all used events to run in kernel space.",
+			 PARSE_OPT_EXCLUSIVE),
+	OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user,
+			 "Configure all used events to run in user space.",
+			 PARSE_OPT_EXCLUSIVE),
 	OPT_END()
 };
 
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index ebdd130..6822e4f 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,
 	if (config->identifier)
 		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
 
+	if (config->all_user) {
+		attr->exclude_kernel = 1;
+		attr->exclude_user   = 0;
+	}
+
+	if (config->all_kernel) {
+		attr->exclude_kernel = 0;
+		attr->exclude_user   = 1;
+	}
+
 	/*
 	 * Disabling all counters initially, they will be enabled
 	 * either manually by us or by kernel via enable_on_exec
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index edbeb2f..081c4a5 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -106,6 +106,8 @@ struct perf_stat_config {
 	bool			 big_num;
 	bool			 no_merge;
 	bool			 walltime_run_table;
+	bool			 all_kernel;
+	bool			 all_user;
 	FILE			*output;
 	unsigned int		 interval;
 	unsigned int		 timeout;

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

end of thread, other threads:[~2019-10-22  0:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11  5:05 [PATCH] perf stat: Support --all-kernel/--all-user Jin Yao
2019-10-14 14:42 ` Jiri Olsa
2019-10-14 16:23   ` Arnaldo Carvalho de Melo
2019-10-15  1:57     ` Jin, Yao
2019-10-15 15:11       ` Arnaldo Carvalho de Melo
2019-10-16  0:43         ` Jin, Yao
2019-10-21 23:19 ` [tip: perf/core] " tip-bot2 for Jin Yao

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).