tools/perf/util/machine.c
Source file repositories/reference/linux-study-clean/tools/perf/util/machine.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/machine.c- Extension
.c- Size
- 86355 bytes
- Lines
- 3341
- 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
dirent.herrno.hinttypes.hregex.hstdlib.hcallchain.hdebug.hdso.henv.hevent.hevsel.hhist.hmachine.hmap.hmap_symbol.hbranch.hmem-events.hmem-info.hpath.hsrcline.hsymbol.hsynthetic-events.hsort.hstrlist.htarget.hthread.hutil.hvdso.hstdbool.hsys/types.hsys/stat.hunistd.h
Detected Declarations
struct machine_fprintf_cb_argsstruct machine__map_x86_64_entry_trampolines_argsstruct iterationsstruct machine__for_each_dso_cb_argsfunction machine__set_mmap_namefunction thread__set_guest_commfunction machine__initfunction mmap_handlerfunction machine__init_livefunction machine__delete_threadsfunction machine__exitfunction machine__deletefunction machines__initfunction machines__exitfunction machines__set_comm_execfunction thread__set_guest_commfunction machines__process_guestsfunction machines__set_id_hdr_sizefunction machine__update_thread_pidfunction get_idle_threadfunction machine__process_comm_eventfunction machine__process_namespaces_eventfunction machine__process_cgroup_eventfunction machine__process_lost_eventfunction machine__process_lost_samples_eventfunction machine__process_aux_eventfunction machine__process_itrace_start_eventfunction machine__process_aux_output_hw_id_eventfunction machine__process_switch_eventfunction machine__process_ksymbol_registerfunction machine__process_ksymbol_unregisterfunction machine__process_ksymbolfunction machine__process_text_pokefunction machines__fprintf_dsosfunction machine__fprintf_dsos_buildidfunction machines__fprintf_dsos_buildidfunction machine_fprintf_cbfunction machine__fprintffunction machine__get_kallsyms_filenamefunction machine__get_running_kernel_startfunction machine__create_extra_kernel_mapfunction find_entry_trampolinefunction machine__map_x86_64_entry_trampolines_cbfunction machine__map_x86_64_entry_trampolinesfunction machine__create_extra_kernel_mapsfunction __machine__create_kernel_mapsfunction machine__destroy_kernel_mapsfunction machines__create_guest_kernel_maps
Annotated Snippet
struct machine_fprintf_cb_args {
FILE *fp;
size_t printed;
};
static int machine_fprintf_cb(struct thread *thread, void *data)
{
struct machine_fprintf_cb_args *args = data;
/* TODO: handle fprintf errors. */
args->printed += thread__fprintf(thread, args->fp);
return 0;
}
size_t machine__fprintf(struct machine *machine, FILE *fp)
{
struct machine_fprintf_cb_args args = {
.fp = fp,
.printed = 0,
};
size_t ret = fprintf(fp, "Threads: %zu\n", threads__nr(&machine->threads));
machine__for_each_thread(machine, machine_fprintf_cb, &args);
return ret + args.printed;
}
static struct dso *machine__get_kernel(struct machine *machine)
{
const char *vmlinux_name = machine->mmap_name;
struct dso *kernel;
if (machine__is_host(machine)) {
if (symbol_conf.vmlinux_name)
vmlinux_name = symbol_conf.vmlinux_name;
kernel = machine__findnew_kernel(machine, vmlinux_name,
"[kernel]", DSO_SPACE__KERNEL);
} else {
if (symbol_conf.default_guest_vmlinux_name)
vmlinux_name = symbol_conf.default_guest_vmlinux_name;
kernel = machine__findnew_kernel(machine, vmlinux_name,
"[guest.kernel]",
DSO_SPACE__KERNEL_GUEST);
}
if (kernel != NULL && (!dso__has_build_id(kernel)))
dso__read_running_kernel_build_id(kernel, machine);
return kernel;
}
void machine__get_kallsyms_filename(struct machine *machine, char *buf,
size_t bufsz)
{
if (machine__is_default_guest(machine))
scnprintf(buf, bufsz, "%s", symbol_conf.default_guest_kallsyms);
else
scnprintf(buf, bufsz, "%s/proc/kallsyms", machine->root_dir);
}
const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
/* Figure out the start address of kernel map from /proc/kallsyms.
* Returns the name of the start symbol in *symbol_name. Pass in NULL as
* symbol_name if it's not that important.
*/
static int machine__get_running_kernel_start(struct machine *machine,
const char **symbol_name,
u64 *start, u64 *end)
{
char filename[PATH_MAX];
int i, err = -1;
const char *name;
u64 addr = 0;
machine__get_kallsyms_filename(machine, filename, PATH_MAX);
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
return 0;
for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
err = kallsyms__get_function_start(filename, name, &addr);
if (!err)
break;
}
if (err)
return -1;
Annotation
- Immediate include surface: `dirent.h`, `errno.h`, `inttypes.h`, `regex.h`, `stdlib.h`, `callchain.h`, `debug.h`, `dso.h`.
- Detected declarations: `struct machine_fprintf_cb_args`, `struct machine__map_x86_64_entry_trampolines_args`, `struct iterations`, `struct machine__for_each_dso_cb_args`, `function machine__set_mmap_name`, `function thread__set_guest_comm`, `function machine__init`, `function mmap_handler`, `function machine__init_live`, `function machine__delete_threads`.
- 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.