Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp523689rdb; Tue, 31 Oct 2023 14:18:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHntVNg5ZlKLNjgyZiu7AkmgGt41TuxJab5BlcCo85/nBvgglxP+dRSpWbkzEFJc8QFEYN X-Received: by 2002:a05:6e02:2143:b0:357:549f:eca2 with SMTP id d3-20020a056e02214300b00357549feca2mr19183302ilv.5.1698787091514; Tue, 31 Oct 2023 14:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698787091; cv=none; d=google.com; s=arc-20160816; b=gjCR18sAxUWIBR2P91yoHU+pVo7Si738d8bo/gZILOwllTph5MspylvrA+k/1xjaTA hJ8ZEkMgoQck7+nA7uM7Fm5VAOLiTGWDs8Oru2asJmn2JUo8o8ftBNSKgJxr7iEvYZsD MeYjJ4ud/kaaAmikRa4xfXL6oeeC3oNAWRY+hu52oA88ScZMXMDrSbjBzqE47G4spi9l V+OkboT0tfE7+S+C++sAZebow4HnOpTHlZ7zlTA/Fz0z0xkBkSQWwgHUBKAghg13jrtw DCIGdVLjdOkM+pP3Xspd7QPSSUuNml19r5CFaLrECeNnaeQ6dIPgiHNOsJ8TlI6heY7z piBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y1Yq+3ShDQgpfpcYUyIMyFkgY+l7KDe/6XnMhUdZqTk=; fh=EIH9XAmicvPIUSP7TBeBhZ/WaoqG49JQ3xV1i3Gl7Co=; b=Z3atXVrHKGENJVlOJJNjzPWeFl55w3GADoTrgPd8vbZjfLd7XBAQfTWcOq1ixabLwM xd4yoTAZA6P13nCHJuaS6XxG/pvXtYWGpdU7ZJJWHbyDea1PC4g8NNgJ/6qM0xOvPNSj olPK2e8LXPNMxOXbXttIfqN56K+41nEXaq9YGq72E37Knqnj+Ii9lizVC7SLtCtJg1SR m0ohn477fdDmy9f7ahT+9cb0g/TZQVROttjib+Z/mnlsjkDFgj7WpyJEUPONUM4DsAG8 dlcaXuOdlnuUpfqYmwadENTOb0it5vmDtn1Q7IdrpEh5sbTV8z6EbYoBAoaqUpHA/U9v LsFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bmGzC++R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id h11-20020a65480b000000b005b8357f7450si1595407pgs.207.2023.10.31.14.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 14:18:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bmGzC++R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D69AC80D2406; Tue, 31 Oct 2023 14:18:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345966AbjJaVRc (ORCPT + 99 others); Tue, 31 Oct 2023 17:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344909AbjJaVRY (ORCPT ); Tue, 31 Oct 2023 17:17:24 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F8BF102; Tue, 31 Oct 2023 14:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698787042; x=1730323042; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zo0SjhppzHz8KIhLBFut/vdTqKWLRvdvfZU51vUO2Uk=; b=bmGzC++R7+q8Io3O8+B3sw5HIhvTck7xAg6m0JyTnjh8WrgVo7/pdfCp O/FO8DjVnDYAKKvF9a2Jc0IHBbDh0ku6sxnw48kVc1DJ219ikfa6tVZYc NEqZpvkg/vL7+44oHNGSSzyw8YvpU92DNWh7OggmBK+3Se2jS8HI2xbX7 kYYRgY7/gS5PBXQTMxPlL1/uEn/0BDq0HI3hutY6VImHmgoPri33lDjFp m0A3TAz32PXXq4mQIuURgnRDZcY/4RDwLESDlI8YAeW5wb8z6eAA6e0G2 xKUq5vkudb4TwUsgQWZLpKHivYlNS7c636oQ6JPZ8/BV2qoL40dpdWhFs A==; X-IronPort-AV: E=McAfee;i="6600,9927,10880"; a="388197123" X-IronPort-AV: E=Sophos;i="6.03,266,1694761200"; d="scan'208";a="388197123" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 14:17:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10880"; a="884335009" X-IronPort-AV: E=Sophos;i="6.03,266,1694761200"; d="scan'208";a="884335009" Received: from agluck-desk3.sc.intel.com ([172.25.222.74]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 14:17:20 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Peter Newman , Jonathan Corbet , Shuah Khan , x86@kernel.org Cc: Shaopeng Tan , James Morse , Jamie Iles , Babu Moger , Randy Dunlap , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v10 6/8] x86/resctrl: Introduce snc_nodes_per_l3_cache Date: Tue, 31 Oct 2023 14:17:06 -0700 Message-ID: <20231031211708.37390-7-tony.luck@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231031211708.37390-1-tony.luck@intel.com> References: <20231020213100.123598-1-tony.luck@intel.com> <20231031211708.37390-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 31 Oct 2023 14:18:02 -0700 (PDT) Intel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes. This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node. Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes. The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users. The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero. Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation. Add a global integer "snc_nodes_per_l3_cache" that will show how many SNC nodes share each L3 cache. When this is "1", SNC mode is either not implemented, or not enabled, but all places that need to check it are updated to take appropriate action when SNC mode is enabled. Code that needs to take action when SNC is enabled is: 1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes. 2) Likewise the "mon_scale" value must be divided by the number of SNC nodes. 3) The RMID renumbering operates when using the value from the IA32_PQR_ASSOC MSR to count accesses by a task. When reading an RMID counter, code must adjust from the logical RMID used to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into the IA32_QM_EVTSEL MSR. 4) The L3 cache is divided between the SNC nodes. So the value reported in the resctrl "size" file is divided by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor. 5) The "-o mba_MBps" mount option must be disabled in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements. Signed-off-by: Tony Luck --- Changes since v9 Fixed missing word s/monitoring on Intel/monitoring on an Intel/ Deleted "A later patch" paragraph. Expanded description how how values are "adjusted" for mon_scale and cache size. Changed type of "snc_nodes_per_l3_cache" to "unsigned int". arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index ce3a70657842..e7a75a439c16 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); extern struct dentry *debugfs_resctrl; +extern unsigned int snc_nodes_per_l3_cache; + enum resctrl_res_level { RDT_RESOURCE_L3, RDT_RESOURCE_L2, diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index d2c1aa8411a3..97d2a5a7dd41 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -48,6 +48,12 @@ int max_name_width, max_data_width; */ bool rdt_alloc_capable; +/* + * Number of SNC nodes that share each L3 cache. Default is 1 for + * systems that do not support SNC, or have SNC disabled. + */ +unsigned int snc_nodes_per_l3_cache = 1; + static void mba_wrmsr_intel(struct rdt_ctrl_domain *d, struct msr_param *m, struct rdt_resource *r); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 4e145f5620b0..30b7c3b9b517 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid) static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) { + struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + int cpu = smp_processor_id(); + int rmid_offset = 0; u64 msr_val; + /* + * When SNC mode is on, need to compute the offset to read the + * physical RMID counter for the node to which this CPU belongs. + */ + if (snc_nodes_per_l3_cache > 1) + rmid_offset = (cpu_to_node(cpu) % snc_nodes_per_l3_cache) * r->num_rmid; + /* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits @@ -158,7 +168,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) * IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) * are error bits. */ - wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid); + wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid + rmid_offset); rdmsrl(MSR_IA32_QM_CTR, msr_val); if (msr_val & RMID_VAL_ERROR) @@ -783,8 +793,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) int ret; resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024; - hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale; - r->num_rmid = boot_cpu_data.x86_cache_max_rmid + 1; + 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; hw_res->mbm_width = MBM_CNTR_WIDTH_BASE; if (mbm_offset > 0 && mbm_offset <= MBM_CNTR_WIDTH_OFFSET_MAX) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 21bbd832f3f2..79d57dade568 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1425,7 +1425,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } - return size; + return size / snc_nodes_per_l3_cache; } /* @@ -2298,7 +2298,8 @@ static bool supports_mba_mbps(void) struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl; return (is_mbm_local_enabled() && - r->alloc_capable && is_mba_linear()); + r->alloc_capable && is_mba_linear() && + snc_nodes_per_l3_cache == 1); } /* -- 2.41.0