~laumann/drawcpu

a32218e2c7d0a55651107f4b7a394f8f37a0b663 — Thomas Bracht Laumann Jespersen 7 months ago 7687b39 master
List per-cpu caches properly

Expand the list of identified caches when the allocated array is filled.
1 files changed, 31 insertions(+), 4 deletions(-)

M main.c
M main.c => main.c +31 -4
@@ 135,6 135,7 @@ listcaches(int cpu, struct cpucaches *cs)
	int j;
	int err;
	cpucache c;
	cpucache *tmp;

	err = 0;



@@ 191,15 192,22 @@ listcaches(int cpu, struct cpucaches *cs)
				break;

		if (j == cs->len) {
			printf("Adding new cache @ %lu!\n", cs->len);
			printf("type=%-14s level=%u shared_cpu_map=%02x size=%s\n", c.type, c.level, c.shared_cpu_map, c.size);
			if (cs->len == cs->cap) {
				tmp = reallocarray(cs->caches, cs->cap * 2, sizeof(cpucache));
				if (!tmp) {
					err = errno;
					perror(DRAWCPU);
					break;
				}
				cs->caches = tmp;
				cs->cap *= 2;
			}
			cs->caches[j].level = c.level;
			cs->caches[j].shared_cpu_map = c.shared_cpu_map;
			cs->caches[j].type = c.type;
			cs->caches[j].size = c.size;
			cs->len++;
		} else {
			printf("Found existing one!\n");
			free(c.type);
			free(c.size);
		}


@@ 218,7 226,9 @@ main(int argc, char *argv[])
	uint lo, hi;
	int err;
	int cpu;
	int i;
	struct cpucaches *caches;
	cpucache *c;

	caches = cpucachesnew();
	if (!caches)


@@ 230,7 240,24 @@ main(int argc, char *argv[])

	printf("err=%d lo=%u hi=%u\n", err, lo, hi);
	for (cpu = lo; cpu <= hi; cpu++) {
		printf(">>> CPU%u\n", cpu);
		listcaches(cpu, caches);
	}
	printf("OK. Got %lu unique caches\n", caches->len);

	for (cpu = lo; cpu <= hi; cpu++) {
		printf(">>> CPU%u\n", cpu);
		for (i = 0; i < caches->len; i++) {
			c = &caches->caches[i];
			if (c->shared_cpu_map & (1 << cpu)) {
				printf("type=%-14s level=%u shared_cpu_map=%02x size=%s\n", c->type, c->level, c->shared_cpu_map, c->size);
			}
		}
	}

	for (i = 0; i < caches->len; i++) {
		free(caches->caches[i].type);
		free(caches->caches[i].size);
	}
	free(caches->caches);
	free(caches);
}