tools/perf/bench/pmu-scan.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/pmu-scan.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/pmu-scan.c- Extension
.c- Size
- 3951 bytes
- Lines
- 188
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdio.hbench.hutil/debug.hutil/pmu.hutil/pmus.hutil/stat.hlinux/atomic.hlinux/err.hlinux/time64.hsubcmd/parse-options.h
Detected Declarations
struct pmu_scan_resultfunction save_resultfunction check_resultfunction delete_resultfunction run_pmu_scanfunction bench_pmu_scan
Annotated Snippet
struct pmu_scan_result {
char *name;
int nr_aliases;
int nr_formats;
int nr_caps;
bool is_core;
};
static const struct option options[] = {
OPT_UINTEGER('i', "iterations", &iterations,
"Number of iterations used to compute average"),
OPT_END()
};
static const char *const bench_usage[] = {
"perf bench internals pmu-scan <options>",
NULL
};
static int nr_pmus;
static struct pmu_scan_result *results;
static int save_result(void)
{
struct perf_pmu *pmu = NULL;
struct list_head *list;
struct pmu_scan_result *r;
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
r = realloc(results, (nr_pmus + 1) * sizeof(*r));
if (r == NULL)
return -ENOMEM;
results = r;
r = results + nr_pmus;
r->name = strdup(pmu->name);
r->is_core = pmu->is_core;
r->nr_caps = pmu->nr_caps;
r->nr_aliases = perf_pmu__num_events(pmu);
r->nr_formats = 0;
list_for_each(list, &pmu->format)
r->nr_formats++;
pr_debug("pmu[%d] name=%s, nr_caps=%d, nr_aliases=%d, nr_formats=%d\n",
nr_pmus, r->name, r->nr_caps, r->nr_aliases, r->nr_formats);
nr_pmus++;
}
perf_pmus__destroy();
return 0;
}
static int check_result(bool core_only)
{
struct pmu_scan_result *r;
struct perf_pmu *pmu;
struct list_head *list;
int nr;
for (int i = 0; i < nr_pmus; i++) {
r = &results[i];
if (core_only && !r->is_core)
continue;
pmu = perf_pmus__find(r->name);
if (pmu == NULL) {
pr_err("Cannot find PMU %s\n", r->name);
return -1;
}
if (pmu->nr_caps != (u32)r->nr_caps) {
pr_err("Unmatched number of event caps in %s: expect %d vs got %d\n",
pmu->name, r->nr_caps, pmu->nr_caps);
return -1;
}
nr = perf_pmu__num_events(pmu);
if (nr != r->nr_aliases) {
pr_err("Unmatched number of event aliases in %s: expect %d vs got %d\n",
pmu->name, r->nr_aliases, nr);
return -1;
}
nr = 0;
list_for_each(list, &pmu->format)
nr++;
if (nr != r->nr_formats) {
Annotation
- Immediate include surface: `errno.h`, `stdio.h`, `bench.h`, `util/debug.h`, `util/pmu.h`, `util/pmus.h`, `util/stat.h`, `linux/atomic.h`.
- Detected declarations: `struct pmu_scan_result`, `function save_result`, `function check_result`, `function delete_result`, `function run_pmu_scan`, `function bench_pmu_scan`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.