tools/perf/util/thread.c
Source file repositories/reference/linux-study-clean/tools/perf/util/thread.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/thread.c- Extension
.c- Size
- 15459 bytes
- Lines
- 624
- 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
elf.herrno.hfcntl.hstdlib.hstdio.hstring.hlinux/kernel.hlinux/zalloc.hdso.hsession.hthread.hthread-stack.hdebug.hnamespaces.hcomm.hmap.hsymbol.hunwind.hcallchain.hdwarf-regs.hapi/fs/fs.h
Detected Declarations
struct thread__prepare_access_maps_cb_argsstruct thread__e_machine_callback_argsfunction thread__init_mapsfunction thread__set_priv_destructorfunction thread__deletefunction thread__namespaces_listfunction thread__putfunction __thread__set_namespacesfunction thread__set_namespacesfunction ____thread__set_commfunction __thread__set_commfunction thread__set_comm_from_procfunction __thread__comm_lenfunction thread__comm_lenfunction thread__fprintffunction thread__insert_mapfunction thread__prepare_access_maps_cbfunction thread__prepare_accessfunction thread__clone_mapsfunction thread__forkfunction thread__find_cpumode_addr_locationfunction read_proc_e_machine_for_pidfunction thread__e_machine_callbackfunction thread__e_machinefunction thread__memcpyfunction thread__free_stitch_listfunction list_for_each_entry_safefunction list_for_each_entry_safe
Annotated Snippet
struct thread__prepare_access_maps_cb_args {
int err;
struct maps *maps;
};
static int thread__prepare_access_maps_cb(struct map *map, void *data)
{
bool initialized = false;
struct thread__prepare_access_maps_cb_args *args = data;
args->err = unwind__prepare_access(args->maps, map, &initialized);
return (args->err || initialized) ? 1 : 0;
}
static int thread__prepare_access(struct thread *thread)
{
struct thread__prepare_access_maps_cb_args args = {
.err = 0,
};
if (dwarf_callchain_users) {
args.maps = thread__maps(thread);
maps__for_each_map(thread__maps(thread), thread__prepare_access_maps_cb, &args);
}
return args.err;
}
static int thread__clone_maps(struct thread *thread, struct thread *parent, bool do_maps_clone)
{
/* This is new thread, we share map groups for process. */
if (thread__pid(thread) == thread__pid(parent))
return thread__prepare_access(thread);
if (maps__equal(thread__maps(thread), thread__maps(parent))) {
pr_debug("broken map groups on thread %d/%d parent %d/%d\n",
thread__pid(thread), thread__tid(thread),
thread__pid(parent), thread__tid(parent));
return 0;
}
/* But this one is new process, copy maps. */
return do_maps_clone ? maps__copy_from(thread__maps(thread), thread__maps(parent)) : 0;
}
int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone)
{
if (thread__comm_set(parent)) {
const char *comm = thread__comm_str(parent);
int err;
if (!comm)
return -ENOMEM;
err = thread__set_comm(thread, comm, timestamp);
if (err)
return err;
}
thread__set_ppid(thread, thread__tid(parent));
return thread__clone_maps(thread, parent, do_maps_clone);
}
void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
bool symbols, struct addr_location *al)
{
size_t i;
const u8 cpumodes[] = {
PERF_RECORD_MISC_USER,
PERF_RECORD_MISC_KERNEL,
PERF_RECORD_MISC_GUEST_USER,
PERF_RECORD_MISC_GUEST_KERNEL
};
for (i = 0; i < ARRAY_SIZE(cpumodes); i++) {
if (symbols)
thread__find_symbol(thread, cpumodes[i], addr, al);
else
thread__find_map(thread, cpumodes[i], addr, al);
if (al->map)
break;
}
}
static uint16_t read_proc_e_machine_for_pid(pid_t pid, uint32_t *e_flags)
{
char path[6 /* "/proc/" */ + 11 /* max length of pid */ + 5 /* "/exe\0" */];
int fd;
uint16_t e_machine = EM_NONE;
snprintf(path, sizeof(path), "/proc/%d/exe", pid);
Annotation
- Immediate include surface: `elf.h`, `errno.h`, `fcntl.h`, `stdlib.h`, `stdio.h`, `string.h`, `linux/kernel.h`, `linux/zalloc.h`.
- Detected declarations: `struct thread__prepare_access_maps_cb_args`, `struct thread__e_machine_callback_args`, `function thread__init_maps`, `function thread__set_priv_destructor`, `function thread__delete`, `function thread__namespaces_list`, `function thread__put`, `function __thread__set_namespaces`, `function thread__set_namespaces`, `function ____thread__set_comm`.
- 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.