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 | |
9f52425b TL |
22 | |
23 | #define MBM_CNTR_WIDTH 24 | |
24 | ||
edf6fa1c VS |
25 | #define RMID_VAL_ERROR BIT_ULL(63) |
26 | #define RMID_VAL_UNAVAIL BIT_ULL(62) | |
6a445edc VS |
27 | |
28 | /** | |
29 | * struct mon_evt - Entry in the event list of a resource | |
30 | * @evtid: event id | |
31 | * @name: name of the event | |
32 | */ | |
33 | struct mon_evt { | |
34 | u32 evtid; | |
35 | char *name; | |
36 | struct list_head list; | |
37 | }; | |
38 | ||
d89b7379 VS |
39 | /** |
40 | * struct mon_data_bits - Monitoring details for each event file | |
41 | * @rid: Resource id associated with the event file. | |
42 | * @evtid: Event id associated with the event file | |
43 | * @domid: The domain to which the event file belongs | |
44 | */ | |
45 | union mon_data_bits { | |
46 | void *priv; | |
47 | struct { | |
48 | unsigned int rid : 10; | |
49 | unsigned int evtid : 8; | |
50 | unsigned int domid : 14; | |
51 | } u; | |
52 | }; | |
53 | ||
54 | struct rmid_read { | |
55 | struct rdtgroup *rgrp; | |
9f52425b | 56 | struct rdt_domain *d; |
d89b7379 VS |
57 | int evtid; |
58 | u64 val; | |
59 | }; | |
60 | ||
6a445edc VS |
61 | extern unsigned int intel_cqm_threshold; |
62 | extern bool rdt_alloc_capable; | |
63 | extern bool rdt_mon_capable; | |
64 | extern unsigned int rdt_mon_features; | |
c7d9aac6 VS |
65 | |
66 | enum rdt_group_type { | |
67 | RDTCTRL_GROUP = 0, | |
68 | RDTMON_GROUP, | |
69 | RDT_NUM_GROUP, | |
70 | }; | |
71 | ||
72 | /** | |
73 | * struct mongroup - store mon group's data in resctrl fs. | |
d89b7379 | 74 | * @mon_data_kn kernlfs node for the mon_data directory |
c7d9aac6 VS |
75 | * @parent: parent rdtgrp |
76 | * @crdtgrp_list: child rdtgroup node list | |
77 | * @rmid: rmid for this rdtgroup | |
78 | */ | |
79 | struct mongroup { | |
d89b7379 | 80 | struct kernfs_node *mon_data_kn; |
c7d9aac6 VS |
81 | struct rdtgroup *parent; |
82 | struct list_head crdtgrp_list; | |
83 | u32 rmid; | |
84 | }; | |
85 | ||
5ff193fb FY |
86 | /** |
87 | * struct rdtgroup - store rdtgroup's data in resctrl file system. | |
88 | * @kn: kernfs node | |
89 | * @rdtgroup_list: linked list for all rdtgroups | |
90 | * @closid: closid for this rdtgroup | |
12e0110c | 91 | * @cpu_mask: CPUs assigned to this rdtgroup |
60cf5e10 FY |
92 | * @flags: status bits |
93 | * @waitcount: how many cpus expect to find this | |
12e0110c | 94 | * group when they acquire rdtgroup_mutex |
c7d9aac6 VS |
95 | * @type: indicates type of this rdtgroup - either |
96 | * monitor only or ctrl_mon group | |
97 | * @mon: mongroup related data | |
5ff193fb FY |
98 | */ |
99 | struct rdtgroup { | |
100 | struct kernfs_node *kn; | |
101 | struct list_head rdtgroup_list; | |
0734ded1 | 102 | u32 closid; |
12e0110c | 103 | struct cpumask cpu_mask; |
60cf5e10 FY |
104 | int flags; |
105 | atomic_t waitcount; | |
c7d9aac6 VS |
106 | enum rdt_group_type type; |
107 | struct mongroup mon; | |
5ff193fb FY |
108 | }; |
109 | ||
60cf5e10 FY |
110 | /* rdtgroup.flags */ |
111 | #define RDT_DELETED 1 | |
112 | ||
4ffa3c97 JO |
113 | /* rftype.flags */ |
114 | #define RFTYPE_FLAGS_CPUS_LIST 1 | |
115 | ||
5dc1d5c6 T |
116 | /* |
117 | * Define the file type flags for base and info directories. | |
118 | */ | |
119 | #define RFTYPE_INFO BIT(0) | |
120 | #define RFTYPE_BASE BIT(1) | |
121 | #define RF_CTRLSHIFT 4 | |
d4ab3320 | 122 | #define RF_MONSHIFT 5 |
5dc1d5c6 | 123 | #define RFTYPE_CTRL BIT(RF_CTRLSHIFT) |
d4ab3320 | 124 | #define RFTYPE_MON BIT(RF_MONSHIFT) |
5dc1d5c6 T |
125 | #define RFTYPE_RES_CACHE BIT(8) |
126 | #define RFTYPE_RES_MB BIT(9) | |
127 | #define RF_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL) | |
d4ab3320 | 128 | #define RF_MON_INFO (RFTYPE_INFO | RFTYPE_MON) |
5dc1d5c6 T |
129 | #define RF_CTRL_BASE (RFTYPE_BASE | RFTYPE_CTRL) |
130 | ||
5ff193fb FY |
131 | /* List of all resource groups */ |
132 | extern struct list_head rdt_all_groups; | |
133 | ||
de016df8 VS |
134 | extern int max_name_width, max_data_width; |
135 | ||
5ff193fb FY |
136 | int __init rdtgroup_init(void); |
137 | ||
4e978d06 FY |
138 | /** |
139 | * struct rftype - describe each file in the resctrl file system | |
17f8ba1d TG |
140 | * @name: File name |
141 | * @mode: Access mode | |
142 | * @kf_ops: File operations | |
4ffa3c97 | 143 | * @flags: File specific RFTYPE_FLAGS_* flags |
5dc1d5c6 | 144 | * @fflags: File specific RF_* or RFTYPE_* flags |
17f8ba1d TG |
145 | * @seq_show: Show content of the file |
146 | * @write: Write to the file | |
4e978d06 FY |
147 | */ |
148 | struct rftype { | |
149 | char *name; | |
150 | umode_t mode; | |
151 | struct kernfs_ops *kf_ops; | |
4ffa3c97 | 152 | unsigned long flags; |
5dc1d5c6 | 153 | unsigned long fflags; |
4e978d06 FY |
154 | |
155 | int (*seq_show)(struct kernfs_open_file *of, | |
156 | struct seq_file *sf, void *v); | |
157 | /* | |
158 | * write() is the generic write callback which maps directly to | |
159 | * kernfs write operation and overrides all other operations. | |
160 | * Maximum write size is determined by ->max_write_len. | |
161 | */ | |
162 | ssize_t (*write)(struct kernfs_open_file *of, | |
163 | char *buf, size_t nbytes, loff_t off); | |
164 | }; | |
165 | ||
9f52425b TL |
166 | /** |
167 | * struct mbm_state - status for each MBM counter in each domain | |
168 | * @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes) | |
169 | * @prev_msr Value of IA32_QM_CTR for this RMID last time we read it | |
170 | */ | |
171 | struct mbm_state { | |
172 | u64 chunks; | |
173 | u64 prev_msr; | |
174 | }; | |
175 | ||
0921c547 TG |
176 | /** |
177 | * struct rdt_domain - group of cpus sharing an RDT resource | |
178 | * @list: all instances of this resource | |
179 | * @id: unique id for this instance | |
180 | * @cpu_mask: which cpus share this resource | |
edf6fa1c VS |
181 | * @rmid_busy_llc: |
182 | * bitmap of which limbo RMIDs are above threshold | |
9f52425b TL |
183 | * @mbm_total: saved state for MBM total bandwidth |
184 | * @mbm_local: saved state for MBM local bandwidth | |
0921c547 TG |
185 | * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) |
186 | * @new_ctrl: new ctrl value to be loaded | |
187 | * @have_new_ctrl: did user provide new_ctrl for this domain | |
188 | */ | |
189 | struct rdt_domain { | |
190 | struct list_head list; | |
191 | int id; | |
192 | struct cpumask cpu_mask; | |
edf6fa1c | 193 | unsigned long *rmid_busy_llc; |
9f52425b TL |
194 | struct mbm_state *mbm_total; |
195 | struct mbm_state *mbm_local; | |
0921c547 TG |
196 | u32 *ctrl_val; |
197 | u32 new_ctrl; | |
198 | bool have_new_ctrl; | |
199 | }; | |
200 | ||
201 | /** | |
202 | * struct msr_param - set a range of MSRs from a domain | |
203 | * @res: The resource to use | |
204 | * @low: Beginning index from base MSR | |
205 | * @high: End index | |
206 | */ | |
207 | struct msr_param { | |
208 | struct rdt_resource *res; | |
209 | int low; | |
210 | int high; | |
211 | }; | |
212 | ||
d3e11b4d TG |
213 | /** |
214 | * struct rdt_cache - Cache allocation related data | |
215 | * @cbm_len: Length of the cache bit mask | |
216 | * @min_cbm_bits: Minimum number of consecutive bits to be set | |
217 | * @cbm_idx_mult: Multiplier of CBM index | |
218 | * @cbm_idx_offset: Offset of CBM index. CBM index is computed by: | |
219 | * closid * cbm_idx_multi + cbm_idx_offset | |
220 | * in a cache bit mask | |
221 | */ | |
222 | struct rdt_cache { | |
223 | unsigned int cbm_len; | |
224 | unsigned int min_cbm_bits; | |
225 | unsigned int cbm_idx_mult; | |
226 | unsigned int cbm_idx_offset; | |
227 | }; | |
228 | ||
05b93417 VS |
229 | /** |
230 | * struct rdt_membw - Memory bandwidth allocation related data | |
231 | * @max_delay: Max throttle delay. Delay is the hardware | |
232 | * representation for memory bandwidth. | |
233 | * @min_bw: Minimum memory bandwidth percentage user can request | |
234 | * @bw_gran: Granularity at which the memory bandwidth is allocated | |
235 | * @delay_linear: True if memory B/W delay is in linear scale | |
236 | * @mb_map: Mapping of memory B/W percentage to memory B/W delay | |
237 | */ | |
238 | struct rdt_membw { | |
239 | u32 max_delay; | |
240 | u32 min_bw; | |
241 | u32 bw_gran; | |
242 | u32 delay_linear; | |
243 | u32 *mb_map; | |
244 | }; | |
245 | ||
6a445edc VS |
246 | static inline bool is_llc_occupancy_enabled(void) |
247 | { | |
248 | return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID)); | |
249 | } | |
250 | ||
9f52425b TL |
251 | static inline bool is_mbm_total_enabled(void) |
252 | { | |
253 | return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID)); | |
254 | } | |
255 | ||
256 | static inline bool is_mbm_local_enabled(void) | |
257 | { | |
258 | return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID)); | |
259 | } | |
260 | ||
261 | static inline bool is_mbm_enabled(void) | |
262 | { | |
263 | return (is_mbm_total_enabled() || is_mbm_local_enabled()); | |
264 | } | |
265 | ||
c1c7c3f9 FY |
266 | /** |
267 | * struct rdt_resource - attributes of an RDT resource | |
d89b7379 | 268 | * @rid: The index of the resource |
1b5c0b75 | 269 | * @alloc_enabled: Is allocation enabled on this machine |
6a445edc | 270 | * @mon_enabled: Is monitoring enabled for this feature |
1b5c0b75 | 271 | * @alloc_capable: Is allocation available on this machine |
6a445edc | 272 | * @mon_capable: Is monitor feature available on this machine |
d3e11b4d TG |
273 | * @name: Name to use in "schemata" file |
274 | * @num_closid: Number of CLOSIDs available | |
275 | * @cache_level: Which cache level defines scope of this resource | |
276 | * @default_ctrl: Specifies default cache cbm or memory B/W percent. | |
277 | * @msr_base: Base MSR address for CBMs | |
0921c547 | 278 | * @msr_update: Function pointer to update QOS MSRs |
d3e11b4d TG |
279 | * @data_width: Character width of data when displaying |
280 | * @domains: All domains for this resource | |
281 | * @cache: Cache allocation related data | |
c6ea67de VS |
282 | * @format_str: Per resource format string to show domain value |
283 | * @parse_ctrlval: Per resource function pointer to parse control values | |
6a445edc VS |
284 | * @evt_list: List of monitoring events |
285 | * @num_rmid: Number of RMIDs available | |
286 | * @mon_scale: cqm counter * mon_scale = occupancy in bytes | |
5dc1d5c6 | 287 | * @fflags: flags to choose base and info files |
c1c7c3f9 FY |
288 | */ |
289 | struct rdt_resource { | |
d89b7379 | 290 | int rid; |
1b5c0b75 | 291 | bool alloc_enabled; |
6a445edc | 292 | bool mon_enabled; |
1b5c0b75 | 293 | bool alloc_capable; |
6a445edc | 294 | bool mon_capable; |
c1c7c3f9 FY |
295 | char *name; |
296 | int num_closid; | |
d3e11b4d | 297 | int cache_level; |
2545e9f5 | 298 | u32 default_ctrl; |
d3e11b4d | 299 | unsigned int msr_base; |
0921c547 TG |
300 | void (*msr_update) (struct rdt_domain *d, struct msr_param *m, |
301 | struct rdt_resource *r); | |
de016df8 | 302 | int data_width; |
c1c7c3f9 | 303 | struct list_head domains; |
a83827d0 TG |
304 | struct rdt_cache cache; |
305 | struct rdt_membw membw; | |
c6ea67de VS |
306 | const char *format_str; |
307 | int (*parse_ctrlval) (char *buf, struct rdt_resource *r, | |
308 | struct rdt_domain *d); | |
6a445edc VS |
309 | struct list_head evt_list; |
310 | int num_rmid; | |
311 | unsigned int mon_scale; | |
5dc1d5c6 | 312 | unsigned long fflags; |
c1c7c3f9 FY |
313 | }; |
314 | ||
c6ea67de | 315 | int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d); |
64e8ed3d | 316 | int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d); |
6a507a6a | 317 | |
2264d9c7 TL |
318 | extern struct mutex rdtgroup_mutex; |
319 | ||
c1c7c3f9 | 320 | extern struct rdt_resource rdt_resources_all[]; |
5ff193fb | 321 | extern struct rdtgroup rdtgroup_default; |
1b5c0b75 | 322 | DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); |
5ff193fb FY |
323 | |
324 | int __init rdtgroup_init(void); | |
c1c7c3f9 FY |
325 | |
326 | enum { | |
327 | RDT_RESOURCE_L3, | |
328 | RDT_RESOURCE_L3DATA, | |
329 | RDT_RESOURCE_L3CODE, | |
330 | RDT_RESOURCE_L2, | |
05b93417 | 331 | RDT_RESOURCE_MBA, |
c1c7c3f9 FY |
332 | |
333 | /* Must be the last */ | |
334 | RDT_NUM_RESOURCES, | |
335 | }; | |
336 | ||
895c663e VS |
337 | #define for_each_capable_rdt_resource(r) \ |
338 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ | |
339 | r++) \ | |
340 | if (r->alloc_capable || r->mon_capable) | |
341 | ||
1b5c0b75 | 342 | #define for_each_alloc_capable_rdt_resource(r) \ |
c1c7c3f9 | 343 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ |
17f8ba1d | 344 | r++) \ |
1b5c0b75 | 345 | if (r->alloc_capable) |
c1c7c3f9 | 346 | |
6a445edc VS |
347 | #define for_each_mon_capable_rdt_resource(r) \ |
348 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ | |
349 | r++) \ | |
350 | if (r->mon_capable) | |
351 | ||
1b5c0b75 | 352 | #define for_each_alloc_enabled_rdt_resource(r) \ |
2264d9c7 TL |
353 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ |
354 | r++) \ | |
1b5c0b75 | 355 | if (r->alloc_enabled) |
2264d9c7 | 356 | |
d4ab3320 VS |
357 | #define for_each_mon_enabled_rdt_resource(r) \ |
358 | for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\ | |
359 | r++) \ | |
360 | if (r->mon_enabled) | |
361 | ||
c1c7c3f9 FY |
362 | /* CPUID.(EAX=10H, ECX=ResID=1).EAX */ |
363 | union cpuid_0x10_1_eax { | |
364 | struct { | |
365 | unsigned int cbm_len:5; | |
366 | } split; | |
367 | unsigned int full; | |
368 | }; | |
369 | ||
ab66a33b VS |
370 | /* CPUID.(EAX=10H, ECX=ResID=3).EAX */ |
371 | union cpuid_0x10_3_eax { | |
372 | struct { | |
373 | unsigned int max_delay:12; | |
374 | } split; | |
375 | unsigned int full; | |
376 | }; | |
377 | ||
2545e9f5 VS |
378 | /* CPUID.(EAX=10H, ECX=ResID).EDX */ |
379 | union cpuid_0x10_x_edx { | |
c1c7c3f9 FY |
380 | struct { |
381 | unsigned int cos_max:16; | |
382 | } split; | |
383 | unsigned int full; | |
384 | }; | |
2264d9c7 | 385 | |
2545e9f5 | 386 | void rdt_ctrl_update(void *arg); |
60cf5e10 FY |
387 | struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn); |
388 | void rdtgroup_kn_unlock(struct kernfs_node *kn); | |
d89b7379 VS |
389 | struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id, |
390 | struct list_head **pos); | |
60ec2440 TL |
391 | ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, |
392 | char *buf, size_t nbytes, loff_t off); | |
393 | int rdtgroup_schemata_show(struct kernfs_open_file *of, | |
394 | struct seq_file *s, void *v); | |
edf6fa1c | 395 | struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); |
c7d9aac6 VS |
396 | int alloc_rmid(void); |
397 | void free_rmid(u32 rmid); | |
6a445edc | 398 | int rdt_get_mon_l3_config(struct rdt_resource *r); |
d89b7379 VS |
399 | void mon_event_count(void *info); |
400 | int rdtgroup_mondata_show(struct seq_file *m, void *arg); | |
895c663e VS |
401 | void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, |
402 | unsigned int dom_id); | |
403 | void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, | |
404 | struct rdt_domain *d); | |
4f341a5e | 405 | |
113c6097 | 406 | #endif /* _ASM_X86_INTEL_RDT_H */ |