[PATCH v4 03/22] perf jevents: Add smi metric group for Intel models

Ian Rogers posted 22 patches 2 months ago
[PATCH v4 03/22] perf jevents: Add smi metric group for Intel models
Posted by Ian Rogers 2 months ago
Allow duplicated metric to be dropped from json files.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/pmu-events/intel_metrics.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
index f875eb844c78..f34b4230a4ee 100755
--- a/tools/perf/pmu-events/intel_metrics.py
+++ b/tools/perf/pmu-events/intel_metrics.py
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
                     JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
-                    MetricGroup, Select)
+                    MetricGroup, MetricRef, Select)
 import argparse
 import json
 import math
@@ -56,6 +56,24 @@ def Rapl() -> MetricGroup:
                      description="Running Average Power Limit (RAPL) power consumption estimates")
 
 
+def Smi() -> MetricGroup:
+    aperf = Event('msr/aperf/')
+    cycles = Event('cycles')
+    smi_num = Event('msr/smi/')
+    smi_cycles = Select(Select((aperf - cycles) / aperf, smi_num > 0, 0),
+                        has_event(aperf),
+                        0)
+    return MetricGroup('smi', [
+        Metric('smi_num', 'Number of SMI interrupts.',
+               Select(smi_num, has_event(smi_num), 0), 'SMI#'),
+        # Note, the smi_cycles "Event" is really a reference to the metric.
+        Metric('smi_cycles',
+               'Percentage of cycles spent in System Management Interrupts. '
+               'Requires /sys/devices/cpu/freeze_on_smi to be 1.',
+               smi_cycles, '100%', threshold=(MetricRef('smi_cycles') > 0.10))
+    ], description = 'System Management Interrupt metrics')
+
+
 def main() -> None:
   global _args
 
@@ -81,6 +99,7 @@ def main() -> None:
   all_metrics = MetricGroup("", [
       Idle(),
       Rapl(),
+      Smi(),
   ])
 
 
-- 
2.46.1.824.gd892dcdcdd-goog
Re: [PATCH v4 03/22] perf jevents: Add smi metric group for Intel models
Posted by Liang, Kan 3 weeks, 1 day ago

