xref: /linux-6.15/include/linux/resctrl.h (revision f62b4e45)
1e79f15a4SChen Yu /* SPDX-License-Identifier: GPL-2.0 */
2e79f15a4SChen Yu #ifndef _RESCTRL_H
3e79f15a4SChen Yu #define _RESCTRL_H
4e79f15a4SChen Yu 
5328ea688STony Luck #include <linux/cacheinfo.h>
663c8b123SJames Morse #include <linux/kernel.h>
763c8b123SJames Morse #include <linux/list.h>
8a21a4391SJames Morse #include <linux/pid.h>
9f16adbafSJames Morse #include <linux/resctrl_types.h>
10a21a4391SJames Morse 
1140fc735bSJames Morse /* CLOSID, RMID value used by the default control group */
1240fc735bSJames Morse #define RESCTRL_RESERVED_CLOSID		0
1340fc735bSJames Morse #define RESCTRL_RESERVED_RMID		0
1440fc735bSJames Morse 
15978fcca9SJames Morse #define RESCTRL_PICK_ANY_CPU		-1
16978fcca9SJames Morse 
17e79f15a4SChen Yu #ifdef CONFIG_PROC_CPU_RESCTRL
18e79f15a4SChen Yu 
19e79f15a4SChen Yu int proc_resctrl_show(struct seq_file *m,
20e79f15a4SChen Yu 		      struct pid_namespace *ns,
21e79f15a4SChen Yu 		      struct pid *pid,
22e79f15a4SChen Yu 		      struct task_struct *tsk);
23e79f15a4SChen Yu 
24e79f15a4SChen Yu #endif
25e79f15a4SChen Yu 
26781096d9SJames Morse /* max value for struct rdt_domain's mbps_val */
27781096d9SJames Morse #define MBA_MAX_MBPS   U32_MAX
28781096d9SJames Morse 
2988464bffSJames Morse /* Walk all possible resources, with variants for only controls or monitors. */
3088464bffSJames Morse #define for_each_rdt_resource(_r)						\
3188464bffSJames Morse 	for ((_r) = resctrl_arch_get_resource(0);				\
3288464bffSJames Morse 	     (_r) && (_r)->rid < RDT_NUM_RESOURCES;				\
3388464bffSJames Morse 	     (_r) = resctrl_arch_get_resource((_r)->rid + 1))
3488464bffSJames Morse 
3588464bffSJames Morse #define for_each_capable_rdt_resource(r)				      \
3688464bffSJames Morse 	for_each_rdt_resource((r))					      \
3788464bffSJames Morse 		if ((r)->alloc_capable || (r)->mon_capable)
3888464bffSJames Morse 
3988464bffSJames Morse #define for_each_alloc_capable_rdt_resource(r)				      \
4088464bffSJames Morse 	for_each_rdt_resource((r))					      \
4188464bffSJames Morse 		if ((r)->alloc_capable)
4288464bffSJames Morse 
4388464bffSJames Morse #define for_each_mon_capable_rdt_resource(r)				      \
4488464bffSJames Morse 	for_each_rdt_resource((r))					      \
4588464bffSJames Morse 		if ((r)->mon_capable)
4688464bffSJames Morse 
47792e0f6fSJames Morse /**
48208ab168SJames Morse  * enum resctrl_conf_type - The type of configuration.
49208ab168SJames Morse  * @CDP_NONE:	No prioritisation, both code and data are controlled or monitored.
50208ab168SJames Morse  * @CDP_CODE:	Configuration applies to instruction fetches.
51208ab168SJames Morse  * @CDP_DATA:	Configuration applies to reads and writes.
52208ab168SJames Morse  */
53208ab168SJames Morse enum resctrl_conf_type {
54208ab168SJames Morse 	CDP_NONE,
55208ab168SJames Morse 	CDP_CODE,
56208ab168SJames Morse 	CDP_DATA,
57208ab168SJames Morse };
58208ab168SJames Morse 
5975408e43SJames Morse #define CDP_NUM_TYPES	(CDP_DATA + 1)
6075408e43SJames Morse 
614cf9acfcSJames Morse /*
624cf9acfcSJames Morse  * struct pseudo_lock_region - pseudo-lock region information
634cf9acfcSJames Morse  * @s:			Resctrl schema for the resource to which this
644cf9acfcSJames Morse  *			pseudo-locked region belongs
654cf9acfcSJames Morse  * @closid:		The closid that this pseudo-locked region uses
664cf9acfcSJames Morse  * @d:			RDT domain to which this pseudo-locked region
674cf9acfcSJames Morse  *			belongs
684cf9acfcSJames Morse  * @cbm:		bitmask of the pseudo-locked region
694cf9acfcSJames Morse  * @lock_thread_wq:	waitqueue used to wait on the pseudo-locking thread
704cf9acfcSJames Morse  *			completion
714cf9acfcSJames Morse  * @thread_done:	variable used by waitqueue to test if pseudo-locking
724cf9acfcSJames Morse  *			thread completed
734cf9acfcSJames Morse  * @cpu:		core associated with the cache on which the setup code
744cf9acfcSJames Morse  *			will be run
754cf9acfcSJames Morse  * @line_size:		size of the cache lines
764cf9acfcSJames Morse  * @size:		size of pseudo-locked region in bytes
774cf9acfcSJames Morse  * @kmem:		the kernel memory associated with pseudo-locked region
784cf9acfcSJames Morse  * @minor:		minor number of character device associated with this
794cf9acfcSJames Morse  *			region
804cf9acfcSJames Morse  * @debugfs_dir:	pointer to this region's directory in the debugfs
814cf9acfcSJames Morse  *			filesystem
824cf9acfcSJames Morse  * @pm_reqs:		Power management QoS requests related to this region
834cf9acfcSJames Morse  */
844cf9acfcSJames Morse struct pseudo_lock_region {
854cf9acfcSJames Morse 	struct resctrl_schema	*s;
864cf9acfcSJames Morse 	u32			closid;
874cf9acfcSJames Morse 	struct rdt_ctrl_domain	*d;
884cf9acfcSJames Morse 	u32			cbm;
894cf9acfcSJames Morse 	wait_queue_head_t	lock_thread_wq;
904cf9acfcSJames Morse 	int			thread_done;
914cf9acfcSJames Morse 	int			cpu;
924cf9acfcSJames Morse 	unsigned int		line_size;
934cf9acfcSJames Morse 	unsigned int		size;
944cf9acfcSJames Morse 	void			*kmem;
954cf9acfcSJames Morse 	unsigned int		minor;
964cf9acfcSJames Morse 	struct dentry		*debugfs_dir;
974cf9acfcSJames Morse 	struct list_head	pm_reqs;
984cf9acfcSJames Morse };
994cf9acfcSJames Morse 
100208ab168SJames Morse /**
101e8f72825SJames Morse  * struct resctrl_staged_config - parsed configuration to be applied
102e8f72825SJames Morse  * @new_ctrl:		new ctrl value to be loaded
103e8f72825SJames Morse  * @have_new_ctrl:	whether the user provided new_ctrl is valid
104e8f72825SJames Morse  */
105e8f72825SJames Morse struct resctrl_staged_config {
106e8f72825SJames Morse 	u32			new_ctrl;
107e8f72825SJames Morse 	bool			have_new_ctrl;
108e8f72825SJames Morse };
109e8f72825SJames Morse 
110cd84f72bSTony Luck enum resctrl_domain_type {
111cd84f72bSTony Luck 	RESCTRL_CTRL_DOMAIN,
112cd84f72bSTony Luck 	RESCTRL_MON_DOMAIN,
113cd84f72bSTony Luck };
114cd84f72bSTony Luck 
115e8f72825SJames Morse /**
116c103d4d4STony Luck  * struct rdt_domain_hdr - common header for different domain types
117792e0f6fSJames Morse  * @list:		all instances of this resource
118792e0f6fSJames Morse  * @id:			unique id for this instance
119cd84f72bSTony Luck  * @type:		type of this instance
120792e0f6fSJames Morse  * @cpu_mask:		which CPUs share this resource
121c103d4d4STony Luck  */
122c103d4d4STony Luck struct rdt_domain_hdr {
123c103d4d4STony Luck 	struct list_head		list;
124c103d4d4STony Luck 	int				id;
125cd84f72bSTony Luck 	enum resctrl_domain_type	type;
126c103d4d4STony Luck 	struct cpumask			cpu_mask;
127c103d4d4STony Luck };
128c103d4d4STony Luck 
129c103d4d4STony Luck /**
130cae2bcb6STony Luck  * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource
131cae2bcb6STony Luck  * @hdr:		common header for different domain types
132cae2bcb6STony Luck  * @plr:		pseudo-locked region (if any) associated with domain
133cae2bcb6STony Luck  * @staged_config:	parsed configuration to be applied
134cae2bcb6STony Luck  * @mbps_val:		When mba_sc is enabled, this holds the array of user
135cae2bcb6STony Luck  *			specified control values for mba_sc in MBps, indexed
136cae2bcb6STony Luck  *			by closid
137cae2bcb6STony Luck  */
138cae2bcb6STony Luck struct rdt_ctrl_domain {
139cae2bcb6STony Luck 	struct rdt_domain_hdr		hdr;
140cae2bcb6STony Luck 	struct pseudo_lock_region	*plr;
141cae2bcb6STony Luck 	struct resctrl_staged_config	staged_config[CDP_NUM_TYPES];
142cae2bcb6STony Luck 	u32				*mbps_val;
143cae2bcb6STony Luck };
144cae2bcb6STony Luck 
145cae2bcb6STony Luck /**
146cae2bcb6STony Luck  * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource
147c103d4d4STony Luck  * @hdr:		common header for different domain types
148328ea688STony Luck  * @ci:			cache info for this domain
149792e0f6fSJames Morse  * @rmid_busy_llc:	bitmap of which limbo RMIDs are above threshold
150792e0f6fSJames Morse  * @mbm_total:		saved state for MBM total bandwidth
151792e0f6fSJames Morse  * @mbm_local:		saved state for MBM local bandwidth
152792e0f6fSJames Morse  * @mbm_over:		worker to periodically read MBM h/w counters
153792e0f6fSJames Morse  * @cqm_limbo:		worker to periodically read CQM h/w counters
154792e0f6fSJames Morse  * @mbm_work_cpu:	worker CPU for MBM h/w counters
155792e0f6fSJames Morse  * @cqm_work_cpu:	worker CPU for CQM h/w counters
156792e0f6fSJames Morse  */
157cae2bcb6STony Luck struct rdt_mon_domain {
158c103d4d4STony Luck 	struct rdt_domain_hdr		hdr;
159328ea688STony Luck 	struct cacheinfo		*ci;
160792e0f6fSJames Morse 	unsigned long			*rmid_busy_llc;
161792e0f6fSJames Morse 	struct mbm_state		*mbm_total;
162792e0f6fSJames Morse 	struct mbm_state		*mbm_local;
163792e0f6fSJames Morse 	struct delayed_work		mbm_over;
164792e0f6fSJames Morse 	struct delayed_work		cqm_limbo;
165792e0f6fSJames Morse 	int				mbm_work_cpu;
166792e0f6fSJames Morse 	int				cqm_work_cpu;
167792e0f6fSJames Morse };
16863c8b123SJames Morse 
16963c8b123SJames Morse /**
17063c8b123SJames Morse  * struct resctrl_cache - Cache allocation related data
17163c8b123SJames Morse  * @cbm_len:		Length of the cache bit mask
1722d4daa54SBabu Moger  * @min_cbm_bits:	Minimum number of consecutive bits to be set.
1732d4daa54SBabu Moger  *			The value 0 means the architecture can support
1742d4daa54SBabu Moger  *			zero CBM.
17563c8b123SJames Morse  * @shareable_bits:	Bitmask of shareable resource with other
17663c8b123SJames Morse  *			executing entities
17739c6eed1SMaciej Wieczor-Retman  * @arch_has_sparse_bitmasks:	True if a bitmask like f00f is valid.
17863c8b123SJames Morse  * @arch_has_per_cpu_cfg:	True if QOS_CFG register for this cache
17963c8b123SJames Morse  *				level has CPU scope.
18063c8b123SJames Morse  */
18163c8b123SJames Morse struct resctrl_cache {
18263c8b123SJames Morse 	unsigned int	cbm_len;
18363c8b123SJames Morse 	unsigned int	min_cbm_bits;
18463c8b123SJames Morse 	unsigned int	shareable_bits;
18539c6eed1SMaciej Wieczor-Retman 	bool		arch_has_sparse_bitmasks;
18663c8b123SJames Morse 	bool		arch_has_per_cpu_cfg;
18763c8b123SJames Morse };
18863c8b123SJames Morse 
18963c8b123SJames Morse /**
19063c8b123SJames Morse  * enum membw_throttle_mode - System's memory bandwidth throttling mode
19163c8b123SJames Morse  * @THREAD_THROTTLE_UNDEFINED:	Not relevant to the system
19263c8b123SJames Morse  * @THREAD_THROTTLE_MAX:	Memory bandwidth is throttled at the core
19363c8b123SJames Morse  *				always using smallest bandwidth percentage
19463c8b123SJames Morse  *				assigned to threads, aka "max throttling"
19563c8b123SJames Morse  * @THREAD_THROTTLE_PER_THREAD:	Memory bandwidth is throttled at the thread
19663c8b123SJames Morse  */
19763c8b123SJames Morse enum membw_throttle_mode {
19863c8b123SJames Morse 	THREAD_THROTTLE_UNDEFINED = 0,
19963c8b123SJames Morse 	THREAD_THROTTLE_MAX,
20063c8b123SJames Morse 	THREAD_THROTTLE_PER_THREAD,
20163c8b123SJames Morse };
20263c8b123SJames Morse 
20363c8b123SJames Morse /**
20463c8b123SJames Morse  * struct resctrl_membw - Memory bandwidth allocation related data
20563c8b123SJames Morse  * @min_bw:		Minimum memory bandwidth percentage user can request
206634ebb98SJames Morse  * @max_bw:		Maximum memory bandwidth value, used as the reset value
20763c8b123SJames Morse  * @bw_gran:		Granularity at which the memory bandwidth is allocated
20863c8b123SJames Morse  * @delay_linear:	True if memory B/W delay is in linear scale
20963c8b123SJames Morse  * @arch_needs_linear:	True if we can't configure non-linear resources
21063c8b123SJames Morse  * @throttle_mode:	Bandwidth throttling mode when threads request
21163c8b123SJames Morse  *			different memory bandwidths
21263c8b123SJames Morse  * @mba_sc:		True if MBA software controller(mba_sc) is enabled
21363c8b123SJames Morse  * @mb_map:		Mapping of memory B/W percentage to memory B/W delay
21463c8b123SJames Morse  */
21563c8b123SJames Morse struct resctrl_membw {
21663c8b123SJames Morse 	u32				min_bw;
217634ebb98SJames Morse 	u32				max_bw;
21863c8b123SJames Morse 	u32				bw_gran;
21963c8b123SJames Morse 	u32				delay_linear;
22063c8b123SJames Morse 	bool				arch_needs_linear;
22163c8b123SJames Morse 	enum membw_throttle_mode	throttle_mode;
22263c8b123SJames Morse 	bool				mba_sc;
22363c8b123SJames Morse 	u32				*mb_map;
22463c8b123SJames Morse };
22563c8b123SJames Morse 
2261c290682SJames Morse struct resctrl_schema;
22763c8b123SJames Morse 
228f436cb69STony Luck enum resctrl_scope {
229f436cb69STony Luck 	RESCTRL_L2_CACHE = 2,
230f436cb69STony Luck 	RESCTRL_L3_CACHE = 3,
2311a171608STony Luck 	RESCTRL_L3_NODE,
232f436cb69STony Luck };
233f436cb69STony Luck 
23463c8b123SJames Morse /**
235c24f5eabSJames Morse  * enum resctrl_schema_fmt - The format user-space provides for a schema.
236c24f5eabSJames Morse  * @RESCTRL_SCHEMA_BITMAP:	The schema is a bitmap in hex.
237c24f5eabSJames Morse  * @RESCTRL_SCHEMA_RANGE:	The schema is a decimal number.
238c24f5eabSJames Morse  */
239c24f5eabSJames Morse enum resctrl_schema_fmt {
240c24f5eabSJames Morse 	RESCTRL_SCHEMA_BITMAP,
241c24f5eabSJames Morse 	RESCTRL_SCHEMA_RANGE,
242c24f5eabSJames Morse };
243c24f5eabSJames Morse 
244c24f5eabSJames Morse /**
24563c8b123SJames Morse  * struct rdt_resource - attributes of a resctrl resource
24663c8b123SJames Morse  * @rid:		The index of the resource
24763c8b123SJames Morse  * @alloc_capable:	Is allocation available on this machine
24863c8b123SJames Morse  * @mon_capable:	Is monitor feature available on this machine
24963c8b123SJames Morse  * @num_rmid:		Number of RMIDs available
250cd84f72bSTony Luck  * @ctrl_scope:		Scope of this resource for control functions
251cd84f72bSTony Luck  * @mon_scope:		Scope of this resource for monitor functions
25263c8b123SJames Morse  * @cache:		Cache allocation related data
25363c8b123SJames Morse  * @membw:		If the component has bandwidth controls, their properties.
254cd84f72bSTony Luck  * @ctrl_domains:	RCU list of all control domains for this resource
255cd84f72bSTony Luck  * @mon_domains:	RCU list of all monitor domains for this resource
25663c8b123SJames Morse  * @name:		Name to use in "schemata" file.
257c24f5eabSJames Morse  * @schema_fmt:		Which format string and parser is used for this schema.
25863c8b123SJames Morse  * @evt_list:		List of monitoring events
259c32a7d77SJames Morse  * @mbm_cfg_mask:	Bandwidth sources that can be tracked when bandwidth
260c32a7d77SJames Morse  *			monitoring events can be configured.
261c091e907SJames Morse  * @cdp_capable:	Is the CDP feature available on this resource
26263c8b123SJames Morse  */
26363c8b123SJames Morse struct rdt_resource {
26463c8b123SJames Morse 	int			rid;
26563c8b123SJames Morse 	bool			alloc_capable;
26663c8b123SJames Morse 	bool			mon_capable;
26763c8b123SJames Morse 	int			num_rmid;
268cd84f72bSTony Luck 	enum resctrl_scope	ctrl_scope;
269cd84f72bSTony Luck 	enum resctrl_scope	mon_scope;
27063c8b123SJames Morse 	struct resctrl_cache	cache;
27163c8b123SJames Morse 	struct resctrl_membw	membw;
272cd84f72bSTony Luck 	struct list_head	ctrl_domains;
273cd84f72bSTony Luck 	struct list_head	mon_domains;
27463c8b123SJames Morse 	char			*name;
275c24f5eabSJames Morse 	enum resctrl_schema_fmt	schema_fmt;
27663c8b123SJames Morse 	struct list_head	evt_list;
277c32a7d77SJames Morse 	unsigned int		mbm_cfg_mask;
278c091e907SJames Morse 	bool			cdp_capable;
27963c8b123SJames Morse };
28063c8b123SJames Morse 
2813c021531SJames Morse /*
2823c021531SJames Morse  * Get the resource that exists at this level. If the level is not supported
2833c021531SJames Morse  * a dummy/not-capable resource can be returned. Levels >= RDT_NUM_RESOURCES
2843c021531SJames Morse  * will return NULL.
2853c021531SJames Morse  */
2863c021531SJames Morse struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
2873c021531SJames Morse 
288cdb9ebc9SJames Morse /**
289cdb9ebc9SJames Morse  * struct resctrl_schema - configuration abilities of a resource presented to
290cdb9ebc9SJames Morse  *			   user-space
291cdb9ebc9SJames Morse  * @list:	Member of resctrl_schema_all.
292e198fde3SJames Morse  * @name:	The name to use in the "schemata" file.
293bb9343c8SJames Morse  * @fmt_str:	Format string to show domain value.
294208ab168SJames Morse  * @conf_type:	Whether this schema is specific to code/data.
295cdb9ebc9SJames Morse  * @res:	The resource structure exported by the architecture to describe
296cdb9ebc9SJames Morse  *		the hardware that is configured by this schema.
2973183e87cSJames Morse  * @num_closid:	The number of closid that can be used with this schema. When
2983183e87cSJames Morse  *		features like CDP are enabled, this will be lower than the
2993183e87cSJames Morse  *		hardware supports for the resource.
300cdb9ebc9SJames Morse  */
301cdb9ebc9SJames Morse struct resctrl_schema {
302cdb9ebc9SJames Morse 	struct list_head		list;
303e198fde3SJames Morse 	char				name[8];
304bb9343c8SJames Morse 	const char			*fmt_str;
305208ab168SJames Morse 	enum resctrl_conf_type		conf_type;
306cdb9ebc9SJames Morse 	struct rdt_resource		*res;
307eb6f3187SJames Morse 	u32				num_closid;
308cdb9ebc9SJames Morse };
309eb6f3187SJames Morse 
3106f06aee3SJames Morse struct resctrl_cpu_defaults {
3116f06aee3SJames Morse 	u32 closid;
3126f06aee3SJames Morse 	u32 rmid;
3136f06aee3SJames Morse };
3146f06aee3SJames Morse 
315650680d6SJames Morse struct resctrl_mon_config_info {
316650680d6SJames Morse 	struct rdt_resource	*r;
317650680d6SJames Morse 	struct rdt_mon_domain	*d;
318650680d6SJames Morse 	u32			evtid;
319650680d6SJames Morse 	u32			mon_config;
320650680d6SJames Morse };
321650680d6SJames Morse 
3226f06aee3SJames Morse /**
3236f06aee3SJames Morse  * resctrl_arch_sync_cpu_closid_rmid() - Refresh this CPU's CLOSID and RMID.
3246f06aee3SJames Morse  *					 Call via IPI.
3256f06aee3SJames Morse  * @info:	If non-NULL, a pointer to a struct resctrl_cpu_defaults
3266f06aee3SJames Morse  *		specifying the new CLOSID and RMID for tasks in the default
3276f06aee3SJames Morse  *		resctrl ctrl and mon group when running on this CPU.  If NULL,
3286f06aee3SJames Morse  *		this CPU is not re-assigned to a different default group.
3296f06aee3SJames Morse  *
3306f06aee3SJames Morse  * Propagates reassignment of CPUs and/or tasks to different resctrl groups
3316f06aee3SJames Morse  * when requested by the resctrl core code.
3326f06aee3SJames Morse  *
3336f06aee3SJames Morse  * This function records the per-cpu defaults specified by @info (if any),
3346f06aee3SJames Morse  * and then reconfigures the CPU's hardware CLOSID and RMID for subsequent
3356f06aee3SJames Morse  * execution based on @current, in the same way as during a task switch.
3366f06aee3SJames Morse  */
3376f06aee3SJames Morse void resctrl_arch_sync_cpu_closid_rmid(void *info);
3386f06aee3SJames Morse 
339dbc58f7eSJames Morse /**
340dbc58f7eSJames Morse  * resctrl_get_default_ctrl() - Return the default control value for this
341dbc58f7eSJames Morse  *                              resource.
342dbc58f7eSJames Morse  * @r:		The resource whose default control type is queried.
343dbc58f7eSJames Morse  */
resctrl_get_default_ctrl(struct rdt_resource * r)344dbc58f7eSJames Morse static inline u32 resctrl_get_default_ctrl(struct rdt_resource *r)
345dbc58f7eSJames Morse {
346dbc58f7eSJames Morse 	switch (r->schema_fmt) {
347dbc58f7eSJames Morse 	case RESCTRL_SCHEMA_BITMAP:
348dbc58f7eSJames Morse 		return BIT_MASK(r->cache.cbm_len) - 1;
349dbc58f7eSJames Morse 	case RESCTRL_SCHEMA_RANGE:
350dbc58f7eSJames Morse 		return r->membw.max_bw;
351dbc58f7eSJames Morse 	}
352dbc58f7eSJames Morse 
353dbc58f7eSJames Morse 	return WARN_ON_ONCE(1);
354dbc58f7eSJames Morse }
355dbc58f7eSJames Morse 
356eb6f3187SJames Morse /* The number of closid supported by this resource regardless of CDP */
357eb6f3187SJames Morse u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
358a547a588SPeter Newman u32 resctrl_arch_system_num_rmid_idx(void);
3592e667819SJames Morse int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
360ff6357bbSJames Morse 
361d81826f8SJames Morse __init bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
362d81826f8SJames Morse 
363650680d6SJames Morse /**
364650680d6SJames Morse  * resctrl_arch_mon_event_config_write() - Write the config for an event.
365650680d6SJames Morse  * @config_info: struct resctrl_mon_config_info describing the resource, domain
366650680d6SJames Morse  *		 and event.
367650680d6SJames Morse  *
368650680d6SJames Morse  * Reads resource, domain and eventid from @config_info and writes the
369650680d6SJames Morse  * event config_info->mon_config into hardware.
370650680d6SJames Morse  *
371650680d6SJames Morse  * Called via IPI to reach a CPU that is a member of the specified domain.
372650680d6SJames Morse  */
373650680d6SJames Morse void resctrl_arch_mon_event_config_write(void *config_info);
374650680d6SJames Morse 
375650680d6SJames Morse /**
376650680d6SJames Morse  * resctrl_arch_mon_event_config_read() - Read the config for an event.
377650680d6SJames Morse  * @config_info: struct resctrl_mon_config_info describing the resource, domain
378650680d6SJames Morse  *		 and event.
379650680d6SJames Morse  *
380650680d6SJames Morse  * Reads resource, domain and eventid from @config_info and reads the
381650680d6SJames Morse  * hardware config value into config_info->mon_config.
382650680d6SJames Morse  *
383650680d6SJames Morse  * Called via IPI to reach a CPU that is a member of the specified domain.
384650680d6SJames Morse  */
385650680d6SJames Morse void resctrl_arch_mon_event_config_read(void *config_info);
386650680d6SJames Morse 
387*f62b4e45SJames Morse /* For use by arch code to remap resctrl's smaller CDP CLOSID range */
resctrl_get_config_index(u32 closid,enum resctrl_conf_type type)388*f62b4e45SJames Morse static inline u32 resctrl_get_config_index(u32 closid,
389*f62b4e45SJames Morse 					   enum resctrl_conf_type type)
390*f62b4e45SJames Morse {
391*f62b4e45SJames Morse 	switch (type) {
392*f62b4e45SJames Morse 	default:
393*f62b4e45SJames Morse 	case CDP_NONE:
394*f62b4e45SJames Morse 		return closid;
395*f62b4e45SJames Morse 	case CDP_CODE:
396*f62b4e45SJames Morse 		return closid * 2 + 1;
397*f62b4e45SJames Morse 	case CDP_DATA:
398*f62b4e45SJames Morse 		return closid * 2;
399*f62b4e45SJames Morse 	}
400*f62b4e45SJames Morse }
401*f62b4e45SJames Morse 
402ff6357bbSJames Morse /*
403ff6357bbSJames Morse  * Update the ctrl_val and apply this config right now.
404ff6357bbSJames Morse  * Must be called on one of the domain's CPUs.
405ff6357bbSJames Morse  */
406cae2bcb6STony Luck int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
407ff6357bbSJames Morse 			    u32 closid, enum resctrl_conf_type t, u32 cfg_val);
408ff6357bbSJames Morse 
409cae2bcb6STony Luck u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
410111136e6SJames Morse 			    u32 closid, enum resctrl_conf_type type);
411cae2bcb6STony Luck int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_domain *d);
412cae2bcb6STony Luck int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d);
413cae2bcb6STony Luck void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_domain *d);
414cae2bcb6STony Luck void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d);
4151b3e50ceSJames Morse void resctrl_online_cpu(unsigned int cpu);
416258c91e8SJames Morse void resctrl_offline_cpu(unsigned int cpu);
4178286618aSJames Morse 
4188286618aSJames Morse /**
4198286618aSJames Morse  * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
4208286618aSJames Morse  *			      for this resource and domain.
4218286618aSJames Morse  * @r:			resource that the counter should be read from.
4228286618aSJames Morse  * @d:			domain that the counter should be read from.
42340fc735bSJames Morse  * @closid:		closid that matches the rmid. Depending on the architecture, the
42440fc735bSJames Morse  *			counter may match traffic of both @closid and @rmid, or @rmid
42540fc735bSJames Morse  *			only.
4268286618aSJames Morse  * @rmid:		rmid of the counter to read.
4278286618aSJames Morse  * @eventid:		eventid to read, e.g. L3 occupancy.
428f7b1843eSJames Morse  * @val:		result of the counter read in bytes.
429e557999fSJames Morse  * @arch_mon_ctx:	An architecture specific value from
430e557999fSJames Morse  *			resctrl_arch_mon_ctx_alloc(), for MPAM this identifies
431e557999fSJames Morse  *			the hardware monitor allocated for this read request.
4328286618aSJames Morse  *
4336fde1424SJames Morse  * Some architectures need to sleep when first programming some of the counters.
4346fde1424SJames Morse  * (specifically: arm64's MPAM cache occupancy counters can return 'not ready'
4356fde1424SJames Morse  *  for a short period of time). Call from a non-migrateable process context on
4366fde1424SJames Morse  * a CPU that belongs to domain @d. e.g. use smp_call_on_cpu() or
4376fde1424SJames Morse  * schedule_work_on(). This function can be called with interrupts masked,
4386fde1424SJames Morse  * e.g. using smp_call_function_any(), but may consistently return an error.
4398286618aSJames Morse  *
4408286618aSJames Morse  * Return:
4418286618aSJames Morse  * 0 on success, or -EIO, -EINVAL etc on error.
4428286618aSJames Morse  */
443cae2bcb6STony Luck int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
44440fc735bSJames Morse 			   u32 closid, u32 rmid, enum resctrl_event_id eventid,
445e557999fSJames Morse 			   u64 *val, void *arch_mon_ctx);
44640fc735bSJames Morse 
4476fde1424SJames Morse /**
4486fde1424SJames Morse  * resctrl_arch_rmid_read_context_check()  - warn about invalid contexts
4496fde1424SJames Morse  *
4506fde1424SJames Morse  * When built with CONFIG_DEBUG_ATOMIC_SLEEP generate a warning when
4516fde1424SJames Morse  * resctrl_arch_rmid_read() is called with preemption disabled.
4526fde1424SJames Morse  *
4536fde1424SJames Morse  * The contract with resctrl_arch_rmid_read() is that if interrupts
4546fde1424SJames Morse  * are unmasked, it can sleep. This allows NOHZ_FULL systems to use an
4556fde1424SJames Morse  * IPI, (and fail if the call needed to sleep), while most of the time
4566fde1424SJames Morse  * the work is scheduled, allowing the call to sleep.
4576fde1424SJames Morse  */
resctrl_arch_rmid_read_context_check(void)4586fde1424SJames Morse static inline void resctrl_arch_rmid_read_context_check(void)
4596fde1424SJames Morse {
4606fde1424SJames Morse 	if (!irqs_disabled())
4616fde1424SJames Morse 		might_sleep();
4626fde1424SJames Morse }
463eb6f3187SJames Morse 
464fea62d37SJames Morse /**
465e3d5138cSJames Morse  * resctrl_find_domain() - Search for a domain id in a resource domain list.
466e3d5138cSJames Morse  * @h:		The domain list to search.
467e3d5138cSJames Morse  * @id:		The domain id to search for.
468e3d5138cSJames Morse  * @pos:	A pointer to position in the list id should be inserted.
469e3d5138cSJames Morse  *
470e3d5138cSJames Morse  * Search the domain list to find the domain id. If the domain id is
471e3d5138cSJames Morse  * found, return the domain. NULL otherwise.  If the domain id is not
472e3d5138cSJames Morse  * found (and NULL returned) then the first domain with id bigger than
473e3d5138cSJames Morse  * the input id can be returned to the caller via @pos.
474e3d5138cSJames Morse  */
475e3d5138cSJames Morse struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
476e3d5138cSJames Morse 					   struct list_head **pos);
477e3d5138cSJames Morse 
478e3d5138cSJames Morse /**
479fea62d37SJames Morse  * resctrl_arch_reset_rmid() - Reset any private state associated with rmid
480fea62d37SJames Morse  *			       and eventid.
481fea62d37SJames Morse  * @r:		The domain's resource.
482fea62d37SJames Morse  * @d:		The rmid's domain.
48340fc735bSJames Morse  * @closid:	closid that matches the rmid. Depending on the architecture, the
48440fc735bSJames Morse  *		counter may match traffic of both @closid and @rmid, or @rmid only.
485fea62d37SJames Morse  * @rmid:	The rmid whose counter values should be reset.
486fea62d37SJames Morse  * @eventid:	The eventid whose counter values should be reset.
487fea62d37SJames Morse  *
488fea62d37SJames Morse  * This can be called from any CPU.
489fea62d37SJames Morse  */
490cae2bcb6STony Luck void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d,
49140fc735bSJames Morse 			     u32 closid, u32 rmid,
49240fc735bSJames Morse 			     enum resctrl_event_id eventid);
493fea62d37SJames Morse 
49492bd5a13SBabu Moger /**
49592bd5a13SBabu Moger  * resctrl_arch_reset_rmid_all() - Reset all private state associated with
49692bd5a13SBabu Moger  *				   all rmids and eventids.
49792bd5a13SBabu Moger  * @r:		The resctrl resource.
49892bd5a13SBabu Moger  * @d:		The domain for which all architectural counter state will
49992bd5a13SBabu Moger  *		be cleared.
50092bd5a13SBabu Moger  *
50192bd5a13SBabu Moger  * This can be called from any CPU.
50292bd5a13SBabu Moger  */
503cae2bcb6STony Luck void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *d);
50492bd5a13SBabu Moger 
5059be68b14SJames Morse /**
5069be68b14SJames Morse  * resctrl_arch_reset_all_ctrls() - Reset the control for each CLOSID to its
5079be68b14SJames Morse  *				    default.
5089be68b14SJames Morse  * @r:		The resctrl resource to reset.
5099be68b14SJames Morse  *
5109be68b14SJames Morse  * This can be called from any CPU.
5119be68b14SJames Morse  */
5129be68b14SJames Morse void resctrl_arch_reset_all_ctrls(struct rdt_resource *r);
5139be68b14SJames Morse 
514ae2328b5SJames Morse extern unsigned int resctrl_rmid_realloc_threshold;
515d80975e2SJames Morse extern unsigned int resctrl_rmid_realloc_limit;
516ae2328b5SJames Morse 
5178079565dSJames Morse int __init resctrl_init(void);
5188079565dSJames Morse void __exit resctrl_exit(void);
5198079565dSJames Morse 
520e79f15a4SChen Yu #endif /* _RESCTRL_H */
521