From: James Morse <james.morse@arm.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- 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. Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Hanjun Guo <guohanjun@huawei.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 48 +++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index e78352e2dcb2..e93797fbe61b 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -1214,9 +1214,7 @@ static void __ris_msmon_read(void *arg) static int _msmon_read(struct mpam_component *comp, struct mon_read *arg) { - int err = 0, idx; - bool read_again; - u64 wait_jiffies; + int err, any_err = 0, idx; struct mpam_msc *msc; struct mpam_msc_ris *ris; @@ -1225,38 +1223,34 @@ static int _msmon_read(struct mpam_component *comp, struct mon_read *arg) arg->ris = ris; msc = ris->msc; - read_again = false; -again: mutex_lock(&msc->lock); err = smp_call_function_any(&msc->accessibility, __ris_msmon_read, arg, true); mutex_unlock(&msc->lock); - if (arg->err == -EBUSY && !read_again) { - read_again = true; - - wait_jiffies = usecs_to_jiffies(comp->class->nrdy_usec); - while (wait_jiffies) - wait_jiffies = schedule_timeout_uninterruptible(wait_jiffies); - - goto again; - } - 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) - break; + any_err = err; } srcu_read_unlock(&mpam_srcu, idx); - return err; + return any_err; } int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, enum mpam_device_features type, u64 *val) { struct mon_read arg; + u64 wait_jiffies = 0; struct mpam_props *cprops = &comp->class->props; + int err = 0; might_sleep(); @@ -1273,7 +1267,25 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, arg.err = 0; *val = 0; - return _msmon_read(comp, &arg); + 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) { + arg = (struct mon_read) { + .ctx = ctx, + .type = type, + .val = val, + }; + *val = 0; + + err = _msmon_read(comp, &arg); + } + + return err; } void mpam_msmon_reset_all_mbwu(struct mpam_component *comp) -- 2.33.0