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.

Dependency Surface

Detected Declarations

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

Implementation Notes