Currently, when a new resource group is created, the allocation values
of the MBA resource are not initialized and remain meaningless data.

For example:

  mkdir /sys/fs/resctrl/p1
  cat /sys/fs/resctrl/p1/schemata
  MB:0=100;1=100

  echo "MB:0=10;1=20" > /sys/fs/resctrl/p1/schemata
  cat /sys/fs/resctrl/p1/schemata
  MB:0= 10;1= 20

  rmdir /sys/fs/resctrl/p1
  mkdir /sys/fs/resctrl/p2
  cat /sys/fs/resctrl/p2/schemata
  MB:0= 10;1= 20

Therefore, when the new group is created, it is reasonable to initialize
MBA resource with default values.

Initialize the MBA resource and cache resources in separate functions.

Signed-off-by: Xiaochen Shen <xiaochen.s...@intel.com>
Reviewed-by: Fenghua Yu <fenghua...@intel.com>
Reviewed-by: Reinette Chatre <reinette.cha...@intel.com>
---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  4 +--
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 52 +++++++++++++++++++------------
 2 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c 
b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 2dbd990..89320c0 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -342,10 +342,10 @@ int update_domains(struct rdt_resource *r, int closid)
        if (cpumask_empty(cpu_mask) || mba_sc)
                goto done;
        cpu = get_cpu();
-       /* Update CBM on this cpu if it's in cpu_mask. */
+       /* Update resource control msr on this CPU if it's in cpu_mask. */
        if (cpumask_test_cpu(cpu, cpu_mask))
                rdt_ctrl_update(&msr_param);
-       /* Update CBM on other cpus. */
+       /* Update resource control msr on other CPUs. */
        smp_call_function_many(cpu_mask, rdt_ctrl_update, &msr_param, 1);
        put_cpu();
 
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c 
b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 9cb6a1d..44b6dbf 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2581,8 +2581,8 @@ static int __init_one_rdt_domain(struct rdt_domain *d, 
struct rdt_resource *r,
        return 0;
 }
 
-/**
- * rdtgroup_init_alloc - Initialize the new RDT group's allocations
+/*
+ * Initialize cache resources with default values.
  *
  * A new RDT group is being created on an allocation capable (CAT)
  * supporting system. Set this group up to start off with all usable
@@ -2591,33 +2591,45 @@ static int __init_one_rdt_domain(struct rdt_domain *d, 
struct rdt_resource *r,
  * If there are no more shareable bits available on any domain then
  * the entire allocation will fail.
  */
+static int rdtgroup_init_cat(struct rdt_resource *r, u32 closid)
+{
+       struct rdt_domain *d;
+       int ret;
+
+       list_for_each_entry(d, &r->domains, list) {
+               ret = __init_one_rdt_domain(d, r, closid);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+/* Initialize MBA resource with default values. */
+static void rdtgroup_init_mba(struct rdt_resource *r)
+{
+       struct rdt_domain *d;
+
+       list_for_each_entry(d, &r->domains, list) {
+               d->new_ctrl = is_mba_sc(r) ? MBA_MAX_MBPS : r->default_ctrl;
+               d->have_new_ctrl = true;
+       }
+}
+
+/* Initialize the RDT group's allocations. */
 static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
 {
        struct rdt_resource *r;
-       struct rdt_domain *d;
        int ret;
 
        for_each_alloc_enabled_rdt_resource(r) {
-               /*
-                * Only initialize default allocations for CBM cache
-                * resources
-                */
-               if (r->rid == RDT_RESOURCE_MBA)
-                       continue;
-               list_for_each_entry(d, &r->domains, list) {
-                       ret = __init_one_rdt_domain(d, r, rdtgrp->closid);
+               if (r->rid == RDT_RESOURCE_MBA) {
+                       rdtgroup_init_mba(r);
+               } else {
+                       ret = rdtgroup_init_cat(r, rdtgrp->closid);
                        if (ret < 0)
                                return ret;
                }
-       }
-
-       for_each_alloc_enabled_rdt_resource(r) {
-               /*
-                * Only initialize default allocations for CBM cache
-                * resources
-                */
-               if (r->rid == RDT_RESOURCE_MBA)
-                       continue;
                ret = update_domains(r, rdtgrp->closid);
                if (ret < 0) {
                        rdt_last_cmd_puts("Failed to initialize allocations\n");
-- 
1.8.3.1

Reply via email to