On 2024-09-26 1:50 p.m., Ian Rogers wrote:
> Allow duplicated metric to be dropped from json files.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/pmu-events/intel_metrics.py | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
> index f875eb844c78..f34b4230a4ee 100755
> --- a/tools/perf/pmu-events/intel_metrics.py
> +++ b/tools/perf/pmu-events/intel_metrics.py
> @@ -2,7 +2,7 @@
>  # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
>  from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
>                      JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
> -                    MetricGroup, Select)
> +                    MetricGroup, MetricRef, Select)
>  import argparse
>  import json
>  import math
> @@ -56,6 +56,24 @@ def Rapl() -> MetricGroup:
>                       description="Running Average Power Limit (RAPL) power consumption estimates")
>  
>  
> +def Smi() -> MetricGroup:
> +    aperf = Event('msr/aperf/')
> +    cycles = Event('cycles')
> +    smi_num = Event('msr/smi/')
> +    smi_cycles = Select(Select((aperf - cycles) / aperf, smi_num > 0, 0),
> +                        has_event(aperf),
> +                        0)
> +    return MetricGroup('smi', [
> +        Metric('smi_num', 'Number of SMI interrupts.',
> +               Select(smi_num, has_event(smi_num), 0), 'SMI#'),
> +        # Note, the smi_cycles "Event" is really a reference to the metric.
> +        Metric('smi_cycles',
> +               'Percentage of cycles spent in System Management Interrupts. '
> +               'Requires /sys/devices/cpu/freeze_on_smi to be 1.',

It seems not work for hybrid?

Thanks,
Kan
> +               smi_cycles, '100%', threshold=(MetricRef('smi_cycles') > 0.10))
> +    ], description = 'System Management Interrupt metrics')
> +
> +
>  def main() -> None:
>    global _args
>  
> @@ -81,6 +99,7 @@ def main() -> None:
>    all_metrics = MetricGroup("", [
>        Idle(),
>        Rapl(),
> +      Smi(),
>    ])
>  
>
Re: [PATCH v4 03/22] perf jevents: Add smi metric group for Intel models
Posted by Ian Rogers 3 weeks, 1 day ago
On Wed, Nov 6, 2024 at 9:32 AM Liang, Kan <kan.liang@linux.intel.com> wrote:
>
>
>
> On 2024-09-26 1:50 p.m., Ian Rogers wrote:
> > Allow duplicated metric to be dropped from json files.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  tools/perf/pmu-events/intel_metrics.py | 21 ++++++++++++++++++++-
> >  1 file changed, 20 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
> > index f875eb844c78..f34b4230a4ee 100755
> > --- a/tools/perf/pmu-events/intel_metrics.py
> > +++ b/tools/perf/pmu-events/intel_metrics.py
> > @@ -2,7 +2,7 @@
> >  # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
> >  from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
> >                      JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
> > -                    MetricGroup, Select)
> > +                    MetricGroup, MetricRef, Select)
> >  import argparse
> >  import json
> >  import math
> > @@ -56,6 +56,24 @@ def Rapl() -> MetricGroup:
> >                       description="Running Average Power Limit (RAPL) power consumption estimates")
> >
> >
> > +def Smi() -> MetricGroup:
> > +    aperf = Event('msr/aperf/')
> > +    cycles = Event('cycles')
> > +    smi_num = Event('msr/smi/')
> > +    smi_cycles = Select(Select((aperf - cycles) / aperf, smi_num > 0, 0),
> > +                        has_event(aperf),
> > +                        0)
> > +    return MetricGroup('smi', [
> > +        Metric('smi_num', 'Number of SMI interrupts.',
> > +               Select(smi_num, has_event(smi_num), 0), 'SMI#'),
> > +        # Note, the smi_cycles "Event" is really a reference to the metric.
> > +        Metric('smi_cycles',
> > +               'Percentage of cycles spent in System Management Interrupts. '
> > +               'Requires /sys/devices/cpu/freeze_on_smi to be 1.',
>
> It seems not work for hybrid?

Thanks. The code is a migration of existing metrics that exist for hybrid:
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#n74
I still lack an easy way to test on hybrid, but I think fixing that
case can be follow on work.

Thanks,
Ian
Re: [PATCH v4 03/22] perf jevents: Add smi metric group for Intel models
Posted by Liang, Kan 3 weeks, 1 day ago

On 2024-11-06 12:42 p.m., Ian Rogers wrote:
> On Wed, Nov 6, 2024 at 9:32 AM Liang, Kan <kan.liang@linux.intel.com> wrote:
>>
>>
>>
>> On 2024-09-26 1:50 p.m., Ian Rogers wrote:
>>> Allow duplicated metric to be dropped from json files.
>>>
>>> Signed-off-by: Ian Rogers <irogers@google.com>
>>> ---
>>>  tools/perf/pmu-events/intel_metrics.py | 21 ++++++++++++++++++++-
>>>  1 file changed, 20 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
>>> index f875eb844c78..f34b4230a4ee 100755
>>> --- a/tools/perf/pmu-events/intel_metrics.py
>>> +++ b/tools/perf/pmu-events/intel_metrics.py
>>> @@ -2,7 +2,7 @@
>>>  # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
>>>  from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
>>>                      JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
>>> -                    MetricGroup, Select)
>>> +                    MetricGroup, MetricRef, Select)
>>>  import argparse
>>>  import json
>>>  import math
>>> @@ -56,6 +56,24 @@ def Rapl() -> MetricGroup:
>>>                       description="Running Average Power Limit (RAPL) power consumption estimates")
>>>
>>>
>>> +def Smi() -> MetricGroup:
>>> +    aperf = Event('msr/aperf/')
>>> +    cycles = Event('cycles')
>>> +    smi_num = Event('msr/smi/')
>>> +    smi_cycles = Select(Select((aperf - cycles) / aperf, smi_num > 0, 0),
>>> +                        has_event(aperf),
>>> +                        0)
>>> +    return MetricGroup('smi', [
>>> +        Metric('smi_num', 'Number of SMI interrupts.',
>>> +               Select(smi_num, has_event(smi_num), 0), 'SMI#'),
>>> +        # Note, the smi_cycles "Event" is really a reference to the metric.
>>> +        Metric('smi_cycles',
>>> +               'Percentage of cycles spent in System Management Interrupts. '
>>> +               'Requires /sys/devices/cpu/freeze_on_smi to be 1.',
>>
>> It seems not work for hybrid?
> 
> Thanks. The code is a migration of existing metrics that exist for hybrid:
> 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#n74
> I still lack an easy way to test on hybrid, but I think fixing that
> case can be follow on work.

The metrics itself works on hybrid. But the description doesn't.
For hybrid, the location of the knob should be
/sys/devices/cpu_atom/freeze_on_smi
and
/sys/devices/cpu_core/freeze_on_smi

Maybe changes it as below?
'Requires /sys/devices/cpu*/freeze_on_smi to be 1.'

Thanks,
Kan