Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _RESCTRL_H
0003 #define _RESCTRL_H
0004 
0005 #include <linux/kernel.h>
0006 #include <linux/list.h>
0007 #include <linux/pid.h>
0008 
0009 #ifdef CONFIG_PROC_CPU_RESCTRL
0010 
0011 int proc_resctrl_show(struct seq_file *m,
0012               struct pid_namespace *ns,
0013               struct pid *pid,
0014               struct task_struct *tsk);
0015 
0016 #endif
0017 
0018 /**
0019  * enum resctrl_conf_type - The type of configuration.
0020  * @CDP_NONE:   No prioritisation, both code and data are controlled or monitored.
0021  * @CDP_CODE:   Configuration applies to instruction fetches.
0022  * @CDP_DATA:   Configuration applies to reads and writes.
0023  */
0024 enum resctrl_conf_type {
0025     CDP_NONE,
0026     CDP_CODE,
0027     CDP_DATA,
0028 };
0029 
0030 #define CDP_NUM_TYPES   (CDP_DATA + 1)
0031 
0032 /**
0033  * struct resctrl_staged_config - parsed configuration to be applied
0034  * @new_ctrl:       new ctrl value to be loaded
0035  * @have_new_ctrl:  whether the user provided new_ctrl is valid
0036  */
0037 struct resctrl_staged_config {
0038     u32         new_ctrl;
0039     bool            have_new_ctrl;
0040 };
0041 
0042 /**
0043  * struct rdt_domain - group of CPUs sharing a resctrl resource
0044  * @list:       all instances of this resource
0045  * @id:         unique id for this instance
0046  * @cpu_mask:       which CPUs share this resource
0047  * @rmid_busy_llc:  bitmap of which limbo RMIDs are above threshold
0048  * @mbm_total:      saved state for MBM total bandwidth
0049  * @mbm_local:      saved state for MBM local bandwidth
0050  * @mbm_over:       worker to periodically read MBM h/w counters
0051  * @cqm_limbo:      worker to periodically read CQM h/w counters
0052  * @mbm_work_cpu:   worker CPU for MBM h/w counters
0053  * @cqm_work_cpu:   worker CPU for CQM h/w counters
0054  * @plr:        pseudo-locked region (if any) associated with domain
0055  * @staged_config:  parsed configuration to be applied
0056  */
0057 struct rdt_domain {
0058     struct list_head        list;
0059     int             id;
0060     struct cpumask          cpu_mask;
0061     unsigned long           *rmid_busy_llc;
0062     struct mbm_state        *mbm_total;
0063     struct mbm_state        *mbm_local;
0064     struct delayed_work     mbm_over;
0065     struct delayed_work     cqm_limbo;
0066     int             mbm_work_cpu;
0067     int             cqm_work_cpu;
0068     struct pseudo_lock_region   *plr;
0069     struct resctrl_staged_config    staged_config[CDP_NUM_TYPES];
0070 };
0071 
0072 /**
0073  * struct resctrl_cache - Cache allocation related data
0074  * @cbm_len:        Length of the cache bit mask
0075  * @min_cbm_bits:   Minimum number of consecutive bits to be set
0076  * @shareable_bits: Bitmask of shareable resource with other
0077  *          executing entities
0078  * @arch_has_sparse_bitmaps:    True if a bitmap like f00f is valid.
0079  * @arch_has_empty_bitmaps: True if the '0' bitmap is valid.
0080  * @arch_has_per_cpu_cfg:   True if QOS_CFG register for this cache
0081  *              level has CPU scope.
0082  */
0083 struct resctrl_cache {
0084     unsigned int    cbm_len;
0085     unsigned int    min_cbm_bits;
0086     unsigned int    shareable_bits;
0087     bool        arch_has_sparse_bitmaps;
0088     bool        arch_has_empty_bitmaps;
0089     bool        arch_has_per_cpu_cfg;
0090 };
0091 
0092 /**
0093  * enum membw_throttle_mode - System's memory bandwidth throttling mode
0094  * @THREAD_THROTTLE_UNDEFINED:  Not relevant to the system
0095  * @THREAD_THROTTLE_MAX:    Memory bandwidth is throttled at the core
0096  *              always using smallest bandwidth percentage
0097  *              assigned to threads, aka "max throttling"
0098  * @THREAD_THROTTLE_PER_THREAD: Memory bandwidth is throttled at the thread
0099  */
0100 enum membw_throttle_mode {
0101     THREAD_THROTTLE_UNDEFINED = 0,
0102     THREAD_THROTTLE_MAX,
0103     THREAD_THROTTLE_PER_THREAD,
0104 };
0105 
0106 /**
0107  * struct resctrl_membw - Memory bandwidth allocation related data
0108  * @min_bw:     Minimum memory bandwidth percentage user can request
0109  * @bw_gran:        Granularity at which the memory bandwidth is allocated
0110  * @delay_linear:   True if memory B/W delay is in linear scale
0111  * @arch_needs_linear:  True if we can't configure non-linear resources
0112  * @throttle_mode:  Bandwidth throttling mode when threads request
0113  *          different memory bandwidths
0114  * @mba_sc:     True if MBA software controller(mba_sc) is enabled
0115  * @mb_map:     Mapping of memory B/W percentage to memory B/W delay
0116  */
0117 struct resctrl_membw {
0118     u32             min_bw;
0119     u32             bw_gran;
0120     u32             delay_linear;
0121     bool                arch_needs_linear;
0122     enum membw_throttle_mode    throttle_mode;
0123     bool                mba_sc;
0124     u32             *mb_map;
0125 };
0126 
0127 struct rdt_parse_data;
0128 struct resctrl_schema;
0129 
0130 /**
0131  * struct rdt_resource - attributes of a resctrl resource
0132  * @rid:        The index of the resource
0133  * @alloc_enabled:  Is allocation enabled on this machine
0134  * @mon_enabled:    Is monitoring enabled for this feature
0135  * @alloc_capable:  Is allocation available on this machine
0136  * @mon_capable:    Is monitor feature available on this machine
0137  * @num_rmid:       Number of RMIDs available
0138  * @cache_level:    Which cache level defines scope of this resource
0139  * @cache:      Cache allocation related data
0140  * @membw:      If the component has bandwidth controls, their properties.
0141  * @domains:        All domains for this resource
0142  * @name:       Name to use in "schemata" file.
0143  * @data_width:     Character width of data when displaying
0144  * @default_ctrl:   Specifies default cache cbm or memory B/W percent.
0145  * @format_str:     Per resource format string to show domain value
0146  * @parse_ctrlval:  Per resource function pointer to parse control values
0147  * @evt_list:       List of monitoring events
0148  * @fflags:     flags to choose base and info files
0149  * @cdp_capable:    Is the CDP feature available on this resource
0150  */
0151 struct rdt_resource {
0152     int         rid;
0153     bool            alloc_enabled;
0154     bool            mon_enabled;
0155     bool            alloc_capable;
0156     bool            mon_capable;
0157     int         num_rmid;
0158     int         cache_level;
0159     struct resctrl_cache    cache;
0160     struct resctrl_membw    membw;
0161     struct list_head    domains;
0162     char            *name;
0163     int         data_width;
0164     u32         default_ctrl;
0165     const char      *format_str;
0166     int         (*parse_ctrlval)(struct rdt_parse_data *data,
0167                          struct resctrl_schema *s,
0168                          struct rdt_domain *d);
0169     struct list_head    evt_list;
0170     unsigned long       fflags;
0171     bool            cdp_capable;
0172 };
0173 
0174 /**
0175  * struct resctrl_schema - configuration abilities of a resource presented to
0176  *             user-space
0177  * @list:   Member of resctrl_schema_all.
0178  * @name:   The name to use in the "schemata" file.
0179  * @conf_type:  Whether this schema is specific to code/data.
0180  * @res:    The resource structure exported by the architecture to describe
0181  *      the hardware that is configured by this schema.
0182  * @num_closid: The number of closid that can be used with this schema. When
0183  *      features like CDP are enabled, this will be lower than the
0184  *      hardware supports for the resource.
0185  */
0186 struct resctrl_schema {
0187     struct list_head        list;
0188     char                name[8];
0189     enum resctrl_conf_type      conf_type;
0190     struct rdt_resource     *res;
0191     u32             num_closid;
0192 };
0193 
0194 /* The number of closid supported by this resource regardless of CDP */
0195 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
0196 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
0197 u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
0198                 u32 closid, enum resctrl_conf_type type);
0199 
0200 #endif /* _RESCTRL_H */