tools/perf/tests/mmap-thread-lookup.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/mmap-thread-lookup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/mmap-thread-lookup.c- Extension
.c- Size
- 5060 bytes
- Lines
- 247
- 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
inttypes.hunistd.hsys/syscall.hsys/types.hsys/mman.hpthread.hstdlib.hstdio.hdebug.henv.hevent.htests.hmachine.hthread_map.hmap.hsymbol.hutil/synthetic-events.hthread.hinternal/lib.h
Detected Declarations
struct thread_datafunction thread_initfunction thread_createfunction threads_createfunction threads_destroyfunction synth_allfunction synth_processfunction mmap_eventsfunction perf_event__synthesize_thread_map
Annotated Snippet
struct thread_data {
pthread_t pt;
pid_t tid;
void *map;
int ready[2];
};
static struct thread_data threads[THREADS];
static int thread_init(struct thread_data *td)
{
void *map;
map = mmap(NULL, page_size,
PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (map == MAP_FAILED) {
perror("mmap failed");
return -1;
}
td->map = map;
td->tid = syscall(SYS_gettid);
pr_debug("tid = %d, map = %p\n", td->tid, map);
return 0;
}
static void *thread_fn(void *arg)
{
struct thread_data *td = arg;
ssize_t ret;
int go = 0;
if (thread_init(td))
return NULL;
/* Signal thread_create thread is initialized. */
ret = write(td->ready[1], &go, sizeof(int));
if (ret != sizeof(int)) {
pr_err("failed to notify\n");
return NULL;
}
while (!go_away) {
/* Waiting for main thread to kill us. */
usleep(100);
}
munmap(td->map, page_size);
return NULL;
}
static int thread_create(int i)
{
struct thread_data *td = &threads[i];
int err, go;
if (pipe(td->ready))
return -1;
err = pthread_create(&td->pt, NULL, thread_fn, td);
if (!err) {
/* Wait for thread initialization. */
ssize_t ret = read(td->ready[0], &go, sizeof(int));
err = ret != sizeof(int);
}
close(td->ready[0]);
close(td->ready[1]);
return err;
}
static int threads_create(void)
{
struct thread_data *td0 = &threads[0];
int i, err = 0;
go_away = 0;
/* 0 is main thread */
if (thread_init(td0))
return -1;
for (i = 1; !err && i < THREADS; i++)
err = thread_create(i);
return err;
}
Annotation
- Immediate include surface: `inttypes.h`, `unistd.h`, `sys/syscall.h`, `sys/types.h`, `sys/mman.h`, `pthread.h`, `stdlib.h`, `stdio.h`.
- Detected declarations: `struct thread_data`, `function thread_init`, `function thread_create`, `function threads_create`, `function threads_destroy`, `function synth_all`, `function synth_process`, `function mmap_events`, `function perf_event__synthesize_thread_map`.
- 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.