1 #ifndef _ASM_X86_INTEL_RDT_H
2 #define _ASM_X86_INTEL_RDT_H
4 #ifdef CONFIG_INTEL_RDT_A
6 #include <linux/sched.h>
7 #include <linux/kernfs.h>
8 #include <linux/jump_label.h>
10 #include <asm/intel_rdt_common.h>
12 #define IA32_L3_QOS_CFG 0xc81
13 #define IA32_L3_CBM_BASE 0xc90
14 #define IA32_L2_CBM_BASE 0xd10
15 #define IA32_MBA_THRTL_BASE 0xd50
17 #define L3_QOS_CDP_ENABLE 0x01ULL
20 * struct rdtgroup - store rdtgroup's data in resctrl file system.
22 * @rdtgroup_list: linked list for all rdtgroups
23 * @closid: closid for this rdtgroup
24 * @cpu_mask: CPUs assigned to this rdtgroup
26 * @waitcount: how many cpus expect to find this
27 * group when they acquire rdtgroup_mutex
30 struct kernfs_node *kn;
31 struct list_head rdtgroup_list;
33 struct cpumask cpu_mask;
42 #define RFTYPE_FLAGS_CPUS_LIST 1
44 /* List of all resource groups */
45 extern struct list_head rdt_all_groups;
47 extern int max_name_width, max_data_width;
49 int __init rdtgroup_init(void);
52 * struct rftype - describe each file in the resctrl file system
55 * @kf_ops: File operations
56 * @flags: File specific RFTYPE_FLAGS_* flags
57 * @seq_show: Show content of the file
58 * @write: Write to the file
63 struct kernfs_ops *kf_ops;
66 int (*seq_show)(struct kernfs_open_file *of,
67 struct seq_file *sf, void *v);
69 * write() is the generic write callback which maps directly to
70 * kernfs write operation and overrides all other operations.
71 * Maximum write size is determined by ->max_write_len.
73 ssize_t (*write)(struct kernfs_open_file *of,
74 char *buf, size_t nbytes, loff_t off);
78 * struct rdt_domain - group of cpus sharing an RDT resource
79 * @list: all instances of this resource
80 * @id: unique id for this instance
81 * @cpu_mask: which cpus share this resource
82 * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID)
83 * @new_ctrl: new ctrl value to be loaded
84 * @have_new_ctrl: did user provide new_ctrl for this domain
87 struct list_head list;
89 struct cpumask cpu_mask;
96 * struct msr_param - set a range of MSRs from a domain
97 * @res: The resource to use
98 * @low: Beginning index from base MSR
102 struct rdt_resource *res;
108 * struct rdt_cache - Cache allocation related data
109 * @cbm_len: Length of the cache bit mask
110 * @min_cbm_bits: Minimum number of consecutive bits to be set
111 * @cbm_idx_mult: Multiplier of CBM index
112 * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
113 * closid * cbm_idx_multi + cbm_idx_offset
114 * in a cache bit mask
117 unsigned int cbm_len;
118 unsigned int min_cbm_bits;
119 unsigned int cbm_idx_mult;
120 unsigned int cbm_idx_offset;
124 * struct rdt_membw - Memory bandwidth allocation related data
125 * @max_delay: Max throttle delay. Delay is the hardware
126 * representation for memory bandwidth.
127 * @min_bw: Minimum memory bandwidth percentage user can request
128 * @bw_gran: Granularity at which the memory bandwidth is allocated
129 * @delay_linear: True if memory B/W delay is in linear scale
130 * @mb_map: Mapping of memory B/W percentage to memory B/W delay
141 * struct rdt_resource - attributes of an RDT resource
142 * @enabled: Is this feature enabled on this machine
143 * @capable: Is this feature available on this machine
144 * @name: Name to use in "schemata" file
145 * @num_closid: Number of CLOSIDs available
146 * @cache_level: Which cache level defines scope of this resource
147 * @default_ctrl: Specifies default cache cbm or memory B/W percent.
148 * @msr_base: Base MSR address for CBMs
149 * @msr_update: Function pointer to update QOS MSRs
150 * @data_width: Character width of data when displaying
151 * @domains: All domains for this resource
152 * @cache: Cache allocation related data
153 * @info_files: resctrl info files for the resource
154 * @nr_info_files: Number of info files
156 struct rdt_resource {
163 unsigned int msr_base;
164 void (*msr_update) (struct rdt_domain *d, struct msr_param *m,
165 struct rdt_resource *r);
167 struct list_head domains;
169 struct rdt_cache cache;
170 struct rdt_membw membw;
172 struct rftype *info_files;
176 void rdt_get_cache_infofile(struct rdt_resource *r);
177 void rdt_get_mba_infofile(struct rdt_resource *r);
179 extern struct mutex rdtgroup_mutex;
181 extern struct rdt_resource rdt_resources_all[];
182 extern struct rdtgroup rdtgroup_default;
183 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
185 int __init rdtgroup_init(void);
194 /* Must be the last */
198 #define for_each_capable_rdt_resource(r) \
199 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
203 #define for_each_enabled_rdt_resource(r) \
204 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
208 /* CPUID.(EAX=10H, ECX=ResID=1).EAX */
209 union cpuid_0x10_1_eax {
211 unsigned int cbm_len:5;
216 /* CPUID.(EAX=10H, ECX=ResID=3).EAX */
217 union cpuid_0x10_3_eax {
219 unsigned int max_delay:12;
224 /* CPUID.(EAX=10H, ECX=ResID).EDX */
225 union cpuid_0x10_x_edx {
227 unsigned int cos_max:16;
232 DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
234 void rdt_ctrl_update(void *arg);
235 struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
236 void rdtgroup_kn_unlock(struct kernfs_node *kn);
237 ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
238 char *buf, size_t nbytes, loff_t off);
239 int rdtgroup_schemata_show(struct kernfs_open_file *of,
240 struct seq_file *s, void *v);
243 * intel_rdt_sched_in() - Writes the task's CLOSid to IA32_PQR_MSR
245 * Following considerations are made so that this has minimal impact
246 * on scheduler hot path:
247 * - This will stay as no-op unless we are running on an Intel SKU
248 * which supports resource control and we enable by mounting the
249 * resctrl file system.
250 * - Caches the per cpu CLOSid values and does the MSR write only
251 * when a task with a different CLOSid is scheduled in.
253 * Must be called with preemption disabled.
255 static inline void intel_rdt_sched_in(void)
257 if (static_branch_likely(&rdt_enable_key)) {
258 struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
262 * If this task has a closid assigned, use it.
263 * Else use the closid assigned to this cpu.
265 closid = current->closid;
267 closid = this_cpu_read(cpu_closid);
269 if (closid != state->closid) {
270 state->closid = closid;
271 wrmsr(MSR_IA32_PQR_ASSOC, state->rmid, closid);
278 static inline void intel_rdt_sched_in(void) {}
280 #endif /* CONFIG_INTEL_RDT_A */
281 #endif /* _ASM_X86_INTEL_RDT_H */