From nobody Tue Dec 16 12:20:40 2025 Received: from out28-50.mail.aliyun.com (out28-50.mail.aliyun.com [115.124.28.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D9C83B8D4B; Thu, 11 Dec 2025 06:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435637; cv=none; b=suXQ5x4GLTTJAeUKOXspWEfnuKYw7S5dgHsRh3Hp6sz2/pu6k/1VsvH6QC53Y898MjWjO1UGqwz/wAtnTX5ROzq0hiKuIJ2/A9kghBp7gPwavDiht423y/mLxFNndt9UfkIGSziWzrbd+WVgSLOibhn3LGzoJMHksoOEV+B/Sgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435637; c=relaxed/simple; bh=0o3JGfptk2ckHJcnm8xaASvg3+sqPLjA9Kk3vCuyNOc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OaSEIEyLY0PTbNFuwHOFsInHdARBFI2825ams7H4v1tnRWoFUHf2gOWy1M2aVxpn7A9nJQUj6sXzjoA293O1Qdewbg9EoWtqKxsuXWMdkw40VGmbWBV5VpKy6T22eGKbjmm9NCaN66ypY2S8RQv17pLXaQQUC/8VGeBz40CGglo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net; spf=pass smtp.mailfrom=open-hieco.net; arc=none smtp.client-ip=115.124.28.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=open-hieco.net Received: from localhost.localdomain(mailfrom:shenxiaochen@open-hieco.net fp:SMTPD_---.fhodoTV_1765435622 cluster:ay29) by smtp.aliyun-inc.com; Thu, 11 Dec 2025 14:47:03 +0800 From: Xiaochen Shen To: tony.luck@intel.com, reinette.chatre@intel.com, bp@alien8.de, fenghuay@nvidia.com, shuah@kernel.org, skhan@linuxfoundation.org Cc: babu.moger@amd.com, james.morse@arm.com, Dave.Martin@arm.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shenxiaochen@open-hieco.net Subject: [PATCH v3 1/4] selftests/resctrl: Define CPU vendor IDs as bits to match usage Date: Thu, 11 Dec 2025 14:46:29 +0800 Message-ID: <20251211064632.2344393-2-shenxiaochen@open-hieco.net> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> References: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Suggested-by: Reinette Chatre Suggested-by: Fenghua Yu Signed-off-by: Xiaochen Shen --- tools/testing/selftests/resctrl/resctrl.h | 7 ++--- .../testing/selftests/resctrl/resctrl_tests.c | 26 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index cd3adfc14969..d0f094360e6f 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "../kselftest.h" =20 #define MB (1024 * 1024) @@ -36,8 +37,8 @@ * Define as bits because they're used for vendor_specific bitmask in * the struct resctrl_test. */ -#define ARCH_INTEL 1 -#define ARCH_AMD 2 +#define ARCH_INTEL BIT(0) +#define ARCH_AMD BIT(1) =20 #define END_OF_TESTS 1 =20 @@ -163,7 +164,7 @@ extern int snc_unreliable; extern char llc_occup_path[1024]; =20 int snc_nodes_per_l3_cache(void); -int get_vendor(void); +unsigned int get_vendor(void); bool check_resctrlfs_support(void); int filter_dmesg(void); int get_domain_id(const char *resource, int cpu_no, int *domain_id); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testin= g/selftests/resctrl/resctrl_tests.c index 5154ffd821c4..08cbd094e936 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -23,16 +23,24 @@ static struct resctrl_test *resctrl_tests[] =3D { &l2_noncont_cat_test, }; =20 -static int detect_vendor(void) +static unsigned int detect_vendor(void) { - FILE *inf =3D fopen("/proc/cpuinfo", "r"); - int vendor_id =3D 0; + static bool initialized; + static unsigned int vendor_id; + FILE *inf; char *s =3D NULL; char *res; =20 - if (!inf) + if (initialized) return vendor_id; =20 + inf =3D fopen("/proc/cpuinfo", "r"); + if (!inf) { + vendor_id =3D 0; + initialized =3D true; + return vendor_id; + } + res =3D fgrep(inf, "vendor_id"); =20 if (res) @@ -45,15 +53,17 @@ static int detect_vendor(void) =20 fclose(inf); free(res); + + initialized =3D true; return vendor_id; } =20 -int get_vendor(void) +unsigned int get_vendor(void) { - static int vendor =3D -1; + unsigned int vendor; + + vendor =3D detect_vendor(); =20 - if (vendor =3D=3D -1) - vendor =3D detect_vendor(); if (vendor =3D=3D 0) ksft_print_msg("Can not get vendor info...\n"); =20 --=20 2.47.3 From nobody Tue Dec 16 12:20:40 2025 Received: from out28-194.mail.aliyun.com (out28-194.mail.aliyun.com [115.124.28.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48B8027E7EC; Thu, 11 Dec 2025 06:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435636; cv=none; b=WdJaBoMaRrE6C2tewkMDxYoPV133zzJhyg9RbnhakL6P3+52rU+IXDS471sT3JPQY+bIZhiIUCKOuCqkUF4RmrgAKOGLn+1+sfXJ3FYu4jYa9WAGOVpU9s1jG0E4LR0ZMuEWsEZCnD2rV9PT+cUSm+H5tkCXtIyMdxX6CR/eG3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435636; c=relaxed/simple; bh=2YEoP/WBSLku9O3QwMjDqy7IlRvGoIPXUKxMPvaCe1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DgxkaDAOjYnQWaj569zJw+l1IKdvfo3NDp8xmwihqkM7XzDVF1vS6uZSoxYjPny6B/NMFrkTDhT0c9RzL3WnlUMNYmQUAvhmpDU6FzYXPFjU/AEYIGICi/lRWWz5AWv0ShZa/j3zhfGblQu2ggliZBj47QCeSEnWGVz7dHh1KzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net; spf=pass smtp.mailfrom=open-hieco.net; arc=none smtp.client-ip=115.124.28.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=open-hieco.net Received: from localhost.localdomain(mailfrom:shenxiaochen@open-hieco.net fp:SMTPD_---.fhodoUl_1765435623 cluster:ay29) by smtp.aliyun-inc.com; Thu, 11 Dec 2025 14:47:04 +0800 From: Xiaochen Shen To: tony.luck@intel.com, reinette.chatre@intel.com, bp@alien8.de, fenghuay@nvidia.com, shuah@kernel.org, skhan@linuxfoundation.org Cc: babu.moger@amd.com, james.morse@arm.com, Dave.Martin@arm.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shenxiaochen@open-hieco.net Subject: [PATCH v3 2/4] selftests/resctrl: Add CPU vendor detection for Hygon Date: Thu, 11 Dec 2025 14:46:30 +0800 Message-ID: <20251211064632.2344393-3-shenxiaochen@open-hieco.net> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> References: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The resctrl selftest currently fails on Hygon CPUs that support Platform QoS features, printing the error: "# Can not get vendor info..." This occurs because vendor detection is missing for Hygon CPUs. Fix this by extending the CPU vendor detection logic to include Hygon's vendor ID. Signed-off-by: Xiaochen Shen Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrl_tests.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index d0f094360e6f..2817c9e41797 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -39,6 +39,7 @@ */ #define ARCH_INTEL BIT(0) #define ARCH_AMD BIT(1) +#define ARCH_HYGON BIT(2) =20 #define END_OF_TESTS 1 =20 diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testin= g/selftests/resctrl/resctrl_tests.c index 08cbd094e936..92cc6aaef338 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -50,6 +50,8 @@ static unsigned int detect_vendor(void) vendor_id =3D ARCH_INTEL; else if (s && !strcmp(s, ": AuthenticAMD\n")) vendor_id =3D ARCH_AMD; + else if (s && !strcmp(s, ": HygonGenuine\n")) + vendor_id =3D ARCH_HYGON; =20 fclose(inf); free(res); --=20 2.47.3 From nobody Tue Dec 16 12:20:40 2025 Received: from out28-145.mail.aliyun.com (out28-145.mail.aliyun.com [115.124.28.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23D8D227E95; Thu, 11 Dec 2025 06:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435638; cv=none; b=nJf6YnWLbfaxIwC3SmkhM5jxXJd3pY4XytJ12nEIv632ZdeMhyZuSuHszG2nbldubj1c+9uwEGXchHiNB9uHCm+ebQJcO9oUVVLK9oYVaCNZFSc/1YZOm2QSFQbN1hb6Xi7ZqSLmR/CF425ODEcNofUrREjJBZF7lTstuedkJ4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435638; c=relaxed/simple; bh=PWVX4P/C70Eb5WxPZWLOS8flK6NgL+KCQmC97/5fE7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cfOfxeIhgR+XQ6l1I43X7HjSnBprPxwlQjw0l1hhXtqauNjRM96piIuQ163YbmqNLNY9rFlpV+gzGMAzGBZ3/k1GQb8uLVPJ9xq+96NS/xucPh5nJmz3F7gRD/WwO14vGrmX64fdNaCQywYKmc/bEL8VEv1LXfieGReM6TIWMrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net; spf=pass smtp.mailfrom=open-hieco.net; arc=none smtp.client-ip=115.124.28.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=open-hieco.net Received: from localhost.localdomain(mailfrom:shenxiaochen@open-hieco.net fp:SMTPD_---.fhodoW._1765435624 cluster:ay29) by smtp.aliyun-inc.com; Thu, 11 Dec 2025 14:47:06 +0800 From: Xiaochen Shen To: tony.luck@intel.com, reinette.chatre@intel.com, bp@alien8.de, fenghuay@nvidia.com, shuah@kernel.org, skhan@linuxfoundation.org Cc: babu.moger@amd.com, james.morse@arm.com, Dave.Martin@arm.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shenxiaochen@open-hieco.net Subject: [PATCH v3 3/4] selftests/resctrl: Fix a division by zero error on Hygon Date: Thu, 11 Dec 2025 14:46:31 +0800 Message-ID: <20251211064632.2344393-4-shenxiaochen@open-hieco.net> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> References: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit a1cd99e700ec ("selftests/resctrl: Adjust effective L3 cache size with SNC= enabled") introduced the snc_nodes_per_l3_cache() function to detect the Intel Sub-NUMA Clustering (SNC) feature by comparing #CPUs in node0 with #CPUs sharing LLC with CPU0. The function was designed to return: (1) >1: SNC mode is enabled. (2) 1: SNC mode is not enabled or not supported. However, on certain Hygon CPUs, #CPUs sharing LLC with CPU0 is actually less than #CPUs in node0. This results in snc_nodes_per_l3_cache() returning 0 (calculated as cache_cpus / node_cpus). This leads to a division by zero error in get_cache_size(): *cache_size /=3D snc_nodes_per_l3_cache(); Causing the resctrl selftest to fail with: "Floating point exception (core dumped)" Fix the issue by ensuring snc_nodes_per_l3_cache() returns 1 when SNC mode is not supported on the platform. Fixes: a1cd99e700ec ("selftests/resctrl: Adjust effective L3 cache size wit= h SNC enabled") Signed-off-by: Xiaochen Shen Reviewed-by: Reinette Chatre Reviewed-by: Fenghua Yu --- tools/testing/selftests/resctrl/resctrlfs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index 195f04c4d158..b9c1bfb6cc02 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -243,6 +243,16 @@ int snc_nodes_per_l3_cache(void) } snc_mode =3D cache_cpus / node_cpus; =20 + /* + * On some platforms (e.g. Hygon), + * cache_cpus < node_cpus, the calculated snc_mode is 0. + * + * Set snc_mode =3D 1 to indicate that SNC mode is not + * supported on the platform. + */ + if (!snc_mode) + snc_mode =3D 1; + if (snc_mode > 1) ksft_print_msg("SNC-%d mode discovered.\n", snc_mode); } --=20 2.47.3 From nobody Tue Dec 16 12:20:40 2025 Received: from out28-52.mail.aliyun.com (out28-52.mail.aliyun.com [115.124.28.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 841312882CD; Thu, 11 Dec 2025 06:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435638; cv=none; b=CFesyMcRn7gaOBdmh7i4pjATbzZkkBFAbT64wMJFsx6lf2m3ulLZwZuT0MkXw0DLOpiCT5BFFO+gT4PMrAHGwIUj0ElZ9aMSZsXTP3oPiNLBeloeuRz9lS0mcJx6CdXnQTywPc+1g6bEDl1iy6w2Ek4m1PLxjxOwHpUaWnWguWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765435638; c=relaxed/simple; bh=DqP/hJfyPqzgzGn53rBaJvj9v6j0Lfk8qad3fEOXkbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZhD8krTlhU9uPGHZCefVND5GbYqCOUduu/G5vbjvsk6frDkb8GKNjeN90Yed/N/iotG3Ig8R/5sB1tjnNrm63EqAyLgioCid4pRO/Fmy1Z66cWMTSa9uBacCu32NNTPJXCHMgtjGUpTGceSczIiV7Uly1pkuhc7mvH4w46nP0Jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net; spf=pass smtp.mailfrom=open-hieco.net; arc=none smtp.client-ip=115.124.28.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=open-hieco.net Received: from localhost.localdomain(mailfrom:shenxiaochen@open-hieco.net fp:SMTPD_---.fhodoYA_1765435626 cluster:ay29) by smtp.aliyun-inc.com; Thu, 11 Dec 2025 14:47:07 +0800 From: Xiaochen Shen To: tony.luck@intel.com, reinette.chatre@intel.com, bp@alien8.de, fenghuay@nvidia.com, shuah@kernel.org, skhan@linuxfoundation.org Cc: babu.moger@amd.com, james.morse@arm.com, Dave.Martin@arm.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shenxiaochen@open-hieco.net Subject: [PATCH v3 4/4] selftests/resctrl: Fix non-contiguous CBM check for Hygon Date: Thu, 11 Dec 2025 14:46:32 +0800 Message-ID: <20251211064632.2344393-5-shenxiaochen@open-hieco.net> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> References: <20251211064632.2344393-1-shenxiaochen@open-hieco.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The resctrl selftest currently fails on Hygon CPUs that always supports non-contiguous CBM, printing the error: "# Hardware and kernel differ on non-contiguous CBM support!" This occurs because the arch_supports_noncont_cat() function lacks vendor detection for Hygon CPUs, preventing proper identification of their non-contiguous CBM capability. Fix this by adding Hygon vendor ID detection to arch_supports_noncont_cat(). Signed-off-by: Xiaochen Shen Reviewed-by: Reinette Chatre Reviewed-by: Fenghua Yu --- Maintainer note: Even though this is a fix it is not a candidate for backport since it is based on another patch series (x86/resctrl: Fix Platform QoS issues for Hygon) which is in process of being added to resctrl. tools/testing/selftests/resctrl/cat_test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/sel= ftests/resctrl/cat_test.c index 94cfdba5308d..f00b622c1460 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -290,8 +290,10 @@ static int cat_run_test(const struct resctrl_test *tes= t, const struct user_param =20 static bool arch_supports_noncont_cat(const struct resctrl_test *test) { - /* AMD always supports non-contiguous CBM. */ - if (get_vendor() =3D=3D ARCH_AMD) + unsigned int vendor_id =3D get_vendor(); + + /* AMD and Hygon always support non-contiguous CBM. */ + if (vendor_id =3D=3D ARCH_AMD || vendor_id =3D=3D ARCH_HYGON) return true; =20 #if defined(__i386__) || defined(__x86_64__) /* arch */ --=20 2.47.3