tools/lib/perf/cpumap.c
Source file repositories/reference/linux-study-clean/tools/lib/perf/cpumap.c
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/perf/cpumap.c- Extension
.c- Size
- 11569 bytes
- Lines
- 495
- 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
errno.hperf/cpumap.hstdlib.hlinux/refcount.hinternal/cpumap.hasm/bug.hstdio.hstring.hunistd.hctype.hlimits.hinternal.hapi/fs/fs.h
Detected Declarations
function perf_cpu_map__set_nrfunction cpu_map__deletefunction perf_cpu_map__putfunction cmp_cpufunction __perf_cpu_map__cpufunction __perf_cpu_map__nrfunction perf_cpu_map__cpufunction perf_cpu_map__nrfunction perf_cpu_map__has_any_cpu_or_is_emptyfunction perf_cpu_map__is_any_cpu_or_is_emptyfunction perf_cpu_map__is_emptyfunction perf_cpu_map__idxfunction perf_cpu_map__hasfunction perf_cpu_map__equalfunction perf_cpu_map__has_any_cpufunction perf_cpu_map__minfunction perf_cpu_map__for_each_cpu_skip_anyfunction perf_cpu_map__maxfunction perf_cpu_map__is_subsetfunction change
Annotated Snippet
__perf_cpu_map__cpu(cpus, i - 1).cpu) {
RC_CHK_ACCESS(cpus)->map[j++].cpu =
__perf_cpu_map__cpu(cpus, i).cpu;
}
}
perf_cpu_map__set_nr(cpus, j);
assert(j <= nr_cpus);
}
return cpus;
}
struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
{
struct perf_cpu_map *cpus = NULL;
unsigned long start_cpu, end_cpu = 0;
char *p = NULL;
unsigned int nr_cpus = 0, max_entries = 0;
struct perf_cpu *tmp_cpus = NULL, *tmp;
if (!cpu_list)
return perf_cpu_map__new_online_cpus();
/*
* must handle the case of empty cpumap to cover
* TOPOLOGY header for NUMA nodes with no CPU
* ( e.g., because of CPU hotplug)
*/
if (!isdigit(*cpu_list) && *cpu_list != '\0')
goto out;
while (isdigit(*cpu_list)) {
p = NULL;
start_cpu = strtoul(cpu_list, &p, 0);
if (start_cpu >= INT16_MAX
|| (*p != '\0' && *p != ',' && *p != '-' && *p != '\n'))
goto invalid;
if (*p == '-') {
cpu_list = ++p;
p = NULL;
end_cpu = strtoul(cpu_list, &p, 0);
if (end_cpu >= INT16_MAX || (*p != '\0' && *p != ',' && *p != '\n'))
goto invalid;
if (end_cpu < start_cpu)
goto invalid;
} else {
end_cpu = start_cpu;
}
WARN_ONCE(end_cpu >= MAX_NR_CPUS, "Perf can support %d CPUs. "
"Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS);
for (; start_cpu <= end_cpu; start_cpu++) {
/* check for duplicates */
for (unsigned int i = 0; i < nr_cpus; i++) {
if (tmp_cpus[i].cpu == (int16_t)start_cpu)
goto invalid;
}
if (nr_cpus == max_entries) {
max_entries += max(end_cpu - start_cpu + 1, 16UL);
tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu));
if (tmp == NULL)
goto invalid;
tmp_cpus = tmp;
}
tmp_cpus[nr_cpus++].cpu = (int16_t)start_cpu;
}
if (*p)
++p;
cpu_list = p;
}
if (nr_cpus > 0) {
cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
} else if (*cpu_list != '\0') {
pr_warning("Unexpected characters at end of cpu list ('%s'), using online CPUs.",
cpu_list);
cpus = perf_cpu_map__new_online_cpus();
} else {
cpus = perf_cpu_map__new_any_cpu();
}
invalid:
free(tmp_cpus);
out:
return cpus;
}
Annotation
- Immediate include surface: `errno.h`, `perf/cpumap.h`, `stdlib.h`, `linux/refcount.h`, `internal/cpumap.h`, `asm/bug.h`, `stdio.h`, `string.h`.
- Detected declarations: `function perf_cpu_map__set_nr`, `function cpu_map__delete`, `function perf_cpu_map__put`, `function cmp_cpu`, `function __perf_cpu_map__cpu`, `function __perf_cpu_map__nr`, `function perf_cpu_map__cpu`, `function perf_cpu_map__nr`, `function perf_cpu_map__has_any_cpu_or_is_empty`, `function perf_cpu_map__is_any_cpu_or_is_empty`.
- 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.