tools/perf/util/util.c
Source file repositories/reference/linux-study-clean/tools/perf/util/util.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/util.c- Extension
.c- Size
- 10881 bytes
- Lines
- 556
- 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
perf.hutil.hdebug.hevent.hapi/fs/fs.hsys/stat.hsys/utsname.hdirent.hfcntl.hinttypes.hsignal.hstdio.hstdlib.hstring.herrno.hlimits.hlinux/capability.hlinux/kernel.hlinux/log2.hlinux/time64.hlinux/overflow.hunistd.hcap.hstrlist.hstring2.h
Detected Declarations
function perf_set_singlethreadedfunction perf_set_multithreadedfunction sysctl__max_stackfunction sysctl__nmi_watchdog_enabledfunction event_attr_initfunction mkdir_pfunction match_patfunction rm_rf_depth_patfunction rm_rf_a_kcore_dirfunction kcore_dir_filterfunction rm_rf_kcore_dirfunction strlist__for_each_entryfunction cpumask_to_cpulistfunction print_separator2function rm_rf_perf_datafunction rm_rffunction lsdir_no_dot_filterfunction boolfunction hex_widthfunction perf_event_paranoidfunction perf_event_paranoid_checkfunction perf_tipfunction perf_debuginfod_setupfunction do_realloc_array_as_neededfunction sched_getcpufunction scandirat
Annotated Snippet
if (!match_pat(d->d_name, pat)) {
ret = -2;
break;
}
scnprintf(namebuf, sizeof(namebuf), "%s/%s",
path, d->d_name);
/* We have to check symbolic link itself */
ret = lstat(namebuf, &statbuf);
if (ret < 0) {
pr_debug("stat failed: %s\n", namebuf);
break;
}
if (S_ISDIR(statbuf.st_mode))
ret = depth ? rm_rf_depth_pat(namebuf, depth - 1, pat) : 0;
else
ret = unlink(namebuf);
}
closedir(dir);
if (ret < 0)
return ret;
return rmdir(path);
}
static int rm_rf_a_kcore_dir(const char *path, const char *name)
{
char kcore_dir_path[PATH_MAX];
const char *pat[] = {
"kcore",
"kallsyms",
"modules",
NULL,
};
snprintf(kcore_dir_path, sizeof(kcore_dir_path), "%s/%s", path, name);
return rm_rf_depth_pat(kcore_dir_path, 0, pat);
}
static bool kcore_dir_filter(const char *name __maybe_unused, struct dirent *d)
{
const char *pat[] = {
"kcore_dir",
"kcore_dir__[1-9]*",
NULL,
};
return match_pat(d->d_name, pat);
}
static int rm_rf_kcore_dir(const char *path)
{
struct strlist *kcore_dirs;
struct str_node *nd;
int ret;
kcore_dirs = lsdir(path, kcore_dir_filter);
if (!kcore_dirs)
return 0;
strlist__for_each_entry(nd, kcore_dirs) {
ret = rm_rf_a_kcore_dir(path, nd->s);
if (ret)
return ret;
}
strlist__delete(kcore_dirs);
return 0;
}
void cpumask_to_cpulist(char *cpumask, char *cpulist)
{
int i, j, bm_size, nbits;
int len = strlen(cpumask);
unsigned long *bm;
char cpus[MAX_NR_CPUS];
for (i = 0; i < len; i++) {
if (cpumask[i] == ',') {
for (j = i; j < len; j++)
cpumask[j] = cpumask[j + 1];
}
}
Annotation
- Immediate include surface: `perf.h`, `util.h`, `debug.h`, `event.h`, `api/fs/fs.h`, `sys/stat.h`, `sys/utsname.h`, `dirent.h`.
- Detected declarations: `function perf_set_singlethreaded`, `function perf_set_multithreaded`, `function sysctl__max_stack`, `function sysctl__nmi_watchdog_enabled`, `function event_attr_init`, `function mkdir_p`, `function match_pat`, `function rm_rf_depth_pat`, `function rm_rf_a_kcore_dir`, `function kcore_dir_filter`.
- 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.