cpumf/lshwc: Allocate memory for per-cpu counter

Allocate the memory required to save the per CPU CPUMF counter value
at the beginning of program execution when the involved number of
CPUs is known. This a bit faster then checking for memory allocation
each time a counter value is retrieved.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Thomas Richter
2024-10-25 16:22:44 +02:00
committed by Jan Höppner
parent 283ae4dd2f
commit 9df45d4256

View File

@@ -490,11 +490,7 @@ static bool add_countervalue(size_t idx, unsigned int cpu, unsigned long value)
warnx("Invalid CPU number %d", cpu);
return false;
}
if (!ctrname[idx].ccv) /* Unknown counter */
ctrname[idx].ccv = calloc(max_possible_cpus,
sizeof(unsigned long));
if (ctrname[idx].ccv)
ctrname[idx].ccv[cpu] = value;
ctrname[idx].ccv[cpu] = value;
ctrname[idx].total += value;
ctrname[idx].hitcnt = true;
return true;
@@ -757,6 +753,9 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
for (unsigned int i = 0; i < ARRAY_SIZE(ctrname); ++i)
ctrname[i].ccv = util_zalloc(max_possible_cpus * sizeof(unsigned long));
if (optind >= argc) {
ch = do_it(NULL);
} else {