[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <SJ1PR11MB60838CA98A341F59260BDE18FCE6A@SJ1PR11MB6083.namprd11.prod.outlook.com>
Date: Wed, 30 Aug 2023 15:43:05 +0000
From: "Luck, Tony" <tony.luck@...el.com>
To: "Wieczor-Retman, Maciej" <maciej.wieczor-retman@...el.com>
CC: "Yu, Fenghua" <fenghua.yu@...el.com>,
"Chatre, Reinette" <reinette.chatre@...el.com>,
Peter Newman <peternewman@...gle.com>,
"Jonathan Corbet" <corbet@....net>,
Shuah Khan <skhan@...uxfoundation.org>,
"x86@...nel.org" <x86@...nel.org>,
Shaopeng Tan <tan.shaopeng@...itsu.com>,
James Morse <james.morse@....com>,
Jamie Iles <quic_jiles@...cinc.com>,
"Babu Moger" <babu.moger@....com>,
Randy Dunlap <rdunlap@...radead.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
"patches@...ts.linux.dev" <patches@...ts.linux.dev>
Subject: RE: [PATCH v5 8/8] selftests/resctrl: Adjust effective L3 cache size
when SNC enabled
> >+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
Powered by blists - more mailing lists