x86: Add Cache QoS Monitoring (CQM) support
Subsystems (4)
cover x86: Add Cache QoS Monitoring (CQM) support
RFC: This is a work-in-progress patchset. Looking for general feedback on the approach and design of this changeset, especially since this is adding a new cgroup subsystem to present the data from this CPU feature.
This patchset adds support for the new Cache QoS Monitoring (CQM) feature found in future Intel Xeon processors.
CQM allows a process, or set of processes, to be tracked by the CPU to determine the cache usage of that task group. Using this data from the CPU, software can be written to extract this data and report cache usage and occupancy for a particular process, or group of processes.
More information about Cache QoS Monitoring can be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.14.
This series is also laying the framework for additional Platform QoS features in future Intel Xeon processors.
The CPU features themselves are relatively straight-forward, but the presentation of the data is less straight-forward. Since this tracks cache usage and occupancy per process (by swapping Resource Monitor IDs, or RMIDs, when processes are rescheduled), perf would not be a good fit for this data, which does not report on a per-process level. Therefore, a new cgroup subsystem, cacheqos, has been added. This operates very similarly to the cpu and cpuacct cgroup subsystems, where tasks can be grouped into sub-leaves of the root-level cgroup.
Peter P Waskiewicz Jr (3):
x86: Add support for Cache QoS Monitoring (CQM) detection
x86: Add Cache QoS Monitoring support to x86 perf uncore
cgroup: Add new cacheqos cgroup subsys to support Cache QoS Monitoring
RFC PATCH 1/3 x86: Add support for Cache QoS Monitoring (CQM) detection
This patch adds support for the new Cache QoS Monitoring (CQM) feature found in future Intel Xeon processors. It includes the new values to track CQM resources to the cpuinfo_x86 structure, plus the CPUID detection routines for CQM.
CQM allows a process, or set of processes, to be tracked by the CPU to determine the cache usage of that task group. Using this data from the CPU, software can be written to extract this data and report cache usage and occupancy for a particular process, or group of processes.
More information about Cache QoS Monitoring can be found in the Intel (R) x86 Architecture Software Developer Manual, section 17.14.
--- arch/x86/configs/x86_64_defconfig | 1 + arch/x86/include/asm/cpufeature.h | 9 ++++++++- arch/x86/include/asm/processor.h | 3 +++ arch/x86/kernel/cpu/common.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-)
arch/x86/configs/x86_64_defconfig +1 -0
@@ -14,6 +14,7 @@ CONFIG_LOG_BUF_SHIFT=18 CONFIG_CGROUPS=y CONFIG_CGROUP_FREEZER=y CONFIG_CPUSETS=y +CONFIG_CGROUP_CACHEQOS=y CONFIG_CGROUP_CPUACCT=y CONFIG_RESOURCE_COUNTERS=y CONFIG_CGROUP_SCHED=y
arch/x86/include/asm/cpufeature.h +8 -1
@@ -8,7 +8,7 @@#include <asm/required-features.h> #endif -#define NCAPINTS 10/* N 32-bit words worth of info */ +#define NCAPINTS 12/* N 32-bit words worth of info */ #define NBUGINTS 1/* N 32-bit bug flags */ /*
@@ -216,10 +216,17 @@#define X86_FEATURE_ERMS (9*32+ 9)/* Enhanced REP MOVSB/STOSB */ #define X86_FEATURE_INVPCID (9*32+10)/* Invalidate Processor Context ID */ #define X86_FEATURE_RTM (9*32+11)/* Restricted Transactional Memory */ +#define X86_FEATURE_CQM (9*32+12)/* Cache QoS Monitoring */ #define X86_FEATURE_RDSEED (9*32+18)/* The RDSEED instruction */ #define X86_FEATURE_ADX (9*32+19)/* The ADCX and ADOX instructions */ #define X86_FEATURE_SMAP (9*32+20)/* Supervisor Mode Access Prevention */ +/* Intel-defined CPU QoS Sub-leaf, CPUID level 0x0000000F:0 (edx), word 10 */ +#define X86_FEATURE_CQM_LLC (10*32+ 1)/* LLC QoS if 1 */ + +/* Intel-defined CPU QoS Sub-leaf, CPUID level 0x0000000F:1 (edx), word 11 */ +#define X86_FEATURE_CQM_OCCUP_LLC (11*32+ 0)/* LLC occupancy monitoring if 1 */ +/* * BUG word(s) */
arch/x86/include/asm/processor.h +3 -0
@@ -110,6 +110,9 @@ struct cpuinfo_x86 {/* in KB - valid for CPUS which support this call: */ int x86_cache_size;int x86_cache_alignment;/* In bytes */ +/* Cache QoS architectural values: */ +int x86_cache_max_rmid;/* max index */ +int x86_cache_occ_scale;/* scale to bytes */ int x86_power;unsigned long loops_per_jiffy;/* cpuid returned max cores value: */
arch/x86/kernel/cpu/common.c +39 -0
@@ -626,6 +626,30 @@ void get_cpu_cap(struct cpuinfo_x86 *c) c->x86_capability[9 ] = ebx; } +/* Additional Intel-defined flags: level 0x0000000F */ +if (c->cpuid_level >=0x0000000F ) { +u32 eax, ebx, ecx, edx; + +/* QoS sub-leaf, EAX=0Fh, ECX=0 */ +cpuid_count (0x0000000F ,0 , &eax, &ebx, &ecx, &edx); + c->x86_capability[10 ] = edx; +if (cpu_has (c,X86_FEATURE_CQM_LLC )) { +/* will be overridden if occupancy monitoring exists */ + c->x86_cache_max_rmid = ebx; + +/* QoS sub-leaf, EAX=0Fh, ECX=1 */ +cpuid_count (0x0000000F ,1 , &eax, &ebx, &ecx, &edx); + c->x86_capability[11 ] = edx; +if (cpu_has (c,X86_FEATURE_CQM_OCCUP_LLC )) { + c->x86_cache_max_rmid = ecx; + c->x86_cache_occ_scale = ebx; + } + }else { + c->x86_cache_max_rmid =-1 ; + c->x86_cache_occ_scale =-1 ; + } + } +/* AMD-defined flags: level 0x80000001 */ xlvl =cpuid_eax (0x80000000 ); c->extended_cpuid_level = xlvl;
@@ -814,6 +838,20 @@ static void generic_identify(struct cpuinfo_x86 *c)detect_nopl (c); } +static void x86_init_cache_qos (struct cpuinfo_x86 *c) +{ +/* +* The heavy lifting of max_rmid and cache_occ_scale are handled +* in get_cpu_cap(). Here we just set the max_rmid for the boot_cpu +* in case CQM bits really aren't there in this CPU. +*/ +if (c != &boot_cpu_data) { + boot_cpu_data.x86_cache_max_rmid = +min (boot_cpu_data.x86_cache_max_rmid, + c->x86_cache_max_rmid); + } +} +/* * This does the hard work of actually picking apart the CPU stuff... */
@@ -903,6 +941,7 @@ static void identify_cpu(struct cpuinfo_x86 *c)init_hypervisor (c);x86_init_rdrand (c); +x86_init_cache_qos (c);/* * Clear/Set all flags overriden by options, need do it
Signature · 1 line
1.8.3.1
RFC PATCH 2/3 x86: Add Cache QoS Monitoring support to x86 perf uncore
In reply to Peter P Waskiewicz JrThis patch adds the MSRs and masks for CQM to the x86 uncore.
The actual scheduling functions using the MSRs will be included in the next patch when the new cgroup subsystem is added, as there are dependencies on structs from the cgroup.
--- arch/x86/kernel/cpu/perf_event_intel_uncore.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_uncore.h +13 -0
@@ -412,6 +412,19 @@#define NHMEX_W_PMON_GLOBAL_FIXED_EN (1ULL << 31) +#ifdef CONFIG_CGROUP_CACHEQOS +/* Intel Cache QoS Monitoring uncore support */ +#define IA32_QM_EVTSEL 0xc8d +#define IA32_QM_CTR 0xc8e +#define IA32_PQR_ASSOC 0xc8f + +#define IA32_QM_EVTSEL_EVTID_READ_OCC 0x01 +#define IA32_QM_CTR_ERR (0x03llu << 62) +#define IA32_RMID_PQR_MASK 0x3ff +#define IA32_QM_EVTSEL_RMID_POSITION 32 + +#endif /* CONFIG_CGROUP_CACHEQOS */ +struct intel_uncore_ops ;struct intel_uncore_pmu ;struct intel_uncore_box ;
Signature · 1 line
1.8.3.1
RFC PATCH 3/3 cgroup: Add new cacheqos cgroup subsys to support Cache QoS Monitoring
In reply to Peter P Waskiewicz JrThis patch adds a new cgroup subsystem, named cacheqos. This cgroup controller is intended to manage task groups to track cache occupancy and usage of a CPU.
This patch also adds the scheduler functions to the Intel uncore events to implement Cache QoS Monitoring. This needs to be added along with the cgroup subsystem since events from the cgroup trigger when a task needs to be tracked on the underlying CPU.
The patch also adds the Kconfig option for enabling/disabling the CGROUP_CACHEQOS subsystem.
--- arch/x86/kernel/cpu/perf_event_intel_uncore.c | 52 ++++ include/linux/cgroup_subsys.h | 4 + include/linux/perf_event.h | 15 + init/Kconfig | 6 + kernel/sched/core.c | 432 ++++++++++++++++++++++++++ kernel/sched/sched.h | 55 ++++ 6 files changed, 564 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_uncore.c +52 -0
@@ -1633,6 +1633,58 @@ static struct intel_uncore_type *snb_msr_uncores[] = { };/* end of Sandy Bridge uncore support */ +#ifdef CONFIG_CGROUP_CACHEQOS + +/* needed for the cacheqos cgroup structs */ +#include "../../../kernel/sched/sched.h" + +void cacheqos_map_schedule_out (void ) +{ +/* +* cacheqos_map_schedule_in() will set the MSR correctly, but +* clearing the MSR here will prevent occupancy counts against this +* task during the context switch. In other words, this gives a +* "better" representation of what's happening in the cache. +*/ +wrmsrl (IA32_PQR_ASSOC ,0 ); +} + +void cacheqos_map_schedule_in (struct cacheqos *cq) +{ +u64 map; + + map = cq->rmid &IA32_RMID_PQR_MASK ; +wrmsrl (IA32_PQR_ASSOC , map); +} + +void cacheqos_read (void *arg) +{ +struct cacheqos *cq = arg; +u64 config; +u64 result =0 ; +int cpu, node; + + cpu =smp_processor_id (); + node =cpu_to_node (cpu); + + config = cq->rmid; + config = ((config &IA32_RMID_PQR_MASK ) << +IA32_QM_EVTSEL_RMID_POSITION ) | +IA32_QM_EVTSEL_EVTID_READ_OCC ; +wrmsrl (IA32_QM_EVTSEL , config); +rdmsrl (IA32_QM_CTR , result); + +/* place results in sys_wide_info area for recovery */ +if (result &IA32_QM_CTR_ERR ) + result =-1 ; +else + result &= ~IA32_QM_CTR_ERR ; + + cq->subsys_wide_info->node_results[node] = + result * cq->subsys_wide_info->cache_occ_scale; +} +#endif /* CONFIG_CGROUP_CACHEQOS */ +/* Nehalem uncore support */ static void nhm_uncore_msr_disable_box (struct intel_uncore_box *box) {
include/linux/cgroup_subsys.h +4 -0
@@ -50,6 +50,10 @@ SUBSYS(net_prio)#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_HUGETLB ) SUBSYS(hugetlb)#endif + +#if IS_SUBSYS_ENABLED (CONFIG_CGROUP_CACHEQOS ) +SUBSYS(cacheqos) +#endif /* * DO NOT ADD ANY SUBSYSTEM WITHOUT EXPLICIT ACKS FROM CGROUP MAINTAINERS. */
include/linux/perf_event.h +15 -0
@@ -670,12 +670,22 @@ perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) }extern struct static_key_deferred perf_sched_events; +#ifdef CONFIG_CGROUP_CACHEQOS +extern int cacheqos_cgroup_is_active; +inline void cacheqos_sched_out (void ); +inline void cacheqos_sched_in (struct task_struct *task); +#endif /* CONFIG_CGROUP_CACHEQOS */ static inline void perf_event_task_sched_in (struct task_struct *prev,struct task_struct *task) {if (static_key_false (&perf_sched_events.key))__perf_event_task_sched_in (prev, task); + +#ifdef CONFIG_CGROUP_CACHEQOS +if (cacheqos_cgroup_is_active) +cacheqos_sched_in (task); +#endif /* CONFIG_CGROUP_CACHEQOS */ } static inline void perf_event_task_sched_out(struct task_struct *prev,
@@ -685,6 +695,11 @@ static inline void perf_event_task_sched_out(struct task_struct *prev,if (static_key_false (&perf_sched_events.key))__perf_event_task_sched_out (prev, next); + +#ifdef CONFIG_CGROUP_CACHEQOS +if (cacheqos_cgroup_is_active) +cacheqos_sched_out (); +#endif /* CONFIG_CGROUP_CACHEQOS */ }extern void perf_event_mmap (struct vm_area_struct *vma);
init/Kconfig +6 -0
@@ -905,6 +905,12 @@ config PROC_PID_CPUSET depends on CPUSETS default y +config CGROUP_CACHEQOS + bool "Simple Cache QoS Monitoring cgroup subsystem" + help + Provides a simple Resource Controller for monitoring the + total cache occupancy by the tasks in a cgroup. + config CGROUP_CPUACCT bool "Simple CPU accounting cgroup subsystem" help
kernel/sched/core.c +432 -0
438 lines not on this page · raw message
kernel/sched/sched.h +55 -0
61 lines not on this page · raw message
Signature · 1 line
1.8.3.1