[PATCH 05/15] x86/resctrl: Detect ABMC feature details

From: Babu Moger
Date: Thu Nov 30 2023 - 19:58:02 EST


ABMC feature details are reported via CPUID Fn8000_0020_EBX_x5.
Bits Description
15:0 MAX_ABMC Maximum Supported Assignable Bandwidth
Monitoring Counter ID + 1

Detect the feature details and update
/sys/fs/resctrl/info/L3_MON/mon_features.

The 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@xxxxxxx>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
---
Documentation/arch/x86/resctrl.rst | 7 +++++++
arch/x86/kernel/cpu/resctrl/core.c | 17 +++++++++++++++++
arch/x86/kernel/cpu/resctrl/internal.h | 2 ++
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 +++
include/linux/resctrl.h | 2 ++
5 files changed, 31 insertions(+)

diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index d816ded93c22..1293cb6cba98 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -197,6 +197,13 @@ with the following files:
mbm_local_bytes
mbm_local_bytes_config

+ If the system supports Assignable Bandwidth Monitoring
+ Counters (ABMC), the output will have additional text.
+ Example::
+
+ # cat /sys/fs/resctrl/info/L3_MON/mon_features
+ abmc_capable
+
"mbm_total_bytes_config", "mbm_local_bytes_config":
Read/write files containing the configuration for the mbm_total_bytes
and mbm_local_bytes events, respectively, when the Bandwidth
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index a257017b4de5..278698a74c49 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -303,6 +303,17 @@ static void rdt_get_cdp_l2_config(void)
rdt_get_cdp_config(RDT_RESOURCE_L2);
}

+static void rdt_get_abmc_cfg(struct rdt_resource *r)
+{
+ struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+ u32 eax, ebx, ecx, edx;
+
+ r->abmc_capable = true;
+ /* Query CPUID_Fn80000020_EBX_x05 for number of ABMC counters */
+ cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
+ hw_res->abmc_counters = (ebx & 0xFFFF) + 1;
+}
+
static void
mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
{
@@ -815,6 +826,12 @@ static __init bool get_rdt_alloc_resources(void)
if (get_slow_mem_config())
ret = true;

+ if (rdt_cpu_has(X86_FEATURE_ABMC)) {
+ r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+ rdt_get_abmc_cfg(r);
+ ret = true;
+ }
+
return ret;
}

diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index 524d8bec1439..0b22be85a444 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -388,6 +388,7 @@ struct rdt_parse_data {
* resctrl_arch_get_num_closid() to avoid confusion
* with struct resctrl_schema's property of the same name,
* which has been corrected for features like CDP.
+ * @abmc_countes: Maximum number of ABMC counters supported
* @msr_base: Base MSR address for CBMs
* @msr_update: Function pointer to update QOS MSRs
* @mon_scale: cqm counter * mon_scale = occupancy in bytes
@@ -401,6 +402,7 @@ struct rdt_parse_data {
struct rdt_hw_resource {
struct rdt_resource r_resctrl;
u32 num_closid;
+ u32 abmc_counters;
unsigned int msr_base;
void (*msr_update) (struct rdt_domain *d, struct msr_param *m,
struct rdt_resource *r);
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 6c22718dbaa2..feeb57ee7888 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1077,6 +1077,9 @@ static int rdt_mon_features_show(struct kernfs_open_file *of,
seq_printf(seq, "%s_config\n", mevt->name);
}

+ if (r->abmc_capable)
+ seq_printf(seq, "abmc_capable\n");
+
return 0;
}

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 66942d7fba7f..656af479a19b 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -162,6 +162,7 @@ struct resctrl_schema;
* @evt_list: List of monitoring events
* @fflags: flags to choose base and info files
* @cdp_capable: Is the CDP feature available on this resource
+ * @abmc_capable: Does system capable of supporting ABMC feature?
*/
struct rdt_resource {
int rid;
@@ -182,6 +183,7 @@ struct rdt_resource {
struct list_head evt_list;
unsigned long fflags;
bool cdp_capable;
+ bool abmc_capable;
};

/**
--
2.34.1