diff mbox series

[RFC,2/9] perf metrics: Don't iter sys metrics if we already found a CPU match

Message ID 20230628102949.2598096-3-john.g.garry@oracle.com (mailing list archive)
State New, archived
Headers show
Series perf tool: sys event metric support re-write | expand

Commit Message

John Garry June 28, 2023, 10:29 a.m. UTC
In metricgroup__add_metric() we still iter the sys metrics if we already
found a match from the CPU table, which is pretty pointless, so don't
bother.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 tools/perf/util/metricgroup.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Ian Rogers June 30, 2023, 5:41 p.m. UTC | #1
On Wed, Jun 28, 2023 at 3:30 AM John Garry <john.g.garry@oracle.com> wrote:
>
> In metricgroup__add_metric() we still iter the sys metrics if we already
> found a match from the CPU table, which is pretty pointless, so don't
> bother.
>
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>  tools/perf/util/metricgroup.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index 4389ccd29fe7..8d2ac2513530 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -1261,6 +1261,12 @@ static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
>
>                 has_match = data.has_match;
>         }
> +
> +       if (has_match) {
> +               ret = 0;
> +               goto out;
> +       }
> +

I think this can just be:

if (!has_match)

However, I'm not sure I agree with the intent of the change. We may
have a metric like IPC and want it to apply to all types of CPU, GPU,
etc. If we short-cut here then that won't be possible.

Thanks,
Ian
>         {
>                 struct metricgroup_iter_data data = {
>                         .fn = metricgroup__add_metric_sys_event_iter,
> @@ -1279,6 +1285,7 @@ static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
>
>                 pmu_for_each_sys_metric(metricgroup__sys_event_iter, &data);
>         }
> +
>         /* End of pmu events. */
>         if (!has_match)
>                 ret = -EINVAL;
> --
> 2.35.3
>
John Garry July 3, 2023, 1:09 p.m. UTC | #2
On 30/06/2023 18:41, Ian Rogers wrote:
> On Wed, Jun 28, 2023 at 3:30 AM John Garry<john.g.garry@oracle.com>  wrote:
>> In metricgroup__add_metric() we still iter the sys metrics if we already
>> found a match from the CPU table, which is pretty pointless, so don't
>> bother.
>>
>> Signed-off-by: John Garry<john.g.garry@oracle.com>
>> ---
>>   tools/perf/util/metricgroup.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
>> index 4389ccd29fe7..8d2ac2513530 100644
>> --- a/tools/perf/util/metricgroup.c
>> +++ b/tools/perf/util/metricgroup.c
>> @@ -1261,6 +1261,12 @@ static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
>>
>>                  has_match = data.has_match;
>>          }

Hi Ian,

>> +
>> +       if (has_match) {
>> +               ret = 0;
>> +               goto out;
>> +       }
>> +
> I think this can just be:
> 
> if (!has_match)

But ret has no initial value

> 
> However, I'm not sure I agree with the intent of the change. We may
> have a metric like IPC and want it to apply to all types of CPU, GPU,
> etc. If we short-cut here then that won't be possible.

A few points to make on this:
- Currently we don't have any same-named metrics like this, so not much 
use in supporting it in the code (yet).
- Even if we had some same-named metrics, I am not sure if it even works 
properly. Do we have any uncore PMU metrics which have same name as CPU 
metrics?
- Further to the previous point, do we really want same-named metrics 
for different PMUs in the future? I think event / metric names need to 
be chosen carefully to avoid clash for other PMUs or keywords. For your 
example, if I did ask for IPC metric, I'd like to be able to just know 
I'm getting IPC metric for CPUs or some other PMUs, but not both.

Thanks,
John

>
Ian Rogers July 12, 2023, 5:40 a.m. UTC | #3
On Mon, Jul 3, 2023 at 6:09 AM John Garry <john.g.garry@oracle.com> wrote:
>
> On 30/06/2023 18:41, Ian Rogers wrote:
> > On Wed, Jun 28, 2023 at 3:30 AM John Garry<john.g.garry@oracle.com>  wrote:
> >> In metricgroup__add_metric() we still iter the sys metrics if we already
> >> found a match from the CPU table, which is pretty pointless, so don't
> >> bother.
> >>
> >> Signed-off-by: John Garry<john.g.garry@oracle.com>
> >> ---
> >>   tools/perf/util/metricgroup.c | 7 +++++++
> >>   1 file changed, 7 insertions(+)
> >>
> >> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> >> index 4389ccd29fe7..8d2ac2513530 100644
> >> --- a/tools/perf/util/metricgroup.c
> >> +++ b/tools/perf/util/metricgroup.c
> >> @@ -1261,6 +1261,12 @@ static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
> >>
> >>                  has_match = data.has_match;
> >>          }
>
> Hi Ian,
>
> >> +
> >> +       if (has_match) {
> >> +               ret = 0;
> >> +               goto out;
> >> +       }
> >> +
> > I think this can just be:
> >
> > if (!has_match)
>
> But ret has no initial value
>
> >
> > However, I'm not sure I agree with the intent of the change. We may
> > have a metric like IPC and want it to apply to all types of CPU, GPU,
> > etc. If we short-cut here then that won't be possible.
>
> A few points to make on this:
> - Currently we don't have any same-named metrics like this, so not much
> use in supporting it in the code (yet).

