From: Xie XiuQi <xiexiuqi(a)huawei.com>
commit 34c0582d2a207eea0bbf740fb67a782c95a452b7 openEuler-1.0
hulk inclusion
category: feature
bugzilla: 5510
CVE: NA
Signed-off-by: Xie XiuQi <xiexiuqi(a)huawei.com>
Reviewed-by: Hanjun Guo <guohanjun(a)huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang(a)huawei.com>
Signed-off-by: Xin Hao <haoxing990(a)gmail.com>
---
arch/arm64/include/asm/mpam.h | 1 +
arch/arm64/kernel/mpam.c | 7 ++--
arch/arm64/kernel/mpam_ctrlmon.c | 62 ++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h
index 4b800abe45f9..9f6b94ea1ce2 100644
--- a/arch/arm64/include/asm/mpam.h
+++ b/arch/arm64/include/asm/mpam.h
@@ -336,6 +336,7 @@ struct raw_resctrl_resource {
};
int parse_cbm(char *buf, struct raw_resctrl_resource *r, struct rdt_domain *d);
+int parse_bw(char *buf, struct raw_resctrl_resource *r, struct rdt_domain *d);
union mon_data_bits {
void *priv;
diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c
index a33a01285d81..fc30dcbbeac3 100644
--- a/arch/arm64/kernel/mpam.c
+++ b/arch/arm64/kernel/mpam.c
@@ -207,8 +207,8 @@ struct raw_resctrl_resource raw_resctrl_resources_all[] = {
[MPAM_RESOURCE_MC] = {
.msr_update = bw_wrmsr,
.msr_read = bw_rdmsr,
- .parse_ctrlval = parse_cbm, /* [FIXME] add parse_bw() helper */
- .format_str = "%d=%0*x",
+ .parse_ctrlval = parse_bw, /* [FIXME] add parse_bw() helper */
+ .format_str = "%d=%0*d",
.mon_read = mbwu_read,
.mon_write = mbwu_write,
},
@@ -270,7 +270,8 @@ u64 bw_rdmsr(struct rdt_domain *d, int partid)
mpam_writel(partid, d->base + MPAMCFG_PART_SEL);
max = mpam_readl(d->base + MPAMCFG_MBW_MAX);
- return MBW_MAX_GET(max);
+ max = MBW_MAX_GET(max);
+ return roundup((max * 100) / 64, 5);
}
/*
diff --git a/arch/arm64/kernel/mpam_ctrlmon.c b/arch/arm64/kernel/mpam_ctrlmon.c
index b6bf0b86c1a4..3fa095cfce7e 100644
--- a/arch/arm64/kernel/mpam_ctrlmon.c
+++ b/arch/arm64/kernel/mpam_ctrlmon.c
@@ -82,6 +82,68 @@ int parse_cbm(char *buf, struct raw_resctrl_resource *r, struct
rdt_domain *d)
return 0;
}
+/* define bw_min as 5 percentage, that are 5% ~ 100% which cresponding masks: */
+static u32 bw_max_mask[20] = {
+ 3, /* 3/64: 5% */
+ 6, /* 6/64: 10% */
+ 10, /* 10/64: 15% */
+ 13, /* 13/64: 20% */
+ 16, /* 16/64: 25% */
+ 19, /* ... */
+ 22,
+ 26,
+ 29,
+ 32,
+ 35,
+ 38,
+ 42,
+ 45,
+ 48,
+ 51,
+ 54,
+ 58,
+ 61,
+ 63 /* 100% */
+};
+
+static bool bw_validate(char *buf, unsigned long *data, struct raw_resctrl_resource *r)
+{
+ unsigned long bw;
+ int ret, idx;
+
+ ret = kstrtoul(buf, 10, &bw);
+ if (ret) {
+ rdt_last_cmd_printf("non-hex character in mask %s\n", buf);
+ return false;
+ }
+
+ bw = bw < 5 ? 5 : bw;
+ bw = bw > 100 ? 100 : bw;
+
+ idx = roundup(bw, 5) / 5 - 1;
+
+ *data = bw_max_mask[idx];
+ return true;
+}
+
+int parse_bw(char *buf, struct raw_resctrl_resource *r, struct rdt_domain *d)
+{
+ unsigned long data;
+
+ if (d->have_new_ctrl) {
+ rdt_last_cmd_printf("duplicate domain %d\n", d->id);
+ return -EINVAL;
+ }
+
+ if (!bw_validate(buf, &data, r))
+ return -EINVAL;
+
+ d->new_ctrl = data;
+ d->have_new_ctrl = true;
+
+ return 0;
+}
+
/*
* For each domain in this resource we expect to find a series of:
* id=mask
--
2.31.0