perf jevents: Add cycles breakdown metric for arm64/AMD/Intel

Breakdown cycles to user, kernel and guest. Add a common_metrics.py
file for such metrics.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Thomas Falcon <thomas.falcon@intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Benjamin Gray <bgray@linux.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xu Yang <xu.yang_2@nxp.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2026-01-27 10:45:05 -08:00 committed by Arnaldo Carvalho de Melo
parent e74f72a7e2
commit 82e53e7ae0
5 changed files with 28 additions and 2 deletions

View File

@ -52,7 +52,7 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) $(JSON_DIRS_ROOT)
$(call rule_mkdir)
$(Q)$(call echo-cmd,gen)$(PYTHON) $(LEGACY_CACHE_PY) > $@
GEN_METRIC_DEPS := pmu-events/metric.py
GEN_METRIC_DEPS := pmu-events/metric.py pmu-events/common_metrics.py
# Generate AMD Json
ZENS = $(shell ls -d pmu-events/arch/x86/amdzen*)

View File

@ -4,6 +4,7 @@ import argparse
import math
import os
from typing import Optional
from common_metrics import Cycles
from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
JsonEncodeMetricGroupDescriptions, Literal, LoadEvents,
Metric, MetricGroup, Select)
@ -475,6 +476,7 @@ def main() -> None:
AmdItlb(),
AmdLdSt(),
AmdUpc(),
Cycles(),
Idle(),
Rapl(),
UncoreL3(),

View File

@ -4,6 +4,7 @@ import argparse
import os
from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, LoadEvents,
MetricGroup)
from common_metrics import Cycles
# Global command line arguments.
_args = None
@ -34,7 +35,9 @@ def main() -> None:
directory = f"{_args.events_path}/arm64/{_args.vendor}/{_args.model}/"
LoadEvents(directory)
all_metrics = MetricGroup("", [])
all_metrics = MetricGroup("", [
Cycles(),
])
if _args.metricgroups:
print(JsonEncodeMetricGroupDescriptions(all_metrics))

View File

@ -0,0 +1,19 @@
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
from metric import (d_ratio, Event, Metric, MetricGroup)
def Cycles() -> MetricGroup:
cyc_k = Event("cpu\\-cycles:kHh") # exclude user and guest
cyc_g = Event("cpu\\-cycles:G") # exclude host
cyc_u = Event("cpu\\-cycles:uH") # exclude kernel, hypervisor and guest
cyc = cyc_k + cyc_g + cyc_u
return MetricGroup("lpm_cycles", [
Metric("lpm_cycles_total", "Total number of cycles", cyc, "cycles"),
Metric("lpm_cycles_user", "User cycles as a percentage of all cycles",
d_ratio(cyc_u, cyc), "100%"),
Metric("lpm_cycles_kernel", "Kernel cycles as a percentage of all cycles",
d_ratio(cyc_k, cyc), "100%"),
Metric("lpm_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)")

View File

@ -6,6 +6,7 @@ import math
import os
import re
from typing import Optional
from common_metrics import Cycles
from metric import (d_ratio, has_event, max, source_count, CheckPmu, Event,
JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
Literal, LoadEvents, Metric, MetricConstraint, MetricGroup,
@ -1095,6 +1096,7 @@ def main() -> None:
LoadEvents(directory)
all_metrics = MetricGroup("", [
Cycles(),
Idle(),
Rapl(),
Smi(),