tools/perf/util/tool_pmu.c
Source file repositories/reference/linux-study-clean/tools/perf/util/tool_pmu.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/tool_pmu.c- Extension
.c- Size
- 13562 bytes
- Lines
- 580
- 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
cgroup.hcounts.hcputopo.hevsel.hpmu.hprint-events.hsmt.hstat.htime-utils.htool_pmu.htsc.hapi/fs/fs.hapi/io.hinternal/threadmap.hperf/threadmap.hfcntl.hstrings.h
Detected Declarations
function tool_pmu__skip_eventfunction tool_pmu__num_skip_eventsfunction tool_pmu__str_to_eventfunction tool_pmu__for_each_eventfunction perf_pmu__is_toolfunction evsel__is_toolfunction evsel__tool_eventfunction read_until_charfunction read_stat_fieldfunction read_pid_stat_fieldfunction evsel__tool_pmu_prepare_openfunction evsel__tool_pmu_openfunction arch_get_tsc_freqfunction tool_pmu__cpu_slots_per_cyclefunction has_pmemfunction tool_pmu__read_eventfunction perf_counts__updatefunction evsel__tool_pmu_read
Annotated Snippet
if (c == -2) {
/* Assume a -ve was read */
c = io__get_dec(&io, val);
*val *= -1;
}
if (c != ' ')
return -EINVAL;
if (field == i)
return 0;
i++;
}
return -EINVAL;
}
int evsel__tool_pmu_prepare_open(struct evsel *evsel,
struct perf_cpu_map *cpus,
int nthreads)
{
if ((evsel__tool_event(evsel) == TOOL_PMU__EVENT_SYSTEM_TIME ||
evsel__tool_event(evsel) == TOOL_PMU__EVENT_USER_TIME) &&
!evsel->start_times) {
evsel->start_times = xyarray__new(perf_cpu_map__nr(cpus),
nthreads,
sizeof(__u64));
if (!evsel->start_times)
return -ENOMEM;
}
return 0;
}
#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
int evsel__tool_pmu_open(struct evsel *evsel,
struct perf_thread_map *threads,
int start_cpu_map_idx, int end_cpu_map_idx)
{
enum tool_pmu_event ev = evsel__tool_event(evsel);
int pid = -1, idx = 0, thread = 0, nthreads, err = 0, old_errno;
if (ev == TOOL_PMU__EVENT_NUM_CPUS)
return 0;
if (ev == TOOL_PMU__EVENT_DURATION_TIME) {
if (evsel->core.attr.sample_period) /* no sampling */
return -EINVAL;
evsel->start_time = rdclock();
return 0;
}
if (evsel->cgrp)
pid = evsel->cgrp->fd;
nthreads = perf_thread_map__nr(threads);
for (idx = start_cpu_map_idx; idx < end_cpu_map_idx; idx++) {
for (thread = 0; thread < nthreads; thread++) {
if (!evsel->cgrp && !evsel->core.system_wide)
pid = perf_thread_map__pid(threads, thread);
if (ev == TOOL_PMU__EVENT_USER_TIME || ev == TOOL_PMU__EVENT_SYSTEM_TIME) {
bool system = ev == TOOL_PMU__EVENT_SYSTEM_TIME;
__u64 *start_time = NULL;
int fd;
if (evsel->core.attr.sample_period) {
/* no sampling */
err = -EINVAL;
goto out_close;
}
if (pid > -1) {
char buf[64];
snprintf(buf, sizeof(buf), "/proc/%d/stat", pid);
fd = open(buf, O_RDONLY);
evsel->pid_stat = true;
} else {
fd = open("/proc/stat", O_RDONLY);
}
FD(evsel, idx, thread) = fd;
if (fd < 0) {
err = -errno;
goto out_close;
}
start_time = xyarray__entry(evsel->start_times, idx, thread);
if (pid > -1) {
err = read_pid_stat_field(fd, system ? 15 : 14,
start_time);
} else {
struct perf_cpu cpu;
cpu = perf_cpu_map__cpu(evsel->core.cpus, idx);
Annotation
- Immediate include surface: `cgroup.h`, `counts.h`, `cputopo.h`, `evsel.h`, `pmu.h`, `print-events.h`, `smt.h`, `stat.h`.
- Detected declarations: `function tool_pmu__skip_event`, `function tool_pmu__num_skip_events`, `function tool_pmu__str_to_event`, `function tool_pmu__for_each_event`, `function perf_pmu__is_tool`, `function evsel__is_tool`, `function evsel__tool_event`, `function read_until_char`, `function read_stat_field`, `function read_pid_stat_field`.
- 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.