tools/perf/util/mmap.c
Source file repositories/reference/linux-study-clean/tools/perf/util/mmap.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/mmap.c- Extension
.c- Size
- 9221 bytes
- Lines
- 360
- 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
sys/mman.herrno.hinttypes.hasm/bug.hlinux/zalloc.hstdlib.hstring.hunistd.hperf/mmap.hnumaif.hcpumap.hdebug.hevent.hmmap.h../perf.hinternal/lib.hlinux/bitmap.h
Detected Declarations
function Copyrightfunction mmap__mmap_lenfunction auxtrace_mmap__mmapfunction auxtrace_mmap__munmapfunction perf_mmap__aio_allocfunction perf_mmap__aio_freefunction perf_mmap__aio_bindfunction perf_mmap__aio_allocfunction perf_mmap__aio_freefunction perf_mmap__aio_bindfunction perf_mmap__aio_mmapfunction perf_mmap__aio_munmapfunction perf_mmap__aio_enabledfunction perf_mmap__aio_mmapfunction perf_mmap__aio_munmapfunction build_node_maskfunction perf_mmap__setup_affinity_maskfunction mmap__mmapfunction perf_mmap__push
Annotated Snippet
if (!node_mask) {
pr_err("Failed to allocate node mask for mbind: error %m\n");
return -1;
}
__set_bit(node_index, node_mask);
if (mbind(data, mmap_len, MPOL_BIND, node_mask, node_index + 1 + 1, 0)) {
pr_err("Failed to bind [%p-%p] AIO buffer to node %lu: error %m\n",
data, data + mmap_len, node_index);
err = -1;
}
bitmap_free(node_mask);
}
return err;
}
#else /* !HAVE_LIBNUMA_SUPPORT */
static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{
map->aio.data[idx] = malloc(mmap__mmap_len(map));
if (map->aio.data[idx] == NULL)
return -1;
return 0;
}
static void perf_mmap__aio_free(struct mmap *map, int idx)
{
zfree(&(map->aio.data[idx]));
}
static int perf_mmap__aio_bind(struct mmap *map __maybe_unused, int idx __maybe_unused,
struct perf_cpu cpu __maybe_unused, int affinity __maybe_unused)
{
return 0;
}
#endif
static int perf_mmap__aio_mmap(struct mmap *map, struct mmap_params *mp)
{
int delta_max, i, prio, ret;
map->aio.nr_cblocks = mp->nr_cblocks;
if (map->aio.nr_cblocks) {
map->aio.aiocb = calloc(map->aio.nr_cblocks, sizeof(struct aiocb *));
if (!map->aio.aiocb) {
pr_debug2("failed to allocate aiocb for data buffer, error %m\n");
return -1;
}
map->aio.cblocks = calloc(map->aio.nr_cblocks, sizeof(struct aiocb));
if (!map->aio.cblocks) {
pr_debug2("failed to allocate cblocks for data buffer, error %m\n");
return -1;
}
map->aio.data = calloc(map->aio.nr_cblocks, sizeof(void *));
if (!map->aio.data) {
pr_debug2("failed to allocate data buffer, error %m\n");
return -1;
}
delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX);
for (i = 0; i < map->aio.nr_cblocks; ++i) {
ret = perf_mmap__aio_alloc(map, i);
if (ret == -1) {
pr_debug2("failed to allocate data buffer area, error %m");
return -1;
}
ret = perf_mmap__aio_bind(map, i, map->core.cpu, mp->affinity);
if (ret == -1)
return -1;
/*
* Use cblock.aio_fildes value different from -1
* to denote started aio write operation on the
* cblock so it requires explicit record__aio_sync()
* call prior the cblock may be reused again.
*/
map->aio.cblocks[i].aio_fildes = -1;
/*
* Allocate cblocks with priority delta to have
* faster aio write system calls because queued requests
* are kept in separate per-prio queues and adding
* a new request will iterate thru shorter per-prio
* list. Blocks with numbers higher than
* _SC_AIO_PRIO_DELTA_MAX go with priority 0.
*/
prio = delta_max - i;
map->aio.cblocks[i].aio_reqprio = prio >= 0 ? prio : 0;
}
}
return 0;
}
Annotation
- Immediate include surface: `sys/mman.h`, `errno.h`, `inttypes.h`, `asm/bug.h`, `linux/zalloc.h`, `stdlib.h`, `string.h`, `unistd.h`.
- Detected declarations: `function Copyright`, `function mmap__mmap_len`, `function auxtrace_mmap__mmap`, `function auxtrace_mmap__munmap`, `function perf_mmap__aio_alloc`, `function perf_mmap__aio_free`, `function perf_mmap__aio_bind`, `function perf_mmap__aio_alloc`, `function perf_mmap__aio_free`, `function perf_mmap__aio_bind`.
- 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.