[v1,13/20] perf jevents: Add cycles breakdown metric for Intel

Message ID 20240229001806.4158429-14-irogers@google.com
State New
Headers
Series Python generated Intel metrics |

Commit Message

Ian Rogers Feb. 29, 2024, 12:17 a.m. UTC
  Breakdown cycles to user, kernel and guest.

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

Comments

Liang, Kan Feb. 29, 2024, 9:30 p.m. UTC | #1
On 2024-02-28 7:17 p.m., Ian Rogers wrote:
> Breakdown cycles to user, kernel and guest.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/pmu-events/intel_metrics.py | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
> index dae44d296861..fef40969a4b8 100755
> --- a/tools/perf/pmu-events/intel_metrics.py
> +++ b/tools/perf/pmu-events/intel_metrics.py
> @@ -26,6 +26,23 @@ core_cycles = Event("CPU_CLK_UNHALTED.THREAD_P_ANY",
>  smt_cycles = Select(core_cycles / 2, Literal("#smt_on"), core_cycles)
>  
>  
> +def Cycles() -> MetricGroup:
> +  cyc_k = Event("cycles:kHh")
> +  cyc_g = Event("cycles:G")
> +  cyc_u = Event("cycles:uH")
> +  cyc = cyc_k + cyc_g + cyc_u
> +
> +  return MetricGroup("cycles", [
> +      Metric("cycles_total", "Total number of cycles", cyc, "cycles"),
> +      Metric("cycles_user", "User cycles as a percentage of all cycles",
> +             d_ratio(cyc_u, cyc), "100%"),
> +      Metric("cycles_kernel", "Kernel cycles as a percentage of all cycles",
> +             d_ratio(cyc_k, cyc), "100%"),
> +      Metric("cycles_guest", "Hypervisor guest cycles as a percentage of all cycles",
> +             d_ratio(cyc_g, cyc), "100%"),
> +  ], description = "cycles breakdown per privilege level (users, kernel, guest)")
> +
> +
>  def Idle() -> Metric:
>    cyc = Event("msr/mperf/")
>    tsc = Event("msr/tsc/")
> @@ -770,6 +787,7 @@ def IntelLdSt() -> Optional[MetricGroup]:
>  
>  
>  all_metrics = MetricGroup("", [
> +    Cycles(),

The metric group seem exactly the same on AMD and ARM. Maybe we can have
tools/perf/pmu-events/common_metrics.py for all the common metrics.

Thanks,
Kan

>      Idle(),
>      Rapl(),
>      Smi(),
  
Ian Rogers March 1, 2024, 12:48 a.m. UTC | #2
On Thu, Feb 29, 2024 at 1:30 PM Liang, Kan <kan.liang@linux.intel.com> wrote:
>
>
>
> On 2024-02-28 7:17 p.m., Ian Rogers wrote:
> > Breakdown cycles to user, kernel and guest.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  tools/perf/pmu-events/intel_metrics.py | 18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> >
> > diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
> > index dae44d296861..fef40969a4b8 100755
> > --- a/tools/perf/pmu-events/intel_metrics.py
> > +++ b/tools/perf/pmu-events/intel_metrics.py
> > @@ -26,6 +26,23 @@ core_cycles = Event("CPU_CLK_UNHALTED.THREAD_P_ANY",
> >  smt_cycles = Select(core_cycles / 2, Literal("#smt_on"), core_cycles)
> >
> >
> > +def Cycles() -> MetricGroup:
> > +  cyc_k = Event("cycles:kHh")
> > +  cyc_g = Event("cycles:G")
> > +  cyc_u = Event("cycles:uH")
> > +  cyc = cyc_k + cyc_g + cyc_u
> > +
> > +  return MetricGroup("cycles", [
> > +      Metric("cycles_total", "Total number of cycles", cyc, "cycles"),
> > +      Metric("cycles_user", "User cycles as a percentage of all cycles",
> > +             d_ratio(cyc_u, cyc), "100%"),
> > +      Metric("cycles_kernel", "Kernel cycles as a percentage of all cycles",
> > +             d_ratio(cyc_k, cyc), "100%"),
> > +      Metric("cycles_guest", "Hypervisor guest cycles as a percentage of all cycles",
> > +             d_ratio(cyc_g, cyc), "100%"),
> > +  ], description = "cycles breakdown per privilege level (users, kernel, guest)")
> > +
> > +
> >  def Idle() -> Metric:
> >    cyc = Event("msr/mperf/")
> >    tsc = Event("msr/tsc/")
> > @@ -770,6 +787,7 @@ def IntelLdSt() -> Optional[MetricGroup]:
> >
> >
> >  all_metrics = MetricGroup("", [
> > +    Cycles(),
>
> The metric group seem exactly the same on AMD and ARM. Maybe we can have
> tools/perf/pmu-events/common_metrics.py for all the common metrics.

Agreed. I think we can drop cycles in the three sets and then once
then do the common_metrics.py as a follow up.

Thanks,
Ian

> Thanks,
> Kan
>
> >      Idle(),
> >      Rapl(),
> >      Smi(),
  
Liang, Kan March 1, 2024, 1:53 p.m. UTC | #3
On 2024-02-29 7:48 p.m., Ian Rogers wrote:
> On Thu, Feb 29, 2024 at 1:30 PM Liang, Kan <kan.liang@linux.intel.com> wrote:
>>
>>
>>
>> On 2024-02-28 7:17 p.m., Ian Rogers wrote:
>>> Breakdown cycles to user, kernel and guest.
>>>
>>> Signed-off-by: Ian Rogers <irogers@google.com>
>>> ---
>>>  tools/perf/pmu-events/intel_metrics.py | 18 ++++++++++++++++++
>>>  1 file changed, 18 insertions(+)
>>>
>>> diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
>>> index dae44d296861..fef40969a4b8 100755
>>> --- a/tools/perf/pmu-events/intel_metrics.py
>>> +++ b/tools/perf/pmu-events/intel_metrics.py
>>> @@ -26,6 +26,23 @@ core_cycles = Event("CPU_CLK_UNHALTED.THREAD_P_ANY",
>>>  smt_cycles = Select(core_cycles / 2, Literal("#smt_on"), core_cycles)
>>>
>>>
>>> +def Cycles() -> MetricGroup:
>>> +  cyc_k = Event("cycles:kHh")
>>> +  cyc_g = Event("cycles:G")
>>> +  cyc_u = Event("cycles:uH")
>>> +  cyc = cyc_k + cyc_g + cyc_u
>>> +
>>> +  return MetricGroup("cycles", [
>>> +      Metric("cycles_total", "Total number of cycles", cyc, "cycles"),
>>> +      Metric("cycles_user", "User cycles as a percentage of all cycles",
>>> +             d_ratio(cyc_u, cyc), "100%"),
>>> +      Metric("cycles_kernel", "Kernel cycles as a percentage of all cycles",
>>> +             d_ratio(cyc_k, cyc), "100%"),
>>> +      Metric("cycles_guest", "Hypervisor guest cycles as a percentage of all cycles",
>>> +             d_ratio(cyc_g, cyc), "100%"),
>>> +  ], description = "cycles breakdown per privilege level (users, kernel, guest)")
>>> +
>>> +
>>>  def Idle() -> Metric:
>>>    cyc = Event("msr/mperf/")
>>>    tsc = Event("msr/tsc/")
>>> @@ -770,6 +787,7 @@ def IntelLdSt() -> Optional[MetricGroup]:
>>>
>>>
>>>  all_metrics = MetricGroup("", [
>>> +    Cycles(),
>>
>> The metric group seem exactly the same on AMD and ARM. Maybe we can have
>> tools/perf/pmu-events/common_metrics.py for all the common metrics.
> 
> Agreed. I think we can drop cycles in the three sets and then once
> then do the common_metrics.py as a follow up.
>

Sounds good to me.

Thanks,
Kan

> Thanks,
> Ian
> 
>> Thanks,
>> Kan
>>
>>>      Idle(),
>>>      Rapl(),
>>>      Smi(),
>
  

Patch

diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
index dae44d296861..fef40969a4b8 100755
--- a/tools/perf/pmu-events/intel_metrics.py
+++ b/tools/perf/pmu-events/intel_metrics.py
@@ -26,6 +26,23 @@  core_cycles = Event("CPU_CLK_UNHALTED.THREAD_P_ANY",
 smt_cycles = Select(core_cycles / 2, Literal("#smt_on"), core_cycles)
 
 
+def Cycles() -> MetricGroup:
+  cyc_k = Event("cycles:kHh")
+  cyc_g = Event("cycles:G")
+  cyc_u = Event("cycles:uH")
+  cyc = cyc_k + cyc_g + cyc_u
+
+  return MetricGroup("cycles", [
+      Metric("cycles_total", "Total number of cycles", cyc, "cycles"),
+      Metric("cycles_user", "User cycles as a percentage of all cycles",
+             d_ratio(cyc_u, cyc), "100%"),
+      Metric("cycles_kernel", "Kernel cycles as a percentage of all cycles",
+             d_ratio(cyc_k, cyc), "100%"),
+      Metric("cycles_guest", "Hypervisor guest cycles as a percentage of all cycles",
+             d_ratio(cyc_g, cyc), "100%"),
+  ], description = "cycles breakdown per privilege level (users, kernel, guest)")
+
+
 def Idle() -> Metric:
   cyc = Event("msr/mperf/")
   tsc = Event("msr/tsc/")
@@ -770,6 +787,7 @@  def IntelLdSt() -> Optional[MetricGroup]:
 
 
 all_metrics = MetricGroup("", [
+    Cycles(),
     Idle(),
     Rapl(),
     Smi(),