arm_mpam: Add basic mpam driver
Subsystems (4)
James Morse
maintainerPATCH v2 14/29 arm_mpam: Merge supported features during mpam_enable() into mpam_class
In reply to James MorseTo make a decision about whether to expose an mpam class as a resctrl resource we need to know its overall supported features and properties.
Once we've probed all the resources, we can walk the tree and produce overall values by merging the bitmaps. This eliminates features that are only supported by some MSC that make up a component or class.
If bitmap properties are mismatched within a component we cannot support the mismatched feature.
Care has to be taken as vMSC may hold mismatched RIS.
--- drivers/resctrl/mpam_devices.c | 215 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 8 ++ 2 files changed, 223 insertions(+)
drivers/resctrl/mpam_devices.c +215 -0
@@ -961,8 +961,223 @@ static struct platform_driver mpam_msc_driver = { .remove = mpam_msc_drv_remove, }; +/* Any of these features mean the BWA_WD field is valid. */ +static bool mpam_has_bwa_wd_feature (struct mpam_props *props) +{ +if (mpam_has_feature (mpam_feat_mbw_min, props)) +return true; +if (mpam_has_feature (mpam_feat_mbw_max, props)) +return true; +if (mpam_has_feature (mpam_feat_mbw_prop, props)) +return true; +return false; +} + +#define MISMATCHED_HELPER (parent, child, helper, field, alias) \ + helper(parent) && \ + ((helper(child) && (parent)->field != (child)->field) || \ + (!helper(child) && !(alias))) + +#define MISMATCHED_FEAT (parent, child, feat, field, alias) \ + mpam_has_feature((feat), (parent)) && \ + ((mpam_has_feature((feat), (child)) && (parent)->field != (child)->field) || \ + (!mpam_has_feature((feat), (child)) && !(alias))) + +#define CAN_MERGE_FEAT (parent, child, feat, alias) \ + (alias) && !mpam_has_feature((feat), (parent)) && \ + mpam_has_feature((feat), (child)) + +/* +* Combine two props fields. +* If this is for controls that alias the same resource, it is safe to just +* copy the values over. If two aliasing controls implement the same scheme +* a safe value must be picked. +* For non-aliasing controls, these control different resources, and the +* resulting safe value must be compatible with both. When merging values in +* the tree, all the aliasing resources must be handled first. +* On mismatch, parent is modified. +*/ +static void __props_mismatch (struct mpam_props *parent, +struct mpam_props *child,bool alias) +{ +if (CAN_MERGE_FEAT (parent, child, mpam_feat_cpor_part, alias)) { + parent->cpbm_wd = child->cpbm_wd; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_cpor_part, + cpbm_wd, alias)) { +pr_debug ("%s cleared cpor_part\n" , __func__); +mpam_clear_feature (mpam_feat_cpor_part, &parent->features); + parent->cpbm_wd =0 ; + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_mbw_part, alias)) { + parent->mbw_pbm_bits = child->mbw_pbm_bits; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_mbw_part, + mbw_pbm_bits, alias)) { +pr_debug ("%s cleared mbw_part\n" , __func__); +mpam_clear_feature (mpam_feat_mbw_part, &parent->features); + parent->mbw_pbm_bits =0 ; + } + +/* bwa_wd is a count of bits, fewer bits means less precision */ +if (alias && !mpam_has_bwa_wd_feature (parent) &&mpam_has_bwa_wd_feature (child)) { + parent->bwa_wd = child->bwa_wd; + }else if (MISMATCHED_HELPER (parent, child, mpam_has_bwa_wd_feature, + bwa_wd, alias)) { +pr_debug ("%s took the min bwa_wd\n" , __func__); + parent->bwa_wd =min (parent->bwa_wd, child->bwa_wd); + } + +/* For num properties, take the minimum */ +if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_csu, alias)) { + parent->num_csu_mon = child->num_csu_mon; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_msmon_csu, + num_csu_mon, alias)) { +pr_debug ("%s took the min num_csu_mon\n" , __func__); + parent->num_csu_mon =min (parent->num_csu_mon, child->num_csu_mon); + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_mbwu, alias)) { + parent->num_mbwu_mon = child->num_mbwu_mon; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_msmon_mbwu, + num_mbwu_mon, alias)) { +pr_debug ("%s took the min num_mbwu_mon\n" , __func__); + parent->num_mbwu_mon =min (parent->num_mbwu_mon, child->num_mbwu_mon); + } + +if (alias) { +/* Merge features for aliased resources */ + parent->features |= child->features; + }else { +/* Clear missing features for non aliasing */ + parent->features &= child->features; + } +} + +/* +* If a vmsc doesn't match class feature/configuration, do the right thing(tm). +* For 'num' properties we can just take the minimum. +* For properties where the mismatched unused bits would make a difference, we +* nobble the class feature, as we can't configure all the resources. +* e.g. The L3 cache is composed of two resources with 13 and 17 portion +* bitmaps respectively. +*/ +static void +__class_props_mismatch (struct mpam_class *class,struct mpam_vmsc *vmsc) +{ +struct mpam_props *cprops = &class->props; +struct mpam_props *vprops = &vmsc->props; + +lockdep_assert_held (&mpam_list_lock);/* we modify class */ + +pr_debug ("%s: Merging features for class:0x%lx &= vmsc:0x%lx\n" , +dev_name (&vmsc->msc->pdev->dev), + (long )cprops->features, (long )vprops->features); + +/* Take the safe value for any common features */ +__props_mismatch (cprops, vprops, false); +} + +static void +__vmsc_props_mismatch (struct mpam_vmsc *vmsc,struct mpam_msc_ris *ris) +{ +struct mpam_props *rprops = &ris->props; +struct mpam_props *vprops = &vmsc->props; + +lockdep_assert_held (&mpam_list_lock);/* we modify vmsc */ + +pr_debug ("%s: Merging features for vmsc:0x%lx |= ris:0x%lx\n" , +dev_name (&vmsc->msc->pdev->dev), + (long )vprops->features, (long )rprops->features); + +/* +* Merge mismatched features - Copy any features that aren't common, +* but take the safe value for any common features. +*/ +__props_mismatch (vprops, rprops, true); +} + +/* +* Copy the first component's first vMSC's properties and features to the +* class. __class_props_mismatch() will remove conflicts. +* It is not possible to have a class with no components, or a component with +* no resources. The vMSC properties have already been built. +*/ +static void mpam_enable_init_class_features (struct mpam_class *class) +{ +struct mpam_vmsc *vmsc; +struct mpam_component *comp; + + comp =list_first_entry_or_null (&class->components, + struct mpam_component, class_list); +if (WARN_ON (!comp)) +return ; + + vmsc =list_first_entry_or_null (&comp->vmsc, + struct mpam_vmsc, comp_list); +if (WARN_ON (!vmsc)) +return ; + + class->props = vmsc->props; +} + +static void mpam_enable_merge_vmsc_features (struct mpam_component *comp) +{ +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; +struct mpam_class *class = comp->class; + +list_for_each_entry (vmsc, &comp->vmsc, comp_list) { +list_for_each_entry (ris, &vmsc->ris, vmsc_list) { +__vmsc_props_mismatch (vmsc, ris); + class->nrdy_usec =max (class->nrdy_usec, + vmsc->msc->nrdy_usec); + } + } +} + +static void mpam_enable_merge_class_features (struct mpam_component *comp) +{ +struct mpam_vmsc *vmsc; +struct mpam_class *class = comp->class; + +list_for_each_entry (vmsc, &comp->vmsc, comp_list) +__class_props_mismatch (class, vmsc); +} + +/* +* Merge all the common resource features into class. +* vmsc features are bitwise-or'd together, this must be done first. +* Next the class features are the bitwise-and of all the vmsc features. +* Other features are the min/max as appropriate. +* +* To avoid walking the whole tree twice, the class->nrdy_usec property is +* updated when working with the vmsc as it is a max(), and doesn't need +* initialising first. +*/ +static void mpam_enable_merge_features (struct list_head *all_classes_list) +{ +struct mpam_class *class; +struct mpam_component *comp; + +lockdep_assert_held (&mpam_list_lock); + +list_for_each_entry (class, all_classes_list, classes_list) { +list_for_each_entry (comp, &class->components, class_list) +mpam_enable_merge_vmsc_features (comp); + +mpam_enable_init_class_features (class); + +list_for_each_entry (comp, &class->components, class_list) +mpam_enable_merge_class_features (comp); + } +} +static void mpam_enable_once (void ) { +mutex_lock (&mpam_list_lock); +mpam_enable_merge_features (&mpam_classes); +mutex_unlock (&mpam_list_lock); +/* * Once the cpuhp callbacks have been changed, mpam_partid_max can no * longer change.
drivers/resctrl/mpam_internal.h +8 -0
@@ -161,12 +161,20 @@ static inline void mpam_set_feature(enum mpam_device_features feat, props->features |= (1 << feat); } +static inline void mpam_clear_feature (enum mpam_device_features feat, +mpam_features_t *supported) +{ + *supported &= ~(1 << feat); +} +struct mpam_class {/* mpam_components in this class */ struct list_head components;cpumask_t affinity; +struct mpam_props props; +u32 nrdy_usec;u8 level;enum mpam_class_types type;
Signature · 1 line
2.39.5
Re: [PATCH v2 14/29] arm_mpam: Merge supported features during mpam_enable() into mpam_class
Quoted 9 lines · On Wed, 10 Sep 2025 20:42:54 +0000 James Morse <[email protected]> wrote:
To make a decision about whether to expose an mpam class as a resctrl resource we need to know its overall supported features and properties.
Once we've probed all the resources, we can walk the tree and produce overall values by merging the bitmaps. This eliminates features that are only supported by some MSC that make up a component or class.
Quoted 7 lines
If bitmap properties are mismatched within a component we cannot support the mismatched feature.
Care has to be taken as vMSC may hold mismatched RIS.
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
A trivial things inline.
Quoted 23 lines
drivers/resctrl/mpam_devices.c +23
-0+/* +* Combine two props fields. +* If this is for controls that alias the same resource, it is safe to just +* copy the values over. If two aliasing controls implement the same scheme +* a safe value must be picked. +* For non-aliasing controls, these control different resources, and the +* resulting safe value must be compatible with both. When merging values in +* the tree, all the aliasing resources must be handled first. +* On mismatch, parent is modified. +*/ +static void __props_mismatch (struct mpam_props *parent, +struct mpam_props *child,bool alias) +{ +if (CAN_MERGE_FEAT (parent, child, mpam_feat_cpor_part, alias)) { + parent->cpbm_wd = child->cpbm_wd; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_cpor_part, + cpbm_wd, alias)) { +pr_debug ("%s cleared cpor_part\n" , __func__); +mpam_clear_feature (mpam_feat_cpor_part, &parent->features); + parent->cpbm_wd =0 ; + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_mbw_part, alias)) {
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1022
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ parent->mbw_pbm_bits = child->mbw_pbm_bits; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_mbw_part, + mbw_pbm_bits, alias)) { +pr_debug ("%s cleared mbw_part\n" , __func__); +mpam_clear_feature (mpam_feat_mbw_part, &parent->features); + parent->mbw_pbm_bits =0 ; + } + +/* bwa_wd is a count of bits, fewer bits means less precision */ +if (alias && !mpam_has_bwa_wd_feature (parent) &&mpam_has_bwa_wd_feature (child)) {
Seems like an overly long line given other local wrapping.
Quoted 25 lines
drivers/resctrl/mpam_devices.c +24
-0+ parent->bwa_wd = child->bwa_wd; + }else if (MISMATCHED_HELPER (parent, child, mpam_has_bwa_wd_feature, + bwa_wd, alias)) { +pr_debug ("%s took the min bwa_wd\n" , __func__); + parent->bwa_wd =min (parent->bwa_wd, child->bwa_wd); + } + +/* For num properties, take the minimum */ +if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_csu, alias)) { + parent->num_csu_mon = child->num_csu_mon; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_msmon_csu, + num_csu_mon, alias)) { +pr_debug ("%s took the min num_csu_mon\n" , __func__); + parent->num_csu_mon =min (parent->num_csu_mon, child->num_csu_mon); + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_mbwu, alias)) { + parent->num_mbwu_mon = child->num_mbwu_mon; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_msmon_mbwu, + num_mbwu_mon, alias)) { +pr_debug ("%s took the min num_mbwu_mon\n" , __func__); + parent->num_mbwu_mon =min (parent->num_mbwu_mon, child->num_mbwu_mon); + } +
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1065
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+/* +* If a vmsc doesn't match class feature/configuration, do the right thing(tm). +* For 'num' properties we can just take the minimum. +* For properties where the mismatched unused bits would make a difference, we +* nobble the class feature, as we can't configure all the resources. +* e.g. The L3 cache is composed of two resources with 13 and 17 portion +* bitmaps respectively. +*/ +static void +__class_props_mismatch (struct mpam_class *class,struct mpam_vmsc *vmsc)
I'm not really sure what the __ prefix denotes here.
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1074
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+{ +struct mpam_props *cprops = &class->props; +struct mpam_props *vprops = &vmsc->props; + +lockdep_assert_held (&mpam_list_lock);/* we modify class */ + +pr_debug ("%s: Merging features for class:0x%lx &= vmsc:0x%lx\n" , +dev_name (&vmsc->msc->pdev->dev), + (long )cprops->features, (long )vprops->features);
According to https://docs.kernel.org/core-api/printk-formats.html
should be fine using %x for u16 values. So why dance through a cast to long?
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ +/* Take the safe value for any common features */ +__props_mismatch (cprops, vprops, false); +} + +static void
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1090
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+__vmsc_props_mismatch(struct mpam_vmsc *vmsc, struct mpam_msc_ris *ris) +{ + struct mpam_props *rprops = &ris->props; +struct mpam_props *vprops = &vmsc->props; + +lockdep_assert_held (&mpam_list_lock);/* we modify vmsc */ + +pr_debug ("%s: Merging features for vmsc:0x%lx |= ris:0x%lx\n" , +dev_name (&vmsc->msc->pdev->dev), + (long )vprops->features, (long )rprops->features);
Same as above comment on casts being unnecessary.
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1103
Quoted 13 lines
drivers/resctrl/mpam_devices.c +13
-0+ +/* +* Merge mismatched features - Copy any features that aren't common, +* but take the safe value for any common features. +*/ +__props_mismatch (vprops, rprops, true); +} + +/* +* Copy the first component's first vMSC's properties and features to the +* class. __class_props_mismatch() will remove conflicts. +* It is not possible to have a class with no components, or a component with +* no resources. The vMSC properties have already been built.
If it's not possible do we need the defensive _or_null and error checks?
Quoted 12 lines
+ */
drivers/resctrl/mpam_devices.c +11
-0+static void mpam_enable_init_class_features (struct mpam_class *class) +{ +struct mpam_vmsc *vmsc; +struct mpam_component *comp; + + comp =list_first_entry_or_null (&class->components, + struct mpam_component, class_list); +if (WARN_ON (!comp)) +return ; + + vmsc = list_first_entry_or_null(&comp->vmsc,
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1149
Quoted 10 lines
drivers/resctrl/mpam_devices.c +9
-0+ struct mpam_vmsc, comp_list); +if (WARN_ON (!vmsc)) +return ; + + class->props = vmsc->props; +} +/* +* Merge all the common resource features into class. +* vmsc features are bitwise-or'd together, this must be done first.
I'm not sure what 'this' is here - I think it's a missing plural that has me confused. Perhaps 'these must be done first.'
Quoted 6 lines
+ * Next the class features are the bitwise-and of all the vmsc features.
+ * Other features are the min/max as appropriate.
+ *
+ * To avoid walking the whole tree twice, theclass->nrdy_usecproperty is
+ * updated when working with the vmsc as it is amax(), and doesn't need
+ * initialising first.
Perhaps state that this comment is about what happens in each call of mpam_enable_merge_vmsc_features() Or move the comment to that function.
Quoted 18 lines
+ */
drivers/resctrl/mpam_devices.c +17
-0+static void mpam_enable_merge_features (struct list_head *all_classes_list) +{ +struct mpam_class *class; +struct mpam_component *comp; + +lockdep_assert_held (&mpam_list_lock); + +list_for_each_entry (class, all_classes_list, classes_list) { +list_for_each_entry (comp, &class->components, class_list) +mpam_enable_merge_vmsc_features (comp); + +mpam_enable_init_class_features (class); + +list_for_each_entry (comp, &class->components, class_list) +mpam_enable_merge_class_features (comp); + } +}
James Morse
maintainerRe: [PATCH v2 14/29] arm_mpam: Merge supported features during mpam_enable() into mpam_class
Hi Jonathan,
Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 10 Sep 2025 20:42:54 +0000 James Morse <[email protected]> wrote:
To make a decision about whether to expose an mpam class as a resctrl resource we need to know its overall supported features and properties.
Once we've probed all the resources, we can walk the tree and produce overall values by merging the bitmaps. This eliminates features that are only supported by some MSC that make up a component or class.
Quoted 7 lines
Quoted 4 lines
If bitmap properties are mismatched within a component we cannot support the mismatched feature.
Care has to be taken as vMSC may hold mismatched RIS.
A trivial things inline.
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 27 lines
Quoted 27 lines
drivers/resctrl/mpam_devices.c +27
-0+/* +* Combine two props fields. +* If this is for controls that alias the same resource, it is safe to just +* copy the values over. If two aliasing controls implement the same scheme +* a safe value must be picked. +* For non-aliasing controls, these control different resources, and the +* resulting safe value must be compatible with both. When merging values in +* the tree, all the aliasing resources must be handled first. +* On mismatch, parent is modified. +*/ +static void __props_mismatch (struct mpam_props *parent, +struct mpam_props *child,bool alias) +{ +if (CAN_MERGE_FEAT (parent, child, mpam_feat_cpor_part, alias)) { + parent->cpbm_wd = child->cpbm_wd; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_cpor_part, + cpbm_wd, alias)) { +pr_debug ("%s cleared cpor_part\n" , __func__); +mpam_clear_feature (mpam_feat_cpor_part, &parent->features); + parent->cpbm_wd =0 ; + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_mbw_part, alias)) { + parent->mbw_pbm_bits = child->mbw_pbm_bits; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_mbw_part, + mbw_pbm_bits, alias)) { +pr_debug ("%s cleared mbw_part\n" , __func__);
Quoted 8 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1022
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+mpam_clear_feature (mpam_feat_mbw_part, &parent->features); + parent->mbw_pbm_bits =0 ; + } + +/* bwa_wd is a count of bits, fewer bits means less precision */ +if (alias && !mpam_has_bwa_wd_feature (parent) &&mpam_has_bwa_wd_feature (child)) {Seems like an overly long line given other local wrapping.
Fixed.
Quoted 5 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1026
Quoted 5 lines
drivers/resctrl/mpam_devices.c +4
-0+ parent->bwa_wd = child->bwa_wd; + }else if (MISMATCHED_HELPER (parent, child, mpam_has_bwa_wd_feature, + bwa_wd, alias)) { +pr_debug ("%s took the min bwa_wd\n" , __func__);
These __func__ arguments need to go as pr_fmt has this covered.
Quoted 21 lines
Quoted 19 lines
drivers/resctrl/mpam_devices.c +19
-0+ parent->bwa_wd =min (parent->bwa_wd, child->bwa_wd); + } + +/* For num properties, take the minimum */ +if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_csu, alias)) { + parent->num_csu_mon = child->num_csu_mon; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_msmon_csu, + num_csu_mon, alias)) { +pr_debug ("%s took the min num_csu_mon\n" , __func__); + parent->num_csu_mon =min (parent->num_csu_mon, child->num_csu_mon); + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_mbwu, alias)) { + parent->num_mbwu_mon = child->num_mbwu_mon; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_msmon_mbwu, + num_mbwu_mon, alias)) { +pr_debug ("%s took the min num_mbwu_mon\n" , __func__); + parent->num_mbwu_mon =min (parent->num_mbwu_mon, child->num_mbwu_mon); + }
Quoted 13 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1065
Quoted 11 lines
drivers/resctrl/mpam_devices.c +11
-0+ +/* +* If a vmsc doesn't match class feature/configuration, do the right thing(tm). +* For 'num' properties we can just take the minimum. +* For properties where the mismatched unused bits would make a difference, we +* nobble the class feature, as we can't configure all the resources. +* e.g. The L3 cache is composed of two resources with 13 and 17 portion +* bitmaps respectively. +*/ +static void +__class_props_mismatch (struct mpam_class *class,struct mpam_vmsc *vmsc)I'm not really sure what the __ prefix denotes here.
Just that its the innards of something and needs comprehending as part of its caller.
Quoted 4 lines
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+{ +struct mpam_props *cprops = &class->props; +struct mpam_props *vprops = &vmsc->props; +
Quoted 8 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1074
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+lockdep_assert_held (&mpam_list_lock);/* we modify class */ + +pr_debug ("%s: Merging features for class:0x%lx &= vmsc:0x%lx\n" , +dev_name (&vmsc->msc->pdev->dev), + (long )cprops->features, (long )vprops->features);According to https://docs.kernel.org/core-api/printk-formats.html
should be fine using %x for u16 values. So why dance through a cast to long?
To isolate it from a subsequent change that makes that field a u32, the existence of which means one day it'll be a u64. If it ever gets bigger than unsigned-long, it'll need to be a bitmap array, which would need this code to change. Until then doing, it like this makes changes to the size less churny.
Quoted 10 lines
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ +/* Take the safe value for any common features */ +__props_mismatch (cprops, vprops, false); +} + +static void +__vmsc_props_mismatch (struct mpam_vmsc *vmsc,struct mpam_msc_ris *ris) +{ +struct mpam_props *rprops = &ris->props; +struct mpam_props *vprops = &vmsc->props;
Quoted 8 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1090
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ +lockdep_assert_held (&mpam_list_lock);/* we modify vmsc */ + +pr_debug ("%s: Merging features for vmsc:0x%lx |= ris:0x%lx\n" , +dev_name (&vmsc->msc->pdev->dev), + (long )vprops->features, (long )rprops->features);Same as above comment on casts being unnecessary.
I expect to have to change this in the future.
As these two debug messages have a dev to hand, they should probably use dev_debug() instead of manually printing the dev_name().
Quoted 7 lines
Quoted 7 lines
drivers/resctrl/mpam_devices.c +7
-0+ +/* +* Merge mismatched features - Copy any features that aren't common, +* but take the safe value for any common features. +*/ +__props_mismatch (vprops, rprops, true); +}
Quoted 8 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1103
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ +/* +* Copy the first component's first vMSC's properties and features to the +* class. __class_props_mismatch() will remove conflicts. +* It is not possible to have a class with no components, or a component with +* no resources. The vMSC properties have already been built. If it's not possible do we need the defensive
_or_nulland error checks?
This is just paranoia. I've removed it.
Quoted 19 lines
Quoted 18 lines
+ */
drivers/resctrl/mpam_devices.c +17
-0+static void mpam_enable_init_class_features (struct mpam_class *class) +{ +struct mpam_vmsc *vmsc; +struct mpam_component *comp; + + comp =list_first_entry_or_null (&class->components, + struct mpam_component, class_list); +if (WARN_ON (!comp)) +return ; + + vmsc =list_first_entry_or_null (&comp->vmsc, + struct mpam_vmsc, comp_list); +if (WARN_ON (!vmsc)) +return ; + + class->props = vmsc->props; +}
Quoted 6 lines
Quoted 3 lines
+/*
+ * Merge all the common resource features into class.
+ * vmsc features are bitwise-or'd together, this must be done first.I'm not sure what 'this' is here - I think it's a missing plural that has me confused. Perhaps 'these must be done first.'
The bitwise-or. It's singular because its done for each class/component at a time.
The reason is so that mpam_enable_init_class_features() see's all the features in the first vmsc, not a subset of them. It's because vmsc hold non-overlapping features, which is all to support a platform that has two RIS with different types of control that do the same thing. (made up example:) memory min/max on ingress and memory portions on egress. Both are memory bandwidth for the same hardware block, but for whatever structural reason, it gets exposed as separate RIS.
Rephrased as:
| * vmsc features are bitwise-or'd together as the first step so that | * mpam_enable_init_class_features() can initialise the class with a | * representive set of features.
Quoted 9 lines
Quoted 6 lines
+ * Next the class features are the bitwise-and of all the vmsc features.
+ * Other features are the min/max as appropriate.
+ *
+ * To avoid walking the whole tree twice, theclass->nrdy_usecproperty is
+ * updated when working with the vmsc as it is amax(), and doesn't need
+ * initialising first.Perhaps state that this comment is about what happens in each call of
mpam_enable_merge_vmsc_features()Or move the comment to that function.
Sure. The comment is to try and stop people 'fixing' it to only loop over class->components once. That'll work on 99% of platforms, but discard all the controls on a few strange ones.
Quoted 10 lines
Quoted 10 lines
+ */
drivers/resctrl/mpam_devices.c +9
-0+static void mpam_enable_merge_features (struct list_head *all_classes_list) +{ +struct mpam_class *class; +struct mpam_component *comp; + +lockdep_assert_held (&mpam_list_lock); + +list_for_each_entry (class, all_classes_list, classes_list) { +list_for_each_entry (comp, &class->components, class_list)
Quoted 10 lines
drivers/resctrl/mpam_devices.c static struct platform_driver mpam_msc_driver = { · line 1173
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+mpam_enable_merge_vmsc_features (comp); + +mpam_enable_init_class_features (class); + +list_for_each_entry (comp, &class->components, class_list) +mpam_enable_merge_class_features (comp); + } +}
Thanks,
James
Re: [PATCH v2 14/29] arm_mpam: Merge supported features during mpam_enable() into mpam_class
In reply to James MorseQuoted 9 lines · James Morse
To make a decision about whether to expose an mpam class as a resctrl resource we need to know its overall supported features and properties.
Once we've probed all the resources, we can walk the tree and produce overall values by merging the bitmaps. This eliminates features that are only supported by some MSC that make up a component or class.
Quoted 7 lines
If bitmap properties are mismatched within a component we cannot support the mismatched feature.
Care has to be taken as vMSC may hold mismatched RIS.
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
Thanks.
-Fenghua
James Morse
maintainerPATCH v2 15/29 arm_mpam: Reset MSC controls from cpu hp callbacks
In reply to James MorseWhen a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
---
Changes since RFC:
* Last bitmap write will always be non-zero.
* Dropped READ_ONCE() - teh value can no longer change.
* Write 0 to proporitional stride, remove the bwa_fract variable.
* Removed nested srcu lock, the assert should cover it.
--- drivers/resctrl/mpam_devices.c | 117 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 8 +++ 2 files changed, 125 insertions(+)
drivers/resctrl/mpam_devices.c +117 -0
@@ -7,6 +7,7 @@#include <linux/atomic.h> #include <linux/arm_mpam.h> #include <linux/bitfield.h> +#include <linux/bitmap.h> #include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/cpumask.h>
@@ -777,8 +778,110 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)return 0 ; } +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) +{ +u32 num_words, msb; +u32 bm = ~0 ; +int i; + +lockdep_assert_held (&msc->part_sel_lock); + +if (wd ==0 ) +return ; + +/* +* Write all ~0 to all but the last 32bit-word, which may +* have fewer bits... +*/ + num_words =DIV_ROUND_UP (wd,32 ); +for (i =0 ; i < num_words -1 ; i++, reg +=sizeof (bm)) +__mpam_write_reg (msc, reg, bm); + +/* +* ....and then the last (maybe) partial 32bit word. When wd is a +* multiple of 32, msb should be 31 to write a full 32bit word. +*/ + msb = (wd -1 ) %32 ; + bm =GENMASK (msb,0 ); +__mpam_write_reg (msc, reg, bm); +} + +static void mpam_reset_ris_partid (struct mpam_msc_ris *ris,u16 partid) +{ +struct mpam_msc *msc = ris->vmsc->msc; +struct mpam_props *rprops = &ris->props; + +mpam_assert_srcu_read_lock_held (); + +mutex_lock (&msc->part_sel_lock); +__mpam_part_sel (ris->ris_idx, partid, msc); + +if (mpam_has_feature (mpam_feat_cpor_part, rprops)) +mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , rprops->cpbm_wd); + +if (mpam_has_feature (mpam_feat_mbw_part, rprops)) +mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , rprops->mbw_pbm_bits); + +if (mpam_has_feature (mpam_feat_mbw_min, rprops)) +mpam_write_partsel_reg (msc,MBW_MIN ,0 ); + +if (mpam_has_feature (mpam_feat_mbw_max, rprops)) +mpam_write_partsel_reg (msc,MBW_MAX ,MPAMCFG_MBW_MAX_MAX ); + +if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) +mpam_write_partsel_reg (msc,MBW_PROP ,0 ); +mutex_unlock (&msc->part_sel_lock); +} + +static void mpam_reset_ris (struct mpam_msc_ris *ris) +{ +u16 partid, partid_max; + +mpam_assert_srcu_read_lock_held (); + +if (ris->in_reset_state) +return ; + +spin_lock (&partid_max_lock); + partid_max = mpam_partid_max; +spin_unlock (&partid_max_lock); +for (partid =0 ; partid < partid_max; partid++) +mpam_reset_ris_partid (ris, partid); +} + +static void mpam_reset_msc (struct mpam_msc *msc,bool online) +{ +struct mpam_msc_ris *ris; + +mpam_assert_srcu_read_lock_held (); + +list_for_each_entry_srcu (ris, &msc->ris, msc_list,srcu_read_lock_held (&mpam_srcu)) { +mpam_reset_ris (ris); + +/* +* Set in_reset_state when coming online. The reset state +* for non-zero partid may be lost while the CPUs are offline. +*/ + ris->in_reset_state = online; + } +} +static int mpam_cpu_online (unsigned int cpu) { +int idx; +struct mpam_msc *msc; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!cpumask_test_cpu (cpu, &msc->accessibility)) +continue ; + +if (atomic_fetch_inc (&msc->online_refs) ==0 ) +mpam_reset_msc (msc, true); + } +srcu_read_unlock (&mpam_srcu, idx); +return 0 ; }
@@ -818,6 +921,20 @@ static int mpam_discovery_cpu_online(unsigned int cpu)static int mpam_cpu_offline (unsigned int cpu) { +int idx; +struct mpam_msc *msc; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!cpumask_test_cpu (cpu, &msc->accessibility)) +continue ; + +if (atomic_dec_and_test (&msc->online_refs)) +mpam_reset_msc (msc, false); + } +srcu_read_unlock (&mpam_srcu, idx); +return 0 ; }
drivers/resctrl/mpam_internal.h +8 -0
@@ -5,6 +5,7 @@#define MPAM_INTERNAL_H #include <linux/arm_mpam.h> +#include <linux/atomic.h> #include <linux/cpumask.h> #include <linux/io.h> #include <linux/llist.h>
@@ -45,6 +46,7 @@ struct mpam_msc {struct pcc_mbox_chan *pcc_chan;u32 nrdy_usec;cpumask_t accessibility; +atomic_t online_refs;/* * probe_lock is only taken during discovery. After discovery these
@@ -223,6 +225,7 @@ struct mpam_msc_ris {u8 ris_idx;u64 idr;struct mpam_props props; +bool in_reset_state;cpumask_t affinity;
@@ -242,6 +245,11 @@ struct mpam_msc_ris {extern struct srcu_struct mpam_srcu;extern struct list_head mpam_classes; +static inline void mpam_assert_srcu_read_lock_held (void ) +{ +WARN_ON_ONCE (!srcu_read_lock_held ((&mpam_srcu))); +} +/* System wide partid/pmg values */ extern u16 mpam_partid_max;extern u8 mpam_pmg_max;
Signature · 1 line
2.39.5
Ben Horgan
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
Hi James,
Quoted 88 lines · James Morse
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
CC Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since RFC:
* Last bitmap write will always be non-zero.
* DroppedREAD_ONCE()- teh value can no longer change.
* Write 0 to proporitional stride, remove thebwa_fractvariable.
* Removed nested srcu lock, the assert should cover it.--- drivers/resctrl/mpam_devices.c | 117 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 8 +++ 2 files changed, 125 insertions(+)drivers/resctrl/mpam_devices.c +43
-0@@ -7,6 +7,7 @@#include <linux/atomic.h> #include <linux/arm_mpam.h> #include <linux/bitfield.h> +#include <linux/bitmap.h> #include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/cpumask.h> @@ -777,8 +778,110 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)return 0 ; } +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) +{ +u32 num_words, msb; +u32 bm = ~0 ; +int i; + +lockdep_assert_held (&msc->part_sel_lock); + +if (wd ==0 ) +return ; + +/* +* Write all ~0 to all but the last 32bit-word, which may +* have fewer bits... +*/ + num_words =DIV_ROUND_UP (wd,32 ); +for (i =0 ; i < num_words -1 ; i++, reg +=sizeof (bm)) +__mpam_write_reg (msc, reg, bm); + +/* +* ....and then the last (maybe) partial 32bit word. When wd is a +* multiple of 32, msb should be 31 to write a full 32bit word. +*/ + msb = (wd -1 ) %32 ; + bm =GENMASK (msb,0 ); +__mpam_write_reg (msc, reg, bm); +} + +static void mpam_reset_ris_partid (struct mpam_msc_ris *ris,u16 partid) +{ +struct mpam_msc *msc = ris->vmsc->msc; +struct mpam_props *rprops = &ris->props; + +mpam_assert_srcu_read_lock_held (); + +mutex_lock (&msc->part_sel_lock); +__mpam_part_sel (ris->ris_idx, partid, msc); + +if (mpam_has_feature (mpam_feat_cpor_part, rprops)) +mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , rprops->cpbm_wd); + +if (mpam_has_feature (mpam_feat_mbw_part, rprops))
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 832
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , rprops->mbw_pbm_bits); + +if (mpam_has_feature (mpam_feat_mbw_min, rprops)) +mpam_write_partsel_reg (msc,MBW_MIN ,0 ); + +if (mpam_has_feature (mpam_feat_mbw_max, rprops)) +mpam_write_partsel_reg (msc,MBW_MAX ,MPAMCFG_MBW_MAX_MAX ); + +if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) +mpam_write_partsel_reg (msc,MBW_PROP ,0 );
If mpam_feat_ccap_part is already in enum mpam_device_features then the reset would belong here but I expect it is better just to introduce mpam_feat_ccap_part later (patch 21). I also commented on this feature introduction split on patch 13.
Quoted 14 lines
drivers/resctrl/mpam_devices.c +14
-0+mutex_unlock (&msc->part_sel_lock); +} + +static void mpam_reset_ris (struct mpam_msc_ris *ris) +{ +u16 partid, partid_max; + +mpam_assert_srcu_read_lock_held (); + +if (ris->in_reset_state) +return ; + +spin_lock (&partid_max_lock); + partid_max = mpam_partid_max;
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 856
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+spin_unlock (&partid_max_lock); +for (partid =0 ; partid < partid_max; partid++) +mpam_reset_ris_partid (ris, partid); +} + +static void mpam_reset_msc (struct mpam_msc *msc,bool online) +{ +struct mpam_msc_ris *ris; + +mpam_assert_srcu_read_lock_held ();
Unneeded? Checked in list_for_each_entry_srcu().> +
Quoted 81 lines
drivers/resctrl/mpam_devices.c +39
-0+list_for_each_entry_srcu (ris, &msc->ris, msc_list,srcu_read_lock_held (&mpam_srcu)) { +mpam_reset_ris (ris); + +/* +* Set in_reset_state when coming online. The reset state +* for non-zero partid may be lost while the CPUs are offline. +*/ + ris->in_reset_state = online; + } +} +static int mpam_cpu_online (unsigned int cpu) { +int idx; +struct mpam_msc *msc; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!cpumask_test_cpu (cpu, &msc->accessibility)) +continue ; + +if (atomic_fetch_inc (&msc->online_refs) ==0 ) +mpam_reset_msc (msc, true); + } +srcu_read_unlock (&mpam_srcu, idx); +return 0 ; }@@ -818,6 +921,20 @@ static int mpam_discovery_cpu_online(unsigned int cpu)static int mpam_cpu_offline (unsigned int cpu) { +int idx; +struct mpam_msc *msc; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!cpumask_test_cpu (cpu, &msc->accessibility)) +continue ; + +if (atomic_dec_and_test (&msc->online_refs)) +mpam_reset_msc (msc, false); + } +srcu_read_unlock (&mpam_srcu, idx); +return 0 ; }drivers/resctrl/mpam_internal.h +3
-0@@ -5,6 +5,7 @@#define MPAM_INTERNAL_H #include <linux/arm_mpam.h> +#include <linux/atomic.h> #include <linux/cpumask.h> #include <linux/io.h> #include <linux/llist.h> @@ -45,6 +46,7 @@ struct mpam_msc {struct pcc_mbox_chan *pcc_chan;u32 nrdy_usec;cpumask_t accessibility; +atomic_t online_refs;/* * probe_lock is only taken during discovery. After discovery these @@ -223,6 +225,7 @@ struct mpam_msc_ris {u8 ris_idx;u64 idr;struct mpam_props props; +bool in_reset_state;cpumask_t affinity;@@ -242,6 +245,11 @@ struct mpam_msc_ris {extern struct srcu_struct mpam_srcu;
drivers/resctrl/mpam_internal.h struct mpam_msc_ris { · line 255
Quoted 10 lines
drivers/resctrl/mpam_internal.h +5
-0extern struct list_head mpam_classes; +static inline void mpam_assert_srcu_read_lock_held (void ) +{ +WARN_ON_ONCE (!srcu_read_lock_held ((&mpam_srcu))); +} +/* System wide partid/pmg values */ extern u16 mpam_partid_max;extern u8 mpam_pmg_max;
Thanks,
Ben
Ben Horgan
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
Quoted 33 lines · Ben Horgan
Hi James,
Quoted 30 lines · James Morse
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
CC Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since RFC:
* Last bitmap write will always be non-zero.
* DroppedREAD_ONCE()- teh value can no longer change.
* Write 0 to proporitional stride, remove thebwa_fractvariable.
* Removed nested srcu lock, the assert should cover it.--- drivers/resctrl/mpam_devices.c | 117 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 8 +++ 2 files changed, 125 insertions(+)
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 856
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ +static void mpam_reset_msc (struct mpam_msc *msc,bool online) +{ +struct mpam_msc_ris *ris; + +mpam_assert_srcu_read_lock_held ();Unneeded? Checked in
list_for_each_entry_srcu().> +
If you do get rid of this then that leaves one use of the helper, mpam_assert_srcu_read_lock_held(), and so the helper could go.
Quoted 5 lines
Thanks,
Ben
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
Hi Ben,
Quoted 29 lines · Ben Horgan
Quoted 20 lines · Ben Horgan
Hi James,
Quoted 16 lines · James Morse
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
Quoted 7 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 856
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+static void mpam_reset_msc (struct mpam_msc *msc,bool online) +{ +struct mpam_msc_ris *ris; + +mpam_assert_srcu_read_lock_held ();Unneeded? Checked in
list_for_each_entry_srcu().> +
Quoted 2 lines
If you do get rid of this then that leaves one use of the helper,
mpam_assert_srcu_read_lock_held(), and so the helper could go.
By the end of the series, yes. But there are transiently a few more until then - they get removed and replaced with comments when those functions get called by IPI as lockdep expects the lock to be held by current, which isn't true if you IPI'd.
I'll drop the helper.
Thanks,
James
James Morse
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
In reply to Ben HorganHi Ben,
Quoted 46 lines · Ben Horgan
Quoted 45 lines · James Morse
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
drivers/resctrl/mpam_devices.c +22
-0@@ -777,8 +778,110 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) +static void mpam_reset_ris_partid (struct mpam_msc_ris *ris,u16 partid) +{ +struct mpam_msc *msc = ris->vmsc->msc; +struct mpam_props *rprops = &ris->props; + +mpam_assert_srcu_read_lock_held (); + +mutex_lock (&msc->part_sel_lock); +__mpam_part_sel (ris->ris_idx, partid, msc); + +if (mpam_has_feature (mpam_feat_cpor_part, rprops)) +mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , rprops->cpbm_wd); + +if (mpam_has_feature (mpam_feat_mbw_part, rprops)) +mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , rprops->mbw_pbm_bits); + +if (mpam_has_feature (mpam_feat_mbw_min, rprops)) +mpam_write_partsel_reg (msc,MBW_MIN ,0 ); + +if (mpam_has_feature (mpam_feat_mbw_max, rprops)) +mpam_write_partsel_reg (msc,MBW_MAX ,MPAMCFG_MBW_MAX_MAX ); +
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 832
Quoted 2 lines
drivers/resctrl/mpam_devices.c +2
-0+if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) +mpam_write_partsel_reg (msc,MBW_PROP ,0 );If
mpam_feat_ccap_partis already in enummpam_device_featuresthen the reset would belong here but I expect it is better just to introducempam_feat_ccap_partlater (patch 21). I also commented on this feature introduction split on patch 13.
Yup, this is some knock on cleanup from that change. (I didn't understand what you meant the first time round!)
Quoted 10 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 856
Quoted 8 lines
drivers/resctrl/mpam_devices.c +7
-0+mutex_unlock (&msc->part_sel_lock); +} +static void mpam_reset_msc (struct mpam_msc *msc,bool online) +{ +struct mpam_msc_ris *ris; + +mpam_assert_srcu_read_lock_held ();Unneeded? Checked in
list_for_each_entry_srcu().> +
So it is! I'll rip those out. They were mostly for documentation anyway. There will likely be a few others of these in the series...
Quoted 11 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 868
Quoted 11 lines
drivers/resctrl/mpam_devices.c +11
-0+list_for_each_entry_srcu (ris, &msc->ris, msc_list,srcu_read_lock_held (&mpam_srcu)) { +mpam_reset_ris (ris); + +/* +* Set in_reset_state when coming online. The reset state +* for non-zero partid may be lost while the CPUs are offline. +*/ + ris->in_reset_state = online; + } +} +
Thanks,
James
Re: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
In reply to James MorseQuoted 12 lines · On Wed, 10 Sep 2025 20:42:55 +0000 James Morse <[email protected]> wrote:
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
Quoted 7 lines
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
CC Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>
Just one trivial passing comment from me.
Jonathan
Quoted 18 lines
---
Changes since RFC:
* Last bitmap write will always be non-zero.
* DroppedREAD_ONCE()- teh value can no longer change.
* Write 0 to proporitional stride, remove thebwa_fractvariable.
* Removed nested srcu lock, the assert should cover it.--- drivers/resctrl/mpam_devices.c | 117 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 8 +++ 2 files changed, 125 insertions(+)drivers/resctrl/mpam_devices.c +0
-0
drivers/resctrl/mpam_devices.c static int mpam_discovery_cpu_online(unsigned int cpu) · line 927
Quoted 7 lines
drivers/resctrl/mpam_devices.c +4
-0@@ -818,6 +921,20 @@ static int mpam_discovery_cpu_online(unsigned int cpu)static int mpam_cpu_offline (unsigned int cpu) { +int idx; +struct mpam_msc *msc; + + idx =srcu_read_lock (&mpam_srcu);
Might be worth using
guard(srcu)(&mpam_srcu);
here but only real advantage it bring is in hiding the local idx variable away.
Quoted 12 lines
drivers/resctrl/mpam_devices.c +10
-0+list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!cpumask_test_cpu (cpu, &msc->accessibility)) +continue ; + +if (atomic_dec_and_test (&msc->online_refs)) +mpam_reset_msc (msc, false); + } +srcu_read_unlock (&mpam_srcu, idx); +return 0 ; }
James Morse
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
Hi Jonathan,
Quoted 28 lines · Jonathan Cameron
Quoted 8 lines · On Wed, 10 Sep 2025 20:42:55 +0000 James Morse <[email protected]> wrote:
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
Quoted 8 lines
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
To reset, write the maximum values for all discovered controls.
Just one trivial passing comment from me.
Quoted 6 lines
drivers/resctrl/mpam_devices.c +0
-0@@ -818,6 +921,20 @@ static int mpam_discovery_cpu_online(unsigned int cpu)
Quoted 11 lines
drivers/resctrl/mpam_devices.c static int mpam_discovery_cpu_online(unsigned int cpu) · line 927
Quoted 6 lines
drivers/resctrl/mpam_devices.c +4
-0static int mpam_cpu_offline (unsigned int cpu) { +int idx; +struct mpam_msc *msc; + + idx =srcu_read_lock (&mpam_srcu);Might be worth using
guard(srcu)(&mpam_srcu);
here but only real advantage it bring is in hiding the local idx variable away.
Sure. I did that in a few other places, it looks like I either missed this, or thought it got more complicated later...
Thanks,
James
RE: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
In reply to James MorseHello James,
There is a space in "cpu hp" in the title.
Best reagrards,
Shaopeng TAN
James Morse
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
Hi Shaopeng,
Quoted 1 line · Shaopeng Tan (Fujitsu)
There is a space in "cpu hp" in the title.
Yeah, I'm inconsistent in how I spell that. I'll fix it.
Thanks,
James
A message that is not in the archive (sent off-list or not yet received): [email protected]
James Morse
maintainerRe: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks
Hi Fenghua,
Quoted 22 lines · Fenghua Yu
Hi, James,
Quoted 4 lines · James Morse
When a CPU comes online, it may bring a newly accessible MSC with it. Only the default partid has its value reset by hardware, and even then the MSC might not have been reset since its config was previously dirtyied. e.g. Kexec.
typo: s/dirtyied/dirtied/
Quoted 11 lines
Any in-use partid must have its configuration restored, or reset. In-use partids may be held in caches and evicted later.
MSC are also reset when CPUs are taken offline to cover cases where firmware doesn't reset the MSC over reboot using UEFI, or kexec where there is no firmware involvement.
If the configuration for a RIS has not been touched since it was brought online, it does not need resetting again.
Quoted 8 lines
Quoted 4 lines
To reset, write the maximum values for all discovered controls.
CC Rohit Mathew<[email protected]>Signed-off-by James Morse<[email protected]>Other than the minor comments,
Reviewed-by Fenghua Yu <[email protected]>
Thanks,
Quoted 17 lines
[SNIP]
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 848
Quoted 13 lines
drivers/resctrl/mpam_devices.c +13
-0+static void mpam_reset_ris (struct mpam_msc_ris *ris) +{ + u16 partid, partid_max; + + mpam_assert_srcu_read_lock_held(); + + if (ris->in_reset_state) + return; + + spin_lock(&partid_max_lock); + partid_max = mpam_partid_max; + spin_unlock(&partid_max_lock); + for (partid = 0; partid < partid_max; partid++)* Should
partid_maxbe inclusive? So it's "partid <partid_max+ 1" here?
Quoted 3 lines
MPAM spec says max PARTID is inclusive: "The range of valid PARTIDs is 0 to the maximum PARTID, inclusive. The maximum values of a PARTID implemented by different MSCs need not be the same".
Hmmm, if partid_max is 0 then this loop should run only once, so yet.
Thanks,
James
James Morse
maintainerPATCH v2 16/29 arm_mpam: Add a helper to touch an MSC from any CPU
In reply to James MorseResetting RIS entries from the cpuhp callback is easy as the callback occurs on the correct CPU. This won't be true for any other caller that wants to reset or configure an MSC.
Add a helper that schedules the provided function if necessary.
Callers should take the cpuhp lock to prevent the cpuhp callbacks from changing the MSC state.
--- drivers/resctrl/mpam_devices.c | 37 +++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-)
drivers/resctrl/mpam_devices.c +34 -3
@@ -833,20 +833,51 @@ static void mpam_reset_ris_partid(struct mpam_msc_ris *ris, u16 partid)mutex_unlock (&msc->part_sel_lock); } -static void mpam_reset_ris (struct mpam_msc_ris *ris) +/* +* Called via smp_call_on_cpu() to prevent migration, while still being +* pre-emptible. +*/ +static int mpam_reset_ris (void *arg) {u16 partid, partid_max; +struct mpam_msc_ris *ris = arg;mpam_assert_srcu_read_lock_held ();if (ris->in_reset_state) -return ; +return 0 ;spin_lock (&partid_max_lock); partid_max = mpam_partid_max;spin_unlock (&partid_max_lock);for (partid =0 ; partid < partid_max; partid++)mpam_reset_ris_partid (ris, partid); + +return 0 ; +} + +/* +* Get the preferred CPU for this MSC. If it is accessible from this CPU, +* this CPU is preferred. This can be preempted/migrated, it will only result +* in more work. +*/ +static int mpam_get_msc_preferred_cpu (struct mpam_msc *msc) +{ +int cpu =raw_smp_processor_id (); + +if (cpumask_test_cpu (cpu, &msc->accessibility)) +return cpu; + +return cpumask_first_and (&msc->accessibility, cpu_online_mask); +} + +static int mpam_touch_msc (struct mpam_msc *msc,int (*fn)(void *a),void *arg) +{ +lockdep_assert_irqs_enabled (); +lockdep_assert_cpus_held (); +mpam_assert_srcu_read_lock_held (); + +return smp_call_on_cpu (mpam_get_msc_preferred_cpu (msc), fn, arg, true); }static void mpam_reset_msc (struct mpam_msc *msc,bool online)
@@ -856,7 +887,7 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online)mpam_assert_srcu_read_lock_held ();list_for_each_entry_srcu (ris, &msc->ris, msc_list,srcu_read_lock_held (&mpam_srcu)) { -mpam_reset_ris (ris); +mpam_touch_msc (msc, &mpam_reset_ris, ris);/* * Set in_reset_state when coming online. The reset state
Signature · 1 line
2.39.5
Re: [PATCH v2 16/29] arm_mpam: Add a helper to touch an MSC from any CPU
Quoted 11 lines · On Wed, 10 Sep 2025 20:42:56 +0000 James Morse <[email protected]> wrote:
Resetting RIS entries from the cpuhp callback is easy as the callback occurs on the correct CPU. This won't be true for any other caller that wants to reset or configure an MSC.
Add a helper that schedules the provided function if necessary.
Callers should take the cpuhp lock to prevent the cpuhp callbacks from changing the MSC state.
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
James Morse
maintainerRe: [PATCH v2 16/29] arm_mpam: Add a helper to touch an MSC from any CPU
Hi Jonathan,
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Wed, 10 Sep 2025 20:42:56 +0000 James Morse <[email protected]> wrote:
Resetting RIS entries from the cpuhp callback is easy as the callback occurs on the correct CPU. This won't be true for any other caller that wants to reset or configure an MSC.
Add a helper that schedules the provided function if necessary.
Quoted 7 lines
Quoted 5 lines
Callers should take the cpuhp lock to prevent the cpuhp callbacks from changing the MSC state.
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
James
Re: [PATCH v2 16/29] arm_mpam: Add a helper to touch an MSC from any CPU
In reply to James MorseQuoted 11 lines · James Morse
Resetting RIS entries from the cpuhp callback is easy as the callback occurs on the correct CPU. This won't be true for any other caller that wants to reset or configure an MSC.
Add a helper that schedules the provided function if necessary.
Callers should take the cpuhp lock to prevent the cpuhp callbacks from changing the MSC state.
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
Thanks.
-Fenghua
[SNIP]
James Morse
maintainerPATCH v2 17/29 arm_mpam: Extend reset logic to allow devices to be reset any time
In reply to James Morsecpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.
Add a helper to reset RIS via their class. Call this from mpam_disable(), which can be scheduled from the error interrupt handler.
---
Changes since v1:
* more complete use of _srcu helpers.
* Use guard macro for srcu.
* Dropped a might_sleep() - something else will bark.
--- drivers/resctrl/mpam_devices.c | 56 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +54 -2
@@ -842,8 +842,6 @@ static int mpam_reset_ris(void *arg)u16 partid, partid_max;struct mpam_msc_ris *ris = arg; -mpam_assert_srcu_read_lock_held (); -if (ris->in_reset_state)return 0 ;
@@ -1340,8 +1338,56 @@ static void mpam_enable_once(void) mpam_partid_max + 1, mpam_pmg_max + 1); } +static void mpam_reset_component_locked (struct mpam_component *comp) +{ +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (vmsc, &comp->vmsc, comp_list, +srcu_read_lock_held (&mpam_srcu)) { + msc = vmsc->msc; + +list_for_each_entry_srcu (ris, &vmsc->ris, vmsc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!ris->in_reset_state) +mpam_touch_msc (msc, mpam_reset_ris, ris); + ris->in_reset_state = true; + } + } +} + +static void mpam_reset_class_locked (struct mpam_class *class) +{ +struct mpam_component *comp; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (comp, &class->components, class_list, +srcu_read_lock_held (&mpam_srcu)) +mpam_reset_component_locked (comp); +} + +static void mpam_reset_class (struct mpam_class *class) +{ +cpus_read_lock (); +mpam_reset_class_locked (class); +cpus_read_unlock (); +} + +/* +* Called in response to an error IRQ. +* All of MPAMs errors indicate a software bug, restore any modified +* controls to their reset values. +*/ void mpam_disable (struct work_struct *ignored) { +int idx; +struct mpam_class *class;struct mpam_msc *msc, *tmp;mutex_lock (&mpam_cpuhp_state_lock);
@@ -1351,6 +1397,12 @@ void mpam_disable(struct work_struct *ignored) }mutex_unlock (&mpam_cpuhp_state_lock); + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (class, &mpam_classes, classes_list, +srcu_read_lock_held (&mpam_srcu)) +mpam_reset_class (class); +srcu_read_unlock (&mpam_srcu, idx); +mutex_lock (&mpam_list_lock);list_for_each_entry_safe (msc, tmp, &mpam_all_msc, all_msc_list)mpam_msc_destroy (msc);
Signature · 1 line
2.39.5
Re: [PATCH v2 17/29] arm_mpam: Extend reset logic to allow devices to be reset any time
Hi James,
Quoted 24 lines · James Morse
cpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.Add a helper to reset RIS via their class. Call this from
mpam_disable(), which can be scheduled from the error interrupt handler.Signed-off-by James Morse <[email protected]>---
Changes since v1:
* more complete use of_srcuhelpers.
* Use guard macro for srcu.
* Dropped amight_sleep()- something else will bark.--- drivers/resctrl/mpam_devices.c | 56 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +0
-0
drivers/resctrl/mpam_devices.c static int mpam_reset_ris(void *arg) · line 846
Quoted 5 lines
drivers/resctrl/mpam_devices.c +0
-2@@ -842,8 +842,6 @@ static int mpam_reset_ris(void *arg)u16 partid, partid_max;struct mpam_msc_ris *ris = arg; -mpam_assert_srcu_read_lock_held (); -
Remove where it is introduced. There is already one in mpam_reset_ris_partid() at that time.
drivers/resctrl/mpam_devices.c static int mpam_reset_ris(void *arg) · line 846
Quoted 2 lines
drivers/resctrl/mpam_devices.c +0
-0if (ris->in_reset_state)return 0 ;
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 17/29] arm_mpam: Extend reset logic to allow devices to be reset any time
Hi Ben,
Quoted 17 lines · Ben Horgan
Quoted 16 lines · James Morse
cpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.Add a helper to reset RIS via their class. Call this from
mpam_disable(), which can be scheduled from the error interrupt handler.drivers/resctrl/mpam_devices.c +0
-0@@ -842,8 +842,6 @@ static int mpam_reset_ris(void *arg)u16 partid, partid_max;struct mpam_msc_ris *ris = arg;
Quoted 5 lines
drivers/resctrl/mpam_devices.c static int mpam_reset_ris(void *arg) · line 846
Quoted 2 lines
drivers/resctrl/mpam_devices.c +0
-2-mpam_assert_srcu_read_lock_held (); -Remove where it is introduced. There is already one in
mpam_reset_ris_partid()at that time.
Mmmm, this should really have been replaced with a comment.
I prefer each function to have an assert like this as documentation. In this case, a new caller may miss the lock, but always hit the 'in_reset_state' case during testing, and be caught out when a call to mpam_reset_ris_partid() occurs. Having documentation comments that can also bark at you when you ignore them is really handy!
It's removed in this patch because calling it via mpam_touch_msc() puts it behind an call to schedule, and lockdep expects 'current' to be the one holding the lock.
I'll add the comment. Looks like it just got dropped when mpam_touch_msc() stopped using an IPI...
Quoted 4 lines
drivers/resctrl/mpam_devices.c static int mpam_reset_ris(void *arg) · line 846
Quoted 2 lines
drivers/resctrl/mpam_devices.c +0
-0if (ris->in_reset_state)return 0 ;Reviewed-by Ben Horgan <[email protected]>
Thanks!
James
Re: [PATCH v2 17/29] arm_mpam: Extend reset logic to allow devices to be reset any time
In reply to James MorseQuoted 6 lines · On Wed, 10 Sep 2025 20:42:57 +0000 James Morse <[email protected]> wrote:
cpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.
Quoted 8 lines
Add a helper to reset RIS via their class. Call this from
mpam_disable(), which can be scheduled from the error interrupt handler.Signed-off-by James Morse <[email protected]>---
Changes since v1:
* more complete use of_srcuhelpers.
* Use guard macro for srcu.
I'm not seeing a strong reason for doing this for the case here and not for cases in earlier patches like in mpam_cpu_online() I'm a fan of using these broadly in a given code base, so would guard(srcu) in those earlier patches as well.
Anyhow, one other trivial thing inline that you can ignore or not as you wish.
Quoted 24 lines
* Dropped a
might_sleep()- something else will bark.--- drivers/resctrl/mpam_devices.c | 56 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +2
-2@@ -842,8 +842,6 @@ static int mpam_reset_ris(void *arg)u16 partid, partid_max;struct mpam_msc_ris *ris = arg; -mpam_assert_srcu_read_lock_held (); -if (ris->in_reset_state)return 0 ;@@ -1340,8 +1338,56 @@ static void mpam_enable_once(void) mpam_partid_max + 1, mpam_pmg_max + 1); } +static void mpam_reset_component_locked (struct mpam_component *comp) +{
drivers/resctrl/mpam_devices.c static void mpam_enable_once(void) · line 1352
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (vmsc, &comp->vmsc, comp_list, +srcu_read_lock_held (&mpam_srcu)) { + msc = vmsc->msc;
Might be worth reducing scope of msc and ris
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+ +list_for_each_entry_srcu (ris, &vmsc->ris, vmsc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!ris->in_reset_state) +mpam_touch_msc (msc, mpam_reset_ris, ris); + ris->in_reset_state = true; + } + } +}
James Morse
maintainerRe: [PATCH v2 17/29] arm_mpam: Extend reset logic to allow devices to be reset any time
Hi Jonathan,
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Wed, 10 Sep 2025 20:42:57 +0000 James Morse <[email protected]> wrote:
cpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.
Quoted 8 lines
Quoted 5 lines
Add a helper to reset RIS via their class. Call this from
mpam_disable(), which can be scheduled from the error interrupt handler.Changes since v1:
* Use guard macro for srcu.I'm not seeing a strong reason for doing this for the case here and not for cases in earlier patches like in
mpam_cpu_online()
I just missed them...
Quoted 3 lines
I'm a fan of using
these broadly in a given code base, so would guard(srcu) in those earlier patches as well.
I've done the online/offline - I'll take another pass through them.
Quoted 3 lines
Anyhow, one other trivial thing inline that you can ignore or not as you wish.
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 5 lines
Quoted 4 lines
drivers/resctrl/mpam_devices.c +0
-0
Quoted 15 lines
drivers/resctrl/mpam_devices.c static void mpam_enable_once(void) · line 1349
Quoted 13 lines
drivers/resctrl/mpam_devices.c +12
-0@@ -1340,8 +1338,56 @@ static void mpam_enable_once(void) +static void mpam_reset_component_locked (struct mpam_component *comp) +{ +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (vmsc, &comp->vmsc, comp_list, +srcu_read_lock_held (&mpam_srcu)) { + msc = vmsc->msc;Might be worth reducing scope of msc and ris
Sure,
Thanks,
James
Fenghua Yu
reviewerRe: [PATCH v2 17/29] arm_mpam: Extend reset logic to allow devices to be reset any time
In reply to James MorseHi, James,
Quoted 36 lines · James Morse
cpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.Add a helper to reset RIS via their class. Call this from
mpam_disable(), which can be scheduled from the error interrupt handler.Signed-off-by James Morse <[email protected]>---
Changes since v1:
* more complete use of_srcuhelpers.
* Use guard macro for srcu.
* Dropped amight_sleep()- something else will bark.--- drivers/resctrl/mpam_devices.c | 56 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +0
-2@@ -842,8 +842,6 @@ static int mpam_reset_ris(void *arg)u16 partid, partid_max;struct mpam_msc_ris *ris = arg; -mpam_assert_srcu_read_lock_held (); -if (ris->in_reset_state)return 0 ;@@ -1340,8 +1338,56 @@ static void mpam_enable_once(void) mpam_partid_max + 1, mpam_pmg_max + 1); }
drivers/resctrl/mpam_devices.c static void mpam_enable_once(void) · line 1350
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+static void mpam_reset_component_locked (struct mpam_component *comp) +{ +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +
Nested locks on mpam_srcu in this call chain:
mpam_disable() -> mpam_reset_class() -> mpam_reset_class_locked() -> mpam_component_locked()
There are redundant locks on mpam_srcu in mpam_disabled(), mpam_reset_class_locked(), and mpam_reset_component_locked().
It's better to guard mpam_srcu only in the top function mpam_disable() for simpler logic and lower overhead.
Quoted 45 lines
drivers/resctrl/mpam_devices.c +38
-0list_for_each_entry_srcu (vmsc, &comp->vmsc, comp_list, + srcu_read_lock_held(&mpam_srcu)) { + msc = vmsc->msc; + +list_for_each_entry_srcu (ris, &vmsc->ris, vmsc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!ris->in_reset_state) +mpam_touch_msc (msc, mpam_reset_ris, ris); + ris->in_reset_state = true; + } + } +} + +static void mpam_reset_class_locked (struct mpam_class *class) +{ +struct mpam_component *comp; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (comp, &class->components, class_list, +srcu_read_lock_held (&mpam_srcu)) +mpam_reset_component_locked (comp); +} + +static void mpam_reset_class (struct mpam_class *class) +{ +cpus_read_lock (); +mpam_reset_class_locked (class); +cpus_read_unlock (); +} + +/* +* Called in response to an error IRQ. +* All of MPAMs errors indicate a software bug, restore any modified +* controls to their reset values. +*/ void mpam_disable (struct work_struct *ignored) { +int idx; +struct mpam_class *class;struct mpam_msc *msc, *tmp;mutex_lock(&mpam_cpuhp_state_lock);
drivers/resctrl/mpam_devices.c void mpam_disable(struct work_struct *ignored) · line 1400
Quoted 4 lines
drivers/resctrl/mpam_devices.c +1
-0@@ -1351,6 +1397,12 @@ void mpam_disable(struct work_struct *ignored) }mutex_unlock (&mpam_cpuhp_state_lock); + idx =srcu_read_lock (&mpam_srcu);
It's better to change to guard(srcu)(&mpam_srcu);
drivers/resctrl/mpam_devices.c void mpam_disable(struct work_struct *ignored) · line 1408
Quoted 8 lines
drivers/resctrl/mpam_devices.c +5
-0+list_for_each_entry_srcu (class, &mpam_classes, classes_list, +srcu_read_lock_held (&mpam_srcu)) +mpam_reset_class (class); +srcu_read_unlock (&mpam_srcu, idx); +mutex_lock (&mpam_list_lock);list_for_each_entry_safe (msc, tmp, &mpam_all_msc, all_msc_list)mpam_msc_destroy (msc);
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 17/29] arm_mpam: Extend reset logic to allow devices to be reset any time
Hi Fenghua,
Quoted 31 lines · Fenghua Yu
Quoted 18 lines · James Morse
cpuhp callbacks aren't the only time the MSC configuration may need to be reset. Resctrl has an API call to reset a class.
If an MPAM error interrupt arrives it indicates the driver has misprogrammed an MSC. The safest thing to do is reset all the MSCs and disable MPAM.Add a helper to reset RIS via their class. Call this from
mpam_disable(), which can be scheduled from the error interrupt handler.drivers/resctrl/mpam_devices.c +0
-0@@ -1340,8 +1338,56 @@ static void
mpam_enable_once(void)mpam_partid_max+ 1,mpam_pmg_max+ 1);
}
+static voidmpam_reset_component_locked(struct mpam_component *comp)drivers/resctrl/mpam_devices.c static void mpam_enable_once(void) · line 1353
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+{ + struct mpam_msc *msc; + struct mpam_vmsc *vmsc; + struct mpam_msc_ris *ris; + + lockdep_assert_cpus_held(); + + guard(srcu)(&mpam_srcu); +Nested locks on
mpam_srcuin this call chain:
Quoted 1 line
mpam_disable()->mpam_reset_class()->mpam_reset_class_locked()->mpam_component_locked()
These are allowed to nest like this.
Quoted 5 lines
There are redundant locks on
mpam_srcuinmpam_disabled(),mpam_reset_class_locked(), andmpam_reset_component_locked().It's better to guard
mpam_srcuonly in the top functionmpam_disable()for simpler logic and lower overhead.
These things don't block, so there no real overhead. Shuffling them around to avoid the harmless nesting would likely complicate the flow, not simplify it.
In the reset case you point at here, the resctrl code would need to take the srcu lock before calling it - which is exposing the innards of what that function does.
Quoted 23 lines
Quoted 23 lines
list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list, + srcu_read_lock_held(&mpam_srcu)){ + msc =vmsc->msc;drivers/resctrl/mpam_devices.c +14
-0+ + list_for_each_entry_srcu(ris, &vmsc->ris, vmsc_list, + srcu_read_lock_held(&mpam_srcu)) { + if (!ris->in_reset_state) + mpam_touch_msc(msc, mpam_reset_ris, ris); + ris->in_reset_state = true; + } + } +} +/* +* Called in response to an error IRQ. +* All of MPAMs errors indicate a software bug, restore any modified +* controls to their reset values. +*/ void
mpam_disable(struct work_struct *ignored)
{
+ int idx;
+ structmpam_class*class;
Quoted 8 lines
drivers/resctrl/mpam_devices.c void mpam_disable(struct work_struct *ignored) · line 1399
Quoted 6 lines
struct
mpam_msc*msc, *tmp;
mutex_lock(&mpam_cpuhp_state_lock);drivers/resctrl/mpam_devices.c +0
-0@@ -1351,6 +1397,12 @@ void mpam_disable(struct work_struct *ignored) } mutex_unlock(&mpam_cpuhp_state_lock); + idx = srcu_read_lock(&mpam_srcu);It's better to change to guard(srcu)(&mpam_srcu);
For this one - absolutely not.
The guard() thing allows the toolchain to decide when to drop the lock. Further down in this same function is an attempt to free the memory that got deferred. Guess what happens if you call synchronize_srcu() while still in an srcu read side section....
Quoted 8 lines
drivers/resctrl/mpam_devices.c void mpam_disable(struct work_struct *ignored) · line 1408
Quoted 8 lines
drivers/resctrl/mpam_devices.c +5
-0+ list_for_each_entry_srcu(class, &mpam_classes, classes_list, + srcu_read_lock_held(&mpam_srcu)) + mpam_reset_class(class); + srcu_read_unlock(&mpam_srcu, idx); + mutex_lock(&mpam_list_lock); list_for_each_entry_safe(msc, tmp, &mpam_all_msc, all_msc_list) mpam_msc_destroy(msc);
Thanks,
James
James Morse
maintainerPATCH v2 18/29 arm_mpam: Register and enable IRQs
In reply to James MorseRegister and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead, mpam_disable() gets scheduled.
Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the mpam_disable() path can be called asynchronously, which will walk structures sized by max_partid. Ensure this size is fixed before the interrupt is requested.
---
Changes since v1:
* Made mpam_unregister_irqs() safe to race with itself.
* Removed threaded interrupts.
* Schedule mpam_disable() from cpuhp callback in the case of an error.
* Added mpam_disable_reason.
* Use alloc_percpu()
Changes since RFC:
* Use guard marco when walking srcu list.
* Use INTEN macro for enabling interrupts.
* Move partid_max_published up earlier in mpam_enable_once().
--- drivers/resctrl/mpam_devices.c | 277 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 10 ++ 2 files changed, 284 insertions(+), 3 deletions(-)
drivers/resctrl/mpam_devices.c +274 -3
@@ -14,6 +14,9 @@#include <linux/device.h> #include <linux/errno.h> #include <linux/gfp.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> #include <linux/mutex.h>
@@ -166,6 +169,24 @@ static u64 mpam_msc_read_idr(struct mpam_msc *msc)return (idr_high <<32 ) | idr_low; } +static void mpam_msc_zero_esr (struct mpam_msc *msc) +{ +__mpam_write_reg (msc,MPAMF_ESR ,0 ); +if (msc->has_extd_esr) +__mpam_write_reg (msc,MPAMF_ESR +4 ,0 ); +} + +static u64 mpam_msc_read_esr (struct mpam_msc *msc) +{ +u64 esr_high =0 , esr_low; + + esr_low =__mpam_read_reg (msc,MPAMF_ESR ); +if (msc->has_extd_esr) + esr_high =__mpam_read_reg (msc,MPAMF_ESR +4 ); + +return (esr_high <<32 ) | esr_low; +} +static void __mpam_part_sel_raw (u32 partsel,struct mpam_msc *msc) {lockdep_assert_held (&msc->part_sel_lock);
@@ -754,6 +775,7 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) pmg_max =FIELD_GET (MPAMF_IDR_PMG_MAX , idr); msc->partid_max =min (msc->partid_max, partid_max); msc->pmg_max =min (msc->pmg_max, pmg_max); + msc->has_extd_esr =FIELD_GET (MPAMF_IDR_HAS_EXTD_ESR , idr);mutex_lock (&mpam_list_lock); ris =mpam_get_or_create_ris (msc, ris_idx);
@@ -768,6 +790,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)mutex_unlock (&msc->part_sel_lock); } +/* Clear any stale errors */ +mpam_msc_zero_esr (msc); +spin_lock (&partid_max_lock); mpam_partid_max =min (mpam_partid_max, msc->partid_max); mpam_pmg_max =min (mpam_pmg_max, msc->pmg_max);
@@ -895,6 +920,13 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void _enable_percpu_irq (void *_irq) +{ +int *irq = _irq; + +enable_percpu_irq (*irq,IRQ_TYPE_NONE ); +} +static int mpam_cpu_online (unsigned int cpu) {int idx;
@@ -906,6 +938,9 @@ static int mpam_cpu_online(unsigned int cpu)if (!cpumask_test_cpu (cpu, &msc->accessibility))continue ; +if (msc->reenable_error_ppi) +_enable_percpu_irq (&msc->reenable_error_ppi); +if (atomic_fetch_inc (&msc->online_refs) ==0 )mpam_reset_msc (msc, true); }
@@ -959,6 +994,9 @@ static int mpam_cpu_offline(unsigned int cpu)if (!cpumask_test_cpu (cpu, &msc->accessibility))continue ; +if (msc->reenable_error_ppi) +disable_percpu_irq (msc->reenable_error_ppi); +if (atomic_dec_and_test (&msc->online_refs))mpam_reset_msc (msc, false); }
@@ -985,6 +1023,51 @@ static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online),mutex_unlock (&mpam_cpuhp_state_lock); } +static int __setup_ppi (struct mpam_msc *msc) +{ +int cpu; +struct device *dev = &msc->pdev->dev; + + msc->error_dev_id = alloc_percpu(struct mpam_msc *); +if (!msc->error_dev_id) +return -ENOMEM ; + +for_each_cpu (cpu, &msc->accessibility) { +struct mpam_msc *empty = *per_cpu_ptr (msc->error_dev_id, cpu); + +if (empty) { +dev_err_once (dev,"MSC shares PPI with %s!\n" , +dev_name (&empty->pdev->dev)); +return -EBUSY ; + } + *per_cpu_ptr (msc->error_dev_id, cpu) = msc; + } + +return 0 ; +} + +static int mpam_msc_setup_error_irq (struct mpam_msc *msc) +{ +int irq; + + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +return 0 ; + +/* Allocate and initialise the percpu device pointer for PPI */ +if (irq_is_percpu (irq)) +return __setup_ppi (msc); + +/* sanity check: shared interrupts can be routed anywhere? */ +if (!cpumask_equal (&msc->accessibility, cpu_possible_mask)) { +pr_err_once ("msc:%u is a private resource with a shared error interrupt" , + msc->id); +return -EINVAL ; + } + +return 0 ; +} +/* * An MSC can control traffic from a set of CPUs, but may only be accessible * from a (hopefully wider) set of CPUs. The common reason for this is power
@@ -1060,6 +1143,10 @@ static int mpam_msc_drv_probe(struct platform_device *pdev)break ; } + err =mpam_msc_setup_error_irq (msc); +if (err) +break ; +if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &msc->pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;
@@ -1318,11 +1405,172 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) } } +static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" , + [1 ] ="PARTID_SEL_Range" , + [2 ] ="Req_PARTID_Range" , + [3 ] ="MSMONCFG_ID_RANGE" , + [4 ] ="Req_PMG_Range" , + [5 ] ="Monitor_Range" , + [6 ] ="intPARTID_Range" , + [7 ] ="Unexpected_INTERNAL" , + [8 ] ="Undefined_RIS_PART_SEL" , + [9 ] ="RIS_No_Control" , + [10 ] ="Undefined_RIS_MON_SEL" , + [11 ] ="RIS_No_Monitor" , + [12 ...15 ] ="Reserved" +}; + +static int mpam_enable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); + +return 0 ; +} + +/* This can run in mpam_disable(), and the interrupt handler on the same CPU */ +static int mpam_disable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,0 ); + +return 0 ; +} + +static irqreturn_t __mpam_irq_handler (int irq,struct mpam_msc *msc) +{ +u64 reg; +u16 partid; +u8 errcode, pmg, ris; + +if (WARN_ON_ONCE (!msc) || +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), + &msc->accessibility))) +return IRQ_NONE ; + + reg =mpam_msc_read_esr (msc); + + errcode =FIELD_GET (MPAMF_ESR_ERRCODE , reg); +if (!errcode) +return IRQ_NONE ; + +/* Clear level triggered irq */ +mpam_msc_zero_esr (msc); + + partid =FIELD_GET (MPAMF_ESR_PARTID_MON , reg); + pmg =FIELD_GET (MPAMF_ESR_PMG , reg); + ris =FIELD_GET (MPAMF_ESR_RIS , reg); + +pr_err_ratelimited ("error irq from msc:%u '%s', partid:%u, pmg: %u, ris: %u\n" , + msc->id, mpam_errcode_names[errcode], partid, pmg, + ris); + +/* Disable this interrupt. */ +mpam_disable_msc_ecr (msc); + +/* +* Schedule the teardown work. Don't use a threaded IRQ as we can't +* unregister the interrupt from the threaded part of the handler. +*/ + mpam_disable_reason ="hardware error interrupt" ; +schedule_work (&mpam_broken_work); + +return IRQ_HANDLED ; +} + +static irqreturn_t mpam_ppi_handler (int irq,void *dev_id) +{ +struct mpam_msc *msc = *(struct mpam_msc **)dev_id; + +return __mpam_irq_handler (irq, msc); +} + +static irqreturn_t mpam_spi_handler (int irq,void *dev_id) +{ +struct mpam_msc *msc = dev_id; + +return __mpam_irq_handler (irq, msc); +} + +static int mpam_register_irqs (void ) +{ +int err, irq; +struct mpam_msc *msc; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +/* The MPAM spec says the interrupt can be SPI, PPI or LPI */ +/* We anticipate sharing the interrupt with other MSCs */ +if (irq_is_percpu (irq)) { + err =request_percpu_irq (irq, &mpam_ppi_handler, +"mpam:msc:error" , + msc->error_dev_id); +if (err) +return err; + + msc->reenable_error_ppi = irq; +smp_call_function_many (&msc->accessibility, + &_enable_percpu_irq, &irq, + true); + }else { + err =devm_request_irq (&msc->pdev->dev,irq, + &mpam_spi_handler,IRQF_SHARED , +"mpam:msc:error" , msc); +if (err) +return err; + } + +set_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags); +mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); +set_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags); + } + +return 0 ; +} + +static void mpam_unregister_irqs (void ) +{ +int irq, idx; +struct mpam_msc *msc; + +cpus_read_lock (); +/* take the lock as free_irq() can sleep */ + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +if (test_and_clear_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags)) +mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); + +if (test_and_clear_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags)) { +if (irq_is_percpu (irq)) { + msc->reenable_error_ppi =0 ; +free_percpu_irq (irq, msc->error_dev_id); + }else { +devm_free_irq (&msc->pdev->dev, irq, msc); + } + } + } +srcu_read_unlock (&mpam_srcu, idx); +cpus_read_unlock (); +} +static void mpam_enable_once (void ) { -mutex_lock (&mpam_list_lock); -mpam_enable_merge_features (&mpam_classes); -mutex_unlock (&mpam_list_lock); +int err;/* * Once the cpuhp callbacks have been changed, mpam_partid_max can no
@@ -1332,6 +1580,27 @@ static void mpam_enable_once(void) partid_max_published = true;spin_unlock (&partid_max_lock); +/* +* If all the MSC have been probed, enabling the IRQs happens next. +* That involves cross-calling to a CPU that can reach the MSC, and +* the locks must be taken in this order: +*/ +cpus_read_lock (); +mutex_lock (&mpam_list_lock); +mpam_enable_merge_features (&mpam_classes); + + err =mpam_register_irqs (); +if (err) +pr_warn ("Failed to register irqs: %d\n" , err); + +mutex_unlock (&mpam_list_lock); +cpus_read_unlock (); + +if (err) { +schedule_work (&mpam_broken_work); +return ; + } +mpam_register_cpuhp_callbacks (mpam_cpu_online, mpam_cpu_offline); printk(KERN_INFO "MPAM enabled with %u PARTIDs and %u PMGs\n",
@@ -1397,6 +1666,8 @@ void mpam_disable(struct work_struct *ignored) }mutex_unlock (&mpam_cpuhp_state_lock); +mpam_unregister_irqs (); + idx =srcu_read_lock (&mpam_srcu);list_for_each_entry_srcu (class, &mpam_classes, classes_list,srcu_read_lock_held (&mpam_srcu))
drivers/resctrl/mpam_internal.h +10 -0
@@ -32,6 +32,10 @@ struct mpam_garbage {struct platform_device *pdev; }; +/* Bit positions for error_irq_flags */ +#define MPAM_ERROR_IRQ_REQUESTED 0 +#define MPAM_ERROR_IRQ_HW_ENABLED 1 +struct mpam_msc {/* member of mpam_all_msc */ struct list_head all_msc_list;
@@ -46,6 +50,11 @@ struct mpam_msc {struct pcc_mbox_chan *pcc_chan;u32 nrdy_usec;cpumask_t accessibility; +bool has_extd_esr; + +int reenable_error_ppi; +struct mpam_msc *__percpu *error_dev_id; +atomic_t online_refs;/*
@@ -54,6 +63,7 @@ struct mpam_msc {*/ struct mutex probe_lock;bool probed; +unsigned long error_irq_flags;u16 partid_max;u8 pmg_max;unsigned long ris_idxs;
Signature · 1 line
2.39.5
Re: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
Quoted 13 lines · On Wed, 10 Sep 2025 20:42:58 +0000 James Morse <[email protected]> wrote:
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Quoted 7 lines
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.CC Rohit Mathew <[email protected]>Tested-by Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>
A few comments inline.
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1409
Quoted 6 lines
drivers/resctrl/mpam_devices.c +2
-0@@ -1318,11 +1405,172 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) } } +static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" ,
I think you had a bunch of defines for these in an earlier patch. Can we use that to index here instead of [0] etc.
Quoted 11 lines
drivers/resctrl/mpam_devices.c +11
-0+ [1] = "PARTID_SEL_Range", + [2] = "Req_PARTID_Range", + [3] = "MSMONCFG_ID_RANGE", + [4] = "Req_PMG_Range", + [5] = "Monitor_Range", + [6] = "intPARTID_Range", + [7] = "Unexpected_INTERNAL", + [8] = "Undefined_RIS_PART_SEL", + [9] = "RIS_No_Control", + [10] = "Undefined_RIS_MON_SEL", + [11] = "RIS_No_Monitor",
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list)
Quoted 10 lines
drivers/resctrl/mpam_devices.c +8
-0+ [12 ... 15] = "Reserved" +}; +static void mpam_unregister_irqs (void ) +{ +int irq, idx; +struct mpam_msc *msc; + +cpus_read_lock ();
guard(cpus_read_lock)(); guard(srcu)(&mpam_srcu);
Quoted 39 lines
drivers/resctrl/mpam_devices.c +27
-3+/* take the lock as free_irq() can sleep */ + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +if (test_and_clear_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags)) +mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); + +if (test_and_clear_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags)) { +if (irq_is_percpu (irq)) { + msc->reenable_error_ppi =0 ; +free_percpu_irq (irq, msc->error_dev_id); + }else { +devm_free_irq (&msc->pdev->dev, irq, msc); + } + } + } +srcu_read_unlock (&mpam_srcu, idx); +cpus_read_unlock (); +} +static void mpam_enable_once (void ) { -mutex_lock (&mpam_list_lock); -mpam_enable_merge_features (&mpam_classes); -mutex_unlock (&mpam_list_lock); +int err;/* * Once the cpuhp callbacks have been changed, mpam_partid_max can no @@ -1332,6 +1580,27 @@ static void mpam_enable_once(void) partid_max_published = true;spin_unlock (&partid_max_lock); +/* +* If all the MSC have been probed, enabling the IRQs happens next.
drivers/resctrl/mpam_devices.c static void mpam_enable_once(void) · line 1594
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+* That involves cross-calling to a CPU that can reach the MSC, and +* the locks must be taken in this order: +*/ +cpus_read_lock (); +mutex_lock (&mpam_list_lock); +mpam_enable_merge_features (&mpam_classes); + + err =mpam_register_irqs (); +if (err) +pr_warn ("Failed to register irqs: %d\n" , err);
Perhaps move the print into the if (err) below?
Quoted 14 lines
drivers/resctrl/mpam_devices.c +8
-0+ +mutex_unlock (&mpam_list_lock); +cpus_read_unlock (); + +if (err) { +schedule_work (&mpam_broken_work); +return ; + }drivers/resctrl/mpam_internal.h +0
-0
drivers/resctrl/mpam_internal.h struct mpam_garbage { · line 37
Quoted 6 lines
drivers/resctrl/mpam_internal.h +3
-0@@ -32,6 +32,10 @@ struct mpam_garbage {struct platform_device *pdev; }; +/* Bit positions for error_irq_flags */ +#define MPAM_ERROR_IRQ_REQUESTED 0 +#define MPAM_ERROR_IRQ_HW_ENABLED 1
If there aren't going to be load more of these (I've not really thought about whether there might) then using a bitmap for these seems to add complexity that we wouldn't see with
bool error_irq_req;
bool error_irq_hw_enabled;
Quoted 24 lines
drivers/resctrl/mpam_internal.h +7
-0+struct mpam_msc {/* member of mpam_all_msc */ struct list_head all_msc_list;@@ -46,6 +50,11 @@ struct mpam_msc {struct pcc_mbox_chan *pcc_chan;u32 nrdy_usec;cpumask_t accessibility; +bool has_extd_esr; + +int reenable_error_ppi; +struct mpam_msc *__percpu *error_dev_id; +atomic_t online_refs;/* @@ -54,6 +63,7 @@ struct mpam_msc {*/ struct mutex probe_lock;bool probed; +unsigned long error_irq_flags;u16 partid_max;u8 pmg_max;unsigned long ris_idxs;
James Morse
maintainerRe: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
Hi Jonathan,
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Wed, 10 Sep 2025 20:42:58 +0000 James Morse <[email protected]> wrote:
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.(quoted diff) +0
-0@@ -1318,11 +1405,172 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) } }
Quoted 5 lines
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1409
Quoted 2 lines
drivers/resctrl/mpam_devices.c +2
-0+static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" ,I think you had a bunch of defines for these in an earlier patch. Can we use that to index here instead of [0] etc.
Sure,
Quoted 15 lines
Quoted 13 lines
drivers/resctrl/mpam_devices.c +13
-0+ [1] = "PARTID_SEL_Range", + [2] = "Req_PARTID_Range", + [3] = "MSMONCFG_ID_RANGE", + [4] = "Req_PMG_Range", + [5] = "Monitor_Range", + [6] = "intPARTID_Range", + [7] = "Unexpected_INTERNAL", + [8] = "Undefined_RIS_PART_SEL", + [9] = "RIS_No_Control", + [10] = "Undefined_RIS_MON_SEL", + [11] = "RIS_No_Monitor", + [12 ... 15] = "Reserved" +};
Quoted 9 lines
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1546
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+static void mpam_unregister_irqs (void ) +{ +int irq, idx; +struct mpam_msc *msc; + +cpus_read_lock ();guard(cpus_read_lock)(); guard(srcu)(&mpam_srcu);
Sure, looks like I didn't realise there was a cpus_read_lock version of this when I went looking for places to add this.
Quoted 1 line
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1547
Quoted 1 line
drivers/resctrl/mpam_devices.c +1
-0+/* take the lock as free_irq() can sleep */
The comment gets dropped as this mattered for an earlier locking scheme. (but free_irq() can still sleep)
Quoted 27 lines
Quoted 27 lines
drivers/resctrl/mpam_devices.c +22
-0+ idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +if (test_and_clear_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags)) +mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); + +if (test_and_clear_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags)) { +if (irq_is_percpu (irq)) { + msc->reenable_error_ppi =0 ; +free_percpu_irq (irq, msc->error_dev_id); + }else { +devm_free_irq (&msc->pdev->dev, irq, msc); + } + } + } +srcu_read_unlock (&mpam_srcu, idx); +cpus_read_unlock (); +}@@ -1332,6 +1580,27 @@ static void mpam_enable_once(void) partid_max_published = true;spin_unlock (&partid_max_lock);
Quoted 14 lines
drivers/resctrl/mpam_devices.c static void mpam_enable_once(void) · line 1594
Quoted 12 lines
drivers/resctrl/mpam_devices.c +12
-0+/* +* If all the MSC have been probed, enabling the IRQs happens next. +* That involves cross-calling to a CPU that can reach the MSC, and +* the locks must be taken in this order: +*/ +cpus_read_lock (); +mutex_lock (&mpam_list_lock); +mpam_enable_merge_features (&mpam_classes); + + err =mpam_register_irqs (); +if (err) +pr_warn ("Failed to register irqs: %d\n" , err);Perhaps move the print into the if (err) below?
More types of error get later, and its maybe useful to know which of these failed.
Quoted 8 lines
Quoted 8 lines
drivers/resctrl/mpam_internal.h +0
-0@@ -32,6 +32,10 @@ struct mpam_garbage {struct platform_device *pdev; };
Quoted 9 lines
drivers/resctrl/mpam_internal.h struct mpam_garbage { · line 37
Quoted 3 lines
drivers/resctrl/mpam_internal.h +3
-0+/* Bit positions for error_irq_flags */ +#define MPAM_ERROR_IRQ_REQUESTED 0 +#define MPAM_ERROR_IRQ_HW_ENABLED 1If there aren't going to be load more of these (I've not really thought about whether there might) then using a bitmap for these seems to add complexity that we wouldn't see with
boolerror_irq_req;
boolerror_irq_hw_enabled;
It's a bitmap so that mpam_unregister_irqs() can use test_and_clear_bit() on them, because with a real interrupt mpam_unregister_irqs() can run multiple times in parallel with itself.
Doing this as bools would mean having a mutex to prevent that from happening.
I'll do that as its a slightly simpler.
Thanks,
James
Ben Horgan
maintainerRe: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
In reply to James MorseHi James,
Quoted 42 lines · James Morse
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.CC Rohit Mathew <[email protected]>Tested-by Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Madempam_unregister_irqs()safe to race with itself.
* Removed threaded interrupts.
* Schedulempam_disable()from cpuhp callback in the case of an error.
* Addedmpam_disable_reason.
* Usealloc_percpu()Changes since RFC:
* Use guard marco when walking srcu list.
* Use INTEN macro for enabling interrupts.
* Movepartid_max_publishedup earlier inmpam_enable_once().--- drivers/resctrl/mpam_devices.c | 277 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 10 ++ 2 files changed, 284 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +3
-0+static int __setup_ppi (struct mpam_msc *msc) +{ +int cpu;
drivers/resctrl/mpam_devices.c static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online), · line 1038
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+struct device *dev = &msc->pdev->dev; + + msc->error_dev_id = alloc_percpu(struct mpam_msc *); +if (!msc->error_dev_id) +return -ENOMEM ; + +for_each_cpu (cpu, &msc->accessibility) { +struct mpam_msc *empty = *per_cpu_ptr (msc->error_dev_id, cpu); + +if (empty) {
I'm confused about how this if conditioned can be satisfied. Isn't the alloc clearing msc->error_dev_id for each cpu and then it's only getting set for each cpu later in the iteration.
Quoted 287 lines
drivers/resctrl/mpam_devices.c +223
-3+dev_err_once (dev,"MSC shares PPI with %s!\n" , +dev_name (&empty->pdev->dev)); +return -EBUSY ; + } + *per_cpu_ptr (msc->error_dev_id, cpu) = msc; + } + +return 0 ; +} + +static int mpam_msc_setup_error_irq (struct mpam_msc *msc) +{ +int irq; + + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +return 0 ; + +/* Allocate and initialise the percpu device pointer for PPI */ +if (irq_is_percpu (irq)) +return __setup_ppi (msc); + +/* sanity check: shared interrupts can be routed anywhere? */ +if (!cpumask_equal (&msc->accessibility, cpu_possible_mask)) { +pr_err_once ("msc:%u is a private resource with a shared error interrupt" , + msc->id); +return -EINVAL ; + } + +return 0 ; +} +/* * An MSC can control traffic from a set of CPUs, but may only be accessible * from a (hopefully wider) set of CPUs. The common reason for this is power @@ -1060,6 +1143,10 @@ static int mpam_msc_drv_probe(struct platform_device *pdev)break ; } + err =mpam_msc_setup_error_irq (msc); +if (err) +break ; +if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &msc->pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;@@ -1318,11 +1405,172 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) } } +static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" , + [1 ] ="PARTID_SEL_Range" , + [2 ] ="Req_PARTID_Range" , + [3 ] ="MSMONCFG_ID_RANGE" , + [4 ] ="Req_PMG_Range" , + [5 ] ="Monitor_Range" , + [6 ] ="intPARTID_Range" , + [7 ] ="Unexpected_INTERNAL" , + [8 ] ="Undefined_RIS_PART_SEL" , + [9 ] ="RIS_No_Control" , + [10 ] ="Undefined_RIS_MON_SEL" , + [11 ] ="RIS_No_Monitor" , + [12 ...15 ] ="Reserved" +}; + +static int mpam_enable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); + +return 0 ; +} + +/* This can run in mpam_disable(), and the interrupt handler on the same CPU */ +static int mpam_disable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,0 ); + +return 0 ; +} + +static irqreturn_t __mpam_irq_handler (int irq,struct mpam_msc *msc) +{ +u64 reg; +u16 partid; +u8 errcode, pmg, ris; + +if (WARN_ON_ONCE (!msc) || +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), + &msc->accessibility))) +return IRQ_NONE ; + + reg =mpam_msc_read_esr (msc); + + errcode =FIELD_GET (MPAMF_ESR_ERRCODE , reg); +if (!errcode) +return IRQ_NONE ; + +/* Clear level triggered irq */ +mpam_msc_zero_esr (msc); + + partid =FIELD_GET (MPAMF_ESR_PARTID_MON , reg); + pmg =FIELD_GET (MPAMF_ESR_PMG , reg); + ris =FIELD_GET (MPAMF_ESR_RIS , reg); + +pr_err_ratelimited ("error irq from msc:%u '%s', partid:%u, pmg: %u, ris: %u\n" , + msc->id, mpam_errcode_names[errcode], partid, pmg, + ris); + +/* Disable this interrupt. */ +mpam_disable_msc_ecr (msc); + +/* +* Schedule the teardown work. Don't use a threaded IRQ as we can't +* unregister the interrupt from the threaded part of the handler. +*/ + mpam_disable_reason ="hardware error interrupt" ; +schedule_work (&mpam_broken_work); + +return IRQ_HANDLED ; +} + +static irqreturn_t mpam_ppi_handler (int irq,void *dev_id) +{ +struct mpam_msc *msc = *(struct mpam_msc **)dev_id; + +return __mpam_irq_handler (irq, msc); +} + +static irqreturn_t mpam_spi_handler (int irq,void *dev_id) +{ +struct mpam_msc *msc = dev_id; + +return __mpam_irq_handler (irq, msc); +} + +static int mpam_register_irqs (void ) +{ +int err, irq; +struct mpam_msc *msc; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +/* The MPAM spec says the interrupt can be SPI, PPI or LPI */ +/* We anticipate sharing the interrupt with other MSCs */ +if (irq_is_percpu (irq)) { + err =request_percpu_irq (irq, &mpam_ppi_handler, +"mpam:msc:error" , + msc->error_dev_id); +if (err) +return err; + + msc->reenable_error_ppi = irq; +smp_call_function_many (&msc->accessibility, + &_enable_percpu_irq, &irq, + true); + }else { + err =devm_request_irq (&msc->pdev->dev,irq, + &mpam_spi_handler,IRQF_SHARED , +"mpam:msc:error" , msc); +if (err) +return err; + } + +set_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags); +mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); +set_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags); + } + +return 0 ; +} + +static void mpam_unregister_irqs (void ) +{ +int irq, idx; +struct mpam_msc *msc; + +cpus_read_lock (); +/* take the lock as free_irq() can sleep */ + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +if (test_and_clear_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags)) +mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); + +if (test_and_clear_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags)) { +if (irq_is_percpu (irq)) { + msc->reenable_error_ppi =0 ; +free_percpu_irq (irq, msc->error_dev_id); + }else { +devm_free_irq (&msc->pdev->dev, irq, msc); + } + } + } +srcu_read_unlock (&mpam_srcu, idx); +cpus_read_unlock (); +} +static void mpam_enable_once (void ) { -mutex_lock (&mpam_list_lock); -mpam_enable_merge_features (&mpam_classes); -mutex_unlock (&mpam_list_lock); +int err;/* * Once the cpuhp callbacks have been changed, mpam_partid_max can no @@ -1332,6 +1580,27 @@ static void mpam_enable_once(void) partid_max_published = true;spin_unlock (&partid_max_lock); +/* +* If all the MSC have been probed, enabling the IRQs happens next. +* That involves cross-calling to a CPU that can reach the MSC, and +* the locks must be taken in this order: +*/ +cpus_read_lock (); +mutex_lock (&mpam_list_lock); +mpam_enable_merge_features (&mpam_classes); + + err =mpam_register_irqs (); +if (err) +pr_warn ("Failed to register irqs: %d\n" , err); + +mutex_unlock (&mpam_list_lock); +cpus_read_unlock (); + +if (err) { +schedule_work (&mpam_broken_work); +return ; + } +mpam_register_cpuhp_callbacks (mpam_cpu_online, mpam_cpu_offline); printk(KERN_INFO "MPAM enabled with %u PARTIDs and %u PMGs\n",@@ -1397,6 +1666,8 @@ void mpam_disable(struct work_struct *ignored) }mutex_unlock (&mpam_cpuhp_state_lock); +mpam_unregister_irqs (); + idx =srcu_read_lock (&mpam_srcu);list_for_each_entry_srcu (class, &mpam_classes, classes_list,srcu_read_lock_held (&mpam_srcu))drivers/resctrl/mpam_internal.h +9
-0@@ -32,6 +32,10 @@ struct mpam_garbage {struct platform_device *pdev; }; +/* Bit positions for error_irq_flags */ +#define MPAM_ERROR_IRQ_REQUESTED 0 +#define MPAM_ERROR_IRQ_HW_ENABLED 1 +struct mpam_msc {/* member of mpam_all_msc */ struct list_head all_msc_list;@@ -46,6 +50,11 @@ struct mpam_msc {struct pcc_mbox_chan *pcc_chan;u32 nrdy_usec;cpumask_t accessibility; +bool has_extd_esr; + +int reenable_error_ppi; +struct mpam_msc *__percpu *error_dev_id; +atomic_t online_refs;/*
drivers/resctrl/mpam_internal.h struct mpam_msc { · line 69
Quoted 7 lines
drivers/resctrl/mpam_internal.h +1
-0@@ -54,6 +63,7 @@ struct mpam_msc {*/ struct mutex probe_lock;bool probed; +unsigned long error_irq_flags;u16 partid_max;u8 pmg_max;unsigned long ris_idxs;
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
Hi Ben,
Quoted 28 lines · Ben Horgan
Quoted 27 lines · James Morse
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.drivers/resctrl/mpam_devices.c +9
-0+static int __setup_ppi (struct mpam_msc *msc) +{ +int cpu; +struct device *dev = &msc->pdev->dev; + + msc->error_dev_id = alloc_percpu(struct mpam_msc *); +if (!msc->error_dev_id) +return -ENOMEM ; +
Quoted 8 lines
drivers/resctrl/mpam_devices.c static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online), · line 1038
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+for_each_cpu (cpu, &msc->accessibility) { +struct mpam_msc *empty = *per_cpu_ptr (msc->error_dev_id, cpu); + +if (empty) {I'm confused about how this if conditioned can be satisfied. Isn't the alloc clearing
msc->error_dev_idfor each cpu and then it's only getting set for each cpu later in the iteration.
Yes, you're right.
I think this was part of the support for PPI partitions, where multiple partitions would get set up here. This was a sanity check that they didn't overlap...
I've ripped that out.
Quoted 9 lines
drivers/resctrl/mpam_devices.c static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online), · line 1047
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+dev_err_once (dev,"MSC shares PPI with %s!\n" , +dev_name (&empty->pdev->dev)); +return -EBUSY ; + } + *per_cpu_ptr (msc->error_dev_id, cpu) = msc; + } + +return 0 ; +}
Thanks,
James
Re: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
In reply to James MorseHi James,
Quoted 5 lines · James Morse
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed.
Nit: MPAMF_ESR? (Casual readers may confuse it with ESR_ELx. Formally, there is no MPAM "ESR" register, though people familiar with the spec will of course know what you're referring to.)
Quoted 47 lines
The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.CC Rohit Mathew <[email protected]>Tested-by Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Madempam_unregister_irqs()safe to race with itself.
* Removed threaded interrupts.
* Schedulempam_disable()from cpuhp callback in the case of an error.
* Addedmpam_disable_reason.
* Usealloc_percpu()Changes since RFC:
* Use guard marco when walking srcu list.
* Use INTEN macro for enabling interrupts.
* Movepartid_max_publishedup earlier inmpam_enable_once().--- drivers/resctrl/mpam_devices.c | 277 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 10 ++ 2 files changed, 284 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +3
-0@@ -14,6 +14,9 @@#include <linux/device.h> #include <linux/errno.h> #include <linux/gfp.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> #include <linux/mutex.h>
drivers/resctrl/mpam_devices.c static u64 mpam_msc_read_idr(struct mpam_msc *msc) · line 172
Quoted 4 lines
drivers/resctrl/mpam_devices.c +1
-0@@ -166,6 +169,24 @@ static u64 mpam_msc_read_idr(struct mpam_msc *msc)return (idr_high <<32 ) | idr_low; } +static void mpam_msc_zero_esr (struct mpam_msc *msc)
Nit: Maybe clear_esr? (The fact that setting the ERRCODE and OVRWR fields to zero clears the interrupt and prepares for unambiguous reporting of the next error is more of an implementation detail. It doesn't matter what the rest of the register is set to.)
drivers/resctrl/mpam_devices.c static u64 mpam_msc_read_idr(struct mpam_msc *msc) · line 175
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+{ +__mpam_write_reg (msc,MPAMF_ESR ,0 ); +if (msc->has_extd_esr)
This deasserts the interrupt (if level-sensitive) and enables the MSC to report further errors. If we are unlucky and error occurs now, won't we splat the newly HW-generated RIS field by:
drivers/resctrl/mpam_devices.c static u64 mpam_msc_read_idr(struct mpam_msc *msc) · line 176
Quoted 1 line
drivers/resctrl/mpam_devices.c +1
-0+__mpam_write_reg (msc,MPAMF_ESR +4 ,0 );
...? If so, we will diagnose the wrong RIS when we pump the new error from MPAMF_ESR. I think the correct interpretation of the spec may be that:
a) software should treat fields in MPAMF_ESR[63:32] as vaild only if ERRCODE is nonzero, and
b) software should never write to MPAMF_ESR[63:32] while ERRCODE is zero.
Does this look right? Should the fields be cleared in the opposite order?
Or alternatively, is it actually necessary to clear MPAMF_ESR[63:32] at all?
(The spec seems a bit vague on what software is supposed to do with this register to ensure correctness...)
Quoted 12 lines
drivers/resctrl/mpam_devices.c +12
-0+} + +static u64 mpam_msc_read_esr (struct mpam_msc *msc) +{ +u64 esr_high =0 , esr_low; + + esr_low =__mpam_read_reg (msc,MPAMF_ESR ); +if (msc->has_extd_esr) + esr_high =__mpam_read_reg (msc,MPAMF_ESR +4 ); + +return (esr_high <<32 ) | esr_low; +}
[...]
drivers/resctrl/mpam_devices.c static void mpam_reset_msc(struct mpam_msc *msc, bool online) · line 927
Quoted 9 lines
drivers/resctrl/mpam_devices.c +5
-0@@ -895,6 +920,13 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void _enable_percpu_irq (void *_irq) +{ +int *irq = _irq; + +enable_percpu_irq (*irq,IRQ_TYPE_NONE );
Can the type vary? (Maybe this makes no sense on GIC-based systems -- IRQ_TYPE_NONE (or "0") seems overwhelmingly common.)
(Just my lack of familiarity takling, here.)
[...]
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+static int __setup_ppi (struct mpam_msc *msc) +{ +int cpu; +struct device *dev = &msc->pdev->dev; + + msc->error_dev_id = alloc_percpu(struct mpam_msc *); +if (!msc->error_dev_id) +return -ENOMEM ; +
drivers/resctrl/mpam_devices.c static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online), · line 1044
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+for_each_cpu (cpu, &msc->accessibility) { +struct mpam_msc *empty = *per_cpu_ptr (msc->error_dev_id, cpu); + +if (empty) { +dev_err_once (dev,"MSC shares PPI with %s!\n" , +dev_name (&empty->pdev->dev)); +return -EBUSY ; + } + *per_cpu_ptr (msc->error_dev_id, cpu) = msc; + }
How are PPIs supposed to work?
An individual MSC that is affine to multiple CPUs has no way to distinguish which CPU an error relates to, and no CPU-specific (or even RIS-specific) ESR.
So, won't such an interrupt be pointlessly take the interrupt on all CPUs, which would all fight over the reported event?
Have you encountered any platforms wired up this way? The spec recommends not to do this, but does not provide any rationale...
The spec only mentions PPIs in the context of being affine to a single CPU (PE). It's not clear to me that any other use of PPIs makes sense (?)
If we really have to cope with this, maybe it would make sense to pick a single CPU in the affinity set (though we might have to move it around if the unlucky CPU is offlined).
[...]
Quoted 14 lines
drivers/resctrl/mpam_devices.c +14
-0+static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" , + [1 ] ="PARTID_SEL_Range" , + [2 ] ="Req_PARTID_Range" , + [3 ] ="MSMONCFG_ID_RANGE" , + [4 ] ="Req_PMG_Range" , + [5 ] ="Monitor_Range" , + [6 ] ="intPARTID_Range" , + [7 ] ="Unexpected_INTERNAL" , + [8 ] ="Undefined_RIS_PART_SEL" , + [9 ] ="RIS_No_Control" , + [10 ] ="Undefined_RIS_MON_SEL" , + [11 ] ="RIS_No_Monitor" , + [12 ...15 ] ="Reserved"
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1431
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+}; + +static int mpam_enable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); + +return 0 ; +}
This could also be a switch () { case 0: return "foo";
case 1: return "bar"; ... }, without the explicit table. This would avoid having to think about the ERRCODE field growing. (There are some RES0 bits looming over it.)
(This also tends to avoid the extra pointer table in .rodata, which might be of interest if this were a hot path.)
[...]
(Review truncated -- that's the comments I had so far on the previous series.)
Cheers
---Dave
James Morse
maintainerRe: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
Hi Dave,
Quoted 8 lines · Dave Martin
Quoted 5 lines · James Morse
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed.
Nit:
MPAMF_ESR? (Casual readers may confuse it withESR_ELx.
Sure, fixed.
Quoted 24 lines
Formally, there is no MPAM "ESR" register, though people familiar with the spec will of course know what you're referring to.)
Quoted 21 lines
The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.drivers/resctrl/mpam_devices.c +0
-0@@ -166,6 +169,24 @@ static u64 mpam_msc_read_idr(struct mpam_msc *msc)return (idr_high <<32 ) | idr_low; }
Quoted 6 lines
drivers/resctrl/mpam_devices.c static u64 mpam_msc_read_idr(struct mpam_msc *msc) · line 172
Quoted 1 line
drivers/resctrl/mpam_devices.c +1
-0+static void mpam_msc_zero_esr (struct mpam_msc *msc)Nit: Maybe
clear_esr? (The fact that setting the ERRCODE and OVRWR fields to zero clears the interrupt and prepares for unambiguous reporting of the next error is more of an implementation detail. It doesn't matter what the rest of the register is set to.)
If you think that name is clearer - sure,
Quoted 20 lines
drivers/resctrl/mpam_devices.c static u64 mpam_msc_read_idr(struct mpam_msc *msc) · line 175
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+{ +__mpam_write_reg (msc,MPAMF_ESR ,0 ); +if (msc->has_extd_esr)This deasserts the interrupt (if level-sensitive) and enables the MSC to report further errors. If we are unlucky and error occurs now, won't we splat the newly HW-generated RIS field by:
drivers/resctrl/mpam_devices.c static u64 mpam_msc_read_idr(struct mpam_msc *msc) · line 176
Quoted 1 line
drivers/resctrl/mpam_devices.c +1
-0+__mpam_write_reg (msc,MPAMF_ESR +4 ,0 );...? If so, we will diagnose the wrong RIS when we pump the new error from
MPAMF_ESR. I think the correct interpretation of the spec may be that:a) software should treat fields in MPAMF_ESR[63:32] as vaild only if ERRCODE is nonzero, and
b) software should never write to MPAMF_ESR[63:32] while ERRCODE is zero.
Quoted 8 lines
Does this look right? Should the fields be cleared in the opposite order?
Or alternatively, is it actually necessary to clear MPAMF_ESR[63:32] at all?
(The spec seems a bit vague on what software is supposed to do with this register to ensure correctness...)
Yeah - I don't think there was much intention here beyond making the RIS available for the first error. As none of these errors can really be handled, I don't think a second error value matters too much.
I've reordered it as you suggest, and added a block comment to explain the problem:
-----%<-----
u64 esr_low = __mpam_read_reg(msc, MPAMF_ESR); if (!esr_low) return; /* * Clearing the high/low bits of MPAMF_ESR can not be atomic. * Clear the top half first, so that the pending error bits in the * lower half prevent hardware from updating either half of the * register. */ if (msc->has_extd_esr) __mpam_write_reg(msc, MPAMF_ESR + 4, 0); __mpam_write_reg(msc, MPAMF_ESR, 0);
-----%<-----
We should probably go bother the architects to find out if we can modify the high bits like this safely.
Quoted 15 lines
drivers/resctrl/mpam_devices.c static void mpam_reset_msc(struct mpam_msc *msc, bool online) · line 927
Quoted 11 lines
drivers/resctrl/mpam_devices.c +6
-0+}@@ -895,6 +920,13 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void _enable_percpu_irq (void *_irq) +{ +int *irq = _irq; + +enable_percpu_irq (*irq,IRQ_TYPE_NONE );Can the type vary? (Maybe this makes no sense on GIC-based systems --
IRQ_TYPE_NONE(or "0") seems overwhelmingly common.)
Quoted 1 line
(Just my lack of familiarity takling, here.)
PPI can be edge or level - but the irqchip doesn't need to know at this point, and specifying NONE tells it to use what it already knows. The irqchip already got told what firmware table said when the interrupt was registered. I believe the GIC knows its a PPI from the intid, they live in a magic range.
Quoted 15 lines
[...]
Quoted 13 lines
drivers/resctrl/mpam_devices.c +13
-0+static int __setup_ppi (struct mpam_msc *msc) +{ +int cpu; +struct device *dev = &msc->pdev->dev; + + msc->error_dev_id = alloc_percpu(struct mpam_msc *); +if (!msc->error_dev_id) +return -ENOMEM ; + +for_each_cpu (cpu, &msc->accessibility) { +struct mpam_msc *empty = *per_cpu_ptr (msc->error_dev_id, cpu); + +if (empty) {
Quoted 8 lines
drivers/resctrl/mpam_devices.c static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online), · line 1044
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+dev_err_once (dev,"MSC shares PPI with %s!\n" , +dev_name (&empty->pdev->dev)); +return -EBUSY ; + } + *per_cpu_ptr (msc->error_dev_id, cpu) = msc; + }How are PPIs supposed to work?
You take the interrupt on the corresponding CPU, and the irqchip gives you the corresponding percpu pointer. That is what is being setup here.
Quoted 3 lines
An individual MSC that is affine to multiple CPUs has no way to distinguish which CPU an error relates to, and no CPU-specific (or even RIS-specific) ESR.
For deeper caches this is certainly a problem. But for things close in to the CPU, they may well know which CPU this transaction came from. The MSC may even be part of the CPU.
Quoted 2 lines
So, won't such an interrupt be pointlessly take the interrupt on all CPUs, which would all fight over the reported event?
It ought to be only one, but nothing requires this.
Quoted 8 lines
Have you encountered any platforms wired up this way? The spec recommends not to do this, but does not provide any rationale...
The spec only mentions PPIs in the context of being affine to a single CPU (PE).
It's not clear to me that any other use of PPIs makes sense (?)
The PPI problem also exists the other way round. If your MSC is not globally accessible, you can't wire its interrupts up to an SPI, otherwise linux can route the interrupt to CPUs that can't access the MSC.
The only tool you have to get out of this is to use a PPI.
This came up multiple times with RAS when the caches signalled errors and it really needed to go to the local CPUs, not a random CPU in a remote package.
It's my assumption that folk will build platforms the same shape, and reach for PPI again.
Quoted 3 lines
If we really have to cope with this, maybe it would make sense to pick a single CPU in the affinity set (though we might have to move it around if the unlucky CPU is offlined).
Unfortunately PPI are a totally separate set of wiring with a reserved intid range (or two!) and their own registers in the GICR. It isn't possible to pretend they're a regular interrupt taken on a particular CPU.
A choice that can be made here is to assume no-one will ever(?) use these, and drop support. I don't know of a platform that is using PPI - but I can't say no-one is.
Quoted 33 lines
[...]
Quoted 14 lines
drivers/resctrl/mpam_devices.c +14
-0+static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" , + [1 ] ="PARTID_SEL_Range" , + [2 ] ="Req_PARTID_Range" , + [3 ] ="MSMONCFG_ID_RANGE" , + [4 ] ="Req_PMG_Range" , + [5 ] ="Monitor_Range" , + [6 ] ="intPARTID_Range" , + [7 ] ="Unexpected_INTERNAL" , + [8 ] ="Undefined_RIS_PART_SEL" , + [9 ] ="RIS_No_Control" , + [10 ] ="Undefined_RIS_MON_SEL" , + [11 ] ="RIS_No_Monitor" , + [12 ...15 ] ="Reserved" drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1431
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+}; + +static int mpam_enable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); + +return 0 ; +}This could also be a switch () { case 0: return "foo";
case 1: return "bar"; ... }, without the explicit table. This would avoid having to think about the ERRCODE field growing. (There are some RES0 bits looming over it.)
Quoted 2 lines
(This also tends to avoid the extra pointer table in .rodata, which might be of interest if this were a hot path.)
Given they added new fields to the end of the list, I'm not worried about it becoming sparse.
Thanks,
James
Fenghua Yu
reviewerRe: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
In reply to James MorseHi, James,
Quoted 326 lines · James Morse
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.CC Rohit Mathew <[email protected]>Tested-by Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Madempam_unregister_irqs()safe to race with itself.
* Removed threaded interrupts.
* Schedulempam_disable()from cpuhp callback in the case of an error.
* Addedmpam_disable_reason.
* Usealloc_percpu()Changes since RFC:
* Use guard marco when walking srcu list.
* Use INTEN macro for enabling interrupts.
* Movepartid_max_publishedup earlier inmpam_enable_once().--- drivers/resctrl/mpam_devices.c | 277 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 10 ++ 2 files changed, 284 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +218
-0@@ -14,6 +14,9 @@#include <linux/device.h> #include <linux/errno.h> #include <linux/gfp.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqdesc.h> #include <linux/list.h> #include <linux/lockdep.h> #include <linux/mutex.h> @@ -166,6 +169,24 @@ static u64 mpam_msc_read_idr(struct mpam_msc *msc)return (idr_high <<32 ) | idr_low; } +static void mpam_msc_zero_esr (struct mpam_msc *msc) +{ +__mpam_write_reg (msc,MPAMF_ESR ,0 ); +if (msc->has_extd_esr) +__mpam_write_reg (msc,MPAMF_ESR +4 ,0 ); +} + +static u64 mpam_msc_read_esr (struct mpam_msc *msc) +{ +u64 esr_high =0 , esr_low; + + esr_low =__mpam_read_reg (msc,MPAMF_ESR ); +if (msc->has_extd_esr) + esr_high =__mpam_read_reg (msc,MPAMF_ESR +4 ); + +return (esr_high <<32 ) | esr_low; +} +static void __mpam_part_sel_raw (u32 partsel,struct mpam_msc *msc) {lockdep_assert_held (&msc->part_sel_lock);@@ -754,6 +775,7 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) pmg_max =FIELD_GET (MPAMF_IDR_PMG_MAX , idr); msc->partid_max =min (msc->partid_max, partid_max); msc->pmg_max =min (msc->pmg_max, pmg_max); + msc->has_extd_esr =FIELD_GET (MPAMF_IDR_HAS_EXTD_ESR , idr);mutex_lock (&mpam_list_lock); ris =mpam_get_or_create_ris (msc, ris_idx);@@ -768,6 +790,9 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)mutex_unlock (&msc->part_sel_lock); } +/* Clear any stale errors */ +mpam_msc_zero_esr (msc); +spin_lock (&partid_max_lock); mpam_partid_max =min (mpam_partid_max, msc->partid_max); mpam_pmg_max =min (mpam_pmg_max, msc->pmg_max);@@ -895,6 +920,13 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void _enable_percpu_irq (void *_irq) +{ +int *irq = _irq; + +enable_percpu_irq (*irq,IRQ_TYPE_NONE ); +} +static int mpam_cpu_online (unsigned int cpu) {int idx;@@ -906,6 +938,9 @@ static int mpam_cpu_online(unsigned int cpu)if (!cpumask_test_cpu (cpu, &msc->accessibility))continue ; +if (msc->reenable_error_ppi) +_enable_percpu_irq (&msc->reenable_error_ppi); +if (atomic_fetch_inc (&msc->online_refs) ==0 )mpam_reset_msc (msc, true); }@@ -959,6 +994,9 @@ static int mpam_cpu_offline(unsigned int cpu)if (!cpumask_test_cpu (cpu, &msc->accessibility))continue ; +if (msc->reenable_error_ppi) +disable_percpu_irq (msc->reenable_error_ppi); +if (atomic_dec_and_test (&msc->online_refs))mpam_reset_msc (msc, false); }@@ -985,6 +1023,51 @@ static void mpam_register_cpuhp_callbacks(int (*online)(unsigned int online),mutex_unlock (&mpam_cpuhp_state_lock); } +static int __setup_ppi (struct mpam_msc *msc) +{ +int cpu; +struct device *dev = &msc->pdev->dev; + + msc->error_dev_id = alloc_percpu(struct mpam_msc *); +if (!msc->error_dev_id) +return -ENOMEM ; + +for_each_cpu (cpu, &msc->accessibility) { +struct mpam_msc *empty = *per_cpu_ptr (msc->error_dev_id, cpu); + +if (empty) { +dev_err_once (dev,"MSC shares PPI with %s!\n" , +dev_name (&empty->pdev->dev)); +return -EBUSY ; + } + *per_cpu_ptr (msc->error_dev_id, cpu) = msc; + } + +return 0 ; +} + +static int mpam_msc_setup_error_irq (struct mpam_msc *msc) +{ +int irq; + + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +return 0 ; + +/* Allocate and initialise the percpu device pointer for PPI */ +if (irq_is_percpu (irq)) +return __setup_ppi (msc); + +/* sanity check: shared interrupts can be routed anywhere? */ +if (!cpumask_equal (&msc->accessibility, cpu_possible_mask)) { +pr_err_once ("msc:%u is a private resource with a shared error interrupt" , + msc->id); +return -EINVAL ; + } + +return 0 ; +} +/* * An MSC can control traffic from a set of CPUs, but may only be accessible * from a (hopefully wider) set of CPUs. The common reason for this is power @@ -1060,6 +1143,10 @@ static int mpam_msc_drv_probe(struct platform_device *pdev)break ; } + err =mpam_msc_setup_error_irq (msc); +if (err) +break ; +if (device_property_read_u32 (&pdev->dev,"pcc-channel" , &msc->pcc_subspace_id)) msc->iface =MPAM_IFACE_MMIO ;@@ -1318,11 +1405,172 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) } } +static char *mpam_errcode_names[16 ] = { + [0 ] ="No error" , + [1 ] ="PARTID_SEL_Range" , + [2 ] ="Req_PARTID_Range" , + [3 ] ="MSMONCFG_ID_RANGE" , + [4 ] ="Req_PMG_Range" , + [5 ] ="Monitor_Range" , + [6 ] ="intPARTID_Range" , + [7 ] ="Unexpected_INTERNAL" , + [8 ] ="Undefined_RIS_PART_SEL" , + [9 ] ="RIS_No_Control" , + [10 ] ="Undefined_RIS_MON_SEL" , + [11 ] ="RIS_No_Monitor" , + [12 ...15 ] ="Reserved" +}; + +static int mpam_enable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,MPAMF_ECR_INTEN ); + +return 0 ; +} + +/* This can run in mpam_disable(), and the interrupt handler on the same CPU */ +static int mpam_disable_msc_ecr (void *_msc) +{ +struct mpam_msc *msc = _msc; + +__mpam_write_reg (msc,MPAMF_ECR ,0 ); + +return 0 ; +} + +static irqreturn_t __mpam_irq_handler (int irq,struct mpam_msc *msc) +{ +u64 reg; +u16 partid; +u8 errcode, pmg, ris; + +if (WARN_ON_ONCE (!msc) || +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), + &msc->accessibility))) +return IRQ_NONE ; + + reg =mpam_msc_read_esr (msc); + + errcode =FIELD_GET (MPAMF_ESR_ERRCODE , reg); +if (!errcode) +return IRQ_NONE ; + +/* Clear level triggered irq */ +mpam_msc_zero_esr (msc); + + partid =FIELD_GET (MPAMF_ESR_PARTID_MON , reg); + pmg =FIELD_GET (MPAMF_ESR_PMG , reg); + ris =FIELD_GET (MPAMF_ESR_RIS , reg); + +pr_err_ratelimited ("error irq from msc:%u '%s', partid:%u, pmg: %u, ris: %u\n" , + msc->id, mpam_errcode_names[errcode], partid, pmg, + ris); + +/* Disable this interrupt. */ +mpam_disable_msc_ecr (msc); + +/* +* Schedule the teardown work. Don't use a threaded IRQ as we can't +* unregister the interrupt from the threaded part of the handler. +*/ + mpam_disable_reason ="hardware error interrupt" ; +schedule_work (&mpam_broken_work); + +return IRQ_HANDLED ; +} + +static irqreturn_t mpam_ppi_handler (int irq,void *dev_id) +{ +struct mpam_msc *msc = *(struct mpam_msc **)dev_id; + +return __mpam_irq_handler (irq, msc); +} + +static irqreturn_t mpam_spi_handler (int irq,void *dev_id) +{ +struct mpam_msc *msc = dev_id; + +return __mpam_irq_handler (irq, msc); +} + +static int mpam_register_irqs (void ) +{ +int err, irq; +struct mpam_msc *msc; + +lockdep_assert_cpus_held (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +/* The MPAM spec says the interrupt can be SPI, PPI or LPI */ +/* We anticipate sharing the interrupt with other MSCs */ +if (irq_is_percpu (irq)) { + err =request_percpu_irq (irq, &mpam_ppi_handler, +"mpam:msc:error" , + msc->error_dev_id); +if (err) +return err; + + msc->reenable_error_ppi = irq; +smp_call_function_many (&msc->accessibility, + &_enable_percpu_irq, &irq, + true); + }else { + err =devm_request_irq (&msc->pdev->dev,irq, + &mpam_spi_handler,IRQF_SHARED , +"mpam:msc:error" , msc); +if (err) +return err; + } + +set_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags); +mpam_touch_msc (msc, mpam_enable_msc_ecr, msc); +set_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags); + } + +return 0 ;
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1548
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+} + +static void mpam_unregister_irqs (void ) +{ +int irq, idx; +struct mpam_msc *msc; + +cpus_read_lock (); +/* take the lock as free_irq() can sleep */ + idx =srcu_read_lock (&mpam_srcu);
guard(srcu)(&mpam_srcu);
Quoted 12 lines
drivers/resctrl/mpam_devices.c +12
-0+list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list, +srcu_read_lock_held (&mpam_srcu)) { + irq =platform_get_irq_byname_optional (msc->pdev,"error" ); +if (irq <=0 ) +continue ; + +if (test_and_clear_bit (MPAM_ERROR_IRQ_HW_ENABLED , &msc->error_irq_flags)) +mpam_touch_msc (msc, mpam_disable_msc_ecr, msc); + +if (test_and_clear_bit (MPAM_ERROR_IRQ_REQUESTED , &msc->error_irq_flags)) { +if (irq_is_percpu (irq)) { + msc->reenable_error_ppi =0 ;
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1570
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+free_percpu_irq (irq, msc->error_dev_id); + }else { +devm_free_irq (&msc->pdev->dev, irq, msc); + } + } + } +srcu_read_unlock (&mpam_srcu, idx); +cpus_read_unlock (); +} +
[SNIP]
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 18/29] arm_mpam: Register and enable IRQs
Hi Fenghua,
Quoted 24 lines · Fenghua Yu
Quoted 22 lines · James Morse
Register and enable error IRQs. All the MPAM error interrupts indicate a software bug, e.g. out of range partid. If the error interrupt is ever signalled, attempt to disable MPAM.
Only the irq handler accesses the ESR register, so no locking is needed. The work to disable MPAM after an error needs to happen at process context as it takes mutex. It also unregisters the interrupts, meaning it can't be done from the threaded part of a threaded interrupt. Instead,
mpam_disable()gets scheduled.Enabling the IRQs in the MSC may involve cross calling to a CPU that can access the MSC.
Once the IRQ is requested, the
mpam_disable()path can be called asynchronously, which will walk structures sized bymax_partid. Ensure this size is fixed before the interrupt is requested.drivers/resctrl/mpam_devices.c +0
-0@@ -1318,11 +1405,172 @@ static void mpam_enable_merge_features(struct list_head
Quoted 10 lines
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1548
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+static void mpam_unregister_irqs (void ) +{ + int irq, idx; + struct mpam_msc *msc; + + cpus_read_lock(); + /* take the lock as free_irq() can sleep */ + idx = srcu_read_lock(&mpam_srcu);guard(srcu)(&mpam_srcu);
Yes - Jonathan already suggested this.
Quoted 13 lines
Quoted 13 lines
drivers/resctrl/mpam_devices.c +13
-0+ list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list, + srcu_read_lock_held(&mpam_srcu)) { + irq = platform_get_irq_byname_optional(msc->pdev, "error"); + if (irq <= 0) + continue; + + if (test_and_clear_bit(MPAM_ERROR_IRQ_HW_ENABLED, &msc->error_irq_flags)) + mpam_touch_msc(msc, mpam_disable_msc_ecr, msc); + + if (test_and_clear_bit(MPAM_ERROR_IRQ_REQUESTED, &msc->error_irq_flags)) { + if (irq_is_percpu(irq)) { + msc->reenable_error_ppi = 0; + free_percpu_irq(irq, msc->error_dev_id);
Quoted 8 lines
drivers/resctrl/mpam_devices.c static void mpam_enable_merge_features(struct list_head *all_classes_list) · line 1569
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+ } else { + devm_free_irq(&msc->pdev->dev, irq, msc); + } + } + } + srcu_read_unlock(&mpam_srcu, idx); + cpus_read_unlock(); +}
James
James Morse
maintainerPATCH v2 19/29 arm_mpam: Use a static key to indicate when mpam is enabled
In reply to James MorseOnce all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to enable/disable the context switch of the MPAM system registers.
--- drivers/resctrl/mpam_devices.c | 12 ++++++++++++ drivers/resctrl/mpam_internal.h | 8 ++++++++ 2 files changed, 20 insertions(+)
drivers/resctrl/mpam_devices.c +12 -0
@@ -29,6 +29,8 @@#include "mpam_internal.h" +DEFINE_STATIC_KEY_FALSE (mpam_enabled);/* TODO: move to arch code */ +/* * mpam_list_lock protects the SRCU lists when writing. Once the * mpam_enabled key is enabled these lists are read-only,
@@ -956,6 +958,9 @@ static int mpam_discovery_cpu_online(unsigned int cpu)struct mpam_msc *msc;bool new_device_probed = false; +if (mpam_is_enabled ()) +return 0 ; +guard (srcu)(&mpam_srcu);list_for_each_entry_srcu (msc, &mpam_all_msc, all_msc_list,srcu_read_lock_held (&mpam_srcu)) {
@@ -1471,6 +1476,10 @@ static irqreturn_t __mpam_irq_handler(int irq, struct mpam_msc *msc)/* Disable this interrupt. */ mpam_disable_msc_ecr (msc); +/* Are we racing with the thread disabling MPAM? */ +if (!mpam_is_enabled ()) +return IRQ_HANDLED ; +/* * Schedule the teardown work. Don't use a threaded IRQ as we can't * unregister the interrupt from the threaded part of the handler.
@@ -1601,6 +1610,7 @@ static void mpam_enable_once(void)return ; } +static_branch_enable (&mpam_enabled);mpam_register_cpuhp_callbacks (mpam_cpu_online, mpam_cpu_offline); printk(KERN_INFO "MPAM enabled with %u PARTIDs and %u PMGs\n",
@@ -1666,6 +1676,8 @@ void mpam_disable(struct work_struct *ignored) }mutex_unlock (&mpam_cpuhp_state_lock); +static_branch_disable (&mpam_enabled); +mpam_unregister_irqs (); idx =srcu_read_lock (&mpam_srcu);
drivers/resctrl/mpam_internal.h +8 -0
@@ -8,6 +8,7 @@#include <linux/atomic.h> #include <linux/cpumask.h> #include <linux/io.h> +#include <linux/jump_label.h> #include <linux/llist.h> #include <linux/mailbox_client.h> #include <linux/mutex.h>
@@ -17,6 +18,13 @@#define MPAM_MSC_MAX_NUM_RIS 16 +DECLARE_STATIC_KEY_FALSE (mpam_enabled); + +static inline bool mpam_is_enabled (void ) +{ +return static_branch_likely (&mpam_enabled); +} +/* * Structures protected by SRCU may not be freed for a surprising amount of * time (especially if perf is running). To ensure the MPAM error interrupt can
Signature · 1 line
2.39.5
Re: [PATCH v2 19/29] arm_mpam: Use a static key to indicate when mpam is enabled
Quoted 7 lines · On Wed, 10 Sep 2025 20:42:59 +0000 James Morse <[email protected]> wrote:
Once all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Quoted 5 lines
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to enable/disable the context switch of the MPAM system registers.
Signed-off-by James Morse <[email protected]>
Seems fine to me (other than the TODO move to arch code that should probably be resolved.
James Morse
maintainerRe: [PATCH v2 19/29] arm_mpam: Use a static key to indicate when mpam is enabled
Hi Jonathan,
Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 10 Sep 2025 20:42:59 +0000 James Morse <[email protected]> wrote:
Once all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Quoted 8 lines
Quoted 5 lines
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to enable/disable the context switch of the MPAM system registers.
Signed-off-by James Morse <[email protected]>Seems fine to me (other than the TODO move to arch code that should probably be resolved.
That is just to make it clear this isn't where it should live, its a quirk of moving the arch code alter to reduce the number of trees this interacts with. I've dropped the word 'TODO'...
Quoted 1 line
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
James
Re: [PATCH v2 19/29] arm_mpam: Use a static key to indicate when mpam is enabled
In reply to James MorseHi James,
Quoted 11 lines · James Morse
Once all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to enable/disable the context switch of the MPAM system registers.
Quoted 6 lines
Signed-off-by James Morse <[email protected]>--- drivers/resctrl/mpam_devices.c | 12 ++++++++++++ drivers/resctrl/mpam_internal.h | 8 ++++++++ 2 files changed, 20 insertions(+)
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 19/29] arm_mpam: Use a static key to indicate when mpam is enabled
Hi Ben,
Quoted 8 lines · Ben Horgan
Quoted 7 lines · James Morse
Once all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Quoted 5 lines
Quoted 3 lines
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to enable/disable the context switch of the MPAM system registers.
Reviewed-by Ben Horgan <[email protected]>
Thanks!
James
Re: [PATCH v2 19/29] arm_mpam: Use a static key to indicate when mpam is enabled
In reply to James MorseQuoted 9 lines · James Morse
Once all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to
nit...s/repsonse/response/
Quoted 3 lines
enable/disable the context switch of the MPAM system registers.
Signed-off-by James Morse <[email protected]>
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 19/29] arm_mpam: Use a static key to indicate when mpam is enabled
Hi Fenghua,
Quoted 4 lines · Fenghua Yu
Quoted 3 lines · James Morse
Once all the MSC have been probed, the system wide usable number of PARTID is known and the configuration arrays can be allocated.
Quoted 8 lines
Quoted 6 lines
After this point, checking all the MSC have been probed is pointless, and the cpuhp callbacks should restore the configuration, instead of just resetting the MSC.
Add a static key to enable this behaviour. This will also allow MPAM to be disabled in repsonse to an error, and the architecture code to
nit...s/repsonse/response/
Oops,
Quoted 5 lines
Quoted 3 lines
enable/disable the context switch of the MPAM system registers.
Signed-off-by James Morse <[email protected]>Reviewed-by Fenghua Yu <[email protected]>
Thanks!
James
James Morse
maintainerPATCH v2 20/29 arm_mpam: Allow configuration to be applied and restored during cpu online
In reply to James MorseWhen CPUs come online the MSC's original configuration should be restored.
Add struct mpam_config to hold the configuration. This has a bitmap of features that were modified. Once the maximum partid is known, allocate a configuration array for each component, and reprogram each RIS configuration from this.
---
Changes since v1:
* Switched entry_rcu to srcu versions.
Changes since RFC:
* Added a comment about the ordering around max_partid.
* Allocate configurations after interrupts are registered to reduce churn.
* Added mpam_assert_partid_sizes_fixed();
* Make reset use an all-ones instead of zero config.
--- drivers/resctrl/mpam_devices.c | 269 +++++++++++++++++++++++++++++--- drivers/resctrl/mpam_internal.h | 29 +++- 2 files changed, 271 insertions(+), 27 deletions(-)
drivers/resctrl/mpam_devices.c +247 -22
@@ -114,6 +114,16 @@ static LLIST_HEAD(mpam_garbage);/* When mpam is disabled, the printed reason to aid debugging */ static char *mpam_disable_reason; +/* +* Once mpam is enabled, new requestors cannot further reduce the available +* partid. Assert that the size is fixed, and new requestors will be turned +* away. +*/ +static void mpam_assert_partid_sizes_fixed (void ) +{ +WARN_ON_ONCE (!partid_max_published); +} +static u32 __mpam_read_reg (struct mpam_msc *msc,u16 reg) {WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility));
@@ -363,12 +373,16 @@ static void mpam_class_destroy(struct mpam_class *class)add_to_garbage (class); } +static void __destroy_component_cfg (struct mpam_component *comp); +static void mpam_comp_destroy (struct mpam_component *comp) {struct mpam_class *class = comp->class;lockdep_assert_held (&mpam_list_lock); +__destroy_component_cfg (comp); +list_del_rcu (&comp->class_list);add_to_garbage (comp);
@@ -833,50 +847,105 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)__mpam_write_reg (msc, reg, bm); } -static void mpam_reset_ris_partid (struct mpam_msc_ris *ris,u16 partid) +/* Called via IPI. Call while holding an SRCU reference */ +static void mpam_reprogram_ris_partid (struct mpam_msc_ris *ris,u16 partid, +struct mpam_config *cfg) {struct mpam_msc *msc = ris->vmsc->msc;struct mpam_props *rprops = &ris->props; -mpam_assert_srcu_read_lock_held (); -mutex_lock (&msc->part_sel_lock);__mpam_part_sel (ris->ris_idx, partid, msc); -if (mpam_has_feature (mpam_feat_cpor_part, rprops)) -mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , rprops->cpbm_wd); +if (mpam_has_feature (mpam_feat_cpor_part, rprops) && +mpam_has_feature (mpam_feat_cpor_part, cfg)) { +if (cfg->reset_cpbm) +mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , + rprops->cpbm_wd); +else +mpam_write_partsel_reg (msc,CPBM , cfg->cpbm); + } -if (mpam_has_feature (mpam_feat_mbw_part, rprops)) -mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , rprops->mbw_pbm_bits); +if (mpam_has_feature (mpam_feat_mbw_part, rprops) && +mpam_has_feature (mpam_feat_mbw_part, cfg)) { +if (cfg->reset_mbw_pbm) +mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , + rprops->mbw_pbm_bits); +else +mpam_write_partsel_reg (msc,MBW_PBM , cfg->mbw_pbm); + } -if (mpam_has_feature (mpam_feat_mbw_min, rprops)) +if (mpam_has_feature (mpam_feat_mbw_min, rprops) && +mpam_has_feature (mpam_feat_mbw_min, cfg))mpam_write_partsel_reg (msc,MBW_MIN ,0 ); -if (mpam_has_feature (mpam_feat_mbw_max, rprops)) -mpam_write_partsel_reg (msc,MBW_MAX ,MPAMCFG_MBW_MAX_MAX ); +if (mpam_has_feature (mpam_feat_mbw_max, rprops) && +mpam_has_feature (mpam_feat_mbw_max, cfg)) +mpam_write_partsel_reg (msc,MBW_MAX , cfg->mbw_max); -if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) +if (mpam_has_feature (mpam_feat_mbw_prop, rprops) && +mpam_has_feature (mpam_feat_mbw_prop, cfg))mpam_write_partsel_reg (msc,MBW_PROP ,0 );mutex_unlock (&msc->part_sel_lock); } +struct reprogram_ris { +struct mpam_msc_ris *ris; +struct mpam_config *cfg; +}; + +/* Call with MSC lock held */ +static int mpam_reprogram_ris (void *_arg) +{ +u16 partid, partid_max; +struct reprogram_ris *arg = _arg; +struct mpam_msc_ris *ris = arg->ris; +struct mpam_config *cfg = arg->cfg; + +if (ris->in_reset_state) +return 0 ; + +spin_lock (&partid_max_lock); + partid_max = mpam_partid_max; +spin_unlock (&partid_max_lock); +for (partid =0 ; partid <= partid_max; partid++) +mpam_reprogram_ris_partid (ris, partid, cfg); + +return 0 ; +} + +static void mpam_init_reset_cfg (struct mpam_config *reset_cfg) +{ +memset (reset_cfg,0 ,sizeof (*reset_cfg)); + + reset_cfg->features = ~0 ; + reset_cfg->cpbm = ~0 ; + reset_cfg->mbw_pbm = ~0 ; + reset_cfg->mbw_max =MPAMCFG_MBW_MAX_MAX ; + + reset_cfg->reset_cpbm = true; + reset_cfg->reset_mbw_pbm = true; +} +/* * Called via smp_call_on_cpu() to prevent migration, while still being * pre-emptible. */ static int mpam_reset_ris (void *arg) { -u16 partid, partid_max; +struct mpam_config reset_cfg;struct mpam_msc_ris *ris = arg; +struct reprogram_ris reprogram_arg;if (ris->in_reset_state)return 0 ; -spin_lock (&partid_max_lock); - partid_max = mpam_partid_max; -spin_unlock (&partid_max_lock); -for (partid =0 ; partid < partid_max; partid++) -mpam_reset_ris_partid (ris, partid); +mpam_init_reset_cfg (&reset_cfg); + + reprogram_arg.ris = ris; + reprogram_arg.cfg = &reset_cfg; + +mpam_reprogram_ris (&reprogram_arg);return 0 ; }
@@ -922,6 +991,40 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void mpam_reprogram_msc (struct mpam_msc *msc) +{ +u16 partid; +bool reset; +struct mpam_config *cfg; +struct mpam_msc_ris *ris; + +/* +* No lock for mpam_partid_max as partid_max_published has been +* set by mpam_enabled(), so the values can no longer change. +*/ +mpam_assert_partid_sizes_fixed (); + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (ris, &msc->ris, msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!mpam_is_enabled () && !ris->in_reset_state) { +mpam_touch_msc (msc, &mpam_reset_ris, ris); + ris->in_reset_state = true; +continue ; + } + + reset = true; +for (partid =0 ; partid <= mpam_partid_max; partid++) { + cfg = &ris->vmsc->comp->cfg[partid]; +if (cfg->features) + reset = false; + +mpam_reprogram_ris_partid (ris, partid, cfg); + } + ris->in_reset_state = reset; + } +} +static void _enable_percpu_irq (void *_irq) {int *irq = _irq;
@@ -944,7 +1047,7 @@ static int mpam_cpu_online(unsigned int cpu)_enable_percpu_irq (&msc->reenable_error_ppi);if (atomic_fetch_inc (&msc->online_refs) ==0 ) -mpam_reset_msc (msc, true); +mpam_reprogram_msc (msc); }srcu_read_unlock (&mpam_srcu, idx);
@@ -1577,6 +1680,45 @@ static void mpam_unregister_irqs(void)cpus_read_unlock (); } +static void __destroy_component_cfg (struct mpam_component *comp) +{ +add_to_garbage (comp->cfg); +} + +static int __allocate_component_cfg (struct mpam_component *comp) +{ +mpam_assert_partid_sizes_fixed (); + +if (comp->cfg) +return 0 ; + + comp->cfg =kcalloc (mpam_partid_max +1 ,sizeof (*comp->cfg),GFP_KERNEL ); +if (!comp->cfg) +return -ENOMEM ; +init_garbage (comp->cfg); + +return 0 ; +} + +static int mpam_allocate_config (void ) +{ +int err =0 ; +struct mpam_class *class; +struct mpam_component *comp; + +lockdep_assert_held (&mpam_list_lock); + +list_for_each_entry (class, &mpam_classes, classes_list) { +list_for_each_entry (comp, &class->components, class_list) { + err =__allocate_component_cfg (comp); +if (err) +return err; + } + } + +return 0 ; +} +static void mpam_enable_once (void ) {int err;
@@ -1596,12 +1738,21 @@ static void mpam_enable_once(void)*/ cpus_read_lock ();mutex_lock (&mpam_list_lock); -mpam_enable_merge_features (&mpam_classes); +do { +mpam_enable_merge_features (&mpam_classes); - err =mpam_register_irqs (); -if (err) -pr_warn ("Failed to register irqs: %d\n" , err); + err =mpam_register_irqs (); +if (err) { +pr_warn ("Failed to register irqs: %d\n" , err); +break ; + } + err =mpam_allocate_config (); +if (err) { +pr_err ("Failed to allocate configuration arrays.\n" ); +break ; + } + }while (0 );mutex_unlock (&mpam_list_lock);cpus_read_unlock ();
@@ -1624,6 +1775,9 @@ static void mpam_reset_component_locked(struct mpam_component *comp)struct mpam_msc_ris *ris;lockdep_assert_cpus_held (); +mpam_assert_partid_sizes_fixed (); + +memset (comp->cfg,0 , (mpam_partid_max *sizeof (*comp->cfg)));guard (srcu)(&mpam_srcu); list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list,
@@ -1723,6 +1877,77 @@ void mpam_enable(struct work_struct *work)mpam_enable_once (); } +struct mpam_write_config_arg { +struct mpam_msc_ris *ris; +struct mpam_component *comp; +u16 partid; +}; + +static int __write_config (void *arg) +{ +struct mpam_write_config_arg *c = arg; + +mpam_reprogram_ris_partid (c->ris, c->partid, &c->comp->cfg[c->partid]); + +return 0 ; +} + +#define maybe_update_config (cfg, feature, newcfg, member, changes) do { \ + if (mpam_has_feature(feature, newcfg) && \ + (newcfg)->member != (cfg)->member) { \ + (cfg)->member = (newcfg)->member; \ + cfg->features |= (1 << feature); \ + \ + (changes) |= (1 << feature); \ + } \ +} while (0) + +static mpam_features_t mpam_update_config (struct mpam_config *cfg, +const struct mpam_config *newcfg) +{ +mpam_features_t changes =0 ; + +maybe_update_config (cfg, mpam_feat_cpor_part, newcfg, cpbm, changes); +maybe_update_config (cfg, mpam_feat_mbw_part, newcfg, mbw_pbm, changes); +maybe_update_config (cfg, mpam_feat_mbw_max, newcfg, mbw_max, changes); + +return changes; +} + +int mpam_apply_config (struct mpam_component *comp,u16 partid, +struct mpam_config *cfg) +{ +struct mpam_write_config_arg arg; +struct mpam_msc_ris *ris; +struct mpam_vmsc *vmsc; +struct mpam_msc *msc; + +lockdep_assert_cpus_held (); + +/* Don't pass in the current config! */ +WARN_ON_ONCE (&comp->cfg[partid] == cfg); + +if (!mpam_update_config (&comp->cfg[partid], cfg)) +return 0 ; + + arg.comp = comp; + arg.partid = partid; + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (vmsc, &comp->vmsc, comp_list, +srcu_read_lock_held (&mpam_srcu)) { + msc = vmsc->msc; + +list_for_each_entry_srcu (ris, &vmsc->ris, vmsc_list, +srcu_read_lock_held (&mpam_srcu)) { + arg.ris = ris; +mpam_touch_msc (msc, __write_config, &arg); + } + } + +return 0 ; +} +static int __init mpam_msc_driver_init (void ) {if (!system_supports_mpam ())
drivers/resctrl/mpam_internal.h +24 -5
@@ -169,11 +169,7 @@ struct mpam_props {u16 num_mbwu_mon; }; -static inline bool mpam_has_feature (enum mpam_device_features feat, -struct mpam_props *props) -{ -return (1 << feat) & props->features; -} +#define mpam_has_feature (_feat, x) ((1 << (_feat)) & (x)->features)static inline void mpam_set_feature (enum mpam_device_features feat,struct mpam_props *props)
@@ -204,6 +200,20 @@ struct mpam_class {struct mpam_garbage garbage; }; +struct mpam_config { +/* Which configuration values are valid. */ +mpam_features_t features; + +u32 cpbm; +u32 mbw_pbm; +u16 mbw_max; + +bool reset_cpbm; +bool reset_mbw_pbm; + +struct mpam_garbage garbage; +}; +struct mpam_component {u32 comp_id;
@@ -212,6 +222,12 @@ struct mpam_component {cpumask_t affinity; +/* +* Array of configuration values, indexed by partid. +* Read from cpuhp callbacks, hold the cpuhp lock when writing. +*/ +struct mpam_config *cfg; +/* member of mpam_class:components */ struct list_head class_list;
@@ -276,6 +292,9 @@ extern u8 mpam_pmg_max;void mpam_enable (struct work_struct *work);void mpam_disable (struct work_struct *work); +int mpam_apply_config (struct mpam_component *comp,u16 partid, +struct mpam_config *cfg); +int mpam_get_cpumask_from_cache_id (unsigned long cache_id,u32 cache_level,cpumask_t *affinity);
Signature · 1 line
2.39.5
Re: [PATCH v2 20/29] arm_mpam: Allow configuration to be applied and restored during cpu online
Quoted 9 lines · On Wed, 10 Sep 2025 20:43:00 +0000 James Morse <[email protected]> wrote:
When CPUs come online the MSC's original configuration should be restored.
Add struct
mpam_configto hold the configuration. This has a bitmap of features that were modified. Once the maximum partid is known, allocate a configuration array for each component, and reprogram each RIS configuration from this.CC Dave Martin <[email protected]>Signed-off-by James Morse <[email protected]>
Trivial comments
drivers/resctrl/mpam_devices.c static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd) · line 919
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ +static void mpam_init_reset_cfg (struct mpam_config *reset_cfg) +{ +memset (reset_cfg,0 ,sizeof (*reset_cfg));
Might as well do the following and skip the memset.
*reset_cfg = (struct mpam_config) {
.features = ~0,
.cpbm = ~0,
.mbw_pbm = ~0,
.mbw_max = MPAM...
.reset_cpbm = true,
.reset_mbw_pbm = true,
};drivers/resctrl/mpam_devices.c static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)
Quoted 13 lines
drivers/resctrl/mpam_devices.c +12
-0+ + reset_cfg->features = ~0 ; + reset_cfg->cpbm = ~0 ; + reset_cfg->mbw_pbm = ~0 ; + reset_cfg->mbw_max =MPAMCFG_MBW_MAX_MAX ; + + reset_cfg->reset_cpbm = true; + reset_cfg->reset_mbw_pbm = true; +} +static int mpam_allocate_config (void ) +{ +int err =0 ;
Always set before use. Maybe push down so it is in tighter scope and can declare and initialize to final value in one line.
Quoted 22 lines
drivers/resctrl/mpam_devices.c +15
-0+struct mpam_class *class; +struct mpam_component *comp; + +lockdep_assert_held (&mpam_list_lock); + +list_for_each_entry (class, &mpam_classes, classes_list) { +list_for_each_entry (comp, &class->components, class_list) { + err =__allocate_component_cfg (comp); +if (err) +return err; + } + } + +return 0 ; +}drivers/resctrl/mpam_internal.h +0
-0
drivers/resctrl/mpam_internal.h struct mpam_props { · line 172
Quoted 9 lines
drivers/resctrl/mpam_internal.h +1
-5@@ -169,11 +169,7 @@ struct mpam_props {u16 num_mbwu_mon; }; -static inline bool mpam_has_feature (enum mpam_device_features feat, -struct mpam_props *props) -{ -return (1 << feat) & props->features; -} +#define mpam_has_feature (_feat, x) ((1 << (_feat)) & (x)->features)
If this is worth doing push it back to original introduction. I'm not sure it is necessary.
Jonathan
James Morse
maintainerRe: [PATCH v2 20/29] arm_mpam: Allow configuration to be applied and restored during cpu online
Hi Jonathan,
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Wed, 10 Sep 2025 20:43:00 +0000 James Morse <[email protected]> wrote:
When CPUs come online the MSC's original configuration should be restored.
Quoted 7 lines
Quoted 4 lines
Add struct
mpam_configto hold the configuration. This has a bitmap of features that were modified. Once the maximum partid is known, allocate a configuration array for each component, and reprogram each RIS configuration from this.Trivial comments
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 6 lines
drivers/resctrl/mpam_devices.c static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd) · line 919
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+static void mpam_init_reset_cfg (struct mpam_config *reset_cfg) +{ +memset (reset_cfg,0 ,sizeof (*reset_cfg));Might as well do the following and skip the memset.
Quoted 8 lines
*reset_cfg = (struct mpam_config) {
.features = ~0,
.cpbm = ~0,
.mbw_pbm = ~0,
.mbw_max = MPAM...
.reset_cpbm = true,
.reset_mbw_pbm = true,
};Sure,
Quoted 9 lines
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+ reset_cfg->features = ~0 ; + reset_cfg->cpbm = ~0 ; + reset_cfg->mbw_pbm = ~0 ; + reset_cfg->mbw_max =MPAMCFG_MBW_MAX_MAX ; + + reset_cfg->reset_cpbm = true; + reset_cfg->reset_mbw_pbm = true; +}
Quoted 6 lines
drivers/resctrl/mpam_devices.c static void mpam_unregister_irqs(void) · line 1705
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+static int mpam_allocate_config (void ) +{ +int err =0 ;Always set before use. Maybe push down so it is in tighter scope and can declare and initialize to final value in one line.
Sure,
Quoted 25 lines
Quoted 25 lines
drivers/resctrl/mpam_devices.c +15
-0+struct mpam_class *class; +struct mpam_component *comp; + +lockdep_assert_held (&mpam_list_lock); + +list_for_each_entry (class, &mpam_classes, classes_list) { +list_for_each_entry (comp, &class->components, class_list) { + err =__allocate_component_cfg (comp); +if (err) +return err; + } + } + +return 0 ; +}drivers/resctrl/mpam_internal.h +0
-0@@ -169,11 +169,7 @@ struct mpam_props {u16 num_mbwu_mon; };
Quoted 9 lines
drivers/resctrl/mpam_internal.h struct mpam_props { · line 172
Quoted 6 lines
drivers/resctrl/mpam_internal.h +1
-5-static inline bool mpam_has_feature (enum mpam_device_features feat, -struct mpam_props *props) -{ -return (1 << feat) & props->features; -} +#define mpam_has_feature (_feat, x) ((1 << (_feat)) & (x)->features)If this is worth doing push it back to original introduction. I'm not sure it is necessary.
It's the change in this patch that makes it necessary, maybe_update_config() goes calling mpam_has_feature() on a configuration instead of a class/msc/ris props structure. I could have made that a separate helper to get the type right - but making it a macro was simpler.
I'll push it back earlier.
Thanks,
James
Re: [PATCH v2 20/29] arm_mpam: Allow configuration to be applied and restored during cpu online
In reply to James MorseHi James,
Quoted 18 lines · James Morse
When CPUs come online the MSC's original configuration should be restored.
Add struct
mpam_configto hold the configuration. This has a bitmap of features that were modified. Once the maximum partid is known, allocate a configuration array for each component, and reprogram each RIS configuration from this.CC Dave Martin <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Switchedentry_rcuto srcu versions.Changes since RFC:
* Added a comment about the ordering aroundmax_partid.
* Allocate configurations after interrupts are registered to reduce churn.
* Addedmpam_assert_partid_sizes_fixed();
* Make reset use an all-ones instead of zero config.
Quoted 5 lines
--- drivers/resctrl/mpam_devices.c | 269 +++++++++++++++++++++++++++++--- drivers/resctrl/mpam_internal.h | 29 +++- 2 files changed, 271 insertions(+), 27 deletions(-)
Thanks,
Ben
Fenghua Yu
reviewerRe: [PATCH v2 20/29] arm_mpam: Allow configuration to be applied and restored during cpu online
In reply to James MorseHi, James,
Quoted 192 lines · James Morse
When CPUs come online the MSC's original configuration should be restored.
Add struct
mpam_configto hold the configuration. This has a bitmap of features that were modified. Once the maximum partid is known, allocate a configuration array for each component, and reprogram each RIS configuration from this.CC Dave Martin <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Switchedentry_rcuto srcu versions.Changes since RFC:
* Added a comment about the ordering aroundmax_partid.
* Allocate configurations after interrupts are registered to reduce churn.
* Addedmpam_assert_partid_sizes_fixed();
* Make reset use an all-ones instead of zero config.--- drivers/resctrl/mpam_devices.c | 269 +++++++++++++++++++++++++++++--- drivers/resctrl/mpam_internal.h | 29 +++- 2 files changed, 271 insertions(+), 27 deletions(-)drivers/resctrl/mpam_devices.c +90
-17@@ -114,6 +114,16 @@ static LLIST_HEAD(mpam_garbage);/* When mpam is disabled, the printed reason to aid debugging */ static char *mpam_disable_reason; +/* +* Once mpam is enabled, new requestors cannot further reduce the available +* partid. Assert that the size is fixed, and new requestors will be turned +* away. +*/ +static void mpam_assert_partid_sizes_fixed (void ) +{ +WARN_ON_ONCE (!partid_max_published); +} +static u32 __mpam_read_reg (struct mpam_msc *msc,u16 reg) {WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility));@@ -363,12 +373,16 @@ static void mpam_class_destroy(struct mpam_class *class)add_to_garbage (class); } +static void __destroy_component_cfg (struct mpam_component *comp); +static void mpam_comp_destroy (struct mpam_component *comp) {struct mpam_class *class = comp->class;lockdep_assert_held (&mpam_list_lock); +__destroy_component_cfg (comp); +list_del_rcu (&comp->class_list);add_to_garbage (comp);@@ -833,50 +847,105 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)__mpam_write_reg (msc, reg, bm); } -static void mpam_reset_ris_partid (struct mpam_msc_ris *ris,u16 partid) +/* Called via IPI. Call while holding an SRCU reference */ +static void mpam_reprogram_ris_partid (struct mpam_msc_ris *ris,u16 partid, +struct mpam_config *cfg) {struct mpam_msc *msc = ris->vmsc->msc;struct mpam_props *rprops = &ris->props; -mpam_assert_srcu_read_lock_held (); -mutex_lock (&msc->part_sel_lock);__mpam_part_sel (ris->ris_idx, partid, msc); -if (mpam_has_feature (mpam_feat_cpor_part, rprops)) -mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , rprops->cpbm_wd); +if (mpam_has_feature (mpam_feat_cpor_part, rprops) && +mpam_has_feature (mpam_feat_cpor_part, cfg)) { +if (cfg->reset_cpbm) +mpam_reset_msc_bitmap (msc,MPAMCFG_CPBM , + rprops->cpbm_wd); +else +mpam_write_partsel_reg (msc,CPBM , cfg->cpbm); + } -if (mpam_has_feature (mpam_feat_mbw_part, rprops)) -mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , rprops->mbw_pbm_bits); +if (mpam_has_feature (mpam_feat_mbw_part, rprops) && +mpam_has_feature (mpam_feat_mbw_part, cfg)) { +if (cfg->reset_mbw_pbm) +mpam_reset_msc_bitmap (msc,MPAMCFG_MBW_PBM , + rprops->mbw_pbm_bits); +else +mpam_write_partsel_reg (msc,MBW_PBM , cfg->mbw_pbm); + } -if (mpam_has_feature (mpam_feat_mbw_min, rprops)) +if (mpam_has_feature (mpam_feat_mbw_min, rprops) && +mpam_has_feature (mpam_feat_mbw_min, cfg))mpam_write_partsel_reg (msc,MBW_MIN ,0 ); -if (mpam_has_feature (mpam_feat_mbw_max, rprops)) -mpam_write_partsel_reg (msc,MBW_MAX ,MPAMCFG_MBW_MAX_MAX ); +if (mpam_has_feature (mpam_feat_mbw_max, rprops) && +mpam_has_feature (mpam_feat_mbw_max, cfg)) +mpam_write_partsel_reg (msc,MBW_MAX , cfg->mbw_max); -if (mpam_has_feature (mpam_feat_mbw_prop, rprops)) +if (mpam_has_feature (mpam_feat_mbw_prop, rprops) && +mpam_has_feature (mpam_feat_mbw_prop, cfg))mpam_write_partsel_reg (msc,MBW_PROP ,0 );mutex_unlock (&msc->part_sel_lock); } +struct reprogram_ris { +struct mpam_msc_ris *ris; +struct mpam_config *cfg; +}; + +/* Call with MSC lock held */ +static int mpam_reprogram_ris (void *_arg) +{ +u16 partid, partid_max; +struct reprogram_ris *arg = _arg; +struct mpam_msc_ris *ris = arg->ris; +struct mpam_config *cfg = arg->cfg; + +if (ris->in_reset_state) +return 0 ; + +spin_lock (&partid_max_lock); + partid_max = mpam_partid_max; +spin_unlock (&partid_max_lock); +for (partid =0 ; partid <= partid_max; partid++) +mpam_reprogram_ris_partid (ris, partid, cfg); + +return 0 ; +} + +static void mpam_init_reset_cfg (struct mpam_config *reset_cfg) +{ +memset (reset_cfg,0 ,sizeof (*reset_cfg)); + + reset_cfg->features = ~0 ; + reset_cfg->cpbm = ~0 ; + reset_cfg->mbw_pbm = ~0 ; + reset_cfg->mbw_max =MPAMCFG_MBW_MAX_MAX ; + + reset_cfg->reset_cpbm = true; + reset_cfg->reset_mbw_pbm = true; +} +/* * Called via smp_call_on_cpu() to prevent migration, while still being * pre-emptible. */ static int mpam_reset_ris (void *arg) { -u16 partid, partid_max; +struct mpam_config reset_cfg;struct mpam_msc_ris *ris = arg; +struct reprogram_ris reprogram_arg;if (ris->in_reset_state)return 0 ; -spin_lock (&partid_max_lock); - partid_max = mpam_partid_max; -spin_unlock (&partid_max_lock); -for (partid =0 ; partid < partid_max; partid++) -mpam_reset_ris_partid (ris, partid); +mpam_init_reset_cfg (&reset_cfg); + + reprogram_arg.ris = ris; + reprogram_arg.cfg = &reset_cfg; + +mpam_reprogram_ris (&reprogram_arg);return 0 ; }@@ -922,6 +991,40 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void mpam_reprogram_msc (struct mpam_msc *msc) +{ +u16 partid; +bool reset;
drivers/resctrl/mpam_devices.c static void mpam_reset_msc(struct mpam_msc *msc, bool online) · line 1007
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+struct mpam_config *cfg; +struct mpam_msc_ris *ris; + +/* +* No lock for mpam_partid_max as partid_max_published has been +* set by mpam_enabled(), so the values can no longer change. +*/ +mpam_assert_partid_sizes_fixed (); + +guard (srcu)(&mpam_srcu);
mpam_srcu is locked in caller mpam_cpu_online(). It's unnecessary to call guard(srcu)(&mpam_srcu) here again for simpler logic and less overhead.
Quoted 24 lines
drivers/resctrl/mpam_devices.c +20
-0+list_for_each_entry_srcu (ris, &msc->ris, msc_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!mpam_is_enabled () && !ris->in_reset_state) { +mpam_touch_msc (msc, &mpam_reset_ris, ris); + ris->in_reset_state = true; +continue ; + } + + reset = true; +for (partid =0 ; partid <= mpam_partid_max; partid++) { + cfg = &ris->vmsc->comp->cfg[partid]; +if (cfg->features) + reset = false; + +mpam_reprogram_ris_partid (ris, partid, cfg); + } + ris->in_reset_state = reset; + } +} +static void _enable_percpu_irq (void *_irq) {int *irq = _irq;
drivers/resctrl/mpam_devices.c static int mpam_cpu_online(unsigned int cpu) · line 1052
Quoted 7 lines
drivers/resctrl/mpam_devices.c +1
-1@@ -944,7 +1047,7 @@ static int mpam_cpu_online(unsigned int cpu)_enable_percpu_irq (&msc->reenable_error_ppi);if (atomic_fetch_inc (&msc->online_refs) ==0 ) -mpam_reset_msc (msc, true); +mpam_reprogram_msc (msc); }srcu_read_unlock (&mpam_srcu, idx);
[SNIP]
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 20/29] arm_mpam: Allow configuration to be applied and restored during cpu online
Hi Fenghua,
Quoted 26 lines · Fenghua Yu
Quoted 25 lines · James Morse
When CPUs come online the MSC's original configuration should be restored.
Add struct
mpam_configto hold the configuration. This has a bitmap of features that were modified. Once the maximum partid is known, allocate a configuration array for each component, and reprogram each RIS configuration from this.drivers/resctrl/mpam_devices.c +8
-0@@ -922,6 +991,40 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online) } } +static void mpam_reprogram_msc(struct mpam_msc *msc) +{ + u16 partid; + bool reset; + struct mpam_config *cfg; + struct mpam_msc_ris *ris; + + /* +* No lock for mpam_partid_max as partid_max_published has been
Quoted 8 lines
drivers/resctrl/mpam_devices.c static void mpam_reset_msc(struct mpam_msc *msc, bool online) · line 1007
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+* set by mpam_enabled(), so the values can no longer change. +*/ + mpam_assert_partid_sizes_fixed(); + + guard(srcu)(&mpam_srcu);
mpam_srcuis locked in callermpam_cpu_online(). It's unnecessary to call guard(srcu) (&mpam_srcu) here again for simpler logic and less overhead.
It's not simpler - as now the requirements for the innards of mpam_reprogram_msc() have to spill out to the callers.
I also contest that its less overhead - this is used on the cpuhp path, I'd suspect the 'cost' can't even be measured.
The good news is at the end of the day this thing only has that one caller, so I'll change this one ...
Thanks,
James
James Morse
maintainerPATCH v2 21/29 arm_mpam: Probe and reset the rest of the features
In reply to James MorseMPAM supports more features than are going to be exposed to resctrl. For partid other than 0, the reset values of these controls isn't known.
Discover the rest of the features so they can be reset to avoid any side effects when resctrl is in use.
PARTID narrowing allows MSC/RIS to support less configuration space than is usable. If this feature is found on a class of device we are likely to use, then reduce the partid_max to make it usable. This allows us to map a PARTID to itself.
---
Changes since v1:
* Added reset for cassoc.
* Added detection of CSU XCL.
--- drivers/resctrl/mpam_devices.c | 181 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 17 ++- 2 files changed, 196 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +181 -0
@@ -214,6 +214,15 @@ static void __mpam_part_sel(u8 ris_idx, u16 partid, struct mpam_msc *msc)__mpam_part_sel_raw (partsel, msc); } +static void __mpam_intpart_sel (u8 ris_idx,u16 intpartid,struct mpam_msc *msc) +{ +u32 partsel =FIELD_PREP (MPAMCFG_PART_SEL_RIS , ris_idx) | +FIELD_PREP (MPAMCFG_PART_SEL_PARTID_SEL , intpartid) | +MPAMCFG_PART_SEL_INTERNAL ; + +__mpam_part_sel_raw (partsel, msc); +} +int mpam_register_requestor (u16 partid_max,u8 pmg_max) {int err =0 ;
@@ -667,10 +676,35 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)struct mpam_msc *msc = ris->vmsc->msc;struct device *dev = &msc->pdev->dev;struct mpam_props *props = &ris->props; +struct mpam_class *class = ris->vmsc->comp->class;lockdep_assert_held (&msc->probe_lock);lockdep_assert_held (&msc->part_sel_lock); +/* Cache Capacity Partitioning */ +if (FIELD_GET (MPAMF_IDR_HAS_CCAP_PART , ris->idr)) { +u32 ccap_features =mpam_read_partsel_reg (msc,CCAP_IDR ); + + props->cmax_wd =FIELD_GET (MPAMF_CCAP_IDR_CMAX_WD , ccap_features); +if (props->cmax_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CMAX_SOFTLIM , ccap_features)) +mpam_set_feature (mpam_feat_cmax_softlim, props); + +if (props->cmax_wd && + !FIELD_GET (MPAMF_CCAP_IDR_NO_CMAX , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cmax, props); + +if (props->cmax_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CMIN , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cmin, props); + + props->cassoc_wd =FIELD_GET (MPAMF_CCAP_IDR_CASSOC_WD , ccap_features); + +if (props->cassoc_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CASSOC , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cassoc, props); + } +/* Cache Portion partitioning */ if (FIELD_GET (MPAMF_IDR_HAS_CPOR_PART , ris->idr)) {u32 cpor_features =mpam_read_partsel_reg (msc,CPOR_IDR );
@@ -693,6 +727,31 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) props->bwa_wd =FIELD_GET (MPAMF_MBW_IDR_BWA_WD , mbw_features);if (props->bwa_wd &&FIELD_GET (MPAMF_MBW_IDR_HAS_MAX , mbw_features))mpam_set_feature (mpam_feat_mbw_max, props); + +if (props->bwa_wd &&FIELD_GET (MPAMF_MBW_IDR_HAS_MIN , mbw_features)) +mpam_set_feature (mpam_feat_mbw_min, props); + +if (props->bwa_wd &&FIELD_GET (MPAMF_MBW_IDR_HAS_PROP , mbw_features)) +mpam_set_feature (mpam_feat_mbw_prop, props); + } + +/* Priority partitioning */ +if (FIELD_GET (MPAMF_IDR_HAS_PRI_PART , ris->idr)) { +u32 pri_features =mpam_read_partsel_reg (msc,PRI_IDR ); + + props->intpri_wd =FIELD_GET (MPAMF_PRI_IDR_INTPRI_WD , pri_features); +if (props->intpri_wd &&FIELD_GET (MPAMF_PRI_IDR_HAS_INTPRI , pri_features)) { +mpam_set_feature (mpam_feat_intpri_part, props); +if (FIELD_GET (MPAMF_PRI_IDR_INTPRI_0_IS_LOW , pri_features)) +mpam_set_feature (mpam_feat_intpri_part_0_low, props); + } + + props->dspri_wd =FIELD_GET (MPAMF_PRI_IDR_DSPRI_WD , pri_features); +if (props->dspri_wd &&FIELD_GET (MPAMF_PRI_IDR_HAS_DSPRI , pri_features)) { +mpam_set_feature (mpam_feat_dspri_part, props); +if (FIELD_GET (MPAMF_PRI_IDR_DSPRI_0_IS_LOW , pri_features)) +mpam_set_feature (mpam_feat_dspri_part_0_low, props); + } }/* Performance Monitoring */
@@ -717,6 +776,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)mpam_set_feature (mpam_feat_msmon_csu, props); +if (FIELD_GET (MPAMF_CSUMON_IDR_HAS_XCL , csumonidr)) +mpam_set_feature (mpam_feat_msmon_csu_xcl, props); +/* Is NRDY hardware managed? */ hw_managed =mpam_ris_hw_probe_hw_nrdy (ris,CSU );if (hw_managed)
@@ -752,6 +814,21 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)*/ } } + +/* +* RIS with PARTID narrowing don't have enough storage for one +* configuration per PARTID. If these are in a class we could use, +* reduce the supported partid_max to match the number of intpartid. +* If the class is unknown, just ignore it. +*/ +if (FIELD_GET (MPAMF_IDR_HAS_PARTID_NRW , ris->idr) && + class->type !=MPAM_CLASS_UNKNOWN ) { +u32 nrwidr =mpam_read_partsel_reg (msc,PARTID_NRW_IDR ); +u16 partid_max =FIELD_GET (MPAMF_PARTID_NRW_IDR_INTPARTID_MAX , nrwidr); + +mpam_set_feature (mpam_feat_partid_nrw, props); + msc->partid_max =min (msc->partid_max, partid_max); + } }static int mpam_msc_hw_probe (struct mpam_msc *msc)
@@ -851,12 +928,28 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd)static void mpam_reprogram_ris_partid (struct mpam_msc_ris *ris,u16 partid,struct mpam_config *cfg) { +u32 pri_val =0 ; +u16 cmax =MPAMCFG_CMAX_CMAX ;struct mpam_msc *msc = ris->vmsc->msc;struct mpam_props *rprops = &ris->props; +u16 dspri =GENMASK (rprops->dspri_wd,0 ); +u16 intpri =GENMASK (rprops->intpri_wd,0 );mutex_lock (&msc->part_sel_lock);__mpam_part_sel (ris->ris_idx, partid, msc); +if (mpam_has_feature (mpam_feat_partid_nrw, rprops)) { +/* Update the intpartid mapping */ +mpam_write_partsel_reg (msc,INTPARTID , +MPAMCFG_INTPARTID_INTERNAL | partid); + +/* +* Then switch to the 'internal' partid to update the +* configuration. +*/ +__mpam_intpart_sel (ris->ris_idx, partid, msc); + } +if (mpam_has_feature (mpam_feat_cpor_part, rprops) &&mpam_has_feature (mpam_feat_cpor_part, cfg)) {if (cfg->reset_cpbm)
@@ -886,6 +979,32 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,if (mpam_has_feature (mpam_feat_mbw_prop, rprops) &&mpam_has_feature (mpam_feat_mbw_prop, cfg))mpam_write_partsel_reg (msc,MBW_PROP ,0 ); + +if (mpam_has_feature (mpam_feat_cmax_cmax, rprops)) +mpam_write_partsel_reg (msc,CMAX , cmax); + +if (mpam_has_feature (mpam_feat_cmax_cmin, rprops)) +mpam_write_partsel_reg (msc,CMIN ,0 ); + +if (mpam_has_feature (mpam_feat_cmax_cassoc, rprops)) +mpam_write_partsel_reg (msc,CASSOC ,MPAMCFG_CASSOC_CASSOC ); + +if (mpam_has_feature (mpam_feat_intpri_part, rprops) || +mpam_has_feature (mpam_feat_dspri_part, rprops)) { +/* aces high? */ +if (!mpam_has_feature (mpam_feat_intpri_part_0_low, rprops)) + intpri =0 ; +if (!mpam_has_feature (mpam_feat_dspri_part_0_low, rprops)) + dspri =0 ; + +if (mpam_has_feature (mpam_feat_intpri_part, rprops)) + pri_val |=FIELD_PREP (MPAMCFG_PRI_INTPRI , intpri); +if (mpam_has_feature (mpam_feat_dspri_part, rprops)) + pri_val |=FIELD_PREP (MPAMCFG_PRI_DSPRI , dspri); + +mpam_write_partsel_reg (msc,PRI , pri_val); + } +mutex_unlock (&msc->part_sel_lock); }
@@ -1314,6 +1433,16 @@ static bool mpam_has_bwa_wd_feature(struct mpam_props *props)return false; } +/* Any of these features mean the CMAX_WD field is valid. */ +static bool mpam_has_cmax_wd_feature (struct mpam_props *props) +{ +if (mpam_has_feature (mpam_feat_cmax_cmax, props)) +return true; +if (mpam_has_feature (mpam_feat_cmax_cmin, props)) +return true; +return false; +} +#define MISMATCHED_HELPER (parent, child, helper, field, alias) \ helper(parent) && \ ((helper(child) && (parent)->field != (child)->field) || \
@@ -1368,6 +1497,23 @@ static void __props_mismatch(struct mpam_props *parent, parent->bwa_wd =min (parent->bwa_wd, child->bwa_wd); } +if (alias && !mpam_has_cmax_wd_feature (parent) &&mpam_has_cmax_wd_feature (child)) { + parent->cmax_wd = child->cmax_wd; + }else if (MISMATCHED_HELPER (parent, child, mpam_has_cmax_wd_feature, + cmax_wd, alias)) { +pr_debug ("%s took the min cmax_wd\n" , __func__); + parent->cmax_wd =min (parent->cmax_wd, child->cmax_wd); + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_cmax_cassoc, alias)) { + parent->cassoc_wd = child->cassoc_wd; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_cmax_cassoc, + cassoc_wd, alias)) { +pr_debug ("%s cleared cassoc_wd\n" , __func__); +mpam_clear_feature (mpam_feat_cmax_cassoc, &parent->features); + parent->cassoc_wd =0 ; + } +/* For num properties, take the minimum */ if (CAN_MERGE_FEAT (parent, child, mpam_feat_msmon_csu, alias)) { parent->num_csu_mon = child->num_csu_mon;
@@ -1385,6 +1531,41 @@ static void __props_mismatch(struct mpam_props *parent, parent->num_mbwu_mon =min (parent->num_mbwu_mon, child->num_mbwu_mon); } +if (CAN_MERGE_FEAT (parent, child, mpam_feat_intpri_part, alias)) { + parent->intpri_wd = child->intpri_wd; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_intpri_part, + intpri_wd, alias)) { +pr_debug ("%s took the min intpri_wd\n" , __func__); + parent->intpri_wd =min (parent->intpri_wd, child->intpri_wd); + } + +if (CAN_MERGE_FEAT (parent, child, mpam_feat_dspri_part, alias)) { + parent->dspri_wd = child->dspri_wd; + }else if (MISMATCHED_FEAT (parent, child, mpam_feat_dspri_part, + dspri_wd, alias)) { +pr_debug ("%s took the min dspri_wd\n" , __func__); + parent->dspri_wd =min (parent->dspri_wd, child->dspri_wd); + } + +/* TODO: alias support for these two */ +/* {int,ds}pri may not have differing 0-low behaviour */ +if (mpam_has_feature (mpam_feat_intpri_part, parent) && + (!mpam_has_feature (mpam_feat_intpri_part, child) || +mpam_has_feature (mpam_feat_intpri_part_0_low, parent) != +mpam_has_feature (mpam_feat_intpri_part_0_low, child))) { +pr_debug ("%s cleared intpri_part\n" , __func__); +mpam_clear_feature (mpam_feat_intpri_part, &parent->features); +mpam_clear_feature (mpam_feat_intpri_part_0_low, &parent->features); + } +if (mpam_has_feature (mpam_feat_dspri_part, parent) && + (!mpam_has_feature (mpam_feat_dspri_part, child) || +mpam_has_feature (mpam_feat_dspri_part_0_low, parent) != +mpam_has_feature (mpam_feat_dspri_part_0_low, child))) { +pr_debug ("%s cleared dspri_part\n" , __func__); +mpam_clear_feature (mpam_feat_dspri_part, &parent->features); +mpam_clear_feature (mpam_feat_dspri_part_0_low, &parent->features); + } +if (alias) {/* Merge features for aliased resources */ parent->features |= child->features;
drivers/resctrl/mpam_internal.h +15 -2
@@ -136,25 +136,34 @@ static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc)* When we compact the supported features, we don't care what they are. * Storing them as a bitmap makes life easy. */ -typedef u16 mpam_features_t ; +typedef u32 mpam_features_t ;/* Bits for mpam_features_t */ enum mpam_device_features { - mpam_feat_ccap_part =0 , + mpam_feat_cmax_softlim, + mpam_feat_cmax_cmax, + mpam_feat_cmax_cmin, + mpam_feat_cmax_cassoc, mpam_feat_cpor_part, mpam_feat_mbw_part, mpam_feat_mbw_min, mpam_feat_mbw_max, mpam_feat_mbw_prop, + mpam_feat_intpri_part, + mpam_feat_intpri_part_0_low, + mpam_feat_dspri_part, + mpam_feat_dspri_part_0_low, mpam_feat_msmon, mpam_feat_msmon_csu, mpam_feat_msmon_csu_capture, + mpam_feat_msmon_csu_xcl, mpam_feat_msmon_csu_hw_nrdy, mpam_feat_msmon_mbwu, mpam_feat_msmon_mbwu_capture, mpam_feat_msmon_mbwu_rwbw, mpam_feat_msmon_mbwu_hw_nrdy, mpam_feat_msmon_capt, + mpam_feat_partid_nrw,MPAM_FEATURE_LAST , };static_assert (BITS_PER_TYPE (mpam_features_t) >=MPAM_FEATURE_LAST );
@@ -165,6 +174,10 @@ struct mpam_props {u16 cpbm_wd;u16 mbw_pbm_bits;u16 bwa_wd; +u16 cmax_wd; +u16 cassoc_wd; +u16 intpri_wd; +u16 dspri_wd;u16 num_csu_mon;u16 num_mbwu_mon; };
Signature · 1 line
2.39.5
Re: [PATCH v2 21/29] arm_mpam: Probe and reset the rest of the features
Quoted 12 lines · On Wed, 10 Sep 2025 20:43:01 +0000 James Morse <[email protected]> wrote:
MPAM supports more features than are going to be exposed to resctrl. For partid other than 0, the reset values of these controls isn't known.
Discover the rest of the features so they can be reset to avoid any side effects when resctrl is in use.
PARTID narrowing allows MSC/RIS to support less configuration space than is usable. If this feature is found on a class of device we are likely to use, then reduce the
partid_maxto make it usable. This allows us to map a PARTID to itself.
Quoted 4 lines
CC Rohit Mathew <[email protected]>CC Zeng Heng <[email protected]>CC Dave Martin <[email protected]>Signed-off-by James Morse <[email protected]>
A few trivial things inline.
Quoted 21 lines
int
mpam_register_requestor(u16 partid_max, u8 pmg_max){drivers/resctrl/mpam_devices.c +10
-0int err =0 ;@@ -667,10 +676,35 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)struct mpam_msc *msc = ris->vmsc->msc;struct device *dev = &msc->pdev->dev;struct mpam_props *props = &ris->props; +struct mpam_class *class = ris->vmsc->comp->class;lockdep_assert_held (&msc->probe_lock);lockdep_assert_held (&msc->part_sel_lock); +/* Cache Capacity Partitioning */ +if (FIELD_GET (MPAMF_IDR_HAS_CCAP_PART , ris->idr)) { +u32 ccap_features =mpam_read_partsel_reg (msc,CCAP_IDR ); + + props->cmax_wd =FIELD_GET (MPAMF_CCAP_IDR_CMAX_WD , ccap_features); +if (props->cmax_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CMAX_SOFTLIM , ccap_features)) +mpam_set_feature (mpam_feat_cmax_softlim, props); +
drivers/resctrl/mpam_devices.c static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) · line 702
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+if (props->cmax_wd && + !FIELD_GET (MPAMF_CCAP_IDR_NO_CMAX , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cmax, props); + +if (props->cmax_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CMIN , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cmin, props); + + props->cassoc_wd =FIELD_GET (MPAMF_CCAP_IDR_CASSOC_WD , ccap_features); +
Trivial but blank line here feels inconsistent with local style. I'd drop it.
Quoted 11 lines
drivers/resctrl/mpam_devices.c +5
-0+if (props->cassoc_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CASSOC , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cassoc, props); + } +drivers/resctrl/mpam_internal.h +0
-0
drivers/resctrl/mpam_internal.h static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc) · line 139
Quoted 5 lines
drivers/resctrl/mpam_internal.h +1
-1@@ -136,25 +136,34 @@ static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc)* When we compact the supported features, we don't care what they are. * Storing them as a bitmap makes life easy. */ -typedef u16 mpam_features_t ; +typedef u32 mpam_features_t ;
This is strengthening my view that this should just be a DECLARE_BITMAP(MPAM_FEATURE_LAST) in the appropriate places.
Quoted 42 lines
drivers/resctrl/mpam_internal.h +14
-1/* Bits for mpam_features_t */ enum mpam_device_features { - mpam_feat_ccap_part =0 , + mpam_feat_cmax_softlim, + mpam_feat_cmax_cmax, + mpam_feat_cmax_cmin, + mpam_feat_cmax_cassoc, mpam_feat_cpor_part, mpam_feat_mbw_part, mpam_feat_mbw_min, mpam_feat_mbw_max, mpam_feat_mbw_prop, + mpam_feat_intpri_part, + mpam_feat_intpri_part_0_low, + mpam_feat_dspri_part, + mpam_feat_dspri_part_0_low, mpam_feat_msmon, mpam_feat_msmon_csu, mpam_feat_msmon_csu_capture, + mpam_feat_msmon_csu_xcl, mpam_feat_msmon_csu_hw_nrdy, mpam_feat_msmon_mbwu, mpam_feat_msmon_mbwu_capture, mpam_feat_msmon_mbwu_rwbw, mpam_feat_msmon_mbwu_hw_nrdy, mpam_feat_msmon_capt, + mpam_feat_partid_nrw,MPAM_FEATURE_LAST , };static_assert (BITS_PER_TYPE (mpam_features_t) >=MPAM_FEATURE_LAST );@@ -165,6 +174,10 @@ struct mpam_props {u16 cpbm_wd;u16 mbw_pbm_bits;u16 bwa_wd; +u16 cmax_wd; +u16 cassoc_wd; +u16 intpri_wd; +u16 dspri_wd;u16 num_csu_mon;u16 num_mbwu_mon; };
James Morse
maintainerRe: [PATCH v2 21/29] arm_mpam: Probe and reset the rest of the features
Hi Jonathan,
Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 10 Sep 2025 20:43:01 +0000 James Morse <[email protected]> wrote:
MPAM supports more features than are going to be exposed to resctrl. For partid other than 0, the reset values of these controls isn't known.
Discover the rest of the features so they can be reset to avoid any side effects when resctrl is in use.
Quoted 8 lines
Quoted 4 lines
PARTID narrowing allows MSC/RIS to support less configuration space than is usable. If this feature is found on a class of device we are likely to use, then reduce the
partid_maxto make it usable. This allows us to map a PARTID to itself.A few trivial things inline.
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 22 lines
Quoted 22 lines
drivers/resctrl/mpam_devices.c +14
-0@@ -667,10 +676,35 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)struct mpam_msc *msc = ris->vmsc->msc;struct device *dev = &msc->pdev->dev;struct mpam_props *props = &ris->props; +struct mpam_class *class = ris->vmsc->comp->class;lockdep_assert_held (&msc->probe_lock);lockdep_assert_held (&msc->part_sel_lock); +/* Cache Capacity Partitioning */ +if (FIELD_GET (MPAMF_IDR_HAS_CCAP_PART , ris->idr)) { +u32 ccap_features =mpam_read_partsel_reg (msc,CCAP_IDR ); + + props->cmax_wd =FIELD_GET (MPAMF_CCAP_IDR_CMAX_WD , ccap_features); +if (props->cmax_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CMAX_SOFTLIM , ccap_features)) +mpam_set_feature (mpam_feat_cmax_softlim, props); + +if (props->cmax_wd && + !FIELD_GET (MPAMF_CCAP_IDR_NO_CMAX , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cmax, props); +
Quoted 8 lines
drivers/resctrl/mpam_devices.c static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) · line 702
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+if (props->cmax_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CMIN , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cmin, props); + + props->cassoc_wd =FIELD_GET (MPAMF_CCAP_IDR_CASSOC_WD , ccap_features); +Trivial but blank line here feels inconsistent with local style. I'd drop it.
Sure,
Quoted 6 lines
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+if (props->cassoc_wd && +FIELD_GET (MPAMF_CCAP_IDR_HAS_CASSOC , ccap_features)) +mpam_set_feature (mpam_feat_cmax_cassoc, props); + } +
Quoted 13 lines
drivers/resctrl/mpam_internal.h static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc) · line 139
Quoted 10 lines
drivers/resctrl/mpam_internal.h +1
-1@@ -136,25 +136,34 @@ static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc)* When we compact the supported features, we don't care what they are. * Storing them as a bitmap makes life easy. */ -typedef u16 mpam_features_t ; +typedef u32 mpam_features_t ;This is strengthening my view that this should just be a
DECLARE_BITMAP(MPAM_FEATURE_LAST)in the appropriate places.
I don't think this list is going to grow much. But sure.
Most stuff can be churned out, but this makes an utter mess of exposing the value to debugfs.., I do need that exposed as "why didn't resctrl do what I wanted" is a very common question - and being able to see what the hardware supports really helps.
Looks like exposing the first 'ulong' is the simplest - it kicks the can this creates down the road. I experimented with u32_array - but its no better.
Thanks,
James
James Morse
maintainerPATCH v2 22/29 arm_mpam: Add helpers to allocate monitors
In reply to James MorseMPAM's MSC support a number of monitors, each of which supports bandwidth counters, or cache-storage-utilisation counters. To use a counter, a monitor needs to be configured. Add helpers to allocate and free CSU or MBWU monitors.
--- drivers/resctrl/mpam_devices.c | 2 ++ drivers/resctrl/mpam_internal.h | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
drivers/resctrl/mpam_devices.c +2 -0
@@ -340,6 +340,8 @@ mpam_class_alloc(u8 level_idx, enum mpam_class_types type) class->level = level_idx; class->type = type;INIT_LIST_HEAD_RCU (&class->classes_list); +ida_init (&class->ida_csu_mon); +ida_init (&class->ida_mbwu_mon);list_add_rcu (&class->classes_list, &mpam_classes);
drivers/resctrl/mpam_internal.h +35 -0
@@ -210,6 +210,9 @@ struct mpam_class {/* member of mpam_classes */ struct list_head classes_list; +struct ida ida_csu_mon; +struct ida ida_mbwu_mon; +struct mpam_garbage garbage; };
@@ -288,6 +291,38 @@ struct mpam_msc_ris {struct mpam_garbage garbage; }; +static inline int mpam_alloc_csu_mon (struct mpam_class *class) +{ +struct mpam_props *cprops = &class->props; + +if (!mpam_has_feature (mpam_feat_msmon_csu, cprops)) +return -EOPNOTSUPP ; + +return ida_alloc_range (&class->ida_csu_mon,0 , cprops->num_csu_mon -1 , +GFP_KERNEL ); +} + +static inline void mpam_free_csu_mon (struct mpam_class *class,int csu_mon) +{ +ida_free (&class->ida_csu_mon, csu_mon); +} + +static inline int mpam_alloc_mbwu_mon (struct mpam_class *class) +{ +struct mpam_props *cprops = &class->props; + +if (!mpam_has_feature (mpam_feat_msmon_mbwu, cprops)) +return -EOPNOTSUPP ; + +return ida_alloc_range (&class->ida_mbwu_mon,0 , + cprops->num_mbwu_mon -1 ,GFP_KERNEL ); +} + +static inline void mpam_free_mbwu_mon (struct mpam_class *class,int mbwu_mon) +{ +ida_free (&class->ida_mbwu_mon, mbwu_mon); +} +/* List of all classes - protected by srcu*/ extern struct srcu_struct mpam_srcu;extern struct list_head mpam_classes;
Signature · 1 line
2.39.5
Re: [PATCH v2 22/29] arm_mpam: Add helpers to allocate monitors
Quoted 7 lines · On Wed, 10 Sep 2025 20:43:02 +0000 James Morse <[email protected]> wrote:
MPAM's MSC support a number of monitors, each of which supports bandwidth counters, or cache-storage-utilisation counters. To use a counter, a monitor needs to be configured. Add helpers to allocate and free CSU or MBWU monitors.
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
One minor requested change inline that will probably otherwise get picked up by someone's cleanup script
Quoted 51 lines
--- drivers/resctrl/mpam_devices.c | 2 ++ drivers/resctrl/mpam_internal.h | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/resctrl/mpam_devices.c +2
-0@@ -340,6 +340,8 @@ mpam_class_alloc(u8 level_idx, enum mpam_class_types type) class->level = level_idx; class->type = type;INIT_LIST_HEAD_RCU (&class->classes_list); +ida_init (&class->ida_csu_mon); +ida_init (&class->ida_mbwu_mon);list_add_rcu (&class->classes_list, &mpam_classes);drivers/resctrl/mpam_internal.h +18
-0@@ -210,6 +210,9 @@ struct mpam_class {/* member of mpam_classes */ struct list_head classes_list; +struct ida ida_csu_mon; +struct ida ida_mbwu_mon; +struct mpam_garbage garbage; };@@ -288,6 +291,38 @@ struct mpam_msc_ris {struct mpam_garbage garbage; }; +static inline int mpam_alloc_csu_mon (struct mpam_class *class) +{ +struct mpam_props *cprops = &class->props; + +if (!mpam_has_feature (mpam_feat_msmon_csu, cprops)) +return -EOPNOTSUPP ; + +return ida_alloc_range (&class->ida_csu_mon,0 , cprops->num_csu_mon -1 , +GFP_KERNEL ); +} + +static inline void mpam_free_csu_mon (struct mpam_class *class,int csu_mon) +{ +ida_free (&class->ida_csu_mon, csu_mon); +}
drivers/resctrl/mpam_internal.h struct mpam_msc_ris { · line 318
Quoted 10 lines
drivers/resctrl/mpam_internal.h +10
-0+ +static inline int mpam_alloc_mbwu_mon (struct mpam_class *class) +{ +struct mpam_props *cprops = &class->props; + +if (!mpam_has_feature (mpam_feat_msmon_mbwu, cprops)) +return -EOPNOTSUPP ; + +return ida_alloc_range (&class->ida_mbwu_mon,0 , + cprops->num_mbwu_mon -1 ,GFP_KERNEL );
ida_alloc_max() - which is just a wrapper that sets the minimum to 0 but none the less perhaps conveys things slightly better.
Quoted 10 lines
drivers/resctrl/mpam_internal.h +7
-0+} + +static inline void mpam_free_mbwu_mon (struct mpam_class *class,int mbwu_mon) +{ +ida_free (&class->ida_mbwu_mon, mbwu_mon); +} +/* List of all classes - protected by srcu*/ extern struct srcu_struct mpam_srcu;extern struct list_head mpam_classes;
James Morse
maintainerRe: [PATCH v2 22/29] arm_mpam: Add helpers to allocate monitors
Hi Jonathan,
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Wed, 10 Sep 2025 20:43:02 +0000 James Morse <[email protected]> wrote:
MPAM's MSC support a number of monitors, each of which supports bandwidth counters, or cache-storage-utilisation counters. To use a counter, a monitor needs to be configured. Add helpers to allocate and free CSU or MBWU monitors.
Quoted 7 lines
Quoted 2 lines
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>One minor requested change inline that will probably otherwise get picked up by someone's cleanup script
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 5 lines
Quoted 4 lines
drivers/resctrl/mpam_internal.h +0
-0
Quoted 12 lines
drivers/resctrl/mpam_internal.h struct mpam_msc_ris { · line 318
Quoted 9 lines
drivers/resctrl/mpam_internal.h +9
-0+static inline int mpam_alloc_mbwu_mon (struct mpam_class *class) +{ +struct mpam_props *cprops = &class->props; + +if (!mpam_has_feature (mpam_feat_msmon_mbwu, cprops)) +return -EOPNOTSUPP ; + +return ida_alloc_range (&class->ida_mbwu_mon,0 , + cprops->num_mbwu_mon -1 ,GFP_KERNEL );
ida_alloc_max()- which is just a wrapper that sets the minimum to 0 but none the less perhaps conveys things slightly better.
Sure - I didn't spot that when I did this.
Thanks,
James
James Morse
maintainerRe: [PATCH v2 22/29] arm_mpam: Add helpers to allocate monitors
In reply to Jonathan CameronHi Jonathan,
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Wed, 10 Sep 2025 20:43:02 +0000 James Morse <[email protected]> wrote:
MPAM's MSC support a number of monitors, each of which supports bandwidth counters, or cache-storage-utilisation counters. To use a counter, a monitor needs to be configured. Add helpers to allocate and free CSU or MBWU monitors.
Quoted 7 lines
Quoted 2 lines
Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>One minor requested change inline that will probably otherwise get picked up by someone's cleanup script
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 5 lines
Quoted 4 lines
drivers/resctrl/mpam_internal.h +0
-0
Quoted 12 lines
drivers/resctrl/mpam_internal.h struct mpam_msc_ris { · line 318
Quoted 9 lines
drivers/resctrl/mpam_internal.h +9
-0+static inline int mpam_alloc_mbwu_mon (struct mpam_class *class) +{ +struct mpam_props *cprops = &class->props; + +if (!mpam_has_feature (mpam_feat_msmon_mbwu, cprops)) +return -EOPNOTSUPP ; + +return ida_alloc_range (&class->ida_mbwu_mon,0 , + cprops->num_mbwu_mon -1 ,GFP_KERNEL );
ida_alloc_max()- which is just a wrapper that sets the minimum to 0 but none the less perhaps conveys things slightly better.
Sure - I didn't spot that when I did this.
Thanks,
James
James Morse
maintainerPATCH v2 23/29 arm_mpam: Add mpam_msmon_read() to read monitor value
In reply to James MorseReading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add mpam_msmon_read() to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.
---
Changes since v1:
* Added XCL support.
* Merged FLT/CTL constants.
* a spelling mistake in a comment.
* moved structrues around.
--- drivers/resctrl/mpam_devices.c | 226 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ 2 files changed, 245 insertions(+)
drivers/resctrl/mpam_devices.c +226 -0
@@ -898,6 +898,232 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)return 0 ; } +struct mon_read { +struct mpam_msc_ris *ris; +struct mon_cfg *ctx; +enum mpam_device_features type; +u64 *val; +int err; +}; + +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mon_cfg *ctx = m->ctx; + +/* +* For CSU counters its implementation-defined what happens when not +* filtering by partid. +*/ + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; + + *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; + *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg); + } + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =MSMON_CFG_CSU_CTL_TYPE_CSU ; + +if (mpam_has_feature (mpam_feat_msmon_csu_xcl, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_CSU_FLT_XCL , + ctx->csu_exclude_clean); + +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =MSMON_CFG_MBWU_CTL_TYPE_MBWU ; + +if (mpam_has_feature (mpam_feat_msmon_mbwu_rwbw, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_MBWU_FLT_RWBW , ctx->opts); + +break ; +default : +return ; + } +} + +static void read_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =mpam_read_monsel_reg (msc,CFG_CSU_CTL ); + *flt_val =mpam_read_monsel_reg (msc,CFG_CSU_FLT ); +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); + *flt_val =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); +break ; +default : +return ; + } +} + +/* Remove values set by the hardware to prevent apparent mismatches. */ +static void clean_msmon_ctl_val (u32 *cur_ctl) +{ + *cur_ctl &= ~MSMON_CFG_x_CTL_OFLOW_STATUS; +} + +static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, +u32 flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +/* +* Write the ctl_val with the enable bit cleared, reset the counter, +* then enable counter. +*/ +switch (m->type) { +case mpam_feat_msmon_csu: +mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +mpam_write_monsel_reg (msc,CSU ,0 ); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +case mpam_feat_msmon_mbwu: +mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +default : +return ; + } +} + +/* Call with MSC lock held */ +static void __ris_msmon_read (void *arg) +{ +u64 now; +bool nrdy = false; +struct mon_read *m = arg; +struct mon_cfg *ctx = m->ctx; +struct mpam_msc_ris *ris = m->ris; +struct mpam_props *rprops = &ris->props; +struct mpam_msc *msc = m->ris->vmsc->msc; +u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt; + +if (!mpam_mon_sel_lock (msc)) { + m->err = -EIO ; +return ; + } + mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , ctx->mon) | +FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); +mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); + +/* +* Read the existing configuration to avoid re-writing the same values. +* This saves waiting for 'nrdy' on subsequent reads. +*/ +read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt); +clean_msmon_ctl_val (&cur_ctl); +gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); +if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) +write_msmon_ctl_flt_vals (m, ctl_val, flt_val); + +switch (m->type) { +case mpam_feat_msmon_csu: + now =mpam_read_monsel_reg (msc,CSU ); +if (mpam_has_feature (mpam_feat_msmon_csu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; +break ; +case mpam_feat_msmon_mbwu: + now =mpam_read_monsel_reg (msc,MBWU ); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; +break ; +default : + m->err = -EINVAL ; +break ; + } +mpam_mon_sel_unlock (msc); + +if (nrdy) { + m->err = -EBUSY ; +return ; + } + + now =FIELD_GET (MSMON___VALUE , now); + *m->val += now; +} + +static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ +int err, idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc; + +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { + arg->ris = ris; + + err =smp_call_function_any (&msc->accessibility, + __ris_msmon_read, arg, + true); +if (!err && arg->err) + err = arg->err; +if (err) +break ; + } +if (err) +break ; + } +srcu_read_unlock (&mpam_srcu, idx); + +return err; +} + +int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx, +enum mpam_device_features type,u64 *val) +{ +int err; +struct mon_read arg; +u64 wait_jiffies =0 ; +struct mpam_props *cprops = &comp->class->props; + +might_sleep (); + +if (!mpam_is_enabled ()) +return -EIO ; + +if (!mpam_has_feature (type, cprops)) +return -EOPNOTSUPP ; + +memset (&arg,0 ,sizeof (arg)); + arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); +if (err == -EBUSY && comp->class->nrdy_usec) + wait_jiffies =usecs_to_jiffies (comp->class->nrdy_usec); + +while (wait_jiffies) + wait_jiffies =schedule_timeout_uninterruptible (wait_jiffies); + +if (err == -EBUSY ) { +memset (&arg,0 ,sizeof (arg)); + arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); + } + +return err; +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;
drivers/resctrl/mpam_internal.h +19 -0
@@ -196,6 +196,22 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, *supported &= ~(1 << feat); } +/* The values for MSMON_CFG_MBWU_FLT.RWBW */ +enum mon_filter_options { +COUNT_BOTH =0 , +COUNT_WRITE =1 , +COUNT_READ =2 , +}; + +struct mon_cfg { +u16 mon; +u8 pmg; +bool match_pmg; +bool csu_exclude_clean; +u32 partid; +enum mon_filter_options opts; +}; +struct mpam_class {/* mpam_components in this class */ struct list_head components;
@@ -343,6 +359,9 @@ void mpam_disable(struct work_struct *work);int mpam_apply_config (struct mpam_component *comp,u16 partid,struct mpam_config *cfg); +int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx, +enum mpam_device_features ,u64 *val); +int mpam_get_cpumask_from_cache_id (unsigned long cache_id,u32 cache_level,cpumask_t *affinity);
Signature · 1 line
2.39.5
Ben Horgan
maintainerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
Hi James,
Quoted 182 lines · James Morse
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.CC Shanker Donthineni <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Added XCL support.
* Merged FLT/CTL constants.
* a spelling mistake in a comment.
* moved structrues around.--- drivers/resctrl/mpam_devices.c | 226 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ 2 files changed, 245 insertions(+)drivers/resctrl/mpam_devices.c +153
-0@@ -898,6 +898,232 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)return 0 ; } +struct mon_read { +struct mpam_msc_ris *ris; +struct mon_cfg *ctx; +enum mpam_device_features type; +u64 *val; +int err; +}; + +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mon_cfg *ctx = m->ctx; + +/* +* For CSU counters its implementation-defined what happens when not +* filtering by partid. +*/ + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; + + *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; + *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg); + } + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =MSMON_CFG_CSU_CTL_TYPE_CSU ; + +if (mpam_has_feature (mpam_feat_msmon_csu_xcl, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_CSU_FLT_XCL , + ctx->csu_exclude_clean); + +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =MSMON_CFG_MBWU_CTL_TYPE_MBWU ; + +if (mpam_has_feature (mpam_feat_msmon_mbwu_rwbw, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_MBWU_FLT_RWBW , ctx->opts); + +break ; +default : +return ; + } +} + +static void read_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =mpam_read_monsel_reg (msc,CFG_CSU_CTL ); + *flt_val =mpam_read_monsel_reg (msc,CFG_CSU_FLT ); +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); + *flt_val =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); +break ; +default : +return ; + } +} + +/* Remove values set by the hardware to prevent apparent mismatches. */ +static void clean_msmon_ctl_val (u32 *cur_ctl) +{ + *cur_ctl &= ~MSMON_CFG_x_CTL_OFLOW_STATUS; +} + +static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, +u32 flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +/* +* Write the ctl_val with the enable bit cleared, reset the counter, +* then enable counter. +*/ +switch (m->type) { +case mpam_feat_msmon_csu: +mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +mpam_write_monsel_reg (msc,CSU ,0 ); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +case mpam_feat_msmon_mbwu: +mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +default : +return ; + } +} + +/* Call with MSC lock held */ +static void __ris_msmon_read (void *arg) +{ +u64 now; +bool nrdy = false; +struct mon_read *m = arg; +struct mon_cfg *ctx = m->ctx; +struct mpam_msc_ris *ris = m->ris; +struct mpam_props *rprops = &ris->props; +struct mpam_msc *msc = m->ris->vmsc->msc; +u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt; + +if (!mpam_mon_sel_lock (msc)) { + m->err = -EIO ; +return ; + } + mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , ctx->mon) | +FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); +mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); + +/* +* Read the existing configuration to avoid re-writing the same values. +* This saves waiting for 'nrdy' on subsequent reads. +*/ +read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt); +clean_msmon_ctl_val (&cur_ctl); +gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); +if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) +write_msmon_ctl_flt_vals (m, ctl_val, flt_val); + +switch (m->type) { +case mpam_feat_msmon_csu: + now =mpam_read_monsel_reg (msc,CSU ); +if (mpam_has_feature (mpam_feat_msmon_csu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; +break ; +case mpam_feat_msmon_mbwu: + now =mpam_read_monsel_reg (msc,MBWU ); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; +break ; +default : + m->err = -EINVAL ; +break ; + } +mpam_mon_sel_unlock (msc); + +if (nrdy) { + m->err = -EBUSY ; +return ; + } + + now =FIELD_GET (MSMON___VALUE , now); + *m->val += now; +}
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1063
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ +static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ +int err, idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) {
This can be list_for_each_entry_srcu(). (I thought I'd already commented but turns out that was on another patch.)
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1066
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+ msc = vmsc->msc; + +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) {
Also here.
[...]
Thanks,
Ben
Ben Horgan
maintainerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
Hi James,
Quoted 49 lines · Ben Horgan
Hi James,
Quoted 46 lines · James Morse
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.CC Shanker Donthineni <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Added XCL support.
* Merged FLT/CTL constants.
* a spelling mistake in a comment.
* moved structrues around.--- drivers/resctrl/mpam_devices.c | 226 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ 2 files changed, 245 insertions(+)drivers/resctrl/mpam_devices.c +21
-0+ +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mon_cfg *ctx = m->ctx; + +/* +* For CSU counters its implementation-defined what happens when not +* filtering by partid. +*/ + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; + + *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; + *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg); + } + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =MSMON_CFG_CSU_CTL_TYPE_CSU ;
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 936
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+ +if (mpam_has_feature (mpam_feat_msmon_csu_xcl, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_CSU_FLT_XCL , + ctx->csu_exclude_clean); + +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =MSMON_CFG_MBWU_CTL_TYPE_MBWU ;
As you mentioned offline, this zeroes the other bits in *ctl_val.
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
Hi Ben,
Quoted 37 lines · Ben Horgan
Quoted 36 lines · Ben Horgan
Quoted 35 lines · James Morse
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.drivers/resctrl/mpam_devices.c +23
-0+ +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mon_cfg *ctx = m->ctx; + +/* +* For CSU counters its implementation-defined what happens when not +* filtering by partid. +*/ + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; + + *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; + *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg); + } + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =MSMON_CFG_CSU_CTL_TYPE_CSU ; + +if (mpam_has_feature (mpam_feat_msmon_csu_xcl, &m->ris->props))
Quoted 8 lines
Quoted 6 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 936
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ *flt_val |=FIELD_PREP (MSMON_CFG_CSU_FLT_XCL , + ctx->csu_exclude_clean); + +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =MSMON_CFG_MBWU_CTL_TYPE_MBWU ;As you mentioned offline, this zeroes the other bits in
*ctl_val.
Yes - a bug introduced during a late night, I've fixed this up.
Thanks,
James
James Morse
maintainerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
In reply to Ben HorganHi Ben,
Quoted 32 lines · Ben Horgan
Quoted 13 lines · James Morse
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.drivers/resctrl/mpam_devices.c +0
-0drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 907
Quoted 10 lines
drivers/resctrl/mpam_devices.c +9
-0@@ -898,6 +898,232 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) +static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ +int err, idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) {This can be
list_for_each_entry_srcu(). (I thought I'd already commented but turns out that was on another patch.)
Quoted 5 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1066
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+ msc = vmsc->msc; + +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) {Also here.
Yup - thanks I missed these. Fixed.
I bet I went cross-eyed between here and mpam_apply_config() as they are structurally similar.
Thanks,
James
Re: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
In reply to James MorseQuoted 10 lines · On Wed, 10 Sep 2025 20:43:03 +0000 James Morse <[email protected]> wrote:
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.CC Shanker Donthineni <[email protected]>Signed-off-by James Morse <[email protected]>
Hi James,
A couple of minor comments inline,
Jonathan
Quoted 12 lines
drivers/resctrl/mpam_devices.c +12
-0+static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, +u32 flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +/* +* Write the ctl_val with the enable bit cleared, reset the counter, +* then enable counter. +*/ +switch (m->type) { +case mpam_feat_msmon_csu: +mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val);
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 993
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +mpam_write_monsel_reg (msc,CSU ,0 ); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +case mpam_feat_msmon_mbwu: +mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ;
Given nothing to do later, I'd just return at end of each case. Entirely up to you though as this is just a personal style preference.
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+default : +return ; + } +}
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1062
Quoted 10 lines
drivers/resctrl/mpam_devices.c +9
-0+ +static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ +int err, idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + + idx =srcu_read_lock (&mpam_srcu);
guard(srcu)(&mpam_srcu);
Then you can do direct returns on errors which looks like it will simplify things somewhat by letting you just return on err.
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1064
Quoted 2 lines
drivers/resctrl/mpam_devices.c +2
-0+list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc;
I'd bring the declaration down here as well.
struct mpam_msc *msc = vmsc->msc;
Could bring ris down here as well.
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { + arg->ris = ris; +
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1078
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ err =smp_call_function_any (&msc->accessibility, + __ris_msmon_read, arg, + true); +if (!err && arg->err) + err = arg->err; +if (err) +break ; + } +if (err) +break ;
This won't be needed if you returned on error above.
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1082
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ } +srcu_read_unlock (&mpam_srcu, idx); + +return err;
And you only reach here with above changes if err == 0 so return 0; appropriate.
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+} + +int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx, +enum mpam_device_features type,u64 *val) +{ +int err; +struct mon_read arg; +u64 wait_jiffies =0 ; +struct mpam_props *cprops = &comp->class->props;
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1101
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ +might_sleep (); + +if (!mpam_is_enabled ()) +return -EIO ; + +if (!mpam_has_feature (type, cprops)) +return -EOPNOTSUPP ; + +memset (&arg,0 ,sizeof (arg));
Either use = { }; at declaration or maybe
arg = (struct mon_read) {
.ctx = ctx,
.type = type,
.val = val,
};rather than bothering with separate memset.
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ;
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1115
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ + err =_msmon_read (comp, &arg); +if (err == -EBUSY && comp->class->nrdy_usec) + wait_jiffies =usecs_to_jiffies (comp->class->nrdy_usec); + +while (wait_jiffies) + wait_jiffies =schedule_timeout_uninterruptible (wait_jiffies); + +if (err == -EBUSY ) { +memset (&arg,0 ,sizeof (arg));
Same as above.
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); + } + +return err; +}
James Morse
maintainerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
Hi Jonathan,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Wed, 10 Sep 2025 20:43:03 +0000 James Morse <[email protected]> wrote:
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.CC Shanker Donthineni <[email protected]>Signed-off-by James Morse <[email protected]>drivers/resctrl/mpam_devices.c +17
-0+static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, +u32 flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +/* +* Write the ctl_val with the enable bit cleared, reset the counter, +* then enable counter. +*/ +switch (m->type) { +case mpam_feat_msmon_csu: +mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +mpam_write_monsel_reg (msc,CSU ,0 ); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +case mpam_feat_msmon_mbwu:
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 993
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ;Given nothing to do later, I'd just return at end of each case. Entirely up to you though as this is just a personal style preference.
Out of habit I try to avoid functions returning from different places, as it makes it harder to add locking later. Maybe the fancy cleanup c++ thing changes that.
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ default: + return;
But I'm clearly inconsistent!
I've changes this as you suggest.
Quoted 42 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1062
Quoted 12 lines
drivers/resctrl/mpam_devices.c +11
-0+ } +} + +static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ +int err, idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + + idx =srcu_read_lock (&mpam_srcu);guard(srcu)(&mpam_srcu);Then you can do direct returns on errors which looks like it will simplify things somewhat by letting you just return on err.
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1064
Quoted 2 lines
drivers/resctrl/mpam_devices.c +2
-0+list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc;I'd bring the declaration down here as well.
struct mpam_msc *msc = vmsc->msc;Could bring ris down here as well.
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { + arg->ris = ris; +drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1078
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ err =smp_call_function_any (&msc->accessibility, + __ris_msmon_read, arg, + true); +if (!err && arg->err) + err = arg->err; +if (err) +break ; + } +if (err) +break ;This won't be needed if you returned on error above.
Quoted 6 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1082
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ } +srcu_read_unlock (&mpam_srcu, idx); + +return err;And you only reach here with above changes if err == 0 so return 0; appropriate.
I've done all of the above.
(I'd even already worked it out from your earlier feedback)
Quoted 21 lines
Quoted 9 lines
drivers/resctrl/mpam_devices.c +9
-0+} + +int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx, +enum mpam_device_features type,u64 *val) +{ +int err; +struct mon_read arg; +u64 wait_jiffies =0 ; +struct mpam_props *cprops = &comp->class->props;drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1101
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ +might_sleep (); + +if (!mpam_is_enabled ()) +return -EIO ; + +if (!mpam_has_feature (type, cprops)) +return -EOPNOTSUPP ; + +memset (&arg,0 ,sizeof (arg));Either use = { }; at declaration or maybe
Quoted 7 lines
arg = (struct mon_read) { .ctx = ctx, .type = type, .val = val, };rather than bothering with separate memset.
The memset is because arg gets re-used, but there are fields not touched here that get modified, like 'err'. But this struct assignment works too...
Quoted 8 lines
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+ arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); +if (err == -EBUSY && comp->class->nrdy_usec) + wait_jiffies =usecs_to_jiffies (comp->class->nrdy_usec);
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1115
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ +while (wait_jiffies) + wait_jiffies =schedule_timeout_uninterruptible (wait_jiffies); + +if (err == -EBUSY ) { +memset (&arg,0 ,sizeof (arg));Same as above.
Yup - its like this so that they look the same.
Quoted 11 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1125
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); + } + +return err; +}
Thanks,
James
Fenghua Yu
reviewerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
In reply to James MorseHi, James,
Quoted 176 lines · James Morse
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.CC Shanker Donthineni <[email protected]>Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Added XCL support.
* Merged FLT/CTL constants.
* a spelling mistake in a comment.
* moved structrues around.--- drivers/resctrl/mpam_devices.c | 226 ++++++++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 19 +++ 2 files changed, 245 insertions(+)drivers/resctrl/mpam_devices.c +147
-0@@ -898,6 +898,232 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)return 0 ; } +struct mon_read { +struct mpam_msc_ris *ris; +struct mon_cfg *ctx; +enum mpam_device_features type; +u64 *val; +int err; +}; + +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mon_cfg *ctx = m->ctx; + +/* +* For CSU counters its implementation-defined what happens when not +* filtering by partid. +*/ + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; + + *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { + *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; + *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg); + } + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =MSMON_CFG_CSU_CTL_TYPE_CSU ; + +if (mpam_has_feature (mpam_feat_msmon_csu_xcl, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_CSU_FLT_XCL , + ctx->csu_exclude_clean); + +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =MSMON_CFG_MBWU_CTL_TYPE_MBWU ; + +if (mpam_has_feature (mpam_feat_msmon_mbwu_rwbw, &m->ris->props)) + *flt_val |=FIELD_PREP (MSMON_CFG_MBWU_FLT_RWBW , ctx->opts); + +break ; +default : +return ; + } +} + +static void read_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val, +u32 *flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +switch (m->type) { +case mpam_feat_msmon_csu: + *ctl_val =mpam_read_monsel_reg (msc,CFG_CSU_CTL ); + *flt_val =mpam_read_monsel_reg (msc,CFG_CSU_FLT ); +break ; +case mpam_feat_msmon_mbwu: + *ctl_val =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); + *flt_val =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); +break ; +default : +return ; + } +} + +/* Remove values set by the hardware to prevent apparent mismatches. */ +static void clean_msmon_ctl_val (u32 *cur_ctl) +{ + *cur_ctl &= ~MSMON_CFG_x_CTL_OFLOW_STATUS; +} + +static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val, +u32 flt_val) +{ +struct mpam_msc *msc = m->ris->vmsc->msc; + +/* +* Write the ctl_val with the enable bit cleared, reset the counter, +* then enable counter. +*/ +switch (m->type) { +case mpam_feat_msmon_csu: +mpam_write_monsel_reg (msc,CFG_CSU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val); +mpam_write_monsel_reg (msc,CSU ,0 ); +mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +case mpam_feat_msmon_mbwu: +mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); +break ; +default : +return ; + } +} + +/* Call with MSC lock held */ +static void __ris_msmon_read (void *arg) +{ +u64 now; +bool nrdy = false; +struct mon_read *m = arg; +struct mon_cfg *ctx = m->ctx; +struct mpam_msc_ris *ris = m->ris; +struct mpam_props *rprops = &ris->props; +struct mpam_msc *msc = m->ris->vmsc->msc; +u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt; + +if (!mpam_mon_sel_lock (msc)) { + m->err = -EIO ; +return ; + } + mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , ctx->mon) | +FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); +mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); + +/* +* Read the existing configuration to avoid re-writing the same values. +* This saves waiting for 'nrdy' on subsequent reads. +*/ +read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt); +clean_msmon_ctl_val (&cur_ctl); +gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); +if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) +write_msmon_ctl_flt_vals (m, ctl_val, flt_val); + +switch (m->type) { +case mpam_feat_msmon_csu: + now =mpam_read_monsel_reg (msc,CSU ); +if (mpam_has_feature (mpam_feat_msmon_csu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; +break ; +case mpam_feat_msmon_mbwu: + now =mpam_read_monsel_reg (msc,MBWU ); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; +break ; +default : + m->err = -EINVAL ; +break ; + } +mpam_mon_sel_unlock (msc); + +if (nrdy) { + m->err = -EBUSY ;
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1057
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+return ; + } + + now =FIELD_GET (MSMON___VALUE , now); + *m->val += now; +} + +static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ +int err, idx;
Can err be initialized to some error code e.g. -ENODEV?
Quoted 12 lines
drivers/resctrl/mpam_devices.c +12
-0+struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc; + +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { + arg->ris = ris; + + err = smp_call_function_any(&msc->accessibility,
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1079
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+ __ris_msmon_read, arg, + true); +if (!err && arg->err) + err = arg->err; +if (err) +break ; + } +if (err) +break ; + }
comp->vmsc or vmsc->ris usually are not empty. But in some condition, they can be empty. In that case, uninitialized err value may cause unexpected behavior for the callers.
So it's better to initialize err to avoid any complexity.
Quoted 78 lines
drivers/resctrl/mpam_devices.c +47
-0+srcu_read_unlock (&mpam_srcu, idx); + +return err; +} + +int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx, +enum mpam_device_features type,u64 *val) +{ +int err; +struct mon_read arg; +u64 wait_jiffies =0 ; +struct mpam_props *cprops = &comp->class->props; + +might_sleep (); + +if (!mpam_is_enabled ()) +return -EIO ; + +if (!mpam_has_feature (type, cprops)) +return -EOPNOTSUPP ; + +memset (&arg,0 ,sizeof (arg)); + arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); +if (err == -EBUSY && comp->class->nrdy_usec) + wait_jiffies =usecs_to_jiffies (comp->class->nrdy_usec); + +while (wait_jiffies) + wait_jiffies =schedule_timeout_uninterruptible (wait_jiffies); + +if (err == -EBUSY ) { +memset (&arg,0 ,sizeof (arg)); + arg.ctx = ctx; + arg.type = type; + arg.val = val; + *val =0 ; + + err =_msmon_read (comp, &arg); + } + +return err; +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;drivers/resctrl/mpam_internal.h +16
-0@@ -196,6 +196,22 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, *supported &= ~(1 << feat); } +/* The values for MSMON_CFG_MBWU_FLT.RWBW */ +enum mon_filter_options { +COUNT_BOTH =0 , +COUNT_WRITE =1 , +COUNT_READ =2 , +}; + +struct mon_cfg { +u16 mon; +u8 pmg; +bool match_pmg; +bool csu_exclude_clean; +u32 partid; +enum mon_filter_options opts; +}; +struct mpam_class {/* mpam_components in this class */ struct list_head components;
drivers/resctrl/mpam_internal.h void mpam_disable(struct work_struct *work); · line 367
Quoted 9 lines
drivers/resctrl/mpam_internal.h +3
-0@@ -343,6 +359,9 @@ void mpam_disable(struct work_struct *work);int mpam_apply_config (struct mpam_component *comp,u16 partid,struct mpam_config *cfg); +int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx, +enum mpam_device_features ,u64 *val); +int mpam_get_cpumask_from_cache_id (unsigned long cache_id,u32 cache_level,cpumask_t *affinity);
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value
Hi Fenghua,
Quoted 15 lines · Fenghua Yu
Quoted 13 lines · James Morse
Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware.
Add
mpam_msmon_read()to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again.drivers/resctrl/mpam_devices.c +0
-0@@ -898,6 +898,232 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)
Quoted 5 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1057
Quoted 3 lines
drivers/resctrl/mpam_devices.c +3
-0+static int _msmon_read (struct mpam_component *comp,struct mon_read *arg) +{ + int err, idx;Can err be initialized to some error code e.g.
-ENODEV?
Feedback from Jonathan has led to numerous changes here.
Quoted 16 lines
Quoted 16 lines
drivers/resctrl/mpam_devices.c +16
-0+ struct mpam_msc *msc; + struct mpam_vmsc *vmsc; + struct mpam_msc_ris *ris; + + idx = srcu_read_lock(&mpam_srcu); + list_for_each_entry_rcu(vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc; + + list_for_each_entry_rcu(ris, &vmsc->ris, vmsc_list) { + arg->ris = ris; + + err = smp_call_function_any(&msc->accessibility, + __ris_msmon_read, arg, + true); + if (!err && arg->err) + err = arg->err;
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1079
Quoted 6 lines
drivers/resctrl/mpam_devices.c +6
-0+ if (err) + break; + } + if (err) + break; + }
comp->vmscorvmsc->risusually are not empty. But in some condition, they can be empty.
Really? There is no call to create a VMSC - only to create a RIS with a set of ids. If you provide an ID for a VMSC that doesn't exist yet - it gets created for the RIS to be added to.
There was some defensive programming earlier, (and a comment that said it wasn't possible). That was some left over debug.
Quoted 3 lines
In that case, uninitialized err value may cause unexpected behavior for the callers.
So it's better to initialize err to avoid any complexity.
Not complexity - the risk is returning an uninitialised value.
After Jonathan's feedback, and my guess at to what Zheng is seeing, it looks like this:
----------%<----------
static int _msmon_read(struct mpam_component *comp, struct mon_read *arg)
{
int err, any_err = 0;
struct mpam_vmsc *vmsc;
guard(srcu)(&mpam_srcu);
list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list,
srcu_read_lock_held(&mpam_srcu)) {
struct mpam_msc *msc = vmsc->msc;
struct mpam_msc_ris *ris;
list_for_each_entry_srcu(ris, &vmsc->ris, vmsc_list,
srcu_read_lock_held(&mpam_srcu)) {
arg->ris = ris;
err = smp_call_function_any(&msc->accessibility,
__ris_msmon_read, arg,
true);
if (!err && arg->err)
err = arg->err;
/*
* Save one error to be returned to the caller, but
* keep reading counters so that get reprogrammed. On
* platforms with NRDY this lets us wait once.
*/
if (err)
any_err = err;
}
}
return any_err;
}----------%<----------
Quoted 4 lines
drivers/resctrl/mpam_devices.c static int mpam_msc_hw_probe(struct mpam_msc *msc) · line 1083
Quoted 4 lines
drivers/resctrl/mpam_devices.c +4
-0+ srcu_read_unlock(&mpam_srcu, idx); + + return err; +}
Thanks,
James
James Morse
maintainerPATCH v2 24/29 arm_mpam: Track bandwidth counter state for overflow and power management
In reply to James MorseBandwidth counters need to run continuously to correctly reflect the bandwidth.
The value read may be lower than the previous value read in the case of overflow and when the hardware is reset due to CPU hotplug.
Add struct mbwu_state to track the bandwidth counter to allow overflow and power management to be handled.
---
Changes since v1:
* Fixed lock/unlock typo.
--- drivers/resctrl/mpam_devices.c | 154 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 23 +++++ 2 files changed, 175 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +152 -2
@@ -918,6 +918,7 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg);
@@ -972,6 +973,7 @@ static void clean_msmon_ctl_val(u32 *cur_ctl)static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val,u32 flt_val) { +struct msmon_mbwu_state *mbwu_state;struct mpam_msc *msc = m->ris->vmsc->msc;/*
@@ -990,20 +992,32 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val);mpam_write_monsel_reg (msc,MBWU ,0 );mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); + + mbwu_state = &m->ris->mbwu_state[m->ctx->mon]; +if (mbwu_state) + mbwu_state->prev_val =0 ; +break ;default :return ; } } +static u64 mpam_msmon_overflow_val (struct mpam_msc_ris *ris) +{ +/* TODO: scaling, and long counters */ +return GENMASK_ULL (30 ,0 ); +} +/* Call with MSC lock held */ static void __ris_msmon_read (void *arg) { -u64 now;bool nrdy = false;struct mon_read *m = arg; +u64 now, overflow_val =0 ;struct mon_cfg *ctx = m->ctx;struct mpam_msc_ris *ris = m->ris; +struct msmon_mbwu_state *mbwu_state;struct mpam_props *rprops = &ris->props;struct mpam_msc *msc = m->ris->vmsc->msc;u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt;
@@ -1031,11 +1045,30 @@ static void __ris_msmon_read(void *arg) now =mpam_read_monsel_reg (msc,CSU );if (mpam_has_feature (mpam_feat_msmon_csu_hw_nrdy, rprops)) nrdy = now &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now);break ;case mpam_feat_msmon_mbwu: now =mpam_read_monsel_reg (msc,MBWU );if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) nrdy = now &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now); + +if (nrdy) +break ; + + mbwu_state = &ris->mbwu_state[ctx->mon]; +if (!mbwu_state) +break ; + +/* Add any pre-overflow value to the mbwu_state->val */ +if (mbwu_state->prev_val > now) + overflow_val =mpam_msmon_overflow_val (ris) - mbwu_state->prev_val; + + mbwu_state->prev_val = now; + mbwu_state->correction += overflow_val; + +/* Include bandwidth consumed before the last hardware reset */ + now += mbwu_state->correction;break ;default : m->err = -EINVAL ;
@@ -1048,7 +1081,6 @@ static void __ris_msmon_read(void *arg)return ; } - now =FIELD_GET (MSMON___VALUE , now); *m->val += now; }
@@ -1261,6 +1293,67 @@ static int mpam_reprogram_ris(void *_arg)return 0 ; } +/* Call with MSC lock held */ +static int mpam_restore_mbwu_state (void *_ris) +{ +int i; +struct mon_read mwbu_arg; +struct mpam_msc_ris *ris = _ris; + +for (i =0 ; i < ris->props.num_mbwu_mon; i++) { +if (ris->mbwu_state[i].enabled) { + mwbu_arg.ris = ris; + mwbu_arg.ctx = &ris->mbwu_state[i].cfg; + mwbu_arg.type = mpam_feat_msmon_mbwu; + +__ris_msmon_read (&mwbu_arg); + } + } + +return 0 ; +} + +/* Call with MSC lock and held */ +static int mpam_save_mbwu_state (void *arg) +{ +int i; +u64 val; +struct mon_cfg *cfg; +u32 cur_flt, cur_ctl, mon_sel; +struct mpam_msc_ris *ris = arg; +struct msmon_mbwu_state *mbwu_state; +struct mpam_msc *msc = ris->vmsc->msc; + +for (i =0 ; i < ris->props.num_mbwu_mon; i++) { + mbwu_state = &ris->mbwu_state[i]; + cfg = &mbwu_state->cfg; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +return -EIO ; + + mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , i) | +FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); +mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); + + cur_flt =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); + cur_ctl =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 ); + + val =mpam_read_monsel_reg (msc,MBWU ); +mpam_write_monsel_reg (msc,MBWU ,0 ); + + cfg->mon = i; + cfg->pmg =FIELD_GET (MSMON_CFG_x_FLT_PMG, cur_flt); + cfg->match_pmg =FIELD_GET (MSMON_CFG_x_CTL_MATCH_PMG, cur_ctl); + cfg->partid =FIELD_GET (MSMON_CFG_x_FLT_PARTID, cur_flt); + mbwu_state->correction += val; + mbwu_state->enabled =FIELD_GET (MSMON_CFG_x_CTL_EN, cur_ctl); +mpam_mon_sel_unlock (msc); + } + +return 0 ; +} +static void mpam_init_reset_cfg (struct mpam_config *reset_cfg) {memset (reset_cfg,0 ,sizeof (*reset_cfg));
@@ -1335,6 +1428,9 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online)* for non-zero partid may be lost while the CPUs are offline. */ ris->in_reset_state = online; + +if (mpam_is_enabled () && !online) +mpam_touch_msc (msc, &mpam_save_mbwu_state, ris); } }
@@ -1369,6 +1465,9 @@ static void mpam_reprogram_msc(struct mpam_msc *msc)mpam_reprogram_ris_partid (ris, partid, cfg); } ris->in_reset_state = reset; + +if (mpam_has_feature (mpam_feat_msmon_mbwu, &ris->props)) +mpam_touch_msc (msc, &mpam_restore_mbwu_state, ris); } }
@@ -2091,11 +2190,33 @@ static void mpam_unregister_irqs(void)static void __destroy_component_cfg (struct mpam_component *comp) { +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +lockdep_assert_held (&mpam_list_lock); +add_to_garbage (comp->cfg); +list_for_each_entry (vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc; + +if (mpam_mon_sel_lock (msc)) { +list_for_each_entry (ris, &vmsc->ris, vmsc_list) +add_to_garbage (ris->mbwu_state); +mpam_mon_sel_unlock (msc); + } + } }static int __allocate_component_cfg (struct mpam_component *comp) { +int err =0 ; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; +struct msmon_mbwu_state *mbwu_state; + +lockdep_assert_held (&mpam_list_lock);mpam_assert_partid_sizes_fixed ();if (comp->cfg)
@@ -2106,6 +2227,35 @@ static int __allocate_component_cfg(struct mpam_component *comp)return -ENOMEM ;init_garbage (comp->cfg); +list_for_each_entry (vmsc, &comp->vmsc, comp_list) { +if (!vmsc->props.num_mbwu_mon) +continue ; + + msc = vmsc->msc; +list_for_each_entry (ris, &vmsc->ris, vmsc_list) { +if (!ris->props.num_mbwu_mon) +continue ; + + mbwu_state =kcalloc (ris->props.num_mbwu_mon, +sizeof (*ris->mbwu_state), +GFP_KERNEL ); +if (!mbwu_state) { +__destroy_component_cfg (comp); + err = -ENOMEM ; +break ; + } + +if (mpam_mon_sel_lock (msc)) { +init_garbage (mbwu_state); + ris->mbwu_state = mbwu_state; +mpam_mon_sel_unlock (msc); + } + } + +if (err) +break ; + } +return 0 ; }
drivers/resctrl/mpam_internal.h +23 -0
@@ -212,6 +212,26 @@ struct mon_cfg {enum mon_filter_options opts; }; +/* +* Changes to enabled and cfg are protected by the msc->lock. +* Changes to prev_val and correction are protected by the msc's mon_sel_lock. +*/ +struct msmon_mbwu_state { +bool enabled; +struct mon_cfg cfg; + +/* The value last read from the hardware. Used to detect overflow. */ +u64 prev_val; + +/* +* The value to add to the new reading to account for power management, +* and shifts to trigger the overflow interrupt. +*/ +u64 correction; + +struct mpam_garbage garbage; +}; +struct mpam_class {/* mpam_components in this class */ struct list_head components;
@@ -304,6 +324,9 @@ struct mpam_msc_ris {/* parent: */ struct mpam_vmsc *vmsc; +/* msmon mbwu configuration is preserved over reset */ +struct msmon_mbwu_state *mbwu_state; +struct mpam_garbage garbage; };
Signature · 1 line
2.39.5
Re: [PATCH v2 24/29] arm_mpam: Track bandwidth counter state for overflow and power management
Quoted 10 lines · On Wed, 10 Sep 2025 20:43:04 +0000 James Morse <[email protected]> wrote:
Bandwidth counters need to run continuously to correctly reflect the bandwidth.
The value read may be lower than the previous value read in the case of overflow and when the hardware is reset due to CPU hotplug.
Add struct
mbwu_stateto track the bandwidth counter to allow overflow and power management to be handled.Signed-off-by James Morse <[email protected]>
Trivial comment inline. I haven't spent enough time thinking about this to give a proper review so no tags yet.
Jonathan
Quoted 13 lines
---
Changes since v1:
* Fixed lock/unlock typo.--- drivers/resctrl/mpam_devices.c | 154 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 23 +++++ 2 files changed, 175 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +0
-0
drivers/resctrl/mpam_devices.c static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, · line 921
Quoted 4 lines
drivers/resctrl/mpam_devices.c +1
-0@@ -918,6 +918,7 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +
Unrelated change. If it makes sense figure out where to push it back to.
Quoted 3 lines
drivers/resctrl/mpam_devices.c +0
-0if (m->ctx->match_pmg) { *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg);
James Morse
maintainerRe: [PATCH v2 24/29] arm_mpam: Track bandwidth counter state for overflow and power management
Hi Jonathan,
Quoted 24 lines · Jonathan Cameron
Quoted 10 lines · On Wed, 10 Sep 2025 20:43:04 +0000 James Morse <[email protected]> wrote:
Bandwidth counters need to run continuously to correctly reflect the bandwidth.
The value read may be lower than the previous value read in the case of overflow and when the hardware is reset due to CPU hotplug.
Add struct
mbwu_stateto track the bandwidth counter to allow overflow and power management to be handled.Signed-off-by James Morse <[email protected]>Trivial comment inline. I haven't spent enough time thinking about this to give a proper review so no tags yet.
Quoted 7 lines
drivers/resctrl/mpam_devices.c +0
-0@@ -918,6 +918,7 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID;
Quoted 4 lines
drivers/resctrl/mpam_devices.c static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, · line 921
Quoted 2 lines
drivers/resctrl/mpam_devices.c +1
-0*flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +Unrelated change. If it makes sense figure out where to push it back to.
Done. This is may favourite mistake to make with a merge conflict!
Thanks,
James
Quoted 4 lines
Quoted 3 lines
drivers/resctrl/mpam_devices.c +0
-0if (m->ctx->match_pmg) { *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg);
Ben Horgan
maintainerRe: [PATCH v2 24/29] arm_mpam: Track bandwidth counter state for overflow and power management
In reply to James MorseHi James,
Quoted 39 lines · James Morse
Bandwidth counters need to run continuously to correctly reflect the bandwidth.
The value read may be lower than the previous value read in the case of overflow and when the hardware is reset due to CPU hotplug.
Add struct
mbwu_stateto track the bandwidth counter to allow overflow and power management to be handled.Signed-off-by James Morse <[email protected]>---
Changes since v1:
* Fixed lock/unlock typo.--- drivers/resctrl/mpam_devices.c | 154 +++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 23 +++++ 2 files changed, 175 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +2
-0@@ -918,6 +918,7 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, *ctl_val |= MSMON_CFG_x_CTL_MATCH_PARTID; *flt_val =FIELD_PREP (MSMON_CFG_x_FLT_PARTID, ctx->partid); +if (m->ctx->match_pmg) { *ctl_val |= MSMON_CFG_x_CTL_MATCH_PMG; *flt_val |=FIELD_PREP (MSMON_CFG_x_FLT_PMG, ctx->pmg);@@ -972,6 +973,7 @@ static void clean_msmon_ctl_val(u32 *cur_ctl)static void write_msmon_ctl_flt_vals (struct mon_read *m,u32 ctl_val,u32 flt_val) { +struct msmon_mbwu_state *mbwu_state;struct mpam_msc *msc = m->ris->vmsc->msc;/*
drivers/resctrl/mpam_devices.c static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val, · line 998
Quoted 7 lines
drivers/resctrl/mpam_devices.c +4
-0@@ -990,20 +992,32 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val);mpam_write_monsel_reg (msc,MBWU ,0 );mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); + + mbwu_state = &m->ris->mbwu_state[m->ctx->mon]; +if (mbwu_state) + mbwu_state->prev_val =0 ;
What's the if condition doing here?
The below could make more sense but I don't think you can get here if the allocation fails.
if (m->ris->mbwu_state)
Quoted 204 lines
drivers/resctrl/mpam_devices.c +130
-2+break ;default :return ; } } +static u64 mpam_msmon_overflow_val (struct mpam_msc_ris *ris) +{ +/* TODO: scaling, and long counters */ +return GENMASK_ULL (30 ,0 ); +} +/* Call with MSC lock held */ static void __ris_msmon_read (void *arg) { -u64 now;bool nrdy = false;struct mon_read *m = arg; +u64 now, overflow_val =0 ;struct mon_cfg *ctx = m->ctx;struct mpam_msc_ris *ris = m->ris; +struct msmon_mbwu_state *mbwu_state;struct mpam_props *rprops = &ris->props;struct mpam_msc *msc = m->ris->vmsc->msc;u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt;@@ -1031,11 +1045,30 @@ static void __ris_msmon_read(void *arg) now =mpam_read_monsel_reg (msc,CSU );if (mpam_has_feature (mpam_feat_msmon_csu_hw_nrdy, rprops)) nrdy = now &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now);break ;case mpam_feat_msmon_mbwu: now =mpam_read_monsel_reg (msc,MBWU );if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) nrdy = now &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now); + +if (nrdy) +break ; + + mbwu_state = &ris->mbwu_state[ctx->mon]; +if (!mbwu_state) +break ; + +/* Add any pre-overflow value to the mbwu_state->val */ +if (mbwu_state->prev_val > now) + overflow_val =mpam_msmon_overflow_val (ris) - mbwu_state->prev_val; + + mbwu_state->prev_val = now; + mbwu_state->correction += overflow_val; + +/* Include bandwidth consumed before the last hardware reset */ + now += mbwu_state->correction;break ;default : m->err = -EINVAL ;@@ -1048,7 +1081,6 @@ static void __ris_msmon_read(void *arg)return ; } - now =FIELD_GET (MSMON___VALUE , now); *m->val += now; }@@ -1261,6 +1293,67 @@ static int mpam_reprogram_ris(void *_arg)return 0 ; } +/* Call with MSC lock held */ +static int mpam_restore_mbwu_state (void *_ris) +{ +int i; +struct mon_read mwbu_arg; +struct mpam_msc_ris *ris = _ris; + +for (i =0 ; i < ris->props.num_mbwu_mon; i++) { +if (ris->mbwu_state[i].enabled) { + mwbu_arg.ris = ris; + mwbu_arg.ctx = &ris->mbwu_state[i].cfg; + mwbu_arg.type = mpam_feat_msmon_mbwu; + +__ris_msmon_read (&mwbu_arg); + } + } + +return 0 ; +} + +/* Call with MSC lock and held */ +static int mpam_save_mbwu_state (void *arg) +{ +int i; +u64 val; +struct mon_cfg *cfg; +u32 cur_flt, cur_ctl, mon_sel; +struct mpam_msc_ris *ris = arg; +struct msmon_mbwu_state *mbwu_state; +struct mpam_msc *msc = ris->vmsc->msc; + +for (i =0 ; i < ris->props.num_mbwu_mon; i++) { + mbwu_state = &ris->mbwu_state[i]; + cfg = &mbwu_state->cfg; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +return -EIO ; + + mon_sel =FIELD_PREP (MSMON_CFG_MON_SEL_MON_SEL , i) | +FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx); +mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); + + cur_flt =mpam_read_monsel_reg (msc,CFG_MBWU_FLT ); + cur_ctl =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 ); + + val =mpam_read_monsel_reg (msc,MBWU ); +mpam_write_monsel_reg (msc,MBWU ,0 ); + + cfg->mon = i; + cfg->pmg =FIELD_GET (MSMON_CFG_x_FLT_PMG, cur_flt); + cfg->match_pmg =FIELD_GET (MSMON_CFG_x_CTL_MATCH_PMG, cur_ctl); + cfg->partid =FIELD_GET (MSMON_CFG_x_FLT_PARTID, cur_flt); + mbwu_state->correction += val; + mbwu_state->enabled =FIELD_GET (MSMON_CFG_x_CTL_EN, cur_ctl); +mpam_mon_sel_unlock (msc); + } + +return 0 ; +} +static void mpam_init_reset_cfg (struct mpam_config *reset_cfg) {memset (reset_cfg,0 ,sizeof (*reset_cfg));@@ -1335,6 +1428,9 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online)* for non-zero partid may be lost while the CPUs are offline. */ ris->in_reset_state = online; + +if (mpam_is_enabled () && !online) +mpam_touch_msc (msc, &mpam_save_mbwu_state, ris); } }@@ -1369,6 +1465,9 @@ static void mpam_reprogram_msc(struct mpam_msc *msc)mpam_reprogram_ris_partid (ris, partid, cfg); } ris->in_reset_state = reset; + +if (mpam_has_feature (mpam_feat_msmon_mbwu, &ris->props)) +mpam_touch_msc (msc, &mpam_restore_mbwu_state, ris); } }@@ -2091,11 +2190,33 @@ static void mpam_unregister_irqs(void)static void __destroy_component_cfg (struct mpam_component *comp) { +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +lockdep_assert_held (&mpam_list_lock); +add_to_garbage (comp->cfg); +list_for_each_entry (vmsc, &comp->vmsc, comp_list) { + msc = vmsc->msc; + +if (mpam_mon_sel_lock (msc)) { +list_for_each_entry (ris, &vmsc->ris, vmsc_list) +add_to_garbage (ris->mbwu_state); +mpam_mon_sel_unlock (msc); + } + } }static int __allocate_component_cfg (struct mpam_component *comp) { +int err =0 ; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; +struct msmon_mbwu_state *mbwu_state; + +lockdep_assert_held (&mpam_list_lock);mpam_assert_partid_sizes_fixed ();if (comp->cfg)@@ -2106,6 +2227,35 @@ static int __allocate_component_cfg(struct mpam_component *comp)return -ENOMEM ;init_garbage (comp->cfg); +list_for_each_entry (vmsc, &comp->vmsc, comp_list) { +if (!vmsc->props.num_mbwu_mon) +continue ; + + msc = vmsc->msc; +list_for_each_entry (ris, &vmsc->ris, vmsc_list) { +if (!ris->props.num_mbwu_mon) +continue ; + + mbwu_state =kcalloc (ris->props.num_mbwu_mon, +sizeof (*ris->mbwu_state), +GFP_KERNEL ); +if (!mbwu_state) {
drivers/resctrl/mpam_devices.c static int __allocate_component_cfg(struct mpam_component *comp) · line 2252
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+__destroy_component_cfg (comp); + err = -ENOMEM ; +break ; + } + +if (mpam_mon_sel_lock (msc)) { +init_garbage (mbwu_state); + ris->mbwu_state = mbwu_state; +mpam_mon_sel_unlock (msc); + }
The if statement is confusing now that mpam_mon_sel_lock() unconditionally returns true.
Quoted 41 lines
drivers/resctrl/mpam_devices.c +6
-0+ } + +if (err) +break ; + } +return 0 ; }drivers/resctrl/mpam_internal.h +20
-0@@ -212,6 +212,26 @@ struct mon_cfg {enum mon_filter_options opts; }; +/* +* Changes to enabled and cfg are protected by the msc->lock. +* Changes to prev_val and correction are protected by the msc's mon_sel_lock. +*/ +struct msmon_mbwu_state { +bool enabled; +struct mon_cfg cfg; + +/* The value last read from the hardware. Used to detect overflow. */ +u64 prev_val; + +/* +* The value to add to the new reading to account for power management, +* and shifts to trigger the overflow interrupt. +*/ +u64 correction; + +struct mpam_garbage garbage; +}; +struct mpam_class {/* mpam_components in this class */ struct list_head components;
drivers/resctrl/mpam_internal.h struct mpam_msc_ris { · line 332
Quoted 9 lines
drivers/resctrl/mpam_internal.h +3
-0@@ -304,6 +324,9 @@ struct mpam_msc_ris {/* parent: */ struct mpam_vmsc *vmsc; +/* msmon mbwu configuration is preserved over reset */ +struct msmon_mbwu_state *mbwu_state; +struct mpam_garbage garbage; };
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 24/29] arm_mpam: Track bandwidth counter state for overflow and power management
Hi Ben,
Quoted 10 lines · Ben Horgan
Quoted 8 lines · James Morse
Bandwidth counters need to run continuously to correctly reflect the bandwidth.
The value read may be lower than the previous value read in the case of overflow and when the hardware is reset due to CPU hotplug.
Add struct
mbwu_stateto track the bandwidth counter to allow overflow and power management to be handled.
Quoted 14 lines
drivers/resctrl/mpam_devices.c static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val, · line 998
Quoted 12 lines
drivers/resctrl/mpam_devices.c +4
-0@@ -990,20 +992,32 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val);mpam_write_monsel_reg (msc,MBWU ,0 );mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); + + mbwu_state = &m->ris->mbwu_state[m->ctx->mon]; +if (mbwu_state) + mbwu_state->prev_val =0 ;What's the if condition doing here?
Yes, that looks like cruft....
It took the address of an array element - how could it be null?!
Quoted 2 lines
The below could make more sense but I don't think you can get here if the allocation fails.
Heh ... only because __allocate_component_cfg() has lost the error value. Without the outer/inner locking stuff, its feasible for __allocate_component_cfg() to return the error value directly.
With that fixed, and ignoring a bogus ctx->mon value - I agree you can't get a case where this needs checking.
I think this was originally testing if the array had been allocated, and its been folded wrongly at some point in the past. I assume I kept those bogus tests around as I saw it blow up with nonsense num_mbwu_mon - which is something I'll retest.
Quoted 29 lines
Quoted 29 lines
drivers/resctrl/mpam_devices.c +19
-0+break ;default :return ; } }@@ -2106,6 +2227,35 @@ static int __allocate_component_cfg(struct mpam_component *comp)return -ENOMEM ;init_garbage (comp->cfg); +list_for_each_entry (vmsc, &comp->vmsc, comp_list) { +if (!vmsc->props.num_mbwu_mon) +continue ; + + msc = vmsc->msc; +list_for_each_entry (ris, &vmsc->ris, vmsc_list) { +if (!ris->props.num_mbwu_mon) +continue ; + + mbwu_state =kcalloc (ris->props.num_mbwu_mon, +sizeof (*ris->mbwu_state), +GFP_KERNEL ); +if (!mbwu_state) { +__destroy_component_cfg (comp); + err = -ENOMEM ; +break ; + } +
Quoted 8 lines
drivers/resctrl/mpam_devices.c static int __allocate_component_cfg(struct mpam_component *comp) · line 2252
Quoted 5 lines
drivers/resctrl/mpam_devices.c +5
-0+if (mpam_mon_sel_lock (msc)) { +init_garbage (mbwu_state); + ris->mbwu_state = mbwu_state; +mpam_mon_sel_unlock (msc); + }The if statement is confusing now that
mpam_mon_sel_lock()unconditionally returns true.
Sure, but this and the __must_check means all the paths that use this must be able to return an error.
This is a churn-or-not trade-off for the inclusion of the firmware-backed support. I'd prefer it to be hard to add code-paths that are going to create a lot of work when that comes - especially as folk are promising platforms that need this in the coming months.
Thanks,
James
James Morse
maintainerPATCH v2 25/29 arm_mpam: Probe for long/lwd mbwu counters
In reply to James MorseFrom: Rohit Mathew <[email protected]>
mpam v0.1 and versions above v1.0 support optional long counter for memory bandwidth monitoring. The MPAMF_MBWUMON_IDR register have fields indicating support for long counters. As of now, a 44 bit counter represented by HAS_LONG field (bit 30) and a 63 bit counter represented by LWD (bit 29) can be optionally integrated. Probe for these counters and set corresponding feature bits if any of these counters are present.
--- drivers/resctrl/mpam_devices.c | 23 ++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 9 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_devices.c +22 -1
@@ -795,7 +795,7 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)dev_err_once (dev,"Counters are not usable because not-ready timeout was not provided by firmware." ); }if (FIELD_GET (MPAMF_MSMON_IDR_MSMON_MBWU , msmon_features)) { -bool hw_managed; +bool has_long, hw_managed;u32 mbwumon_idr =mpam_read_partsel_reg (msc,MBWUMON_IDR ); props->num_mbwu_mon =FIELD_GET (MPAMF_MBWUMON_IDR_NUM_MON , mbwumon_idr);
@@ -805,6 +805,27 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_MBWUMON_IDR_HAS_RWBW , mbwumon_idr))mpam_set_feature (mpam_feat_msmon_mbwu_rwbw, props); +/* +* Treat long counter and its extension, lwd as mutually +* exclusive feature bits. Though these are dependent +* fields at the implementation level, there would never +* be a need for mpam_feat_msmon_mbwu_44counter (long +* counter) and mpam_feat_msmon_mbwu_63counter (lwd) +* bits to be set together. +* +* mpam_feat_msmon_mbwu isn't treated as an exclusive +* bit as this feature bit would be used as the "front +* facing feature bit" for any checks related to mbwu +* monitors. +*/ + has_long =FIELD_GET (MPAMF_MBWUMON_IDR_HAS_LONG , mbwumon_idr); +if (props->num_mbwu_mon && has_long) { +if (FIELD_GET (MPAMF_MBWUMON_IDR_LWD , mbwumon_idr)) +mpam_set_feature (mpam_feat_msmon_mbwu_63counter, props); +else +mpam_set_feature (mpam_feat_msmon_mbwu_44counter, props); + } +/* Is NRDY hardware managed? */ hw_managed =mpam_ris_hw_probe_hw_nrdy (ris,MBWU );if (hw_managed)
drivers/resctrl/mpam_internal.h +9 -0
@@ -158,7 +158,16 @@ enum mpam_device_features { mpam_feat_msmon_csu_capture, mpam_feat_msmon_csu_xcl, mpam_feat_msmon_csu_hw_nrdy, + +/* +* Having mpam_feat_msmon_mbwu set doesn't mean the regular 31 bit MBWU +* counter would be used. The exact counter used is decided based on the +* status of mpam_feat_msmon_mbwu_44counter/mpam_feat_msmon_mbwu_63counter +* as well. +*/ mpam_feat_msmon_mbwu, + mpam_feat_msmon_mbwu_44counter, + mpam_feat_msmon_mbwu_63counter, mpam_feat_msmon_mbwu_capture, mpam_feat_msmon_mbwu_rwbw, mpam_feat_msmon_mbwu_hw_nrdy,
Signature · 1 line
2.39.5
Re: [PATCH v2 25/29] arm_mpam: Probe for long/lwd mbwu counters
Quoted 9 lines · On Wed, 10 Sep 2025 20:43:05 +0000 James Morse <[email protected]> wrote:
From: Rohit Mathew <[email protected]>
mpam v0.1 and versions above v1.0 support optional long counter for memory bandwidth monitoring. The
MPAMF_MBWUMON_IDRregister have fields indicating support for long counters. As of now, a 44 bit counter represented byHAS_LONGfield (bit 30) and a 63 bit counter represented by LWD (bit 29) can be optionally integrated. Probe for these counters and set corresponding feature bits if any of these counters are present.
Quoted 3 lines
Signed-off-by Rohit Mathew <[email protected]>Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
Hi Rohit, James.
I'd like a little more justification of the 'front facing' use for the first feature bit. To me that seems confusing but I may well be missing why we can't have 3 exclusive features.
Jonathan
Quoted 24 lines
--- drivers/resctrl/mpam_devices.c | 23 ++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 9 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-)drivers/resctrl/mpam_devices.c +3
-1@@ -795,7 +795,7 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)dev_err_once (dev,"Counters are not usable because not-ready timeout was not provided by firmware." ); }if (FIELD_GET (MPAMF_MSMON_IDR_MSMON_MBWU , msmon_features)) { -bool hw_managed; +bool has_long, hw_managed;u32 mbwumon_idr =mpam_read_partsel_reg (msc,MBWUMON_IDR ); props->num_mbwu_mon =FIELD_GET (MPAMF_MBWUMON_IDR_NUM_MON , mbwumon_idr);@@ -805,6 +805,27 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_MBWUMON_IDR_HAS_RWBW , mbwumon_idr))mpam_set_feature (mpam_feat_msmon_mbwu_rwbw, props); +/* +* Treat long counter and its extension, lwd as mutually
drivers/resctrl/mpam_devices.c static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) · line 819
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+* exclusive feature bits. Though these are dependent +* fields at the implementation level, there would never +* be a need for mpam_feat_msmon_mbwu_44counter (long +* counter) and mpam_feat_msmon_mbwu_63counter (lwd) +* bits to be set together. +* +* mpam_feat_msmon_mbwu isn't treated as an exclusive +* bit as this feature bit would be used as the "front +* facing feature bit" for any checks related to mbwu +* monitors.
Why do we need such a 'front facing' bit? Why isn't it sufficient just to add a little helper or macro to find out if mbwu is turned on?
Quoted 33 lines
drivers/resctrl/mpam_devices.c +9
-0+*/ + has_long =FIELD_GET (MPAMF_MBWUMON_IDR_HAS_LONG , mbwumon_idr); +if (props->num_mbwu_mon && has_long) { +if (FIELD_GET (MPAMF_MBWUMON_IDR_LWD , mbwumon_idr)) +mpam_set_feature (mpam_feat_msmon_mbwu_63counter, props); +else +mpam_set_feature (mpam_feat_msmon_mbwu_44counter, props); + } +/* Is NRDY hardware managed? */ hw_managed =mpam_ris_hw_probe_hw_nrdy (ris,MBWU );if (hw_managed)drivers/resctrl/mpam_internal.h +9
-0@@ -158,7 +158,16 @@ enum mpam_device_features { mpam_feat_msmon_csu_capture, mpam_feat_msmon_csu_xcl, mpam_feat_msmon_csu_hw_nrdy, + +/* +* Having mpam_feat_msmon_mbwu set doesn't mean the regular 31 bit MBWU +* counter would be used. The exact counter used is decided based on the +* status of mpam_feat_msmon_mbwu_44counter/mpam_feat_msmon_mbwu_63counter +* as well. +*/ mpam_feat_msmon_mbwu, + mpam_feat_msmon_mbwu_44counter, + mpam_feat_msmon_mbwu_63counter, mpam_feat_msmon_mbwu_capture, mpam_feat_msmon_mbwu_rwbw, mpam_feat_msmon_mbwu_hw_nrdy,
James Morse
maintainerRe: [PATCH v2 25/29] arm_mpam: Probe for long/lwd mbwu counters
Hi Jonathan,
Quoted 31 lines · Jonathan Cameron
Quoted 8 lines · On Wed, 10 Sep 2025 20:43:05 +0000 James Morse <[email protected]> wrote:
From: Rohit Mathew <[email protected]>
mpam v0.1 and versions above v1.0 support optional long counter for memory bandwidth monitoring. The
MPAMF_MBWUMON_IDRregister have fields indicating support for long counters. As of now, a 44 bit counter represented byHAS_LONGfield (bit 30) and a 63 bit counter represented by LWD (bit 29) can be optionally integrated. Probe for these counters and set corresponding feature bits if any of these counters are present.I'd like a little more justification of the 'front facing' use for the first feature bit. To me that seems confusing but I may well be missing why we can't have 3 exclusive features.
Quoted 17 lines
drivers/resctrl/mpam_devices.c +1
-1@@ -795,7 +795,7 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)dev_err_once (dev,"Counters are not usable because not-ready timeout was not provided by firmware." ); }if (FIELD_GET (MPAMF_MSMON_IDR_MSMON_MBWU , msmon_features)) { -bool hw_managed; +bool has_long, hw_managed;u32 mbwumon_idr =mpam_read_partsel_reg (msc,MBWUMON_IDR ); props->num_mbwu_mon =FIELD_GET (MPAMF_MBWUMON_IDR_NUM_MON , mbwumon_idr);@@ -805,6 +805,27 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)if (FIELD_GET (MPAMF_MBWUMON_IDR_HAS_RWBW , mbwumon_idr))mpam_set_feature (mpam_feat_msmon_mbwu_rwbw, props);
Quoted 15 lines
drivers/resctrl/mpam_devices.c static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) · line 819
Quoted 12 lines
drivers/resctrl/mpam_devices.c +12
-0+/* +* Treat long counter and its extension, lwd as mutually +* exclusive feature bits. Though these are dependent +* fields at the implementation level, there would never +* be a need for mpam_feat_msmon_mbwu_44counter (long +* counter) and mpam_feat_msmon_mbwu_63counter (lwd) +* bits to be set together. +* +* mpam_feat_msmon_mbwu isn't treated as an exclusive +* bit as this feature bit would be used as the "front +* facing feature bit" for any checks related to mbwu +* monitors. Why do we need such a 'front facing' bit? Why isn't it sufficient just to add a little helper or macro to find out if mbwu is turned on?
(I read Rohit's front-facing as top-level).
I think Rohit thought it would be simpler - there is one feature enum that gets passed in from the resctrl glue code saying "I want to read a bandwidth counter", because there is only one, and it doesn't care what size. I think Rohit didn't want to touch that code!
As that is really a separate concept, I think its worth handling explicitly:mpam_feat_msmon_mbwu means there are counters, and mpam_feat_msmon_mbwu_{31,44,63}counter say which ones are supported.
The helper you suggest an then pick which one is best.
Thanks,
James
James Morse
maintainerPATCH v2 26/29 arm_mpam: Use long MBWU counters if supported
In reply to James MorseFrom: Rohit Mathew <[email protected]>
If the 44 bit (long) or 63 bit (LWD) counters are detected on probing the RIS, use long/LWD counter instead of the regular 31 bit mbwu counter.
Only 32bit accesses to the MSC are required to be supported by the spec, but these registers are 64bits. The lower half may overflow into the higher half between two 32bit reads. To avoid this, use a helper that reads the top half multiple times to check for overflow.
---
Changes since v1:
* Only clear OFLOW_STATUS_L on MBWU counters.
Changes since RFC:
* Commit message wrangling.
* Refer to 31 bit counters as opposed to 32 bit (registers).
--- drivers/resctrl/mpam_devices.c | 91 ++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 9 deletions(-)
drivers/resctrl/mpam_devices.c +82 -9
@@ -927,6 +927,48 @@ struct mon_read {int err; }; +static bool mpam_ris_has_mbwu_long_counter (struct mpam_msc_ris *ris) +{ +return (mpam_has_feature (mpam_feat_msmon_mbwu_63counter, &ris->props) || +mpam_has_feature (mpam_feat_msmon_mbwu_44counter, &ris->props)); +} + +static u64 mpam_msc_read_mbwu_l (struct mpam_msc *msc) +{ +int retry =3 ; +u32 mbwu_l_low; +u64 mbwu_l_high1, mbwu_l_high2; + +mpam_mon_sel_lock_held (msc); + +WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); + + mbwu_l_high2 =__mpam_read_reg (msc,MSMON_MBWU_L +4 ); +do { + mbwu_l_high1 = mbwu_l_high2; + mbwu_l_low =__mpam_read_reg (msc,MSMON_MBWU_L ); + mbwu_l_high2 =__mpam_read_reg (msc,MSMON_MBWU_L +4 ); + + retry--; + }while (mbwu_l_high1 != mbwu_l_high2 && retry >0 ); + +if (mbwu_l_high1 == mbwu_l_high2) +return (mbwu_l_high1 <<32 ) | mbwu_l_low; +return MSMON___NRDY_L ; +} + +static void mpam_msc_zero_mbwu_l (struct mpam_msc *msc) +{ +mpam_mon_sel_lock_held (msc); + +WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); + +__mpam_write_reg (msc,MSMON_MBWU_L ,0 ); +__mpam_write_reg (msc,MSMON_MBWU_L +4 ,0 ); +} +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val,u32 *flt_val) {
@@ -989,6 +1031,9 @@ static void read_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val,static void clean_msmon_ctl_val (u32 *cur_ctl) { *cur_ctl &= ~MSMON_CFG_x_CTL_OFLOW_STATUS; + +if (FIELD_GET (MSMON_CFG_x_CTL_TYPE, *cur_ctl) ==MSMON_CFG_MBWU_CTL_TYPE_MBWU ) + *cur_ctl &= ~MSMON_CFG_MBWU_CTL_OFLOW_STATUS_L ; } static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,
@@ -1011,7 +1056,11 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,case mpam_feat_msmon_mbwu:mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val);mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); -mpam_write_monsel_reg (msc,MBWU ,0 ); +if (mpam_ris_has_mbwu_long_counter (m->ris)) +mpam_msc_zero_mbwu_l (m->ris->vmsc->msc); +else +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); mbwu_state = &m->ris->mbwu_state[m->ctx->mon];
@@ -1026,8 +1075,13 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,static u64 mpam_msmon_overflow_val (struct mpam_msc_ris *ris) { -/* TODO: scaling, and long counters */ -return GENMASK_ULL (30 ,0 ); +/* TODO: implement scaling counters */ +if (mpam_has_feature (mpam_feat_msmon_mbwu_63counter, &ris->props)) +return GENMASK_ULL (62 ,0 ); +else if (mpam_has_feature (mpam_feat_msmon_mbwu_44counter, &ris->props)) +return GENMASK_ULL (43 ,0 ); +else +return GENMASK_ULL (30 ,0 ); }/* Call with MSC lock held */
@@ -1069,10 +1123,24 @@ static void __ris_msmon_read(void *arg) now =FIELD_GET (MSMON___VALUE , now);break ;case mpam_feat_msmon_mbwu: - now =mpam_read_monsel_reg (msc,MBWU ); -if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) - nrdy = now &MSMON___NRDY ; - now =FIELD_GET (MSMON___VALUE , now); +/* +* If long or lwd counters are supported, use them, else revert +* to the 31 bit counter. +*/ +if (mpam_ris_has_mbwu_long_counter (ris)) { + now =mpam_msc_read_mbwu_l (msc); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY_L ; +if (mpam_has_feature (mpam_feat_msmon_mbwu_63counter, rprops)) + now =FIELD_GET (MSMON___LWD_VALUE , now); +else + now =FIELD_GET (MSMON___L_VALUE , now); + }else { + now =mpam_read_monsel_reg (msc,MBWU ); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now); + }if (nrdy)break ;
@@ -1360,8 +1428,13 @@ static int mpam_save_mbwu_state(void *arg) cur_ctl =mpam_read_monsel_reg (msc,CFG_MBWU_CTL );mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 ); - val =mpam_read_monsel_reg (msc,MBWU ); -mpam_write_monsel_reg (msc,MBWU ,0 ); +if (mpam_ris_has_mbwu_long_counter (ris)) { + val =mpam_msc_read_mbwu_l (msc); +mpam_msc_zero_mbwu_l (msc); + }else { + val =mpam_read_monsel_reg (msc,MBWU ); +mpam_write_monsel_reg (msc,MBWU ,0 ); + } cfg->mon = i; cfg->pmg =FIELD_GET (MSMON_CFG_x_FLT_PMG, cur_flt);
Signature · 1 line
2.39.5
Re: [PATCH v2 26/29] arm_mpam: Use long MBWU counters if supported
Quoted 11 lines · On Wed, 10 Sep 2025 20:43:06 +0000 James Morse <[email protected]> wrote:
From: Rohit Mathew <[email protected]>
If the 44 bit (long) or 63 bit (LWD) counters are detected on probing the RIS, use long/LWD counter instead of the regular 31 bit mbwu counter.
Only 32bit accesses to the MSC are required to be supported by the spec, but these registers are 64bits. The lower half may overflow into the higher half between two 32bit reads. To avoid this, use a helper that reads the top half multiple times to check for overflow.
Quoted 4 lines
Signed-off-by Rohit Mathew <[email protected]>[morse: merged multiple patches from Rohit]Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
James Morse
maintainerRe: [PATCH v2 26/29] arm_mpam: Use long MBWU counters if supported
Hi Jonathan,
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Wed, 10 Sep 2025 20:43:06 +0000 James Morse <[email protected]> wrote:
From: Rohit Mathew <[email protected]>
If the 44 bit (long) or 63 bit (LWD) counters are detected on probing the RIS, use long/LWD counter instead of the regular 31 bit mbwu counter.
Only 32bit accesses to the MSC are required to be supported by the spec, but these registers are 64bits. The lower half may overflow into the higher half between two 32bit reads. To avoid this, use a helper that reads the top half multiple times to check for overflow.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Rohit Mathew <[email protected]>[morse: merged multiple patches from Rohit]Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Your push back on the 'front facing' thing in the previous patch made some knock on changes here, but I think they're minor.
Thanks,
James
Re: [PATCH v2 26/29] arm_mpam: Use long MBWU counters if supported
In reply to James MorseQuoted 11 lines · James Morse
From: Rohit Mathew <[email protected]>
If the 44 bit (long) or 63 bit (LWD) counters are detected on probing the RIS, use long/LWD counter instead of the regular 31 bit mbwu counter.
Only 32bit accesses to the MSC are required to be supported by the spec, but these registers are 64bits. The lower half may overflow into the higher half between two 32bit reads. To avoid this, use a helper that reads the top half multiple times to check for overflow.
Quoted 4 lines
Signed-off-by Rohit Mathew <[email protected]>[morse: merged multiple patches from Rohit]Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>
Thanks.
-Fenghua
Quoted 148 lines
---
Changes since v1:
* Only clearOFLOW_STATUS_Lon MBWU counters.Changes since RFC:
* Commit message wrangling.
* Refer to 31 bit counters as opposed to 32 bit (registers).--- drivers/resctrl/mpam_devices.c | 91 ++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 9 deletions(-)drivers/resctrl/mpam_devices.c +82
-9@@ -927,6 +927,48 @@ struct mon_read {int err; }; +static bool mpam_ris_has_mbwu_long_counter (struct mpam_msc_ris *ris) +{ +return (mpam_has_feature (mpam_feat_msmon_mbwu_63counter, &ris->props) || +mpam_has_feature (mpam_feat_msmon_mbwu_44counter, &ris->props)); +} + +static u64 mpam_msc_read_mbwu_l (struct mpam_msc *msc) +{ +int retry =3 ; +u32 mbwu_l_low; +u64 mbwu_l_high1, mbwu_l_high2; + +mpam_mon_sel_lock_held (msc); + +WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); + + mbwu_l_high2 =__mpam_read_reg (msc,MSMON_MBWU_L +4 ); +do { + mbwu_l_high1 = mbwu_l_high2; + mbwu_l_low =__mpam_read_reg (msc,MSMON_MBWU_L ); + mbwu_l_high2 =__mpam_read_reg (msc,MSMON_MBWU_L +4 ); + + retry--; + }while (mbwu_l_high1 != mbwu_l_high2 && retry >0 ); + +if (mbwu_l_high1 == mbwu_l_high2) +return (mbwu_l_high1 <<32 ) | mbwu_l_low; +return MSMON___NRDY_L ; +} + +static void mpam_msc_zero_mbwu_l (struct mpam_msc *msc) +{ +mpam_mon_sel_lock_held (msc); + +WARN_ON_ONCE ((MSMON_MBWU_L +sizeof (u64)) > msc->mapped_hwpage_sz); +WARN_ON_ONCE (!cpumask_test_cpu (smp_processor_id (), &msc->accessibility)); + +__mpam_write_reg (msc,MSMON_MBWU_L ,0 ); +__mpam_write_reg (msc,MSMON_MBWU_L +4 ,0 ); +} +static void gen_msmon_ctl_flt_vals (struct mon_read *m,u32 *ctl_val,u32 *flt_val) {@@ -989,6 +1031,9 @@ static void read_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val,static void clean_msmon_ctl_val (u32 *cur_ctl) { *cur_ctl &= ~MSMON_CFG_x_CTL_OFLOW_STATUS; + +if (FIELD_GET (MSMON_CFG_x_CTL_TYPE, *cur_ctl) ==MSMON_CFG_MBWU_CTL_TYPE_MBWU ) + *cur_ctl &= ~MSMON_CFG_MBWU_CTL_OFLOW_STATUS_L ; } static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,@@ -1011,7 +1056,11 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,case mpam_feat_msmon_mbwu:mpam_write_monsel_reg (msc,CFG_MBWU_FLT , flt_val);mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val); -mpam_write_monsel_reg (msc,MBWU ,0 ); +if (mpam_ris_has_mbwu_long_counter (m->ris)) +mpam_msc_zero_mbwu_l (m->ris->vmsc->msc); +else +mpam_write_monsel_reg (msc,MBWU ,0 ); +mpam_write_monsel_reg (msc,CFG_MBWU_CTL , ctl_val | MSMON_CFG_x_CTL_EN); mbwu_state = &m->ris->mbwu_state[m->ctx->mon];@@ -1026,8 +1075,13 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,static u64 mpam_msmon_overflow_val (struct mpam_msc_ris *ris) { -/* TODO: scaling, and long counters */ -return GENMASK_ULL (30 ,0 ); +/* TODO: implement scaling counters */ +if (mpam_has_feature (mpam_feat_msmon_mbwu_63counter, &ris->props)) +return GENMASK_ULL (62 ,0 ); +else if (mpam_has_feature (mpam_feat_msmon_mbwu_44counter, &ris->props)) +return GENMASK_ULL (43 ,0 ); +else +return GENMASK_ULL (30 ,0 ); }/* Call with MSC lock held */ @@ -1069,10 +1123,24 @@ static void __ris_msmon_read(void *arg) now =FIELD_GET (MSMON___VALUE , now);break ;case mpam_feat_msmon_mbwu: - now =mpam_read_monsel_reg (msc,MBWU ); -if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) - nrdy = now &MSMON___NRDY ; - now =FIELD_GET (MSMON___VALUE , now); +/* +* If long or lwd counters are supported, use them, else revert +* to the 31 bit counter. +*/ +if (mpam_ris_has_mbwu_long_counter (ris)) { + now =mpam_msc_read_mbwu_l (msc); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY_L ; +if (mpam_has_feature (mpam_feat_msmon_mbwu_63counter, rprops)) + now =FIELD_GET (MSMON___LWD_VALUE , now); +else + now =FIELD_GET (MSMON___L_VALUE , now); + }else { + now =mpam_read_monsel_reg (msc,MBWU ); +if (mpam_has_feature (mpam_feat_msmon_mbwu_hw_nrdy, rprops)) + nrdy = now &MSMON___NRDY ; + now =FIELD_GET (MSMON___VALUE , now); + }if (nrdy)break ;@@ -1360,8 +1428,13 @@ static int mpam_save_mbwu_state(void *arg) cur_ctl =mpam_read_monsel_reg (msc,CFG_MBWU_CTL );mpam_write_monsel_reg (msc,CFG_MBWU_CTL ,0 ); - val =mpam_read_monsel_reg (msc,MBWU ); -mpam_write_monsel_reg (msc,MBWU ,0 ); +if (mpam_ris_has_mbwu_long_counter (ris)) { + val =mpam_msc_read_mbwu_l (msc); +mpam_msc_zero_mbwu_l (msc); + }else { + val =mpam_read_monsel_reg (msc,MBWU ); +mpam_write_monsel_reg (msc,MBWU ,0 ); + } cfg->mon = i; cfg->pmg =FIELD_GET (MSMON_CFG_x_FLT_PMG, cur_flt);
James Morse
maintainerPATCH v2 27/29 arm_mpam: Add helper to reset saved mbwu state
In reply to James Morseresctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
--- drivers/resctrl/mpam_devices.c | 47 +++++++++++++++++++++++++++++++-- drivers/resctrl/mpam_internal.h | 5 +++- 2 files changed, 49 insertions(+), 3 deletions(-)
drivers/resctrl/mpam_devices.c +45 -2
@@ -1088,9 +1088,11 @@ static u64 mpam_msmon_overflow_val(struct mpam_msc_ris *ris)static void __ris_msmon_read (void *arg) {bool nrdy = false; +bool config_mismatch;struct mon_read *m = arg;u64 now, overflow_val =0 ;struct mon_cfg *ctx = m->ctx; +bool reset_on_next_read = false;struct mpam_msc_ris *ris = m->ris;struct msmon_mbwu_state *mbwu_state;struct mpam_props *rprops = &ris->props;
@@ -1105,6 +1107,14 @@ static void __ris_msmon_read(void *arg)FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx);mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); +if (m->type == mpam_feat_msmon_mbwu) { + mbwu_state = &ris->mbwu_state[ctx->mon]; +if (mbwu_state) { + reset_on_next_read = mbwu_state->reset_on_next_read; + mbwu_state->reset_on_next_read = false; + } + } +/* * Read the existing configuration to avoid re-writing the same values. * This saves waiting for 'nrdy' on subsequent reads.
@@ -1112,7 +1122,10 @@ static void __ris_msmon_read(void *arg)read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt);clean_msmon_ctl_val (&cur_ctl);gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); -if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) + config_mismatch = cur_flt != flt_val || + cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN); + +if (config_mismatch || reset_on_next_read)write_msmon_ctl_flt_vals (m, ctl_val, flt_val);switch (m->type) {
@@ -1145,7 +1158,6 @@ static void __ris_msmon_read(void *arg)if (nrdy)break ; - mbwu_state = &ris->mbwu_state[ctx->mon];if (!mbwu_state)break ;
@@ -1245,6 +1257,37 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,return err; } +void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx) +{ +int idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +if (!mpam_is_enabled ()) +return ; + + idx =srcu_read_lock (&mpam_srcu); +list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &vmsc->props)) +continue ; + + msc = vmsc->msc; +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &ris->props)) +continue ; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +continue ; + + ris->mbwu_state[ctx->mon].correction =0 ; + ris->mbwu_state[ctx->mon].reset_on_next_read = true; +mpam_mon_sel_unlock (msc); + } + } +srcu_read_unlock (&mpam_srcu, idx); +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;
drivers/resctrl/mpam_internal.h +4 -1
@@ -223,10 +223,12 @@ struct mon_cfg {/* * Changes to enabled and cfg are protected by the msc->lock. -* Changes to prev_val and correction are protected by the msc's mon_sel_lock. +* Changes to reset_on_next_read, prev_val and correction are protected by the +* msc's mon_sel_lock. */ struct msmon_mbwu_state {bool enabled; +bool reset_on_next_read;struct mon_cfg cfg;/* The value last read from the hardware. Used to detect overflow. */
@@ -393,6 +395,7 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid,int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx,enum mpam_device_features ,u64 *val); +void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx);int mpam_get_cpumask_from_cache_id (unsigned long cache_id,u32 cache_level,cpumask_t *affinity);
Signature · 1 line
2.39.5
Re: [PATCH v2 27/29] arm_mpam: Add helper to reset saved mbwu state
Quoted 9 lines · On Wed, 10 Sep 2025 20:43:07 +0000 James Morse <[email protected]> wrote:
resctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
Signed-off-by James Morse <[email protected]>
Minor comments inline.
Jonathan
Quoted 5 lines
drivers/resctrl/mpam_devices.c +1
-0@@ -1245,6 +1257,37 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,return err; } +void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx)
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1270
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+{ +int idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +if (!mpam_is_enabled ()) +return ; + + idx =srcu_read_lock (&mpam_srcu);
Maybe guard() though it doesn't add that much here.
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1271
Quoted 1 line
drivers/resctrl/mpam_devices.c +1
-0+list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) {
Reason not to use _srcu variants?
Quoted 27 lines
drivers/resctrl/mpam_devices.c +19
-0+if (!mpam_has_feature (mpam_feat_msmon_mbwu, &vmsc->props)) +continue ; + + msc = vmsc->msc; +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &ris->props)) +continue ; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +continue ; + + ris->mbwu_state[ctx->mon].correction =0 ; + ris->mbwu_state[ctx->mon].reset_on_next_read = true; +mpam_mon_sel_unlock (msc); + } + } +srcu_read_unlock (&mpam_srcu, idx); +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;drivers/resctrl/mpam_internal.h +0
-0
drivers/resctrl/mpam_internal.h struct mon_cfg { · line 227
Quoted 6 lines
drivers/resctrl/mpam_internal.h +2
-1@@ -223,10 +223,12 @@ struct mon_cfg {/* * Changes to enabled and cfg are protected by the msc->lock. -* Changes to prev_val and correction are protected by the msc's mon_sel_lock. +* Changes to reset_on_next_read, prev_val and correction are protected by the +* msc's mon_sel_lock.
Getting close to the point where a list of one per line would reduce churn. If you anticipate adding more to this in future I'd definitely consider it. e.g.
* msc's mon_sel_lcok protects:
* - reset_on_next_read
* - prev_val
* - correction
*/
Quoted 15 lines
drivers/resctrl/mpam_internal.h +2
-0*/ struct msmon_mbwu_state {bool enabled; +bool reset_on_next_read;struct mon_cfg cfg;/* The value last read from the hardware. Used to detect overflow. */ @@ -393,6 +395,7 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid,int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx,enum mpam_device_features ,u64 *val); +void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx);int mpam_get_cpumask_from_cache_id (unsigned long cache_id,u32 cache_level,cpumask_t *affinity);
James Morse
maintainerRe: [PATCH v2 27/29] arm_mpam: Add helper to reset saved mbwu state
Hi Jonathan,
Quoted 20 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 10 Sep 2025 20:43:07 +0000 James Morse <[email protected]> wrote:
resctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
Signed-off-by James Morse <[email protected]>Minor comments inline.
Quoted 4 lines
drivers/resctrl/mpam_devices.c +0
-0@@ -1245,6 +1257,37 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,return err; }
Quoted 13 lines
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1270
Quoted 11 lines
drivers/resctrl/mpam_devices.c +11
-0+void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx) +{ +int idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +if (!mpam_is_enabled ()) +return ; + + idx =srcu_read_lock (&mpam_srcu);Maybe
guard()though it doesn't add that much here.
'Fixed' already based on your other feedback.
Quoted 3 lines
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1271
Quoted 1 line
drivers/resctrl/mpam_devices.c +1
-0+list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) {Reason not to use
_srcuvariants?
Typo - I'd switched it all to srcu because of the pcc thing's need to sleep, but didn't fix all these properly.
Quoted 28 lines
Quoted 28 lines
drivers/resctrl/mpam_devices.c +19
-0+if (!mpam_has_feature (mpam_feat_msmon_mbwu, &vmsc->props)) +continue ; + + msc = vmsc->msc; +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &ris->props)) +continue ; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +continue ; + + ris->mbwu_state[ctx->mon].correction =0 ; + ris->mbwu_state[ctx->mon].reset_on_next_read = true; +mpam_mon_sel_unlock (msc); + } + } +srcu_read_unlock (&mpam_srcu, idx); +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;drivers/resctrl/mpam_internal.h +0
-0@@ -223,10 +223,12 @@ struct mon_cfg {
Quoted 14 lines
drivers/resctrl/mpam_internal.h struct mon_cfg { · line 227
Quoted 5 lines
drivers/resctrl/mpam_internal.h +2
-1/* * Changes to enabled and cfg are protected by the msc->lock. -* Changes to prev_val and correction are protected by the msc's mon_sel_lock. +* Changes to reset_on_next_read, prev_val and correction are protected by the +* msc's mon_sel_lock. Getting close to the point where a list of one per line would reduce churn. If you anticipate adding more to this in future I'd definitely consider it. e.g.
* msc'smon_sel_lcokprotects:
* -reset_on_next_read
* -prev_val
* - correction
*/
It doesn't get expanded further, this is the last patch of the driver. But this is easier to read, so I'll do that.
Thanks,
James
RE: [PATCH v2 27/29] arm_mpam: Add helper to reset saved mbwu state
In reply to James MorseHello James
Quoted 47 lines
resctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
Signed-off-by James Morse <[email protected]>--- drivers/resctrl/mpam_devices.c | 47 +++++++++++++++++++++++++++++++-- drivers/resctrl/mpam_internal.h | 5 +++- 2 files changed, 49 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +2
-0@@ -1088,9 +1088,11 @@ static u64 mpam_msmon_overflow_val(struct mpam_msc_ris *ris) static void __ris_msmon_read(void *arg) {bool nrdy = false; +bool config_mismatch;struct mon_read *m = arg;u64 now, overflow_val =0 ;struct mon_cfg *ctx = m->ctx; +bool reset_on_next_read = false;struct mpam_msc_ris *ris = m->ris;struct msmon_mbwu_state *mbwu_state; struct mpam_props *rprops = &ris->props; @@ -1105,6 +1107,14 @@static void __ris_msmon_read (void *arg)drivers/resctrl/mpam_devices.c +4
-0FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx);mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); +if (m->type == mpam_feat_msmon_mbwu) { + mbwu_state = &ris->mbwu_state[ctx->mon]; +if (mbwu_state) { + reset_on_next_read =
mbwu_state->reset_on_next_read;drivers/resctrl/mpam_devices.c +4
-0+ mbwu_state->reset_on_next_read = false; + } + } +/* * Read the existing configuration to avoid re-writing the same values. * This saves waiting for 'nrdy' on subsequent reads.
drivers/resctrl/mpam_devices.c static void __ris_msmon_read(void *arg) · line 1129
Quoted 9 lines
drivers/resctrl/mpam_devices.c +4
-1@@ -1112,7 +1122,10 @@ static void __ris_msmon_read(void *arg)read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt);clean_msmon_ctl_val (&cur_ctl);gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); -if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) + config_mismatch = cur_flt != flt_val || + cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN); + +if (config_mismatch || reset_on_next_read)write_msmon_ctl_flt_vals (m, ctl_val, flt_val);
mbm_handle_overflow() calls __ris_msmon_read() every second.
If there are multiple monitor groups, the config_mismatch will "true" every second.
Then "mbwu_state->prev_val = 0;" in function write_msmon_ctl_flt_vals() will be always run. This means that for multiple monitoring groups, the MemoryBandwidth monitoring value is cleared every second.
https://lore.kernel.org/lkml/[email protected]/
+ mbwu_state = &m->ris->mbwu_state[m->ctx->mon];
+ if (mbwu_state)
+ mbwu_state->prev_val = 0;
Best regards,
Shaopeng TAN
Quoted 87 lines
drivers/resctrl/mpam_devices.c +1
-1switch (m->type) {@@ -1145,7 +1158,6 @@ static void __ris_msmon_read(void *arg)if (nrdy)break ; - mbwu_state = &ris->mbwu_state[ctx->mon];if (!mbwu_state)break ;@@ -1245,6 +1257,37 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, return err; } +void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct
mon_cfgdrivers/resctrl/mpam_devices.c +12
-0+*ctx) { + int idx; + struct mpam_msc *msc; + struct mpam_vmsc *vmsc; + struct mpam_msc_ris *ris; + + if (!mpam_is_enabled()) + return; + + idx = srcu_read_lock(&mpam_srcu); + list_for_each_entry_rcu(vmsc, &comp->vmsc, comp_list) { + if (!mpam_has_feature(mpam_feat_msmon_mbwu,
&vmsc->props))drivers/resctrl/mpam_devices.c +5
-0+continue ; + + msc = vmsc->msc; + list_for_each_entry_rcu(ris, &vmsc->ris, vmsc_list) { + if (!mpam_has_feature(mpam_feat_msmon_mbwu,
&ris->props))drivers/resctrl/mpam_devices.c +7
-0+continue ; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +continue ; + + ris->mbwu_state[ctx->mon].correction =0 ; + ris->mbwu_state[ctx->mon].reset_on_next_read =true;
drivers/resctrl/mpam_devices.c +6
-0+mpam_mon_sel_unlock (msc); + } + } +srcu_read_unlock (&mpam_srcu, idx); +} + static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16wd) {
drivers/resctrl/mpam_devices.c +0
-0u32 num_words, msb;(quoted diff) +0
-0
b/drivers/resctrl/mpam_internal.hindexc190826dfbda..7cbcafe8294a100644drivers/resctrl/mpam_internal.h +0
-1@@ -223,10 +223,12 @@ struct mon_cfg {/* * Changes to enabled and cfg are protected by the msc->lock. -* Changes to prev_val and correction are protected by the msc's
mon_sel_lock.
+ * Changes toreset_on_next_read,prev_valand correction are protected
+ by the
+ * msc'smon_sel_lock.
*/
structmsmon_mbwu_state{drivers/resctrl/mpam_internal.h +2
-0bool enabled; +bool reset_on_next_read;struct mon_cfg cfg;/* The value last read from the hardware. Used to detect overflow. */ @@ -393,6 +395,7 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid, int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,enum mpam_device_features ,u64 *val); +void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct
mon_cfg
+*ctx);int mpam_get_cpumask_from_cache_id(unsigned long
cache_id, u32cache_level,
cpumask_t*affinity);
--
2.39.5
James Morse
maintainerRe: [PATCH v2 27/29] arm_mpam: Add helper to reset saved mbwu state
Hi Shaopeng,
Quoted 8 lines · Shaopeng Tan (Fujitsu)
Quoted 7 lines
resctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
Quoted 14 lines
Quoted 5 lines
drivers/resctrl/mpam_devices.c +0
-0drivers/resctrl/mpam_devices.c static void __ris_msmon_read(void *arg) · line 1129
Quoted 9 lines
drivers/resctrl/mpam_devices.c +4
-1@@ -1112,7 +1122,10 @@ static void __ris_msmon_read(void *arg)read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt);clean_msmon_ctl_val (&cur_ctl);gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); -if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) + config_mismatch = cur_flt != flt_val || + cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN); + +if (config_mismatch || reset_on_next_read)write_msmon_ctl_flt_vals (m, ctl_val, flt_val);
I don't have a platform that implements any of the bandwidth counters, so may need a hand to debug this ...
Quoted 2 lines
mbm_handle_overflow()calls__ris_msmon_read()every second.
If there are multiple monitor groups, theconfig_mismatchwill "true" every second.
It shouldn't be - I think you've forced it into a pathalogical case that the resctrl glue code tries very hard to avoid.
The pattern of allocating a montior, detecing a mismatch and reconfiguring it is needed for CSU. That stuff is re-usable for MBWU, but you never want it to happen outside control/monitor group creation because it means you're losing data.
For those reading along at home:
resctrl expects there to be as many hardware monitors as PARTID*PMG - because every control and monitor group has 'mbm_total_bytes' or equivalent files. User-space can read these at any time, and the deal is they start at 0 from boot, and reset when the control or monitor group is created.
This means the MPAM driver needs to have enough, and it needs to pre-configure them on startup.
The resctrl glue code calls this 'free running'. It means when you call resctrl_arch_mon_ctx_alloc() for a bandwidth monitor - it doesn't allocate a context, but returns a magic out of range value 'USE_RMID_IDX' so that subsequent calls use the pre-allocated monitor.
If you don't have PARTID*PMG's worth of monitors - you can't have resctrl's mbm_total_bytes interface. People regularly complain about this - but the alternative is counters that randomly reset, meaning you could never trust the value.
I have no intention of supporting that mode, (its already available in /dev/urandom!)
If you're seeing this mismatch happen from the overflow thread - I think you've forced the mbwu counters on when you don't have enough monitors.
Even if the resctrl overflow 'thread' used the same mon_ctx - USE_RMID_IDX means it will access a different hardware monitor each time.
Another option is clean_msmon_ctl_val() is missing a bit that is set by hardware, causing the values to mismatch when they shouldn't.
Could you check mon_ctx is USE_RMID_IDX, and check which bits are mismatching?
Quoted 2 lines
Then "
mbwu_state->prev_val= 0;" in functionwrite_msmon_ctl_flt_vals()will be always run. This means that for multiple monitoring groups, the MemoryBandwidth monitoring value is cleared every second.
Yes - this should never happen because the overflow thread should never cause a mismatch, and the montiros should only be reconfigured when control/monitor groups are allocated.
Thanks,
James
Re: [PATCH v2 27/29] arm_mpam: Add helper to reset saved mbwu state
In reply to James MorseHi, James,
Quoted 9 lines · James Morse
resctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
Signed-off-by James Morse <[email protected]>
Other than the following minor change,
Quoted 61 lines
--- drivers/resctrl/mpam_devices.c | 47 +++++++++++++++++++++++++++++++-- drivers/resctrl/mpam_internal.h | 5 +++- 2 files changed, 49 insertions(+), 3 deletions(-)drivers/resctrl/mpam_devices.c +15
-2@@ -1088,9 +1088,11 @@ static u64 mpam_msmon_overflow_val(struct mpam_msc_ris *ris)static void __ris_msmon_read (void *arg) {bool nrdy = false; +bool config_mismatch;struct mon_read *m = arg;u64 now, overflow_val =0 ;struct mon_cfg *ctx = m->ctx; +bool reset_on_next_read = false;struct mpam_msc_ris *ris = m->ris;struct msmon_mbwu_state *mbwu_state;struct mpam_props *rprops = &ris->props;@@ -1105,6 +1107,14 @@ static void __ris_msmon_read(void *arg)FIELD_PREP (MSMON_CFG_MON_SEL_RIS , ris->ris_idx);mpam_write_monsel_reg (msc,CFG_MON_SEL , mon_sel); +if (m->type == mpam_feat_msmon_mbwu) { + mbwu_state = &ris->mbwu_state[ctx->mon]; +if (mbwu_state) { + reset_on_next_read = mbwu_state->reset_on_next_read; + mbwu_state->reset_on_next_read = false; + } + } +/* * Read the existing configuration to avoid re-writing the same values. * This saves waiting for 'nrdy' on subsequent reads. @@ -1112,7 +1122,10 @@ static void __ris_msmon_read(void *arg)read_msmon_ctl_flt_vals (m, &cur_ctl, &cur_flt);clean_msmon_ctl_val (&cur_ctl);gen_msmon_ctl_flt_vals (m, &ctl_val, &flt_val); -if (cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN)) + config_mismatch = cur_flt != flt_val || + cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN); + +if (config_mismatch || reset_on_next_read)write_msmon_ctl_flt_vals (m, ctl_val, flt_val);switch (m->type) {@@ -1145,7 +1158,6 @@ static void __ris_msmon_read(void *arg)if (nrdy)break ; - mbwu_state = &ris->mbwu_state[ctx->mon];if (!mbwu_state)break ;@@ -1245,6 +1257,37 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,return err; } +void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx)
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1270
Quoted 10 lines
drivers/resctrl/mpam_devices.c +10
-0+{ +int idx; +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +if (!mpam_is_enabled ()) +return ; + + idx =srcu_read_lock (&mpam_srcu);
guard(srcu)(&mpam_srcu);
Quoted 42 lines
drivers/resctrl/mpam_devices.c +20
-0+list_for_each_entry_rcu (vmsc, &comp->vmsc, comp_list) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &vmsc->props)) +continue ; + + msc = vmsc->msc; +list_for_each_entry_rcu (ris, &vmsc->ris, vmsc_list) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &ris->props)) +continue ; + +if (WARN_ON_ONCE (!mpam_mon_sel_lock (msc))) +continue ; + + ris->mbwu_state[ctx->mon].correction =0 ; + ris->mbwu_state[ctx->mon].reset_on_next_read = true; +mpam_mon_sel_unlock (msc); + } + } +srcu_read_unlock (&mpam_srcu, idx); +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;drivers/resctrl/mpam_internal.h +3
-1@@ -223,10 +223,12 @@ struct mon_cfg {/* * Changes to enabled and cfg are protected by the msc->lock. -* Changes to prev_val and correction are protected by the msc's mon_sel_lock. +* Changes to reset_on_next_read, prev_val and correction are protected by the +* msc's mon_sel_lock. */ struct msmon_mbwu_state {bool enabled; +bool reset_on_next_read;struct mon_cfg cfg;/* The value last read from the hardware. Used to detect overflow. */
drivers/resctrl/mpam_internal.h int mpam_apply_config(struct mpam_component *comp, u16 partid, · line 401
Quoted 7 lines
drivers/resctrl/mpam_internal.h +1
-0@@ -393,6 +395,7 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid,int mpam_msmon_read (struct mpam_component *comp,struct mon_cfg *ctx,enum mpam_device_features ,u64 *val); +void mpam_msmon_reset_mbwu (struct mpam_component *comp,struct mon_cfg *ctx);int mpam_get_cpumask_from_cache_id (unsigned long cache_id,u32 cache_level,cpumask_t *affinity);
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 27/29] arm_mpam: Add helper to reset saved mbwu state
Hi Fenghua,
Quoted 9 lines · Fenghua Yu
Quoted 8 lines · James Morse
resctrl expects to reset the bandwidth counters when the filesystem is mounted.
To allow this, add a helper that clears the saved mbwu state. Instead of cross calling to each CPU that can access the component MSC to write to the counter, set a flag that causes it to be zero'd on the the next read. This is easily done by forcing a configuration update.
Quoted 5 lines
Quoted 1 line
Signed-off-by James Morse <[email protected]>Other than the following minor change,
Reviewed-by Fenghua Yu <[email protected]>
Thanks!
Quoted 14 lines
Quoted 14 lines
drivers/resctrl/mpam_devices.c +0
-0@@ -1245,6 +1257,37 @@ int mpam_msmon_read(struct
mpam_component*comp, structmon_cfg*ctx,
return err;
}
+voidmpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx)+{
+ int idx;
+ structmpam_msc*msc;
+ structmpam_vmsc*vmsc;
Quoted 8 lines
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1270
Quoted 6 lines
+ struct
mpam_msc_ris*ris;drivers/resctrl/mpam_devices.c +5
-0+ + if (!mpam_is_enabled()) + return; + + idx = srcu_read_lock(&mpam_srcu);guard(srcu)(&mpam_srcu);
Yeah, Jonathan had already suggested it.
Quoted 11 lines
Quoted 11 lines
+
list_for_each_entry_rcu(vmsc, &comp->vmsc, comp_list){ + if (!mpam_has_feature(mpam_feat_msmon_mbwu,&vmsc->props)) + continue;drivers/resctrl/mpam_devices.c +8
-0+ + msc = vmsc->msc; + list_for_each_entry_rcu(ris, &vmsc->ris, vmsc_list) { + if (!mpam_has_feature(mpam_feat_msmon_mbwu, &ris->props)) + continue; + + if (WARN_ON_ONCE(!mpam_mon_sel_lock(msc))) + continue;
Quoted 8 lines
drivers/resctrl/mpam_devices.c int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, · line 1289
Quoted 8 lines
drivers/resctrl/mpam_devices.c +8
-0+ + ris->mbwu_state[ctx->mon].correction = 0; + ris->mbwu_state[ctx->mon].reset_on_next_read = true; + mpam_mon_sel_unlock(msc); + } + } + srcu_read_unlock(&mpam_srcu, idx); +}
Thanks,
James
James Morse
maintainerPATCH v2 28/29 arm_mpam: Add kunit test for bitmap reset
In reply to James MorseThe bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
--- drivers/resctrl/Kconfig | 10 +++++ drivers/resctrl/mpam_devices.c | 4 ++ drivers/resctrl/test_mpam_devices.c | 68 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 drivers/resctrl/test_mpam_devices.c
drivers/resctrl/Kconfig +10 -0
@@ -5,10 +5,20 @@ menuconfig ARM64_MPAM_DRIVER MPAM driver for System IP, e,g. caches and memory controllers. if ARM64_MPAM_DRIVER + config ARM64_MPAM_DRIVER_DEBUG bool "Enable debug messages from the MPAM driver" depends on ARM64_MPAM_DRIVER help Say yes here to enable debug messages from the MPAM driver. +config MPAM_KUNIT_TEST + bool "KUnit tests for MPAM driver " if !KUNIT_ALL_TESTS + depends on KUNIT=y + default KUNIT_ALL_TESTS + help + Enable this option to run tests in the MPAM driver. + + If unsure, say N. + endif
drivers/resctrl/mpam_devices.c +4 -0
@@ -2662,3 +2662,7 @@ static int __init mpam_msc_driver_init(void) }/* Must occur after arm64_mpam_register_cpus() from arch_initcall() */ subsys_initcall (mpam_msc_driver_init); + +#ifdef CONFIG_MPAM_KUNIT_TEST +#include "test_mpam_devices.c" +#endif
drivers/resctrl/test_mpam_devices.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH v2 28/29] arm_mpam: Add kunit test for bitmap reset
Quoted 7 lines · On Wed, 10 Sep 2025 20:43:08 +0000 James Morse <[email protected]> wrote:
The bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by James Morse <[email protected]>
Few trivial comments inline.
Quoted 12 lines
--- drivers/resctrl/Kconfig | 10 +++++ drivers/resctrl/mpam_devices.c | 4 ++ drivers/resctrl/test_mpam_devices.c | 68 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 drivers/resctrl/test_mpam_devices.cdrivers/resctrl/Kconfig +0
-0
drivers/resctrl/Kconfig menuconfig ARM64_MPAM_DRIVER · line 11
Quoted 7 lines
drivers/resctrl/Kconfig +1
-0@@ -5,10 +5,20 @@ menuconfig ARM64_MPAM_DRIVER MPAM driver for System IP, e,g. caches and memory controllers. if ARM64_MPAM_DRIVER + config ARM64_MPAM_DRIVER_DEBUG bool "Enable debug messages from the MPAM driver" depends on ARM64_MPAM_DRIVER
Doing this under an if for the same isn't useful. So if you want to do this style I'd do it before adding this earlier config option.
Quoted 20 lines
drivers/resctrl/Kconfig +9
-0help Say yes here to enable debug messages from the MPAM driver. +config MPAM_KUNIT_TEST + bool "KUnit tests for MPAM driver " if !KUNIT_ALL_TESTS + depends on KUNIT=y + default KUNIT_ALL_TESTS + help + Enable this option to run tests in the MPAM driver. + + If unsure, say N. + endifdrivers/resctrl/test_mpam_devices.c new file +0
-0
drivers/resctrl/test_mpam_devices.c line 10
Quoted 10 lines
drivers/resctrl/test_mpam_devices.c new file +10
-0@@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2024 Arm Ltd. +/* This file is intended to be included into mpam_devices.c */ + +#include <kunit/test.h> + +static void test_mpam_reset_msc_bitmap (struct kunit *test) +{ +char __iomem *buf =kunit_kzalloc (test,SZ_16K ,GFP_KERNEL ); +struct mpam_msc fake_msc = {0 };
= { }; is sufficient and what newer c specs have adopted to mean fill everything including holes in structures with 0. There are some tests that ensure that behavior applies with older compilers + the options we use for building the kernel.
drivers/resctrl/test_mpam_devices.c line 21
Quoted 11 lines
drivers/resctrl/test_mpam_devices.c new file +11
-0+u32 *test_result; + +if (!buf) +return ; + + fake_msc.mapped_hwpage = buf; + fake_msc.mapped_hwpage_sz =SZ_16K ; +cpumask_copy (&fake_msc.accessibility, cpu_possible_mask); + +mutex_init (&fake_msc.part_sel_lock); +mutex_lock (&fake_msc.part_sel_lock);
Perhaps add a comment to say this is to satisfy lock markings? Otherwise someone might wonder why mutex_init() immediately followed by taking the lock maskes sense.
Quoted 35 lines
drivers/resctrl/test_mpam_devices.c new file +35
-0+ + test_result = (u32 *)(buf +MPAMCFG_CPBM ); + +mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,0 ); +KUNIT_EXPECT_EQ (test, test_result[0 ],0 ); +KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); + test_result[0 ] =0 ; + test_result[1 ] =0 ; + +mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,1 ); +KUNIT_EXPECT_EQ (test, test_result[0 ],1 ); +KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); + test_result[0 ] =0 ; + test_result[1 ] =0 ; + +mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,16 ); +KUNIT_EXPECT_EQ (test, test_result[0 ],0xffff ); +KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); + test_result[0 ] =0 ; + test_result[1 ] =0 ; + +mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,32 ); +KUNIT_EXPECT_EQ (test, test_result[0 ],0xffffffff ); +KUNIT_EXPECT_EQ (test, test_result[1 ],0 ); + test_result[0 ] =0 ; + test_result[1 ] =0 ; + +mpam_reset_msc_bitmap (&fake_msc,MPAMCFG_CPBM ,33 ); +KUNIT_EXPECT_EQ (test, test_result[0 ],0xffffffff ); +KUNIT_EXPECT_EQ (test, test_result[1 ],1 ); + test_result[0 ] =0 ; + test_result[1 ] =0 ; + +mutex_unlock (&fake_msc.part_sel_lock); +}
James Morse
maintainerRe: [PATCH v2 28/29] arm_mpam: Add kunit test for bitmap reset
Hi Jonathan,
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Wed, 10 Sep 2025 20:43:08 +0000 James Morse <[email protected]> wrote:
The bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
Quoted 7 lines
Quoted 2 lines
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by James Morse <[email protected]>Few trivial comments inline.
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 7 lines
Quoted 7 lines
drivers/resctrl/Kconfig +0
-0@@ -5,10 +5,20 @@ menuconfig ARM64_MPAM_DRIVER MPAM driver for System IP, e,g. caches and memory controllers.
Quoted 8 lines
drivers/resctrl/Kconfig menuconfig ARM64_MPAM_DRIVER · line 11
Quoted 5 lines
drivers/resctrl/Kconfig +1
-0if ARM64_MPAM_DRIVER + config ARM64_MPAM_DRIVER_DEBUG bool "Enable debug messages from the MPAM driver" depends on ARM64_MPAM_DRIVERDoing this under an if for the same isn't useful. So if you want to do this style I'd do it before adding this earlier config option.
Yup, you pointed at the this same shape of bug earlier in the series.
Quoted 27 lines
Quoted 27 lines
drivers/resctrl/Kconfig +9
-0help Say yes here to enable debug messages from the MPAM driver. +config MPAM_KUNIT_TEST + bool "KUnit tests for MPAM driver " if !KUNIT_ALL_TESTS + depends on KUNIT=y + default KUNIT_ALL_TESTS + help + Enable this option to run tests in the MPAM driver. + + If unsure, say N. + endifdrivers/resctrl/test_mpam_devices.c new file +7
-0@@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2024 Arm Ltd. +/* This file is intended to be included into mpam_devices.c */ + +#include <kunit/test.h> + +static void test_mpam_reset_msc_bitmap (struct kunit *test)
Quoted 8 lines
drivers/resctrl/test_mpam_devices.c line 10
Quoted 3 lines
drivers/resctrl/test_mpam_devices.c new file +3
-0+{ +char __iomem *buf =kunit_kzalloc (test,SZ_16K ,GFP_KERNEL ); +struct mpam_msc fake_msc = {0 };= { }; is sufficient and what newer c specs have adopted to mean fill everything including holes in structures with 0. There are some tests that ensure that behavior applies with older compilers + the options we use for building the kernel.
Muscle memory is difficult to overcome ... I've fixed this one, and will keep an eye out for more.
Quoted 7 lines
Quoted 7 lines
drivers/resctrl/test_mpam_devices.c new file +7
-0+u32 *test_result; + +if (!buf) +return ; + + fake_msc.mapped_hwpage = buf; + fake_msc.mapped_hwpage_sz =SZ_16K ;
Quoted 8 lines
drivers/resctrl/test_mpam_devices.c line 21
Quoted 4 lines
drivers/resctrl/test_mpam_devices.c new file +4
-0+cpumask_copy (&fake_msc.accessibility, cpu_possible_mask); + +mutex_init (&fake_msc.part_sel_lock); +mutex_lock (&fake_msc.part_sel_lock);Perhaps add a comment to say this is to satisfy lock markings? Otherwise someone might wonder why
mutex_init()immediately followed by taking the lock maskes sense.
Makes sense, Done.
Quoted 2 lines
drivers/resctrl/test_mpam_devices.c line 23
Quoted 2 lines
drivers/resctrl/test_mpam_devices.c new file +2
-0+ + test_result = (u32 *)(buf +MPAMCFG_CPBM );
Thanks,
James
Re: [PATCH v2 28/29] arm_mpam: Add kunit test for bitmap reset
In reply to James MorseHi James,
Quoted 19 lines · James Morse
The bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by James Morse <[email protected]>--- drivers/resctrl/Kconfig | 10 +++++ drivers/resctrl/mpam_devices.c | 4 ++ drivers/resctrl/test_mpam_devices.c | 68 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 drivers/resctrl/test_mpam_devices.cdrivers/resctrl/Kconfig +0
-0
drivers/resctrl/Kconfig menuconfig ARM64_MPAM_DRIVER · line 8
Quoted 4 lines
drivers/resctrl/Kconfig +1
-0@@ -5,10 +5,20 @@ menuconfig ARM64_MPAM_DRIVER MPAM driver for System IP, e,g. caches and memory controllers. if ARM64_MPAM_DRIVER +
Nit: add the empty line in an earlier patch
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 28/29] arm_mpam: Add kunit test for bitmap reset
Hi Ben,
Quoted 13 lines · Ben Horgan
Quoted 12 lines · James Morse
The bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
drivers/resctrl/Kconfig +0
-0@@ -5,10 +5,20 @@ menuconfig ARM64_MPAM_DRIVER MPAM driver for System IP, e,g. caches and memory controllers.
Quoted 4 lines
drivers/resctrl/Kconfig menuconfig ARM64_MPAM_DRIVER · line 8
Quoted 2 lines
drivers/resctrl/Kconfig +1
-0if ARM64_MPAM_DRIVER +Nit: add the empty line in an earlier patch
Fixed,
Quoted 1 line
Reviewed-by Ben Horgan <[email protected]>
Thanks!
James
Re: [PATCH v2 28/29] arm_mpam: Add kunit test for bitmap reset
In reply to James MorseQuoted 7 lines · James Morse
The bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by James Morse <[email protected]>
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 28/29] arm_mpam: Add kunit test for bitmap reset
Hi Fenghua,
Quoted 10 lines · Fenghua Yu
Quoted 7 lines · James Morse
The bitmap reset code has been a source of bugs. Add a unit test.
This currently has to be built in, as the rest of the driver is builtin.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by James Morse <[email protected]>Reviewed-by Fenghua Yu <[email protected]>
Thanks!
James
James Morse
maintainerPATCH v2 29/29 arm_mpam: Add kunit tests for props_mismatch()
In reply to James MorseWhen features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
---
Changes since v1:
* Waggled some words in comments.
* Moved a bunch of variables to be global - shuts up a compiler warning.
--- drivers/resctrl/mpam_internal.h | 8 +- drivers/resctrl/test_mpam_devices.c | 321 ++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_internal.h +7 -1
@@ -20,6 +20,12 @@DECLARE_STATIC_KEY_FALSE (mpam_enabled); +#ifdef CONFIG_MPAM_KUNIT_TEST +#define PACKED_FOR_KUNIT __packed +#else +#define PACKED_FOR_KUNIT +#endif +static inline bool mpam_is_enabled (void ) {return static_branch_likely (&mpam_enabled);
@@ -189,7 +195,7 @@ struct mpam_props {u16 dspri_wd;u16 num_csu_mon;u16 num_mbwu_mon; -}; +}PACKED_FOR_KUNIT ;#define mpam_has_feature (_feat, x) ((1 << (_feat)) & (x)->features)
drivers/resctrl/test_mpam_devices.c +321 -0
333 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH v2 29/29] arm_mpam: Add kunit tests for props_mismatch()
Quoted 7 lines · On Wed, 10 Sep 2025 20:43:09 +0000 James Morse <[email protected]> wrote:
When features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
Signed-off-by James Morse <[email protected]>
Nice in general though I didn't go through the test expected results etc. A few comments inline.
Thanks and looking forward to seeing this go in.
Jonathan
Quoted 27 lines
---
Changes since v1:
* Waggled some words in comments.
* Moved a bunch of variables to be global - shuts up a compiler warning.--- drivers/resctrl/mpam_internal.h | 8 +- drivers/resctrl/test_mpam_devices.c | 321 ++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 1 deletion(-)drivers/resctrl/mpam_internal.h +6
-0@@ -20,6 +20,12 @@DECLARE_STATIC_KEY_FALSE (mpam_enabled); +#ifdef CONFIG_MPAM_KUNIT_TEST +#define PACKED_FOR_KUNIT __packed +#else +#define PACKED_FOR_KUNIT +#endif +static inline bool mpam_is_enabled (void ) {return static_branch_likely (&mpam_enabled);
drivers/resctrl/mpam_internal.h struct mpam_props { · line 198
Quoted 5 lines
drivers/resctrl/mpam_internal.h +1
-1@@ -189,7 +195,7 @@ struct mpam_props {u16 dspri_wd;u16 num_csu_mon;u16 num_mbwu_mon; -}; +}PACKED_FOR_KUNIT ;
Add a comment on 'why'.
Quoted 40 lines
drivers/resctrl/mpam_internal.h +0
-0#define mpam_has_feature (_feat, x) ((1 << (_feat)) & (x)->features)drivers/resctrl/test_mpam_devices.c +29
-0@@ -4,6 +4,325 @@#include <kunit/test.h> +/* +* This test catches fields that aren't being sanitised - but can't tell you +* which one... +*/ +static void test__props_mismatch (struct kunit *test) +{ +struct mpam_props parent = {0 }; +struct mpam_props child; + +memset (&child,0xff ,sizeof (child)); +__props_mismatch (&parent, &child, false); + +memset (&child,0 ,sizeof (child)); +KUNIT_EXPECT_EQ (test,memcmp (&parent, &child,sizeof (child)),0 ); + +memset (&child,0xff ,sizeof (child)); +__props_mismatch (&parent, &child, true); + +KUNIT_EXPECT_EQ (test,memcmp (&parent, &child,sizeof (child)),0 ); +} + +static struct list_head fake_classes_list; +static struct mpam_class fake_class = {0 }; +static struct mpam_component fake_comp1 = {0 }; +static struct mpam_component fake_comp2 = {0 }; +static struct mpam_vmsc fake_vmsc1 = {0 }; +static struct mpam_vmsc fake_vmsc2 = {0 }; +static struct mpam_msc fake_msc1 = {0 }; +static struct mpam_msc fake_msc2 = {0 };
drivers/resctrl/test_mpam_devices.c line 45
Quoted 10 lines
drivers/resctrl/test_mpam_devices.c +10
-0+static struct mpam_msc_ris fake_ris1 = {0 }; +static struct mpam_msc_ris fake_ris2 = {0 }; +static struct platform_device fake_pdev = {0 }; + +static void test_mpam_enable_merge_features (struct kunit *test) +{ +#define RESET_FAKE_HIEARCHY () do { \ + INIT_LIST_HEAD(&fake_classes_list); \ + \ + memset(&fake_class, 0, sizeof(fake_class)); \
Maybe just use a function? Seems to be changing stuff that is global mostly anyway so seems like it won't need large numbers of parameters or anything like that.
Quoted 63 lines
drivers/resctrl/test_mpam_devices.c +63
-0+ fake_class.level =3 ; \ + fake_class.type =MPAM_CLASS_CACHE ; \ +INIT_LIST_HEAD_RCU (&fake_class.components); \ +INIT_LIST_HEAD (&fake_class.classes_list); \ + \ +memset (&fake_comp1,0 ,sizeof (fake_comp1)); \ +memset (&fake_comp2,0 ,sizeof (fake_comp2)); \ + fake_comp1.comp_id =1 ; \ + fake_comp2.comp_id =2 ; \ +INIT_LIST_HEAD (&fake_comp1.vmsc); \ +INIT_LIST_HEAD (&fake_comp1.class_list); \ +INIT_LIST_HEAD (&fake_comp2.vmsc); \ +INIT_LIST_HEAD (&fake_comp2.class_list); \ + \ +memset (&fake_vmsc1,0 ,sizeof (fake_vmsc1)); \ +memset (&fake_vmsc2,0 ,sizeof (fake_vmsc2)); \ +INIT_LIST_HEAD (&fake_vmsc1.ris); \ +INIT_LIST_HEAD (&fake_vmsc1.comp_list); \ + fake_vmsc1.msc = &fake_msc1; \ +INIT_LIST_HEAD (&fake_vmsc2.ris); \ +INIT_LIST_HEAD (&fake_vmsc2.comp_list); \ + fake_vmsc2.msc = &fake_msc2; \ + \ +memset (&fake_ris1,0 ,sizeof (fake_ris1)); \ +memset (&fake_ris2,0 ,sizeof (fake_ris2)); \ + fake_ris1.ris_idx =1 ; \ +INIT_LIST_HEAD (&fake_ris1.msc_list); \ + fake_ris2.ris_idx =2 ; \ +INIT_LIST_HEAD (&fake_ris2.msc_list); \ + \ + fake_msc1.pdev = &fake_pdev; \ + fake_msc2.pdev = &fake_pdev; \ + \ +list_add (&fake_class.classes_list, &fake_classes_list); \ +}while (0 ) + +RESET_FAKE_HIEARCHY (); + +mutex_lock (&mpam_list_lock); + +/* One Class+Comp, two RIS in one vMSC with common features */ + fake_comp1.class = &fake_class; +list_add (&fake_comp1.class_list, &fake_class.components); + fake_comp2.class =NULL ; + fake_vmsc1.comp = &fake_comp1; +list_add (&fake_vmsc1.comp_list, &fake_comp1.vmsc); + fake_vmsc2.comp =NULL ; + fake_ris1.vmsc = &fake_vmsc1; +list_add (&fake_ris1.vmsc_list, &fake_vmsc1.ris); + fake_ris2.vmsc = &fake_vmsc1; +list_add (&fake_ris2.vmsc_list, &fake_vmsc1.ris); + +mpam_set_feature (mpam_feat_cpor_part, &fake_ris1.props); +mpam_set_feature (mpam_feat_cpor_part, &fake_ris2.props); + fake_ris1.props.cpbm_wd =4 ; + fake_ris2.props.cpbm_wd =4 ; + +mpam_enable_merge_features (&fake_classes_list); + +KUNIT_EXPECT_TRUE (test,mpam_has_feature (mpam_feat_cpor_part, &fake_class.props)); +KUNIT_EXPECT_EQ (test, fake_class.props.cpbm_wd,4 ); + +RESET_FAKE_HIEARCHY ();
James Morse
maintainerRe: [PATCH v2 29/29] arm_mpam: Add kunit tests for props_mismatch()
Hi Jonathan,
Quoted 18 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 10 Sep 2025 20:43:09 +0000 James Morse <[email protected]> wrote:
When features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
Signed-off-by James Morse <[email protected]>Nice in general though I didn't go through the test expected results etc.
A few comments inline.
Thanks and looking forward to seeing this go in.
Quoted 12 lines
drivers/resctrl/mpam_internal.h struct mpam_props { · line 198
Quoted 10 lines
drivers/resctrl/mpam_internal.h +1
-1@@ -189,7 +195,7 @@ struct mpam_props {u16 dspri_wd;u16 num_csu_mon;u16 num_mbwu_mon; -}; +}PACKED_FOR_KUNIT ;Add a comment on 'why'.
| * Kunit tests use memset() to set up feature combinations that should be | * removed, and will false-positive if the compiler introduces padding that | * isn't cleared during sanitisation.
Quoted 43 lines
Quoted 43 lines
drivers/resctrl/test_mpam_devices.c +35
-0@@ -4,6 +4,325 @@#include <kunit/test.h> +/* +* This test catches fields that aren't being sanitised - but can't tell you +* which one... +*/ +static void test__props_mismatch (struct kunit *test) +{ +struct mpam_props parent = {0 }; +struct mpam_props child; + +memset (&child,0xff ,sizeof (child)); +__props_mismatch (&parent, &child, false); + +memset (&child,0 ,sizeof (child)); +KUNIT_EXPECT_EQ (test,memcmp (&parent, &child,sizeof (child)),0 ); + +memset (&child,0xff ,sizeof (child)); +__props_mismatch (&parent, &child, true); + +KUNIT_EXPECT_EQ (test,memcmp (&parent, &child,sizeof (child)),0 ); +} + +static struct list_head fake_classes_list; +static struct mpam_class fake_class = {0 }; +static struct mpam_component fake_comp1 = {0 }; +static struct mpam_component fake_comp2 = {0 }; +static struct mpam_vmsc fake_vmsc1 = {0 }; +static struct mpam_vmsc fake_vmsc2 = {0 }; +static struct mpam_msc fake_msc1 = {0 }; +static struct mpam_msc fake_msc2 = {0 }; +static struct mpam_msc_ris fake_ris1 = {0 }; +static struct mpam_msc_ris fake_ris2 = {0 }; +static struct platform_device fake_pdev = {0 }; + +static void test_mpam_enable_merge_features (struct kunit *test) +{
Quoted 8 lines
drivers/resctrl/test_mpam_devices.c line 45
Quoted 4 lines
drivers/resctrl/test_mpam_devices.c +4
-0+#define RESET_FAKE_HIEARCHY () do { \ + INIT_LIST_HEAD(&fake_classes_list); \ + \ + memset(&fake_class, 0, sizeof(fake_class)); \Maybe just use a function? Seems to be changing stuff that is global mostly anyway so seems like it won't need large numbers of parameters or anything like that.
Sure - it only became global in v3.
Thanks,
James
Re: [PATCH v2 29/29] arm_mpam: Add kunit tests for props_mismatch()
In reply to James MorseHi James,
Quoted 7 lines · James Morse
When features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
Signed-off-by James Morse <[email protected]>
Quoted 9 lines
---
Changes since v1:
* Waggled some words in comments.
* Moved a bunch of variables to be global - shuts up a compiler warning.--- drivers/resctrl/mpam_internal.h | 8 +- drivers/resctrl/test_mpam_devices.c | 321 ++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 1 deletion(-)
Looks good to me, I checked the tests for v1. I agree with Jonathan that you could make RESET_FAKE_HIEARCHY() a function now that you've changed to use globals.
Thanks,
Ben
James Morse
maintainerRe: [PATCH v2 29/29] arm_mpam: Add kunit tests for props_mismatch()
Hi Ben,
Quoted 8 lines · Ben Horgan
Quoted 5 lines · James Morse
When features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
Quoted 5 lines
Looks good to me, I checked the tests for v1. I agree with Jonathan that you could make
RESET_FAKE_HIEARCHY()a function now that you've changed to use globals.Reviewed-by Ben Horgan <[email protected]>
Thanks!
James
Re: [PATCH v2 29/29] arm_mpam: Add kunit tests for props_mismatch()
In reply to James MorseQuoted 7 lines · James Morse
When features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
Signed-off-by James Morse <[email protected]>
Thanks.
-Fenghua
James Morse
maintainerRe: [PATCH v2 29/29] arm_mpam: Add kunit tests for props_mismatch()
Hi Fenghua,
Quoted 10 lines · Fenghua Yu
Quoted 7 lines · James Morse
When features are mismatched between MSC the way features are combined to the class determines whether resctrl can support this SoC.
Add some tests to illustrate the sort of thing that is expected to work, and those that must be removed.
Signed-off-by James Morse <[email protected]>Reviewed-by Fenghua Yu <[email protected]>
Thanks!
James
Quoted 35 lines · James Morse
Hello,
The major changes since v1 are:
* DT got ripped out - see below.
* Themon_sellocking was simplified - but that will come back.Otherwise the myriad of changes are noted on each patch.
~
This is just enough MPAM driver for ACPI. DT got ripped out. If you need DT support - please share your DTS so the DT folk know the binding is what is needed.
This doesn't contain any of the resctrl code, meaning you can't actually drive it from user-space yet. Becuase of that, its hidden behindCONFIG_EXPERT. This will change once the user interface is connected up.This is the initial group of patches that allows the resctrl code to be built on top. Including that will increase the number of trees that may need to coordinate, so breaking it up make sense.
The locking got simplified, but is still strange - this is because of the 'mpam-fb' firmware interface specification that is still alpha. That thing needs to wait for an interrupt after every system register write, which significantly impacts the driver. Some features just won't work, e.g. reading the monitor registers via perf.
I've not found a platform that can test all the behaviours around the monitors, so this is where I'd expect the most bugs.
The MPAM spec that describes all the system and MMIO registers can be found here:
https://developer.arm.com/documentation/ddi0598/db/?lang=en
(Ignored the 'RETIRED' warning - that is just arm moving the documentation around.
This document has the best overview)
Quoted 8 lines
The expectation is this will go via the arm64 tree.
This series is based on v6.17-rc4, and can be retrieved from:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/driver/v2The rest of the driver can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/snapshot/v6.17-rc4
[SNIP]
Thanks.
-Fenghua