[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d28d3e39-3f09-4187-934a-19b71ce188cc@open-hieco.net>
Date: Wed, 10 Dec 2025 12:46:48 +0800
From: Xiaochen Shen <shenxiaochen@...n-hieco.net>
To: Reinette Chatre <reinette.chatre@...el.com>,
Fenghua Yu <fenghuay@...dia.com>, tony.luck@...el.com, bp@...en8.de,
shuah@...nel.org, skhan@...uxfoundation.org
Cc: babu.moger@....com, james.morse@....com, Dave.Martin@....com,
x86@...nel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, shenxiaochen@...n-hieco.net
Subject: Re: [PATCH v2 1/3] selftests/resctrl: Add CPU vendor detection for
Hygon
Hi Reinette,
On 12/10/2025 7:02 AM, 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;
> }
>
> Reinette
Thank you very much! I will make the change in v3 patch series.
Could you help review the revised patch description for the change?
--------------------------------
...
and makes it obvious when adding new vendor IDs.
Accordingly, update the return types of detect_vendor() and get_vendor()
from 'int' to 'unsigned int' to align with their usage as bitmask values
and to prevent potentially risky type conversions.
Furthermore, introduce a bool flag 'initialized' to simplify the
get_vendor() -> detect_vendor() logic. This ensures the vendor ID is
detected only once and resolves the ambiguity of using the same variable
'vendor' both as a value and as a state.
--------------------------------
Thank you!
Best regards,
Xiaochen Shen
Powered by blists - more mailing lists