xref: /linux/include/linux/resctrl.h (revision 0be3ff0c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _RESCTRL_H
3 #define _RESCTRL_H
4 
5 #include <linux/kernel.h>
6 #include <linux/list.h>
7 #include <linux/pid.h>
8 
9 #ifdef CONFIG_PROC_CPU_RESCTRL
10 
11 int proc_resctrl_show(struct seq_file *m,
12 		      struct pid_namespace *ns,
13 		      struct pid *pid,
14 		      struct task_struct *tsk);
15 
16 #endif
17 
18 /**
19  * enum resctrl_conf_type - The type of configuration.
20  * @CDP_NONE:	No prioritisation, both code and data are controlled or monitored.
21  * @CDP_CODE:	Configuration applies to instruction fetches.
22  * @CDP_DATA:	Configuration applies to reads and writes.
23  */
24 enum resctrl_conf_type {
25 	CDP_NONE,
26 	CDP_CODE,
27 	CDP_DATA,
28 };
29 
30 #define CDP_NUM_TYPES	(CDP_DATA + 1)
31 
32 /**
33  * struct resctrl_staged_config - parsed configuration to be applied
34  * @new_ctrl:		new ctrl value to be loaded
35  * @have_new_ctrl:	whether the user provided new_ctrl is valid
36  */
37 struct resctrl_staged_config {
38 	u32			new_ctrl;
39 	bool			have_new_ctrl;
40 };
41 
42 /**
43  * struct rdt_domain - group of CPUs sharing a resctrl resource
44  * @list:		all instances of this resource
45  * @id:			unique id for this instance
46  * @cpu_mask:		which CPUs share this resource
47  * @rmid_busy_llc:	bitmap of which limbo RMIDs are above threshold
48  * @mbm_total:		saved state for MBM total bandwidth
49  * @mbm_local:		saved state for MBM local bandwidth
50  * @mbm_over:		worker to periodically read MBM h/w counters
51  * @cqm_limbo:		worker to periodically read CQM h/w counters
52  * @mbm_work_cpu:	worker CPU for MBM h/w counters
53  * @cqm_work_cpu:	worker CPU for CQM h/w counters
54  * @plr:		pseudo-locked region (if any) associated with domain
55  * @staged_config:	parsed configuration to be applied
56  */
57 struct rdt_domain {
58 	struct list_head		list;
59 	int				id;
60 	struct cpumask			cpu_mask;
61 	unsigned long			*rmid_busy_llc;
62 	struct mbm_state		*mbm_total;
63 	struct mbm_state		*mbm_local;
64 	struct delayed_work		mbm_over;
65 	struct delayed_work		cqm_limbo;
66 	int				mbm_work_cpu;
67 	int				cqm_work_cpu;
68 	struct pseudo_lock_region	*plr;
69 	struct resctrl_staged_config	staged_config[CDP_NUM_TYPES];
70 };
71 
72 /**
73  * struct resctrl_cache - Cache allocation related data
74  * @cbm_len:		Length of the cache bit mask
75  * @min_cbm_bits:	Minimum number of consecutive bits to be set
76  * @shareable_bits:	Bitmask of shareable resource with other
77  *			executing entities
78  * @arch_has_sparse_bitmaps:	True if a bitmap like f00f is valid.
79  * @arch_has_empty_bitmaps:	True if the '0' bitmap is valid.
80  * @arch_has_per_cpu_cfg:	True if QOS_CFG register for this cache
81  *				level has CPU scope.
82  */
83 struct resctrl_cache {
84 	unsigned int	cbm_len;
85 	unsigned int	min_cbm_bits;
86 	unsigned int	shareable_bits;
87 	bool		arch_has_sparse_bitmaps;
88 	bool		arch_has_empty_bitmaps;
89 	bool		arch_has_per_cpu_cfg;
90 };
91 
92 /**
93  * enum membw_throttle_mode - System's memory bandwidth throttling mode
94  * @THREAD_THROTTLE_UNDEFINED:	Not relevant to the system
95  * @THREAD_THROTTLE_MAX:	Memory bandwidth is throttled at the core
96  *				always using smallest bandwidth percentage
97  *				assigned to threads, aka "max throttling"
98  * @THREAD_THROTTLE_PER_THREAD:	Memory bandwidth is throttled at the thread
99  */
100 enum membw_throttle_mode {
101 	THREAD_THROTTLE_UNDEFINED = 0,
102 	THREAD_THROTTLE_MAX,
103 	THREAD_THROTTLE_PER_THREAD,
104 };
105 
106 /**
107  * struct resctrl_membw - Memory bandwidth allocation related data
108  * @min_bw:		Minimum memory bandwidth percentage user can request
109  * @bw_gran:		Granularity at which the memory bandwidth is allocated
110  * @delay_linear:	True if memory B/W delay is in linear scale
111  * @arch_needs_linear:	True if we can't configure non-linear resources
112  * @throttle_mode:	Bandwidth throttling mode when threads request
113  *			different memory bandwidths
114  * @mba_sc:		True if MBA software controller(mba_sc) is enabled
115  * @mb_map:		Mapping of memory B/W percentage to memory B/W delay
116  */
117 struct resctrl_membw {
118 	u32				min_bw;
119 	u32				bw_gran;
120 	u32				delay_linear;
121 	bool				arch_needs_linear;
122 	enum membw_throttle_mode	throttle_mode;
123 	bool				mba_sc;
124 	u32				*mb_map;
125 };
126 
127 struct rdt_parse_data;
128 struct resctrl_schema;
129 
130 /**
131  * struct rdt_resource - attributes of a resctrl resource
132  * @rid:		The index of the resource
133  * @alloc_enabled:	Is allocation enabled on this machine
134  * @mon_enabled:	Is monitoring enabled for this feature
135  * @alloc_capable:	Is allocation available on this machine
136  * @mon_capable:	Is monitor feature available on this machine
137  * @num_rmid:		Number of RMIDs available
138  * @cache_level:	Which cache level defines scope of this resource
139  * @cache:		Cache allocation related data
140  * @membw:		If the component has bandwidth controls, their properties.
141  * @domains:		All domains for this resource
142  * @name:		Name to use in "schemata" file.
143  * @data_width:		Character width of data when displaying
144  * @default_ctrl:	Specifies default cache cbm or memory B/W percent.
145  * @format_str:		Per resource format string to show domain value
146  * @parse_ctrlval:	Per resource function pointer to parse control values
147  * @evt_list:		List of monitoring events
148  * @fflags:		flags to choose base and info files
149  * @cdp_capable:	Is the CDP feature available on this resource
150  */
151 struct rdt_resource {
152 	int			rid;
153 	bool			alloc_enabled;
154 	bool			mon_enabled;
155 	bool			alloc_capable;
156 	bool			mon_capable;
157 	int			num_rmid;
158 	int			cache_level;
159 	struct resctrl_cache	cache;
160 	struct resctrl_membw	membw;
161 	struct list_head	domains;
162 	char			*name;
163 	int			data_width;
164 	u32			default_ctrl;
165 	const char		*format_str;
166 	int			(*parse_ctrlval)(struct rdt_parse_data *data,
167 						 struct resctrl_schema *s,
168 						 struct rdt_domain *d);
169 	struct list_head	evt_list;
170 	unsigned long		fflags;
171 	bool			cdp_capable;
172 };
173 
174 /**
175  * struct resctrl_schema - configuration abilities of a resource presented to
176  *			   user-space
177  * @list:	Member of resctrl_schema_all.
178  * @name:	The name to use in the "schemata" file.
179  * @conf_type:	Whether this schema is specific to code/data.
180  * @res:	The resource structure exported by the architecture to describe
181  *		the hardware that is configured by this schema.
182  * @num_closid:	The number of closid that can be used with this schema. When
183  *		features like CDP are enabled, this will be lower than the
184  *		hardware supports for the resource.
185  */
186 struct resctrl_schema {
187 	struct list_head		list;
188 	char				name[8];
189 	enum resctrl_conf_type		conf_type;
190 	struct rdt_resource		*res;
191 	u32				num_closid;
192 };
193 
194 /* The number of closid supported by this resource regardless of CDP */
195 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
196 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
197 u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
198 			    u32 closid, enum resctrl_conf_type type);
199 
200 #endif /* _RESCTRL_H */
201