[RFC PATCH 20/20] x86/intel_rdt: Merge cdp enable/disable calls

From: James Morse
Date: Fri Aug 24 2018 - 06:46:48 EST


Now that the cdp_enable() and cdp_disable() calls are basically the same,
merge them into cdp_set_enabled(true/false).

All these functions are behind resctrl_arch_set_cdp_enabled(),
so the can take the rdt_hw_resource directly.

Signed-off-by: James Morse <james.morse@xxxxxxx>
---
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 49 ++++++------------------
1 file changed, 12 insertions(+), 37 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index 38cd463443e8..b9b7375ef8a9 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -1017,10 +1017,9 @@ static inline bool is_mba_linear(void)
return rdt_resources_all[RDT_RESOURCE_MBA].resctrl.membw.delay_linear;
}

-static int set_cache_qos_cfg(int level, bool enable)
+static int set_cache_qos_cfg(struct rdt_hw_resource *hw_res, bool enable)
{
void (*update)(void *arg);
- struct rdt_resource *r_l;
cpumask_var_t cpu_mask;
struct rdt_domain *d;
int cpu;
@@ -1028,15 +1027,14 @@ static int set_cache_qos_cfg(int level, bool enable)
if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
return -ENOMEM;

- if (level == RDT_RESOURCE_L3)
+ if (hw_res == &rdt_resources_all[RDT_RESOURCE_L3])
update = l3_qos_cfg_update;
- else if (level == RDT_RESOURCE_L2)
+ else if (hw_res == &rdt_resources_all[RDT_RESOURCE_L2])
update = l2_qos_cfg_update;
else
return -EINVAL;

- r_l = &rdt_resources_all[level].resctrl;
- list_for_each_entry(d, &r_l->domains, list) {
+ list_for_each_entry(d, &hw_res->resctrl.domains, list) {
/* Pick one CPU from each domain instance to update MSR */
cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
}
@@ -1078,53 +1076,30 @@ static int set_mba_sc(bool mba_sc)
return 0;
}

-static int cdp_enable(int level)
+static int cdp_set_enabled(struct rdt_hw_resource *hw_res, bool enable)
{
- struct rdt_resource *r_l = &rdt_resources_all[level].resctrl;
int ret;

- if (!r_l->alloc_capable || !r_l->cdp_capable)
+ if (!hw_res->resctrl.cdp_capable)
return -EINVAL;

- ret = set_cache_qos_cfg(level, true);
+ ret = set_cache_qos_cfg(hw_res, enable);
if (!ret)
- r_l->cdp_enabled = true;
+ hw_res->resctrl.cdp_enabled = enable;

return ret;
}

-static void cdp_disable(int level)
-{
- struct rdt_resource *r = &rdt_resources_all[level].resctrl;
-
- if (r->cdp_enabled) {
- set_cache_qos_cfg(level, false);
- r->cdp_enabled = false;
- }
-}
-
int resctrl_arch_set_cdp_enabled(bool enable)
{
int ret = -EINVAL;
struct rdt_hw_resource *l3 = &rdt_resources_all[RDT_RESOURCE_L3];
struct rdt_hw_resource *l2 = &rdt_resources_all[RDT_RESOURCE_L2];

- if (l3 && l3->resctrl.cdp_capable) {
- if (!enable) {
- cdp_disable(RDT_RESOURCE_L3);
- ret = 0;
- } else {
- ret = cdp_enable(RDT_RESOURCE_L3);
- }
- }
- if (l2 && l2->resctrl.cdp_capable) {
- if (!enable) {
- cdp_disable(RDT_RESOURCE_L2);
- ret = 0;
- } else {
- ret = cdp_enable(RDT_RESOURCE_L2);
- }
- }
+ if (l3 && l3->resctrl.cdp_capable)
+ ret = cdp_set_enabled(l3, enable);
+ if (l2 && l2->resctrl.cdp_capable)
+ ret = cdp_set_enabled(l2, enable);

return ret;
}
--
2.18.0