Skip to content

Commit 80d147d

Browse files
Dave MartinJames Morse
authored andcommitted
arm_mpam: resctrl: Convert to/from MPAMs fixed-point formats
MPAM uses a fixed-point formats for some hardware controls. Resctrl provides the bandwidth controls as a percentage. Add helpers to convert between these. Ensure bwa_wd is at most 16 to make it clear higher values have no meaning. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Jesse Chick <jessechick@os.amperecomputing.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Signed-off-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 01a0021 commit 80d147d

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

drivers/resctrl/mpam_devices.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,13 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)
713713
mpam_set_feature(mpam_feat_mbw_part, props);
714714

715715
props->bwa_wd = FIELD_GET(MPAMF_MBW_IDR_BWA_WD, mbw_features);
716+
717+
/*
718+
* The BWA_WD field can represent 0-63, but the control fields it
719+
* describes have a maximum of 16 bits.
720+
*/
721+
props->bwa_wd = min(props->bwa_wd, 16);
722+
716723
if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features))
717724
mpam_set_feature(mpam_feat_mbw_max, props);
718725

drivers/resctrl/mpam_resctrl.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/errno.h>
1111
#include <linux/limits.h>
1212
#include <linux/list.h>
13+
#include <linux/math.h>
1314
#include <linux/printk.h>
1415
#include <linux/rculist.h>
1516
#include <linux/resctrl.h>
@@ -242,6 +243,56 @@ static bool cache_has_usable_cpor(struct mpam_class *class)
242243
return class->props.cpbm_wd <= 32;
243244
}
244245

246+
/*
247+
* Each fixed-point hardware value architecturally represents a range
248+
* of values: the full range 0% - 100% is split contiguously into
249+
* (1 << cprops->bwa_wd) equal bands.
250+
*
251+
* Although the bwa_bwd fields have 6 bits the maximum valid value is 16
252+
* as it reports the width of fields that are at most 16 bits. When
253+
* fewer than 16 bits are valid the least significant bits are
254+
* ignored. The implied binary point is kept between bits 15 and 16 and
255+
* so the valid bits are leftmost.
256+
*
257+
* See ARM IHI0099B.a "MPAM system component specification", Section 9.3,
258+
* "The fixed-point fractional format" for more information.
259+
*
260+
* Find the nearest percentage value to the upper bound of the selected band:
261+
*/
262+
static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops)
263+
{
264+
u32 val = mbw_max;
265+
266+
val >>= 16 - cprops->bwa_wd;
267+
val += 1;
268+
val *= MAX_MBA_BW;
269+
val = DIV_ROUND_CLOSEST(val, 1 << cprops->bwa_wd);
270+
271+
return val;
272+
}
273+
274+
/*
275+
* Find the band whose upper bound is closest to the specified percentage.
276+
*
277+
* A round-to-nearest policy is followed here as a balanced compromise
278+
* between unexpected under-commit of the resource (where the total of
279+
* a set of resource allocations after conversion is less than the
280+
* expected total, due to rounding of the individual converted
281+
* percentages) and over-commit (where the total of the converted
282+
* allocations is greater than expected).
283+
*/
284+
static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops)
285+
{
286+
u32 val = pc;
287+
288+
val <<= cprops->bwa_wd;
289+
val = DIV_ROUND_CLOSEST(val, MAX_MBA_BW);
290+
val = max(val, 1) - 1;
291+
val <<= 16 - cprops->bwa_wd;
292+
293+
return val;
294+
}
295+
245296
/* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */
246297
static void mpam_resctrl_pick_caches(void)
247298
{

0 commit comments

Comments
 (0)