[RFC PATCH v2 0/5] topdown with metrics

Andrew Kilroy posted 5 patches 4 years, 5 months ago
tools/perf/builtin-stat.c     | 257 +++++++++++++++++++++++++---------
tools/perf/util/metricgroup.c |  12 ++
tools/perf/util/metricgroup.h |   7 +
tools/perf/util/topdown.c     |  10 ++
tools/perf/util/topdown.h     |   1 +
5 files changed, 223 insertions(+), 64 deletions(-)
[RFC PATCH v2 0/5] topdown with metrics
Posted by Andrew Kilroy 4 years, 5 months ago
This patch series adds the ability for the --topdown option to use
metrics (defined in json files in the pmu-events directory) to describe
how to calculate and determine the output columns for topdown level 1.

For this to work, a number of metrics have to be defined for the
relevant processor with the MetricGroup name "TopDownL1".  perf will
arrange for the events defined in each metric to be collected, and each
metric will be displayed in the output, as if

  perf stat -M 'TopDownL1' --metric-only -- exampleapp

had been used.

Topdown was already implemented where certain kernel events are defined.
If these kernel events are defined, the new json metrics behaviour is
not used.  The json metrics approach is only used if the kernel events
are absent.

The last patch in the series disables the json metrics behaviour on x86.
This is because of concerns that due to SMT it's not straightforward to
express the various formulas as json for certain x86 cpus.  See

  https://lore.kernel.org/linux-perf-users/12e0deef-08db-445f-4958-bcd5c3e10367@linux.intel.com/#t

Changes since v1:

Addition of code to detect whether topdown kernel events are available,
and if so use them.  Otherwise set up the json metrics.

Disable the use of json metrics on non-x86 architectures, for the reason
stated above.

 - Link to v1: 
   https://lore.kernel.org/linux-perf-users/20211214184240.24215-1-andrew.kilroy@arm.com/T/#m514a788bdc3613f057dbd5b6a339c762d37f8b85


Andrew Kilroy (5):
  perf stat: Implement --topdown with metrics
  perf stat: Topdown kernel events setup function
  perf stat: Topdown json metrics setup function
  perf stat: Detect if topdown kernel events supported
  perf stat: Ensure only topdown kernel events used on x86

 tools/perf/builtin-stat.c     | 257 +++++++++++++++++++++++++---------
 tools/perf/util/metricgroup.c |  12 ++
 tools/perf/util/metricgroup.h |   7 +
 tools/perf/util/topdown.c     |  10 ++
 tools/perf/util/topdown.h     |   1 +
 5 files changed, 223 insertions(+), 64 deletions(-)

-- 
2.17.1

Re: [RFC PATCH v2 0/5] topdown with metrics
Posted by John Garry 4 years, 5 months ago
On 11/01/2022 15:07, Andrew Kilroy wrote:
> This patch series adds the ability for the --topdown option to use
> metrics (defined in json files in the pmu-events directory) to describe
> how to calculate and determine the output columns for topdown level 1.
> 
> For this to work, a number of metrics have to be defined for the
> relevant processor with the MetricGroup name "TopDownL1".  perf will
> arrange for the events defined in each metric to be collected, and each
> metric will be displayed in the output, as if
> 
>    perf stat -M 'TopDownL1' --metric-only -- exampleapp
> 
> had been used.
> 
> Topdown was already implemented where certain kernel events are defined.
> If these kernel events are defined, the new json metrics behaviour is
> not used.  The json metrics approach is only used if the kernel events
> are absent.
> 
> The last patch in the series disables the json metrics behaviour on x86.
> This is because of concerns that due to SMT it's not straightforward to
> express the various formulas as json for certain x86 cpus.  See

I suppose this solution is ok.

A concern is that today we only have 1x arm64 platform which actually 
supports this in mainline.

Do you have any more which you plan to support?

I think that it's the frontend bound and fetch_bubble event which 
doesn't have a standard arm solution.

Note that I do have a series for perf tool which can read arm cpu pmu 
sysfs events folder to find events which are implemented (I don't think 
all required events are mandated) and match that against the common arch 
events JSON, so that we don't need a JSON definition file for each core 
implementation from all implementators - this would improve scalability. 
However a concern is that some events - like inst_spec - have imp def 
meaning, so may not be good to always use by default for all cores metrics.

