From nobody Fri Dec 19 19:34:09 2025 Received: from out28-74.mail.aliyun.com (out28-74.mail.aliyun.com [115.124.28.74]) (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 6863F33ADBF for ; Thu, 4 Dec 2025 12:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764852886; cv=none; b=V2jP2Vp8aOWVTq1XlTuivzCZJFOfYIW6CAlSVkwi/RldSQ7OZO1TC/ZZd9FS9gs8WDEGzp/8/aqsLzr/c67L0SwyDRExZOPuBZP0JZX0ZO2IYwT4oUKIOKiB65LH65ar42m9PRCo4GrtOBHMikbWXmMc2irT1Qdgdt7hxlaFtmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764852886; c=relaxed/simple; bh=5HluE/OJBzH5/xGQiEDcCuDjz+mpxA0ShvC+6bNLf1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9Pc2ACoedDLuAtXd3FoilhDHhdGUYo5H9cXiR4PHB126STPY/yLSNWm2ch6y9DVTYjcLSduMud/4mqlwjsEJIJgep/yMdNZl00n+a5HA5iPmUdrbrvU3ydsl0/IsKZ5Uhu0A/81Sze0aUT4fbVLdDSVxd+YAme8w38njurjNis= 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.74 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_---.fcqdLfM_1764851936 cluster:ay29) by smtp.aliyun-inc.com; Thu, 04 Dec 2025 20:38:58 +0800 From: Xiaochen Shen To: tony.luck@intel.com, reinette.chatre@intel.com, bp@alien8.de, fenghuay@nvidia.com Cc: babu.moger@amd.com, james.morse@arm.com, Dave.Martin@arm.com, x86@kernel.org, linux-kernel@vger.kernel.org, shenxiaochen@open-hieco.net Subject: [PATCH 2/3] selftests/resctrl: Fix a division by zero error on Hygon Date: Thu, 4 Dec 2025 20:38:15 +0800 Message-ID: <20251204123816.2802393-3-shenxiaochen@open-hieco.net> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251204123816.2802393-1-shenxiaochen@open-hieco.net> References: <20251204123816.2802393-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 --- 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..2b075e7334bf 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 certain Hygon platforms: + * 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