tools/perf/tests/mmap-basic.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/mmap-basic.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/mmap-basic.c- Extension
.c- Size
- 12379 bytes
- Lines
- 446
- 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.hfcntl.hinttypes.hstdlib.hperf/cpumap.hcpumap.hdebug.hevent.hevlist.hevsel.hthread_map.htests.hutil/affinity.hutil/mmap.hutil/sample.hlinux/err.hlinux/kernel.hlinux/string.hperf/evlist.hperf/mmap.h
Detected Declarations
enum user_read_statefunction test__basic_mmapfunction set_user_readfunction test_stat_user_readfunction test__mmap_user_read_instrfunction test__mmap_user_read_cyclesfunction test__mmap_user_read_instr_disabledfunction test__mmap_user_read_cycles_disabled
Annotated Snippet
if (IS_ERR(evsels[i])) {
pr_debug("evsel__new(%s)\n", name);
if (PTR_ERR(evsels[i]) == -EACCES) {
/* Permissions failure, flag the failure as a skip. */
err = TEST_SKIP;
}
goto out_delete_evlist;
}
evsels[i]->core.attr.wakeup_events = 1;
evsel__set_sample_id(evsels[i], false);
evlist__add(evlist, evsels[i]);
if (evsel__open(evsels[i], cpus, threads) < 0) {
pr_debug("failed to open counter: %s, "
"tweak /proc/sys/kernel/perf_event_paranoid?\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
nr_events[i] = 0;
expected_nr_events[i] = 1 + rand() % 127;
}
if (evlist__mmap(evlist, 128) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno,
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
for (i = 0; i < nsyscalls; ++i)
for (j = 0; j < expected_nr_events[i]; ++j) {
syscalls[i]();
}
md = &evlist->mmap[0];
if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
while ((event = perf_mmap__read_event(&md->core)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_SAMPLE) {
pr_debug("unexpected %s event\n",
perf_event__name(event->header.type));
goto out_delete_evlist;
}
perf_sample__init(&sample, /*all=*/false);
err = evlist__parse_sample(evlist, event, &sample);
if (err) {
pr_err("Can't parse sample, err = %d\n", err);
perf_sample__exit(&sample);
goto out_delete_evlist;
}
err = -1;
evsel = evlist__id2evsel(evlist, sample.id);
perf_sample__exit(&sample);
if (evsel == NULL) {
pr_debug("event with id %" PRIu64
" doesn't map to an evsel\n", sample.id);
goto out_delete_evlist;
}
nr_events[evsel->core.idx]++;
perf_mmap__consume(&md->core);
}
perf_mmap__read_done(&md->core);
out_init:
err = 0;
evlist__for_each_entry(evlist, evsel) {
if (nr_events[evsel->core.idx] != expected_nr_events[evsel->core.idx]) {
pr_debug("expected %d %s events, got %d\n",
expected_nr_events[evsel->core.idx],
evsel__name(evsel), nr_events[evsel->core.idx]);
err = -1;
goto out_delete_evlist;
}
}
out_delete_evlist:
evlist__delete(evlist);
out_free_cpus:
perf_cpu_map__put(cpus);
out_free_threads:
perf_thread_map__put(threads);
return err;
}
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `inttypes.h`, `stdlib.h`, `perf/cpumap.h`, `cpumap.h`, `debug.h`, `event.h`.
- Detected declarations: `enum user_read_state`, `function test__basic_mmap`, `function set_user_read`, `function test_stat_user_read`, `function test__mmap_user_read_instr`, `function test__mmap_user_read_cycles`, `function test__mmap_user_read_instr_disabled`, `function test__mmap_user_read_cycles_disabled`.
- 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.