[PATCH v13 04/27] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details

Babu Moger posted 27 patches 7 months ago
[PATCH v13 04/27] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details
Posted by Babu Moger 7 months ago
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

The feature details are documented 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).

Detect the feature and number of assignable monitoring counters supported.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v13: No changes.

v12: Resolved conflicts because of latest merge.
     Removed Reviewed-by as the patch has changed.

v11: No changes.

v10: No changes.

v9: Added Reviewed-by tag. No code changes

v8: Used GENMASK for the mask.

v7: Removed WARN_ON for num_mbm_cntrs. Decided to dynamically allocate the
    bitmap. WARN_ON is not required anymore.
    Removed redundant comments.

v6: Commit message update.
    Renamed abmc_capable to mbm_cntr_assignable.

v5: Name change num_cntrs to num_mbm_cntrs.
    Moved abmc_capable to resctrl_mon.

v4: Removed resctrl_arch_has_abmc(). Added all the code inline. We dont
    need to separate this as arch code.

v3: Removed changes related to mon_features.
    Moved rdt_cpu_has to core.c and added new function resctrl_arch_has_abmc.
    Also moved the fields mbm_assign_capable and mbm_assign_cntrs to
    rdt_resource. (James)

v2: Changed the field name to mbm_assign_capable from abmc_capable.
---
 arch/x86/kernel/cpu/resctrl/monitor.c | 9 +++++++--
 include/linux/resctrl.h               | 4 ++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index aeb2a9283069..fd2761d9f3f7 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -345,6 +345,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	unsigned int threshold;
+	u32 eax, ebx, ecx, edx;
 
 	snc_nodes_per_l3_cache = snc_get_config();
 
@@ -375,13 +376,17 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
 
 	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
-		u32 eax, ebx, ecx, edx;
-
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
 		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
 	}
 
+	if (rdt_cpu_has(X86_FEATURE_ABMC)) {
+		r->mon.mbm_cntr_assignable = true;
+		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
+		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
+	}
+
 	r->mon_capable = true;
 
 	return 0;
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 2a8fa454d3e6..065fb6e38933 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -260,11 +260,15 @@ enum resctrl_schema_fmt {
  * @num_rmid:		Number of RMIDs available
  * @mbm_cfg_mask:	Bandwidth sources that can be tracked when bandwidth
  *			monitoring events can be configured.
+ * @num_mbm_cntrs:	Number of assignable monitoring counters
+ * @mbm_cntr_assignable:Is system capable of supporting monitor assignment?
  * @evt_list:		List of monitoring events
  */
 struct resctrl_mon {
 	int			num_rmid;
 	unsigned int		mbm_cfg_mask;
+	int			num_mbm_cntrs;
+	bool			mbm_cntr_assignable;
 	struct list_head	evt_list;
 };
 
-- 
2.34.1
Re: [PATCH v13 04/27] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details
Posted by Reinette Chatre 6 months, 3 weeks ago
Hi Babu,

On 5/15/25 3:51 PM, Babu Moger wrote:
> 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
> 
> The feature details are documented 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).
> 
> Detect the feature and number of assignable monitoring counters supported.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---

...

> ---
>  arch/x86/kernel/cpu/resctrl/monitor.c | 9 +++++++--
>  include/linux/resctrl.h               | 4 ++++
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
> index aeb2a9283069..fd2761d9f3f7 100644
> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
> @@ -345,6 +345,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
>  	unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
>  	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
>  	unsigned int threshold;
> +	u32 eax, ebx, ecx, edx;
>  
>  	snc_nodes_per_l3_cache = snc_get_config();
>  
> @@ -375,13 +376,17 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
>  	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
>  
>  	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
> -		u32 eax, ebx, ecx, edx;
> -
>  		/* Detect list of bandwidth sources that can be tracked */
>  		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
>  		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
>  	}
>  
> +	if (rdt_cpu_has(X86_FEATURE_ABMC)) {
> +		r->mon.mbm_cntr_assignable = true;
> +		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
> +		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
> +	}
> +

Shouldn't ABMC detection also include enumeration of which configurations
are supported? From what I can tell, looking ahead patch #18 hardcodes definitions
of all known "bandwidth types" (which term to use TBD) and then patch #20 allows
*any* of these types to be configured irrespective of whether system
supports it.
AMD spec mentions "The types of L3 transactions that ABMC can track are
configurable and identified by CPUID Fn8000_0020_ECX_x3."  It thus looks
like the enumeration of r->mon.mbm_cfg_mask when BMEC is enabled is
required for ABMC also and used by this implementation.

