diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index caf88c460dd28..3127ffb96b907 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -1400,6 +1400,7 @@ static void __ris_msmon_read(void *arg) { bool nrdy = false; bool config_mismatch; + bool overflow; struct mon_read *m = arg; u64 now, overflow_val = 0; struct mon_cfg *ctx = m->ctx; @@ -1431,13 +1432,20 @@ static void __ris_msmon_read(void *arg) * This saves waiting for 'nrdy' on subsequent reads. */ read_msmon_ctl_flt_vals(m, &cur_ctl, &cur_flt); + overflow = cur_ctl & MSMON_CFG_x_CTL_OFLOW_STATUS; + clean_msmon_ctl_val(&cur_ctl); gen_msmon_ctl_flt_vals(m, &ctl_val, &flt_val); config_mismatch = cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN); - if (config_mismatch || reset_on_next_read) + if (config_mismatch || reset_on_next_read) { write_msmon_ctl_flt_vals(m, ctl_val, flt_val); + overflow = false; + } else if (overflow) { + mpam_write_monsel_reg(msc, CFG_MBWU_CTL, + cur_ctl & ~MSMON_CFG_x_CTL_OFLOW_STATUS); + } switch (m->type) { case mpam_feat_msmon_csu: @@ -1477,18 +1485,13 @@ static void __ris_msmon_read(void *arg) mbwu_state = &ris->mbwu_state[ctx->mon]; - /* Add any pre-overflow value to the mbwu_state->val */ - if (mbwu_state->prev_val > now) { - overflow_val = mpam_msmon_overflow_val(m->type); - if (mpam_has_quirk(T241_MBW_COUNTER_SCALE_64, msc)) - overflow_val *= 64; - overflow_val -= mbwu_state->prev_val; - } - - mbwu_state->prev_val = now; - mbwu_state->correction += overflow_val; + if (overflow) + mbwu_state->correction += mpam_msmon_overflow_val(m->type); - /* Include bandwidth consumed before the last hardware reset */ + /* + * Include bandwidth consumed before the last hardware reset and + * a counter size increment for each overflow. + */ now += mbwu_state->correction; break; default: diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h index e006a1bdbd1ec..913821416bde6 100644 --- a/drivers/resctrl/mpam_internal.h +++ b/drivers/resctrl/mpam_internal.h @@ -327,7 +327,7 @@ struct msmon_mbwu_state { /* * The value to add to the new reading to account for power management, - * and shifts to trigger the overflow interrupt. + * and overflow. */ u64 correction;