]>
Commit | Line | Data |
---|---|---|
113c6097 FY |
1 | #ifndef _ASM_X86_INTEL_RDT_H |
2 | #define _ASM_X86_INTEL_RDT_H | |
3 | ||
5b825c3a | 4 | #include <linux/sched.h> |
8ff42c02 | 5 | #include <linux/kernfs.h> |
5ff193fb FY |
6 | #include <linux/jump_label.h> |
7 | ||
8 | #define IA32_L3_QOS_CFG 0xc81 | |
113c6097 | 9 | #define IA32_L3_CBM_BASE 0xc90 |
c1c7c3f9 | 10 | #define IA32_L2_CBM_BASE 0xd10 |
05b93417 | 11 | #define IA32_MBA_THRTL_BASE 0xd50 |
113c6097 | 12 | |
5ff193fb FY |
13 | #define L3_QOS_CDP_ENABLE 0x01ULL |
14 | ||
6a445edc VS |
15 | /* |
16 | * Event IDs are used to program IA32_QM_EVTSEL before reading event | |
17 | * counter from IA32_QM_CTR | |
18 | */ | |
19 | #define QOS_L3_OCCUP_EVENT_ID 0x01 | |
20 | #define QOS_L3_MBM_TOTAL_EVENT_ID 0x02 | |
21 | #define QOS_L3_MBM_LOCAL_EVENT_ID 0x03 | |
edf6fa1c VS |
22 | #define RMID_VAL_ERROR BIT_ULL(63) |
23 | #define RMID_VAL_UNAVAIL BIT_ULL(62) | |
6a445edc VS |
24 | |
25 | /** | |
26 | * struct mon_evt - Entry in the event list of a resource | |
27 | * @evtid: event id | |
28 | * @name: name of the event | |
29 | */ | |
30 | struct mon_evt { | |
31 | u32 evtid; | |
32 | char *name; | |
33 | struct list_head list; | |
34 | }; | |
35 | ||
36 | extern unsigned int intel_cqm_threshold; | |
37 | extern bool rdt_alloc_capable; | |
38 | extern bool rdt_mon_capable; | |
39 | extern unsigned int rdt_mon_features; | |
5ff193fb FY |
40 | /** |
41 | * struct rdtgroup - store rdtgroup's data in resctrl file system. | |
42 | * @kn: kernfs node | |
43 | * @rdtgroup_list: linked list for all rdtgroups | |
44 | * @closid: closid for this rdtgroup | |
12e0110c | 45 | * @cpu_mask: CPUs assigned to this rdtgroup |
60cf5e10 FY |
46 | * @flags: status bits |
47 | * @waitcount: how many cpus expect to find this | |
12e0110c | 48 | * group when they acquire rdtgroup_mutex |
5ff193fb FY |
49 | */ |
50 | struct rdtgroup { | |
51 | struct kernfs_node *kn; | |
52 | struct list_head rdtgroup_list; | |
53 | int closid; | |
12e0110c | 54 | struct cpumask cpu_mask; |
60cf5e10 FY |
55 | int flags; |
56 | atomic_t waitcount; | |
5ff193fb FY |
57 | }; |
58 | ||
60cf5e10 FY |
59 | /* rdtgroup.flags */ |
60 | #define RDT_DELETED 1 | |
61 | ||
4ffa3c97 JO |
62 | /* rftype.flags */ |
63 | #define RFTYPE_FLAGS_CPUS_LIST 1 | |
64 | ||
5dc1d5c6 TL |
65 | /* |
66 | * Define the file type flags for base and info directories. | |
67 | */ | |
68 | #define RFTYPE_INFO BIT(0) | |
69 | #define RFTYPE_BASE BIT(1) | |
70 | #define RF_CTRLSHIFT 4 | |
71 | #define RFTYPE_CTRL BIT(RF_CTRLSHIFT) | |
72 | #define RFTYPE_RES_CACHE BIT(8) | |
73 | #define RFTYPE_RES_MB BIT(9) | |
74 | #define RF_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL) | |
75 | #define RF_CTRL_BASE (RFTYPE_BASE | RFTYPE_CTRL) | |
76 | ||
5ff193fb FY |
77 | /* List of all resource groups */ |
78 | extern struct list_head rdt_all_groups; | |
79 | ||
de016df8 VS |
80 | extern int max_name_width, max_data_width; |
81 | ||
5ff193fb FY |
82 | int __init rdtgroup_init(void); |
83 | ||
4e978d06 FY |
84 | /** |
85 | * struct rftype - describe each file in the resctrl file system | |
17f8ba1d TG |
86 | * @name: File name |
87 | * @mode: Access mode | |
88 | * @kf_ops: File operations | |
4ffa3c97 | 89 | * @flags: File specific RFTYPE_FLAGS_* flags |
5dc1d5c6 | 90 | * @fflags: File specific RF_* or RFTYPE_* flags |
17f8ba1d TG |
91 | * @seq_show: Show content of the file |
92 | * @write: Write to the file | |
4e978d06 FY |
93 | */ |
94 | struct rftype { | |
95 | char *name; | |
96 | umode_t mode; | |
97 | struct kernfs_ops *kf_ops; | |
4ffa3c97 | 98 | unsigned long flags; |
5dc1d5c6 | 99 | unsigned long fflags; |
4e978d06 FY |
100 | |
101 | int (*seq_show)(struct kernfs_open_file *of, | |
102 | struct seq_file *sf, void *v); | |
103 | /* | |
104 | * write() is the generic write callback which maps directly to | |
105 | * kernfs write operation and overrides all other operations. | |
106 | * Maximum write size is determined by ->max_write_len. | |
107 | */ | |
108 | ssize_t (*write)(struct kernfs_open_file *of, | |
109 | char *buf, size_t nbytes, loff_t off); | |
110 | }; | |
111 | ||
0921c547 TG |
112 | /** |
113 | * struct rdt_domain - group of cpus sharing an RDT resource | |
114 | * @list: all instances of this resource | |
115 | * @id: unique id for this instance | |
116 | * @cpu_mask: which cpus share this resource | |
edf6fa1c VS |
117 | * @rmid_busy_llc: |
118 | * bitmap of which limbo RMIDs are above threshold | |
0921c547 TG |
119 | * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) |
120 | * @new_ctrl: new ctrl value to be loaded | |
121 | * @have_new_ctrl: did user provide new_ctrl for this domain | |
122 | */ | |
123 | struct rdt_domain { | |
124 | struct list_head list; | |
125 | int id; | |
126 | struct cpumask cpu_mask; | |
edf6fa1c | 127 | unsigned long *rmid_busy_llc; |
0921c547 TG |
128 | u32 *ctrl_val; |
129 | u32 new_ctrl; | |
130 | bool have_new_ctrl; | |
131 | }; | |
132 | ||
133 | /** | |
134 | * struct msr_param - set a range of MSRs from a domain | |
135 | * @res: The resource to use | |
136 | * @low: Beginning index from base MSR | |
137 | * @high: End index | |
138 | */ | |
139 | struct msr_param { | |
140 | struct rdt_resource *res; | |
141 | int low; | |
142 | int high; | |
143 | }; | |
144 | ||
d3e11b4d TG |
145 | /** |
146 | * struct rdt_cache - Cache allocation related data | |
147 | * @cbm_len: Length of the cache bit mask | |
148 | * @min_cbm_bits: Minimum number of consecutive bits to be set | |
149 | * @cbm_idx_mult: Multiplier of CBM index | |
150 | * @cbm_idx_offset: Offset of CBM index. CBM index is computed by: | |
151 | * closid * cbm_idx_multi + cbm_idx_offset | |
152 | * in a cache bit mask | |
153 | */ | |
154 | struct rdt_cache { | |
155 | unsigned int cbm_len; | |
156 | unsigned int min_cbm_bits; | |
157 | unsigned int cbm_idx_mult; | |
158 | unsigned int cbm_idx_offset; | |
159 | }; | |
160 | ||
05b93417 VS |
161 | /** |
162 | * struct rdt_membw - Memory bandwidth allocation related data | |
163 | * @max_delay: Max throttle delay. Delay is the hardware | |
164 | * representation for memory bandwidth. | |
165 | * @min_bw: Minimum memory bandwidth percentage user can request | |
166 | * @bw_gran: Granularity at which the memory bandwidth is allocated | |
167 | * @delay_linear: True if memory B/W delay is in linear scale | |
168 | * @mb_map: Mapping of memory B/W percentage to memory B/W delay | |
169 | */ | |
170 | struct rdt_membw { | |
171 | u32 max_delay; | |
172 | u32 min_bw; | |
173 | u32 bw_gran; | |
174 | u32 delay_linear; | |
175 | u32 *mb_map; | |
176 | }; | |
177 | ||
6a445edc VS |
178 | static inline bool is_llc_occupancy_enabled(void) |
179 | { | |
180 | return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID)); | |
181 | } | |
182 | ||
c1c7c3f9 FY |
183 | /** |
184 | * struct rdt_resource - attributes of an RDT resource | |
1b5c0b75 | 185 | * @alloc_enabled: Is allocation enabled on this machine |
6a445edc | 186 | * @mon_enabled: Is monitoring enabled for this feature |
1b5c0b75 | 187 | * @alloc_capable: Is allocation available on this machine |
6a445edc | 188 | * @mon_capable: Is monitor feature available on this machine |
d3e11b4d TG |
189 | * @name: Name to use in "schemata" file |
190 | * @num_closid: Number of CLOSIDs available | |
191 | * @cache_level: Which cache level defines scope of this resource | |
192 | * @default_ctrl: Specifies default cache cbm or memory B/W percent. | |
193 | * @msr_base: Base MSR address for CBMs | |
0921c547 | 194 | * @msr_update: Function pointer to update QOS MSRs |
d3e11b4d TG |
195 | * @data_width: Character width of data when displaying |
196 | * @domains: All domains for this resource | |
197 | * @cache: Cache allocation related data | |
c6ea67de VS |
198 | * @format_str: Per resource format string to show domain value |
199 | * @parse_ctrlval: Per resource function pointer to parse control values | |
6a445edc VS |
200 | * @evt_list: List of monitoring events |
201 | * @num_rmid: Number of RMIDs available | |
202 | * @mon_scale: cqm counter * mon_scale = occupancy in bytes | |
5dc1d5c6 | 203 | * @fflags: flags to choose base and info files |
c1c7c3f9 FY |
204 | */ |
205 | struct rdt_resource { | |
1b5c0b75 | 206 | bool alloc_enabled; |
6a445edc | 207 | bool mon_enabled; |
1b5c0b75 | 208 | bool alloc_capable; |
6a445edc | 209 | bool mon_capable; |
c1c7c3f9 FY |
210 | char *name; |
211 | int num_closid; | |
d3e11b4d | 212 | int cache_level; |
2545e9f5 | 213 | u32 default_ctrl; |
d3e11b4d | 214 | unsigned int msr_base; |
0921c547 TG |
215 | void (*msr_update) (struct rdt_domain *d, struct msr_param *m, |
216 | struct rdt_resource *r); | |
de016df8 | 217 | int data_width; |
c1c7c3f9 | 218 | struct list_head domains; |
a83827d0 TG |
219 | struct rdt_cache cache; |
220 | struct rdt_membw membw; | |
c6ea67de VS |
221 | const char *format_str; |
222 | int (*parse_ctrlval) (char *buf, struct rdt_resource *r, | |
223 | struct rdt_domain *d); | |
6a445edc VS |
224 | struct list_head evt_list; |
225 | int num_rmid; | |
226 | unsigned int mon_scale; | |
5dc1d5c6 | 227 | unsigned long fflags; |
c1c7c3f9 FY |
228 | }; |
229 | ||
c6ea67de | 230 | int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d); |
64e8ed3d | 231 | int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d); |
6a507a6a | 232 | |
2264d9c7 TL |
233 | extern struct mutex rdtgroup_mutex; |
234 | ||
c1c7c3f9 | 235 | extern struct rdt_resource rdt_resources_all[]; |
5ff193fb | 236 | extern struct rdtgroup rdtgroup_default; |
1b5c0b75 | 237 | DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); |
5ff193fb FY |
238 | |
239 | int __init rdtgroup_init(void); | |
c1c7c3f9 FY |
240 | |
241 | enum { | |
242 | RDT_RESOURCE_L3, | |
243 | RDT_RESOURCE_L3DATA, | |
244 | RDT_RESOURCE_L3CODE, | |
245 | RDT_RESOURCE_L2, | |
05b93417 | 246 | RDT_RESOURCE_MBA, |
c1c7c3f9 FY |
247 | |
248 | /* Must be the last */ | |
249 | RDT_NUM_RESOURCES, | |
250 | }; | |
251 | ||
1b5c0b75 | 252 | #define for_each_alloc_capable_rdt_resource(r) \ |
c1c7c3f9 | 253 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ |
17f8ba1d | 254 | r++) \ |
1b5c0b75 | 255 | if (r->alloc_capable) |
c1c7c3f9 | 256 | |
6a445edc VS |
257 | #define for_each_mon_capable_rdt_resource(r) \ |
258 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ | |
259 | r++) \ | |
260 | if (r->mon_capable) | |
261 | ||
1b5c0b75 | 262 | #define for_each_alloc_enabled_rdt_resource(r) \ |
2264d9c7 TL |
263 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ |
264 | r++) \ | |
1b5c0b75 | 265 | if (r->alloc_enabled) |
2264d9c7 | 266 | |
c1c7c3f9 FY |
267 | /* CPUID.(EAX=10H, ECX=ResID=1).EAX */ |
268 | union cpuid_0x10_1_eax { | |
269 | struct { | |
270 | unsigned int cbm_len:5; | |
271 | } split; | |
272 | unsigned int full; | |
273 | }; | |
274 | ||
ab66a33b VS |
275 | /* CPUID.(EAX=10H, ECX=ResID=3).EAX */ |
276 | union cpuid_0x10_3_eax { | |
277 | struct { | |
278 | unsigned int max_delay:12; | |
279 | } split; | |
280 | unsigned int full; | |
281 | }; | |
282 | ||
2545e9f5 VS |
283 | /* CPUID.(EAX=10H, ECX=ResID).EDX */ |
284 | union cpuid_0x10_x_edx { | |
c1c7c3f9 FY |
285 | struct { |
286 | unsigned int cos_max:16; | |
287 | } split; | |
288 | unsigned int full; | |
289 | }; | |
2264d9c7 | 290 | |
12e0110c TL |
291 | DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid); |
292 | ||
2545e9f5 | 293 | void rdt_ctrl_update(void *arg); |
60cf5e10 FY |
294 | struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn); |
295 | void rdtgroup_kn_unlock(struct kernfs_node *kn); | |
60ec2440 TL |
296 | ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, |
297 | char *buf, size_t nbytes, loff_t off); | |
298 | int rdtgroup_schemata_show(struct kernfs_open_file *of, | |
299 | struct seq_file *s, void *v); | |
edf6fa1c | 300 | struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); |
6a445edc | 301 | int rdt_get_mon_l3_config(struct rdt_resource *r); |
4f341a5e | 302 | |
113c6097 | 303 | #endif /* _ASM_X86_INTEL_RDT_H */ |