Thanks,
John
Re: [RFC PATCH v2 0/5] topdown with metrics
Posted by Al Grant 4 years, 5 months ago
On 20/01/2022 09:26, John Garry wrote:
> On 11/01/2022 15:07, Andrew Kilroy wrote:
>> This patch series adds the ability for the --topdown option to use
>> metrics (defined in json files in the pmu-events directory) to describe
>> how to calculate and determine the output columns for topdown level 1.
>>
>> For this to work, a number of metrics have to be defined for the
>> relevant processor with the MetricGroup name "TopDownL1".  perf will
>> arrange for the events defined in each metric to be collected, and each
>> metric will be displayed in the output, as if
>>
>>    perf stat -M 'TopDownL1' --metric-only -- exampleapp
>>
>> had been used.
>>
>> Topdown was already implemented where certain kernel events are defined.
>> If these kernel events are defined, the new json metrics behaviour is
>> not used.  The json metrics approach is only used if the kernel events
>> are absent.
>>
>> The last patch in the series disables the json metrics behaviour on x86.
>> This is because of concerns that due to SMT it's not straightforward to
>> express the various formulas as json for certain x86 cpus.  See
> 
> I suppose this solution is ok.
> 
> A concern is that today we only have 1x arm64 platform which actually supports this in mainline.
> 
> Do you have any more which you plan to support?
> 
> I think that it's the frontend bound and fetch_bubble event which doesn't have a standard arm solution.
> 
> Note that I do have a series for perf tool which can read arm cpu pmu sysfs events folder to find events which are implemented (I don't think all required events are mandated) and match that against the common arch events JSON, so that we don't need a JSON definition file for each core implementation from all implementators - this would improve scalability.However a concern is that some events - like inst_spec - have imp def meaning, so may not be good to always use by default for all cores metrics.

Sadly the sysfs list isn't complete, it only includes the events
discoverable from the PMCEIDx registers, and they only cover the
ranges 0x0000-0x003f and 0x4000-0x403f. Although that covers most
events used in standard metrics, it doesn't cover all. Most CPUs
have many more events besides these, and there are now architected
(common) events in the 0x8000 range.

There's a lot to be said for having the kernel expose the complete
list to userspace via sysfs. It would save each userspace tool
needing its own set of vendor-supplied information. But to get
that complete list, the kernel would need the same vendor
information the userspace tools are using now.

(And your concern about the metrics varying even when the same
events are present, is quite valid.)

Al
Re: [RFC PATCH v2 0/5] topdown with metrics
Posted by Andrew Kilroy 4 years, 5 months ago

On 20/01/2022 09:26, John Garry wrote:
> On 11/01/2022 15:07, Andrew Kilroy wrote:
>> This patch series adds the ability for the --topdown option to use
>> metrics (defined in json files in the pmu-events directory) to describe
>> how to calculate and determine the output columns for topdown level 1.
>>
>> For this to work, a number of metrics have to be defined for the
>> relevant processor with the MetricGroup name "TopDownL1".  perf will
>> arrange for the events defined in each metric to be collected, and each
>> metric will be displayed in the output, as if
>>
>>    perf stat -M 'TopDownL1' --metric-only -- exampleapp
>>
>> had been used.
>>
>> Topdown was already implemented where certain kernel events are defined.
>> If these kernel events are defined, the new json metrics behaviour is
>> not used.  The json metrics approach is only used if the kernel events
>> are absent.
>>
>> The last patch in the series disables the json metrics behaviour on x86.
>> This is because of concerns that due to SMT it's not straightforward to
>> express the various formulas as json for certain x86 cpus.  See
> 
> I suppose this solution is ok.
> 

Thanks, would you mind giving it a Reviewed-By?

> A concern is that today we only have 1x arm64 platform which actually 
> supports this in mainline.
> 
> Do you have any more which you plan to support?
> 

The Neoverse cores, mainly.

> I think that it's the frontend bound and fetch_bubble event which 
> doesn't have a standard arm solution.
> 
> Note that I do have a series for perf tool which can read arm cpu pmu 
> sysfs events folder to find events which are implemented (I don't think 
> all required events are mandated) and match that against the common arch 
> events JSON, so that we don't need a JSON definition file for each core 
> implementation from all implementators - this would improve scalability. 
> However a concern is that some events - like inst_spec - have imp def 
> meaning, so may not be good to always use by default for all cores metrics.
> 
> Thanks,
> John

Thanks,
Andrew
Re: [RFC PATCH v2 0/5] topdown with metrics
Posted by Andrew Kilroy 4 years, 4 months ago

On 27/01/2022 11:42, Andrew Kilroy wrote:
> 
> 
> On 20/01/2022 09:26, John Garry wrote:
>> On 11/01/2022 15:07, Andrew Kilroy wrote:
>>> This patch series adds the ability for the --topdown option to use
>>> metrics (defined in json files in the pmu-events directory) to describe
>>> how to calculate and determine the output columns for topdown level 1.
>>>
>>> For this to work, a number of metrics have to be defined for the
>>> relevant processor with the MetricGroup name "TopDownL1".  perf will
>>> arrange for the events defined in each metric to be collected, and each
>>> metric will be displayed in the output, as if
>>>
>>>    perf stat -M 'TopDownL1' --metric-only -- exampleapp
>>>
>>> had been used.
>>>
>>> Topdown was already implemented where certain kernel events are defined.
>>> If these kernel events are defined, the new json metrics behaviour is
>>> not used.  The json metrics approach is only used if the kernel events
>>> are absent.
>>>
>>> The last patch in the series disables the json metrics behaviour on x86.
>>> This is because of concerns that due to SMT it's not straightforward to
>>> express the various formulas as json for certain x86 cpus.  See
>>
>> I suppose this solution is ok.
>>
> 
> Thanks, would you mind giving it a Reviewed-By?
> 
>> A concern is that today we only have 1x arm64 platform which actually 
>> supports this in mainline.
>>
>> Do you have any more which you plan to support?
>>
> 
> The Neoverse cores, mainly.
> 

Thanks for the feedback on this RFC, I think we'll resubmit these 
patches at a later time, when we've got a json metrics file or two.

Thanks,
Andrew