x86: Intel Cache Allocation Support
Subsystems (4)
v3 cover x86: Intel Cache Allocation Support
This patch adds a new cgroup subsystem to support the new Cache Allocation Technology (CAT) feature found in future Intel Xeon processors.
Cache Allocation Technology(CAT) provides a way for the Software (OS/VMM) to restrict cache allocation to a defined 'subset' of cache which may be overlapping with other 'subsets'. This feature is used when allocating a line in cache ie when pulling new data into the cache.
This patch series is dependent on the patches for Intel Cache QOS Monitoring from Matt since the series also implements a common software cache for the IA32_PQR_MSR :
https://lkml.kernel.org/r/[email protected]
Changes in V3:
- Implements a common software cache for IA32_PQR_MSR
- Implements support for hsw CAT enumeration. This does not use the brand strings like earlier version but does a probe test. The probe test is done only on hsw family of processors
- Made a few coding convention, name changes and minor fixes
Changes in V2:
- Removed HSW specific enumeration changes. Plan to include it later as a seperate patch.
- Fixed the code in prep_arch_switch to be specific for x86 and removed x86 defines.
- Fixed cbm_write to not write all 1s when a cgroup is freed.
- Fixed one possible memory leak in init.
- Changed some of manual bitmap
manipulation to use the predefined bitmap APIs to make code more readable
- Changed name in sources from cqe to cat
- Global cat enable flag changed to static_key and disabled cgroup early_init
Vikas Shivappa (6):
x86/intel_cat: Intel Cache Allocation Technology detection x86/intel_cat: Adds support for Class of service management x86/intel_cat: Support cache bit mask for Intel CAT x86/intel_cat: Implement scheduling support for Intel CAT x86/intel_rdt: Software Cache for IA32_PQR_MSR x86/intel_cat: Intel haswell CAT enumeration
arch/x86/include/asm/cpufeature.h | 6 +- arch/x86/include/asm/intel_cat.h | 99 ++++++++ arch/x86/include/asm/processor.h | 3 + arch/x86/include/asm/rdt.h | 13 + arch/x86/include/asm/switch_to.h | 3 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 16 ++ arch/x86/kernel/cpu/intel_cat.c | 367 +++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel_cqm.c | 20 +- include/linux/cgroup_subsys.h | 4 + init/Kconfig | 11 + kernel/sched/core.c | 1 + kernel/sched/sched.h | 3 + 13 files changed, 533 insertions(+), 14 deletions(-) create mode 100644 arch/x86/include/asm/intel_cat.h create mode 100644 arch/x86/include/asm/rdt.h create mode 100644 arch/x86/kernel/cpu/intel_cat.c
Signature · 1 line
1.9.1
PATCH v3 1/6 x86/intel_cat: Intel Cache Allocation Technology detection
This patch adds support for the new Cache Allocation Technology (CAT) feature found in future Intel Xeon processors. It includes CPUID enumeration routines for CAT and new values to track CAT resources to the cpuinfo_x86 structure.
Cache Allocation Technology(CAT) provides a way for the Software (OS/VMM) to restrict cache allocation to a defined 'subset' of cache which may be overlapping with other 'subsets'. This feature is used when allocating a line in cache ie when pulling new data into the cache. The programming of the h/w is done via programming MSRs.
More information about CAT be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.15.
--- arch/x86/include/asm/cpufeature.h | 6 ++++- arch/x86/include/asm/processor.h | 3 +++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 16 ++++++++++++ arch/x86/kernel/cpu/intel_cat.c | 51 +++++++++++++++++++++++++++++++++++++++ init/Kconfig | 11 +++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/intel_cat.c
arch/x86/include/asm/cpufeature.h +5 -1
@@ -12,7 +12,7 @@#include <asm/disabled-features.h> #endif -#define NCAPINTS 13/* N 32-bit words worth of info */ +#define NCAPINTS 14/* N 32-bit words worth of info */ #define NBUGINTS 1/* N 32-bit bug flags */ /*
@@ -227,6 +227,7 @@#define X86_FEATURE_RTM ( 9*32+11)/* Restricted Transactional Memory */ #define X86_FEATURE_CQM ( 9*32+12)/* Cache QoS Monitoring */ #define X86_FEATURE_MPX ( 9*32+14)/* Memory Protection Extension */ +#define X86_FEATURE_CAT ( 9*32+15)/* Cache QOS Enforcement */ #define X86_FEATURE_AVX512F ( 9*32+16)/* AVX-512 Foundation */ #define X86_FEATURE_RDSEED ( 9*32+18)/* The RDSEED instruction */ #define X86_FEATURE_ADX ( 9*32+19)/* The ADCX and ADOX instructions */
@@ -248,6 +249,9 @@/* Intel-defined CPU QoS Sub-leaf, CPUID level 0x0000000F:1 (edx), word 12 */ #define X86_FEATURE_CQM_OCCUP_LLC (12*32+ 0)/* LLC occupancy monitoring if 1 */ +/* Intel-defined CPU features, CPUID level 0x00000010:0 (ebx), word 13 */ +#define X86_FEATURE_CAT_L3 (13*32 + 1)/*Cache QOS Enforcement L3*/ +/* * BUG word(s) */
arch/x86/include/asm/processor.h +3 -0
@@ -112,6 +112,9 @@ struct cpuinfo_x86 {/* Cache QoS architectural values: */ int x86_cache_max_rmid;/* max index */ int x86_cache_occ_scale;/* scale to bytes */ +/* Cache Allocation Technology values */ +int x86_cat_cbmlength; +int x86_cat_closs;int x86_power;unsigned long loops_per_jiffy;/* cpuid returned max cores value: */
arch/x86/kernel/cpu/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_nhmex.o endif +obj-$(CONFIG_CGROUP_CAT) +=intel_cat.o obj-$(CONFIG_X86_MCE) += mcheck/ obj-$(CONFIG_MTRR) += mtrr/
arch/x86/kernel/cpu/common.c +16 -0
@@ -668,6 +668,22 @@ void get_cpu_cap(struct cpuinfo_x86 *c) } } +/* Additional Intel-defined flags: level 0x00000010 */ +if (c->cpuid_level >=0x00000010 ) { +u32 eax, ebx, ecx, edx; + +cpuid_count (0x00000010 ,0 , &eax, &ebx, &ecx, &edx); + c->x86_capability[13 ] = ebx; + +if (cpu_has (c,X86_FEATURE_CAT ) && +cpu_has (c,X86_FEATURE_CAT_L3 )) { + +cpuid_count (0x00000010 ,1 , &eax, &ebx, &ecx, &edx); + c->x86_cat_closs = (edx &0xffff ) +1 ; + c->x86_cat_cbmlength = (eax &0xf ) +1 ; + } + } +/* AMD-defined flags: level 0x80000001 */ xlvl =cpuid_eax (0x80000000 ); c->extended_cpuid_level = xlvl;
arch/x86/kernel/cpu/intel_cat.c new file +51 -0
51 lines not on this page · raw message
init/Kconfig +11 -0
@@ -961,6 +961,17 @@ config CPUSETS Say N if unsure. +config CGROUP_CAT + bool "Cache Allocation Technology cgroup subsystem" + depends on X86_64 + help + This option provides framework to allocate cache lines when + applications fill cache. + This can be used by users to configure how much cache that can be + allocated to different PIDs. + + Say N if unsure. + config PROC_PID_CPUSET bool "Include legacy /proc/<pid>/cpuset file" depends on CPUSETS
Signature · 1 line
1.9.1
Re: [PATCH 1/6] x86/intel_cat: Intel Cache Allocation Technology detection
Trivial nit below.
Quoted 15 lines · Vikas Shivappa
This patch adds support for the new Cache Allocation Technology (CAT) feature found in future Intel Xeon processors. It includes CPUID enumeration routines for CAT and new values to track CAT resources to the
cpuinfo_x86structure.Cache Allocation Technology(CAT) provides a way for the Software (OS/VMM) to restrict cache allocation to a defined 'subset' of cache which may be overlapping with other 'subsets'. This feature is used when allocating a line in cache ie when pulling new data into the cache. The programming of the h/w is done via programming MSRs.
More information about CAT be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.15.
Signed-off-by Vikas Shivappa <[email protected]>
[...]
init/Kconfig config CPUSETS · line 966
Quoted 11 lines
init/Kconfig +3
-0@@ -961,6 +961,17 @@ config CPUSETS Say N if unsure. +config CGROUP_CAT + bool "Cache Allocation Technology cgroup subsystem" + depends on X86_64
Odd indentation. Just make it a tab (as I suppose the indentation of "help" already is).
init/Kconfig config CPUSETS · line 977
Quoted 11 lines
init/Kconfig +8
-0+ help + This option provides framework to allocate cache lines when + applications fill cache. + This can be used by users to configure how much cache that can be + allocated to different PIDs. + + Say N if unsure. + config PROC_PID_CPUSET bool "Include legacy /proc/<pid>/cpuset file" depends on CPUSETS
Paul Bolle
Re: [PATCH 1/6] x86/intel_cat: Intel Cache Allocation Technology detection
Quoted 27 lines · Paul Bolle
Trivial nit below.
Quoted 15 lines · Vikas Shivappa
This patch adds support for the new Cache Allocation Technology (CAT) feature found in future Intel Xeon processors. It includes CPUID enumeration routines for CAT and new values to track CAT resources to the
cpuinfo_x86structure.Cache Allocation Technology(CAT) provides a way for the Software (OS/VMM) to restrict cache allocation to a defined 'subset' of cache which may be overlapping with other 'subsets'. This feature is used when allocating a line in cache ie when pulling new data into the cache. The programming of the h/w is done via programming MSRs.
More information about CAT be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.15.
Signed-off-by Vikas Shivappa <[email protected]>[...]
Quoted 6 lines
init/Kconfig +0
-0@@ -961,6 +961,17 @@ config CPUSETS
Quoted 8 lines
init/Kconfig config CPUSETS · line 966
Quoted 5 lines
init/Kconfig +3
-0Say N if unsure. +config CGROUP_CAT + bool "Cache Allocation Technology cgroup subsystem" + depends on X86_64Odd indentation. Just make it a tab (as I suppose the indentation of "help" already is).
ok , Will fix. Wish the checkpatch.pl caught that :)
Thanks,
Vikas
Quoted 17 lines
init/Kconfig config CPUSETS · line 977
Quoted 12 lines
init/Kconfig +8
-0+ help + This option provides framework to allocate cache lines when + applications fill cache. + This can be used by users to configure how much cache that can be + allocated to different PIDs. + + Say N if unsure. + config PROC_PID_CPUSET bool "Include legacy /proc/<pid>/cpuset file" depends on CPUSETSPaul Bolle
Re: [PATCH 1/6] x86/intel_cat: Intel Cache Allocation Technology
In reply to Paul BolleThis patch adds support for the new Cache Allocation Technology (CAT) feature found in future Intel Xeon processors. It includes CPUID enumeration routines for CAT and new values to track CAT resources to the cpuinfo_x86 structure.
Cache Allocation Technology(CAT) provides a way for the Software (OS/VMM) to restrict cache allocation to a defined 'subset' of cache which may be overlapping with other 'subsets'. This feature is used when allocating a line in cache ie when pulling new data into the cache. The programming of the h/w is done via programming MSRs.
More information about CAT be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.15.
---
A minor change with Corrected indentation in init/Kconfig
arch/x86/include/asm/cpufeature.h | 6 ++++- arch/x86/include/asm/processor.h | 3 +++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 16 ++++++++++++ arch/x86/kernel/cpu/intel_cat.c | 51 +++++++++++++++++++++++++++++++++++++++ init/Kconfig | 11 +++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/intel_cat.c
arch/x86/include/asm/cpufeature.h +5 -1
@@ -12,7 +12,7 @@#include <asm/disabled-features.h> #endif -#define NCAPINTS 13/* N 32-bit words worth of info */ +#define NCAPINTS 14/* N 32-bit words worth of info */ #define NBUGINTS 1/* N 32-bit bug flags */ /*
@@ -227,6 +227,7 @@#define X86_FEATURE_RTM ( 9*32+11)/* Restricted Transactional Memory */ #define X86_FEATURE_CQM ( 9*32+12)/* Cache QoS Monitoring */ #define X86_FEATURE_MPX ( 9*32+14)/* Memory Protection Extension */ +#define X86_FEATURE_CAT ( 9*32+15)/* Cache QOS Enforcement */ #define X86_FEATURE_AVX512F ( 9*32+16)/* AVX-512 Foundation */ #define X86_FEATURE_RDSEED ( 9*32+18)/* The RDSEED instruction */ #define X86_FEATURE_ADX ( 9*32+19)/* The ADCX and ADOX instructions */
@@ -248,6 +249,9 @@/* Intel-defined CPU QoS Sub-leaf, CPUID level 0x0000000F:1 (edx), word 12 */ #define X86_FEATURE_CQM_OCCUP_LLC (12*32+ 0)/* LLC occupancy monitoring if 1 */ +/* Intel-defined CPU features, CPUID level 0x00000010:0 (ebx), word 13 */ +#define X86_FEATURE_CAT_L3 (13*32 + 1)/*Cache QOS Enforcement L3*/ +/* * BUG word(s) */
arch/x86/include/asm/processor.h +3 -0
@@ -112,6 +112,9 @@ struct cpuinfo_x86 {/* Cache QoS architectural values: */ int x86_cache_max_rmid;/* max index */ int x86_cache_occ_scale;/* scale to bytes */ +/* Cache Allocation Technology values */ +int x86_cat_cbmlength; +int x86_cat_closs;int x86_power;unsigned long loops_per_jiffy;/* cpuid returned max cores value: */
arch/x86/kernel/cpu/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \ perf_event_intel_uncore_nhmex.o endif +obj-$(CONFIG_CGROUP_CAT) +=intel_cat.o obj-$(CONFIG_X86_MCE) += mcheck/ obj-$(CONFIG_MTRR) += mtrr/
arch/x86/kernel/cpu/common.c +16 -0
@@ -668,6 +668,22 @@ void get_cpu_cap(struct cpuinfo_x86 *c) } } +/* Additional Intel-defined flags: level 0x00000010 */ +if (c->cpuid_level >=0x00000010 ) { +u32 eax, ebx, ecx, edx; + +cpuid_count (0x00000010 ,0 , &eax, &ebx, &ecx, &edx); + c->x86_capability[13 ] = ebx; + +if (cpu_has (c,X86_FEATURE_CAT ) && +cpu_has (c,X86_FEATURE_CAT_L3 )) { + +cpuid_count (0x00000010 ,1 , &eax, &ebx, &ecx, &edx); + c->x86_cat_closs = (edx &0xffff ) +1 ; + c->x86_cat_cbmlength = (eax &0xf ) +1 ; + } + } +/* AMD-defined flags: level 0x80000001 */ xlvl =cpuid_eax (0x80000000 ); c->extended_cpuid_level = xlvl;
arch/x86/kernel/cpu/intel_cat.c new file +51 -0
51 lines not on this page · raw message
init/Kconfig +11 -0
@@ -961,6 +961,17 @@ config CPUSETS Say N if unsure. +config CGROUP_CAT + bool "Cache Allocation Technology cgroup subsystem" + depends on X86_64 + help + This option provides framework to allocate cache lines when + applications fill cache. + This can be used by users to configure how much cache that can be + allocated to different PIDs. + + Say N if unsure. + config PROC_PID_CPUSET bool "Include legacy /proc/<pid>/cpuset file" depends on CPUSETS
Signature · 1 line
1.9.1
Re: [PATCH 1/6] x86/intel_cat: Intel Cache Allocation Technology detection
In reply to Vikas ShivappaQuoted 15 lines · Vikas Shivappa
This patch adds support for the new Cache Allocation Technology (CAT) feature found in future Intel Xeon processors. It includes CPUID enumeration routines for CAT and new values to track CAT resources to the
cpuinfo_x86structure.Cache Allocation Technology(CAT) provides a way for the Software (OS/VMM) to restrict cache allocation to a defined 'subset' of cache which may be overlapping with other 'subsets'. This feature is used when allocating a line in cache ie when pulling new data into the cache. The programming of the h/w is done via programming MSRs.
More information about CAT be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.15.
Signed-off-by Vikas Shivappa <[email protected]>
Quoted 9 lines
--- arch/x86/include/asm/cpufeature.h | 6 ++++- arch/x86/include/asm/processor.h | 3 +++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 16 ++++++++++++ arch/x86/kernel/cpu/intel_cat.c | 51 +++++++++++++++++++++++++++++++++++++++ init/Kconfig | 11 +++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/intel_cat.c
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
PATCH v3 2/6 x86/intel_cat: Adds support for Class of service management
In reply to Vikas ShivappaThis patch adds a cgroup subsystem to support cache allocation. When a CAT cgroup is created it has a CLOSid and CBM associated with it which are inherited from its parent. A Class of service(CLOS) in Cache Allocation is represented by a CLOSid. CLOSid is internal to the kernel and not exposed to user. Cache bitmask(CBM) represents one cache 'subset'. Root cgroup would have all available bits set for its CBM and would be assigned the CLOSid 0.
CLOSid allocation is tracked using a separate bitmap. The maximum number of CLOSids is specified by the h/w during CPUID enumeration and the kernel simply throws an -ENOSPC when it runs out of CLOSids.
Each CBM has an associated CLOSid. If multiple cgroups have the same CBM they would also have the same CLOSid. The reference count parameter in CLOSid-CBM map keeps track of how many cgroups are using each CLOSid<->CBM mapping.
--- arch/x86/include/asm/intel_cat.h | 40 +++++++++++++ arch/x86/kernel/cpu/intel_cat.c | 126 +++++++++++++++++++++++++++++++++++++-- include/linux/cgroup_subsys.h | 4 ++ 3 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 arch/x86/include/asm/intel_cat.h
arch/x86/include/asm/intel_cat.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _CAT_H_ +#define _CAT_H_ + +#ifdef CONFIG_CGROUP_CAT + +#include <linux/cgroup.h> + +struct cat_subsys_info { +/* Clos Bitmap to keep track of available CLOSids.*/ +unsigned long *closmap; +}; + +struct cache_alloc { +struct cgroup_subsys_state css; +/* Class of service for the cgroup.*/ +unsigned int clos; +/* Corresponding cache bit mask.*/ +unsigned long *cbm; +}; + +struct clos_cbm_map { +unsigned long cbm; +unsigned int cgrp_count; +}; + +/* +* Return cat group corresponding to this container. +*/ +static inline struct cache_alloc *css_cat (struct cgroup_subsys_state *css) +{ + return css ? container_of(css, struct cache_alloc, css) : NULL; +} + +static inline struct cache_alloc *parent_cat (struct cache_alloc *cq) +{ +return css_cat (cq->css.parent); +} + +#endif +#endif
arch/x86/kernel/cpu/intel_cat.c +121 -5
144 lines not on this page · raw message
include/linux/cgroup_subsys.h +4 -0
@@ -47,6 +47,10 @@ SUBSYS(net_prio) SUBSYS(hugetlb)#endif +#if IS_ENABLED (CONFIG_CGROUP_CAT ) +SUBSYS(cat) +#endif +/* * The following subsystems are not supported on the default hierarchy. */
Signature · 1 line
1.9.1
PATCH v3 3/6 x86/intel_cat: Support cache bit mask for Intel CAT
In reply to Vikas ShivappaAdd support for cache bit mask manipulation. The change adds a file to the CAT cgroup which represents the CBM for the cgroup.
The CAT cgroup follows cgroup hierarchy ,mkdir and adding tasks to the cgroup never fails. When a child cgroup is created it inherits the CLOSid and the CBM from its parent. When a user changes the default CBM for a cgroup, a new CLOSid may be allocated if the CBM was not used before. If the new CBM is the one that is already used, the reference for that CLOSid<->CBM is incremented. The changing of 'cbm' may fail with -ERRNOSPC once the kernel runs out of maximum CLOSids it can support.
User can create as many cgroups as he wants but having different CBMs at the same time is restricted by the maximum number of CLOSids (multiple cgroups can have the same CBM).
Kernel maintains a CLOSid<->cbm mapping which keeps reference counter for each cgroup using a CLOSid.
The tasks in the CAT cgroup would get to fill the LLC cache represented by the cgroup's 'cbm' file.
Reuse of CLOSids for cgroups with same bitmask also has following goodness:
- This helps to use the scant CLOSids optimally.
- This also implies that during context switch, write to PQR-MSR is done only when a task with a different bitmask is scheduled in.
--- arch/x86/include/asm/intel_cat.h | 3 + arch/x86/kernel/cpu/intel_cat.c | 155 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+)
arch/x86/include/asm/intel_cat.h +3 -0
@@ -4,6 +4,9 @@#ifdef CONFIG_CGROUP_CAT #include <linux/cgroup.h> +#define MAX_CBM_LENGTH 32 +#define IA32_L3_CBM_BASE 0xc90 +#define CBM_FROM_INDEX (x) (IA32_L3_CBM_BASE + x) struct cat_subsys_info {/* Clos Bitmap to keep track of available CLOSids.*/
arch/x86/kernel/cpu/intel_cat.c +155 -0
169 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 4/6 x86/intel_cat: Implement scheduling support for Intel CAT
In reply to Vikas ShivappaAdds support for IA32_PQR_ASSOC MSR writes during task scheduling.
The high 32 bits in the per processor MSR IA32_PQR_ASSOC represents the CLOSid. During context switch kernel implements this by writing the CLOSid of the cgroup to which the task belongs to the CPU's IA32_PQR_ASSOC MSR.
This would let the task fill in the cache 'subset' represented by the cgroup's Cache bit mask(CBM).
--- arch/x86/include/asm/intel_cat.h | 54 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/switch_to.h | 3 +++ arch/x86/kernel/cpu/intel_cat.c | 3 +++ kernel/sched/core.c | 1 + kernel/sched/sched.h | 3 +++ 5 files changed, 64 insertions(+)
arch/x86/include/asm/intel_cat.h +54 -0
@@ -4,9 +4,12 @@#ifdef CONFIG_CGROUP_CAT #include <linux/cgroup.h> +#define MSR_IA32_PQR_ASSOC 0xc8f#define MAX_CBM_LENGTH 32#define IA32_L3_CBM_BASE 0xc90#define CBM_FROM_INDEX (x) (IA32_L3_CBM_BASE + x) +DECLARE_PER_CPU(unsigned int, x86_cpu_clos); +extern struct static_key cat_enable_key; struct cat_subsys_info {/* Clos Bitmap to keep track of available CLOSids.*/
@@ -26,6 +29,11 @@ struct clos_cbm_map {unsigned int cgrp_count; }; +static inline bool cat_enabled (void ) +{ +return static_key_false (&cat_enable_key); +} +/* * Return cat group corresponding to this container. */
@@ -39,5 +47,51 @@ static inline struct cache_alloc *parent_cat(struct cache_alloc *cq)return css_cat (cq->css.parent); } +/* +* Return cat group to which this task belongs. +*/ +static inline struct cache_alloc *task_cat (struct task_struct *task) +{ +return css_cat (task_css (task, cat_cgrp_id)); +} + +/* +* cat_sched_in() - Writes the task's CLOSid to IA32_PQR_MSR +* if the current Closid is different than the new one. +*/ + +static inline void cat_sched_in (struct task_struct *task) +{ +struct cache_alloc *cq; +unsigned int clos; + +if (!cat_enabled ()) +return ; + +/* +* This needs to be fixed after CQM code stabilizes +* to cache the whole PQR instead of just CLOSid. +* PQR has closid in high 32 bits and CQM-RMID in low 10 bits. +* Should not write a 0 to the low 10 bits of PQR +* and corrupt RMID. +*/ + clos =this_cpu_read (x86_cpu_clos); + +rcu_read_lock (); + cq =task_cat (task); +if (cq->clos == clos) { +rcu_read_unlock (); +return ; + } + +wrmsr (MSR_IA32_PQR_ASSOC ,0 , cq->clos); +this_cpu_write (x86_cpu_clos, cq->clos); +rcu_read_unlock (); +} + +#else + +static inline void cat_sched_in (struct task_struct *task) {} +#endif #endif
arch/x86/include/asm/switch_to.h +3 -0
@@ -8,6 +8,9 @@ struct tss_struct;void __switch_to_xtra (struct task_struct *prev_p,struct task_struct *next_p,struct tss_struct *tss); +#include <asm/intel_cat.h> +#define post_arch_switch (current) cat_sched_in(current) +#ifdef CONFIG_X86_32 #ifdef CONFIG_CC_STACKPROTECTOR
arch/x86/kernel/cpu/intel_cat.c +3 -0
@@ -32,6 +32,8 @@ static struct clos_cbm_map *ccmap;static struct cat_subsys_info catss_info;static DEFINE_MUTEX (cat_group_mutex);struct cache_alloc cat_root_group; +struct static_key __read_mostly cat_enable_key =STATIC_KEY_INIT_FALSE ; +DEFINE_PER_CPU(unsigned int, x86_cpu_clos);#define cat_for_each_child (pos_css, parent_cq) \ css_for_each_child((pos_css), &(parent_cq)->css)
@@ -78,6 +80,7 @@ static int __init cat_late_init(void) ccm->cbm = (u32)((u64)(1 << cbm_len) -1 ); cat_root_group.cbm = &(ccm->cbm); ccm->cgrp_count++; +static_key_slow_inc (&cat_enable_key); }pr_info ("cbmlength:%u,Closs: %u\n" , cbm_len, maxid);
kernel/sched/core.c +1 -0
@@ -2249,6 +2249,7 @@ static struct rq *finish_task_switch(struct task_struct *prev) prev_state = prev->state;vtime_task_switch (prev);finish_arch_switch (prev); +post_arch_switch (current);perf_event_task_sched_in (prev, current);finish_lock_switch (rq, prev);finish_arch_post_lock_switch ();
kernel/sched/sched.h +3 -0
@@ -1008,6 +1008,9 @@ static inline int task_on_rq_migrating(struct task_struct *p)#ifndef finish_arch_switch# define finish_arch_switch (prev) do { } while (0)#endif +#ifndef post_arch_switch +# define post_arch_switch (current) do { } while (0) +#endif #ifndef finish_arch_post_lock_switch# define finish_arch_post_lock_switch () do { } while (0)#endif
Signature · 1 line
1.9.1
PATCH v3 5/6 x86/intel_rdt: Software Cache for IA32_PQR_MSR
In reply to Vikas ShivappaThis patch implements a common software cache for IA32_PQR_MSR(RMID 0:9,
CLOSId 32:63) to be used by both CMT and CAT. CMT updates the RMID
where as CAT updates the CLOSid in the software cache. When the new RMID/CLOSid value is different from the cached values, IA32_PQR_MSR is updated. Since the measured rdmsr latency for IA32_PQR_MSR is very high(~250 cycles) this software cache is necessary to avoid reading the MSR to compare the current CLOSid value.
--- arch/x86/include/asm/intel_cat.h | 36 ++++++++++++++++-------------- arch/x86/include/asm/rdt.h | 13 +++++++++++ arch/x86/kernel/cpu/perf_event_intel_cqm.c | 20 ++++++----------- 3 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 arch/x86/include/asm/rdt.h
arch/x86/include/asm/intel_cat.h +19 -17
@@ -4,11 +4,13 @@#ifdef CONFIG_CGROUP_CAT #include <linux/cgroup.h> -#define MSR_IA32_PQR_ASSOC 0xc8f -#define MAX_CBM_LENGTH 32 -#define IA32_L3_CBM_BASE 0xc90 +#include <asm/rdt.h> + +#define MAX_CBM_LENGTH 32 +#define IA32_L3_CBM_BASE 0xc90#define CBM_FROM_INDEX (x) (IA32_L3_CBM_BASE + x) -DECLARE_PER_CPU(unsigned int, x86_cpu_clos); + +DECLARE_PER_CPU(struct intel_pqr_state, pqr_state);extern struct static_key cat_enable_key; struct cat_subsys_info {
@@ -63,30 +65,30 @@ static inline struct cache_alloc *task_cat(struct task_struct *task)static inline void cat_sched_in (struct task_struct *task) {struct cache_alloc *cq; -unsigned int clos; +struct intel_pqr_state *state =this_cpu_ptr (&pqr_state); +unsigned long flags;if (!cat_enabled ())return ; -/* -* This needs to be fixed after CQM code stabilizes -* to cache the whole PQR instead of just CLOSid. -* PQR has closid in high 32 bits and CQM-RMID in low 10 bits. -* Should not write a 0 to the low 10 bits of PQR -* and corrupt RMID. -*/ - clos =this_cpu_read (x86_cpu_clos); - +raw_spin_lock_irqsave (&state->lock, flags);rcu_read_lock (); cq =task_cat (task); -if (cq->clos == clos) { +if (cq->clos == state->clos) {rcu_read_unlock (); +raw_spin_unlock_irqrestore (&state->lock, flags);return ; } -wrmsr (MSR_IA32_PQR_ASSOC ,0 , cq->clos); -this_cpu_write (x86_cpu_clos, cq->clos); +/* +* PQR has closid in high 32 bits and CQM-RMID +* in low 10 bits. Rewrite the exsting rmid from +* software cache. +*/ +wrmsr (MSR_IA32_PQR_ASSOC , state->rmid, cq->clos); + state->clos = cq->clos;rcu_read_unlock (); +raw_spin_unlock_irqrestore (&state->lock, flags); }#else
arch/x86/include/asm/rdt.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _X86_RDT_H_ +#define _X86_RDT_H_ + +#define MSR_IA32_PQR_ASSOC 0x0c8f + +struct intel_pqr_state { +raw_spinlock_t lock; +int rmid; +int clos; +int cnt; +}; + +#endif
arch/x86/kernel/cpu/perf_event_intel_cqm.c +7 -13
@@ -7,22 +7,16 @@#include <linux/perf_event.h> #include <linux/slab.h> #include <asm/cpu_device_id.h> +#include <asm/rdt.h> #include "perf_event.h" -#define MSR_IA32_PQR_ASSOC 0x0c8f#define MSR_IA32_QM_CTR 0x0c8e#define MSR_IA32_QM_EVTSEL 0x0c8dstatic unsigned int cqm_max_rmid =-1 ;static unsigned int cqm_l3_scale;/* supposedly cacheline size */ -struct intel_cqm_state { -raw_spinlock_t lock; -int rmid; -int cnt; -}; - -static DEFINE_PER_CPU(struct intel_cqm_state, cqm_state); +DEFINE_PER_CPU(struct intel_pqr_state, pqr_state);/* * Protects cache_cgroups and cqm_rmid_free_lru and cqm_rmid_limbo_lru.
@@ -931,7 +925,7 @@ out:static void intel_cqm_event_start (struct perf_event *event,int mode) { -struct intel_cqm_state *state =this_cpu_ptr (&cqm_state); +struct intel_pqr_state *state =this_cpu_ptr (&pqr_state);unsigned int rmid = event->hw.cqm_rmid;unsigned long flags;
@@ -948,14 +942,14 @@ static void intel_cqm_event_start(struct perf_event *event, int mode)WARN_ON_ONCE (state->rmid); state->rmid = rmid; -wrmsrl (MSR_IA32_PQR_ASSOC , state->rmid); +wrmsr (MSR_IA32_PQR_ASSOC , state->rmid, state->clos);raw_spin_unlock_irqrestore (&state->lock, flags); }static void intel_cqm_event_stop (struct perf_event *event,int mode) { -struct intel_cqm_state *state =this_cpu_ptr (&cqm_state); +struct intel_pqr_state *state =this_cpu_ptr (&pqr_state);unsigned long flags;if (event->hw.cqm_state &PERF_HES_STOPPED )
@@ -968,7 +962,7 @@ static void intel_cqm_event_stop(struct perf_event *event, int mode)if (!--state->cnt) { state->rmid =0 ; -wrmsrl (MSR_IA32_PQR_ASSOC ,0 ); +wrmsr (MSR_IA32_PQR_ASSOC ,0 , state->clos); }else {WARN_ON_ONCE (!state->rmid); }
@@ -1213,7 +1207,7 @@ static inline void cqm_pick_event_reader(int cpu)static void intel_cqm_cpu_prepare (unsigned int cpu) { -struct intel_cqm_state *state = &per_cpu (cqm_state, cpu); +struct intel_pqr_state *state = &per_cpu (pqr_state, cpu);struct cpuinfo_x86 *c = &cpu_data (cpu);raw_spin_lock_init (&state->lock);
Signature · 1 line
1.9.1
PATCH v3 6/6 x86/intel_cat: Intel haswell CAT enumeration
In reply to Vikas ShivappaCAT(Cache Allocation Technology) on hsw needs to be enumerated separately. CAT is only supported on certain HSW SKUs. This patch does a probe test for hsw CPUs by writing a CLOSid into high 32 bits of IA32_PQR_MSR and see if the bits stick. The probe test is only done after confirming that the CPU is HSW.
--- arch/x86/kernel/cpu/intel_cat.c | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
arch/x86/kernel/cpu/intel_cat.c +42 -0
@@ -38,11 +38,53 @@ DEFINE_PER_CPU(unsigned int, x86_cpu_clos);#define cat_for_each_child (pos_css, parent_cq) \ css_for_each_child((pos_css), &(parent_cq)->css) +/* +* hsw_probetest() - Have to do probe +* test for Intel haswell CPUs as it does not have +* CPUID enumeration support for CAT. +* +* Probes by writing to the high 32 bits(CLOSid) +* of the IA32_PQR_MSR and testing if the bits stick. +* Then hardcode the max CLOS and max bitmask length on hsw. +*/ + +static inline bool hsw_probetest (void ) +{ +u32 l, h_old, h_new, h_tmp; + +if (rdmsr_safe (MSR_IA32_PQR_ASSOC , &l, &h_old)) +return false; + +/* +* Default value is always 0 if feature is present. +*/ + h_tmp = h_old ^0x1U ; +if (wrmsr_safe (MSR_IA32_PQR_ASSOC , l, h_tmp) || +rdmsr_safe (MSR_IA32_PQR_ASSOC , &l, &h_new)) +return false; + +if (h_tmp != h_new) +return false; + +wrmsr_safe (MSR_IA32_PQR_ASSOC , l, h_old); + + boot_cpu_data.x86_cat_closs =4 ; + boot_cpu_data.x86_cat_cbmlength =20 ; + +return true; +} +static inline bool cat_supported (struct cpuinfo_x86 *c) {if (cpu_has (c,X86_FEATURE_CAT_L3 ))return true; +/* +* Probe test for Haswell CPUs. +*/ +if (c->x86 ==6 && c->x86_model ==0x3f ) +return hsw_probetest (); +return false; }
Signature · 1 line
1.9.1