tools/perf/bench/mem-functions.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/mem-functions.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/mem-functions.c- Extension
.c- Size
- 15211 bytes
- Lines
- 631
- 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
bench.h../perf-sys.hsubcmd/parse-options.hutil/cloexec.hutil/debug.hutil/header.hutil/stat.hutil/string2.hmem-memcpy-arch.hmem-memset-arch.hstdio.hstdlib.hstring.hunistd.hsys/time.hsys/mman.herrno.hlinux/time64.hlinux/log2.hpthread.hmem-memcpy-x86-64-asm-def.hmem-memset-x86-64-asm-def.h
Detected Declarations
struct bench_paramsstruct bench_mem_infostruct functionstruct mmap_datafunction init_cyclesfunction get_cyclesfunction clock_getfunction clock_difffunction clock_accumfunction timeval2doublefunction __bench_mem_functionfunction bench_mem_commonfunction memcpy_prefaultfunction do_memcpyfunction bench_munmapfunction mem_allocfunction mem_freefunction bench_mem_memcpyfunction do_memsetfunction bench_mem_memsetfunction mmap_page_touchfunction do_mmapfunction bench_mem_mmap
Annotated Snippet
static int do_mmap(const struct function *r, struct bench_params *p,
void *src __maybe_unused, void *dst __maybe_unused,
union bench_clock *accum)
{
struct mmap_data *data;
int error = 0;
data = calloc(nr_threads, sizeof(*data));
if (!data) {
printf("# Failed to allocate thread resources\n");
return -1;
}
for (unsigned int i = 0; i < nr_threads; i++) {
data[i].func = r;
data[i].params = p;
if (p->seed)
data[i].seed = p->seed + i;
if (pthread_create(&data[i].id, NULL, do_mmap_thread, &data[i]) < 0)
data[i].error = -errno;
}
for (unsigned int i = 0; i < nr_threads; i++) {
union bench_clock *t = &data[i].result;
pthread_join(data[i].id, NULL);
clock_accum(accum, t);
if (use_cycles)
update_stats(&stats, t->cycles);
else
update_stats(&stats, t->tv.tv_sec * 1e6 + t->tv.tv_usec);
error |= data[i].error;
}
free(data);
if (error) {
printf("# Memory allocation failed - maybe size (%s) %s?\n", size_str,
p->page_shift != PAGE_SHIFT_4KB ? "has insufficient hugepages" : "is too large");
}
return error ? -1 : 0;
}
static const char * const bench_mem_mmap_usage[] = {
"perf bench mem mmap <options>",
NULL
};
static const struct function mmap_functions[] = {
{ .name = "demand",
.desc = "Demand loaded mmap()",
.fn.mmap_op = mmap_page_touch },
{ .name = "populate",
.desc = "Eagerly populated mmap()",
.fn.mmap_op = mmap_page_touch },
{ .name = NULL, }
};
int bench_mem_mmap(int argc, const char **argv)
{
static const struct option bench_mmap_options[] = {
OPT_UINTEGER('r', "randomize", &seed,
"Seed to randomize page access offset."),
OPT_UINTEGER('t', "threads", &nr_threads,
"Number of threads to run concurrently (default: 1)."),
OPT_PARENT(bench_common_options),
OPT_END()
};
struct bench_mem_info info = {
.functions = mmap_functions,
.do_op = do_mmap,
.usage = bench_mem_mmap_usage,
.options = bench_mmap_options,
};
return bench_mem_common(argc, argv, &info);
}
Annotation
- Immediate include surface: `bench.h`, `../perf-sys.h`, `subcmd/parse-options.h`, `util/cloexec.h`, `util/debug.h`, `util/header.h`, `util/stat.h`, `util/string2.h`.
- Detected declarations: `struct bench_params`, `struct bench_mem_info`, `struct function`, `struct mmap_data`, `function init_cycles`, `function get_cycles`, `function clock_get`, `function clock_diff`, `function clock_accum`, `function timeval2double`.
- 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.