Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Dave Martin and committed by
James Morse
80d147d2 01a0021f

+58
+7
drivers/resctrl/mpam_devices.c
··· 713 713 mpam_set_feature(mpam_feat_mbw_part, props); 714 714 715 715 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 + 716 723 if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features)) 717 724 mpam_set_feature(mpam_feat_mbw_max, props); 718 725
+51
drivers/resctrl/mpam_resctrl.c
··· 10 10 #include <linux/errno.h> 11 11 #include <linux/limits.h> 12 12 #include <linux/list.h> 13 + #include <linux/math.h> 13 14 #include <linux/printk.h> 14 15 #include <linux/rculist.h> 15 16 #include <linux/resctrl.h> ··· 241 240 242 241 /* resctrl uses u32 for all bitmap configurations */ 243 242 return class->props.cpbm_wd <= 32; 243 + } 244 + 245 + /* 246 + * Each fixed-point hardware value architecturally represents a range 247 + * of values: the full range 0% - 100% is split contiguously into 248 + * (1 << cprops->bwa_wd) equal bands. 249 + * 250 + * Although the bwa_bwd fields have 6 bits the maximum valid value is 16 251 + * as it reports the width of fields that are at most 16 bits. When 252 + * fewer than 16 bits are valid the least significant bits are 253 + * ignored. The implied binary point is kept between bits 15 and 16 and 254 + * so the valid bits are leftmost. 255 + * 256 + * See ARM IHI0099B.a "MPAM system component specification", Section 9.3, 257 + * "The fixed-point fractional format" for more information. 258 + * 259 + * Find the nearest percentage value to the upper bound of the selected band: 260 + */ 261 + static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops) 262 + { 263 + u32 val = mbw_max; 264 + 265 + val >>= 16 - cprops->bwa_wd; 266 + val += 1; 267 + val *= MAX_MBA_BW; 268 + val = DIV_ROUND_CLOSEST(val, 1 << cprops->bwa_wd); 269 + 270 + return val; 271 + } 272 + 273 + /* 274 + * Find the band whose upper bound is closest to the specified percentage. 275 + * 276 + * A round-to-nearest policy is followed here as a balanced compromise 277 + * between unexpected under-commit of the resource (where the total of 278 + * a set of resource allocations after conversion is less than the 279 + * expected total, due to rounding of the individual converted 280 + * percentages) and over-commit (where the total of the converted 281 + * allocations is greater than expected). 282 + */ 283 + static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops) 284 + { 285 + u32 val = pc; 286 + 287 + val <<= cprops->bwa_wd; 288 + val = DIV_ROUND_CLOSEST(val, MAX_MBA_BW); 289 + val = max(val, 1) - 1; 290 + val <<= 16 - cprops->bwa_wd; 291 + 292 + return val; 244 293 } 245 294 246 295 /* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */