1 #ifndef _ASM_X86_INTEL_RDT_H
2 #define _ASM_X86_INTEL_RDT_H
4 #ifdef CONFIG_INTEL_RDT_A
6 #include <linux/kernfs.h>
7 #include <linux/jump_label.h>
9 #include <asm/intel_rdt_common.h>
11 #define IA32_L3_QOS_CFG 0xc81
12 #define IA32_L3_CBM_BASE 0xc90
13 #define IA32_L2_CBM_BASE 0xd10
15 #define L3_QOS_CDP_ENABLE 0x01ULL
18 * struct rdtgroup - store rdtgroup's data in resctrl file system.
20 * @rdtgroup_list: linked list for all rdtgroups
21 * @closid: closid for this rdtgroup
22 * @cpu_mask: CPUs assigned to this rdtgroup
24 * @waitcount: how many cpus expect to find this
25 * group when they acquire rdtgroup_mutex
28 struct kernfs_node *kn;
29 struct list_head rdtgroup_list;
31 struct cpumask cpu_mask;
39 /* List of all resource groups */
40 extern struct list_head rdt_all_groups;
42 int __init rdtgroup_init(void);
45 * struct rftype - describe each file in the resctrl file system
49 * @seq_show: show content of the file
50 * @write: write to the file
55 struct kernfs_ops *kf_ops;
57 int (*seq_show)(struct kernfs_open_file *of,
58 struct seq_file *sf, void *v);
60 * write() is the generic write callback which maps directly to
61 * kernfs write operation and overrides all other operations.
62 * Maximum write size is determined by ->max_write_len.
64 ssize_t (*write)(struct kernfs_open_file *of,
65 char *buf, size_t nbytes, loff_t off);
69 * struct rdt_resource - attributes of an RDT resource
70 * @enabled: Is this feature enabled on this machine
71 * @capable: Is this feature available on this machine
72 * @name: Name to use in "schemata" file
73 * @num_closid: Number of CLOSIDs available
74 * @max_cbm: Largest Cache Bit Mask allowed
75 * @min_cbm_bits: Minimum number of consecutive bits to be set
77 * @domains: All domains for this resource
78 * @num_domains: Number of domains active
79 * @msr_base: Base MSR address for CBMs
80 * @tmp_cbms: Scratch space when updating schemata
81 * @num_tmp_cbms: Number of CBMs in tmp_cbms
82 * @cache_level: Which cache level defines scope of this domain
83 * @cbm_idx_multi: Multiplier of CBM index
84 * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
85 * closid * cbm_idx_multi + cbm_idx_offset
95 struct list_head domains;
106 * struct rdt_domain - group of cpus sharing an RDT resource
107 * @list: all instances of this resource
108 * @id: unique id for this instance
109 * @cpu_mask: which cpus share this resource
110 * @cbm: array of cache bit masks (indexed by CLOSID)
113 struct list_head list;
115 struct cpumask cpu_mask;
120 * struct msr_param - set a range of MSRs from a domain
121 * @res: The resource to use
122 * @low: Beginning index from base MSR
126 struct rdt_resource *res;
131 extern struct mutex rdtgroup_mutex;
133 extern struct rdt_resource rdt_resources_all[];
134 extern struct rdtgroup rdtgroup_default;
135 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
137 int __init rdtgroup_init(void);
145 /* Must be the last */
149 #define for_each_capable_rdt_resource(r) \
150 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
154 #define for_each_enabled_rdt_resource(r) \
155 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
159 /* CPUID.(EAX=10H, ECX=ResID=1).EAX */
160 union cpuid_0x10_1_eax {
162 unsigned int cbm_len:5;
167 /* CPUID.(EAX=10H, ECX=ResID=1).EDX */
168 union cpuid_0x10_1_edx {
170 unsigned int cos_max:16;
175 DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
177 void rdt_cbm_update(void *arg);
178 struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
179 void rdtgroup_kn_unlock(struct kernfs_node *kn);
180 ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
181 char *buf, size_t nbytes, loff_t off);
182 int rdtgroup_schemata_show(struct kernfs_open_file *of,
183 struct seq_file *s, void *v);
186 * intel_rdt_sched_in() - Writes the task's CLOSid to IA32_PQR_MSR
188 * Following considerations are made so that this has minimal impact
189 * on scheduler hot path:
190 * - This will stay as no-op unless we are running on an Intel SKU
191 * which supports resource control and we enable by mounting the
192 * resctrl file system.
193 * - Caches the per cpu CLOSid values and does the MSR write only
194 * when a task with a different CLOSid is scheduled in.
196 * Must be called with preemption disabled.
198 static inline void intel_rdt_sched_in(void)
200 if (static_branch_likely(&rdt_enable_key)) {
201 struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
205 * If this task has a closid assigned, use it.
206 * Else use the closid assigned to this cpu.
208 closid = current->closid;
210 closid = this_cpu_read(cpu_closid);
212 if (closid != state->closid) {
213 state->closid = closid;
214 wrmsr(MSR_IA32_PQR_ASSOC, state->rmid, closid);
221 static inline void intel_rdt_sched_in(void) {}
223 #endif /* CONFIG_INTEL_RDT_A */
224 #endif /* _ASM_X86_INTEL_RDT_H */