]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/x86/include/asm/intel_rdt.h
x86/intel_rdt: Cleanup kernel-doc
[mirror_ubuntu-focal-kernel.git] / arch / x86 / include / asm / intel_rdt.h
CommitLineData
113c6097
FY
1#ifndef _ASM_X86_INTEL_RDT_H
2#define _ASM_X86_INTEL_RDT_H
3
4f341a5e
FY
4#ifdef CONFIG_INTEL_RDT_A
5
5b825c3a 6#include <linux/sched.h>
8ff42c02 7#include <linux/kernfs.h>
5ff193fb
FY
8#include <linux/jump_label.h>
9
4f341a5e
FY
10#include <asm/intel_rdt_common.h>
11
5ff193fb 12#define IA32_L3_QOS_CFG 0xc81
113c6097 13#define IA32_L3_CBM_BASE 0xc90
c1c7c3f9 14#define IA32_L2_CBM_BASE 0xd10
113c6097 15
5ff193fb
FY
16#define L3_QOS_CDP_ENABLE 0x01ULL
17
18/**
19 * struct rdtgroup - store rdtgroup's data in resctrl file system.
20 * @kn: kernfs node
21 * @rdtgroup_list: linked list for all rdtgroups
22 * @closid: closid for this rdtgroup
12e0110c 23 * @cpu_mask: CPUs assigned to this rdtgroup
60cf5e10
FY
24 * @flags: status bits
25 * @waitcount: how many cpus expect to find this
12e0110c 26 * group when they acquire rdtgroup_mutex
5ff193fb
FY
27 */
28struct rdtgroup {
29 struct kernfs_node *kn;
30 struct list_head rdtgroup_list;
31 int closid;
12e0110c 32 struct cpumask cpu_mask;
60cf5e10
FY
33 int flags;
34 atomic_t waitcount;
5ff193fb
FY
35};
36
60cf5e10
FY
37/* rdtgroup.flags */
38#define RDT_DELETED 1
39
5ff193fb
FY
40/* List of all resource groups */
41extern struct list_head rdt_all_groups;
42
de016df8
VS
43extern int max_name_width, max_data_width;
44
5ff193fb
FY
45int __init rdtgroup_init(void);
46
4e978d06
FY
47/**
48 * struct rftype - describe each file in the resctrl file system
17f8ba1d
TG
49 * @name: File name
50 * @mode: Access mode
51 * @kf_ops: File operations
52 * @seq_show: Show content of the file
53 * @write: Write to the file
4e978d06
FY
54 */
55struct rftype {
56 char *name;
57 umode_t mode;
58 struct kernfs_ops *kf_ops;
59
60 int (*seq_show)(struct kernfs_open_file *of,
61 struct seq_file *sf, void *v);
62 /*
63 * write() is the generic write callback which maps directly to
64 * kernfs write operation and overrides all other operations.
65 * Maximum write size is determined by ->max_write_len.
66 */
67 ssize_t (*write)(struct kernfs_open_file *of,
68 char *buf, size_t nbytes, loff_t off);
69};
70
c1c7c3f9
FY
71/**
72 * struct rdt_resource - attributes of an RDT resource
73 * @enabled: Is this feature enabled on this machine
74 * @capable: Is this feature available on this machine
75 * @name: Name to use in "schemata" file
76 * @num_closid: Number of CLOSIDs available
77 * @max_cbm: Largest Cache Bit Mask allowed
17f8ba1d 78 * @data_width: Character width of data when displaying
c1c7c3f9
FY
79 * @min_cbm_bits: Minimum number of consecutive bits to be set
80 * in a cache bit mask
81 * @domains: All domains for this resource
c1c7c3f9 82 * @msr_base: Base MSR address for CBMs
c1c7c3f9
FY
83 * @cache_level: Which cache level defines scope of this domain
84 * @cbm_idx_multi: Multiplier of CBM index
85 * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
86 * closid * cbm_idx_multi + cbm_idx_offset
87 */
88struct rdt_resource {
89 bool enabled;
90 bool capable;
91 char *name;
92 int num_closid;
93 int cbm_len;
94 int min_cbm_bits;
95 u32 max_cbm;
de016df8 96 int data_width;
c1c7c3f9 97 struct list_head domains;
c1c7c3f9 98 int msr_base;
c1c7c3f9
FY
99 int cache_level;
100 int cbm_idx_multi;
101 int cbm_idx_offset;
102};
103
2264d9c7
TL
104/**
105 * struct rdt_domain - group of cpus sharing an RDT resource
106 * @list: all instances of this resource
107 * @id: unique id for this instance
108 * @cpu_mask: which cpus share this resource
109 * @cbm: array of cache bit masks (indexed by CLOSID)
c4026b7b
TL
110 * @new_cbm: new cbm value to be loaded
111 * @have_new_cbm: did user provide new_cbm for this domain
2264d9c7
TL
112 */
113struct rdt_domain {
114 struct list_head list;
115 int id;
116 struct cpumask cpu_mask;
117 u32 *cbm;
c4026b7b
TL
118 u32 new_cbm;
119 bool have_new_cbm;
2264d9c7
TL
120};
121
122/**
123 * struct msr_param - set a range of MSRs from a domain
124 * @res: The resource to use
125 * @low: Beginning index from base MSR
126 * @high: End index
127 */
128struct msr_param {
129 struct rdt_resource *res;
130 int low;
131 int high;
132};
133
134extern struct mutex rdtgroup_mutex;
135
c1c7c3f9 136extern struct rdt_resource rdt_resources_all[];
5ff193fb
FY
137extern struct rdtgroup rdtgroup_default;
138DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
139
140int __init rdtgroup_init(void);
c1c7c3f9
FY
141
142enum {
143 RDT_RESOURCE_L3,
144 RDT_RESOURCE_L3DATA,
145 RDT_RESOURCE_L3CODE,
146 RDT_RESOURCE_L2,
147
148 /* Must be the last */
149 RDT_NUM_RESOURCES,
150};
151
152#define for_each_capable_rdt_resource(r) \
153 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
17f8ba1d 154 r++) \
c1c7c3f9
FY
155 if (r->capable)
156
2264d9c7
TL
157#define for_each_enabled_rdt_resource(r) \
158 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
159 r++) \
160 if (r->enabled)
161
c1c7c3f9
FY
162/* CPUID.(EAX=10H, ECX=ResID=1).EAX */
163union cpuid_0x10_1_eax {
164 struct {
165 unsigned int cbm_len:5;
166 } split;
167 unsigned int full;
168};
169
170/* CPUID.(EAX=10H, ECX=ResID=1).EDX */
171union cpuid_0x10_1_edx {
172 struct {
173 unsigned int cos_max:16;
174 } split;
175 unsigned int full;
176};
2264d9c7 177
12e0110c
TL
178DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
179
2264d9c7 180void rdt_cbm_update(void *arg);
60cf5e10
FY
181struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
182void rdtgroup_kn_unlock(struct kernfs_node *kn);
60ec2440
TL
183ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
184 char *buf, size_t nbytes, loff_t off);
185int rdtgroup_schemata_show(struct kernfs_open_file *of,
186 struct seq_file *s, void *v);
4f341a5e
FY
187
188/*
189 * intel_rdt_sched_in() - Writes the task's CLOSid to IA32_PQR_MSR
190 *
191 * Following considerations are made so that this has minimal impact
192 * on scheduler hot path:
193 * - This will stay as no-op unless we are running on an Intel SKU
194 * which supports resource control and we enable by mounting the
195 * resctrl file system.
196 * - Caches the per cpu CLOSid values and does the MSR write only
197 * when a task with a different CLOSid is scheduled in.
74fcdae1
FY
198 *
199 * Must be called with preemption disabled.
4f341a5e
FY
200 */
201static inline void intel_rdt_sched_in(void)
202{
203 if (static_branch_likely(&rdt_enable_key)) {
204 struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
205 int closid;
206
207 /*
208 * If this task has a closid assigned, use it.
209 * Else use the closid assigned to this cpu.
210 */
211 closid = current->closid;
212 if (closid == 0)
213 closid = this_cpu_read(cpu_closid);
214
215 if (closid != state->closid) {
216 state->closid = closid;
217 wrmsr(MSR_IA32_PQR_ASSOC, state->rmid, closid);
218 }
219 }
220}
221
222#else
223
224static inline void intel_rdt_sched_in(void) {}
225
226#endif /* CONFIG_INTEL_RDT_A */
113c6097 227#endif /* _ASM_X86_INTEL_RDT_H */