Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp277062lqb; Tue, 28 May 2024 15:33:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2jeQQfRM6uuopYYUutNZALgM85pV3TSE6ibqfb19j3UA3c+ZBY86ReXy60p6gVwubexnOBkx8m94iaEdu3QVi6r2Pw+jVdgWbuqVdmQ== X-Google-Smtp-Source: AGHT+IHy99tUvGRTMOIc654dEuLPbyWqsEl6nUN98ROhX72ErrIEmwUWwsCuouWsOiZKm4QjyMik X-Received: by 2002:a17:902:f551:b0:1f0:8cbf:c1b5 with SMTP id d9443c01a7336-1f4ea9942a7mr5308215ad.16.1716935597570; Tue, 28 May 2024 15:33:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716935597; cv=pass; d=google.com; s=arc-20160816; b=maAFjU3WDzFu3v2IsJvUgkVkuEGkeX2+CiVvWP81AtrPfAlLSeaMiRTWvC2GX/Gc7L 628aX37CPSSQydgLUsuMLyL36RS8f1wIcs3aM2T3K6c+7t3PAgJU4d0s988YwhFNR6YG MbEwcDye2Vofrg0psd4NFtAKoMZDOJslFl/rDmLilcC5j/yz3+2WvjYwjOMv8Feoopva 1qTi93WK29CEdp5TIJw/dpx65wQL/J4GlYNubsIe/1iIezC8AoAs+qohtMO3fU3p4XHP WB8zM2LA23g2vVhBquvDupObpQSPmaIqrNVlESybvLs9Fwz1oF8ezBOFf/fwDLQjK7c4 8ShQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NQygQjsvu1A8iB+8Puiroamg90LSYFDxuNUhhZg1pGc=; fh=qTx768JYq6oxdX3jfjUzjJGF83d0IKGtQzHdow3lchk=; b=xF978+ljYc9eXx5t7SMmEqzaNYq8RSNaREnjKe7dZnISqdrprSwbJAvO3WsTax8y2D M29siXAv7YaRJO2zBrcXZOw0XFsTamf9GeTCC8NkugiM/5SXyhDIUluq2AIvvLg5fSj8 jPDoWl7uGiqJCayT+N+vPGCKY9lbHPTxqlsv+LZJ5EPyFuCECXjpKGeVZgHzTgWNBr5t ixUG7gUe8wADoGrDiRCFSYaKRfhmFWMePOALihjmxkHYtiYJtBzpiFWww8eYrnJCN+Ns usxTaK5124WUR0eF2gCZ7qRm3gggEnTyIIFf/0LqBaNb2J4hJ4VObsFUsUou1DHUZ1O6 PsLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g65LGB+X; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-193173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c7c59b3si85939465ad.188.2024.05.28.15.33.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 15:33:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g65LGB+X; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-193173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8587628A48D for ; Tue, 28 May 2024 22:23:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5933145A15; Tue, 28 May 2024 22:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g65LGB+X" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 266F7143897 for ; Tue, 28 May 2024 22:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716934831; cv=none; b=hKjFixotFCWiujUAhYxf3+3y0CUs4jLU/4ocLyi8KgYCjMb5Jr+dSp/W4nnBNvpITvbeMnnDcj0/9Q8gzdrmtLC2BKC5+02x7tmKkhk77H17Qkd5G7t3NLDHZovY9KTnqcmi+znpvVoHOg3FUq4l42crK+wRXgtJqNlXdRi+utg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716934831; c=relaxed/simple; bh=U/FAikBS3HIFP4hXSxgNs+s+WZEIA9TL/WVzdp6SVyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YLvRtXXDepW1xj0ozHY4ezr+Wbho3LG7Qq55xKmPOOKfgdhTelHr1i+1HQctI9QdF9KqpetjKfdlwYLJ3ROy/pEVeAaJNp3MJZEoWWOdBMSgnnnz8xSvsMND2Cuvd4/sZW7Oby3TzbIJ3kzGM/f9c0fPnFbZWtl3qtZuROPUiuI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=g65LGB+X; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716934830; x=1748470830; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U/FAikBS3HIFP4hXSxgNs+s+WZEIA9TL/WVzdp6SVyw=; b=g65LGB+XU5NUvFQtFJoq0qK0m6medeNL7DVeFCzu3nWDaGFUPHPlBpV3 oKcm/MPnrzOCFJnk3qKO5cntzvfOt4PgtttMEtdqWR9PCjzmLbcPFVBf1 KoewG1VppHhQyLLOOtsUOXGbp4mBCQufytsr9Qha9UZVVZ44ImoBf6OaV mzVU3/GJrCVOkVO0eya5Y7VQHIozZsZA/oeaV/GyTHTEB3+GBKCFFdgQK A6YAMLq/TArR6Avt4GeJrfemm6XhVzQUxw+XjdhEPHMu62uA8Zy9541uV MqrGFIaoRGkwWecuXl9iH+yLOtVzNGgGaicQNTGwkb9iRVpNzTbMWhPju g==; X-CSE-ConnectionGUID: IC6XnJ95SXaLht/aglWa3g== X-CSE-MsgGUID: Y1bK4j2URbmzEiySib8Y5A== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="30812268" X-IronPort-AV: E=Sophos;i="6.08,196,1712646000"; d="scan'208";a="30812268" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 15:20:20 -0700 X-CSE-ConnectionGUID: cy0GYZ9QRe61jPOC1hVxbg== X-CSE-MsgGUID: 3spDZ/YyScyOBcsfGegt8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,196,1712646000"; d="scan'208";a="40090788" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 15:20:20 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Maciej Wieczor-Retman , Peter Newman , James Morse , Babu Moger , Drew Fustini , Dave Martin Cc: x86@kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v19 19/20] x86/resctrl: Sub-NUMA Cluster (SNC) detection and enabling Date: Tue, 28 May 2024 15:20:04 -0700 Message-ID: <20240528222006.58283-20-tony.luck@intel.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240528222006.58283-1-tony.luck@intel.com> References: <20240528222006.58283-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There isn't a simple hardware bit that indicates whether a CPU is running in Sub-NUMA Cluster (SNC) mode. Infer the state by comparing number CPUs sharing the L3 cache with CPU0 to the number of CPUs in the same NUMA node as CPU0. If SNC mode is detected, print a single informational message to the console. Add the missing definition of pr_fmt() to monitor.c. This wasn't noticed before as there are only "can't happen" console messages from this file. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/monitor.c | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index c7559735e33a..1c5162a68461 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -15,6 +15,8 @@ * Software Developer Manual June 2016, volume 3, section 17.17. */ +#define pr_fmt(fmt) "resctrl: " fmt + #include #include #include @@ -1095,6 +1097,61 @@ void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain *d) wrmsrl(MSR_RMID_SNC_CONFIG, val); } +/* CPU models that support MSR_RMID_SNC_CONFIG */ +static const struct x86_cpu_id snc_cpu_ids[] __initconst = { + X86_MATCH_VFM(INTEL_ICELAKE_X, 0), + X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X, 0), + X86_MATCH_VFM(INTEL_EMERALDRAPIDS_X, 0), + X86_MATCH_VFM(INTEL_GRANITERAPIDS_X, 0), + X86_MATCH_VFM(INTEL_ATOM_CRESTMONT_X, 0), + {} +}; + +/* + * There isn't a simple hardware bit that indicates whether a CPU is running + * in Sub-NUMA Cluster (SNC) mode. Infer the state by comparing the + * number CPUs sharing the L3 cache with CPU0 to the number of CPUs in + * the same NUMA node as CPU0. + * It is not possible to accurately determine SNC state if the system is + * booted with a maxcpus=N parameter. That distorts the ratio of SNC nodes + * to L3 caches. It will be OK if system is booted with hyperthreading + * disabled (since this doesn't affect the ratio). + */ +static __init int snc_get_config(void) +{ + struct cacheinfo *ci = get_cpu_cacheinfo_level(0, RESCTRL_L3_CACHE); + const cpumask_t *node0_cpumask; + int ret; + + if (!x86_match_cpu(snc_cpu_ids) || !ci) + return 1; + + cpus_read_lock(); + if (num_online_cpus() != num_present_cpus()) + pr_warn("Some CPUs offline, SNC detection may be incorrect\n"); + cpus_read_unlock(); + + node0_cpumask = cpumask_of_node(cpu_to_node(0)); + + ret = cpumask_weight(&ci->shared_cpu_map) / cpumask_weight(node0_cpumask); + + /* sanity check: Only valid results are 1, 2, 3, 4 */ + switch (ret) { + case 1: + break; + case 2 ... 4: + pr_info("Sub-NUMA Cluster mode detected with %d nodes per L3 cache\n", ret); + rdt_resources_all[RDT_RESOURCE_L3].r_resctrl.mon_scope = RESCTRL_L3_NODE; + break; + default: + pr_warn("Ignore improbable SNC node count %d\n", ret); + ret = 1; + break; + } + + return ret; +} + int __init rdt_get_mon_l3_config(struct rdt_resource *r) { unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset; @@ -1102,6 +1159,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) unsigned int threshold; int ret; + snc_nodes_per_l3_cache = snc_get_config(); + resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024; hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache; r->num_rmid = (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3_cache; -- 2.45.0