We have same named metrics for heterogeneous CPU PMUs:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json?h=perf-tools-next#n304
cpu_atom
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json?h=perf-tools-next#n1125
cpu_core

> - Even if we had some same-named metrics, I am not sure if it even works
> properly. Do we have any uncore PMU metrics which have same name as CPU
> metrics?

So I was thinking IPC was a generic concept that would apply to a
co-processor on a network card, a GPU, etc.

> - Further to the previous point, do we really want same-named metrics
> for different PMUs in the future? I think event / metric names need to
> be chosen carefully to avoid clash for other PMUs or keywords. For your
> example, if I did ask for IPC metric, I'd like to be able to just know
> I'm getting IPC metric for CPUs or some other PMUs, but not both.

At the moment if you request an event without a PMU, say instructions
retired, we will attempt to open the event on every PMU - legacy
events (PERF_TYPE_HARDWARE, PERF_TYPE_HW_CACHE) only try the core
PMUs. It would seem consistent if metrics tried to open on every PMU
like most events.

Thanks,
Ian

> Thanks,
> John
>
> >
John Garry July 12, 2023, 9:37 a.m. UTC | #4
On 12/07/2023 06:40, Ian Rogers wrote:
>> A few points to make on this:
>> - Currently we don't have any same-named metrics like this, so not much
>> use in supporting it in the code (yet).
> We have same named metrics for heterogeneous CPU PMUs:
> https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json?h=perf-tools-next*n304__;Iw!!ACWV5N9M2RV99hQ!MyvM7oyC6FgOVgDn2-Ot_TJNh4TF_VM9SlIVwv2AOTkJGdmDJ2NYf5WXh-yLcG1dRxLKdXWZVTzsoOo5yDk$  
> cpu_atom
> https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json?h=perf-tools-next*n1125__;Iw!!ACWV5N9M2RV99hQ!MyvM7oyC6FgOVgDn2-Ot_TJNh4TF_VM9SlIVwv2AOTkJGdmDJ2NYf5WXh-yLcG1dRxLKdXWZVTzsL1dVM3Q$  
> cpu_core
> 

I meant that we have no same-named events for sys PMUs compared to 
uncore/CPU PMUs.

>> - Even if we had some same-named metrics, I am not sure if it even works
>> properly. Do we have any uncore PMU metrics which have same name as CPU
>> metrics?
> So I was thinking IPC was a generic concept that would apply to a
> co-processor on a network card, a GPU, etc.
> 
>> - Further to the previous point, do we really want same-named metrics
>> for different PMUs in the future? I think event / metric names need to
>> be chosen carefully to avoid clash for other PMUs or keywords. For your
>> example, if I did ask for IPC metric, I'd like to be able to just know
>> I'm getting IPC metric for CPUs or some other PMUs, but not both.
> At the moment if you request an event without a PMU, say instructions
> retired, we will attempt to open the event on every PMU - legacy
> events (PERF_TYPE_HARDWARE, PERF_TYPE_HW_CACHE) only try the core
> PMUs. It would seem consistent if metrics tried to open on every PMU
> like most events.

OK, fine. I can drop this change if you prefer. But, to reiterate my 
main point, I still think that there is not much point in looking for 
metrics which currently would not exist.

Thanks,
John
diff mbox series

Patch

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 4389ccd29fe7..8d2ac2513530 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1261,6 +1261,12 @@  static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
 
 		has_match = data.has_match;
 	}
+
+	if (has_match) {
+		ret = 0;
+		goto out;
+	}
+
 	{
 		struct metricgroup_iter_data data = {
 			.fn = metricgroup__add_metric_sys_event_iter,
@@ -1279,6 +1285,7 @@  static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
 
 		pmu_for_each_sys_metric(metricgroup__sys_event_iter, &data);
 	}
+
 	/* End of pmu events. */
 	if (!has_match)
 		ret = -EINVAL;