arm_mpam: Add basic mpam driver
Subsystems (4)
Re: [PATCH v3 26/29] arm_mpam: Use long MBWU counters if supported
In reply to Ben HorganHi Ben
Quoted 173 lines · Ben Horgan
Hi Peter,
Quoted 155 lines · Peter Newman
Hi Ben (and James),
Quoted 127 lines · James Morse
From: Rohit Mathew <[email protected]>
Now that the larger counter sizes are probed, make use of them.
Callers of
mpam_msmon_read()may not know (or care!) about the different counter sizes. Allow them to specifympam_feat_msmon_mbwuand have the driver pick the counter to use.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.
Signed-off-by Rohit Mathew <[email protected]>[morse: merged multiple patches from Rohit, added explicit counter selection ]Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Fenghua Yu <[email protected]>Tested-by Fenghua Yu <[email protected]>---
Changes since v2:
* Removedmpam_feat_msmon_mbwuas a top-level bit for explicit 31bit counter selection.
* Allow callers ofmpam_msmon_read()to specifympam_feat_msmon_mbwuand have the driver pick a supported counter size.
* Rephrased commit message.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 | 134 ++++++++++++++++++++++++++++----- 1 file changed, 116 insertions(+), 18 deletions(-)drivers/resctrl/mpam_devices.c +51
-2@@ -897,6 +897,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) {@@ -924,7 +966,9 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, ctx->csu_exclude_clean);break ; -case mpam_feat_msmon_mbwu: +case mpam_feat_msmon_mbwu_31counter: +case mpam_feat_msmon_mbwu_44counter: +case mpam_feat_msmon_mbwu_63counter: *ctl_val |=MSMON_CFG_MBWU_CTL_TYPE_MBWU ;if (mpam_has_feature (mpam_feat_msmon_mbwu_rwbw, &m->ris->props))@@ -946,7 +990,9 @@ static void read_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, *ctl_val =mpam_read_monsel_reg (msc,CFG_CSU_CTL ); *flt_val =mpam_read_monsel_reg (msc,CFG_CSU_FLT );return ; -case mpam_feat_msmon_mbwu: +case mpam_feat_msmon_mbwu_31counter: +case mpam_feat_msmon_mbwu_44counter: +case mpam_feat_msmon_mbwu_63counter: *ctl_val =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); *flt_val =mpam_read_monsel_reg (msc,CFG_MBWU_FLT );return ;@@ -959,6 +1005,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,@@ -978,10 +1027,15 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,mpam_write_monsel_reg (msc,CSU ,0 );mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN);drivers/resctrl/mpam_devices.c static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val, · line 1037
Quoted 10 lines
drivers/resctrl/mpam_devices.c +5
-1break ; -case mpam_feat_msmon_mbwu: +case mpam_feat_msmon_mbwu_44counter: +case mpam_feat_msmon_mbwu_63counter: +mpam_msc_zero_mbwu_l (m->ris->vmsc->msc); + fallthrough; +case mpam_feat_msmon_mbwu_31counter: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 );The fallthrough above seems to be problematic, assuming the MBWU=0 being last for 31-bit was intentional. For long counters, this is zeroing the counter before updating the filter/control registers, but then clearing the 32-bit version of the counter. This fails to clear the NRDY bit on the long counter, which isn't cleared by software anywhere else.
From section 10.3.2 from the MPAM spec shared:
"On a counting monitor, the NRDY bit remains set until it is reset by
software writing it as 0 in the monitor register, or automatically after the monitor is captured in the capture register by a capture event"Quoted 8 lines
If I update the 63-bit case to call
mpam_msc_zero_mbwu_l(m->ris->vmsc->msc)after updating the control/filter registers (in addition to the other items I pointed in my last reply), I'm able to read MBWU counts from my hardware throughmbm_total_bytes.Thanks,
-PeterThanks for the testing and flagging the problem. We should do the configuration in the same order for all the monitors.
I'll change the case to:
Quoted 13 lines
case mpam_feat_msmon_mbwu_31counter:
case mpam_feat_msmon_mbwu_44counter:
case mpam_feat_msmon_mbwu_63counter:
mpam_write_monsel_reg(msc, CFG_MBWU_FLT, flt_val);
mpam_write_monsel_reg(msc, CFG_MBWU_CTL, ctl_val);
if (m->type == mpam_feat_msmon_mbwu_31counter)
mpam_write_monsel_reg(msc, MBWU, 0);
else
mpam_msc_zero_mbwu_l(m->ris->vmsc->msc);
mpam_write_monsel_reg(msc, CFG_MBWU_CTL, ctl_val | MSMON_CFG_x_CTL_EN);
break;I tried this out but wasn't able to read the counters. I needed to move the MBWU[_L] write to the end. Writing the registers directly on the hardware I'm testing with, I confirmed that just flipping MBWU_CTL.EN sets NRDY:
MBWU_L=0x880
MBWU_CTL=0x828
/ # mmio_read32 $((msc + MBWU_CTL))0x80030042
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x03ecb2c00x00000000
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x03f705800x00000000
Clear MBWU_CTL.EN:
/ # mmio_write32 $((msc + MBWU_CTL)) 0x00030042
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x050046800x80000000
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x050046800x80000000
Clear NRDY and reenable MBWU_CTL.EN:
/ # mmio_write32 $((msc + MBWU_L)) 0; mmio_write32 $((msc + MBWU_L + 4)) 0 / # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x000000000x00000000
/ # mmio_write32 $((msc + MBWU_CTL)) 0x80030042
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x001dee800x80000000
In fact, re-writing the same value back into MBWU_CTL.EN also sets NRDY:
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x00253e000x00000000
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x00b1a6c00x00000000
/ # mmio_write32 $((msc + MBWU_CTL)) 0x80030042
/ # mmio_read32 $((msc + MBWU_L)); mmio_read32 $((msc + MBWU_L + 4))0x018d1d400x80000000
Thanks,
-Peter
Ben Horgan
maintainerRe: [PATCH v3 26/29] arm_mpam: Use long MBWU counters if supported
Hi Peter,
Quoted 241 lines · Peter Newman
Hi Ben
Quoted 173 lines · Ben Horgan
Hi Peter,
Quoted 155 lines · Peter Newman
Hi Ben (and James),
Quoted 127 lines · James Morse
From: Rohit Mathew <[email protected]>
Now that the larger counter sizes are probed, make use of them.
Callers of
mpam_msmon_read()may not know (or care!) about the different counter sizes. Allow them to specifympam_feat_msmon_mbwuand have the driver pick the counter to use.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.
Signed-off-by Rohit Mathew <[email protected]>[morse: merged multiple patches from Rohit, added explicit counter selection ]Signed-off-by James Morse <[email protected]>Reviewed-by Ben Horgan <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Fenghua Yu <[email protected]>Tested-by Fenghua Yu <[email protected]>---
Changes since v2:
* Removedmpam_feat_msmon_mbwuas a top-level bit for explicit 31bit counter selection.
* Allow callers ofmpam_msmon_read()to specifympam_feat_msmon_mbwuand have the driver pick a supported counter size.
* Rephrased commit message.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 | 134 ++++++++++++++++++++++++++++----- 1 file changed, 116 insertions(+), 18 deletions(-)drivers/resctrl/mpam_devices.c +51
-2@@ -897,6 +897,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) {@@ -924,7 +966,9 @@ static void gen_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, ctx->csu_exclude_clean);break ; -case mpam_feat_msmon_mbwu: +case mpam_feat_msmon_mbwu_31counter: +case mpam_feat_msmon_mbwu_44counter: +case mpam_feat_msmon_mbwu_63counter: *ctl_val |=MSMON_CFG_MBWU_CTL_TYPE_MBWU ;if (mpam_has_feature (mpam_feat_msmon_mbwu_rwbw, &m->ris->props))@@ -946,7 +990,9 @@ static void read_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, *ctl_val =mpam_read_monsel_reg (msc,CFG_CSU_CTL ); *flt_val =mpam_read_monsel_reg (msc,CFG_CSU_FLT );return ; -case mpam_feat_msmon_mbwu: +case mpam_feat_msmon_mbwu_31counter: +case mpam_feat_msmon_mbwu_44counter: +case mpam_feat_msmon_mbwu_63counter: *ctl_val =mpam_read_monsel_reg (msc,CFG_MBWU_CTL ); *flt_val =mpam_read_monsel_reg (msc,CFG_MBWU_FLT );return ;@@ -959,6 +1005,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,@@ -978,10 +1027,15 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,mpam_write_monsel_reg (msc,CSU ,0 );mpam_write_monsel_reg (msc,CFG_CSU_CTL , ctl_val | MSMON_CFG_x_CTL_EN);drivers/resctrl/mpam_devices.c static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val, · line 1037
Quoted 10 lines
drivers/resctrl/mpam_devices.c +5
-1break ; -case mpam_feat_msmon_mbwu: +case mpam_feat_msmon_mbwu_44counter: +case mpam_feat_msmon_mbwu_63counter: +mpam_msc_zero_mbwu_l (m->ris->vmsc->msc); + fallthrough; +case mpam_feat_msmon_mbwu_31counter: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 );The fallthrough above seems to be problematic, assuming the MBWU=0 being last for 31-bit was intentional. For long counters, this is zeroing the counter before updating the filter/control registers, but then clearing the 32-bit version of the counter. This fails to clear the NRDY bit on the long counter, which isn't cleared by software anywhere else.
From section 10.3.2 from the MPAM spec shared:
"On a counting monitor, the NRDY bit remains set until it is reset by
software writing it as 0 in the monitor register, or automatically after the monitor is captured in the capture register by a capture event"Quoted 8 lines
If I update the 63-bit case to call
mpam_msc_zero_mbwu_l(m->ris->vmsc->msc)after updating the control/filter registers (in addition to the other items I pointed in my last reply), I'm able to read MBWU counts from my hardware throughmbm_total_bytes.Thanks,
-PeterThanks for the testing and flagging the problem. We should do the configuration in the same order for all the monitors.
I'll change the case to:
Quoted 13 lines
case mpam_feat_msmon_mbwu_31counter: case mpam_feat_msmon_mbwu_44counter: case mpam_feat_msmon_mbwu_63counter: mpam_write_monsel_reg(msc, CFG_MBWU_FLT, flt_val); mpam_write_monsel_reg(msc, CFG_MBWU_CTL, ctl_val); if (m->type == mpam_feat_msmon_mbwu_31counter) mpam_write_monsel_reg(msc, MBWU, 0); else mpam_msc_zero_mbwu_l(m->ris->vmsc->msc); mpam_write_monsel_reg(msc, CFG_MBWU_CTL, ctl_val | MSMON_CFG_x_CTL_EN); break;I tried this out but wasn't able to read the counters. I needed to move the MBWU[_L] write to the end. Writing the registers directly on the hardware I'm testing with, I confirmed that just flipping MBWU_CTL.EN sets NRDY:
MBWU_L=0x880
MBWU_CTL=0x828/ #
mmio_read32$((msc +MBWU_CTL))0x80030042
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x03ecb2c00x00000000
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x03f705800x00000000Clear MBWU_CTL.EN:
/ #
mmio_write32$((msc +MBWU_CTL))0x00030042
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x050046800x80000000
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x050046800x80000000Clear NRDY and reenable MBWU_CTL.EN:
/ #
mmio_write32$((msc +MBWU_L)) 0;mmio_write32$((msc +MBWU_L+ 4)) 0 / #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x000000000x00000000
/ #mmio_write32$((msc +MBWU_CTL))0x80030042
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x001dee800x80000000In fact, re-writing the same value back into MBWU_CTL.EN also sets NRDY:
/ #
mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x00253e000x00000000
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x00b1a6c00x00000000
/ #mmio_write32$((msc +MBWU_CTL))0x80030042
/ #mmio_read32$((msc +MBWU_L));mmio_read32$((msc +MBWU_L+ 4))0x018d1d400x80000000
Quoted 2 lines
Thanks,
-Peter
Thank you very much for the quick testing and diagnosis. It does seeem reasonable that the .EN flip would be considered a configuration change and so indeed the writing NRDY (and the value) should happend after for counting monitors (mbwu). I'll make this change now.
Thanks,
Ben
James Morse
maintainerPATCH v3 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.
---
Changes since v2:
* Switched to guard and fixed non _srcu list walker.
* Made a comment about what is proteted by which lock a list.
--- drivers/resctrl/mpam_devices.c | 46 ++++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 7 ++++- 2 files changed, 51 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_devices.c +45 -1
@@ -1066,9 +1066,11 @@ static u64 mpam_msmon_overflow_val(enum mpam_device_features type)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;
@@ -1083,6 +1085,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.
@@ -1090,7 +1100,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) {
@@ -1242,6 +1255,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) +{ +struct mpam_msc *msc; +struct mpam_vmsc *vmsc; +struct mpam_msc_ris *ris; + +if (!mpam_is_enabled ()) +return ; + +guard (srcu)(&mpam_srcu); +list_for_each_entry_srcu (vmsc, &comp->vmsc, comp_list, +srcu_read_lock_held (&mpam_srcu)) { +if (!mpam_has_feature (mpam_feat_msmon_mbwu, &vmsc->props)) +continue ; + + msc = vmsc->msc; +list_for_each_entry_srcu (ris, &vmsc->ris, vmsc_list, +srcu_read_lock_held (&mpam_srcu)) { +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); + } + } +} +static void mpam_reset_msc_bitmap (struct mpam_msc *msc,u16 reg,u16 wd) {u32 num_words, msb;
drivers/resctrl/mpam_internal.h +6 -1
@@ -204,10 +204,14 @@ 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. +* The msc's mon_sel_lock protects: +* - reset_on_next_read +* - prev_val +* - correction */ 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. */
@@ -369,6 +373,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 v3 27/29] arm_mpam: Add helper to reset saved mbwu state
Quoted 11 lines · On Fri, 17 Oct 2025 18:56:43 +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]>Reviewed-by Fenghua Yu <[email protected]>Tested-by Fenghua Yu <[email protected]>
A couple of little places in here where I think moving things back to earlier patches would reduce churn a little which is always nice for reviewers.
Either way
Quoted 18 lines
---
Changes since v2:
* Switched to guard and fixed non_srculist walker.
* Made a comment about what is proteted by which lock a list.--- drivers/resctrl/mpam_devices.c | 46 ++++++++++++++++++++++++++++++++- drivers/resctrl/mpam_internal.h | 7 ++++- 2 files changed, 51 insertions(+), 2 deletions(-)drivers/resctrl/mpam_devices.c +0
-0/* * 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 1104
Quoted 6 lines
drivers/resctrl/mpam_devices.c +2
-1@@ -1090,7 +1100,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);
Push back to earlier patch perhaps? I guess someone might ask why you don't do it inline, but to me it seems complex enough that I doubt they will. Nice to reduce the churn where it is easy to do.
Quoted 15 lines
drivers/resctrl/mpam_devices.c +2
-0+ +if (config_mismatch || reset_on_next_read)write_msmon_ctl_flt_vals (m, ctl_val, flt_val);switch (m->type) {@@ -1242,6 +1255,37 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,return err; }drivers/resctrl/mpam_internal.h +0
-0
drivers/resctrl/mpam_internal.h struct mon_cfg { · line 207
Quoted 5 lines
drivers/resctrl/mpam_internal.h +1
-1@@ -204,10 +204,14 @@ 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. +* The msc's mon_sel_lock protects:
Nice to push this formatting change back to earlier patch so this becomes a one line change.
Quoted 8 lines
drivers/resctrl/mpam_internal.h +4
-0+* - reset_on_next_read +* - prev_val +* - correction */ struct msmon_mbwu_state {bool enabled; +bool reset_on_next_read;struct mon_cfg cfg;
RE: [PATCH v3 27/29] arm_mpam: Add helper to reset saved mbwu state
In reply to James MorseQuoted 11 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]>Reviewed-by Fenghua Yu <[email protected]>Tested-by Fenghua Yu <[email protected]>
James Morse
maintainerPATCH v3 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.
---
Changes from v2:
* Copyright year,
* Comment about lockdep checks,
* { } instead of { 0 }
* Removed a stray newline.
--- drivers/resctrl/Kconfig | 9 ++++ drivers/resctrl/mpam_devices.c | 4 ++ drivers/resctrl/test_mpam_devices.c | 69 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 drivers/resctrl/test_mpam_devices.c
drivers/resctrl/Kconfig +9 -0
@@ -10,4 +10,13 @@ config ARM64_MPAM_DRIVER_DEBUG 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
@@ -2695,3 +2695,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 +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.39.5
James Morse
maintainerPATCH v3 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 v2:
* Comment on why packing is only needed for kunit tests,
* Made the reset code a function not a macro.
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 | 14 +- drivers/resctrl/test_mpam_devices.c | 320 ++++++++++++++++++++++++++++ 2 files changed, 333 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_internal.h +13 -1
@@ -25,6 +25,12 @@ struct platform_device;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);
@@ -180,7 +186,13 @@ struct mpam_props {u16 dspri_wd;u16 num_csu_mon;u16 num_mbwu_mon; -}; + +/* +* 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. +*/ +}PACKED_FOR_KUNIT ;#define mpam_has_feature (_feat, x) test_bit(_feat, (x)->features)#define mpam_set_feature (_feat, x) set_bit(_feat, (x)->features)
drivers/resctrl/test_mpam_devices.c +320 -0
332 lines not on this page · raw message
Signature · 1 line
2.39.5
Fenghua Yu
reviewerQuoted 10 lines · James Morse
Hello,
A slew of minor changes, nothing really sticks out. 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.
[SNIP]
Quoted 8 lines
This series is based on v6.18-rc4, and can be retrieved from:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/driver/v3The rest of the driver can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/snapshot/v6.18-rc1What is MPAM? Set your time-machine to 2020:
https://lore.kernel.org/lkml/[email protected]/
In case you build/test the mpam/snapshot/v6.18-rc1 branch, need to apply the following patch. After applying this patch, this series and the rest of the drivers run successfully on my machine.
drivers/resctrl/mpam_internal.h +0 -0
@@ -645,6 +645,11 @@ static inline void
mpam_resctrl_teardown_class(struct mpam_class *class) { }
#define MPAMF_IIDR_VARIANT GENMASK(19, 16)
#define MPAMF_IIDR_PRODUCTID GENMASK(31, 20)
+#define MPAMF_IIDR_IMPLEMENTER_SHIFT 0
+#define MPAMF_IIDR_REVISION_SHIFT 12
+#define MPAMF_IIDR_VARIANT_SHIFT 16
+#define MPAMF_IIDR_PRODUCTID_SHIFT 20
+
/* MPAMF_AIDR - MPAM architecture ID register */
#define MPAMF_AIDR_ARCH_MINOR_REV GENMASK(3, 0)
#define MPAMF_AIDR_ARCH_MAJOR_REV GENMASK(7, 4)
[SNIP]
Thanks.
-Fenghua
Hello James,
Quoted 7 lines
This series is based on v6.18-rc4, and can be retrieved from:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/driver/v3The rest of the driver can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/snapshot/v6.18-rc1
This series(mpam/driver/v3) based on v6.18-rc1 and mpam driver(mpam/snapshot/v6.18-rc1) can not run on my machine(The cause is still unknown), But I applied this series and mpam driver on v6.18-rc2, they are run successfully.
However, I make a few minor fixes as follows:
1)
drivers/resctrl/mpam_internal.h +5 -0
@@ -645,6 +645,13 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }#define MPAMF_IIDR_VARIANT GENMASK(19, 16)#define MPAMF_IIDR_PRODUCTID GENMASK(31, 20) +#define MPAMF_IIDR_REVISON_SHIFT 12 +//#define MPAMF_IIDR_REVISION_SHIFT 12 +#define MPAMF_IIDR_IMPLEMENTER_SHIFT 0 +#define MPAMF_IIDR_VARIANT_SHIFT 16 +#define MPAMF_IIDR_PRODUCTID_SHIFT 20
or
#define IIDR_REV(x) ((x) << MPAMF_IIDR_REVISON_SHIFT)
s/MPAMF_IIDR_REVISON_SHIFT/MPAMF_IIDR_REVISION_SHIFT/
2)
drivers/resctrl/mpam_resctrl.c +2 -2
@@ -1113,9 +1118,9 @@ static void mpam_resctrl_pick_counters(void)update_rmid_limits (cache_size);counter_update_class (QOS_L3_OCCUP_EVENT_ID , class); -return ; +break ;default : -return ; +break ; } }
3)
when building this series(mpam/driver/v3),the EXPERT Kconfig option needs to be explicitly enabled. This aligns with Ben's observation in the following patch:
https://lore.kernel.org/lkml/[email protected]/
Best regards,
Shaopeng TAN
Hi James,
Quoted 115 lines · James Morse
Hello,
A slew of minor changes, nothing really sticks out. 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. Because 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)The expectation is this will go via the arm64 tree.
This series is based on v6.18-rc4, and can be retrieved from:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/driver/v3The rest of the driver can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/snapshot/v6.18-rc1What is MPAM? Set your time-machine to 2020:
https://lore.kernel.org/lkml/[email protected]/This series was previously posted here:
[v2] lore.kernel.org/r/[email protected] [v1] lore.kernel.org/r/[email protected] [RFC] lore.kernel.org/r/[email protected]James Morse (27):
ACPI / PPTT: Add a helper to fill a cpumask from a processor container ACPI / PPTT: Stopacpi_count_levels()expecting callers to clear
levels
ACPI / PPTT: Find cache level by cache-id
ACPI / PPTT: Add a helper to fill a cpumask from acache_id
arm64: kconfig: AddKconfigentry for MPAM
ACPI / MPAM: Parse the MPAM table
arm_mpam: Add probe/remove for mpam msc driver and kbuild boiler plate
arm_mpam: Add the class and component structures for firmware
described ris
arm_mpam: Add MPAM MSC register layout definitions
arm_mpam: Add cpuhp callbacks to probe MSC hardware
arm_mpam: Probe hardware to find the supported partid/pmg values
arm_mpam: Add helpers for managing the locking around themon_sel
registers
arm_mpam: Probe the hardware features resctrl supports
arm_mpam: Merge supported features duringmpam_enable()into
mpam_class
arm_mpam: Reset MSC controls from cpuhp callbacks
arm_mpam: Add a helper to touch an MSC from any CPU
arm_mpam: Extend reset logic to allow devices to be reset any time
arm_mpam: Register and enable IRQs
arm_mpam: Use a static key to indicate when mpam is enabled
arm_mpam: Allow configuration to be applied and restored during cpu
online
arm_mpam: Probe and reset the rest of the features
arm_mpam: Add helpers to allocate monitors
arm_mpam: Addmpam_msmon_read()to read monitor value
arm_mpam: Track bandwidth counter state for overflow and power
management
arm_mpam: Add helper to reset saved mbwu state
arm_mpam: Add kunit test for bitmap reset
arm_mpam: Add kunit tests forprops_mismatch()Rohit Mathew (2):
arm_mpam: Probe for long/lwd mbwu counters
arm_mpam: Use long MBWU counters if supportedarch/arm64/Kconfig | 25 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/acpi/arm64/Kconfig | 3 + drivers/acpi/arm64/Makefile | 1 + drivers/acpi/arm64/mpam.c | 384 ++++ drivers/acpi/pptt.c | 248 ++- drivers/acpi/tables.c | 2 +- drivers/resctrl/Kconfig | 22 + drivers/resctrl/Makefile | 4 + drivers/resctrl/mpam_devices.c | 2701 +++++++++++++++++++++++++++ drivers/resctrl/mpam_internal.h | 661 +++++++ drivers/resctrl/test_mpam_devices.c | 389 ++++ include/linux/acpi.h | 26 + include/linux/arm_mpam.h | 58 + include/linux/platform_device.h | 1 + 16 files changed, 4519 insertions(+), 9 deletions(-) create mode 100644 drivers/acpi/arm64/mpam.c create mode 100644 drivers/resctrl/Kconfig create mode 100644 drivers/resctrl/Makefile create mode 100644 drivers/resctrl/mpam_devices.c create mode 100644 drivers/resctrl/mpam_internal.h create mode 100644 drivers/resctrl/test_mpam_devices.c create mode 100644 include/linux/arm_mpam.h
Quoted 3 lines
--
2.39.5
I applied this series and booted the kernel on a Google Cloud C4A host (baremetal) and confirmed through sysfs that all MSCs were probed successfully.
Thanks!
-Peter