linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Babu Moger <babu.moger@amd.com>
To: <corbet@lwn.net>, <fenghua.yu@intel.com>,
	<reinette.chatre@intel.com>, <tglx@linutronix.de>,
	<mingo@redhat.com>, <bp@alien8.de>, <dave.hansen@linux.intel.com>
Cc: <x86@kernel.org>, <hpa@zytor.com>, <paulmck@kernel.org>,
	<rdunlap@infradead.org>, <tj@kernel.org>, <peterz@infradead.org>,
	<seanjc@google.com>, <kim.phillips@amd.com>, <babu.moger@amd.com>,
	<jmattson@google.com>, <ilpo.jarvinen@linux.intel.com>,
	<jithu.joseph@intel.com>, <kan.liang@linux.intel.com>,
	<nikunj@amd.com>, <daniel.sneddon@linux.intel.com>,
	<pbonzini@redhat.com>, <rick.p.edgecombe@intel.com>,
	<rppt@kernel.org>, <maciej.wieczor-retman@intel.com>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<eranian@google.com>, <peternewman@google.com>,
	<dhagiani@amd.com>
Subject: [PATCH 07/15] x86/resctrl: Add support to enable/disable ABMC feature
Date: Thu, 30 Nov 2023 18:57:12 -0600	[thread overview]
Message-ID: <20231201005720.235639-8-babu.moger@amd.com> (raw)
In-Reply-To: <20231201005720.235639-1-babu.moger@amd.com>

Set up the system to enable or disable ABMC feature. By default,
the ABMC is disabled. User needs to mount resctrl with -o abmc option
to enabled the feature.

ABMC is enabled by setting enabled bit(0) in MSR L3_QOS_EXT_CFG. When the
state of ABMC is changed, it must be changed to the updated value on all
logical processors in the QOS Domain.

The ABMC feature details are available in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming
Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth
Monitoring (ABMC).

Signed-off-by: Babu Moger <babu.moger@amd.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
---
 arch/x86/include/asm/msr-index.h       |  1 +
 arch/x86/kernel/cpu/resctrl/internal.h | 10 ++++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 79 +++++++++++++++++++++++++-
 3 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 737a52b89e64..a2086aad580c 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -1123,6 +1123,7 @@
 #define MSR_IA32_MBA_BW_BASE		0xc0000200
 #define MSR_IA32_SMBA_BW_BASE		0xc0000280
 #define MSR_IA32_EVT_CFG_BASE		0xc0000400
+#define MSR_IA32_L3_QOS_EXT_CFG		0xc00003ff
 
 /* MSR_IA32_VMX_MISC bits */
 #define MSR_IA32_VMX_MISC_INTEL_PT                 (1ULL << 14)
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index b8f3a0b1ca41..2801bc0dc132 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -50,6 +50,9 @@
 /* Dirty Victims to All Types of Memory */
 #define DIRTY_VICTIMS_TO_ALL_MEM	BIT(6)
 
+/* ABMC ENABLE */
+#define ABMC_ENABLE			BIT(0)
+
 struct rdt_fs_context {
 	struct kernfs_fs_context	kfc;
 	bool				enable_cdpl2;
@@ -395,6 +398,7 @@ struct rdt_parse_data {
  * @mon_scale:		cqm counter * mon_scale = occupancy in bytes
  * @mbm_width:		Monitor width, to detect and correct for overflow.
  * @cdp_enabled:	CDP state of this resource
+ * @abmc_enabled:	ABMC feature is enabled
  *
  * Members of this structure are either private to the architecture
  * e.g. mbm_width, or accessed via helpers that provide abstraction. e.g.
@@ -410,6 +414,7 @@ struct rdt_hw_resource {
 	unsigned int		mon_scale;
 	unsigned int		mbm_width;
 	bool			cdp_enabled;
+	bool			abmc_enabled;
 };
 
 static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r)
@@ -455,6 +460,11 @@ static inline bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l)
 
 int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable);
 
