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