tools/perf/util/svghelper.c
Source file repositories/reference/linux-study-clean/tools/perf/util/svghelper.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/svghelper.c- Extension
.c- Size
- 23312 bytes
- Lines
- 811
- 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.hstdio.hstdlib.hunistd.hstring.hlinux/bitmap.hlinux/string.hlinux/time64.hlinux/zalloc.hinternal/cpumap.hperf/cpumap.henv.hperf.hsvghelper.h
Detected Declarations
struct topologyfunction cpu2slotfunction cpu2yfunction time2pixelsfunction round_text_sizefunction open_svgfunction normalize_heightfunction svg_uboxfunction svg_lboxfunction svg_fboxfunction svg_boxfunction svg_blockedfunction svg_runningfunction svg_waitingfunction svg_cpu_boxfunction svg_processfunction svg_cstatefunction svg_pstatefunction svg_partial_wakelinefunction svg_wakelinefunction svg_interruptfunction svg_textfunction svg_legenda_boxfunction svg_io_legendafunction svg_legendafunction svg_time_gridfunction svg_closefunction scan_thread_topologyfunction scan_core_topologyfunction str_to_bitmapfunction perf_cpu_map__for_each_cpufunction svg_build_topology_map
Annotated Snippet
struct topology {
cpumask_t *sib_core;
int sib_core_nr;
cpumask_t *sib_thr;
int sib_thr_nr;
};
static void scan_thread_topology(int *map, struct topology *t, int cpu,
int *pos, int nr_cpus)
{
int i;
int thr;
for (i = 0; i < t->sib_thr_nr; i++) {
if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
continue;
for_each_set_bit(thr, cpumask_bits(&t->sib_thr[i]), nr_cpus)
if (map[thr] == -1)
map[thr] = (*pos)++;
}
}
static void scan_core_topology(int *map, struct topology *t, int nr_cpus)
{
int pos = 0;
int i;
int cpu;
for (i = 0; i < t->sib_core_nr; i++)
for_each_set_bit(cpu, cpumask_bits(&t->sib_core[i]), nr_cpus)
scan_thread_topology(map, t, cpu, &pos, nr_cpus);
}
static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus)
{
unsigned int idx;
int ret = 0;
struct perf_cpu_map *map;
struct perf_cpu cpu;
map = perf_cpu_map__new(s);
if (!map)
return -1;
perf_cpu_map__for_each_cpu(cpu, idx, map) {
if (cpu.cpu >= nr_cpus) {
ret = -1;
break;
}
__set_bit(cpu.cpu, cpumask_bits(b));
}
perf_cpu_map__put(map);
return ret;
}
int svg_build_topology_map(struct perf_env *env)
{
int i, nr_cpus;
struct topology t;
char *sib_core, *sib_thr;
int ret = -1;
nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS);
t.sib_core_nr = env->nr_sibling_cores;
t.sib_thr_nr = env->nr_sibling_threads;
t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
t.sib_thr = calloc(env->nr_sibling_threads, sizeof(cpumask_t));
sib_core = env->sibling_cores;
sib_thr = env->sibling_threads;
if (!t.sib_core || !t.sib_thr) {
fprintf(stderr, "topology: no memory\n");
goto exit;
}
for (i = 0; i < env->nr_sibling_cores; i++) {
if (str_to_bitmap(sib_core, &t.sib_core[i], nr_cpus)) {
fprintf(stderr, "topology: can't parse siblings map\n");
goto exit;
}
sib_core += strlen(sib_core) + 1;
}
Annotation
- Immediate include surface: `inttypes.h`, `stdio.h`, `stdlib.h`, `unistd.h`, `string.h`, `linux/bitmap.h`, `linux/string.h`, `linux/time64.h`.
- Detected declarations: `struct topology`, `function cpu2slot`, `function cpu2y`, `function time2pixels`, `function round_text_size`, `function open_svg`, `function normalize_height`, `function svg_ubox`, `function svg_lbox`, `function svg_fbox`.
- 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.