[PATCH v4 02/22] perf jevents: Add idle metric for Intel models

Ian Rogers posted 22 patches 2 months ago
[PATCH v4 02/22] perf jevents: Add idle metric for Intel models
Posted by Ian Rogers 2 months ago
Compute using the msr PMU the percentage of wallclock cycles where the
CPUs are in a low power state.

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

diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
index 58e23eb48312..f875eb844c78 100755
--- a/tools/perf/pmu-events/intel_metrics.py
+++ b/tools/perf/pmu-events/intel_metrics.py
@@ -1,7 +1,8 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
-from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
-                    LoadEvents, Metric, MetricGroup, Select)
+from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
+                    JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
+                    MetricGroup, Select)
 import argparse
 import json
 import math
@@ -11,6 +12,16 @@ import os
 _args = None
 interval_sec = Event("duration_time")
 
+def Idle() -> Metric:
+  cyc = Event("msr/mperf/")
+  tsc = Event("msr/tsc/")
+  low = max(tsc - cyc, 0)
+  return Metric(
+      "idle",
+      "Percentage of total wallclock cycles where CPUs are in low power state (C1 or deeper sleep state)",
+      d_ratio(low, tsc), "100%")
+
+
 def Rapl() -> MetricGroup:
   """Processor power consumption estimate.
 
@@ -68,6 +79,7 @@ def main() -> None:
   LoadEvents(directory)
 
   all_metrics = MetricGroup("", [
+      Idle(),
       Rapl(),
   ])
 
-- 
2.46.1.824.gd892dcdcdd-goog
Re: [PATCH v4 02/22] perf jevents: Add idle metric for Intel models
Posted by Liang, Kan 3 weeks, 1 day ago

On 2024-09-26 1:50 p.m., Ian Rogers wrote:
> Compute using the msr PMU the percentage of wallclock cycles where the
> CPUs are in a low power state.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/pmu-events/intel_metrics.py | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
> index 58e23eb48312..f875eb844c78 100755
> --- a/tools/perf/pmu-events/intel_metrics.py
> +++ b/tools/perf/pmu-events/intel_metrics.py
> @@ -1,7 +1,8 @@
>  #!/usr/bin/env python3
>  # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
> -from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
> -                    LoadEvents, Metric, MetricGroup, Select)
> +from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
> +                    JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
> +                    MetricGroup, Select)
>  import argparse
>  import json
>  import math
> @@ -11,6 +12,16 @@ import os
>  _args = None
>  interval_sec = Event("duration_time")
>  
> +def Idle() -> Metric:
> +  cyc = Event("msr/mperf/")
> +  tsc = Event("msr/tsc/")
> +  low = max(tsc - cyc, 0)
> +  return Metric(
> +      "idle",
> +      "Percentage of total wallclock cycles where CPUs are in low power state (C1 or deeper sleep state)",
> +      d_ratio(low, tsc), "100%")

I'm not sure if the metrics is correct, especially considering the mperf
is a R/W register. If someone clear the mperf, the restuls must be wrong.

Thanks,
Kan

> +
> +
>  def Rapl() -> MetricGroup:
>    """Processor power consumption estimate.
>  
> @@ -68,6 +79,7 @@ def main() -> None:
>    LoadEvents(directory)
>  
>    all_metrics = MetricGroup("", [
> +      Idle(),
>        Rapl(),
>    ])
>
Re: [PATCH v4 02/22] perf jevents: Add idle metric for Intel models
Posted by Liang, Kan 3 weeks, 1 day ago

On 2024-11-06 12:01 p.m., Liang, Kan wrote:
> 
> 
> On 2024-09-26 1:50 p.m., Ian Rogers wrote:
>> Compute using the msr PMU the percentage of wallclock cycles where the
>> CPUs are in a low power state.
>>
>> Signed-off-by: Ian Rogers <irogers@google.com>
>> ---
>>  tools/perf/pmu-events/intel_metrics.py | 16 ++++++++++++++--
>>  1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
>> index 58e23eb48312..f875eb844c78 100755
>> --- a/tools/perf/pmu-events/intel_metrics.py
>> +++ b/tools/perf/pmu-events/intel_metrics.py
>> @@ -1,7 +1,8 @@
>>  #!/usr/bin/env python3
>>  # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
>> -from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
>> -                    LoadEvents, Metric, MetricGroup, Select)
>> +from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
>> +                    JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
>> +                    MetricGroup, Select)
>>  import argparse
>>  import json
>>  import math
>> @@ -11,6 +12,16 @@ import os
>>  _args = None
>>  interval_sec = Event("duration_time")
>>  
>> +def Idle() -> Metric:
>> +  cyc = Event("msr/mperf/")
>> +  tsc = Event("msr/tsc/")
>> +  low = max(tsc - cyc, 0)
>> +  return Metric(
>> +      "idle",
>> +      "Percentage of total wallclock cycles where CPUs are in low power state (C1 or deeper sleep state)",
>> +      d_ratio(low, tsc), "100%")
> 

The mperf and aperf can be enumerated. It's better to check it before
using it, has_event(mperf).

Thanks,
Kan

> I'm not sure if the metrics is correct, especially considering the mperf
> is a R/W register. If someone clear the mperf, the restuls must be wrong.
> 
> Thanks,
> Kan
> 
>> +
>> +
>>  def Rapl() -> MetricGroup:
>>    """Processor power consumption estimate.
>>  
>> @@ -68,6 +79,7 @@ def main() -> None:
>>    LoadEvents(directory)
>>  
>>    all_metrics = MetricGroup("", [
>> +      Idle(),
>>        Rapl(),
>>    ])
>>  
> 
>