tools/testing/selftests/ring-buffer/map_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/ring-buffer/map_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/ring-buffer/map_test.c- Extension
.c- Size
- 7157 bytes
- Lines
- 325
- 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
fcntl.hsched.hstdbool.hstdio.hstdlib.hunistd.hlinux/trace_mmap.hsys/mman.hsys/ioctl.h../user_events/user_events_selftests.hkselftest_harness.h
Detected Declarations
struct tracefs_cpu_map_descfunction Copyrightfunction __tracefs_write_intfunction tracefs_resetfunction tracefs_cpu_mapfunction tracefs_cpu_unmap
Annotated Snippet
struct tracefs_cpu_map_desc {
struct trace_buffer_meta *meta;
int cpu_fd;
};
int tracefs_cpu_map(struct tracefs_cpu_map_desc *desc, int cpu)
{
int page_size = getpagesize();
char *cpu_path;
void *map;
if (asprintf(&cpu_path,
TRACEFS_ROOT"/per_cpu/cpu%d/trace_pipe_raw",
cpu) < 0)
return -ENOMEM;
desc->cpu_fd = open(cpu_path, O_RDONLY | O_NONBLOCK);
free(cpu_path);
if (desc->cpu_fd < 0)
return -ENODEV;
again:
map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, desc->cpu_fd, 0);
if (map == MAP_FAILED)
return -errno;
desc->meta = (struct trace_buffer_meta *)map;
/* the meta-page is bigger than the original mapping */
if (page_size < desc->meta->meta_struct_len) {
int meta_page_size = desc->meta->meta_page_size;
munmap(desc->meta, page_size);
page_size = meta_page_size;
goto again;
}
return 0;
}
void tracefs_cpu_unmap(struct tracefs_cpu_map_desc *desc)
{
munmap(desc->meta, desc->meta->meta_page_size);
close(desc->cpu_fd);
}
FIXTURE(map) {
struct tracefs_cpu_map_desc map_desc;
bool umount;
};
FIXTURE_VARIANT(map) {
int subbuf_size;
};
FIXTURE_VARIANT_ADD(map, subbuf_size_4k) {
.subbuf_size = 4,
};
FIXTURE_VARIANT_ADD(map, subbuf_size_8k) {
.subbuf_size = 8,
};
FIXTURE_SETUP(map)
{
int cpu = sched_getcpu();
cpu_set_t cpu_mask;
bool fail, umount;
char *message;
if (getuid() != 0)
SKIP(return, "Skipping: %s", "Please run the test as root");
if (!tracefs_enabled(&message, &fail, &umount)) {
if (fail) {
TH_LOG("Tracefs setup failed: %s", message);
ASSERT_FALSE(fail);
}
SKIP(return, "Skipping: %s", message);
}
self->umount = umount;
ASSERT_GE(cpu, 0);
ASSERT_EQ(tracefs_reset(), 0);
tracefs_write_int(TRACEFS_ROOT"/buffer_subbuf_size_kb", variant->subbuf_size);
ASSERT_EQ(tracefs_cpu_map(&self->map_desc, cpu), 0);
Annotation
- Immediate include surface: `fcntl.h`, `sched.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `unistd.h`, `linux/trace_mmap.h`, `sys/mman.h`.
- Detected declarations: `struct tracefs_cpu_map_desc`, `function Copyright`, `function __tracefs_write_int`, `function tracefs_reset`, `function tracefs_cpu_map`, `function tracefs_cpu_unmap`.
- 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.