Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_INTEL_RDT_H |
| 2 | #define _ASM_X86_INTEL_RDT_H |
| 3 | |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 4 | #include <linux/jump_label.h> |
| 5 | |
| 6 | #define IA32_L3_QOS_CFG 0xc81 |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 7 | #define IA32_L3_CBM_BASE 0xc90 |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 8 | #define IA32_L2_CBM_BASE 0xd10 |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 9 | |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 10 | #define L3_QOS_CDP_ENABLE 0x01ULL |
| 11 | |
| 12 | /** |
| 13 | * struct rdtgroup - store rdtgroup's data in resctrl file system. |
| 14 | * @kn: kernfs node |
| 15 | * @rdtgroup_list: linked list for all rdtgroups |
| 16 | * @closid: closid for this rdtgroup |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame^] | 17 | * @cpu_mask: CPUs assigned to this rdtgroup |
Fenghua Yu | 60cf5e1 | 2016-10-28 15:04:44 -0700 | [diff] [blame] | 18 | * @flags: status bits |
| 19 | * @waitcount: how many cpus expect to find this |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame^] | 20 | * group when they acquire rdtgroup_mutex |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 21 | */ |
| 22 | struct rdtgroup { |
| 23 | struct kernfs_node *kn; |
| 24 | struct list_head rdtgroup_list; |
| 25 | int closid; |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame^] | 26 | struct cpumask cpu_mask; |
Fenghua Yu | 60cf5e1 | 2016-10-28 15:04:44 -0700 | [diff] [blame] | 27 | int flags; |
| 28 | atomic_t waitcount; |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
Fenghua Yu | 60cf5e1 | 2016-10-28 15:04:44 -0700 | [diff] [blame] | 31 | /* rdtgroup.flags */ |
| 32 | #define RDT_DELETED 1 |
| 33 | |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 34 | /* List of all resource groups */ |
| 35 | extern struct list_head rdt_all_groups; |
| 36 | |
| 37 | int __init rdtgroup_init(void); |
| 38 | |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 39 | /** |
Fenghua Yu | 4e978d0 | 2016-10-28 15:04:43 -0700 | [diff] [blame] | 40 | * struct rftype - describe each file in the resctrl file system |
| 41 | * @name: file name |
| 42 | * @mode: access mode |
| 43 | * @kf_ops: operations |
| 44 | * @seq_show: show content of the file |
| 45 | * @write: write to the file |
| 46 | */ |
| 47 | struct rftype { |
| 48 | char *name; |
| 49 | umode_t mode; |
| 50 | struct kernfs_ops *kf_ops; |
| 51 | |
| 52 | int (*seq_show)(struct kernfs_open_file *of, |
| 53 | struct seq_file *sf, void *v); |
| 54 | /* |
| 55 | * write() is the generic write callback which maps directly to |
| 56 | * kernfs write operation and overrides all other operations. |
| 57 | * Maximum write size is determined by ->max_write_len. |
| 58 | */ |
| 59 | ssize_t (*write)(struct kernfs_open_file *of, |
| 60 | char *buf, size_t nbytes, loff_t off); |
| 61 | }; |
| 62 | |
| 63 | /** |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 64 | * struct rdt_resource - attributes of an RDT resource |
| 65 | * @enabled: Is this feature enabled on this machine |
| 66 | * @capable: Is this feature available on this machine |
| 67 | * @name: Name to use in "schemata" file |
| 68 | * @num_closid: Number of CLOSIDs available |
| 69 | * @max_cbm: Largest Cache Bit Mask allowed |
| 70 | * @min_cbm_bits: Minimum number of consecutive bits to be set |
| 71 | * in a cache bit mask |
| 72 | * @domains: All domains for this resource |
| 73 | * @num_domains: Number of domains active |
| 74 | * @msr_base: Base MSR address for CBMs |
| 75 | * @tmp_cbms: Scratch space when updating schemata |
| 76 | * @cache_level: Which cache level defines scope of this domain |
| 77 | * @cbm_idx_multi: Multiplier of CBM index |
| 78 | * @cbm_idx_offset: Offset of CBM index. CBM index is computed by: |
| 79 | * closid * cbm_idx_multi + cbm_idx_offset |
| 80 | */ |
| 81 | struct rdt_resource { |
| 82 | bool enabled; |
| 83 | bool capable; |
| 84 | char *name; |
| 85 | int num_closid; |
| 86 | int cbm_len; |
| 87 | int min_cbm_bits; |
| 88 | u32 max_cbm; |
| 89 | struct list_head domains; |
| 90 | int num_domains; |
| 91 | int msr_base; |
| 92 | u32 *tmp_cbms; |
| 93 | int cache_level; |
| 94 | int cbm_idx_multi; |
| 95 | int cbm_idx_offset; |
| 96 | }; |
| 97 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 98 | /** |
| 99 | * struct rdt_domain - group of cpus sharing an RDT resource |
| 100 | * @list: all instances of this resource |
| 101 | * @id: unique id for this instance |
| 102 | * @cpu_mask: which cpus share this resource |
| 103 | * @cbm: array of cache bit masks (indexed by CLOSID) |
| 104 | */ |
| 105 | struct rdt_domain { |
| 106 | struct list_head list; |
| 107 | int id; |
| 108 | struct cpumask cpu_mask; |
| 109 | u32 *cbm; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * struct msr_param - set a range of MSRs from a domain |
| 114 | * @res: The resource to use |
| 115 | * @low: Beginning index from base MSR |
| 116 | * @high: End index |
| 117 | */ |
| 118 | struct msr_param { |
| 119 | struct rdt_resource *res; |
| 120 | int low; |
| 121 | int high; |
| 122 | }; |
| 123 | |
| 124 | extern struct mutex rdtgroup_mutex; |
| 125 | |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 126 | extern struct rdt_resource rdt_resources_all[]; |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 127 | extern struct rdtgroup rdtgroup_default; |
| 128 | DECLARE_STATIC_KEY_FALSE(rdt_enable_key); |
| 129 | |
| 130 | int __init rdtgroup_init(void); |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 131 | |
| 132 | enum { |
| 133 | RDT_RESOURCE_L3, |
| 134 | RDT_RESOURCE_L3DATA, |
| 135 | RDT_RESOURCE_L3CODE, |
| 136 | RDT_RESOURCE_L2, |
| 137 | |
| 138 | /* Must be the last */ |
| 139 | RDT_NUM_RESOURCES, |
| 140 | }; |
| 141 | |
| 142 | #define for_each_capable_rdt_resource(r) \ |
| 143 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ |
| 144 | r++) \ |
| 145 | if (r->capable) |
| 146 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 147 | #define for_each_enabled_rdt_resource(r) \ |
| 148 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ |
| 149 | r++) \ |
| 150 | if (r->enabled) |
| 151 | |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 152 | /* CPUID.(EAX=10H, ECX=ResID=1).EAX */ |
| 153 | union cpuid_0x10_1_eax { |
| 154 | struct { |
| 155 | unsigned int cbm_len:5; |
| 156 | } split; |
| 157 | unsigned int full; |
| 158 | }; |
| 159 | |
| 160 | /* CPUID.(EAX=10H, ECX=ResID=1).EDX */ |
| 161 | union cpuid_0x10_1_edx { |
| 162 | struct { |
| 163 | unsigned int cos_max:16; |
| 164 | } split; |
| 165 | unsigned int full; |
| 166 | }; |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 167 | |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame^] | 168 | DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid); |
| 169 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 170 | void rdt_cbm_update(void *arg); |
Fenghua Yu | 60cf5e1 | 2016-10-28 15:04:44 -0700 | [diff] [blame] | 171 | struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn); |
| 172 | void rdtgroup_kn_unlock(struct kernfs_node *kn); |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 173 | #endif /* _ASM_X86_INTEL_RDT_H */ |