Re: [PATCH v2 1/3] selftests/resctrl: Add CPU vendor detection for Hygon

From: Luck, Tony
Date: Tue Dec 09 2025 - 18:42:19 EST


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