Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/intel_rdt: Pick up L3/L2 RDT parameters from CPUID

Define struct rdt_resource to hold all the parameterized values for an RDT
resource and fill in the CPUID enumerated values from leaf 0x10 if
available. Hard code them for the MSR detected Haswells.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Cc: "Ravi V Shankar" <ravi.v.shankar@intel.com>
Cc: "Tony Luck" <tony.luck@intel.com>
Cc: "David Carrillo-Cisneros" <davidcc@google.com>
Cc: "Sai Prakhya" <sai.praneeth.prakhya@intel.com>
Cc: "Peter Zijlstra" <peterz@infradead.org>
Cc: "Stephane Eranian" <eranian@google.com>
Cc: "Dave Hansen" <dave.hansen@intel.com>
Cc: "Shaohua Li" <shli@fb.com>
Cc: "Nilay Vaish" <nilayvaish@gmail.com>
Cc: "Vikas Shivappa" <vikas.shivappa@linux.intel.com>
Cc: "Ingo Molnar" <mingo@elte.hu>
Cc: "Borislav Petkov" <bp@suse.de>
Cc: "H. Peter Anvin" <h.peter.anvin@intel.com>
Link: http://lkml.kernel.org/r/1477142405-32078-9-git-send-email-fenghua.yu@intel.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

Fenghua Yu and committed by
Thomas Gleixner
c1c7c3f9 113c6097

