From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFEC227BF99; Fri, 12 Sep 2025 13:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757683272; cv=none; b=hykkfY+ljcM+zcHPml1tli0xW4ImbeM6WU5uF2nPmwzCh6GDVjoEtTppGfnPaZcuajG54zPJ8R4ovCYY/8dsujbD/+In2MfhvuOOQkgnZcFvUSxt4NDjj3L1kIdhdKBjc1Q+xpDawJsHRMrFLDobDSY0EMDwSKYMXCWTV+dxIuw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757683272; c=relaxed/simple; bh=ORzMtDFEjR/L5y0NRF0wISXHcUu6EqsZFLC76D7gIR0=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X13QS+hyD/HTFL7KraREwbL/g8C1NNSlDy1mvZVdZy7fArKV9TjXPJTpjph1PsghS91hkgkJbxvaMpTuoFZ6PKgNUDalOuC55oeSX9zSWLlSBIDqsHN+pXLiymqnLjQYgttD4QgmsjTefkynUb+42WHWrYUzDcDEYyzsr7dw+1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4cNZhL2Zsjz6L5Gb; Fri, 12 Sep 2025 21:16:50 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 4654B14038F; Fri, 12 Sep 2025 21:21:07 +0800 (CST) Received: from localhost (10.203.177.15) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 12 Sep 2025 15:21:06 +0200 Date: Fri, 12 Sep 2025 14:21:04 +0100 From: Jonathan Cameron To: James Morse CC: , , , D Scott Phillips OS , , , , , , Jamie Iles , Xin Hao , , , , David Hildenbrand , Dave Martin , Koba Ko , Shanker Donthineni , , , Rob Herring , Rohit Mathew , "Rafael Wysocki" , Len Brown , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Catalin Marinas , "Will Deacon" , Greg Kroah-Hartman , Danilo Krummrich Subject: Re: [PATCH v2 23/29] arm_mpam: Add mpam_msmon_read() to read monitor value Message-ID: <20250912142104.00006569@huawei.com> In-Reply-To: <20250910204309.20751-24-james.morse@arm.com> References: <20250910204309.20751-1-james.morse@arm.com> <20250910204309.20751-24-james.morse@arm.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500012.china.huawei.com (7.191.174.4) To frapeml500008.china.huawei.com (7.182.85.71) On Wed, 10 Sep 2025 20:43:03 +0000 James Morse 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 > Signed-off-by: James Morse Hi James, A couple of minor comments inline, Jonathan > +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; 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. > + default: > + return; > + } > +} > + > +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. > + 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. > + > + 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; This won't be needed if you returned on error above. > + } > + srcu_read_unlock(&mpam_srcu, idx); > + > + return err; And you only reach here with above changes if err == 0 so return 0; appropriate. > +} > + > +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)); Either use = { }; at declaration or maybe arg = (struct mon_read) { .ctx = ctx, .type = type, .val = val, }; rather than bothering with separate memset. > + 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)); Same as above. > + arg.ctx = ctx; > + arg.type = type; > + arg.val = val; > + *val = 0; > + > + err = _msmon_read(comp, &arg); > + } > + > + return err; > +}