]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/resctrl: Define CPU vendor IDs as bits to match usage
authorXiaochen Shen <shenxiaochen@open-hieco.net>
Wed, 17 Dec 2025 03:04:54 +0000 (11:04 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 9 Jan 2026 23:49:01 +0000 (16:49 -0700)
commit4f4f01cc333e97b0e63b61ed1a65c928aa662f99
tree769eec4a00f3a49ffbdb36647fa296e9fa552dfc
parent671ef08d9455f5754d1fc96f5a14e357d6b80936
selftests/resctrl: Define CPU vendor IDs as bits to match usage

The CPU vendor IDs are required to be unique bits because they're used
for vendor_specific bitmask in the struct resctrl_test.
Consider for example their usage in test_vendor_specific_check():
return get_vendor() & test->vendor_specific

However, the definitions of CPU vendor IDs in file resctrl.h is quite
subtle as a bitmask value:
  #define ARCH_INTEL     1
  #define ARCH_AMD       2

A clearer and more maintainable approach is to define these CPU vendor
IDs using BIT(). This ensures each vendor corresponds to a distinct bit
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.

Link: https://lore.kernel.org/r/20251217030456.3834956-3-shenxiaochen@open-hieco.net
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Suggested-by: Fenghua Yu <fenghuay@nvidia.com>
Signed-off-by: Xiaochen Shen <shenxiaochen@open-hieco.net>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/resctrl.h
tools/testing/selftests/resctrl/resctrl_tests.c