[PATCH v2 15/33] x86/intel_rdt: Adds support to enable Code Data Prioritization

From: Fenghua Yu
Date: Thu Sep 08 2016 - 02:58:58 EST


From: Vikas Shivappa <vikas.shivappa@xxxxxxxxxxxxxxx>

On Intel SKUs that support Code Data Prioritization(CDP), intel_rdt
operates in 2 modes - legacy cache allocation mode/default or CDP mode.

When CDP is enabled, the number of available CLOSids is halved. Hence the
enabling is done when less than half the number of CLOSids available are
used. When CDP is enabled each CLOSid maps to a
data cache mask and an instruction cache mask. The enabling itself is done
by writing to the IA32_PQOS_CFG MSR and can dynamically be enabled or
disabled.

CDP is disabled when for each (dcache_cbm,icache_cbm) pair, the
dcache_cbm = icache_cbm.

Signed-off-by: Vikas Shivappa <vikas.shivappa@xxxxxxxxxxxxxxx>
Signed-off-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
Reviewed-by: Tony Luck <tony.luck@xxxxxxxxx>
---
arch/x86/include/asm/intel_rdt.h | 7 ++++++
arch/x86/kernel/cpu/intel_rdt.c | 46 +++++++++++++++++++++++++++++-----------
2 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/intel_rdt.h b/arch/x86/include/asm/intel_rdt.h
index 8512174..4e05c6e 100644
--- a/arch/x86/include/asm/intel_rdt.h
+++ b/arch/x86/include/asm/intel_rdt.h
@@ -8,6 +8,7 @@
#define MAX_CBM_LENGTH 32
#define IA32_L3_CBM_BASE 0xc90
#define CBM_FROM_INDEX(x) (IA32_L3_CBM_BASE + x)
+#define MSR_IA32_PQOS_CFG 0xc81

extern struct static_key rdt_enable_key;
void __intel_rdt_sched_in(void *dummy);
@@ -17,6 +18,12 @@ struct clos_cbm_table {
unsigned int clos_refcnt;
};

+struct clos_config {
+ unsigned long *closmap;
+ u32 max_closid;
+ u32 closids_used;
+};
+
/*
* intel_rdt_sched_in() - Writes the task's CLOSid to IA32_PQR_MSR
*
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index a4937d4..e0f23b6 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -31,10 +31,6 @@
*/
static struct clos_cbm_table *cctable;
/*
- * closid availability bit map.
- */
-unsigned long *closmap;
-/*
* Minimum bits required in Cache bitmask.
*/
unsigned int min_bitmask_len = 1;
@@ -49,6 +45,11 @@ static cpumask_t rdt_cpumask;
static cpumask_t tmp_cpumask;
static DEFINE_MUTEX(rdtgroup_mutex);
struct static_key __read_mostly rdt_enable_key = STATIC_KEY_INIT_FALSE;
+struct clos_config cconfig;
+bool cdp_enabled;
+
+#define __DCBM_TABLE_INDEX(x) (x << 1)
+#define __ICBM_TABLE_INDEX(x) ((x << 1) + 1)

struct rdt_remote_data {
int msr;
@@ -122,22 +123,28 @@ static int closid_alloc(u32 *closid)

lockdep_assert_held(&rdtgroup_mutex);

- maxid = boot_cpu_data.x86_cache_max_closid;
- id = find_first_zero_bit(closmap, maxid);
+ maxid = cconfig.max_closid;
+ id = find_first_zero_bit(cconfig.closmap, maxid);
if (id == maxid)
return -ENOSPC;

- set_bit(id, closmap);
+ set_bit(id, cconfig.closmap);
closid_get(id);
*closid = id;
+ cconfig.closids_used++;

return 0;
}

static inline void closid_free(u32 closid)
{
- clear_bit(closid, closmap);
+ clear_bit(closid, cconfig.closmap);
cctable[closid].cbm = 0;
+
+ if (WARN_ON(!cconfig.closids_used))
+ return;
+
+ cconfig.closids_used--;
}

static void closid_put(u32 closid)
@@ -171,6 +178,21 @@ static inline void msr_update_all(int msr, u64 val)
on_each_cpu_mask(&rdt_cpumask, msr_cpu_update, &info, 1);
}

+static bool code_data_mask_equal(void)
+{
+ int i, dindex, iindex;
+
+ for (i = 0; i < cconfig.max_closid; i++) {
+ dindex = __DCBM_TABLE_INDEX(i);
+ iindex = __ICBM_TABLE_INDEX(i);
+ if (cctable[dindex].clos_refcnt &&
+ (cctable[dindex].cbm != cctable[iindex].cbm))
+ return false;
+ }
+
+ return true;
+}
+
/*
* Set only one cpu in cpumask in all cpus that share the same cache.
*/
@@ -191,7 +213,7 @@ static inline bool rdt_cpumask_update(int cpu)
*/
static void cbm_update_msrs(void *dummy)
{
- int maxid = boot_cpu_data.x86_cache_max_closid;
+ int maxid = cconfig.max_closid;
struct rdt_remote_data info;
unsigned int i;

@@ -199,7 +221,7 @@ static void cbm_update_msrs(void *dummy)
if (cctable[i].clos_refcnt) {
info.msr = CBM_FROM_INDEX(i);
info.val = cctable[i].cbm;
- msr_cpu_update(&info);
+ msr_cpu_update((void *) &info);
}
}
}
@@ -275,8 +297,8 @@ static int __init intel_rdt_late_init(void)
}

size = BITS_TO_LONGS(maxid) * sizeof(long);
- closmap = kzalloc(size, GFP_KERNEL);
- if (!closmap) {
+ cconfig.closmap = kzalloc(size, GFP_KERNEL);
+ if (!cconfig.closmap) {
kfree(cctable);
err = -ENOMEM;
goto out_err;
--
2.5.0