From nobody Sun Dec 14 11:16:55 2025 Received: from out198-2.us.a.mail.aliyun.com (out198-2.us.a.mail.aliyun.com [47.90.198.2]) (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 169B623EAB3; Sat, 13 Dec 2025 07:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.198.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765611561; cv=none; b=AGTbg0kb2skNZYuBAJf1L/XPqIgy7/hOZjfxeeaOh8jHH6XTLlXo8kmSgGZE2vgIWnPnSeqLsWoBAX9U+6PfPQvTQdibu5LZTykBB8gjViDFmIsQIjRXqFM1xoLwVje4+0UFNduWThZ7Gg533Qv4lw5RkcwRpHJpeaSqM55QWQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765611561; c=relaxed/simple; bh=PWVX4P/C70Eb5WxPZWLOS8flK6NgL+KCQmC97/5fE7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LlM9FTFYcaZV9zPjQfDYyE13nwQ4l9x3Z8t7yOrlznRJOuwN1rb8ZVjw5VQ94aCtIZCAAM2AjS1jtaKTKYCNb224+Sg6b1Cr8IGeHy2I+pAUn0JCPVWjS9gQAxuS4cMonVH0EVGekzUMYmpwvQIMe/jIf2pSfSceYuoC1b3FwZM= 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=47.90.198.2 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_---.fjNqpoN_1765611537 cluster:ay29) by smtp.aliyun-inc.com; Sat, 13 Dec 2025 15:38:59 +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 v4 1/4] selftests/resctrl: Fix a division by zero error on Hygon Date: Sat, 13 Dec 2025 15:38:08 +0800 Message-ID: <20251213073811.3016864-2-shenxiaochen@open-hieco.net> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251213073811.3016864-1-shenxiaochen@open-hieco.net> References: <20251213073811.3016864-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