+172 -7
+68
arch/x86/include/asm/intel_rdt.h
··· 2 2 #define _ASM_X86_INTEL_RDT_H 3 3 4 4 #define IA32_L3_CBM_BASE 0xc90 5 + #define IA32_L2_CBM_BASE 0xd10 5 6 7 + /** 8 + * struct rdt_resource - attributes of an RDT resource 9 + * @enabled: Is this feature enabled on this machine 10 + * @capable: Is this feature available on this machine 11 + * @name: Name to use in "schemata" file 12 + * @num_closid: Number of CLOSIDs available 13 + * @max_cbm: Largest Cache Bit Mask allowed 14 + * @min_cbm_bits: Minimum number of consecutive bits to be set 15 + * in a cache bit mask 16 + * @domains: All domains for this resource 17 + * @num_domains: Number of domains active 18 + * @msr_base: Base MSR address for CBMs 19 + * @tmp_cbms: Scratch space when updating schemata 20 + * @cache_level: Which cache level defines scope of this domain 21 + * @cbm_idx_multi: Multiplier of CBM index 22 + * @cbm_idx_offset: Offset of CBM index. CBM index is computed by: 23 + * closid * cbm_idx_multi + cbm_idx_offset 24 + */ 25 + struct rdt_resource { 26 + bool enabled; 27 + bool capable; 28 + char *name; 29 + int num_closid; 30 + int cbm_len; 31 + int min_cbm_bits; 32 + u32 max_cbm; 33 + struct list_head domains; 34 + int num_domains; 35 + int msr_base; 36 + u32 *tmp_cbms; 37 + int cache_level; 38 + int cbm_idx_multi; 39 + int cbm_idx_offset; 40 + }; 41 + 42 + extern struct rdt_resource rdt_resources_all[]; 43 + 44 + enum { 45 + RDT_RESOURCE_L3, 46 + RDT_RESOURCE_L3DATA, 47 + RDT_RESOURCE_L3CODE, 48 + RDT_RESOURCE_L2, 49 + 50 + /* Must be the last */ 51 + RDT_NUM_RESOURCES, 52 + }; 53 + 54 + #define for_each_capable_rdt_resource(r) \ 55 + for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ 56 + r++) \ 57 + if (r->capable) 58 + 59 + /* CPUID.(EAX=10H, ECX=ResID=1).EAX */ 60 + union cpuid_0x10_1_eax { 61 + struct { 62 + unsigned int cbm_len:5; 63 + } split; 64 + unsigned int full; 65 + }; 66 + 67 + /* CPUID.(EAX=10H, ECX=ResID=1).EDX */ 68 + union cpuid_0x10_1_edx { 69 + struct { 70 + unsigned int cos_max:16; 71 + } split; 72 + unsigned int full; 73 + }; 6 74 #endif /* _ASM_X86_INTEL_RDT_H */
+104 -7
arch/x86/kernel/cpu/intel_rdt.c
··· 31 31 #include <asm/intel-family.h> 32 32 #include <asm/intel_rdt.h> 33 33 34 + #define domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].domains) 35 + 36 + struct rdt_resource rdt_resources_all[] = { 37 + { 38 + .name = "L3", 39 + .domains = domain_init(RDT_RESOURCE_L3), 40 + .msr_base = IA32_L3_CBM_BASE, 41 + .min_cbm_bits = 1, 42 + .cache_level = 3, 43 + .cbm_idx_multi = 1, 44 + .cbm_idx_offset = 0 45 + }, 46 + { 47 + .name = "L3DATA", 48 + .domains = domain_init(RDT_RESOURCE_L3DATA), 49 + .msr_base = IA32_L3_CBM_BASE, 50 + .min_cbm_bits = 1, 51 + .cache_level = 3, 52 + .cbm_idx_multi = 2, 53 + .cbm_idx_offset = 0 54 + }, 55 + { 56 + .name = "L3CODE", 57 + .domains = domain_init(RDT_RESOURCE_L3CODE), 58 + .msr_base = IA32_L3_CBM_BASE, 59 + .min_cbm_bits = 1, 60 + .cache_level = 3, 61 + .cbm_idx_multi = 2, 62 + .cbm_idx_offset = 1 63 + }, 64 + { 65 + .name = "L2", 66 + .domains = domain_init(RDT_RESOURCE_L2), 67 + .msr_base = IA32_L2_CBM_BASE, 68 + .min_cbm_bits = 1, 69 + .cache_level = 2, 70 + .cbm_idx_multi = 1, 71 + .cbm_idx_offset = 0 72 + }, 73 + }; 74 + 34 75 /* 35 76 * cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs 36 77 * as they do not have CPUID enumeration support for Cache allocation. ··· 95 54 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && 96 55 boot_cpu_data.x86 == 6 && 97 56 boot_cpu_data.x86_model == INTEL_FAM6_HASWELL_X) { 57 + struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3]; 98 58 u32 l, h, max_cbm = BIT_MASK(20) - 1; 99 59 100 60 if (wrmsr_safe(IA32_L3_CBM_BASE, max_cbm, 0)) ··· 103 61 rdmsr(IA32_L3_CBM_BASE, l, h); 104 62 105 63 /* If all the bits were set in MSR, return success */ 106 - return l == max_cbm; 64 + if (l != max_cbm) 65 + return false; 66 + 67 + r->num_closid = 4; 68 + r->cbm_len = 20; 69 + r->max_cbm = max_cbm; 70 + r->min_cbm_bits = 2; 71 + r->capable = true; 72 + r->enabled = true; 73 + 74 + return true; 107 75 } 108 76 109 77 return false; 110 78 } 111 79 80 + static void rdt_get_config(int idx, struct rdt_resource *r) 81 + { 82 + union cpuid_0x10_1_eax eax; 83 + union cpuid_0x10_1_edx edx; 84 + u32 ebx, ecx; 85 + 86 + cpuid_count(0x00000010, idx, &eax.full, &ebx, &ecx, &edx.full); 87 + r->num_closid = edx.split.cos_max + 1; 88 + r->cbm_len = eax.split.cbm_len + 1; 89 + r->max_cbm = BIT_MASK(eax.split.cbm_len + 1) - 1; 90 + r->capable = true; 91 + r->enabled = true; 92 + } 93 + 94 + static void rdt_get_cdp_l3_config(int type) 95 + { 96 + struct rdt_resource *r_l3 = &rdt_resources_all[RDT_RESOURCE_L3]; 97 + struct rdt_resource *r = &rdt_resources_all[type]; 98 + 99 + r->num_closid = r_l3->num_closid / 2; 100 + r->cbm_len = r_l3->cbm_len; 101 + r->max_cbm = r_l3->max_cbm; 102 + r->capable = true; 103 + /* 104 + * By default, CDP is disabled. CDP can be enabled by mount parameter 105 + * "cdp" during resctrl file system mount time. 106 + */ 107 + r->enabled = false; 108 + } 109 + 112 110 static inline bool get_rdt_resources(void) 113 111 { 112 + bool ret = false; 113 + 114 114 if (cache_alloc_hsw_probe()) 115 115 return true; 116 116 117 117 if (!boot_cpu_has(X86_FEATURE_RDT_A)) 118 118 return false; 119 - if (!boot_cpu_has(X86_FEATURE_CAT_L3)) 120 - return false; 121 119 122 - return true; 120 + if (boot_cpu_has(X86_FEATURE_CAT_L3)) { 121 + rdt_get_config(1, &rdt_resources_all[RDT_RESOURCE_L3]); 122 + if (boot_cpu_has(X86_FEATURE_CDP_L3)) { 123 + rdt_get_cdp_l3_config(RDT_RESOURCE_L3DATA); 124 + rdt_get_cdp_l3_config(RDT_RESOURCE_L3CODE); 125 + } 126 + ret = true; 127 + } 128 + if (boot_cpu_has(X86_FEATURE_CAT_L2)) { 129 + /* CPUID 0x10.2 fields are same format at 0x10.1 */ 130 + rdt_get_config(2, &rdt_resources_all[RDT_RESOURCE_L2]); 131 + ret = true; 132 + } 133 + 134 + return ret; 123 135 } 124 136 125 137 static int __init intel_rdt_late_init(void) 126 138 { 139 + struct rdt_resource *r; 140 + 127 141 if (!get_rdt_resources()) 128 142 return -ENODEV; 129 143 130 - pr_info("Intel RDT cache allocation detected\n"); 131 - if (boot_cpu_has(X86_FEATURE_CDP_L3)) 132 - pr_info("Intel RDT code data prioritization detected\n"); 144 + for_each_capable_rdt_resource(r) 145 + pr_info("Intel RDT %s allocation detected\n", r->name); 133 146 134 147 return 0; 135 148 }