From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 2151119EEB6 for ; Thu, 27 Jun 2024 20:39:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520750; cv=none; b=WriN5jaigev+I84A7bX8FfludVznuL98gVo9csp4oo5S8pIbh6rMUlRuB8dCMHokub2f+1iJiOOtGmsXPuBSbASOLQXMrq7DLEgpYtLBOsJVFiOAnCTfRvhySp9Y4Ymqk3AbwmykAj7xuUy7RN2sKUDdwEATwKJdH8dmYQm6imo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520750; c=relaxed/simple; bh=UkO/iO5o0K7iouaKmdiKdS8lN7ENhgwYU9DmqbnkCI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e2Pbo5cpXKg5iZ96V6UBYlTQMKSRoNiOqyXVGSiaF4jYleCQGH24Cku5gjtpmboLP6m5BivxbQ4EIbhmY7mxKLsc9qa9zizvgGJ3e45ZxRUP/YgN75VnEbqWYa8bkKPc7B1xmwX/2drWLOJOjH8Ji9oZxPI0f8geo3lQ0HLQ5gE= 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=Tj+OZW/h; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Tj+OZW/h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520748; x=1751056748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UkO/iO5o0K7iouaKmdiKdS8lN7ENhgwYU9DmqbnkCI0=; b=Tj+OZW/h0cyOxej6okqqWULYylB9lwZzq+/+HvtZXeZwrn6U/bPk9JhD HFhZiIBvnoX5AuYnWzDM7GlzreaLrTxA8pE8tEKB+1DUQp9c28epfMv3i QdzusXchdgdcFQ6eR7Q4JqUn4DQg68hchX8VeB+agPvxEX5F1jSnGrdoy X87BaKgHjDACxUxoUHI3VNOnzko95p7NEId+t4/OBtG7xGiDHi9t2HE0/ mhHbDihX4PEWoF8Un/kiuaN5unqDO84zdGHouoKVQKuhtHOt5EhXxG6Ii Oh2UCuQ5RFoOY8lclXvk6zghDJDaRQWj9bk3nYx2g9Yu0cpgyXzDwasqF g==; X-CSE-ConnectionGUID: d0Qxi3+pTFOUJf2yeEBWKg== X-CSE-MsgGUID: OVWl732nTL+IrNTHf6a7Ww== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809740" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809740" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -0700 X-CSE-ConnectionGUID: bT3k6ah5R6a0Gj/Jw2rgWg== X-CSE-MsgGUID: sJUDW2qkSF2bD7jshjM2IA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052879" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:06 -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 v22 01/18] x86/resctrl: Prepare for new domain scope Date: Thu, 27 Jun 2024 13:38:39 -0700 Message-ID: <20240627203856.66628-2-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" Resctrl resources operate on subsets of CPUs in the system with the defining attribute of each subset being an instance of a particular level of cache. E.g. all CPUs sharing an L3 cache would be part of the same domain. In preparation for features that are scoped at the NUMA node level change the code from explicit references to "cache_level" to a more generic scope. At this point the only options for this scope are groups of CPUs that share an L2 cache or L3 cache. Clean up the error handling when looking up domains. Report invalid id's before calling rdt_find_domain() in preparation for better messages when scope can be other than cache scope. This means that rdt_find_domain() will never return an error. So remove checks for error from the callsites. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 9 ++++- arch/x86/kernel/cpu/resctrl/core.c | 46 ++++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 ++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++- 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index a365f67131ec..ed693bfe474d 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -150,13 +150,18 @@ struct resctrl_membw { struct rdt_parse_data; struct resctrl_schema; =20 +enum resctrl_scope { + RESCTRL_L2_CACHE =3D 2, + RESCTRL_L3_CACHE =3D 3, +}; + /** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available - * @cache_level: Which cache level defines scope of this resource + * @scope: Scope of this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: RCU list of all domains for this resource @@ -174,7 +179,7 @@ struct rdt_resource { bool alloc_capable; bool mon_capable; int num_rmid; - int cache_level; + enum resctrl_scope scope; struct resctrl_cache cache; struct resctrl_membw membw; struct list_head domains; diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index a113d9aba553..f85b2ff40eef 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -68,7 +68,7 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_L3, .name =3D "L3", - .cache_level =3D 3, + .scope =3D RESCTRL_L3_CACHE, .domains =3D domain_init(RDT_RESOURCE_L3), .parse_ctrlval =3D parse_cbm, .format_str =3D "%d=3D%0*x", @@ -82,7 +82,7 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_L2, .name =3D "L2", - .cache_level =3D 2, + .scope =3D RESCTRL_L2_CACHE, .domains =3D domain_init(RDT_RESOURCE_L2), .parse_ctrlval =3D parse_cbm, .format_str =3D "%d=3D%0*x", @@ -96,7 +96,7 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_MBA, .name =3D "MB", - .cache_level =3D 3, + .scope =3D RESCTRL_L3_CACHE, .domains =3D domain_init(RDT_RESOURCE_MBA), .parse_ctrlval =3D parse_bw, .format_str =3D "%d=3D%*u", @@ -108,7 +108,7 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_SMBA, .name =3D "SMBA", - .cache_level =3D 3, + .scope =3D RESCTRL_L3_CACHE, .domains =3D domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval =3D parse_bw, .format_str =3D "%d=3D%*u", @@ -392,9 +392,6 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource = *r, int id, struct rdt_domain *d; struct list_head *l; =20 - if (id < 0) - return ERR_PTR(-ENODEV); - list_for_each(l, &r->domains) { d =3D list_entry(l, struct rdt_domain, list); /* When id is found, return its domain. */ @@ -484,6 +481,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct = rdt_hw_domain *hw_dom) return 0; } =20 +static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) +{ + switch (scope) { + case RESCTRL_L2_CACHE: + case RESCTRL_L3_CACHE: + return get_cpu_cacheinfo_id(cpu, scope); + default: + break; + } + + return -EINVAL; +} + /* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -499,7 +509,7 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct r= dt_hw_domain *hw_dom) */ static void domain_add_cpu(int cpu, struct rdt_resource *r) { - int id =3D get_cpu_cacheinfo_id(cpu, r->cache_level); + int id =3D get_domain_id_from_scope(cpu, r->scope); struct list_head *add_pos =3D NULL; struct rdt_hw_domain *hw_dom; struct rdt_domain *d; @@ -507,12 +517,14 @@ static void domain_add_cpu(int cpu, struct rdt_resour= ce *r) =20 lockdep_assert_held(&domain_list_lock); =20 - d =3D rdt_find_domain(r, id, &add_pos); - if (IS_ERR(d)) { - pr_warn("Couldn't find cache id for CPU %d\n", cpu); + if (id < 0) { + pr_warn_once("Can't find domain id for CPU:%d scope:%d for resource %s\n= ", + cpu, r->scope, r->name); return; } =20 + d =3D rdt_find_domain(r, id, &add_pos); + if (d) { cpumask_set_cpu(cpu, &d->cpu_mask); if (r->cache.arch_has_per_cpu_cfg) @@ -552,15 +564,21 @@ static void domain_add_cpu(int cpu, struct rdt_resour= ce *r) =20 static void domain_remove_cpu(int cpu, struct rdt_resource *r) { - int id =3D get_cpu_cacheinfo_id(cpu, r->cache_level); + int id =3D get_domain_id_from_scope(cpu, r->scope); struct rdt_hw_domain *hw_dom; struct rdt_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 + if (id < 0) { + pr_warn_once("Can't find domain id for CPU:%d scope:%d for resource %s\n= ", + cpu, r->scope, r->name); + return; + } + d =3D rdt_find_domain(r, id, NULL); - if (IS_ERR_OR_NULL(d)) { - pr_warn("Couldn't find cache id for CPU %d\n", cpu); + if (!d) { + pr_warn("Couldn't find domain with id=3D%d for CPU %d\n", id, cpu); return; } hw_dom =3D resctrl_to_arch_dom(d); diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index b7291f60399c..2bf021d42500 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -577,7 +577,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) =20 r =3D &rdt_resources_all[resid].r_resctrl; d =3D rdt_find_domain(r, domid, NULL); - if (IS_ERR_OR_NULL(d)) { + if (!d) { ret =3D -ENOENT; goto out; } diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index 1bbfd3c1e300..201011f0ed0b 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -292,9 +292,13 @@ static void pseudo_lock_region_clear(struct pseudo_loc= k_region *plr) */ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) { + enum resctrl_scope scope =3D plr->s->res->scope; struct cacheinfo *ci; int ret; =20 + if (WARN_ON_ONCE(scope !=3D RESCTRL_L2_CACHE && scope !=3D RESCTRL_L3_CAC= HE)) + return -ENODEV; + /* Pick the first cpu we find that is associated with the cache. */ plr->cpu =3D cpumask_first(&plr->d->cpu_mask); =20 @@ -305,7 +309,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_r= egion *plr) goto out_region; } =20 - ci =3D get_cpu_cacheinfo_level(plr->cpu, plr->s->res->cache_level); + ci =3D get_cpu_cacheinfo_level(plr->cpu, scope); if (ci) { plr->line_size =3D ci->coherency_line_size; plr->size =3D rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index cb68a121dabb..50f5876a3020 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1454,8 +1454,11 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resourc= e *r, struct cacheinfo *ci; int num_b; =20 + if (WARN_ON_ONCE(r->scope !=3D RESCTRL_L2_CACHE && r->scope !=3D RESCTRL_= L3_CACHE)) + return size; + num_b =3D bitmap_weight(&cbm, r->cache.cbm_len); - ci =3D get_cpu_cacheinfo_level(cpumask_any(&d->cpu_mask), r->cache_level); + ci =3D get_cpu_cacheinfo_level(cpumask_any(&d->cpu_mask), r->scope); if (ci) size =3D ci->size / r->cache.cbm_len * num_b; =20 --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 026B319E827 for ; Thu, 27 Jun 2024 20:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520751; cv=none; b=OKIo6aZYK5UMTHZ0INHPw/0YgbpW7YEi6/lJj2xxK4GFKagb3IG8iVW0hhynNXZ3pcbIDCSqQI20YoNcbYSGVX0Pvfn50yeW12NPOxE9P0ZuhIslcty4Kzkiq+jdz3cTmrNHJ3XkwfeFs4cNIQikfpDTRVmgFx3y26au30XT6so= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520751; c=relaxed/simple; bh=kIOWkWOLGJeBKdiY5BBnoK58MBrVc6s7QVR+1qSIHO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ch79AxkRpNjuG7UUAwVqYdIe5UEFEnFfO49pHCjIy8UVbFVHCBQGbxo6L12ogsSmRu4V3pfxsYUf96yyUSYhm4VkvLI57cLRE9Y9FrdfebTujCSf6cQv8aCp7YWoJZk5QB9CJJrSqFmiXfFXkhY9iwj0gf7oDdUvP1BcM45QQ0g= 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=kUC4Nwus; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kUC4Nwus" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520749; x=1751056749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kIOWkWOLGJeBKdiY5BBnoK58MBrVc6s7QVR+1qSIHO8=; b=kUC4Nwus9LtYbyYzZLW1liz+O4XGcoRU/R8R29H5b9Dej00dGbkM7YIV V5CFol3p5frCOw1mJABE9YjAbA4sMBkAUCtmWtPk9uKOcXF9iKYS8xsuR 2wZaPPpazhJVwPjfhhbUul78043pmJwrrImwq+0Bc84jbc4PSpoiHMUqP NP8uQkxtJeU+23nA3xWjgxeV2QELBOnJSeaej1JKiZk0yaXlt9wT9ojf0 E58zEYevFQ3wzmxxcRdBuolgprB+Kdm2nZkWoshqKN9IwQzhIo99yOfpt RyuFS/4JIy8jNaZPS+FHyw2kocmbiBS2E+LIxdeOQh564R24mnrsTQ5dh A==; X-CSE-ConnectionGUID: OCf2QVDLR7+/wcWYvL6Nzw== X-CSE-MsgGUID: IaCEcYjUQai4mmVg+1U83g== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809748" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809748" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -0700 X-CSE-ConnectionGUID: wR0rKOxMTCG40VkEqH/tBg== X-CSE-MsgGUID: rTDV05axSomjuaKBaUJ+2w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052882" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -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 v22 02/18] x86/resctrl: Prepare to split rdt_domain structure Date: Thu, 27 Jun 2024 13:38:40 -0700 Message-ID: <20240627203856.66628-3-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" The rdt_domain structure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources. To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "cpu_mask") into their own structure within the rdt_domain structure. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 24 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 14 +++--- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 81 insertions(+), 73 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index ed693bfe474d..f63fcf17a3bc 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -59,10 +59,20 @@ struct resctrl_staged_config { }; =20 /** - * struct rdt_domain - group of CPUs sharing a resctrl resource + * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource + */ +struct rdt_domain_hdr { + struct list_head list; + int id; + struct cpumask cpu_mask; +}; + +/** + * struct rdt_domain - group of CPUs sharing a resctrl resource + * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth @@ -77,9 +87,7 @@ struct resctrl_staged_config { * by closid */ struct rdt_domain { - struct list_head list; - int id; - struct cpumask cpu_mask; + struct rdt_domain_hdr hdr; unsigned long *rmid_busy_llc; struct mbm_state *mbm_total; struct mbm_state *mbm_local; diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f85b2ff40eef..96fff44f9d03 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -355,9 +355,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct = rdt_resource *r) =20 lockdep_assert_cpus_held(); =20 - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { /* Find the domain that contains this CPU */ - if (cpumask_test_cpu(cpu, &d->cpu_mask)) + if (cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) return d; } =20 @@ -393,12 +393,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resourc= e *r, int id, struct list_head *l; =20 list_for_each(l, &r->domains) { - d =3D list_entry(l, struct rdt_domain, list); + d =3D list_entry(l, struct rdt_domain, hdr.list); /* When id is found, return its domain. */ - if (id =3D=3D d->id) + if (id =3D=3D d->hdr.id) return d; /* Stop searching when finding id's position in sorted list. */ - if (id < d->id) + if (id < d->hdr.id) break; } =20 @@ -526,7 +526,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource= *r) d =3D rdt_find_domain(r, id, &add_pos); =20 if (d) { - cpumask_set_cpu(cpu, &d->cpu_mask); + cpumask_set_cpu(cpu, &d->hdr.cpu_mask); if (r->cache.arch_has_per_cpu_cfg) rdt_domain_reconfigure_cdp(r); return; @@ -537,8 +537,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource= *r) return; =20 d =3D &hw_dom->d_resctrl; - d->id =3D id; - cpumask_set_cpu(cpu, &d->cpu_mask); + d->hdr.id =3D id; + cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 rdt_domain_reconfigure_cdp(r); =20 @@ -552,11 +552,11 @@ static void domain_add_cpu(int cpu, struct rdt_resour= ce *r) return; } =20 - list_add_tail_rcu(&d->list, add_pos); + list_add_tail_rcu(&d->hdr.list, add_pos); =20 err =3D resctrl_online_domain(r, d); if (err) { - list_del_rcu(&d->list); + list_del_rcu(&d->hdr.list); synchronize_rcu(); domain_free(hw_dom); } @@ -583,10 +583,10 @@ static void domain_remove_cpu(int cpu, struct rdt_res= ource *r) } hw_dom =3D resctrl_to_arch_dom(d); =20 - cpumask_clear_cpu(cpu, &d->cpu_mask); - if (cpumask_empty(&d->cpu_mask)) { + cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); + if (cpumask_empty(&d->hdr.cpu_mask)) { resctrl_offline_domain(r, d); - list_del_rcu(&d->list); + list_del_rcu(&d->hdr.list); synchronize_rcu(); =20 /* diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index 2bf021d42500..6246f48b0449 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -69,7 +69,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_= schema *s, =20 cfg =3D &d->staged_config[s->conf_type]; if (cfg->have_new_ctrl) { - rdt_last_cmd_printf("Duplicate domain %d\n", d->id); + rdt_last_cmd_printf("Duplicate domain %d\n", d->hdr.id); return -EINVAL; } =20 @@ -148,7 +148,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resct= rl_schema *s, =20 cfg =3D &d->staged_config[s->conf_type]; if (cfg->have_new_ctrl) { - rdt_last_cmd_printf("Duplicate domain %d\n", d->id); + rdt_last_cmd_printf("Duplicate domain %d\n", d->hdr.id); return -EINVAL; } =20 @@ -231,8 +231,8 @@ static int parse_line(char *line, struct resctrl_schema= *s, return -EINVAL; } dom =3D strim(dom); - list_for_each_entry(d, &r->domains, list) { - if (d->id =3D=3D dom_id) { + list_for_each_entry(d, &r->domains, hdr.list) { + if (d->hdr.id =3D=3D dom_id) { data.buf =3D dom; data.rdtgrp =3D rdtgrp; if (r->parse_ctrlval(&data, s, d)) @@ -280,7 +280,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, str= uct rdt_domain *d, u32 idx =3D get_config_index(closid, t); struct msr_param msr_param; =20 - if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask)) + if (!cpumask_test_cpu(smp_processor_id(), &d->hdr.cpu_mask)) return -EINVAL; =20 hw_dom->ctrl_val[idx] =3D cfg_val; @@ -306,7 +306,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r,= u32 closid) /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); =20 - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { hw_dom =3D resctrl_to_arch_dom(d); msr_param.res =3D NULL; for (t =3D 0; t < CDP_NUM_TYPES; t++) { @@ -330,7 +330,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r,= u32 closid) } } if (msr_param.res) - smp_call_function_any(&d->cpu_mask, rdt_ctrl_update, &msr_param, 1); + smp_call_function_any(&d->hdr.cpu_mask, rdt_ctrl_update, &msr_param, 1); } =20 return 0; @@ -450,7 +450,7 @@ static void show_doms(struct seq_file *s, struct resctr= l_schema *schema, int clo lockdep_assert_cpus_held(); =20 seq_printf(s, "%*s:", max_name_width, schema->name); - list_for_each_entry(dom, &r->domains, list) { + list_for_each_entry(dom, &r->domains, hdr.list) { if (sep) seq_puts(s, ";"); =20 @@ -460,7 +460,7 @@ static void show_doms(struct seq_file *s, struct resctr= l_schema *schema, int clo ctrl_val =3D resctrl_arch_get_config(r, dom, closid, schema->conf_type); =20 - seq_printf(s, r->format_str, dom->id, max_data_width, + seq_printf(s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep =3D true; } @@ -489,7 +489,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, } else { seq_printf(s, "%s:%d=3D%x\n", rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } } else { @@ -537,7 +537,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, return; } =20 - cpu =3D cpumask_any_housekeeping(&d->cpu_mask, RESCTRL_PICK_ANY_CPU); + cpu =3D cpumask_any_housekeeping(&d->hdr.cpu_mask, RESCTRL_PICK_ANY_CPU); =20 /* * cpumask_any_housekeeping() prefers housekeeping CPUs, but @@ -546,7 +546,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, * counters on some platforms if its called in IRQ context. */ if (tick_nohz_full_cpu(cpu)) - smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1); + smp_call_function_any(&d->hdr.cpu_mask, mon_event_count, rr, 1); else smp_call_on_cpu(cpu, smp_mon_event_count, rr, false); =20 diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 2345e6836593..ab8a198d88b3 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -281,7 +281,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_domain *d, =20 resctrl_arch_rmid_read_context_check(); =20 - if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask)) + if (!cpumask_test_cpu(smp_processor_id(), &d->hdr.cpu_mask)) return -EINVAL; =20 ret =3D __rmid_read(rmid, eventid, &msr_val); @@ -364,7 +364,7 @@ void __check_limbo(struct rdt_domain *d, bool force_fre= e) * CLOSID and RMID because there may be dependencies between them * on some architectures. */ - trace_mon_llc_occupancy_limbo(entry->closid, entry->rmid, d->id, val); + trace_mon_llc_occupancy_limbo(entry->closid, entry->rmid, d->hdr.id, va= l); } =20 if (force_free || !rmid_dirty) { @@ -490,7 +490,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) idx =3D resctrl_arch_rmid_idx_encode(entry->closid, entry->rmid); =20 entry->busy =3D 0; - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { /* * For the first limbo RMID in the domain, * setup up the limbo worker. @@ -801,7 +801,7 @@ void cqm_handle_limbo(struct work_struct *work) __check_limbo(d, false); =20 if (has_busy_rmid(d)) { - d->cqm_work_cpu =3D cpumask_any_housekeeping(&d->cpu_mask, + d->cqm_work_cpu =3D cpumask_any_housekeeping(&d->hdr.cpu_mask, RESCTRL_PICK_ANY_CPU); schedule_delayed_work_on(d->cqm_work_cpu, &d->cqm_limbo, delay); @@ -825,7 +825,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, un= signed long delay_ms, unsigned long delay =3D msecs_to_jiffies(delay_ms); int cpu; =20 - cpu =3D cpumask_any_housekeeping(&dom->cpu_mask, exclude_cpu); + cpu =3D cpumask_any_housekeeping(&dom->hdr.cpu_mask, exclude_cpu); dom->cqm_work_cpu =3D cpu; =20 if (cpu < nr_cpu_ids) @@ -868,7 +868,7 @@ void mbm_handle_overflow(struct work_struct *work) * Re-check for housekeeping CPUs. This allows the overflow handler to * move off a nohz_full CPU quickly. */ - d->mbm_work_cpu =3D cpumask_any_housekeeping(&d->cpu_mask, + d->mbm_work_cpu =3D cpumask_any_housekeeping(&d->hdr.cpu_mask, RESCTRL_PICK_ANY_CPU); schedule_delayed_work_on(d->mbm_work_cpu, &d->mbm_over, delay); =20 @@ -897,7 +897,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom,= unsigned long delay_ms, */ if (!resctrl_mounted || !resctrl_arch_mon_capable()) return; - cpu =3D cpumask_any_housekeeping(&dom->cpu_mask, exclude_cpu); + cpu =3D cpumask_any_housekeeping(&dom->hdr.cpu_mask, exclude_cpu); dom->mbm_work_cpu =3D cpu; =20 if (cpu < nr_cpu_ids) diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index 201011f0ed0b..df45c839a58f 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_= lock_region *plr) int cpu; int ret; =20 - for_each_cpu(cpu, &plr->d->cpu_mask) { + for_each_cpu(cpu, &plr->d->hdr.cpu_mask) { pm_req =3D kzalloc(sizeof(*pm_req), GFP_KERNEL); if (!pm_req) { rdt_last_cmd_puts("Failure to allocate memory for PM QoS\n"); @@ -300,7 +300,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_r= egion *plr) return -ENODEV; =20 /* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =3D cpumask_first(&plr->d->cpu_mask); + plr->cpu =3D cpumask_first(&plr->d->hdr.cpu_mask); =20 if (!cpu_online(plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n", @@ -854,10 +854,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_d= omain *d) * associated with them. */ for_each_alloc_capable_rdt_resource(r) { - list_for_each_entry(d_i, &r->domains, list) { + list_for_each_entry(d_i, &r->domains, hdr.list) { if (d_i->plr) cpumask_or(cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } } =20 @@ -865,7 +865,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_dom= ain *d) * Next test if new pseudo-locked region would intersect with * existing region. */ - if (cpumask_intersects(&d->cpu_mask, cpu_with_psl)) + if (cpumask_intersects(&d->hdr.cpu_mask, cpu_with_psl)) ret =3D true; =20 free_cpumask_var(cpu_with_psl); @@ -1197,7 +1197,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup= *rdtgrp, int sel) } =20 plr->thread_done =3D 0; - cpu =3D cpumask_first(&plr->d->cpu_mask); + cpu =3D cpumask_first(&plr->d->hdr.cpu_mask); if (!cpu_online(cpu)) { ret =3D -ENODEV; goto out; @@ -1527,7 +1527,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, st= ruct vm_area_struct *vma) * may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ - if (!cpumask_subset(current->cpus_ptr, &plr->d->cpu_mask)) { + if (!cpumask_subset(current->cpus_ptr, &plr->d->hdr.cpu_mask)) { mutex_unlock(&rdtgroup_mutex); return -EINVAL; } diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 50f5876a3020..b6ba77cdf0e8 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -98,7 +98,7 @@ void rdt_staged_configs_clear(void) lockdep_assert_held(&rdtgroup_mutex); =20 for_each_alloc_capable_rdt_resource(r) { - list_for_each_entry(dom, &r->domains, list) + list_for_each_entry(dom, &r->domains, hdr.list) memset(dom->staged_config, 0, sizeof(dom->staged_config)); } } @@ -317,7 +317,7 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *= of, rdt_last_cmd_puts("Cache domain offline\n"); ret =3D -ENODEV; } else { - mask =3D &rdtgrp->plr->d->cpu_mask; + mask =3D &rdtgrp->plr->d->hdr.cpu_mask; seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n", cpumask_pr_args(mask)); @@ -1021,12 +1021,12 @@ static int rdt_bit_usage_show(struct kernfs_open_fi= le *of, cpus_read_lock(); mutex_lock(&rdtgroup_mutex); hw_shareable =3D r->cache.shareable_bits; - list_for_each_entry(dom, &r->domains, list) { + list_for_each_entry(dom, &r->domains, hdr.list) { if (sep) seq_putc(seq, ';'); sw_shareable =3D 0; exclusive =3D 0; - seq_printf(seq, "%d=3D", dom->id); + seq_printf(seq, "%d=3D", dom->hdr.id); for (i =3D 0; i < closids_supported(); i++) { if (!closid_allocated(i)) continue; @@ -1343,7 +1343,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgr= oup *rdtgrp) if (r->rid =3D=3D RDT_RESOURCE_MBA || r->rid =3D=3D RDT_RESOURCE_SMBA) continue; has_cache =3D true; - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { ctrl =3D resctrl_arch_get_config(r, d, closid, s->conf_type); if (rdtgroup_cbm_overlaps(s, d, ctrl, closid, false)) { @@ -1458,7 +1458,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource= *r, return size; =20 num_b =3D bitmap_weight(&cbm, r->cache.cbm_len); - ci =3D get_cpu_cacheinfo_level(cpumask_any(&d->cpu_mask), r->scope); + ci =3D get_cpu_cacheinfo_level(cpumask_any(&d->hdr.cpu_mask), r->scope); if (ci) size =3D ci->size / r->cache.cbm_len * num_b; =20 @@ -1502,7 +1502,7 @@ static int rdtgroup_size_show(struct kernfs_open_file= *of, size =3D rdtgroup_cbm_to_size(rdtgrp->plr->s->res, rdtgrp->plr->d, rdtgrp->plr->cbm); - seq_printf(s, "%d=3D%u\n", rdtgrp->plr->d->id, size); + seq_printf(s, "%d=3D%u\n", rdtgrp->plr->d->hdr.id, size); } goto out; } @@ -1514,7 +1514,7 @@ static int rdtgroup_size_show(struct kernfs_open_file= *of, type =3D schema->conf_type; sep =3D false; seq_printf(s, "%*s:", max_name_width, schema->name); - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { if (sep) seq_putc(s, ';'); if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKSETUP) { @@ -1532,7 +1532,7 @@ static int rdtgroup_size_show(struct kernfs_open_file= *of, else size =3D rdtgroup_cbm_to_size(r, d, ctrl); } - seq_printf(s, "%d=3D%u", d->id, size); + seq_printf(s, "%d=3D%u", d->hdr.id, size); sep =3D true; } seq_putc(s, '\n'); @@ -1592,7 +1592,7 @@ static void mon_event_config_read(void *info) =20 static void mondata_config_read(struct rdt_domain *d, struct mon_config_in= fo *mon_info) { - smp_call_function_any(&d->cpu_mask, mon_event_config_read, mon_info, 1); + smp_call_function_any(&d->hdr.cpu_mask, mon_event_config_read, mon_info, = 1); } =20 static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32= evtid) @@ -1604,7 +1604,7 @@ static int mbm_config_show(struct seq_file *s, struct= rdt_resource *r, u32 evtid cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 - list_for_each_entry(dom, &r->domains, list) { + list_for_each_entry(dom, &r->domains, hdr.list) { if (sep) seq_puts(s, ";"); =20 @@ -1612,7 +1612,7 @@ static int mbm_config_show(struct seq_file *s, struct= rdt_resource *r, u32 evtid mon_info.evtid =3D evtid; mondata_config_read(dom, &mon_info); =20 - seq_printf(s, "%d=3D0x%02x", dom->id, mon_info.mon_config); + seq_printf(s, "%d=3D0x%02x", dom->hdr.id, mon_info.mon_config); sep =3D true; } seq_puts(s, "\n"); @@ -1678,7 +1678,7 @@ static void mbm_config_write_domain(struct rdt_resour= ce *r, * are scoped at the domain level. Writing any of these MSRs * on one CPU is observed by all the CPUs in the domain. */ - smp_call_function_any(&d->cpu_mask, mon_event_config_write, + smp_call_function_any(&d->hdr.cpu_mask, mon_event_config_write, &mon_info, 1); =20 /* @@ -1728,8 +1728,8 @@ static int mon_config_write(struct rdt_resource *r, c= har *tok, u32 evtid) return -EINVAL; } =20 - list_for_each_entry(d, &r->domains, list) { - if (d->id =3D=3D dom_id) { + list_for_each_entry(d, &r->domains, hdr.list) { + if (d->hdr.id =3D=3D dom_id) { mbm_config_write_domain(r, d, evtid, val); goto next; } @@ -2276,14 +2276,14 @@ static int set_cache_qos_cfg(int level, bool enable) return -ENOMEM; =20 r_l =3D &rdt_resources_all[level].r_resctrl; - list_for_each_entry(d, &r_l->domains, list) { + list_for_each_entry(d, &r_l->domains, hdr.list) { if (r_l->cache.arch_has_per_cpu_cfg) /* Pick all the CPUs in the domain instance */ - for_each_cpu(cpu, &d->cpu_mask) + for_each_cpu(cpu, &d->hdr.cpu_mask) cpumask_set_cpu(cpu, cpu_mask); else /* Pick one CPU from each domain instance to update MSR */ - cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask); + cpumask_set_cpu(cpumask_any(&d->hdr.cpu_mask), cpu_mask); } =20 /* Update QOS_CFG MSR on all the CPUs in cpu_mask */ @@ -2312,7 +2312,7 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *= r) static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domai= n *d) { u32 num_closid =3D resctrl_arch_get_num_closid(r); - int cpu =3D cpumask_any(&d->cpu_mask); + int cpu =3D cpumask_any(&d->hdr.cpu_mask); int i; =20 d->mbps_val =3D kcalloc_node(num_closid, sizeof(*d->mbps_val), @@ -2361,7 +2361,7 @@ static int set_mba_sc(bool mba_sc) =20 r->membw.mba_sc =3D mba_sc; =20 - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { for (i =3D 0; i < num_closid; i++) d->mbps_val[i] =3D MBA_MAX_MBPS; } @@ -2700,7 +2700,7 @@ static int rdt_get_tree(struct fs_context *fc) =20 if (is_mbm_enabled()) { r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; - list_for_each_entry(dom, &r->domains, list) + list_for_each_entry(dom, &r->domains, hdr.list) mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL, RESCTRL_PICK_ANY_CPU); } @@ -2827,13 +2827,13 @@ static int reset_all_ctrls(struct rdt_resource *r) * CBMs in all domains to the maximum mask value. Pick one CPU * from each domain to update the MSRs below. */ - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { hw_dom =3D resctrl_to_arch_dom(d); =20 for (i =3D 0; i < hw_res->num_closid; i++) hw_dom->ctrl_val[i] =3D r->default_ctrl; msr_param.dom =3D d; - smp_call_function_any(&d->cpu_mask, rdt_ctrl_update, &msr_param, 1); + smp_call_function_any(&d->hdr.cpu_mask, rdt_ctrl_update, &msr_param, 1); } =20 return 0; @@ -3031,7 +3031,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, char name[32]; int ret; =20 - sprintf(name, "mon_%s_%02d", r->name, d->id); + sprintf(name, "mon_%s_%02d", r->name, d->hdr.id); /* create the directory */ kn =3D kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp); if (IS_ERR(kn)) @@ -3047,7 +3047,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, } =20 priv.u.rid =3D r->rid; - priv.u.domid =3D d->id; + priv.u.domid =3D d->hdr.id; list_for_each_entry(mevt, &r->evt_list, list) { priv.u.evtid =3D mevt->evtid; ret =3D mon_addfile(kn, mevt->name, priv.priv); @@ -3098,7 +3098,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_= node *parent_kn, /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); =20 - list_for_each_entry(dom, &r->domains, list) { + list_for_each_entry(dom, &r->domains, hdr.list) { ret =3D mkdir_mondata_subdir(parent_kn, dom, r, prgrp); if (ret) return ret; @@ -3257,7 +3257,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d= , struct resctrl_schema *s, */ tmp_cbm =3D cfg->new_ctrl; if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) { - rdt_last_cmd_printf("No space on %s:%d\n", s->name, d->id); + rdt_last_cmd_printf("No space on %s:%d\n", s->name, d->hdr.id); return -ENOSPC; } cfg->have_new_ctrl =3D true; @@ -3280,7 +3280,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s= , u32 closid) struct rdt_domain *d; int ret; =20 - list_for_each_entry(d, &s->res->domains, list) { + list_for_each_entry(d, &s->res->domains, hdr.list) { ret =3D __init_one_rdt_domain(d, s, closid); if (ret < 0) return ret; @@ -3295,7 +3295,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r,= u32 closid) struct resctrl_staged_config *cfg; struct rdt_domain *d; =20 - list_for_each_entry(d, &r->domains, list) { + list_for_each_entry(d, &r->domains, hdr.list) { if (is_mba_sc(r)) { d->mbps_val[closid] =3D MBA_MAX_MBPS; continue; @@ -3941,7 +3941,7 @@ void resctrl_offline_domain(struct rdt_resource *r, s= truct rdt_domain *d) * per domain monitor data directories. */ if (resctrl_mounted && resctrl_arch_mon_capable()) - rmdir_mondata_subdir_allrdtgrp(r, d->id); + rmdir_mondata_subdir_allrdtgrp(r, d->hdr.id); =20 if (is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 4974619EED2 for ; Thu, 27 Jun 2024 20:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520751; cv=none; b=Acgzlp3iNIvwFEbYumf7SklnvaeNjQJJg6yB1LUwwYkc0/GKj8PJUSzyXnNpTAHq6tL/JcXSpCfNfamu5jd8mONgvBM6ApxcF9YNmMAdcIoxt7Mrb0lQ/1XFxgRIpSyTMAQadMXpUNYmJ49bgfgtYJ7xi7qgRn20Ldfr2/qMsyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520751; c=relaxed/simple; bh=LXBAMSRVP85fseAyrme6w9Mg83d2vWUCn9jlQXJtics=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Otsgke8SDTPeP7uxu7qSPp5809vL0rvB2dVACVS+YVKzOVM5Je3zobfp/5QezLGuFjxmLB4fEMeMVJsAfgmgtX4ccuS0AFUNDX9+U/y3o05aPPffW6Ulq/BHoh9FbrlgXA1i4Q0jjtbweBpvjhxvws9q3II4wGm0+BPxfPE27PE= 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=nftsps/S; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nftsps/S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520750; x=1751056750; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LXBAMSRVP85fseAyrme6w9Mg83d2vWUCn9jlQXJtics=; b=nftsps/SEpK79k7bCzKowrCooD0gTP1ZjHYd/0XyD9dveCSPrzxRe2xv YItcmPiABV6qcppSOlHJSwOr/hFPTSuAYTc/lqjjxZlOw5edDPewfctSD 8GZTHqdkcCG7j/na93Hr2F7/8HzlU/5QnALJLO7CAhqf0LQhpDZ3hcvBu wV3UN98RDXwR8ORPgxOwSYZ85ie+fPMAa/QGXJ7Fqh2fCRRn6Ll8a/hmG A0hGVu0JB1cShznnIyaPue7UMmUmQRy5R5+V20Uvla6pNMeEd2I+UkC5q D6ZkIpeBv7ZFqxJCv0Pn6D6HuMxeSP48Pvp7h/JMEo+JuNPVCBwoMZ4tP A==; X-CSE-ConnectionGUID: 9sDQeR1bT+Oma2STFfpbbA== X-CSE-MsgGUID: GKiOWcLzTGOYCRuMwIwcFg== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809755" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809755" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -0700 X-CSE-ConnectionGUID: 8Kp8D7ckSq6tzyxVQeDFKg== X-CSE-MsgGUID: 8PtlfC2YQbqQ+Obm5R3Y6w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052885" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -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 v22 03/18] x86/resctrl: Prepare for different scope for control/monitor operations Date: Thu, 27 Jun 2024 13:38:41 -0700 Message-ID: <20240627203856.66628-4-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" Resctrl assumes that control and monitor operations on a resource are performed at the same scope. Prepare for systems that use different scope (specifically Intel needs to split the RDT_RESOURCE_L3 resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring). Create separate domain lists for control and monitor operations. Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 25 ++- arch/x86/kernel/cpu/resctrl/internal.h | 7 +- arch/x86/kernel/cpu/resctrl/core.c | 224 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 12 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++--- 7 files changed, 240 insertions(+), 96 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index f63fcf17a3bc..96ddf9ff3183 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -58,15 +58,22 @@ struct resctrl_staged_config { bool have_new_ctrl; }; =20 +enum resctrl_domain_type { + RESCTRL_CTRL_DOMAIN, + RESCTRL_MON_DOMAIN, +}; + /** * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance + * @type: type of this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr { struct list_head list; int id; + enum resctrl_domain_type type; struct cpumask cpu_mask; }; =20 @@ -169,10 +176,12 @@ enum resctrl_scope { * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available - * @scope: Scope of this resource + * @ctrl_scope: Scope of this resource for control functions + * @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. - * @domains: RCU list of all domains for this resource + * @ctrl_domains: RCU list of all control domains for this resource + * @mon_domains: RCU list of all monitor domains for this resource * @name: Name to use in "schemata" file. * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent. @@ -187,10 +196,12 @@ struct rdt_resource { bool alloc_capable; bool mon_capable; int num_rmid; - enum resctrl_scope scope; + enum resctrl_scope ctrl_scope; + enum resctrl_scope mon_scope; struct resctrl_cache cache; struct resctrl_membw membw; - struct list_head domains; + struct list_head ctrl_domains; + struct list_head mon_domains; char *name; int data_width; u32 default_ctrl; @@ -236,8 +247,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, st= ruct rdt_domain *d, =20 u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, u32 closid, enum resctrl_conf_type type); -int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d); -void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d); +int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_domain *= d); +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain *d= ); +void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_domain= *d); +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain = *d); void resctrl_online_cpu(unsigned int cpu); void resctrl_offline_cpu(unsigned int cpu); =20 diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index f1d926832ec8..377679b79919 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -558,8 +558,8 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn); int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name); int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name, umode_t mask); -struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id, - struct list_head **pos); +struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id, + struct list_head **pos); ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); int rdtgroup_schemata_show(struct kernfs_open_file *of, @@ -578,7 +578,8 @@ int rdt_pseudo_lock_init(void); void rdt_pseudo_lock_release(void); int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp); void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); -struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); +struct rdt_domain *get_ctrl_domain_from_cpu(int cpu, struct rdt_resource *= r); +struct rdt_domain *get_mon_domain_from_cpu(int cpu, struct rdt_resource *r= ); int closids_supported(void); void closid_free(int closid); int alloc_rmid(u32 closid); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 96fff44f9d03..edd9b2bfb53d 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -60,7 +60,8 @@ static void mba_wrmsr_intel(struct msr_param *m); static void cat_wrmsr(struct msr_param *m); static void mba_wrmsr_amd(struct msr_param *m); =20 -#define domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.dom= ains) +#define ctrl_domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctr= l.ctrl_domains) +#define mon_domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl= .mon_domains) =20 struct rdt_hw_resource rdt_resources_all[] =3D { [RDT_RESOURCE_L3] =3D @@ -68,8 +69,10 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_L3, .name =3D "L3", - .scope =3D RESCTRL_L3_CACHE, - .domains =3D domain_init(RDT_RESOURCE_L3), + .ctrl_scope =3D RESCTRL_L3_CACHE, + .mon_scope =3D RESCTRL_L3_CACHE, + .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_L3), + .mon_domains =3D mon_domain_init(RDT_RESOURCE_L3), .parse_ctrlval =3D parse_cbm, .format_str =3D "%d=3D%0*x", .fflags =3D RFTYPE_RES_CACHE, @@ -82,8 +85,8 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_L2, .name =3D "L2", - .scope =3D RESCTRL_L2_CACHE, - .domains =3D domain_init(RDT_RESOURCE_L2), + .ctrl_scope =3D RESCTRL_L2_CACHE, + .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_L2), .parse_ctrlval =3D parse_cbm, .format_str =3D "%d=3D%0*x", .fflags =3D RFTYPE_RES_CACHE, @@ -96,8 +99,8 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_MBA, .name =3D "MB", - .scope =3D RESCTRL_L3_CACHE, - .domains =3D domain_init(RDT_RESOURCE_MBA), + .ctrl_scope =3D RESCTRL_L3_CACHE, + .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_MBA), .parse_ctrlval =3D parse_bw, .format_str =3D "%d=3D%*u", .fflags =3D RFTYPE_RES_MB, @@ -108,8 +111,8 @@ struct rdt_hw_resource rdt_resources_all[] =3D { .r_resctrl =3D { .rid =3D RDT_RESOURCE_SMBA, .name =3D "SMBA", - .scope =3D RESCTRL_L3_CACHE, - .domains =3D domain_init(RDT_RESOURCE_SMBA), + .ctrl_scope =3D RESCTRL_L3_CACHE, + .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval =3D parse_bw, .format_str =3D "%d=3D%*u", .fflags =3D RFTYPE_RES_MB, @@ -349,13 +352,28 @@ static void cat_wrmsr(struct msr_param *m) wrmsrl(hw_res->msr_base + i, hw_dom->ctrl_val[i]); } =20 -struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) +struct rdt_domain *get_ctrl_domain_from_cpu(int cpu, struct rdt_resource *= r) { struct rdt_domain *d; =20 lockdep_assert_cpus_held(); =20 - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { + /* Find the domain that contains this CPU */ + if (cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) + return d; + } + + return NULL; +} + +struct rdt_domain *get_mon_domain_from_cpu(int cpu, struct rdt_resource *r) +{ + struct rdt_domain *d; + + lockdep_assert_cpus_held(); + + list_for_each_entry(d, &r->mon_domains, hdr.list) { /* Find the domain that contains this CPU */ if (cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) return d; @@ -379,26 +397,26 @@ void rdt_ctrl_update(void *arg) } =20 /* - * rdt_find_domain - Find a domain in a resource that matches input resour= ce id + * rdt_find_domain - Search for a domain id in a resource domain list. * - * Search resource r's domain list to find the resource id. If the resource - * id is found in a domain, return the domain. Otherwise, if requested by - * caller, return the first domain whose id is bigger than the input id. - * The domain list is sorted by id in ascending order. + * Search the domain list to find the domain id. If the domain id is + * found, return the domain. NULL otherwise. If the domain id is not + * found (and NULL returned) then the first domain with id bigger than + * the input id can be returned to the caller via @pos. */ -struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id, - struct list_head **pos) +struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id, + struct list_head **pos) { - struct rdt_domain *d; + struct rdt_domain_hdr *d; struct list_head *l; =20 - list_for_each(l, &r->domains) { - d =3D list_entry(l, struct rdt_domain, hdr.list); + list_for_each(l, h) { + d =3D list_entry(l, struct rdt_domain_hdr, list); /* When id is found, return its domain. */ - if (id =3D=3D d->hdr.id) + if (id =3D=3D d->id) return d; /* Stop searching when finding id's position in sorted list. */ - if (id < d->hdr.id) + if (id < d->id) break; } =20 @@ -494,38 +512,29 @@ static int get_domain_id_from_scope(int cpu, enum res= ctrl_scope scope) return -EINVAL; } =20 -/* - * domain_add_cpu - Add a cpu to a resource's domain list. - * - * If an existing domain in the resource r's domain list matches the cpu's - * resource id, add the cpu in the domain. - * - * Otherwise, a new domain is allocated and inserted into the right positi= on - * in the domain list sorted by id in ascending order. - * - * The order in the domain list is visible to users when we print entries - * in the schemata file and schemata input is validated to have the same o= rder - * as this list. - */ -static void domain_add_cpu(int cpu, struct rdt_resource *r) +static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) { - int id =3D get_domain_id_from_scope(cpu, r->scope); + int id =3D get_domain_id_from_scope(cpu, r->ctrl_scope); struct list_head *add_pos =3D NULL; struct rdt_hw_domain *hw_dom; + struct rdt_domain_hdr *hdr; struct rdt_domain *d; int err; =20 lockdep_assert_held(&domain_list_lock); =20 if (id < 0) { - pr_warn_once("Can't find domain id for CPU:%d scope:%d for resource %s\n= ", - cpu, r->scope, r->name); + pr_warn_once("Can't find control domain id for CPU:%d scope:%d for resou= rce %s\n", + cpu, r->ctrl_scope, r->name); return; } =20 - d =3D rdt_find_domain(r, id, &add_pos); + hdr =3D rdt_find_domain(&r->ctrl_domains, id, &add_pos); + if (hdr) { + if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + return; + d =3D container_of(hdr, struct rdt_domain, hdr); =20 - if (d) { cpumask_set_cpu(cpu, &d->hdr.cpu_mask); if (r->cache.arch_has_per_cpu_cfg) rdt_domain_reconfigure_cdp(r); @@ -538,23 +547,70 @@ static void domain_add_cpu(int cpu, struct rdt_resour= ce *r) =20 d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; + d->hdr.type =3D RESCTRL_CTRL_DOMAIN; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 rdt_domain_reconfigure_cdp(r); =20 - if (r->alloc_capable && domain_setup_ctrlval(r, d)) { + if (domain_setup_ctrlval(r, d)) { domain_free(hw_dom); return; } =20 - if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { + list_add_tail_rcu(&d->hdr.list, add_pos); + + err =3D resctrl_online_ctrl_domain(r, d); + if (err) { + list_del_rcu(&d->hdr.list); + synchronize_rcu(); + domain_free(hw_dom); + } +} + +static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) +{ + int id =3D get_domain_id_from_scope(cpu, r->mon_scope); + struct list_head *add_pos =3D NULL; + struct rdt_hw_domain *hw_dom; + struct rdt_domain_hdr *hdr; + struct rdt_domain *d; + int err; + + lockdep_assert_held(&domain_list_lock); + + if (id < 0) { + pr_warn_once("Can't find monitor domain id for CPU:%d scope:%d for resou= rce %s\n", + cpu, r->mon_scope, r->name); + return; + } + + hdr =3D rdt_find_domain(&r->mon_domains, id, &add_pos); + if (hdr) { + if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + return; + d =3D container_of(hdr, struct rdt_domain, hdr); + + cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + return; + } + + hw_dom =3D kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu)); + if (!hw_dom) + return; + + d =3D &hw_dom->d_resctrl; + d->hdr.id =3D id; + d->hdr.type =3D RESCTRL_MON_DOMAIN; + cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + + if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { domain_free(hw_dom); return; } =20 list_add_tail_rcu(&d->hdr.list, add_pos); =20 - err =3D resctrl_online_domain(r, d); + err =3D resctrl_online_mon_domain(r, d); if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); @@ -562,30 +618,45 @@ static void domain_add_cpu(int cpu, struct rdt_resour= ce *r) } } =20 -static void domain_remove_cpu(int cpu, struct rdt_resource *r) +static void domain_add_cpu(int cpu, struct rdt_resource *r) +{ + if (r->alloc_capable) + domain_add_cpu_ctrl(cpu, r); + if (r->mon_capable) + domain_add_cpu_mon(cpu, r); +} + +static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r) { - int id =3D get_domain_id_from_scope(cpu, r->scope); + int id =3D get_domain_id_from_scope(cpu, r->ctrl_scope); struct rdt_hw_domain *hw_dom; + struct rdt_domain_hdr *hdr; struct rdt_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 if (id < 0) { - pr_warn_once("Can't find domain id for CPU:%d scope:%d for resource %s\n= ", - cpu, r->scope, r->name); + pr_warn_once("Can't find control domain id for CPU:%d scope:%d for resou= rce %s\n", + cpu, r->ctrl_scope, r->name); return; } =20 - d =3D rdt_find_domain(r, id, NULL); - if (!d) { - pr_warn("Couldn't find domain with id=3D%d for CPU %d\n", id, cpu); + hdr =3D rdt_find_domain(&r->ctrl_domains, id, NULL); + if (!hdr) { + pr_warn("Can't find control domain for id=3D%d for CPU %d for resource %= s\n", + id, cpu, r->name); return; } + + if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + return; + + d =3D container_of(hdr, struct rdt_domain, hdr); hw_dom =3D resctrl_to_arch_dom(d); =20 cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); if (cpumask_empty(&d->hdr.cpu_mask)) { - resctrl_offline_domain(r, d); + resctrl_offline_ctrl_domain(r, d); list_del_rcu(&d->hdr.list); synchronize_rcu(); =20 @@ -601,6 +672,53 @@ static void domain_remove_cpu(int cpu, struct rdt_reso= urce *r) } } =20 +static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) +{ + int id =3D get_domain_id_from_scope(cpu, r->mon_scope); + struct rdt_hw_domain *hw_dom; + struct rdt_domain_hdr *hdr; + struct rdt_domain *d; + + lockdep_assert_held(&domain_list_lock); + + if (id < 0) { + pr_warn_once("Can't find monitor domain id for CPU:%d scope:%d for resou= rce %s\n", + cpu, r->mon_scope, r->name); + return; + } + + hdr =3D rdt_find_domain(&r->mon_domains, id, NULL); + if (!hdr) { + pr_warn("Can't find monitor domain for id=3D%d for CPU %d for resource %= s\n", + id, cpu, r->name); + return; + } + + if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + return; + + d =3D container_of(hdr, struct rdt_domain, hdr); + hw_dom =3D resctrl_to_arch_dom(d); + + cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); + if (cpumask_empty(&d->hdr.cpu_mask)) { + resctrl_offline_mon_domain(r, d); + list_del_rcu(&d->hdr.list); + synchronize_rcu(); + domain_free(hw_dom); + + return; + } +} + +static void domain_remove_cpu(int cpu, struct rdt_resource *r) +{ + if (r->alloc_capable) + domain_remove_cpu_ctrl(cpu, r); + if (r->mon_capable) + domain_remove_cpu_mon(cpu, r); +} + static void clear_closid_rmid(int cpu) { struct resctrl_pqr_state *state =3D this_cpu_ptr(&pqr_state); diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index 6246f48b0449..8cc36723f077 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -231,7 +231,7 @@ static int parse_line(char *line, struct resctrl_schema= *s, return -EINVAL; } dom =3D strim(dom); - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { if (d->hdr.id =3D=3D dom_id) { data.buf =3D dom; data.rdtgrp =3D rdtgrp; @@ -306,7 +306,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r,= u32 closid) /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); =20 - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { hw_dom =3D resctrl_to_arch_dom(d); msr_param.res =3D NULL; for (t =3D 0; t < CDP_NUM_TYPES; t++) { @@ -450,7 +450,7 @@ static void show_doms(struct seq_file *s, struct resctr= l_schema *schema, int clo lockdep_assert_cpus_held(); =20 seq_printf(s, "%*s:", max_name_width, schema->name); - list_for_each_entry(dom, &r->domains, hdr.list) { + list_for_each_entry(dom, &r->ctrl_domains, hdr.list) { if (sep) seq_puts(s, ";"); =20 @@ -556,6 +556,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, int rdtgroup_mondata_show(struct seq_file *m, void *arg) { struct kernfs_open_file *of =3D m->private; + struct rdt_domain_hdr *hdr; u32 resid, evtid, domid; struct rdtgroup *rdtgrp; struct rdt_resource *r; @@ -576,11 +577,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) evtid =3D md.u.evtid; =20 r =3D &rdt_resources_all[resid].r_resctrl; - d =3D rdt_find_domain(r, domid, NULL); - if (!d) { + hdr =3D rdt_find_domain(&r->mon_domains, domid, NULL); + if (!hdr || WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) { ret =3D -ENOENT; goto out; } + d =3D container_of(hdr, struct rdt_domain, hdr); =20 mon_event_read(&rr, r, d, rdtgrp, evtid, false); =20 diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index ab8a198d88b3..82a44de8136f 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -490,7 +490,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) idx =3D resctrl_arch_rmid_idx_encode(entry->closid, entry->rmid); =20 entry->busy =3D 0; - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->mon_domains, hdr.list) { /* * For the first limbo RMID in the domain, * setup up the limbo worker. @@ -687,7 +687,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_domain *dom_mbm) idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); pmbm_data =3D &dom_mbm->mbm_local[idx]; =20 - dom_mba =3D get_domain_from_cpu(smp_processor_id(), r_mba); + dom_mba =3D get_ctrl_domain_from_cpu(smp_processor_id(), r_mba); if (!dom_mba) { pr_warn_once("Failure to get domain for MBA update\n"); return; diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index df45c839a58f..bdcf95f561d4 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -292,7 +292,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock= _region *plr) */ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) { - enum resctrl_scope scope =3D plr->s->res->scope; + enum resctrl_scope scope =3D plr->s->res->ctrl_scope; struct cacheinfo *ci; int ret; =20 @@ -854,7 +854,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_dom= ain *d) * associated with them. */ for_each_alloc_capable_rdt_resource(r) { - list_for_each_entry(d_i, &r->domains, hdr.list) { + list_for_each_entry(d_i, &r->ctrl_domains, hdr.list) { if (d_i->plr) cpumask_or(cpu_with_psl, cpu_with_psl, &d_i->hdr.cpu_mask); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index b6ba77cdf0e8..17d4610eecf5 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -98,7 +98,7 @@ void rdt_staged_configs_clear(void) lockdep_assert_held(&rdtgroup_mutex); =20 for_each_alloc_capable_rdt_resource(r) { - list_for_each_entry(dom, &r->domains, hdr.list) + list_for_each_entry(dom, &r->ctrl_domains, hdr.list) memset(dom->staged_config, 0, sizeof(dom->staged_config)); } } @@ -1021,7 +1021,7 @@ static int rdt_bit_usage_show(struct kernfs_open_file= *of, cpus_read_lock(); mutex_lock(&rdtgroup_mutex); hw_shareable =3D r->cache.shareable_bits; - list_for_each_entry(dom, &r->domains, hdr.list) { + list_for_each_entry(dom, &r->ctrl_domains, hdr.list) { if (sep) seq_putc(seq, ';'); sw_shareable =3D 0; @@ -1343,7 +1343,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgr= oup *rdtgrp) if (r->rid =3D=3D RDT_RESOURCE_MBA || r->rid =3D=3D RDT_RESOURCE_SMBA) continue; has_cache =3D true; - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { ctrl =3D resctrl_arch_get_config(r, d, closid, s->conf_type); if (rdtgroup_cbm_overlaps(s, d, ctrl, closid, false)) { @@ -1454,11 +1454,11 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resour= ce *r, struct cacheinfo *ci; int num_b; =20 - if (WARN_ON_ONCE(r->scope !=3D RESCTRL_L2_CACHE && r->scope !=3D RESCTRL_= L3_CACHE)) + if (WARN_ON_ONCE(r->ctrl_scope !=3D RESCTRL_L2_CACHE && r->ctrl_scope != =3D RESCTRL_L3_CACHE)) return size; =20 num_b =3D bitmap_weight(&cbm, r->cache.cbm_len); - ci =3D get_cpu_cacheinfo_level(cpumask_any(&d->hdr.cpu_mask), r->scope); + ci =3D get_cpu_cacheinfo_level(cpumask_any(&d->hdr.cpu_mask), r->ctrl_sco= pe); if (ci) size =3D ci->size / r->cache.cbm_len * num_b; =20 @@ -1514,7 +1514,7 @@ static int rdtgroup_size_show(struct kernfs_open_file= *of, type =3D schema->conf_type; sep =3D false; seq_printf(s, "%*s:", max_name_width, schema->name); - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { if (sep) seq_putc(s, ';'); if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKSETUP) { @@ -1604,7 +1604,7 @@ static int mbm_config_show(struct seq_file *s, struct= rdt_resource *r, u32 evtid cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 - list_for_each_entry(dom, &r->domains, hdr.list) { + list_for_each_entry(dom, &r->mon_domains, hdr.list) { if (sep) seq_puts(s, ";"); =20 @@ -1728,7 +1728,7 @@ static int mon_config_write(struct rdt_resource *r, c= har *tok, u32 evtid) return -EINVAL; } =20 - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->mon_domains, hdr.list) { if (d->hdr.id =3D=3D dom_id) { mbm_config_write_domain(r, d, evtid, val); goto next; @@ -2276,7 +2276,7 @@ static int set_cache_qos_cfg(int level, bool enable) return -ENOMEM; =20 r_l =3D &rdt_resources_all[level].r_resctrl; - list_for_each_entry(d, &r_l->domains, hdr.list) { + list_for_each_entry(d, &r_l->ctrl_domains, hdr.list) { if (r_l->cache.arch_has_per_cpu_cfg) /* Pick all the CPUs in the domain instance */ for_each_cpu(cpu, &d->hdr.cpu_mask) @@ -2361,7 +2361,7 @@ static int set_mba_sc(bool mba_sc) =20 r->membw.mba_sc =3D mba_sc; =20 - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { for (i =3D 0; i < num_closid; i++) d->mbps_val[i] =3D MBA_MAX_MBPS; } @@ -2700,7 +2700,7 @@ static int rdt_get_tree(struct fs_context *fc) =20 if (is_mbm_enabled()) { r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; - list_for_each_entry(dom, &r->domains, hdr.list) + list_for_each_entry(dom, &r->mon_domains, hdr.list) mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL, RESCTRL_PICK_ANY_CPU); } @@ -2824,10 +2824,10 @@ static int reset_all_ctrls(struct rdt_resource *r) =20 /* * Disable resource control for this resource by setting all - * CBMs in all domains to the maximum mask value. Pick one CPU + * CBMs in all ctrl_domains to the maximum mask value. Pick one CPU * from each domain to update the MSRs below. */ - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { hw_dom =3D resctrl_to_arch_dom(d); =20 for (i =3D 0; i < hw_res->num_closid; i++) @@ -3098,7 +3098,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_= node *parent_kn, /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); =20 - list_for_each_entry(dom, &r->domains, hdr.list) { + list_for_each_entry(dom, &r->mon_domains, hdr.list) { ret =3D mkdir_mondata_subdir(parent_kn, dom, r, prgrp); if (ret) return ret; @@ -3280,7 +3280,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s= , u32 closid) struct rdt_domain *d; int ret; =20 - list_for_each_entry(d, &s->res->domains, hdr.list) { + list_for_each_entry(d, &s->res->ctrl_domains, hdr.list) { ret =3D __init_one_rdt_domain(d, s, closid); if (ret < 0) return ret; @@ -3295,7 +3295,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r,= u32 closid) struct resctrl_staged_config *cfg; struct rdt_domain *d; =20 - list_for_each_entry(d, &r->domains, hdr.list) { + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { if (is_mba_sc(r)) { d->mbps_val[closid] =3D MBA_MAX_MBPS; continue; @@ -3926,15 +3926,19 @@ static void domain_destroy_mon_state(struct rdt_dom= ain *d) kfree(d->mbm_local); } =20 -void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d) +void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_domain= *d) { mutex_lock(&rdtgroup_mutex); =20 if (supports_mba_mbps() && r->rid =3D=3D RDT_RESOURCE_MBA) mba_sc_domain_destroy(r, d); =20 - if (!r->mon_capable) - goto out_unlock; + mutex_unlock(&rdtgroup_mutex); +} + +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain = *d) +{ + mutex_lock(&rdtgroup_mutex); =20 /* * If resctrl is mounted, remove all the @@ -3960,7 +3964,6 @@ void resctrl_offline_domain(struct rdt_resource *r, s= truct rdt_domain *d) =20 domain_destroy_mon_state(d); =20 -out_unlock: mutex_unlock(&rdtgroup_mutex); } =20 @@ -3995,7 +3998,7 @@ static int domain_setup_mon_state(struct rdt_resource= *r, struct rdt_domain *d) return 0; } =20 -int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) +int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_domain *= d) { int err =3D 0; =20 @@ -4004,11 +4007,18 @@ int resctrl_online_domain(struct rdt_resource *r, s= truct rdt_domain *d) if (supports_mba_mbps() && r->rid =3D=3D RDT_RESOURCE_MBA) { /* RDT_RESOURCE_MBA is never mon_capable */ err =3D mba_sc_domain_allocate(r, d); - goto out_unlock; } =20 - if (!r->mon_capable) - goto out_unlock; + mutex_unlock(&rdtgroup_mutex); + + return err; +} + +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain *d) +{ + int err; + + mutex_lock(&rdtgroup_mutex); =20 err =3D domain_setup_mon_state(r, d); if (err) @@ -4073,7 +4083,7 @@ void resctrl_offline_cpu(unsigned int cpu) if (!l3->mon_capable) goto out_unlock; =20 - d =3D get_domain_from_cpu(cpu, l3); + d =3D get_mon_domain_from_cpu(cpu, l3); if (d) { if (is_mbm_enabled() && cpu =3D=3D d->mbm_work_cpu) { cancel_delayed_work(&d->mbm_over); --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 C508C19F49D for ; Thu, 27 Jun 2024 20:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520754; cv=none; b=S4F5WKJrR9O5sN2EPGp6dUgDcmG6DOcCPS+jYo4VwBplMnQbawPKv07uaMIuSgA3cdqBSJNkh6aIy6N9yy9nUWciPOG6UeAdYnX3oiEl1P9F4w/s2InxrkUxavOsnRUJKJQWjrEkJgPu4rlfOJrZ14lKMr6l+m/wHRATVIx4m1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520754; c=relaxed/simple; bh=zRul8vJIXVUHLjJjSdvBHjjjQ78+5XXxQkmaD5ZmbZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PexpObIGcr2HBVqS1waVO6fcM3aWCELI+JqLeGmL0HBIkyvr6wZvt0eZf2w7nK4pNV8dwbZZO/9J9pUcgOEYJKjpmZADCLxOm5Tw3qHciAShjwkRJIvXFHuarkKlh6pUh63Kq+5fCtOJg1T7XfOBGjKGtRFdkD57ZBb02mMzCzw= 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=dFNDRfZ0; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dFNDRfZ0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520751; x=1751056751; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zRul8vJIXVUHLjJjSdvBHjjjQ78+5XXxQkmaD5ZmbZo=; b=dFNDRfZ0Wxxe0Dbeg5STX+rvpcZwvu70PJ6ndKCOGXQwBFEnrGXwRJ7k OLIhT4qj1XQeUGsRMlXoe1T+h4QwGKE6Vj61LnpPCiJiQn48Ls6Prg8Vb 5KMkmxqgyPtY152i0FqD30SrpsSuC+ZHNbENQsF/bHakNjuX3Nw9jeOnp ytvVRGHI3J8uwwvTDh0qEAb7BGFApokygr9lK84ZJ1BHZ2wZP0LhIFY6R p+t8FemGPfsuEaN5WSjYryp5Ca7lj1xjHule0XTT5cf2OWnyISxXYkltq krEZo2CQZMdXy4EONqgVfrl+zK/pffa3mc/T/StxMlg/UkOdrLJyKGGA2 w==; X-CSE-ConnectionGUID: huf5Ds/YST2OH53PFC5SUA== X-CSE-MsgGUID: 05zeudM/RmmoBKu4pm1x+A== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809762" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809762" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:08 -0700 X-CSE-ConnectionGUID: iVcud42+QvK6al22zia0NQ== X-CSE-MsgGUID: ZO0GNYTmStmHhz3Rnndp+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052888" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -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 v22 04/18] x86/resctrl: Split the rdt_domain and rdt_hw_domain structures Date: Thu, 27 Jun 2024 13:38:42 -0700 Message-ID: <20240627203856.66628-5-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" The same rdt_domain structure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions. Split into separate rdt_ctrl_domain and rdt_mon_domain structures with just the fields required for control and monitoring respectively. Similar split of the rdt_hw_domain structure into rdt_hw_ctrl_domain and rdt_hw_mon_domain. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 48 ++++++++------- arch/x86/kernel/cpu/resctrl/internal.h | 62 ++++++++++++-------- arch/x86/kernel/cpu/resctrl/core.c | 71 ++++++++++++----------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 28 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 40 ++++++------- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 64 ++++++++++---------- 7 files changed, 174 insertions(+), 145 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 96ddf9ff3183..aa2c22a8e37b 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -78,7 +78,23 @@ struct rdt_domain_hdr { }; =20 /** - * struct rdt_domain - group of CPUs sharing a resctrl resource + * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resour= ce + * @hdr: common header for different domain types + * @plr: pseudo-locked region (if any) associated with domain + * @staged_config: parsed configuration to be applied + * @mbps_val: When mba_sc is enabled, this holds the array of user + * specified control values for mba_sc in MBps, indexed + * by closid + */ +struct rdt_ctrl_domain { + struct rdt_domain_hdr hdr; + struct pseudo_lock_region *plr; + struct resctrl_staged_config staged_config[CDP_NUM_TYPES]; + u32 *mbps_val; +}; + +/** + * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth @@ -87,13 +103,8 @@ struct rdt_domain_hdr { * @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters - * @plr: pseudo-locked region (if any) associated with domain - * @staged_config: parsed configuration to be applied - * @mbps_val: When mba_sc is enabled, this holds the array of user - * specified control values for mba_sc in MBps, indexed - * by closid */ -struct rdt_domain { +struct rdt_mon_domain { struct rdt_domain_hdr hdr; unsigned long *rmid_busy_llc; struct mbm_state *mbm_total; @@ -102,9 +113,6 @@ struct rdt_domain { struct delayed_work cqm_limbo; int mbm_work_cpu; int cqm_work_cpu; - struct pseudo_lock_region *plr; - struct resctrl_staged_config staged_config[CDP_NUM_TYPES]; - u32 *mbps_val; }; =20 /** @@ -208,7 +216,7 @@ struct rdt_resource { const char *format_str; int (*parse_ctrlval)(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d); + struct rdt_ctrl_domain *d); struct list_head evt_list; unsigned long fflags; bool cdp_capable; @@ -242,15 +250,15 @@ int resctrl_arch_update_domains(struct rdt_resource *= r, u32 closid); * Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. */ -int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d, +int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type t, u32 cfg_val); =20 -u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, +u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type type); -int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_domain *= d); -int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain *d= ); -void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_domain= *d); -void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain = *d); +int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d); +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domai= n *d); +void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d); +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_dom= ain *d); void resctrl_online_cpu(unsigned int cpu); void resctrl_offline_cpu(unsigned int cpu); =20 @@ -279,7 +287,7 @@ void resctrl_offline_cpu(unsigned int cpu); * Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, u32 closid, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *arch_mon_ctx); =20 @@ -312,7 +320,7 @@ static inline void resctrl_arch_rmid_read_context_check= (void) * * This can be called from any CPU. */ -void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, +void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, u32 closid, u32 rmid, enum resctrl_event_id eventid); =20 @@ -325,7 +333,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, st= ruct rdt_domain *d, * * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain= *d); +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d); =20 extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 377679b79919..135190e0711c 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -147,7 +147,7 @@ union mon_data_bits { struct rmid_read { struct rdtgroup *rgrp; struct rdt_resource *r; - struct rdt_domain *d; + struct rdt_mon_domain *d; enum resctrl_event_id evtid; bool first; int err; @@ -232,7 +232,7 @@ struct mongroup { */ struct pseudo_lock_region { struct resctrl_schema *s; - struct rdt_domain *d; + struct rdt_ctrl_domain *d; u32 cbm; wait_queue_head_t lock_thread_wq; int thread_done; @@ -355,25 +355,41 @@ struct arch_mbm_state { }; =20 /** - * struct rdt_hw_domain - Arch private attributes of a set of CPUs that sh= are - * a resource + * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs th= at share + * a resource for a control function * @d_resctrl: Properties exposed to the resctrl file system * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) + * + * Members of this structure are accessed via helpers that provide abstrac= tion. + */ +struct rdt_hw_ctrl_domain { + struct rdt_ctrl_domain d_resctrl; + u32 *ctrl_val; +}; + +/** + * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share + * a resource for a monitor function + * @d_resctrl: Properties exposed to the resctrl file system * @arch_mbm_total: arch private state for MBM total bandwidth * @arch_mbm_local: arch private state for MBM local bandwidth * * Members of this structure are accessed via helpers that provide abstrac= tion. */ -struct rdt_hw_domain { - struct rdt_domain d_resctrl; - u32 *ctrl_val; +struct rdt_hw_mon_domain { + struct rdt_mon_domain d_resctrl; struct arch_mbm_state *arch_mbm_total; struct arch_mbm_state *arch_mbm_local; }; =20 -static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain = *r) +static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct r= dt_ctrl_domain *r) +{ + return container_of(r, struct rdt_hw_ctrl_domain, d_resctrl); +} + +static inline struct rdt_hw_mon_domain *resctrl_to_arch_mon_dom(struct rdt= _mon_domain *r) { - return container_of(r, struct rdt_hw_domain, d_resctrl); + return container_of(r, struct rdt_hw_mon_domain, d_resctrl); } =20 /** @@ -385,7 +401,7 @@ static inline struct rdt_hw_domain *resctrl_to_arch_dom= (struct rdt_domain *r) */ struct msr_param { struct rdt_resource *res; - struct rdt_domain *dom; + struct rdt_ctrl_domain *dom; u32 low; u32 high; }; @@ -458,9 +474,9 @@ static inline struct rdt_hw_resource *resctrl_to_arch_r= es(struct rdt_resource *r } =20 int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d); + struct rdt_ctrl_domain *d); int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d); + struct rdt_ctrl_domain *d); =20 extern struct mutex rdtgroup_mutex; =20 @@ -564,22 +580,22 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_fi= le *of, char *buf, size_t nbytes, loff_t off); int rdtgroup_schemata_show(struct kernfs_open_file *of, struct seq_file *s, void *v); -bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_domain *d, +bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domai= n *d, unsigned long cbm, int closid, bool exclusive); -unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_domai= n *d, +unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_ctrl_= domain *d, unsigned long cbm); enum rdtgrp_mode rdtgroup_mode_by_closid(int closid); int rdtgroup_tasks_assigned(struct rdtgroup *r); int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp); -bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned lo= ng cbm); -bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d); +bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_ctrl_domain *d, unsign= ed long cbm); +bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_ctrl_domain *d); int rdt_pseudo_lock_init(void); void rdt_pseudo_lock_release(void); int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp); void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); -struct rdt_domain *get_ctrl_domain_from_cpu(int cpu, struct rdt_resource *= r); -struct rdt_domain *get_mon_domain_from_cpu(int cpu, struct rdt_resource *r= ); +struct rdt_ctrl_domain *get_ctrl_domain_from_cpu(int cpu, struct rdt_resou= rce *r); +struct rdt_mon_domain *get_mon_domain_from_cpu(int cpu, struct rdt_resourc= e *r); int closids_supported(void); void closid_free(int closid); int alloc_rmid(u32 closid); @@ -590,19 +606,19 @@ bool __init rdt_cpu_has(int flag); void mon_event_count(void *info); int rdtgroup_mondata_show(struct seq_file *m, void *arg); void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, - struct rdt_domain *d, struct rdtgroup *rdtgrp, + struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, int evtid, int first); -void mbm_setup_overflow_handler(struct rdt_domain *dom, +void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long delay_ms, int exclude_cpu); void mbm_handle_overflow(struct work_struct *work); void __init intel_rdt_mbm_apply_quirk(void); bool is_mba_sc(struct rdt_resource *r); -void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_m= s, +void cqm_setup_limbo_handler(struct rdt_mon_domain *dom, unsigned long del= ay_ms, int exclude_cpu); void cqm_handle_limbo(struct work_struct *work); -bool has_busy_rmid(struct rdt_domain *d); -void __check_limbo(struct rdt_domain *d, bool force_free); +bool has_busy_rmid(struct rdt_mon_domain *d); +void __check_limbo(struct rdt_mon_domain *d, bool force_free); void rdt_domain_reconfigure_cdp(struct rdt_resource *r); void __init thread_throttle_mode_init(void); void __init mbm_config_rftype_init(const char *config); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index edd9b2bfb53d..b4f2be776408 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -309,8 +309,8 @@ static void rdt_get_cdp_l2_config(void) =20 static void mba_wrmsr_amd(struct msr_param *m) { + struct rdt_hw_ctrl_domain *hw_dom =3D resctrl_to_arch_ctrl_dom(m->dom); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(m->res); - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(m->dom); unsigned int i; =20 for (i =3D m->low; i < m->high; i++) @@ -333,8 +333,8 @@ static u32 delay_bw_map(unsigned long bw, struct rdt_re= source *r) =20 static void mba_wrmsr_intel(struct msr_param *m) { + struct rdt_hw_ctrl_domain *hw_dom =3D resctrl_to_arch_ctrl_dom(m->dom); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(m->res); - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(m->dom); unsigned int i; =20 /* Write the delay values for mba. */ @@ -344,17 +344,17 @@ static void mba_wrmsr_intel(struct msr_param *m) =20 static void cat_wrmsr(struct msr_param *m) { + struct rdt_hw_ctrl_domain *hw_dom =3D resctrl_to_arch_ctrl_dom(m->dom); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(m->res); - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(m->dom); unsigned int i; =20 for (i =3D m->low; i < m->high; i++) wrmsrl(hw_res->msr_base + i, hw_dom->ctrl_val[i]); } =20 -struct rdt_domain *get_ctrl_domain_from_cpu(int cpu, struct rdt_resource *= r) +struct rdt_ctrl_domain *get_ctrl_domain_from_cpu(int cpu, struct rdt_resou= rce *r) { - struct rdt_domain *d; + struct rdt_ctrl_domain *d; =20 lockdep_assert_cpus_held(); =20 @@ -367,9 +367,9 @@ struct rdt_domain *get_ctrl_domain_from_cpu(int cpu, st= ruct rdt_resource *r) return NULL; } =20 -struct rdt_domain *get_mon_domain_from_cpu(int cpu, struct rdt_resource *r) +struct rdt_mon_domain *get_mon_domain_from_cpu(int cpu, struct rdt_resourc= e *r) { - struct rdt_domain *d; + struct rdt_mon_domain *d; =20 lockdep_assert_cpus_held(); =20 @@ -440,18 +440,23 @@ static void setup_default_ctrlval(struct rdt_resource= *r, u32 *dc) *dc =3D r->default_ctrl; } =20 -static void domain_free(struct rdt_hw_domain *hw_dom) +static void ctrl_domain_free(struct rdt_hw_ctrl_domain *hw_dom) +{ + kfree(hw_dom->ctrl_val); + kfree(hw_dom); +} + +static void mon_domain_free(struct rdt_hw_mon_domain *hw_dom) { kfree(hw_dom->arch_mbm_total); kfree(hw_dom->arch_mbm_local); - kfree(hw_dom->ctrl_val); kfree(hw_dom); } =20 -static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain = *d) +static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_ctrl_do= main *d) { + struct rdt_hw_ctrl_domain *hw_dom =3D resctrl_to_arch_ctrl_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(d); struct msr_param m; u32 *dc; =20 @@ -476,7 +481,7 @@ static int domain_setup_ctrlval(struct rdt_resource *r,= struct rdt_domain *d) * @num_rmid: The size of the MBM counter array * @hw_dom: The domain that owns the allocated arrays */ -static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_do= m) +static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *h= w_dom) { size_t tsize; =20 @@ -515,10 +520,10 @@ static int get_domain_id_from_scope(int cpu, enum res= ctrl_scope scope) static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->ctrl_scope); + struct rdt_hw_ctrl_domain *hw_dom; struct list_head *add_pos =3D NULL; - struct rdt_hw_domain *hw_dom; struct rdt_domain_hdr *hdr; - struct rdt_domain *d; + struct rdt_ctrl_domain *d; int err; =20 lockdep_assert_held(&domain_list_lock); @@ -533,7 +538,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) if (hdr) { if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) return; - d =3D container_of(hdr, struct rdt_domain, hdr); + d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); =20 cpumask_set_cpu(cpu, &d->hdr.cpu_mask); if (r->cache.arch_has_per_cpu_cfg) @@ -553,7 +558,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) rdt_domain_reconfigure_cdp(r); =20 if (domain_setup_ctrlval(r, d)) { - domain_free(hw_dom); + ctrl_domain_free(hw_dom); return; } =20 @@ -563,7 +568,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); - domain_free(hw_dom); + ctrl_domain_free(hw_dom); } } =20 @@ -571,9 +576,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) { int id =3D get_domain_id_from_scope(cpu, r->mon_scope); struct list_head *add_pos =3D NULL; - struct rdt_hw_domain *hw_dom; + struct rdt_hw_mon_domain *hw_dom; struct rdt_domain_hdr *hdr; - struct rdt_domain *d; + struct rdt_mon_domain *d; int err; =20 lockdep_assert_held(&domain_list_lock); @@ -588,7 +593,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) if (hdr) { if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) return; - d =3D container_of(hdr, struct rdt_domain, hdr); + d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 cpumask_set_cpu(cpu, &d->hdr.cpu_mask); return; @@ -604,7 +609,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { - domain_free(hw_dom); + mon_domain_free(hw_dom); return; } =20 @@ -614,7 +619,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); - domain_free(hw_dom); + mon_domain_free(hw_dom); } } =20 @@ -629,9 +634,9 @@ static void domain_add_cpu(int cpu, struct rdt_resource= *r) static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->ctrl_scope); - struct rdt_hw_domain *hw_dom; + struct rdt_hw_ctrl_domain *hw_dom; struct rdt_domain_hdr *hdr; - struct rdt_domain *d; + struct rdt_ctrl_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 @@ -651,8 +656,8 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) return; =20 - d =3D container_of(hdr, struct rdt_domain, hdr); - hw_dom =3D resctrl_to_arch_dom(d); + d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); + hw_dom =3D resctrl_to_arch_ctrl_dom(d); =20 cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); if (cpumask_empty(&d->hdr.cpu_mask)) { @@ -661,12 +666,12 @@ static void domain_remove_cpu_ctrl(int cpu, struct rd= t_resource *r) synchronize_rcu(); =20 /* - * rdt_domain "d" is going to be freed below, so clear + * rdt_ctrl_domain "d" is going to be freed below, so clear * its pointer from pseudo_lock_region struct. */ if (d->plr) d->plr->d =3D NULL; - domain_free(hw_dom); + ctrl_domain_free(hw_dom); =20 return; } @@ -675,9 +680,9 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->mon_scope); - struct rdt_hw_domain *hw_dom; + struct rdt_hw_mon_domain *hw_dom; struct rdt_domain_hdr *hdr; - struct rdt_domain *d; + struct rdt_mon_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 @@ -697,15 +702,15 @@ static void domain_remove_cpu_mon(int cpu, struct rdt= _resource *r) if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) return; =20 - d =3D container_of(hdr, struct rdt_domain, hdr); - hw_dom =3D resctrl_to_arch_dom(d); + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =3D resctrl_to_arch_mon_dom(d); =20 cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); if (cpumask_empty(&d->hdr.cpu_mask)) { resctrl_offline_mon_domain(r, d); list_del_rcu(&d->hdr.list); synchronize_rcu(); - domain_free(hw_dom); + mon_domain_free(hw_dom); =20 return; } diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index 8cc36723f077..3b9383612c35 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -60,7 +60,7 @@ static bool bw_validate(char *buf, unsigned long *data, s= truct rdt_resource *r) } =20 int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d) + struct rdt_ctrl_domain *d) { struct resctrl_staged_config *cfg; u32 closid =3D data->rdtgrp->closid; @@ -139,7 +139,7 @@ static bool cbm_validate(char *buf, u32 *data, struct r= dt_resource *r) * resource type. */ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d) + struct rdt_ctrl_domain *d) { struct rdtgroup *rdtgrp =3D data->rdtgrp; struct resctrl_staged_config *cfg; @@ -208,8 +208,8 @@ static int parse_line(char *line, struct resctrl_schema= *s, struct resctrl_staged_config *cfg; struct rdt_resource *r =3D s->res; struct rdt_parse_data data; + struct rdt_ctrl_domain *d; char *dom =3D NULL, *id; - struct rdt_domain *d; unsigned long dom_id; =20 /* Walking r->domains, ensure it can't race with cpuhp */ @@ -272,11 +272,11 @@ static u32 get_config_index(u32 closid, enum resctrl_= conf_type type) } } =20 -int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d, +int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type t, u32 cfg_val) { + struct rdt_hw_ctrl_domain *hw_dom =3D resctrl_to_arch_ctrl_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(d); u32 idx =3D get_config_index(closid, t); struct msr_param msr_param; =20 @@ -297,17 +297,17 @@ int resctrl_arch_update_one(struct rdt_resource *r, s= truct rdt_domain *d, int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) { struct resctrl_staged_config *cfg; - struct rdt_hw_domain *hw_dom; + struct rdt_hw_ctrl_domain *hw_dom; struct msr_param msr_param; + struct rdt_ctrl_domain *d; enum resctrl_conf_type t; - struct rdt_domain *d; u32 idx; =20 /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); =20 list_for_each_entry(d, &r->ctrl_domains, hdr.list) { - hw_dom =3D resctrl_to_arch_dom(d); + hw_dom =3D resctrl_to_arch_ctrl_dom(d); msr_param.res =3D NULL; for (t =3D 0; t < CDP_NUM_TYPES; t++) { cfg =3D &hw_dom->d_resctrl.staged_config[t]; @@ -430,10 +430,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_fi= le *of, return ret ?: nbytes; } =20 -u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, +u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type type) { - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(d); + struct rdt_hw_ctrl_domain *hw_dom =3D resctrl_to_arch_ctrl_dom(d); u32 idx =3D get_config_index(closid, type); =20 return hw_dom->ctrl_val[idx]; @@ -442,7 +442,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, str= uct rdt_domain *d, static void show_doms(struct seq_file *s, struct resctrl_schema *schema, i= nt closid) { struct rdt_resource *r =3D schema->res; - struct rdt_domain *dom; + struct rdt_ctrl_domain *dom; bool sep =3D false; u32 ctrl_val; =20 @@ -514,7 +514,7 @@ static int smp_mon_event_count(void *arg) } =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, - struct rdt_domain *d, struct rdtgroup *rdtgrp, + struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, int evtid, int first) { int cpu; @@ -557,11 +557,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) { struct kernfs_open_file *of =3D m->private; struct rdt_domain_hdr *hdr; + struct rdt_mon_domain *d; u32 resid, evtid, domid; struct rdtgroup *rdtgrp; struct rdt_resource *r; union mon_data_bits md; - struct rdt_domain *d; struct rmid_read rr; int ret =3D 0; =20 @@ -582,7 +582,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret =3D -ENOENT; goto out; } - d =3D container_of(hdr, struct rdt_domain, hdr); + d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 mon_event_read(&rr, r, d, rdtgrp, evtid, false); =20 diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 82a44de8136f..89d7e6fcbaa1 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -209,7 +209,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id = eventid, u64 *val) return 0; } =20 -static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_= dom, +static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain = *hw_dom, u32 rmid, enum resctrl_event_id eventid) { @@ -228,11 +228,11 @@ static struct arch_mbm_state *get_arch_mbm_state(stru= ct rdt_hw_domain *hw_dom, return NULL; } =20 -void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, +void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, u32 unused, u32 rmid, enum resctrl_event_id eventid) { - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(d); + struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); struct arch_mbm_state *am; =20 am =3D get_arch_mbm_state(hw_dom, rmid, eventid); @@ -248,9 +248,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, st= ruct rdt_domain *d, * Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain= *d) +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d) { - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(d); + struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); =20 if (is_mbm_total_enabled()) memset(hw_dom->arch_mbm_total, 0, @@ -269,12 +269,12 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_m= sr, unsigned int width) return chunks >> shift; } =20 -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, u32 unused, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *ignored) { + struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); - struct rdt_hw_domain *hw_dom =3D resctrl_to_arch_dom(d); struct arch_mbm_state *am; u64 msr_val, chunks; int ret; @@ -320,7 +320,7 @@ static void limbo_release_entry(struct rmid_entry *entr= y) * decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo(struct rdt_domain *d, bool force_free) +void __check_limbo(struct rdt_mon_domain *d, bool force_free) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); @@ -378,7 +378,7 @@ void __check_limbo(struct rdt_domain *d, bool force_fre= e) resctrl_arch_mon_ctx_free(r, QOS_L3_OCCUP_EVENT_ID, arch_mon_ctx); } =20 -bool has_busy_rmid(struct rdt_domain *d) +bool has_busy_rmid(struct rdt_mon_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); =20 @@ -479,7 +479,7 @@ int alloc_rmid(u32 closid) static void add_rmid_to_limbo(struct rmid_entry *entry) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; - struct rdt_domain *d; + struct rdt_mon_domain *d; u32 idx; =20 lockdep_assert_held(&rdtgroup_mutex); @@ -531,7 +531,7 @@ void free_rmid(u32 closid, u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } =20 -static struct mbm_state *get_mbm_state(struct rdt_domain *d, u32 closid, +static struct mbm_state *get_mbm_state(struct rdt_mon_domain *d, u32 closi= d, u32 rmid, enum resctrl_event_id evtid) { u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); @@ -667,12 +667,12 @@ void mon_event_count(void *info) * throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidt= h. */ -static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mb= m) +static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *do= m_mbm) { u32 closid, rmid, cur_msr_val, new_msr_val; struct mbm_state *pmbm_data, *cmbm_data; + struct rdt_ctrl_domain *dom_mba; struct rdt_resource *r_mba; - struct rdt_domain *dom_mba; u32 cur_bw, user_bw, idx; struct list_head *head; struct rdtgroup *entry; @@ -733,7 +733,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_domain *dom_mbm) resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val); } =20 -static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, +static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, u32 closid, u32 rmid) { struct rmid_read rr; @@ -791,12 +791,12 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_domain *d, void cqm_handle_limbo(struct work_struct *work) { unsigned long delay =3D msecs_to_jiffies(CQM_LIMBOCHECK_INTERVAL); - struct rdt_domain *d; + struct rdt_mon_domain *d; =20 cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 - d =3D container_of(work, struct rdt_domain, cqm_limbo.work); + d =3D container_of(work, struct rdt_mon_domain, cqm_limbo.work); =20 __check_limbo(d, false); =20 @@ -819,7 +819,7 @@ void cqm_handle_limbo(struct work_struct *work) * @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_m= s, +void cqm_setup_limbo_handler(struct rdt_mon_domain *dom, unsigned long del= ay_ms, int exclude_cpu) { unsigned long delay =3D msecs_to_jiffies(delay_ms); @@ -836,9 +836,9 @@ void mbm_handle_overflow(struct work_struct *work) { unsigned long delay =3D msecs_to_jiffies(MBM_OVERFLOW_INTERVAL); struct rdtgroup *prgrp, *crgrp; + struct rdt_mon_domain *d; struct list_head *head; struct rdt_resource *r; - struct rdt_domain *d; =20 cpus_read_lock(); mutex_lock(&rdtgroup_mutex); @@ -851,7 +851,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; =20 r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; - d =3D container_of(work, struct rdt_domain, mbm_over.work); + d =3D container_of(work, struct rdt_mon_domain, mbm_over.work); =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { mbm_update(r, d, prgrp->closid, prgrp->mon.rmid); @@ -885,7 +885,7 @@ void mbm_handle_overflow(struct work_struct *work) * @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long dela= y_ms, +void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long = delay_ms, int exclude_cpu) { unsigned long delay =3D msecs_to_jiffies(delay_ms); diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index bdcf95f561d4..70f0069b87d8 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -809,7 +809,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp) * Return: true if @cbm overlaps with pseudo-locked region on @d, false * otherwise. */ -bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned lo= ng cbm) +bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_ctrl_domain *d, unsign= ed long cbm) { unsigned int cbm_len; unsigned long cbm_b; @@ -836,11 +836,11 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_d= omain *d, unsigned long cbm * if it is not possible to test due to memory allocation issue, * false otherwise. */ -bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d) +bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_ctrl_domain *d) { + struct rdt_ctrl_domain *d_i; cpumask_var_t cpu_with_psl; struct rdt_resource *r; - struct rdt_domain *d_i; bool ret =3D false; =20 /* Walking r->domains, ensure it can't race with cpuhp */ diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 17d4610eecf5..eb3bbfa96d5a 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -92,8 +92,8 @@ void rdt_last_cmd_printf(const char *fmt, ...) =20 void rdt_staged_configs_clear(void) { + struct rdt_ctrl_domain *dom; struct rdt_resource *r; - struct rdt_domain *dom; =20 lockdep_assert_held(&rdtgroup_mutex); =20 @@ -1012,7 +1012,7 @@ static int rdt_bit_usage_show(struct kernfs_open_file= *of, unsigned long sw_shareable =3D 0, hw_shareable =3D 0; unsigned long exclusive =3D 0, pseudo_locked =3D 0; struct rdt_resource *r =3D s->res; - struct rdt_domain *dom; + struct rdt_ctrl_domain *dom; int i, hwb, swb, excl, psl; enum rdtgrp_mode mode; bool sep =3D false; @@ -1243,7 +1243,7 @@ static int rdt_has_sparse_bitmasks_show(struct kernfs= _open_file *of, * * Return: false if CBM does not overlap, true if it does. */ -static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_dom= ain *d, +static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_ctr= l_domain *d, unsigned long cbm, int closid, enum resctrl_conf_type type, bool exclusive) { @@ -1298,7 +1298,7 @@ static bool __rdtgroup_cbm_overlaps(struct rdt_resour= ce *r, struct rdt_domain *d * * Return: true if CBM overlap detected, false if there is no overlap */ -bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_domain *d, +bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domai= n *d, unsigned long cbm, int closid, bool exclusive) { enum resctrl_conf_type peer_type =3D resctrl_peer_type(s->conf_type); @@ -1329,10 +1329,10 @@ bool rdtgroup_cbm_overlaps(struct resctrl_schema *s= , struct rdt_domain *d, static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp) { int closid =3D rdtgrp->closid; + struct rdt_ctrl_domain *d; struct resctrl_schema *s; struct rdt_resource *r; bool has_cache =3D false; - struct rdt_domain *d; u32 ctrl; =20 /* Walking r->domains, ensure it can't race with cpuhp */ @@ -1448,7 +1448,7 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open= _file *of, * bitmap functions work correctly. */ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, - struct rdt_domain *d, unsigned long cbm) + struct rdt_ctrl_domain *d, unsigned long cbm) { unsigned int size =3D 0; struct cacheinfo *ci; @@ -1476,9 +1476,9 @@ static int rdtgroup_size_show(struct kernfs_open_file= *of, { struct resctrl_schema *schema; enum resctrl_conf_type type; + struct rdt_ctrl_domain *d; struct rdtgroup *rdtgrp; struct rdt_resource *r; - struct rdt_domain *d; unsigned int size; int ret =3D 0; u32 closid; @@ -1590,7 +1590,7 @@ static void mon_event_config_read(void *info) mon_info->mon_config =3D msrval & MAX_EVT_CONFIG_BITS; } =20 -static void mondata_config_read(struct rdt_domain *d, struct mon_config_in= fo *mon_info) +static void mondata_config_read(struct rdt_mon_domain *d, struct mon_confi= g_info *mon_info) { smp_call_function_any(&d->hdr.cpu_mask, mon_event_config_read, mon_info, = 1); } @@ -1598,7 +1598,7 @@ static void mondata_config_read(struct rdt_domain *d,= struct mon_config_info *mo static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32= evtid) { struct mon_config_info mon_info =3D {0}; - struct rdt_domain *dom; + struct rdt_mon_domain *dom; bool sep =3D false; =20 cpus_read_lock(); @@ -1657,7 +1657,7 @@ static void mon_event_config_write(void *info) } =20 static void mbm_config_write_domain(struct rdt_resource *r, - struct rdt_domain *d, u32 evtid, u32 val) + struct rdt_mon_domain *d, u32 evtid, u32 val) { struct mon_config_info mon_info =3D {0}; =20 @@ -1698,7 +1698,7 @@ static int mon_config_write(struct rdt_resource *r, c= har *tok, u32 evtid) struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); char *dom_str =3D NULL, *id_str; unsigned long dom_id, val; - struct rdt_domain *d; + struct rdt_mon_domain *d; =20 /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); @@ -2257,9 +2257,9 @@ static inline bool is_mba_linear(void) static int set_cache_qos_cfg(int level, bool enable) { void (*update)(void *arg); + struct rdt_ctrl_domain *d; struct rdt_resource *r_l; cpumask_var_t cpu_mask; - struct rdt_domain *d; int cpu; =20 /* Walking r->domains, ensure it can't race with cpuhp */ @@ -2309,7 +2309,7 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *= r) l3_qos_cfg_update(&hw_res->cdp_enabled); } =20 -static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domai= n *d) +static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_ctrl_= domain *d) { u32 num_closid =3D resctrl_arch_get_num_closid(r); int cpu =3D cpumask_any(&d->hdr.cpu_mask); @@ -2327,7 +2327,7 @@ static int mba_sc_domain_allocate(struct rdt_resource= *r, struct rdt_domain *d) } =20 static void mba_sc_domain_destroy(struct rdt_resource *r, - struct rdt_domain *d) + struct rdt_ctrl_domain *d) { kfree(d->mbps_val); d->mbps_val =3D NULL; @@ -2353,7 +2353,7 @@ static int set_mba_sc(bool mba_sc) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl; u32 num_closid =3D resctrl_arch_get_num_closid(r); - struct rdt_domain *d; + struct rdt_ctrl_domain *d; int i; =20 if (!supports_mba_mbps() || mba_sc =3D=3D is_mba_sc(r)) @@ -2625,7 +2625,7 @@ static int rdt_get_tree(struct fs_context *fc) { struct rdt_fs_context *ctx =3D rdt_fc2context(fc); unsigned long flags =3D RFTYPE_CTRL_BASE; - struct rdt_domain *dom; + struct rdt_mon_domain *dom; struct rdt_resource *r; int ret; =20 @@ -2810,9 +2810,9 @@ static int rdt_init_fs_context(struct fs_context *fc) static int reset_all_ctrls(struct rdt_resource *r) { struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); - struct rdt_hw_domain *hw_dom; + struct rdt_hw_ctrl_domain *hw_dom; struct msr_param msr_param; - struct rdt_domain *d; + struct rdt_ctrl_domain *d; int i; =20 /* Walking r->domains, ensure it can't race with cpuhp */ @@ -2828,7 +2828,7 @@ static int reset_all_ctrls(struct rdt_resource *r) * from each domain to update the MSRs below. */ list_for_each_entry(d, &r->ctrl_domains, hdr.list) { - hw_dom =3D resctrl_to_arch_dom(d); + hw_dom =3D resctrl_to_arch_ctrl_dom(d); =20 for (i =3D 0; i < hw_res->num_closid; i++) hw_dom->ctrl_val[i] =3D r->default_ctrl; @@ -3021,7 +3021,7 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rdt= _resource *r, } =20 static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, - struct rdt_domain *d, + struct rdt_mon_domain *d, struct rdt_resource *r, struct rdtgroup *prgrp) { union mon_data_bits priv; @@ -3070,7 +3070,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, * and "monitor" groups with given domain id. */ static void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, - struct rdt_domain *d) + struct rdt_mon_domain *d) { struct kernfs_node *parent_kn; struct rdtgroup *prgrp, *crgrp; @@ -3092,7 +3092,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_= node *parent_kn, struct rdt_resource *r, struct rdtgroup *prgrp) { - struct rdt_domain *dom; + struct rdt_mon_domain *dom; int ret; =20 /* Walking r->domains, ensure it can't race with cpuhp */ @@ -3197,7 +3197,7 @@ static u32 cbm_ensure_valid(u32 _val, struct rdt_reso= urce *r) * Set the RDT domain up to start off with all usable allocations. That is, * all shareable and unused bits. All-zero CBM is invalid. */ -static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_sche= ma *s, +static int __init_one_rdt_domain(struct rdt_ctrl_domain *d, struct resctrl= _schema *s, u32 closid) { enum resctrl_conf_type peer_type =3D resctrl_peer_type(s->conf_type); @@ -3277,7 +3277,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d= , struct resctrl_schema *s, */ static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid) { - struct rdt_domain *d; + struct rdt_ctrl_domain *d; int ret; =20 list_for_each_entry(d, &s->res->ctrl_domains, hdr.list) { @@ -3293,7 +3293,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s= , u32 closid) static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid) { struct resctrl_staged_config *cfg; - struct rdt_domain *d; + struct rdt_ctrl_domain *d; =20 list_for_each_entry(d, &r->ctrl_domains, hdr.list) { if (is_mba_sc(r)) { @@ -3919,14 +3919,14 @@ static void __init rdtgroup_setup_default(void) mutex_unlock(&rdtgroup_mutex); } =20 -static void domain_destroy_mon_state(struct rdt_domain *d) +static void domain_destroy_mon_state(struct rdt_mon_domain *d) { bitmap_free(d->rmid_busy_llc); kfree(d->mbm_total); kfree(d->mbm_local); } =20 -void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_domain= *d) +void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d) { mutex_lock(&rdtgroup_mutex); =20 @@ -3936,7 +3936,7 @@ void resctrl_offline_ctrl_domain(struct rdt_resource = *r, struct rdt_domain *d) mutex_unlock(&rdtgroup_mutex); } =20 -void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain = *d) +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_dom= ain *d) { mutex_lock(&rdtgroup_mutex); =20 @@ -3967,7 +3967,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_domain *d) mutex_unlock(&rdtgroup_mutex); } =20 -static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domai= n *d) +static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize; @@ -3998,7 +3998,7 @@ static int domain_setup_mon_state(struct rdt_resource= *r, struct rdt_domain *d) return 0; } =20 -int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_domain *= d) +int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d) { int err =3D 0; =20 @@ -4014,7 +4014,7 @@ int resctrl_online_ctrl_domain(struct rdt_resource *r= , struct rdt_domain *d) return err; } =20 -int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain *d) +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domai= n *d) { int err; =20 @@ -4069,8 +4069,8 @@ static void clear_childcpus(struct rdtgroup *r, unsig= ned int cpu) void resctrl_offline_cpu(unsigned int cpu) { struct rdt_resource *l3 =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + struct rdt_mon_domain *d; struct rdtgroup *rdtgrp; - struct rdt_domain *d; =20 mutex_lock(&rdtgroup_mutex); list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) { --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 837BB1A00CE for ; Thu, 27 Jun 2024 20:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520753; cv=none; b=BIKhrjbSmGUasmNC5xhiixj+7lsTXGnl8W4J8Izm1tkE3fQ5Ycxu1Kv+gbvv0iHQk8PyJANGe4oIavXIUrCWfNvGYC29+2Aq4tsk7qLFuKOD1O0zO1rq7jRr7+sUBdrdDKAMvUkP/X9ZElzhwDNL0Adt6Wer7VSbO4OJhp9mOro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520753; c=relaxed/simple; bh=SH3mTIpDj2uEXUy+GY0B7A3UVMKQH25ecx2M84QmrdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WjeWdzCPol5wB40jpie4NjVvGkWREvXfCLIn0EpSHivNaqaGiutFIgNYQIbGi2wi8KVnhY4fysThNXaenQ2ZarXFQQx8Zjk0g5cNFnGj8HuhwIJJJs+IiyO/eDFWI7KIa1IfdVp2oaUY/aWtBMAKdqrKLNpvTJKy4FqdwkPkSf8= 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=VM/Fq2Gh; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VM/Fq2Gh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520752; x=1751056752; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SH3mTIpDj2uEXUy+GY0B7A3UVMKQH25ecx2M84QmrdU=; b=VM/Fq2GhlV3ZTUXiim72nVqJTtYrU/Mu5kMHTNMGKjTR6vILNCybn6La MaAHTZ9DXLP8IU0QqspWTvn8ETF45pSUZaw1uDrgjGAEmvcZl2YlmkzVi KveHS/RqWev9uIPHkdEwjMx94v9s+bduHie2+Mo1RQD8hD6pSxDOGE3fJ RTaij56Qid2gEOPSk8OtyeCe6OAFDprKpO1JDeJSaBhMd/xtIMa6rQDma mc5OKk1OLCCqAoa3PgNqIyS8hBOmJjuf8Z9o9t5USSMCNDpENpsQMfSRE mbA4VYK+icFjr057UcgxjSXFXCUswaE/cwv5FDoPiYqGbJKFTzeXrG4eE w==; X-CSE-ConnectionGUID: rcVk7zT3TLiqGzY6Oi1oUg== X-CSE-MsgGUID: SS0DmevMRfSgC5emP9B8Zw== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809770" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809770" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:08 -0700 X-CSE-ConnectionGUID: YACErSB9SQGOkU8NeO0PFQ== X-CSE-MsgGUID: 1Qx2OtIgRbixf/44m7qS8Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052891" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:07 -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 v22 05/18] x86/resctrl: Add node-scope to the options for feature scope Date: Thu, 27 Jun 2024 13:38:43 -0700 Message-ID: <20240627203856.66628-6-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" Currently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches. Add RESCTRL_L3_NODE as a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are divided between nodes that share an L3 cache. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index aa2c22a8e37b..64b6ad1b22a1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -176,6 +176,7 @@ struct resctrl_schema; enum resctrl_scope { RESCTRL_L2_CACHE =3D 2, RESCTRL_L3_CACHE =3D 3, + RESCTRL_L3_NODE, }; =20 /** diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index b4f2be776408..b86c525d0620 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -510,6 +510,8 @@ static int get_domain_id_from_scope(int cpu, enum resct= rl_scope scope) case RESCTRL_L2_CACHE: case RESCTRL_L3_CACHE: return get_cpu_cacheinfo_id(cpu, scope); + case RESCTRL_L3_NODE: + return cpu_to_node(cpu); default: break; } --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 B38FA1A00DA for ; Thu, 27 Jun 2024 20:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520753; cv=none; b=FEy8mpLzaVLZygQco77ZfgiTxhURgL/TRYoqfNZcdpdv/kDD51M0jyIfT7jj8Cy2NX/j8hY/ItP6zqnWFQsJHuzP+Sj58lCuFAcVpfOLkq9HRqYqy84gKMNi5Xb5Vjt8ZlymCXy/qWLK4u5wu3uoRKJmzPhQErWojyY/RJkWLwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520753; c=relaxed/simple; bh=54aAjGHfJFB+5C049SN63jcrfNlJ0fB0KsefxbFiJvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2LIrGEy/NEjj0LhgyuZuj6yvdPIFjfQAC46KDsVF1EiV9WR+l7yXd4rXY/mjT1Su/AjTqmHLECgzIGdyAy0hDYs0L3OqeGF58Xrc9zUsJ3uG89VzwVmvYA5vn+TE6fHUtcTOnrIC6ktSrz02wOlQLGC7k5DUlq+eERG2xUlAaM= 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=d8xdFAwT; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="d8xdFAwT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520752; x=1751056752; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=54aAjGHfJFB+5C049SN63jcrfNlJ0fB0KsefxbFiJvc=; b=d8xdFAwTYgP8I0hTSGduY2T4tSvn8GN+6pBNjdaApCLNwA6kWmZktWdF Vt3Qrwco9ZWzkbw7z6hHx/nQh52mIcC3fQcsoEUVWOYw0M6vZ/uD3IX6O /4LQWOLCtuykjau0GrvTMYUrAE70azCHo+Yi32QKDSoxcz+1GyvfD+bF4 1A+g0SSNTvheHZ06htEqXd/dJDowhJibvlfJD3uBIy0mrwYJTcRXoAVBn BSUH6d+hk190yMOkrNfNCvajONaxQmMlnsOQ38S+wl9Cedv2qvKBMnEm4 DFzu2QFWn2Yb3o99XNzVob9aRI96pICJMsRBvL0rTQEvwBOn0gImyzrah Q==; X-CSE-ConnectionGUID: tnkLP+SHRy+ch+KBWtJ0ww== X-CSE-MsgGUID: EWz5LaS+Q+a0jVlSqtzxxA== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809777" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809777" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:08 -0700 X-CSE-ConnectionGUID: fr9eK1OeRAy9sa6hTCbzFA== X-CSE-MsgGUID: BJ55+xNgQEqg7LtEU7f5yg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052894" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:08 -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 v22 06/18] x86/resctrl: Introduce snc_nodes_per_l3_cache Date: Thu, 27 Jun 2024 13:38:44 -0700 Message-ID: <20240627203856.66628-7-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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. RMID sharing mode divides the physical RMIDs evenly between SNC nodes but uses a logical RMID in the IA32_PQR_ASSOC MSR. For example a system with 200 physical RMIDs (as enumerated by CPUID leaf 0xF) that has two SNC nodes per L3 cache instance would have 100 logical RMIDs available for Linux to use. A task running on SNC node 0 with RMID 5 would accumulate LLC occupancy and MBM bandwidth data in physical RMID 5. Another task using RMID 5, but running on SNC node 1 would accumulate data in physical RMID 105. Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation. Add a static global to arch/x86/kernel/cpu/resctrl/monitor.c to indicate how many SNC domains share an L3 cache instance. Initialize this to "1". Runtime detection of SNC mode will adjust this value. Update all places to take appropriate action when SNC mode is enabled: 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) Add a function to convert from logical RMID values (assigned to tasks and loaded into the IA32_PQR_ASSOC MSR on context switch) to physical RMID values to load into IA32_QM_EVTSEL MSR when reading counters on each SNC node. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/monitor.c | 56 ++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 89d7e6fcbaa1..ff4e74594a19 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -97,6 +97,8 @@ unsigned int resctrl_rmid_realloc_limit; =20 #define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5)) =20 +static int snc_nodes_per_l3_cache =3D 1; + /* * The correction factor table is documented in Documentation/arch/x86/res= ctrl.rst. * If rmid > rmid threshold, MBM total and local values should be multipli= ed @@ -185,7 +187,43 @@ static inline struct rmid_entry *__rmid_entry(u32 idx) return entry; } =20 -static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) +/* + * When Sub-NUMA Cluster (SNC) mode is not enabled (as indicated by + * "snc_nodes_per_l3_cache =3D=3D 1") no translation of the RMID value is + * needed. The physical RMID is the same as the logical RMID. + * + * On a platform with SNC mode enabled, Linux enables RMID sharing mode + * via MSR 0xCA0 (see the "RMID Sharing Mode" section in the "Intel + * Resource Director Technology Architecture Specification" for a full + * description of RMID sharing mode). + * + * In RMID sharing mode there are fewer "logical RMID" values available + * to accumulate data ("physical RMIDs" are divided evenly between SNC + * nodes that share an L3 cache). Linux creates an rdt_mon_domain for + * each SNC node. + * + * The value loaded into IA32_PQR_ASSOC is the "logical RMID". + * + * Data is collected independently on each SNC node and can be retrieved + * using the "physical RMID" value computed by this function and loaded + * into IA32_QM_EVTSEL. @cpu can be any CPU in the SNC node. + * + * The scope of the IA32_QM_EVTSEL and IA32_QM_CTR MSRs is at the L3 + * cache. So a "physical RMID" may be read from any CPU that shares + * the L3 cache with the desired SNC node, not just from a CPU in + * the specific SNC node. + */ +static int logical_rmid_to_physical_rmid(int cpu, int lrmid) +{ + struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + + if (snc_nodes_per_l3_cache =3D=3D 1) + return lrmid; + + return lrmid + (cpu_to_node(cpu) % snc_nodes_per_l3_cache) * r->num_rmid; +} + +static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 = *val) { u64 msr_val; =20 @@ -197,7 +235,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, prmid); rdmsrl(MSR_IA32_QM_CTR, msr_val); =20 if (msr_val & RMID_VAL_ERROR) @@ -233,14 +271,17 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, = struct rdt_mon_domain *d, enum resctrl_event_id eventid) { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + int cpu =3D cpumask_any(&d->hdr.cpu_mask); struct arch_mbm_state *am; + u32 prmid; =20 am =3D get_arch_mbm_state(hw_dom, rmid, eventid); if (am) { memset(am, 0, sizeof(*am)); =20 + prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); /* Record any initial, non-zero count value. */ - __rmid_read(rmid, eventid, &am->prev_msr); + __rmid_read_phys(prmid, eventid, &am->prev_msr); } } =20 @@ -275,8 +316,10 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, str= uct rdt_mon_domain *d, { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); + int cpu =3D cpumask_any(&d->hdr.cpu_mask); struct arch_mbm_state *am; u64 msr_val, chunks; + u32 prmid; int ret; =20 resctrl_arch_rmid_read_context_check(); @@ -284,7 +327,8 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_mon_domain *d, if (!cpumask_test_cpu(smp_processor_id(), &d->hdr.cpu_mask)) return -EINVAL; =20 - ret =3D __rmid_read(rmid, eventid, &msr_val); + prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); + ret =3D __rmid_read_phys(prmid, eventid, &msr_val); if (ret) return ret; =20 @@ -1022,8 +1066,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource = *r) int ret; =20 resctrl_rmid_realloc_limit =3D boot_cpu_data.x86_cache_size * 1024; - hw_res->mon_scale =3D boot_cpu_data.x86_cache_occ_scale; - r->num_rmid =3D boot_cpu_data.x86_cache_max_rmid + 1; + hw_res->mon_scale =3D boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l= 3_cache; + r->num_rmid =3D (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3= _cache; hw_res->mbm_width =3D MBM_CNTR_WIDTH_BASE; =20 if (mbm_offset > 0 && mbm_offset <=3D MBM_CNTR_WIDTH_OFFSET_MAX) --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 8456D1A0723 for ; Thu, 27 Jun 2024 20:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520755; cv=none; b=Tn5PI3nDoLdMNrj1HzPsYMsOBD86Nsn9IpFZ7pWJk3HgeN/GlcW6Iq8X+8+A/0xpeNcCbZaEkkFeeA/sGPOSzIdAEj73VM5WkLKOAMmWQ6wuPC2loRrByR9X0LA8yapRye3anB2MQSLpoKSPbGItuAhuY4Bsn+nT5sqFHZwXDKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520755; c=relaxed/simple; bh=UvIfSDsXNSkpE8HdTCsK3woWdj4Uetp4PIewuXeA0AQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jY2xEM6kfOJ3ykKPdaK89TRzKFPkt5UqyYyQ0E/8zgQIzddgcG2p5MEYPAAlVsAU5B+CKsubMmmqXXdtJx9dz4M+40opRMrBoNnb1dKOeu5NHw7zK3BLJpvT5Zf0/dH6y1CClX6ECWur6pIZuazPX/vLoPyppZZFC5XiwuEeSiI= 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=MM0b9fXl; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MM0b9fXl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520754; x=1751056754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UvIfSDsXNSkpE8HdTCsK3woWdj4Uetp4PIewuXeA0AQ=; b=MM0b9fXl4Wyy03UJ9tApXZ/4vdH8t/IxC8cBz2c4nRE8LYTKw6eYo6B5 W3qEmmzGaAhVT2korvoxT//775lqFpWx0RuTIlwdO9+x0aRD+1CKyDzxI EyCp9wm4GnhHtZ4yVIN33tcvBgTpZE6oMMtojElzL1oS2xQU/fs0+iHHS Iq1PFkDOoJ6Gs1Gwfsp4LhDLeAlds5twOyJ0CwCERaWpMEVC7olY+WfCX 5dAdoPuuO9A6dgkvOAW5xwb/O8OIiayqLBszgdHrbY/fOFkoucWL8jczb STWqmA5RjJwU1yB8OjeJTpL0uFWQfnOro5M/7YfZ7QZO6ytksRK4R9lzQ g==; X-CSE-ConnectionGUID: IWBcReTtRRuc7UNAxX5lNQ== X-CSE-MsgGUID: ViGsxMLPQLyFv72kAcNKJg== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809784" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809784" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -0700 X-CSE-ConnectionGUID: 76ui0RJpR62Z8Ju+ASi7UQ== X-CSE-MsgGUID: iELuY1vsTc+35ynjI3UCbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052897" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:08 -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 v22 07/18] x86/resctrl: Block use of mba_MBps mount option on Sub-NUMA Cluster (SNC) systems Date: Thu, 27 Jun 2024 13:38:45 -0700 Message-ID: <20240627203856.66628-8-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" When SNC is enabled there is a mismatch between the MBA control function which operates at L3 cache scope and the MBM monitor functions which measure memory bandwidth on each SNC node. Block use of the mba_MBps when scopes for MBA/MBM do not match. Improve user diagnostics by adding invalfc() message when mba_MBps is not supported. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index eb3bbfa96d5a..d3b0fa958266 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2335,14 +2335,18 @@ static void mba_sc_domain_destroy(struct rdt_resour= ce *r, =20 /* * MBA software controller is supported only if - * MBM is supported and MBA is in linear scale. + * MBM is supported and MBA is in linear scale, + * and the MBM monitor scope is the same as MBA + * control scope. */ static bool supports_mba_mbps(void) { + struct rdt_resource *rmbm =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resct= rl; struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl; =20 return (is_mbm_local_enabled() && - r->alloc_capable && is_mba_linear()); + r->alloc_capable && is_mba_linear() && + r->ctrl_scope =3D=3D rmbm->mon_scope); } =20 /* @@ -2750,6 +2754,7 @@ static int rdt_parse_param(struct fs_context *fc, str= uct fs_parameter *param) { struct rdt_fs_context *ctx =3D rdt_fc2context(fc); struct fs_parse_result result; + const char *msg; int opt; =20 opt =3D fs_parse(fc, rdt_fs_parameters, param, &result); @@ -2764,8 +2769,9 @@ static int rdt_parse_param(struct fs_context *fc, str= uct fs_parameter *param) ctx->enable_cdpl2 =3D true; return 0; case Opt_mba_mbps: + msg =3D "mba_MBps requires local MBM and linear scale MBA at L3 scope"; if (!supports_mba_mbps()) - return -EINVAL; + return invalfc(fc, msg); ctx->enable_mba_mbps =3D true; return 0; case Opt_debug: --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 E9A221A073B for ; Thu, 27 Jun 2024 20:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520755; cv=none; b=cHGwDytAGp9iSy6pS63tdNeqD16/j53NJDfePc6QHofvbzDtNe7kwoXUTDuy+mXRuiSKhpHLyLoPIkbfMw+6GbxDq9nhQRNidnBdXAYkJNIMrwEnBIT9eN02lDXq8fVLuslG/y671YhTCEEq1VsxxMHRIpl4xfmdE1SIvSiVemg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520755; c=relaxed/simple; bh=Furc6t8HDNdOr+Vqn7XeiivEWdd2/Lb1p01l7EFsXv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AahttoXigsGlfSQUmhwy5wMn6mtgZt3We5IkJ0O66EP9KBX3haFT8qRRj23t7yWe1gBIZvNQ+PsqAomybOYp0VmHsyOkaTk8VO2U4cmLP0sjzi/R8So3Pue/ECtVMvu5QaAdN3sR5lDS7j2ERiT/7B5V1sG1Y/0wBspYFcu/yIY= 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=SfxRHnSj; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SfxRHnSj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520754; x=1751056754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Furc6t8HDNdOr+Vqn7XeiivEWdd2/Lb1p01l7EFsXv4=; b=SfxRHnSjet1ep0H1epD/9fnLckiuZARoctoOBuivZwj9meb5k5SCqBS8 ru8V179CV7TPBTNADAMzZc3MO1n3kQ70NbnlgqD4TRDxkAjjLeSarmK3t ENogEbkgexzTQOOtpJzrb3bETHW1JjXGk98Zm3rbrdHs8DVWYZsAh0gKb g6CF0QlQmzI4VjH9PS0zkMcgDVDkKaT2VCbhF8SZPta3NpJcWeVzQpULE V0ps+iK8lsQUVb3emEc/wANB/ijJlx5wLA4HLBC9kLo9IH9p6hrkYA9Dw xLst4U5/xNcORN5JXj9804yqDpUOmCjutnkbIFO/lwcsBAAmDV6b/0qJv w==; X-CSE-ConnectionGUID: 0l7wnPdETv2dezGYMc8VRw== X-CSE-MsgGUID: u0iQbqdUT4qev4eaAbBFDA== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809793" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809793" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -0700 X-CSE-ConnectionGUID: hzY1UXKhSWyfCPVuooQosQ== X-CSE-MsgGUID: r5ORxQCJRnmlA3qdmq66lg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052900" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:08 -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 v22 08/18] x86/resctrl: Prepare for new Sub-NUMA Cluster (SNC) monitor files Date: Thu, 27 Jun 2024 13:38:46 -0700 Message-ID: <20240627203856.66628-9-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When SNC is enabled monitoring data is collected at the SNC node granularity, but must be reported at L3-cache granularity for backwards compatibility in addition to reporting at the node level. Add a "ci" field to the rdt_mon_domain structure to save the cache information about the enclosing L3 cache for the domain. This provides: 1) The cache id which is needed to compose the name of the legacy monitoring directory, and to determine which domains should be summed to provide L3-scoped data. 2) The shared_cpu_map which is needed to determine which CPUs can be used to read the RMID counters with the MSR interface. This is the first step to an eventual goal of monitor reporting files like this (for a system with two SNC nodes per L3): $ cd /sys/fs/resctrl/mon_data $ tree mon_L3_00 mon_L3_00 <- 00 here is L3 cache id =E2=94=9C=E2=94=80=E2=94=80 llc_occupancy \ These files provide legacy su= pport =E2=94=9C=E2=94=80=E2=94=80 mbm_local_bytes > for non-SNC aware monitor a= pps =E2=94=9C=E2=94=80=E2=94=80 mbm_total_bytes / that expect data at L3 cach= e level =E2=94=9C=E2=94=80=E2=94=80 mon_sub_L3_00 <- 00 here is SNC node id =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 llc_occupancy \ These f= iles are finer grained =E2=94=82=C2=A0=C2=A0 =E2=94=9C=E2=94=80=E2=94=80 mbm_local_bytes > data = from each SNC node =E2=94=82=C2=A0=C2=A0 =E2=94=94=E2=94=80=E2=94=80 mbm_total_bytes / =E2=94=94=E2=94=80=E2=94=80 mon_sub_L3_01 =E2=94=9C=E2=94=80=E2=94=80 llc_occupancy \ =E2=94=9C=E2=94=80=E2=94=80 mbm_local_bytes > As above, but for node = 1. =E2=94=94=E2=94=80=E2=94=80 mbm_total_bytes / Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 3 +++ arch/x86/kernel/cpu/resctrl/core.c | 7 ++++++- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1 - arch/x86/kernel/cpu/resctrl/rdtgroup.c | 1 - 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 64b6ad1b22a1..b0875b99e811 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -2,6 +2,7 @@ #ifndef _RESCTRL_H #define _RESCTRL_H =20 +#include #include #include #include @@ -96,6 +97,7 @@ struct rdt_ctrl_domain { /** * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types + * @ci: cache info for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth @@ -106,6 +108,7 @@ struct rdt_ctrl_domain { */ struct rdt_mon_domain { struct rdt_domain_hdr hdr; + struct cacheinfo *ci; unsigned long *rmid_busy_llc; struct mbm_state *mbm_total; struct mbm_state *mbm_local; diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index b86c525d0620..95ef8fe3cb50 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -19,7 +19,6 @@ #include #include #include -#include #include =20 #include @@ -608,6 +607,12 @@ static void domain_add_cpu_mon(int cpu, struct rdt_res= ource *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_MON_DOMAIN; + d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); + if (!d->ci) { + pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); + mon_domain_free(hw_dom); + return; + } cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index 70f0069b87d8..e69489d48625 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -11,7 +11,6 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 -#include #include #include #include diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index d3b0fa958266..70d41a8fd788 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -12,7 +12,6 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 -#include #include #include #include --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 02DE91A08DA for ; Thu, 27 Jun 2024 20:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520757; cv=none; b=uXa43lYuY9i+48/5hWQZD/OUzTpTbOwGyquIXQaL7eVAoFqRZGy63+hiq49Uy74lOasHE66uIxkTM1c0h6jpCB6L2OreY37Gd9Xz30dzqS9Qx3Wwgv0D7gyaYzIYtJNxooV7KXcS8aqDbF0Ng6SxiNOJ+j9zRuCfAqqSoLxAIBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520757; c=relaxed/simple; bh=E1OjYH+VizyHNJwzEabDMPXh9xsy+KGJwiXkqbLxewI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DVkstvFm+U5Mafk+7znnz2noQ2n+FgigNDns9aCPdSZlqr03KOP13kuZUY3M20ZBFyrz30H84vF+NaNQRqSI1q5JFVkkkL5gATMgwgUoWfHihFtpvjcMpTG4CGP/zfbeiGYjcBNXVbX+NiUR/6tI+C6Jt9VaBQwbCVbeNXa9Wro= 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=bcueBF2q; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bcueBF2q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520755; x=1751056755; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E1OjYH+VizyHNJwzEabDMPXh9xsy+KGJwiXkqbLxewI=; b=bcueBF2qaPQB6Rto6F3lmY1R38WN6D0u61BoCnT4d4cSkgJzBHEtMISK WYelBHog0EU07h/Wd+lYtsJYUFTXUOYihI5LKRCiBZaatY5M/yym+lqM+ 4xsws4pgkqOuvpvE/p0aIVjHTjD2Z0NakW/TNiqdtFxHURn9A5ljdep/h 8l29mNkPBuT+4REoYqyZWEAVf60DDMxinA0OnBqK+DOdUNqBpyUMNZ/Kt wQCNSBQykjT1BzqZrNk/d1pvJYRnCiXx01URLOzMeVF5CBagU8EucRmB+ SrA/HdVDd92n+UBz9BMzgEA2P4GZNcw0xp8wyxA4LKyZTDZs4lTN3pkvx A==; X-CSE-ConnectionGUID: WopXxEVER72OCrn4wngYmA== X-CSE-MsgGUID: HQN7kBLORUu/QgERlF/a4w== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809799" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809799" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -0700 X-CSE-ConnectionGUID: WmsZMNx3R/e6qo1fMUCE+g== X-CSE-MsgGUID: fMl+pyJ8RHGYAvKokkMCIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052903" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -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 v22 09/18] x86/resctrl: Add a new field to struct rmid_read for summation of domains Date: Thu, 27 Jun 2024 13:38:47 -0700 Message-ID: <20240627203856.66628-10-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" When a user reads a monitor file rdtgroup_mondata_show() calls mon_event_read() to package up all the required details into an rmid_read structure which is passed across the smp_call*() infrastructure to code that will read data from hardware and return the value (or error status) in the rmid_read structure. Sub-NUMA Cluster (SNC) mode adds files with new semantics. These require the smp_call-ed code to sum event data from all domains that share an L3 cache. Add a pointer to the L3 "cacheinfo" structure to struct rmid_read for the data collection routines to use to pick the domains to be summed. Initialize all on-stack declarations of struct rmid_read: rdtgroup_mondata_show() mbm_update() mkdir_mondata_subdir() to ensure that garbage values from the stack are not passed down to other functions. Remove redundant rr->val =3D 0; from mon_event_read() and rr.first =3D fals= e; from mbm_update() since the rmid_read structure is cleared by compiler. Reinette suggested that the rmid_read structure has become complex enough to warrant documentation of each of its fields and provided the kerneldoc documentation for struct rmid_read. Co-developed-by: Reinette Chatre Signed-off-by: Reinette Chatre Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 19 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 3 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 3 +-- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 135190e0711c..681b5bdcd2f9 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -144,12 +144,31 @@ union mon_data_bits { } u; }; =20 +/** + * struct rmid_read - Data passed across smp_call*() to read event count. + * @rgrp: Resource group for which the counter is being read. If it is a = parent + * resource group then its event count is summed with the count from all + * its child resource groups. + * @r: Resource describing the properties of the event being read. + * @d: Domain that the counter should be read from. If NULL then sum all + * domains in @r sharing L3 @ci.id + * @evtid: Which monitor event to read. + * @first: Initialize MBM counter when true. + * @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing d= omains. + * @err: Error encountered when reading counter. + * @val: Returned value of event counter. If @rgrp is a parent resource = group, + * @val includes the sum of event counts from its child resource groups. + * If @d is NULL, @val includes the sum of all domains in @r sharing @c= i.id, + * (summed across child resource groups if @rgrp is a parent resource g= roup). + * @arch_mon_ctx: Hardware monitor allocated for this read request (MPAM o= nly). + */ struct rmid_read { struct rdtgroup *rgrp; struct rdt_resource *r; struct rdt_mon_domain *d; enum resctrl_event_id evtid; bool first; + struct cacheinfo *ci; int err; u64 val; void *arch_mon_ctx; diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index 3b9383612c35..4d76ff31a9e0 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -529,7 +529,6 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, rr->evtid =3D evtid; rr->r =3D r; rr->d =3D d; - rr->val =3D 0; rr->first =3D first; rr->arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, evtid); if (IS_ERR(rr->arch_mon_ctx)) { @@ -557,12 +556,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) { struct kernfs_open_file *of =3D m->private; struct rdt_domain_hdr *hdr; + struct rmid_read rr =3D {0}; struct rdt_mon_domain *d; u32 resid, evtid, domid; struct rdtgroup *rdtgrp; struct rdt_resource *r; union mon_data_bits md; - struct rmid_read rr; int ret =3D 0; =20 rdtgrp =3D rdtgroup_kn_lock_live(of->kn); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index ff4e74594a19..ca309c93a56b 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -780,9 +780,8 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_mon_domain *dom_mbm) static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, u32 closid, u32 rmid) { - struct rmid_read rr; + struct rmid_read rr =3D {0}; =20 - rr.first =3D false; rr.r =3D r; rr.d =3D d; =20 diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 70d41a8fd788..d0443589cd86 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3029,10 +3029,10 @@ static int mkdir_mondata_subdir(struct kernfs_node = *parent_kn, struct rdt_mon_domain *d, struct rdt_resource *r, struct rdtgroup *prgrp) { + struct rmid_read rr =3D {0}; union mon_data_bits priv; struct kernfs_node *kn; struct mon_evt *mevt; - struct rmid_read rr; char name[32]; int ret; =20 --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 716D91A0B02 for ; Thu, 27 Jun 2024 20:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520757; cv=none; b=h+ei1oPkaFoUG+uDfGXumcGm/Ue78aI5pwVOctQlrrbDd40mMwrd8DW/+HMCSSV3b8ZBmTGgtg06nRoSJAhS7it2ahESS7faBpVtj5j5b2Xlx+GyxdgV3ysHiYfaB1uQBGPvahAnmvFLnlPFcl4RM0Q02YFvuHSmIxyDooLItC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520757; c=relaxed/simple; bh=pRMMuFAo+vgoaQPT6H9NbnUr8oF0p+OxKZvV5KwLCn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ah8K108ANxTo9p1F6j+b3EzxeYq8YCo6E7OBXiYbUczZ1fmFUdR2X6Z9qzKwdUdBfoHuv+Bzhosr60THHWU0eLL8ux/HjpWjPhhw0VAd5I1nGTYhkGWJ0AVWIWjKxek7w8yKUJD2ErBWIJM7M2iRl8rm2bLe9qQddrWhBhp5e1A= 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=OUCWGD2b; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OUCWGD2b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520756; x=1751056756; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pRMMuFAo+vgoaQPT6H9NbnUr8oF0p+OxKZvV5KwLCn4=; b=OUCWGD2bn+ycoAV6CxxAS7J79XwK32hv3XkrUdS64uCArIExdrLMwOhC KUuu1u3ko+xpWHvQ0f1CK/bWmt8FZX3fUUvmc2DECzLkQrCU1hDK8AwuY rd7lAOZJnyjhEBLP/o68JQ8x5MlNexJG6EGDBEL/OR8Eh+TiNzHtsL39K xyZIPBk3fjiejgCTE4vfdAUjxOM+cXNaAJniFfxAcbEj3ukHh66yGGuQ8 ifqLy8iUL/c6ps29xEJvo6lkS57woxeOJq6oAHA7q453XfvYelo4tycpM yFjjrBC5WTVei6uWZ7dv0jwkdXfsOh8kTul9uMl8TeMArm/zHGXksvPhK g==; X-CSE-ConnectionGUID: CwfQRSTERoCDiOFJSe2FGA== X-CSE-MsgGUID: hzKi0keIRziRg1oiMAx/8A== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809807" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809807" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -0700 X-CSE-ConnectionGUID: waKzOfwBTjWeglPIaQTWBw== X-CSE-MsgGUID: caARh1HyT1aqIu2h1Za/ng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052906" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -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 v22 10/18] x86/resctrl: Refactor mkdir_mondata_subdir() with a helper function Date: Thu, 27 Jun 2024 13:38:48 -0700 Message-ID: <20240627203856.66628-11-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" In Sub-NUMA Cluster (SNC) mode Linux must create the monitor files in the original "mon_L3_XX" directories and also in each of the "mon_sub_L3_YY" directories. Refactor mkdir_mondata_subdir() to move the creation of monitoring files into a helper function to avoid the need to duplicate code later. No functional change. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 45 ++++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index d0443589cd86..9c38ddcfe150 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3025,14 +3025,37 @@ static void rmdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, } } =20 +static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain= *d, + struct rdt_resource *r, struct rdtgroup *prgrp) +{ + struct rmid_read rr =3D {0}; + union mon_data_bits priv; + struct mon_evt *mevt; + int ret; + + if (WARN_ON(list_empty(&r->evt_list))) + return -EPERM; + + priv.u.rid =3D r->rid; + priv.u.domid =3D d->hdr.id; + list_for_each_entry(mevt, &r->evt_list, list) { + priv.u.evtid =3D mevt->evtid; + ret =3D mon_addfile(kn, mevt->name, priv.priv); + if (ret) + return ret; + + if (is_mbm_event(mevt->evtid)) + mon_event_read(&rr, r, d, prgrp, mevt->evtid, true); + } + + return 0; +} + static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, struct rdt_mon_domain *d, struct rdt_resource *r, struct rdtgroup *prgrp) { - struct rmid_read rr =3D {0}; - union mon_data_bits priv; struct kernfs_node *kn; - struct mon_evt *mevt; char name[32]; int ret; =20 @@ -3046,22 +3069,10 @@ static int mkdir_mondata_subdir(struct kernfs_node = *parent_kn, if (ret) goto out_destroy; =20 - if (WARN_ON(list_empty(&r->evt_list))) { - ret =3D -EPERM; + ret =3D mon_add_all_files(kn, d, r, prgrp); + if (ret) goto out_destroy; - } =20 - priv.u.rid =3D r->rid; - priv.u.domid =3D d->hdr.id; - list_for_each_entry(mevt, &r->evt_list, list) { - priv.u.evtid =3D mevt->evtid; - ret =3D mon_addfile(kn, mevt->name, priv.priv); - if (ret) - goto out_destroy; - - if (is_mbm_event(mevt->evtid)) - mon_event_read(&rr, r, d, prgrp, mevt->evtid, true); - } kernfs_activate(kn); return 0; =20 --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 E0C851A0B13 for ; Thu, 27 Jun 2024 20:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520757; cv=none; b=orzMrve2Me71CMII7YnZjeLhGUyyUANuGm/x4h9eNZt7K9/vo1lkBVnzMB72Pso4opoqVZdVFgzO/4wMCB8oI54Fz4RnlF2cuun4R1oHv1E9xLmt/B+yrKVIZGBU4QcpdE6VtJFEUKfCi2RfumudwiOZc6RorSNcWQlt28qf63M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520757; c=relaxed/simple; bh=fJdyJmm169ahsAE7AU4WeTiO841LkwbRErK0K/CR60c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XHP9XrsOJbzZ+lsdzNETENF5SAYyf15i/UeqzCX+ifN+crDbuiC6MDGNBkOcSyzHyOyLJheKgBk9O61XXTsouy3CEZBNs3LZRY0KGwK1xj8rXFPg0pcjaEjH4V9eOfXW4eTZ9nES6j2Z0dL8NdbJrNSSkmWD1nr0vXaYI0lYidI= 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=bZOlYAek; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bZOlYAek" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520756; x=1751056756; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fJdyJmm169ahsAE7AU4WeTiO841LkwbRErK0K/CR60c=; b=bZOlYAekppoQEa6hAhfuDR5qoyN0J8a9BEF3PzqC6a7WWh/VeSUFwXm5 MIh3wfFUh8Y1IFVgR7kggRDzws5bdAnvx6wVy0M8kJi/rOFBb7CLzuj30 9OUpEq89cb5NnUwF0NmnwODxdKhSwQQDttyRtgJBjIzfV+UhI/S0ZMPN2 R9/+8XwoX/cyCy2ODqN4QkjCS2nXSvdP+znEMlnU+mCh41eFIOOYw6aF4 kSJfWwe7L95BDOFqedtQ8I2UiVyChbyVHz/C7FHYwtYNpB2oEFRc1oWvP b/+sHIh0unQfxQiL76UNjZkBYPf90d7h8a8NjXF948qeNi9Q76S2BNPij w==; X-CSE-ConnectionGUID: tJn4r/R9RveNUSFSGAKEOg== X-CSE-MsgGUID: 67ddLfWQRDO9fYF0FsT43g== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809814" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809814" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -0700 X-CSE-ConnectionGUID: JpNs+7SFR66Cjb/jD/+CZA== X-CSE-MsgGUID: M1P9tn/2RQ+9+T3tJezhQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052910" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:09 -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 v22 11/18] x86/resctrl: Allocate a new field in union mon_data_bits Date: Thu, 27 Jun 2024 13:38:49 -0700 Message-ID: <20240627203856.66628-12-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" When Sub-NUMA Cluster (SNC) mode is enabled the legacy monitor reporting files must report the sum of the data from all of the SNC nodes that share the L3 cache that is referenced by the monitor file. Resctrl squeezes all the attributes of these files into 32-bits so they can be stored in the "priv" field of struct kernfs_node. Currently only three monitor events are defined by enum resctrl_event_id so reducing it from 8-bits to 7-bits still provides more than enough space to represent all the known event types. But note that this choice was arbitrary. The "rid" field is also far wider than needed for the current number of resource id types. This structure is purely internal to resctrl, no ABI issues with modifying it. Subsequent changes may rearrange the allocation of bits between each of the fields as needed. Give the bit to a new "sum" field that indicates that reading this file must sum across SNC nodes. This bit also indicates that the domid field is the id of an L3 cache (instead of a domain id) to find which domains must be summed. Fix up other issues in the kerneldoc description for mon_data_bits. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/internal.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 681b5bdcd2f9..13d862221f9c 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -127,19 +127,25 @@ struct mon_evt { }; =20 /** - * union mon_data_bits - Monitoring details for each event file + * union mon_data_bits - Monitoring details for each event file. * @priv: Used to store monitoring event data in @u - * as kernfs private data - * @rid: Resource id associated with the event file - * @evtid: Event id associated with the event file - * @domid: The domain to which the event file belongs - * @u: Name of the bit fields struct + * as kernfs private data. + * @u.rid: Resource id associated with the event file. + * @u.evtid: Event id associated with the event file. + * @u.sum: Set when event must be summed across multiple + * domains. + * @u.domid: When @u.sum is zero this is the domain to which + * the event file belongs. When @sum is one this + * is the id of the L3 cache that all domains to be + * summed share. + * @u: Name of the bit fields struct. */ union mon_data_bits { void *priv; struct { unsigned int rid : 10; - enum resctrl_event_id evtid : 8; + enum resctrl_event_id evtid : 7; + unsigned int sum : 1; unsigned int domid : 14; } u; }; --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 5C2D51A2573 for ; Thu, 27 Jun 2024 20:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520759; cv=none; b=Lknbwcuq3L81xfVOeAbfgwfFIDwUGadtcysbq6LMGYkqSLJ71ghoXPqZuyOGbLNEmUkqEjdiGP6bBDlxUAYQT3Oz+Sbvwc3h/BAohYYRIO1LwmAtLIzkY2EgjV2MjBkvP55gzXkJvA+0SN8OgD4gr0qvDKOo1c2guQGww16IstM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520759; c=relaxed/simple; bh=7gwzf/trQEcQpsp3Q62b5pMAB6BI8DFeIhWQ/vV4hOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AKDcQPZO6DQjXqbCWCaJ9l3DY/vR4I0QXympBoewF7gMm01PvK7hNPbKLUYDhcjpXs/BqzxKaUDg25xWnNTe3uxs7CddoCBu+yHiDE2OxX09pO0DfHFpj5pSEe+hTw2c38Gv4Tpaa/WbC+/3qMLrxPsQ502qGTg6By7iwYEcEbI= 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=cV/M2gUB; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cV/M2gUB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520758; x=1751056758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7gwzf/trQEcQpsp3Q62b5pMAB6BI8DFeIhWQ/vV4hOM=; b=cV/M2gUBM6OEbITmsAEKHRbkDJ24UrEQL9lkawjy/Lg0M7oTNzqpT5QL o1ZdyCvFMFjDgSlN+w/0wNDXyn9suqfXax/BomG0KL9VMbsDz3OU+5cRf 5xSW4/N3rKnMRGA9Q/o+0inWcWsVrYoe3AHbN1OpLL700cowuQzdoLLno kxldqYI1r/waKs/cgsSgvnJT1u7KLl57QCKvPLsWSBA5V/TJKIUjcw6/p h+p/yzpKjOzbwFh/A7cj/rmJeQ8O4E1/jhciBQuKhbES9bFsv9AabnG7F Ct20vv+2nm3y11U9MLKPe4UHOD/fNubqdeo+1/GZqcWVJnGbkP0QUvZO4 g==; X-CSE-ConnectionGUID: 88djagKaQPue648rkP4lOQ== X-CSE-MsgGUID: K0pHCU85T5i8DETEmtHWKg== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809821" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809821" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -0700 X-CSE-ConnectionGUID: DF7eNT5fR2Cw5eRCLGviSA== X-CSE-MsgGUID: PT57qZM0QGK+BXaQfjpPYw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052913" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -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 v22 12/18] x86/resctrl: Create Sub-NUMA Cluster (SNC) monitor files Date: Thu, 27 Jun 2024 13:38:50 -0700 Message-ID: <20240627203856.66628-13-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" When SNC mode is enabled, create subdirectories and files to monitor at the SNC node granularity. Legacy behavior is preserved by tagging the monitor files at the L3 granularity with the "sum" attribute. When the user reads these files the kernel will read monitor data from all SNC nodes that share the same L3 cache instance and return the aggregated value to the user. Note that the "domid" field for files that must sum across SNC domains has the L3 cache instance id, while non-summing files use the domain id. The "sum" files do not need to make a call to mon_event_read() to initialize the MBM counters. This will be handled by initializing the individual SNC nodes that share the L3. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 62 +++++++++++++++++++------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 9c38ddcfe150..8502385e389f 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3026,7 +3026,8 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rdt= _resource *r, } =20 static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain= *d, - struct rdt_resource *r, struct rdtgroup *prgrp) + struct rdt_resource *r, struct rdtgroup *prgrp, + bool do_sum) { struct rmid_read rr =3D {0}; union mon_data_bits priv; @@ -3037,14 +3038,15 @@ static int mon_add_all_files(struct kernfs_node *kn= , struct rdt_mon_domain *d, return -EPERM; =20 priv.u.rid =3D r->rid; - priv.u.domid =3D d->hdr.id; + priv.u.domid =3D do_sum ? d->ci->id : d->hdr.id; + priv.u.sum =3D do_sum; list_for_each_entry(mevt, &r->evt_list, list) { priv.u.evtid =3D mevt->evtid; ret =3D mon_addfile(kn, mevt->name, priv.priv); if (ret) return ret; =20 - if (is_mbm_event(mevt->evtid)) + if (!do_sum && is_mbm_event(mevt->evtid)) mon_event_read(&rr, r, d, prgrp, mevt->evtid, true); } =20 @@ -3055,23 +3057,51 @@ static int mkdir_mondata_subdir(struct kernfs_node = *parent_kn, struct rdt_mon_domain *d, struct rdt_resource *r, struct rdtgroup *prgrp) { - struct kernfs_node *kn; + struct kernfs_node *kn, *ckn; char name[32]; - int ret; + bool snc_mode; + int ret =3D 0; =20 - sprintf(name, "mon_%s_%02d", r->name, d->hdr.id); - /* create the directory */ - kn =3D kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp); - if (IS_ERR(kn)) - return PTR_ERR(kn); + lockdep_assert_held(&rdtgroup_mutex); =20 - ret =3D rdtgroup_kn_set_ugid(kn); - if (ret) - goto out_destroy; + snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; + sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); + kn =3D kernfs_find_and_get(parent_kn, name); + if (kn) { + /* + * rdtgroup_mutex will prevent this directory from being + * removed. No need to keep this hold. + */ + kernfs_put(kn); + } else { + kn =3D kernfs_create_dir(parent_kn, name, parent_kn->mode, prgrp); + if (IS_ERR(kn)) + return PTR_ERR(kn); =20 - ret =3D mon_add_all_files(kn, d, r, prgrp); - if (ret) - goto out_destroy; + ret =3D rdtgroup_kn_set_ugid(kn); + if (ret) + goto out_destroy; + ret =3D mon_add_all_files(kn, d, r, prgrp, snc_mode); + if (ret) + goto out_destroy; + } + + if (snc_mode) { + sprintf(name, "mon_sub_%s_%02d", r->name, d->hdr.id); + ckn =3D kernfs_create_dir(kn, name, parent_kn->mode, prgrp); + if (IS_ERR(ckn)) { + ret =3D -EINVAL; + goto out_destroy; + } + + ret =3D rdtgroup_kn_set_ugid(ckn); + if (ret) + goto out_destroy; + + ret =3D mon_add_all_files(ckn, d, r, prgrp, false); + if (ret) + goto out_destroy; + } =20 kernfs_activate(kn); return 0; --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 81AE21A2C11 for ; Thu, 27 Jun 2024 20:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520759; cv=none; b=kqwyFr1rpcR3YKLTSRtMcxfr3Wy5COK5fbLVDlFYQxZK87RzerSJK6aSsC3BQXgfWmgX06VgGgXKOz7fG2viKgW1zTGkJU8taK6/2MkO8catfGSJdo+xSxu60VvVWmPAsJgn8VSfoVmw7yozuaLSVpdEy1AnunAcYk9VrBerkas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520759; c=relaxed/simple; bh=QyDHWOy1sSaunKLVu4tBjbfGSBLpsHu64tRbyDPgVm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ahLhNQhuu3MSrx9r699cQyBJIr4+lMSAABrpUFThKvLdBCjBtkJWmNlTCzGeGf5YfK4hxoSHg1pS6+RcQVKNw5AhXipXI/7+eJCgaCkneA7Kj6T+QSOdFt4ComKmQMlg7RHspAOv3p/UTPxNRt3nHHpXu7FlD3Hfn/2KQH/0BTE= 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=hnLBTJHw; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hnLBTJHw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520758; x=1751056758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QyDHWOy1sSaunKLVu4tBjbfGSBLpsHu64tRbyDPgVm0=; b=hnLBTJHwxZbdwdT5+bV5xRyy+abvlZOETHuIc+ycoGeXKiw42fNJ5dDi Zfn6VBGf0j4xUq2iqZHIKGfj6DKV62J1CXRE/8Scaib1pHPjvatCFJTDx eyRig4a77QlndeRv+UtjMWPmMazPO9g+PaMOvhwiyybQRDoMePugwncYT 4tE6hRy4TyD93DdvJ9dTWvECF5fPu2Pjxki+Zb0dxY4zihGh3OrwLUhhP yqS5S8u5ylpzo3eidmybsufButBXfVIq9mPHtHBXR1n2GU2K4wUgvXk9k ZaYRUijcOAXT2GaJ19HV7psg7Uexc1w/+dMTIKXpcRJysV9hka4q5B+GG g==; X-CSE-ConnectionGUID: BH1F/haySM6ELJCztOqknA== X-CSE-MsgGUID: 7/7CErB3RpqMHffPVSCdxA== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809828" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809828" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -0700 X-CSE-ConnectionGUID: c4TPycXPR3SV8uNzjbTK+g== X-CSE-MsgGUID: y+z1GLdjRLyxadh1DFEDbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052916" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -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 v22 13/18] x86/resctrl: Handle removing directories in Sub-NUMA Cluster (SNC) mode Date: Thu, 27 Jun 2024 13:38:51 -0700 Message-ID: <20240627203856.66628-14-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" In SNC mode there are multiple subdirectories in each L3 level monitor directory (one for each SNC node). If all the CPUs in an SNC node are taken offline, just remove the SNC directory for that node. In non-SNC mode, or when the last SNC node directory is removed, remove the L3 monitor directory. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 8502385e389f..67a8188c6d8f 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3008,20 +3008,46 @@ static int mon_addfile(struct kernfs_node *parent_k= n, const char *name, =20 /* * Remove all subdirectories of mon_data of ctrl_mon groups - * and monitor groups with given domain id. + * and monitor groups for the given domain. + * Remove files and directories containing "sum" of domain data + * when last domain being summed is removed. */ static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, - unsigned int dom_id) + struct rdt_mon_domain *d) { struct rdtgroup *prgrp, *crgrp; + struct kernfs_node *kn; + char subname[32]; + bool snc_mode; char name[32]; =20 + snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; + sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); + if (snc_mode) + sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id); + list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { - sprintf(name, "mon_%s_%02d", r->name, dom_id); - kernfs_remove_by_name(prgrp->mon.mon_data_kn, name); + kn =3D kernfs_find_and_get(prgrp->mon.mon_data_kn, name); + if (!kn) + continue; + kernfs_put(kn); + + if (kn->dir.subdirs <=3D 1) + kernfs_remove(kn); + else + kernfs_remove_by_name(kn, subname); =20 - list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list) - kernfs_remove_by_name(crgrp->mon.mon_data_kn, name); + list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list) { + kn =3D kernfs_find_and_get(crgrp->mon.mon_data_kn, name); + if (!kn) + continue; + kernfs_put(kn); + + if (kn->dir.subdirs <=3D 1) + kernfs_remove(kn); + else + kernfs_remove_by_name(kn, subname); + } } } =20 @@ -3991,7 +4017,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d * per domain monitor data directories. */ if (resctrl_mounted && resctrl_arch_mon_capable()) - rmdir_mondata_subdir_allrdtgrp(r, d->hdr.id); + rmdir_mondata_subdir_allrdtgrp(r, d); =20 if (is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 C7AA61A2C29 for ; Thu, 27 Jun 2024 20:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520760; cv=none; b=a+4MuIEqnQKaTF6svXfaIPundMYgwJnlCTO7gGeCQPtWD9zx8C4ZdbSJdq4udXlNrE8NirtaoHrJx9VE0X7JCnP2+8JWyjrU8jlcSavYcMTyo2iocMYuilGw82ASdRD2KXbM1N65ixNFYfV18Jag6R3F9b86hQkTIsQlTYd4a2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520760; c=relaxed/simple; bh=ZAP1w0D+klf/vYnoc7RYPNBvlo727Y55tNDt7G/JNeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ixniudm0Et1OTMq7EmH6c947v+YGBa4RojbKU+F064PMPybwpTgSg20+aBk9gzs3DcD5+Ro0FAAG183RsneFOOh3kWLNYKjrYb8MIz1f01VUOVEk5fq0Am1c8E3ey0VMfZe/uFwbTa5kEiKo0SlN3Z0e0knTThAK6R2+9t7Kzcw= 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=IwBWOVWZ; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IwBWOVWZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520758; x=1751056758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZAP1w0D+klf/vYnoc7RYPNBvlo727Y55tNDt7G/JNeg=; b=IwBWOVWZL+7mhnd3jyCqRK27UsUlYyT2wGWa+A1YY0fxckdZk/Rm40Vk QuDVxjrBDcSxdEJIc+iEo2nBscFmmeo/OvF9cs76VY1orI907xL2qRapf XBbXpSFdcCve5t/mfGqNxWYDYs6NFuUMqrJJBStuun1vssNSjq1jvOQHZ G+l6TOWdJpcN4bWPbDrmNQsAAmaLaoWnOUAkU6O6dQezHhlTrkoeFfNNu pWQ2YvyyzEEM+cKhNIbeeJC2V4UHlWe568wk1iKzvW8wBYBoELvGiorhe +PVLtJYjlznQxiV3h+K970OOVvot8Sp66gduil+QvEudob9mRd035eIuq Q==; X-CSE-ConnectionGUID: Ib3dXl36RnmLZdel0978qg== X-CSE-MsgGUID: lG+TORGgQVCNI+MciDMhEA== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809835" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809835" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -0700 X-CSE-ConnectionGUID: aWI2Nt6FTo2CgaJuDWV+kw== X-CSE-MsgGUID: 95lagScQQj+ZzPttSy9B/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052919" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -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 v22 14/18] x86/resctrl: Fill out rmid_read structure for smp_call*() to read a counter Date: Thu, 27 Jun 2024 13:38:52 -0700 Message-ID: <20240627203856.66628-15-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" mon_event_read() fills out most fields of the struct rmid_read that is passed via an smp_call*() function to a CPU that is part of the correct domain to read the monitor counters. With Sub-NUMA Cluster (SNC) mode there are now two cases to handle: 1) Reading a file that returns a value for a single domain. + Choose the CPU to execute from the domain cpu_mask 2) Reading a file that must sum across domains sharing an L3 cache instance. + Indicate to called code that a sum is needed by passing a NULL rdt_mon_domain pointer. + Choose the CPU from the L3 shared_cpu_map. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 40 ++++++++++++++++++----- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 13d862221f9c..16982d1baf99 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -632,7 +632,7 @@ void mon_event_count(void *info); int rdtgroup_mondata_show(struct seq_file *m, void *arg); void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, - int evtid, int first); + cpumask_t *cpumask, int evtid, int first); void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long delay_ms, int exclude_cpu); diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index 4d76ff31a9e0..50fa1fe9a073 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -515,7 +515,7 @@ static int smp_mon_event_count(void *arg) =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, - int evtid, int first) + cpumask_t *cpumask, int evtid, int first) { int cpu; =20 @@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, return; } =20 - cpu =3D cpumask_any_housekeeping(&d->hdr.cpu_mask, RESCTRL_PICK_ANY_CPU); + cpu =3D cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU); =20 /* * cpumask_any_housekeeping() prefers housekeeping CPUs, but @@ -545,7 +545,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, * counters on some platforms if its called in IRQ context. */ if (tick_nohz_full_cpu(cpu)) - smp_call_function_any(&d->hdr.cpu_mask, mon_event_count, rr, 1); + smp_call_function_any(cpumask, mon_event_count, rr, 1); else smp_call_on_cpu(cpu, smp_mon_event_count, rr, false); =20 @@ -574,16 +574,40 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) resid =3D md.u.rid; domid =3D md.u.domid; evtid =3D md.u.evtid; - r =3D &rdt_resources_all[resid].r_resctrl; - hdr =3D rdt_find_domain(&r->mon_domains, domid, NULL); - if (!hdr || WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) { + + if (md.u.sum) { + /* + * This file requires summing across all domains that share + * the L3 cache id that was provided in the "domid" field of the + * mon_data_bits union. Search all domains in the resource for + * one that matches this cache id. + */ + list_for_each_entry(d, &r->mon_domains, hdr.list) { + if (d->ci->id =3D=3D domid) { + rr.ci =3D d->ci; + mon_event_read(&rr, r, NULL, rdtgrp, + &d->ci->shared_cpu_map, evtid, false); + goto checkresult; + } + } ret =3D -ENOENT; goto out; + } else { + /* + * This file provides data from a single domain. Search + * the resource to find the domain with "domid". + */ + hdr =3D rdt_find_domain(&r->mon_domains, domid, NULL); + if (!hdr || WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) { + ret =3D -ENOENT; + goto out; + } + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); } - d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 - mon_event_read(&rr, r, d, rdtgrp, evtid, false); +checkresult: =20 if (rr.err =3D=3D -EIO) seq_puts(m, "Error\n"); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 67a8188c6d8f..cd0229f7c30e 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3073,7 +3073,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_mon_domain *d, return ret; =20 if (!do_sum && is_mbm_event(mevt->evtid)) - mon_event_read(&rr, r, d, prgrp, mevt->evtid, true); + mon_event_read(&rr, r, d, prgrp, &d->hdr.cpu_mask, mevt->evtid, true); } =20 return 0; --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 AE6C81A2FDB for ; Thu, 27 Jun 2024 20:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520761; cv=none; b=qFZUAfuHyMQPwIT93zNI1KJ5twlbdsDeeGR6rQlMd93pwzO8vZJoXKqyNaYUi4NmWl+RmbWzuSruQBH4C80scmYEYjkxsr89fuFSsqALyx5HrxwRqYqmdrrO9tjoBbehrwFyr9iv+oq1OnF66JPClXpKM3cns9GwymcCh8IAxCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520761; c=relaxed/simple; bh=zdAqMUk9VHyJiHDiw90uSeeCYe6sqc1oUAH918cf/OY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g4F2VVR4ZzvNbguLqyafVeM6RdZ9Gcyj/ZbAYG9WDNwh0QMWJtERwk0/7nxXMqyMJhNZxPrbd6wH52Mmundt+WvnZSXMnmWymvnGCQpcv5o1Lstu+uxwhEZsbDCvpcX5960Lij6W3pg0gO/BmDPz2m8OX40Gduj6Pk1LbA9519M= 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=GQ9IeppV; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GQ9IeppV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520760; x=1751056760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zdAqMUk9VHyJiHDiw90uSeeCYe6sqc1oUAH918cf/OY=; b=GQ9IeppVzkOWtH96/5dMMGTj7KpAfj6kHkZYC4KLDGVAYtXHfV8T+hOM r1yWNP2KLQdYN/PSC0zG3+HzHF3I++c6kEPR+RA4JnpMjYEv0mV51Nf3B 6OVYhoi8nC9QhMg3fOJI6YzKtUA7PVcmiZOjwTC71XooXzg4jamWKOpbn xVpqk3jZl9K3ttTjfSDeNoInZ4oG9Nm29tCx+s6nDIPTip4A58r2qdXBq ov5sE5TyvvGMn3hqCzt9uih3i5vriK24kMLezk7sHsJ0q0HWFBSZGyz6q uhdJh1hnloHEDzgiNvdNL6hlpGRd+dZI92hPgJOI2jyK5t/TUo+XaS3zg A==; X-CSE-ConnectionGUID: trdc3e7LSxSLwp5IEu4ByQ== X-CSE-MsgGUID: zl4YqEzBQMiNPG37AG5UKg== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809842" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809842" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -0700 X-CSE-ConnectionGUID: Yg5CSV4LQA24iyx2sIpRuw== X-CSE-MsgGUID: pNxhQzCMQDuhEI4i9PSWEA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052922" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:10 -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 v22 15/18] x86/resctrl: Make __mon_event_count() handle sum domains Date: Thu, 27 Jun 2024 13:38:53 -0700 Message-ID: <20240627203856.66628-16-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" Legacy resctrl monitor files must provide the sum of event values across all Sub-NUMA Cluster (SNC) domains that share an L3 cache instance. There are now two cases: 1) A specific domain is provided in struct rmid_read This is either a non-SNC system, or the request is to read data from just one SNC node. 2) Domain pointer is NULL. In this case the cacheinfo field in struct rmid_read indicates that all SNC nodes that share that L3 cache instance should have the event read and return the sum of all values. Update the CPU sanity check. The existing check that an event is read from a CPU in the requested domain still applies when reading a single domain. But when summing across domains a more relaxed check that the current CPU is in the scope of the L3 cache instance is appropriate since the MSRs to read events are scoped at L3 cache level. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/monitor.c | 51 ++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index ca309c93a56b..ca486d00541e 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -324,9 +324,6 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_mon_domain *d, =20 resctrl_arch_rmid_read_context_check(); =20 - if (!cpumask_test_cpu(smp_processor_id(), &d->hdr.cpu_mask)) - return -EINVAL; - prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); ret =3D __rmid_read_phys(prmid, eventid, &msr_val); if (ret) @@ -592,7 +589,10 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_= domain *d, u32 closid, =20 static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) { + int cpu =3D smp_processor_id(); + struct rdt_mon_domain *d; struct mbm_state *m; + int err, ret; u64 tval =3D 0; =20 if (rr->first) { @@ -603,14 +603,47 @@ static int __mon_event_count(u32 closid, u32 rmid, st= ruct rmid_read *rr) return 0; } =20 - rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, rr->evtid, - &tval, rr->arch_mon_ctx); - if (rr->err) - return rr->err; + if (rr->d) { + /* Reading a single domain, must be on a CPU in that domain. */ + if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) + return -EINVAL; + rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, + rr->evtid, &tval, rr->arch_mon_ctx); + if (rr->err) + return rr->err; =20 - rr->val +=3D tval; + rr->val +=3D tval; =20 - return 0; + return 0; + } + + /* Summing domains that share a cache, must be on a CPU for that cache. */ + if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) + return -EINVAL; + + /* + * Legacy files must report the sum of an event across all + * domains that share the same L3 cache instance. + * Report success if a read from any domain succeeds, -EINVAL + * (translated to "Unavailable" for user space) if reading from + * all domains fail for any reason. + */ + ret =3D -EINVAL; + list_for_each_entry(d, &rr->r->mon_domains, hdr.list) { + if (d->ci->id !=3D rr->ci->id) + continue; + err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, + rr->evtid, &tval, rr->arch_mon_ctx); + if (!err) { + rr->val +=3D tval; + ret =3D 0; + } + } + + if (ret) + rr->err =3D ret; + + return ret; } =20 /* --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 ADE8F1A2FDA for ; Thu, 27 Jun 2024 20:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520761; cv=none; b=EHCZNs2CnKfD+fJnJqR20va3w/3skeCTv1wpYiuug7fDFv8QCzmRRqL3iRpj6yXCWvgc47PoKAfSyP7AN646Ee6caulv9LCcB/JudzlAoJ7ZMEBgZYSbLzlxgzLE4Os2n5XWSMOXpbNMrFAZLMjbAHftWOBn8xeLwr29HnZp7ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520761; c=relaxed/simple; bh=CfUd13hXUBp211uAieRQ2S7KiADlmpT8AQ2V+AKCddE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p9/rgJOija6o8+AdkfsKuzvIqBx9HCuJPrsqqNZQX32K3A90EJ1BJdt+mOpDdeksleGWUGyKjij3Q9bxAweagtbQqCto75b/1D5zpLZ9UsEagD21KFDM4ZWxBBcWFzjoU3iRzmX7Gf9IEYNuQy4Y9MMLh+xsoBQJ9S7fvVqiqLc= 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=abTwcZ6g; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="abTwcZ6g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520760; x=1751056760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CfUd13hXUBp211uAieRQ2S7KiADlmpT8AQ2V+AKCddE=; b=abTwcZ6g/hBgVl+JzmqDGekBFurEdxSfB7wgGsBWnKorCj13oYFvOieA xxrYcGTgQFumb289S26MiaS9KHlMaxjWSbVnBFEHkMtxe+LEOQbhGFzTQ Gwkzl5NINQx5hJTKOYVcRIkwLO5PvbzoBL2H5Tocl41LcJKymcoUjhUf+ aUBaYBx7W84H3KlHvkzXI30/yb6O++BdX8M501gOH9+OCEsMe7o8S0Bt7 Z8rDlKPZzqaFGnIIMgjxWPeJF6RDFe5KF7I0H444h+LRp1VK+1/K8YijR vzFcVa6f1EDdnV2DUmyEd8RGIOoosy8J0Nb6G4Xfjev3RTsNor2z/TTPh g==; X-CSE-ConnectionGUID: d6pMchmGTdWvndO3cBnFPA== X-CSE-MsgGUID: PUhDufdoQyqATdVZjnFEBQ== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809850" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809850" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -0700 X-CSE-ConnectionGUID: LpXVDhnbSqe60lUXsGgMgA== X-CSE-MsgGUID: gpfejimFSqq420VVan0R4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052925" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -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 v22 16/18] x86/resctrl: Enable shared RMID mode on Sub-NUMA Cluster (SNC) systems Date: Thu, 27 Jun 2024 13:38:54 -0700 Message-ID: <20240627203856.66628-17-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" Hardware has two RMID configuration options for SNC systems. The default mode divides RMID counters between SNC nodes. E.g. with 200 RMIDs and two SNC nodes per L3 cache RMIDs 0..99 are used on node 0, and 100..199 on node 1. This isn't compatible with Linux resctrl usage. On this example system a process using RMID 5 would only update monitor counters while running on SNC node 0. The other mode is "RMID Sharing Mode". This is enabled by clearing bit 0 of the RMID_SNC_CONFIG (0xCA0) model specific register. In this mode the number of logical RMIDs is the number of physical RMIDs (from CPUID leaf 0xF) divided by the number of SNC nodes per L3 cache instance. A process can use the same RMID across different SNC nodes. See the "Intel Resource Director Technology Architecture Specification" for additional details. When SNC is enabled, update the MSR when a monitor domain is marked online. Technically this is overkill. It only needs to be done once per L3 cache instance rather than per SNC domain. But there is no harm in doing it more than once, and this is not in a critical path. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 2 ++ arch/x86/kernel/cpu/resctrl/monitor.c | 26 ++++++++++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index e022e6eb766c..3cb8dd6311c3 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1164,6 +1164,7 @@ #define MSR_IA32_QM_CTR 0xc8e #define MSR_IA32_PQR_ASSOC 0xc8f #define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0 #define MSR_IA32_L2_CBM_BASE 0xd10 #define MSR_IA32_MBA_THRTL_BASE 0xd50 =20 diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 16982d1baf99..955999aecfca 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -534,6 +534,8 @@ static inline bool resctrl_arch_get_cdp_enabled(enum re= sctrl_res_level l) =20 int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable); =20 +void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain = *d); + /* * To return the common struct rdt_resource, which is contained in struct * rdt_hw_resource, walk the resctrl member of struct rdt_hw_resource. diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 95ef8fe3cb50..1930fce9dfe9 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -615,6 +615,8 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) } cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 + arch_mon_domain_online(r, d); + if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { mon_domain_free(hw_dom); return; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index ca486d00541e..2d9b0bad678d 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -1090,6 +1090,32 @@ static void l3_mon_evt_init(struct rdt_resource *r) list_add_tail(&mbm_local_event.list, &r->evt_list); } =20 +/* + * The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1 + * which indicates that RMIDs are configured in legacy mode. + * This mode is incompatible with Linux resctrl semantics + * as RMIDs are partitioned between SNC nodes, which requires + * a user to know which RMID is allocated to a task. + * Clearing bit 0 reconfigures the RMID counters for use + * in RMID sharing mode. This mode is better for Linux. + * The RMID space is divided between all SNC nodes with the + * RMIDs renumbered to start from zero in each node when + * counting operations from tasks. Code to read the counters + * must adjust RMID counter numbers based on SNC node. See + * logical_rmid_to_physical_rmid() for code that does this. + */ +void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain = *d) +{ + u64 val; + + if (snc_nodes_per_l3_cache =3D=3D 1) + return; + + rdmsrl(MSR_RMID_SNC_CONFIG, val); + val &=3D ~BIT_ULL(0); + wrmsrl(MSR_RMID_SNC_CONFIG, val); +} + int __init rdt_get_mon_l3_config(struct rdt_resource *r) { unsigned int mbm_offset =3D boot_cpu_data.x86_cache_mbm_width_offset; --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 791F01A38E1 for ; Thu, 27 Jun 2024 20:39:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520762; cv=none; b=F4xQ6F81UzL0U4P8NEjZubmtK47WSmuRg9hPza9XxOrnQw+VZ8B0743DDKBXymKP6U+vAvtGd6IC0MQy1XmeQA7SMRhx9sJ174XpdO0ocD0030+FJsKeZBqkcfV8lUxPBnjDPVoFRRRCAyLDdvE50oivennrnVIAmA9AKEtEi38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520762; c=relaxed/simple; bh=vM+3tzSSnqnmtLQ7I5Kq1E3nWSgcu98rwL7vm2afEB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qkI/D7FumC7zP2TvvuP6D9c9tzzld7WsCBCL0pvzNxVP/NTnKDarPpMo14PkvLrWl2yRDeTjntFJOaM5c2EzpDx1mXEgcXey+9+cyA2c1kVlOp05vlc8GBxYX0/bYewquGdw84SXMjtWaS3qpuAbg59jU6vA8KrVkHWMcKKbmGQ= 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=Q8BcyJ6Q; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Q8BcyJ6Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520761; x=1751056761; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vM+3tzSSnqnmtLQ7I5Kq1E3nWSgcu98rwL7vm2afEB0=; b=Q8BcyJ6QblBpY6tSnZGKwLPm2R3zR+9szIlmEHUBgTUUcW2T5T5GtuWm ztiMPgxAmfhIx153pMXed8EtTh6DNz5cLstrAOEgWvCHNk+O0HZCC49T0 ANsZRlDbp7XVYM48J81+NGGbILOTDd7gDUkJ4ZXMjAPeAK8K2XFoHWf/C BQRSE2QUbwfDlMeeFcfNHD6ZJfJZYcX11UzkOQG2Qa2MtYQWLh2KHi1ng ASpTLg8H1zkGC/VdCWqj3qjGZ6XndeTyGRfBnwCtF/zlOD7pHU4xPHOGX gzfRnqMpDEItLK3WhOdHeQDlNDhlOk+pFr8sEaLtPjOGNxH4m04wSjaSr g==; X-CSE-ConnectionGUID: qzcXzUyhT9uxR/GOCtrWfQ== X-CSE-MsgGUID: Ki8MrG79RuGjrZRnH9L6jw== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809857" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809857" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -0700 X-CSE-ConnectionGUID: wS085McKTgSLLW5jSA4S2Q== X-CSE-MsgGUID: +DQpOxQdQdCBL60aMhTX0Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052929" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -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 v22 17/18] x86/resctrl: Sub-NUMA Cluster (SNC) detection Date: Thu, 27 Jun 2024 13:38:55 -0700 Message-ID: <20240627203856.66628-18-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 of 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 Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/monitor.c | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 2d9b0bad678d..00e5c0e5424f 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. */ =20 +#define pr_fmt(fmt) "resctrl: " fmt + #include #include #include @@ -1116,6 +1118,68 @@ void arch_mon_domain_online(struct rdt_resource *r, = struct rdt_mon_domain *d) wrmsrl(MSR_RMID_SNC_CONFIG, val); } =20 +/* CPU models that support MSR_RMID_SNC_CONFIG */ +static const struct x86_cpu_id snc_cpu_ids[] __initconst =3D { + 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 runni= ng + * in Sub-NUMA Cluster (SNC) mode. Infer the state by comparing the + * number of 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=3DN parameter. That distorts the ratio of SNC nod= es + * 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 =3D get_cpu_cacheinfo_level(0, RESCTRL_L3_CACHE); + const cpumask_t *node0_cpumask; + int cpus_per_node, cpus_per_l3; + int ret; + + if (!x86_match_cpu(snc_cpu_ids) || !ci) + return 1; + + cpus_read_lock(); + if (num_online_cpus() !=3D num_present_cpus()) + pr_warn("Some CPUs offline, SNC detection may be incorrect\n"); + cpus_read_unlock(); + + node0_cpumask =3D cpumask_of_node(cpu_to_node(0)); + + cpus_per_node =3D cpumask_weight(node0_cpumask); + cpus_per_l3 =3D cpumask_weight(&ci->shared_cpu_map); + + if (!cpus_per_node || !cpus_per_l3) + return 1; + + ret =3D cpus_per_l3 / cpus_per_node; + + /* 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", r= et); + rdt_resources_all[RDT_RESOURCE_L3].r_resctrl.mon_scope =3D RESCTRL_L3_NO= DE; + break; + default: + pr_warn("Ignore improbable SNC node count %d\n", ret); + ret =3D 1; + break; + } + + return ret; +} + int __init rdt_get_mon_l3_config(struct rdt_resource *r) { unsigned int mbm_offset =3D boot_cpu_data.x86_cache_mbm_width_offset; @@ -1123,6 +1187,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource = *r) unsigned int threshold; int ret; =20 + snc_nodes_per_l3_cache =3D snc_get_config(); + resctrl_rmid_realloc_limit =3D boot_cpu_data.x86_cache_size * 1024; hw_res->mon_scale =3D boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l= 3_cache; r->num_rmid =3D (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3= _cache; --=20 2.45.2 From nobody Thu Dec 18 18:03:50 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 CE1CB1A3BCA for ; Thu, 27 Jun 2024 20:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520763; cv=none; b=OjHaDkh1jbsmqrwoQvKbS71yQ415X0QWEjEPTHHog6I1A1Hp8mgiuNnPeHcQnIy4vZHv6n7yxFrirse6iFkQFz0SHGDUjv+VSYxq4FBz6obYwNTo1HdpDEx30CrZCdKYB9VZtlu0jEdRTJd2isoaAbPzDyAhRvNKQ4ML3jChzrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719520763; c=relaxed/simple; bh=2l7f6lDOELlYeE6YGD7wOuDWjXUX38xsa3dzLbcLFzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HdUP3rh91kKBcG3iyYZd1rkVLsirdjC291uzSkk+4oPIvV2y/CQM9HeplqSqo8w4fOmDwbXvZHLWj82OKCgvkErQz6DaPdRVXHBAPw5q0BDC9D4rlay2htlHiacarlv+ab1aOxOeyE/lBmujY+7dxEQAXP/Y7qSByUk30OSlIAM= 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=k9yAs5X2; arc=none smtp.client-ip=198.175.65.16 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="k9yAs5X2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719520762; x=1751056762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2l7f6lDOELlYeE6YGD7wOuDWjXUX38xsa3dzLbcLFzk=; b=k9yAs5X2eh01sziA+KmInFULhnXfkT5KHP0Mqv1f0ur9GBavXFmGd3Pt ne+C2jHjyzXamMTbiA7x4cnYhoc1kIViuhgzFrRN979V4jNHP8WNpb4Y7 5MHanKMR7bYmCz5QeMG8cyjM6d0tjpjZx0IgjVOz5hkV5Wx0uMTR+1xl4 sY3xeDnOLxyhEo5ukYK+XGrHpUs1dtmseU0WoWpK3kAu+QhhbswG1j0S+ f2mEW0NBmxJf5xzFY5P/trq+PVZxZ2xl9vzyMQZMRmn33NtLJSuhM+zBw V8fph0DjDTFAg62PJNsYx0W8GeobhPpKVBbso6uXi5jI3NCMOli9aYPQn g==; X-CSE-ConnectionGUID: dDvL/R1eRsSSESy6pVAuHg== X-CSE-MsgGUID: 5RsZYIRmTjmNt8ivKIuo4Q== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="16809865" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="16809865" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:12 -0700 X-CSE-ConnectionGUID: yQOysJ53SZiHJid5yxJCbA== X-CSE-MsgGUID: P+X4VGxoRjGh8DmBrBCsFQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="82052933" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 13:39:11 -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 v22 18/18] x86/resctrl: Update documentation with Sub-NUMA cluster changes Date: Thu, 27 Jun 2024 13:38:56 -0700 Message-ID: <20240627203856.66628-19-tony.luck@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627203856.66628-1-tony.luck@intel.com> References: <20240627203856.66628-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: quoted-printable Content-Type: text/plain; charset="utf-8" With Sub-NUMA Cluster (SNC) mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Backwards compatibility is maintained by providing files in the mon_L3_XX directories that sum event counts for all SNC nodes sharing an L3 cache. New files provide per-SNC node event counts. Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- Documentation/arch/x86/resctrl.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/re= sctrl.rst index 627e23869bca..a824affd741d 100644 --- a/Documentation/arch/x86/resctrl.rst +++ b/Documentation/arch/x86/resctrl.rst @@ -375,6 +375,10 @@ When monitoring is enabled all MON groups will also co= ntain: all tasks in the group. In CTRL_MON groups these files provide the sum for all tasks in the CTRL_MON group and all tasks in MON groups. Please see example section for more details on usage. + On systems with Sub-NUMA Cluster (SNC) enabled there are extra + directories for each node (located within the "mon_L3_XX" directory + for the L3 cache they occupy). These are named "mon_sub_L3_YY" + where "YY" is the node number. =20 "mon_hw_id": Available only with debug option. The identifier used by hardware @@ -484,6 +488,29 @@ if non-contiguous 1s value is supported. On a system w= ith a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. =20 +Notes on Sub-NUMA Cluster mode +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +When SNC mode is enabled, Linux may load balance tasks between Sub-NUMA +nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. + +The top-level monitoring files in each "mon_L3_XX" directory provide +the sum of data across all SNC nodes sharing an L3 cache instance. +Users who bind tasks to the CPUs of a specific Sub-NUMA node can read +the "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes" in the +"mon_sub_L3_YY" directories to get node local data. + +Memory bandwidth allocation is still performed at the L3 cache +level. I.e. throttling controls are applied to all SNC nodes. + +L3 cache allocation bitmaps also apply to all SNC nodes. But note that +the amount of L3 cache represented by each bit is divided by the number +of SNC nodes per L3 cache. E.g. with a 100MB cache on a system with 10-bit +allocation masks each bit normally represents 10MB. With SNC mode enabled +with two SNC nodes per L3 cache, each bit only represents 5MB. + Memory bandwidth Allocation and monitoring =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.45.2