tools/perf/pmu-events/amd_metrics.py
Source file repositories/reference/linux-study-clean/tools/perf/pmu-events/amd_metrics.py
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/pmu-events/amd_metrics.py- Extension
.py- Size
- 19841 bytes
- Lines
- 493
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
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)
# Global command line arguments.
_args = None
_zen_model: int = 1
interval_sec = Event("duration_time")
ins = Event("instructions")
cycles = Event("cycles")
# Number of CPU cycles scaled for SMT.
smt_cycles = Select(cycles / 2, Literal("#smt_on"), cycles)
def AmdBr():
def Total() -> MetricGroup:
br = Event("ex_ret_brn")
br_m_all = Event("ex_ret_brn_misp")
br_clr = Event("ex_ret_brn_cond_misp",
"ex_ret_msprd_brnch_instr_dir_msmtch",
"ex_ret_brn_resync")
br_r = d_ratio(br, interval_sec)
ins_r = d_ratio(ins, br)
misp_r = d_ratio(br_m_all, br)
clr_r = d_ratio(br_clr, interval_sec)
return MetricGroup("lpm_br_total", [
Metric("lpm_br_total_retired",
"The number of branch instructions retired per second.", br_r,
"insn/s"),
Metric(
"lpm_br_total_mispred",
"The number of branch instructions retired, of any type, that were "
"not correctly predicted as a percentage of all branch instrucions.",
misp_r, "100%"),
Metric("lpm_br_total_insn_between_branches",
"The number of instructions divided by the number of branches.",
ins_r, "insn"),
Metric("lpm_br_total_insn_fe_resteers",
"The number of resync branches per second.", clr_r, "req/s")
])
def Taken() -> MetricGroup:
br = Event("ex_ret_brn_tkn")
br_m_tk = Event("ex_ret_brn_tkn_misp")
br_r = d_ratio(br, interval_sec)
ins_r = d_ratio(ins, br)
misp_r = d_ratio(br_m_tk, br)
return MetricGroup("lpm_br_taken", [
Metric("lpm_br_taken_retired",
"The number of taken branches that were retired per second.",
br_r, "insn/s"),
Metric(
"lpm_br_taken_mispred",
"The number of retired taken branch instructions that were "
"mispredicted as a percentage of all taken branches.", misp_r,
"100%"),
Metric(
"lpm_br_taken_insn_between_branches",
"The number of instructions divided by the number of taken branches.",
ins_r, "insn"),
])
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.