>  	r->mon_capable = true;
>  
>  	return 0;
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 2a8fa454d3e6..065fb6e38933 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
> @@ -260,11 +260,15 @@ enum resctrl_schema_fmt {
>   * @num_rmid:		Number of RMIDs available
>   * @mbm_cfg_mask:	Bandwidth sources that can be tracked when bandwidth
>   *			monitoring events can be configured.
> + * @num_mbm_cntrs:	Number of assignable monitoring counters
> + * @mbm_cntr_assignable:Is system capable of supporting monitor assignment?

"monitor assignment" has not been used so far, was this intended to be
"counter assignment"?

Reinette
Re: [PATCH v13 04/27] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details
Posted by Moger, Babu 6 months, 2 weeks ago
Hi Reinette,

On 5/22/25 15:54, Reinette Chatre wrote:
> Hi Babu,
> 
> On 5/15/25 3:51 PM, Babu Moger wrote:
>> 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
>>
>> The feature details are documented 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).
>>
>> Detect the feature and number of assignable monitoring counters supported.
>>
>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
> 
> ...
> 
>> ---
>>  arch/x86/kernel/cpu/resctrl/monitor.c | 9 +++++++--
>>  include/linux/resctrl.h               | 4 ++++
>>  2 files changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
>> index aeb2a9283069..fd2761d9f3f7 100644
>> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
>> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
>> @@ -345,6 +345,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
>>  	unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
>>  	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
>>  	unsigned int threshold;
>> +	u32 eax, ebx, ecx, edx;
>>  
>>  	snc_nodes_per_l3_cache = snc_get_config();
>>  
>> @@ -375,13 +376,17 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
>>  	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
>>  
>>  	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
>> -		u32 eax, ebx, ecx, edx;
>> -
>>  		/* Detect list of bandwidth sources that can be tracked */
>>  		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
>>  		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
>>  	}
>>  
>> +	if (rdt_cpu_has(X86_FEATURE_ABMC)) {
>> +		r->mon.mbm_cntr_assignable = true;
>> +		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
>> +		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
>> +	}
>> +
> 
> Shouldn't ABMC detection also include enumeration of which configurations
> are supported? From what I can tell, looking ahead patch #18 hardcodes definitions
> of all known "bandwidth types" (which term to use TBD) and then patch #20 allows
> *any* of these types to be configured irrespective of whether system
> supports it.
> AMD spec mentions "The types of L3 transactions that ABMC can track are
> configurable and identified by CPUID Fn8000_0020_ECX_x3."  It thus looks
> like the enumeration of r->mon.mbm_cfg_mask when BMEC is enabled is
> required for ABMC also and used by this implementation.
> 
>>  	r->mon_capable = true;
>>  
>>  	return 0;
>> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
>> index 2a8fa454d3e6..065fb6e38933 100644
>> --- a/include/linux/resctrl.h
>> +++ b/include/linux/resctrl.h
>> @@ -260,11 +260,15 @@ enum resctrl_schema_fmt {
>>   * @num_rmid:		Number of RMIDs available
>>   * @mbm_cfg_mask:	Bandwidth sources that can be tracked when bandwidth
>>   *			monitoring events can be configured.
>> + * @num_mbm_cntrs:	Number of assignable monitoring counters
>> + * @mbm_cntr_assignable:Is system capable of supporting monitor assignment?
> 
> "monitor assignment" has not been used so far, was this intended to be
> "counter assignment"?

Missed to respond to this comment.  Yes. Sure. Will correct it.
-- 
Thanks
Babu Moger
Re: [PATCH v13 04/27] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details
Posted by Moger, Babu 6 months, 2 weeks ago
Hi Reinette,

On 5/22/25 15:54, Reinette Chatre wrote:
> Hi Babu,
> 
> On 5/15/25 3:51 PM, Babu Moger wrote:
>> 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
>>
>> The feature details are documented 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).
>>
>> Detect the feature and number of assignable monitoring counters supported.
>>
>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
> 
> ...
> 
>> ---
>>  arch/x86/kernel/cpu/resctrl/monitor.c | 9 +++++++--
>>  include/linux/resctrl.h               | 4 ++++
>>  2 files changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
>> index aeb2a9283069..fd2761d9f3f7 100644
>> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
>> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
>> @@ -345,6 +345,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
>>  	unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
>>  	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
>>  	unsigned int threshold;
>> +	u32 eax, ebx, ecx, edx;
>>  
>>  	snc_nodes_per_l3_cache = snc_get_config();
>>  
>> @@ -375,13 +376,17 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
>>  	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
>>  
>>  	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
>> -		u32 eax, ebx, ecx, edx;
>> -
>>  		/* Detect list of bandwidth sources that can be tracked */
>>  		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
>>  		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
>>  	}
>>  
>> +	if (rdt_cpu_has(X86_FEATURE_ABMC)) {
>> +		r->mon.mbm_cntr_assignable = true;
>> +		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
>> +		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
>> +	}
>> +
> 
> Shouldn't ABMC detection also include enumeration of which configurations
> are supported? From what I can tell, looking ahead patch #18 hardcodes definitions
> of all known "bandwidth types" (which term to use TBD) and then patch #20 allows
> *any* of these types to be configured irrespective of whether system
> supports it.
> AMD spec mentions "The types of L3 transactions that ABMC can track are
> configurable and identified by CPUID Fn8000_0020_ECX_x3."  It thus looks
> like the enumeration of r->mon.mbm_cfg_mask when BMEC is enabled is
> required for ABMC also and used by this implementation.

That is true. Will add the following check.

if (rdt_cpu_has(X86_FEATURE_BMEC) || rdt_cpu_has(X86_FEATURE_ABMC)) {
  		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
 		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
}


> 
>>  	r->mon_capable = true;
>>  
>>  	return 0;
>> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
>> index 2a8fa454d3e6..065fb6e38933 100644
>> --- a/include/linux/resctrl.h
>> +++ b/include/linux/resctrl.h
>> @@ -260,11 +260,15 @@ enum resctrl_schema_fmt {
>>   * @num_rmid:		Number of RMIDs available
>>   * @mbm_cfg_mask:	Bandwidth sources that can be tracked when bandwidth
>>   *			monitoring events can be configured.
>> + * @num_mbm_cntrs:	Number of assignable monitoring counters
>> + * @mbm_cntr_assignable:Is system capable of supporting monitor assignment?
> 
> "monitor assignment" has not been used so far, was this intended to be
> "counter assignment"?
> 
> Reinette
> 

-- 
Thanks
Babu Moger