+static inline bool resctrl_arch_get_abmc_enabled(enum resctrl_res_level l)
+{
+	return rdt_resources_all[l].abmc_enabled;
+}
+
 /*
  * 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/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index a4328e12a8f6..7f6ed903ba17 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2365,6 +2365,72 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable)
 	return 0;
 }
 
+static void resctrl_abmc_msrwrite(void *arg)
+{
+	bool *enable = arg;
+	u64 msrval;
+
+	rdmsrl(MSR_IA32_L3_QOS_EXT_CFG, msrval);
+
+	if (*enable)
+		msrval |= ABMC_ENABLE;
+	else
+		msrval &= ~ABMC_ENABLE;
+
+	wrmsrl(MSR_IA32_L3_QOS_EXT_CFG, msrval);
+}
+
+static int resctrl_abmc_setup(enum resctrl_res_level l, bool enable)
+{
+	struct rdt_resource *r = &rdt_resources_all[l].r_resctrl;
+	struct rdt_domain *d;
+
+	/* Update QOS_CFG MSR on all the CPUs in cpu_mask */
+	list_for_each_entry(d, &r->domains, list)
+		on_each_cpu_mask(&d->cpu_mask, resctrl_abmc_msrwrite, &enable, 1);
+
+	return 0;
+}
+
+static int resctrl_abmc_enable(enum resctrl_res_level l)
+{
+	struct rdt_hw_resource *hw_res = &rdt_resources_all[l];
+	int ret = 0;
+
+	if (!hw_res->abmc_enabled) {
+		ret = resctrl_abmc_setup(l, true);
+		if (!ret)
+			hw_res->abmc_enabled = true;
+	}
+
+	return ret;
+}
+
+static void resctrl_abmc_disable(enum resctrl_res_level l)
+{
+	struct rdt_hw_resource *hw_res = &rdt_resources_all[l];
+
+	if (hw_res->abmc_enabled) {
+		resctrl_abmc_setup(l, false);
+		hw_res->abmc_enabled = false;
+	}
+}
+
+int resctrl_arch_set_abmc_enabled(enum resctrl_res_level l, bool enable)
+{
+	struct rdt_hw_resource *hw_res = &rdt_resources_all[l];
+
+	if (!hw_res->r_resctrl.abmc_capable)
+		return -EINVAL;
+
+	if (enable)
+		return resctrl_abmc_enable(l);
+
+	resctrl_abmc_disable(l);
+
+	return 0;
+}
+
 /*
  * We don't allow rdtgroup directories to be created anywhere
  * except the root directory. Thus when looking for the rdtgroup
@@ -2449,7 +2515,7 @@ static void rdt_disable_ctx(void)
 	resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
 	resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
 	set_mba_sc(false);
-
+	resctrl_arch_set_abmc_enabled(RDT_RESOURCE_L3, false);
 	resctrl_debug = false;
 }
 
@@ -2475,11 +2541,19 @@ static int rdt_enable_ctx(struct rdt_fs_context *ctx)
 			goto out_cdpl3;
 	}
 
+	if (ctx->enable_abmc) {
+		ret = resctrl_arch_set_abmc_enabled(RDT_RESOURCE_L3, true);
+		if (ret)
+			goto out_mba_mbps;
+	}
+
 	if (ctx->enable_debug)
 		resctrl_debug = true;
 
 	return 0;
 
+out_mba_mbps:
+	set_mba_sc(false);
 out_cdpl3:
 	resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
 out_cdpl2:
@@ -3802,6 +3876,9 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
 	if (resctrl_debug)
 		seq_puts(seq, ",debug");
 
+	if (resctrl_arch_get_abmc_enabled(RDT_RESOURCE_L3))
+		seq_puts(seq, ",abmc");
+
 	return 0;
 }
 
-- 
2.34.1


  parent reply	other threads:[~2023-12-01  0:58 UTC|newest]

Thread overview: 147+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01  0:57 [PATCH 00/15] x86/resctrl : Support AMD QoS RMID Pinning feature Babu Moger
2023-12-01  0:57 ` [PATCH 01/15] x86/resctrl: Remove hard-coded memory bandwidth limit Babu Moger
2023-12-05 23:18   ` Reinette Chatre
2023-12-06 16:29     ` Moger, Babu
2023-12-06 17:09       ` Reinette Chatre
2023-12-06 17:37         ` Moger, Babu
2023-12-01  0:57 ` [PATCH 02/15] x86/resctrl: Remove hard-coded memory bandwidth event configuration Babu Moger
2023-12-05 23:21   ` Reinette Chatre
2023-12-06 17:17     ` Moger, Babu
2023-12-06 18:32       ` Reinette Chatre
2023-12-06 19:17         ` Moger, Babu
2023-12-07 19:02           ` Reinette Chatre
2023-12-07 23:37             ` Moger, Babu
2023-12-01  0:57 ` [PATCH 03/15] x86/resctrl: Add support for Assignable Bandwidth Monitoring Counters (ABMC) Babu Moger
2023-12-01  0:57 ` [PATCH 04/15] x86/resctrl: Add ABMC feature in the command line options Babu Moger
2023-12-01  0:57 ` [PATCH 05/15] x86/resctrl: Detect ABMC feature details Babu Moger
2023-12-01  0:57 ` [PATCH 06/15] x86/resctrl: Add the mount option for ABMC feature Babu Moger
2023-12-01  0:57 ` Babu Moger [this message]
2023-12-05 16:48   ` [PATCH 07/15] x86/resctrl: Add support to enable/disable " kernel test robot
2023-12-05 17:40     ` Moger, Babu
2023-12-05 18:50   ` kernel test robot
2023-12-01  0:57 ` [PATCH 08/15] x86/resctrl: Introduce interface to display number of ABMC counters Babu Moger
2023-12-01  0:57 ` [PATCH 09/15] x86/resctrl: Add interface to display monitor state of the group Babu Moger
2023-12-01  0:57 ` [PATCH 10/15] x86/resctrl: Initialize ABMC counters bitmap Babu Moger
2023-12-01  0:57 ` [PATCH 11/15] x86/resctrl: Add data structures for ABMC assignment Babu Moger
2023-12-01  0:57 ` [PATCH 12/15] x86/resctrl: Introduce mbm_total_cfg and mbm_local_cfg Babu Moger
2023-12-01  0:57 ` [PATCH 13/15] x86/resctrl: Add the interface to assign a ABMC counter Babu Moger
2023-12-01  0:57 ` [PATCH 14/15] x86/resctrl: Add interface unassign " Babu Moger
2023-12-05 17:55   ` kernel test robot
2023-12-05 18:09     ` Moger, Babu
2023-12-01  0:57 ` [PATCH 15/15] x86/resctrl: Update ABMC assignment on event configuration changes Babu Moger
2023-12-05  0:13 ` [PATCH 00/15] x86/resctrl : Support AMD QoS RMID Pinning feature Peter Newman
2023-12-05 23:17 ` Reinette Chatre
2023-12-06 15:40   ` Moger, Babu
2023-12-06 18:49     ` Reinette Chatre
2023-12-07 16:12       ` Moger, Babu
2023-12-07 19:29         ` Reinette Chatre
2023-12-07 23:07           ` Moger, Babu
2023-12-07 23:26             ` Reinette Chatre
2023-12-07 23:34               ` Moger, Babu
2023-12-08 22:58           ` Moger, Babu
2023-12-08 19:45   ` Peter Newman
2023-12-08 20:09     ` Reinette Chatre
2023-12-12 18:02 ` [PATCH v2 1/2] x86/resctrl: Remove hard-coded memory bandwidth limit Babu Moger
2023-12-15  2:20   ` Reinette Chatre
2024-01-02 19:52     ` Moger, Babu
2023-12-12 18:02 ` [PATCH v2 2/2] x86/resctrl: Remove hard-coded memory bandwidth event configuration Babu Moger
2023-12-15  1:24   ` Reinette Chatre
2024-01-02 20:00     ` Moger, Babu
2024-01-03 18:38       ` Reinette Chatre
2024-01-03 21:03         ` Moger, Babu
2024-01-03 21:40           ` Reinette Chatre
2024-01-04 13:48             ` Moger, Babu
2024-01-04 21:21 ` [PATCH v3 1/2] x86/resctrl: Remove hard-coded memory bandwidth limit Babu Moger
2024-01-05 21:14   ` Reinette Chatre
2024-01-05 23:51     ` Moger, Babu
2024-01-04 21:21 ` [PATCH v3 2/2] x86/resctrl: Remove hard-coded memory bandwidth event configuration Babu Moger
2024-01-05 21:18   ` Reinette Chatre
2024-01-06  0:13     ` Moger, Babu
2024-01-11 21:36 ` [PATCH v4 1/2] x86/resctrl: Remove hard-coded memory bandwidth limit Babu Moger
2024-01-11 21:36 ` [PATCH v4 2/2] x86/resctrl: Read supported bandwidth sources using CPUID command Babu Moger
2024-01-12 19:02   ` Reinette Chatre
2024-01-12 20:38     ` Moger, Babu
2024-01-12 21:24       ` Reinette Chatre
2024-01-12 21:54         ` Moger, Babu
2024-01-15 22:52 ` [PATCH v5 1/2] x86/resctrl: Remove hard-coded memory bandwidth limit Babu Moger
2024-01-23 10:36   ` Borislav Petkov
2024-01-23 14:58     ` Moger, Babu
2024-01-23 15:36   ` [tip: x86/cache] " tip-bot2 for Babu Moger
2024-01-15 22:52 ` [PATCH v5 2/2] x86/resctrl: Read supported bandwidth sources using CPUID command Babu Moger
2024-01-16 19:44   ` Reinette Chatre
2024-01-16 21:39     ` Moger, Babu
2024-01-23 15:36   ` [tip: x86/cache] x86/resctrl: Read supported bandwidth sources from CPUID tip-bot2 for Babu Moger
2024-01-19 18:22 ` [PATCH v2 00/17] x86/resctrl : Support AMD Assignable Bandwidth Monitoring Counters (ABMC) Babu Moger
2024-01-19 18:22   ` [PATCH v2 01/17] x86/cpufeatures: Add word 21 for scattered CPUID features Babu Moger
2024-01-19 18:22   ` [PATCH v2 02/17] x86/resctrl: Add support for Assignable Bandwidth Monitoring Counters (ABMC) Babu Moger
2024-01-19 18:22   ` [PATCH v2 03/17] x86/resctrl: Add ABMC feature in the command line options Babu Moger
2024-01-19 18:22   ` [PATCH v2 04/17] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details Babu Moger
2024-02-20 17:56     ` James Morse
2024-02-20 21:27       ` Moger, Babu
2024-01-19 18:22   ` [PATCH v2 05/17] x86/resctrl: Introduce resctrl_file_fflags_init Babu Moger
2024-01-19 18:22   ` [PATCH v2 06/17] x86/resctrl: Introduce interface to display number of ABMC counters Babu Moger
2024-02-20 18:14     ` James Morse
2024-02-20 21:23       ` Moger, Babu
2024-01-19 18:22   ` [PATCH v2 07/17] x86/resctrl: Add support to enable/disable ABMC feature Babu Moger
2024-01-19 18:22   ` [PATCH v2 08/17] x86/resctrl: Introduce the interface to display ABMC state Babu Moger
2024-01-19 18:22   ` [PATCH v2 09/17] x86/resctrl: Introdruce rdtgroup_assign_enable_write Babu Moger
2024-01-19 18:22   ` [PATCH v2 10/17] x86/resctrl: Add interface to display monitor state of the group Babu Moger
2024-01-19 18:22   ` [PATCH v2 11/17] x86/resctrl: Report Unsupported when MBM events are read Babu Moger
2024-01-19 18:22   ` [PATCH v2 12/17] x86/resctrl: Initialize assignable counters bitmap Babu Moger
2024-01-19 18:22   ` [PATCH v2 13/17] x86/resctrl: Add data structures for ABMC assignment Babu Moger
2024-01-19 18:22   ` [PATCH v2 14/17] x86/resctrl: Introduce mbm_total_cfg and mbm_local_cfg Babu Moger
2024-01-19 18:22   ` [PATCH v2 15/17] x86/resctrl: Add the interface to assign the RMID Babu Moger
2024-01-19 18:22   ` [PATCH v2 16/17] x86/resctrl: Add the interface unassign " Babu Moger
2024-01-19 18:22   ` [PATCH v2 17/17] x86/resctrl: Update RMID assignments on event configuration changes Babu Moger
2024-01-19 18:32   ` [PATCH v2 00/17] x86/resctrl : Support AMD Assignable Bandwidth Monitoring Counters (ABMC) Reinette Chatre
2024-01-19 20:35     ` Moger, Babu
2024-02-02  4:09   ` Reinette Chatre
2024-02-02  5:01     ` Reinette Chatre
2024-02-02 21:57     ` Moger, Babu
2024-02-05 22:38       ` Reinette Chatre
2024-02-08 17:29         ` Moger, Babu
2024-02-16 20:18           ` Peter Newman
2024-02-19 18:00             ` Moger, Babu
2024-02-20 15:21             ` James Morse
2024-02-20 18:11               ` Peter Newman
2024-02-23 21:47                 ` Moger, Babu
2024-02-20 15:21   ` James Morse
2024-02-20 18:14     ` James Morse
2024-02-20 20:48     ` Moger, Babu
2024-02-23 17:17       ` Reinette Chatre
2024-02-23 20:11         ` Moger, Babu
2024-02-23 22:21           ` Reinette Chatre
2024-02-26 17:59             ` Moger, Babu
2024-02-26 21:20               ` Reinette Chatre
2024-02-27 18:12                 ` Moger, Babu
2024-02-27 18:26                   ` Peter Newman
2024-02-27 19:37                     ` Moger, Babu
2024-02-27 20:06                       ` Peter Newman
2024-02-27 20:42                         ` Moger, Babu
2024-02-27 23:50                   ` Reinette Chatre
2024-02-28 17:59                     ` Moger, Babu
2024-02-28 20:04                       ` Reinette Chatre
2024-02-29 20:37                         ` Moger, Babu
2024-02-29 21:50                           ` Reinette Chatre
2024-03-01 20:36                             ` Moger, Babu
2024-03-01 23:20                               ` Reinette Chatre
2024-03-04 19:34                                 ` Moger, Babu
2024-03-04 19:58                                   ` Reinette Chatre
2024-03-04 22:24                                     ` Moger, Babu
2024-03-05 14:58                                       ` Moger, Babu
2024-03-05 17:12                                       ` Reinette Chatre
2024-03-05 19:35                                         ` Moger, Babu
2024-03-07 18:57                                       ` Peter Newman
2024-03-07 20:41                                         ` Reinette Chatre
2024-03-07 22:33                                           ` Peter Newman
2024-03-07 22:53                                             ` Reinette Chatre
2024-03-07 23:14                                               ` Peter Newman
2024-03-08 17:13                                                 ` Reinette Chatre
2024-03-08  3:50                                               ` Moger, Babu
2024-03-08 17:20                                                 ` Reinette Chatre
2024-03-12 13:30                                                   ` Moger, Babu
2024-03-11 15:40                     ` Moger, Babu
2024-03-12 15:13                       ` Reinette Chatre
2024-03-12 17:07                         ` Moger, Babu
2024-03-12 17:15                           ` Reinette Chatre
2024-03-12 17:24                             ` Moger, Babu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231201005720.235639-8-babu.moger@amd.com \
    --to=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=daniel.sneddon@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dhagiani@amd.com \
    --cc=eranian@google.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jithu.joseph@intel.com \
    --cc=jmattson@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=kim.phillips@amd.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=paulmck@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peternewman@google.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=reinette.chatre@intel.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=rppt@kernel.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).