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