[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aTizyW7R8Mqj-lSJ@agluck-desk3>
Date: Tue, 9 Dec 2025 15:42:01 -0800
From: "Luck, Tony" <tony.luck@...el.com>
To: Reinette Chatre <reinette.chatre@...el.com>
CC: Xiaochen Shen <shenxiaochen@...n-hieco.net>, Fenghua Yu
<fenghuay@...dia.com>, <bp@...en8.de>, <shuah@...nel.org>,
<skhan@...uxfoundation.org>, <babu.moger@....com>, <james.morse@....com>,
<Dave.Martin@....com>, <x86@...nel.org>, <linux-kernel@...r.kernel.org>,
<linux-kselftest@...r.kernel.org>
Subject: Re: [PATCH v2 1/3] selftests/resctrl: Add CPU vendor detection for
Hygon
On Tue, Dec 09, 2025 at 03:02:14PM -0800, Reinette Chatre wrote:
> I suggest this be simplified to not have the vendor ID be used both as a value and as a state.
> Here is some pseudo-code that should be able to accomplish this:
>
>
> unsigned int detect_vendor(void)
> {
> static bool initialized = false;
> static unsigned int vendor_id;
> ...
> FILE *inf;
>
>
> if (initialized)
> return vendor_id;
>
> inf = fopen("/proc/cpuinfo", "r");
> if (!inf) {
> vendor_id = 0;
> initialized = true;
> return vendor_id;
> }
>
> /* initialize vendor_id from /proc/cpuinfo */
>
> initialized = true;
> return vendor_id;
> }
>
> unsigned int get_vendor(void)
> {
> unsigned int vendor;
>
> vendor = detect_vendor();
>
> if (vendor == 0)
> ksft_print_msg(...);
>
> return vendor;
> }
If detect_vendor() failed, this you'd get the ksft_print_msg() for every
call to get_vendor().
Why not split completly.
static unsigned int vendor_id;
void detect_vendor(void)
{
FILE *inf = fopen("/proc/cpuinfo", "r");
if (!inf) {
... warning unable to get vendor id ...
}
... initialize from /proc/cpuinfo ...
... warn if doesn't find a known vendor ...
}
Call detect_vendor() at the beginning of main() in each test.
Then just use "vendor_id" whenever you need to test for some vendor
specific feature.
-Tony
Powered by blists - more mailing lists