RE: [PATCH v5 8/8] selftests/resctrl: Adjust effective L3 cache size when SNC enabled

From: Luck, Tony
Date: Wed Aug 30 2023 - 15:05:19 EST


> >+static int count_sys_bitmap_bits(char *name)
> >+{
> >+ FILE *fp = fopen(name, "r");
> >+ int count = 0, c;
> >+
> >+ if (!fp)
> >+ return 0;
> >+
> >+ while ((c = fgetc(fp)) != EOF) {
> >+ if (!isxdigit(c))
> >+ continue;
> >+ switch (c) {
> >+ case 'f':
> >+ count++;
> >+ case '7': case 'b': case 'd': case 'e':
> >+ count++;
> >+ case '3': case '5': case '6': case '9': case 'a': case 'c':
> >+ count++;
> >+ case '1': case '2': case '4': case '8':
> >+ count++;
> >+ }
> >+ }
> >+ fclose(fp);
> >+
> >+ return count;
> >+}
> >+
>
> The resctrl selftest has a function for counting bits, could it be used
> here instead of the switch statement like this for example?
>
> count = count_bits(c);
>
> Or is there some reason this wouldn't be a good fit here?

Thanks for looking at my patch.

That count_bits() function is doing so with input from an "unsigned long"
argument. My function is parsing the string result from a sysfs file which
might look like this:

$ cat shared_cpu_map
0000,00000fff,ffffff00,0000000f,ffffffff

To use count_bits() I'd have to use something like strtol() on each of the
comma separated fields first to convert from ascii strings to binary
values to feed into count_bits().

-Tony