From nobody Tue Dec 16 14:57:43 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F108E1DF74F for ; Fri, 5 Dec 2025 22:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764972031; cv=none; b=KDqjgGLBXpnBWaP1xF1mybdRJ634DdBvgxuuLuISFH0H36yHqKIBLR3AdCtemYTAQeJV6TWI7fiDfGw8WTnligKUvpHI61K2PQKdfb1bixiHn8Z/30qJNnDoWzGsIecYHeYG2duAkC9po4R1vQSOUdwP2GxOKUIgURlbesTatUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764972031; c=relaxed/simple; bh=jQshvI9xiZr2qK3YeIIdQKokz3rapwNNrTTpAd9ednE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QMzze5f3TOVPZahhTGlV0J9K8SOeaLhQRG1y/atayw/ivb+nlX8dTb2T25xL0EleIH2cfdOtDjXaOFxq/B1jwPEjQleC5KQo5CJzkMnL2IpcxrqTHOwrxSBLhiDzbsOjqjkOZBfmPaNjbC25oeZI0m1k/D50G5CoJxOuQ7gmUOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EA4541BB0; Fri, 5 Dec 2025 14:00:21 -0800 (PST) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 667213F740; Fri, 5 Dec 2025 14:00:25 -0800 (PST) From: James Morse To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Dave Martin , Koba Ko , Shanker Donthineni , fenghuay@nvidia.com, baisheng.gao@unisoc.com, Jonathan Cameron , Gavin Shan , Ben Horgan , rohit.mathew@arm.com, reinette.chatre@intel.com, Punit Agrawal , Dave Martin Subject: [RFC PATCH 15/38] arm_mpam: resctrl: Convert to/from MPAMs fixed-point formats Date: Fri, 5 Dec 2025 21:58:38 +0000 Message-Id: <20251205215901.17772-16-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251205215901.17772-1-james.morse@arm.com> References: <20251205215901.17772-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Martin MPAM uses a fixed-point formats for some hardware controls. Resctrl provides the bandwidth controls as a percentage. Add helpers to convert between these. Signed-off-by: Dave Martin Signed-off-by: James Morse --- drivers/resctrl/mpam_resctrl.c | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 19d70d00bbcc..55576d0caf12 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -246,6 +247,46 @@ static bool cache_has_usable_cpor(struct mpam_class *c= lass) return (class->props.cpbm_wd <=3D 32); } =20 +/* + * Each fixed-point hardware value architecturally represents a range + * of values: the full range 0% - 100% is split contiguously into + * (1 << cprops->bwa_wd) equal bands. + * Find the nearest percentage value to the upper bound of the selected ba= nd: + */ +static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops) +{ + u32 val =3D mbw_max; + + val >>=3D 16 - cprops->bwa_wd; + val +=3D 1; + val *=3D MAX_MBA_BW; + val =3D DIV_ROUND_CLOSEST(val, 1 << cprops->bwa_wd); + + return val; +} + +/* + * Find the band whose upper bound is closest to the specified percentage. + * + * A round-to-nearest policy is followed here as a balanced compromise + * between unexpected under-commit of the resource (where the total of + * a set of resource allocations after conversion is less than the + * expected total, due to rounding of the individual converted + * percentages) and over-commit (where the total of the converted + * allocations is greater than expected). + */ +static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops) +{ + u32 val =3D pc; + + val <<=3D cprops->bwa_wd; + val =3D DIV_ROUND_CLOSEST(val, MAX_MBA_BW); + val =3D max(val, 1) - 1; + val <<=3D 16 - cprops->bwa_wd; + + return val; +} + /* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */ static void mpam_resctrl_pick_caches(void) { --=20 2.39.5