The filesystem tracks supported kernel modes, the active mode, and the control and monitoring association for the assigned group. Introduce struct resctrl_kmode_cfg and initialize the default configuration from the platform's capabilities. Signed-off-by: Babu Moger --- v6: Drop ctrl_en/mon_en and use resctrl_arch_alloc_capable() / resctrl_arch_mon_capable() directly. Flatten caps/active into resctrl_kmode_cfg. Rename resctrl_kcfg to resctrl_kmode, ctrl_mode to ctrl, mon_mode to mon, and k_rdtgrp to rdtgrp. Comments describe the objects, not a member list. Rewrite changelog. v5: Replace per-mode registration helpers with a single resctrl_kmode_cfg structure. Derive ctrl_en and mon_en from resctrl_arch_alloc_capable() and resctrl_arch_mon_capable() during filesystem init. Update code comments and changelog. v4: New patch to initialize supported kernel modes. https://lore.kernel.org/lkml/737a4228-52fb-4583-ac64-8efe79c107e6@intel.com/ Changed the kmode_cur to enum resctrl_kernel_mode in resctrl_kmode_cfg. Moved the resctrl_kmode_cfg to filesystem code. --- fs/resctrl/internal.h | 29 +++++++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index e62a277dee85..98f04a2a762b 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -314,6 +314,35 @@ struct mbm_state { u32 prev_bw; }; +/** + * enum kmode_state - Control or monitoring association + * @KMODE_INHERIT: Inherit from the user-space task. + * @KMODE_ASSIGN: Use the backing group's CLOSID or RMID. + */ +enum kmode_state { + KMODE_INHERIT, + KMODE_ASSIGN +}; + +/** + * struct resctrl_kmode_cfg - Kernel mode configuration + * @kmode_sup: Bitmap of supported kernel modes. + * @kmode_cur: Currently selected kernel mode. + * @ctrl: Control association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. + * Kept while %RESCTRL_INHERIT_USER is selected. + * @mon: Monitoring association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. + * Kept while %RESCTRL_INHERIT_USER is selected. + * @rdtgrp: Resource group backing %RESCTRL_GLOBAL_ENABLE_PER_CPU. + * %NULL while that mode is not selected. + */ +struct resctrl_kmode_cfg { + DECLARE_BITMAP(kmode_sup, RESCTRL_NUM_KERNEL_MODES); + enum resctrl_kernel_mode kmode_cur; + enum kmode_state ctrl; + enum kmode_state mon; + struct rdtgroup *rdtgrp; +}; + extern struct mutex rdtgroup_mutex; static inline const char *rdt_kn_name(const struct kernfs_node *kn) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 68be9b903ac6..7c39792be1fa 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -76,6 +76,9 @@ static void rdtgroup_destroy_root(void); struct dentry *debugfs_resctrl; +/* Kernel mode for this system. */ +static struct resctrl_kmode_cfg resctrl_kmode; + /* * Memory bandwidth monitoring event to use for the default CTRL_MON group * and each new CTRL_MON group created by the user. Only relevant when @@ -2297,6 +2300,26 @@ static void io_alloc_init(void) } } +/* + * Set RESCTRL_INHERIT_USER as the default when the platform supports + * allocation or monitoring. Otherwise leave kernel mode unsupported. + */ +static void resctrl_kmode_init(void) +{ + if (!resctrl_arch_alloc_capable() && !resctrl_arch_mon_capable()) + return; + + resctrl_kmode.kmode_cur = RESCTRL_INHERIT_USER; + __set_bit(RESCTRL_INHERIT_USER, resctrl_kmode.kmode_sup); + + /* + * Defaults used when RESCTRL_GLOBAL_ENABLE_PER_CPU mode is + * activated without new values. + */ + resctrl_kmode.ctrl = KMODE_ASSIGN; + resctrl_kmode.mon = KMODE_ASSIGN; +} + void resctrl_file_fflags_init(const char *config, unsigned long fflags) { struct rftype *rft; @@ -4814,6 +4837,8 @@ int resctrl_init(void) if (ret) return ret; + resctrl_kmode_init(); + ret = sysfs_create_mount_point(fs_kobj, "resctrl"); if (ret) { resctrl_l3_mon_resource_exit(); -- 2.43.0