Allow AET to use PMT/TPMI as loadable modules
Subsystems (4)
Tony Luck
maintainerv5 cover Allow AET to use PMT/TPMI as loadable modules
Requiring INTEL_PMT_TELEMETRY=y to enable AET is a functional workaround to enable enumeration of Application Energy Telemetry (AET) events, but unacceptable to many users. It results in increased kernel memory footprint and inability to patch problems by unloading a module and loading an updated version.
Add a registration function to the AET code that can be used by INTEL_PMT_TELEMETRY to provide the enumeration functions.
INTEL_PMT_TELEMETRY can be loaded/unloaded independently of resctrl file system mount/unmount. Perform enumeration on every mount and cleanup on every unmount.
---
Changes since v4:
Abandon use of symbol_request() - new uses are deprecated. Implement the registration mechanism suggested by Christoph. Re-order patches to avoid breaking AET enumeration. Kerneldoc comments on limits to enable/disable events. Add resctrl_mount_lock inline in rdt_get_tree() instead of adding a wrapper.
Tony Luck (7):
x86/resctrl: Stop setting event_group::force_off on RMID shortage fs/resctrl: Add interface to disable a monitor event x86/resctrl: x86/resctrl: Add PMT registration API for AET enumeration
callbacks
platform/x86/intel/pmt: Register enumeration functions with resctrl x86/resctrl: Resolve INTEL_PMT_TELEMETRY symbols at runtime fs/resctrl: Call architecture hooks for every mount/unmount x86/resctrl: Relax Kconfig dependency on INTEL_PMT_TELEMETRY
include/linux/resctrl.h | 44 +++++++++++++- arch/x86/include/asm/resctrl.h | 19 ++++++ arch/x86/kernel/cpu/resctrl/internal.h | 8 +-- arch/x86/kernel/cpu/resctrl/core.c | 23 +++++++- arch/x86/kernel/cpu/resctrl/intel_aet.c | 67 ++++++++++++++++++---- drivers/platform/x86/intel/pmt/telemetry.c | 10 ++++ fs/resctrl/monitor.c | 12 ++++ fs/resctrl/rdtgroup.c | 35 ++++++++--- arch/x86/Kconfig | 2 +- 9 files changed, 193 insertions(+), 27 deletions(-)
base-commit: 591cd656a1bf5ea94a222af5ef2ee76df029c1d2
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 1/7 x86/resctrl: Stop setting event_group::force_off on RMID shortage
Drop the force_off assignment from all_regions_have_sufficient_rmid(). This preserves current single-enumeration behaviour while preparing for the upcoming per-mount enumeration, where latching force_off would incorrectly suppress re-enumeration on subsequent mounts - even when the user explicitly requested the feature via "rdt={feature}".
--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/intel_aet.c +3 -5
@@ -60,8 +60,8 @@ struct pmt_event {* data for all telemetry regions of type @pfname. * Valid if the system supports the event group, * NULL otherwise. -* @force_off: True when "rdt" command line or architecture code disables -* this event group due to insufficient RMIDs. +* @force_off: True when "rdt" command line disables this event group +* to avoid system limitations due to insufficient RMIDs. * @force_on: True when "rdt" command line overrides disable of this * event group. * @guid: Unique number per XML description file.
@@ -214,10 +214,8 @@ static bool all_regions_have_sufficient_rmid(struct event_group *e, struct pmt_fif (!p->regions[i].addr)continue ; tr = &p->regions[i]; -if (tr->num_rmids < e->num_rmid) { - e->force_off = true; +if (tr->num_rmids < e->num_rmid)return false; - } }return true;
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 2/7 fs/resctrl: Add interface to disable a monitor event
In reply to Tony LuckIn preparation for re-running AET enumeration on every mount, AET code must be able to disable events on unmount so the next mount starts from a clean slate.
Add resctrl_disable_mon_event(eventid) which clears the enabled flag for the given event. Add kerneldoc comments to describe limitations on when events may be enabled or disabled.
--- include/linux/resctrl.h | 34 ++++++++++++++++++++++++++++++++++ fs/resctrl/monitor.c | 12 ++++++++++++ 2 files changed, 46 insertions(+)
include/linux/resctrl.h +34 -0
@@ -414,9 +414,43 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r);u32 resctrl_arch_system_num_rmid_idx (void );int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid); +/** +* resctrl_enable_mon_event() - Enable monitoring event +* @eventid: ID of the event +* @any_cpu: True if event data can be read from any CPU. +* @binary_bits:Number of binary places of the fixed-point value expected to +* back a floating point event. Can only be set for floating point +* events. +* @arch_priv: Architecture private data associated with event. Passed back to +* architecture when reading the event via resctrl_arch_rmid_read(). +* +* The file system must not be mounted when enabling an event. +* +* Events that require per-domain (architectural and/or filesystem) state must +* be enabled before the domain structures are allocated. For example before +* CPU hotplug callbacks that allocate domain structures are registered. If the +* architecture discovers a resource after initialization it should enable +* events needing per-domain state before any domain structure allocation which +* should be coordinated with the CPU hotplug callbacks. +* +* Return: +* true if event was successfully enabled, false otherwise. +*/ bool resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu,unsigned int binary_bits,void *arch_priv); +/** +* resctrl_disable_mon_event() - Disable monitoring event +* @eventid: ID of the event +* +* The file system must not be mounted when disabling an event. +* +* Events that require per-domain (architectural and/or filesystem) state +* will require additional cleanup which should be coordinated with the CPU +* hotplug callbacks. +*/ +void resctrl_disable_mon_event (enum resctrl_event_id eventid); +bool resctrl_is_mon_event_enabled (enum resctrl_event_id eventid);bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt);
fs/resctrl/monitor.c +12 -0
@@ -1010,6 +1010,18 @@ bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,return true; } +void resctrl_disable_mon_event (enum resctrl_event_id eventid) +{ +if (WARN_ON_ONCE (eventid <QOS_FIRST_EVENT || eventid >=QOS_NUM_EVENTS )) +return ; +if (!mon_event_all[eventid].enabled) { +pr_warn ("Repeat disable for event %d\n" , eventid); +return ; + } + + mon_event_all[eventid].enabled = false; +} +bool resctrl_is_mon_event_enabled (enum resctrl_event_id eventid) { return eventid >= QOS_FIRST_EVENT && eventid < QOS_NUM_EVENTS &&
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 3/7 x86/resctrl: x86/resctrl: Add PMT registration API for AET enumeration callbacks
In reply to Tony Luckresctrl is always built-in; INTEL_PMT_TELEMETRY may be a module. Add, and export, register/unregister functions so the PMT module can supply/clear enumeration callback functions when loaded/unloaded.
--- arch/x86/include/asm/resctrl.h | 19 ++++++++++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 35 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
arch/x86/include/asm/resctrl.h +19 -0
@@ -4,6 +4,8 @@#ifdef CONFIG_X86_CPU_RESCTRL +#include <linux/intel_pmt_features.h> +#include <linux/intel_vsec.h> #include <linux/jump_label.h> #include <linux/percpu.h> #include <linux/resctrl_types.h>
@@ -193,11 +195,28 @@ static inline void resctrl_arch_mon_ctx_free(struct rdt_resource *r,void resctrl_cpu_detect (struct cpuinfo_x86 *c); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET +void intel_aet_register_enumeration (struct pmt_feature_group *(*get)(enum pmt_feature_id id), +void (*put)(struct pmt_feature_group *p)); +void intel_aet_unregister_enumeration (void );#else +static inline void intel_aet_register_enumeration (struct pmt_feature_group *(*get)(enum pmt_feature_id id), +void (*put)(struct pmt_feature_group *p)) { } +static inline void intel_aet_unregister_enumeration (void ) { } +#endif /* CONFIG_X86_CPU_RESCTRL_INTEL_AET */ + +#else + +#include <linux/intel_pmt_features.h> +#include <linux/intel_vsec.h> static inline void resctrl_arch_sched_in (struct task_struct *tsk) {}static inline void resctrl_cpu_detect (struct cpuinfo_x86 *c) {} +static inline void intel_aet_register_enumeration (struct pmt_feature_group *(*get)(enum pmt_feature_id id), +void (*put)(struct pmt_feature_group *p)) { } +static inline void intel_aet_unregister_enumeration (void ) { } +#endif /* CONFIG_X86_CPU_RESCTRL */ #endif /* _ASM_X86_RESCTRL_H */
arch/x86/kernel/cpu/resctrl/intel_aet.c +35 -0
@@ -12,17 +12,21 @@#define pr_fmt (fmt) "resctrl: " fmt#include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/compiler_types.h> #include <linux/container_of.h> #include <linux/cpumask.h> #include <linux/err.h> #include <linux/errno.h> +#include <linux/export.h> #include <linux/gfp_types.h> #include <linux/init.h> #include <linux/intel_pmt_features.h> #include <linux/intel_vsec.h> #include <linux/io.h> #include <linux/minmax.h> +#include <linux/mutex.h> +#include <linux/module.h> #include <linux/printk.h> #include <linux/rculist.h> #include <linux/rcupdate.h>
@@ -289,6 +293,9 @@ static enum pmt_feature_id lookup_pfid(const char *pfname)return FEATURE_INVALID ; } +static struct pmt_feature_group *(*get_feature)(enum pmt_feature_id id); +static void (*put_feature)(struct pmt_feature_group *p); +/* * Request a copy of struct pmt_feature_group for each event group. If there is * one, the returned structure has an array of telemetry_region structures,
@@ -323,6 +330,25 @@ bool intel_aet_get_events(void)return ret; } +static DEFINE_MUTEX (aet_register_lock); + +void intel_aet_register_enumeration (struct pmt_feature_group *(*get)(enum pmt_feature_id id), +void (*put)(struct pmt_feature_group *p)) +{ +guard (mutex)(&aet_register_lock); + get_feature = get; + put_feature = put; +} +EXPORT_SYMBOL_GPL (intel_aet_register_enumeration); + +void intel_aet_unregister_enumeration (void ) +{ +guard (mutex)(&aet_register_lock); + get_feature =NULL ; + put_feature =NULL ; +} +EXPORT_SYMBOL_GPL (intel_aet_unregister_enumeration); + void __exit intel_aet_exit(void) {struct event_group **peg;
@@ -405,3 +431,12 @@ void intel_aet_mon_domain_setup(int cpu, int id, struct rdt_resource *r,kfree (d); } } + +static int __init intel_aet_init (void ) +{ +request_module ("pmt_telemetry" ); + +return 0 ; +} + +late_initcall (intel_aet_init);
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 4/7 platform/x86/intel/pmt: Register enumeration functions with resctrl
In reply to Tony LuckINTEL_PMT_TELEMETRY is a loadable module, but resctrl is built-in and cannot call PMT functions directly. Register the telemetry enumeration function pointers at resctrl module init, and unregister them at module exit.
Add module_{get,put} calls to the PMT get/put functions to ensure that INTEL_PMT_TELEMETRY cannot be unloaded while resctrl is mounted and referencing the MMIO register space mapped by INTEL_PMT_TELEMETRY.
Note that checkpatch complains about the #include of <asm/resctrl.h>. This is needed rather than <linux/resctrl.h> to get the function stub definitions when CONFIG_X86_CPU_RESCTRL=n.
--- drivers/platform/x86/intel/pmt/telemetry.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/platform/x86/intel/pmt/telemetry.c +10 -0
@@ -25,6 +25,8 @@#include <linux/uaccess.h> #include <linux/xarray.h> +#include <asm/resctrl.h> +#include "class.h" #define TELEM_SIZE_OFFSET 0x0
@@ -283,6 +285,9 @@ struct pmt_feature_group *intel_pmt_get_regions_by_feature(enum pmt_feature_id i region++; } +if (!try_module_get (THIS_MODULE )) +return ERR_PTR (-EINVAL ); +kref_init (&feature_group->kref);return no_free_ptr (feature_group);
@@ -292,6 +297,7 @@ EXPORT_SYMBOL(intel_pmt_get_regions_by_feature);void intel_pmt_put_feature_group (struct pmt_feature_group *feature_group) {kref_put (&feature_group->kref, pmt_feature_group_release); +module_put (THIS_MODULE ); }EXPORT_SYMBOL (intel_pmt_put_feature_group);
@@ -404,6 +410,9 @@ static int pmt_telem_probe(struct auxiliary_device *auxdev, const struct auxiliaintel_pmt_get_features (entry); } +intel_aet_register_enumeration (intel_pmt_get_regions_by_feature, + intel_pmt_put_feature_group); +return 0 ; abort_probe:pmt_telem_remove (auxdev);
@@ -432,6 +441,7 @@ static void __exit pmt_telem_exit(void) {auxiliary_driver_unregister (&pmt_telem_aux_driver);xa_destroy (&telem_array); +intel_aet_unregister_enumeration (); }module_exit (pmt_telem_exit);
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 5/7 x86/resctrl: Resolve INTEL_PMT_TELEMETRY symbols at runtime
In reply to Tony Luckresctrl is always built-in, but INTEL_PMT_TELEMETRY and INTEL_TPMI are logically independent and should be loadable modules. Switch AET to use the function-pointer registration API (introduced in the preceding patch) instead of direct link-time references to PMT symbols.
Move AET enumeration into resctrl_arch_pre_mount() and cleanup into resctrl_arch_unmount() so the PMT module can be unloaded whenever the filesystem is not mounted. Because all cleanup now happens in the unmount path, intel_aet_exit() is no longer needed and is removed.
--- include/linux/resctrl.h | 3 +++ arch/x86/kernel/cpu/resctrl/internal.h | 8 ++++---- arch/x86/kernel/cpu/resctrl/core.c | 23 +++++++++++++++++++--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 26 +++++++++++++++++++------ 4 files changed, 47 insertions(+), 13 deletions(-)
include/linux/resctrl.h +3 -0
@@ -556,6 +556,9 @@ void resctrl_offline_cpu(unsigned int cpu);*/ void resctrl_arch_pre_mount (void ); +/* Called to report unmount. */ +void resctrl_arch_unmount (void ); +/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid * for this resource and domain.
arch/x86/kernel/cpu/resctrl/internal.h +4 -4
@@ -234,15 +234,15 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r);void resctrl_arch_mbm_cntr_assign_set_one (struct rdt_resource *r);#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET -bool intel_aet_get_events (void ); -void __exit intel_aet_exit(void); +bool intel_aet_pre_mount (void ); +void intel_aet_unmount (void );int intel_aet_read_event (int domid,u32 rmid,void *arch_priv,u64 *val);void intel_aet_mon_domain_setup (int cpu,int id,struct rdt_resource *r,struct list_head *add_pos);bool intel_handle_aet_option (bool force_off,char *tok);#else -static inline bool intel_aet_get_events (void ) {return false; } -static inline void __exit intel_aet_exit(void) { } +static inline bool intel_aet_pre_mount (void ) {return false; } +static inline void intel_aet_unmount (void ) { }static inline int intel_aet_read_event (int domid,u32 rmid,void *arch_priv,u64 *val) {return -EINVAL ;
arch/x86/kernel/cpu/resctrl/core.c +20 -3
@@ -769,7 +769,7 @@ void resctrl_arch_pre_mount(void)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG ].r_resctrl;int cpu; -if (!intel_aet_get_events ()) +if (!intel_aet_pre_mount ())return ;/*
@@ -786,6 +786,25 @@ void resctrl_arch_pre_mount(void)cpus_read_unlock (); } +void resctrl_arch_unmount (void ) +{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG ].r_resctrl; +int cpu; + +intel_aet_unmount (); + +if (!r->mon_capable) +return ; + +cpus_read_lock (); +mutex_lock (&domain_list_lock); +for_each_online_cpu (cpu) +domain_remove_cpu_mon (cpu, r); + r->mon_capable = false; +mutex_unlock (&domain_list_lock); +cpus_read_unlock (); +} +enum {RDT_FLAG_CMT ,RDT_FLAG_MBM_TOTAL ,
@@ -1160,8 +1179,6 @@ late_initcall(resctrl_arch_late_init); static void __exit resctrl_arch_exit(void) { -intel_aet_exit (); -cpuhp_remove_state (rdt_online);resctrl_exit ();
arch/x86/kernel/cpu/resctrl/intel_aet.c +20 -6
@@ -25,8 +25,8 @@#include <linux/intel_vsec.h> #include <linux/io.h> #include <linux/minmax.h> -#include <linux/mutex.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/printk.h> #include <linux/rculist.h> #include <linux/rcupdate.h>
@@ -307,7 +307,7 @@ static void (*put_feature)(struct pmt_feature_group *p);* struct pmt_feature_group to indicate that its events are successfully * enabled. */ -bool intel_aet_get_events (void ) +static bool aet_get_events (void ) {struct pmt_feature_group *p;enum pmt_feature_id pfid;
@@ -316,14 +316,14 @@ bool intel_aet_get_events(void)for_each_event_group (peg) { pfid =lookup_pfid ((*peg)->pfname); - p =intel_pmt_get_regions_by_feature (pfid); + p =get_feature (pfid);if (IS_ERR_OR_NULL (p))continue ;if (enable_events (*peg, p)) { (*peg)->pfg = p; ret = true; }else { -intel_pmt_put_feature_group (p); +put_feature (p); } }
@@ -349,13 +349,27 @@ void intel_aet_unregister_enumeration(void) }EXPORT_SYMBOL_GPL (intel_aet_unregister_enumeration); -void __exit intel_aet_exit(void) +bool intel_aet_pre_mount (void ) +{ +guard (mutex)(&aet_register_lock); +if (!get_feature || !put_feature) +return false; + +return aet_get_events (); +} + +void intel_aet_unmount (void ) {struct event_group **peg; +guard (mutex)(&aet_register_lock);for_each_event_group (peg) {if ((*peg)->pfg) { -intel_pmt_put_feature_group ((*peg)->pfg); +struct event_group *e = *peg; + +for (int j =0 ; j < e->num_events; j++) +resctrl_disable_mon_event (e->evts[j].id); +put_feature ((*peg)->pfg); (*peg)->pfg =NULL ; } }
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 6/7 fs/resctrl: Call architecture hooks for every mount/unmount
In reply to Tony LuckArchitecture code for AET needs to acquire INTEL_PMT_TELEMETRY module references on mount and release them on unmount.
Add hooks for every mount/unmount of the resctrl file system so that architecture code can allocate on mount and free on unmount.
Add resctrl_mount_lock to protect mount/unmount operations and write access to "resctrl_mounted". This simplifies the code flow around the repeat mount with -EBUSY return to avoid calling resctrl_arch_pre_mount() when the file system is mounted.
--- include/linux/resctrl.h | 9 ++++++--- fs/resctrl/rdtgroup.c | 35 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-)
include/linux/resctrl.h +6 -3
@@ -551,12 +551,15 @@ void resctrl_online_cpu(unsigned int cpu);void resctrl_offline_cpu (unsigned int cpu);/* -* Architecture hook called at beginning of first file system mount attempt. -* No locks are held. +* Architecture hook called before attempting to mount the file system. +* Called with just resctrl_mount_lock held. */ void resctrl_arch_pre_mount (void ); -/* Called to report unmount. */ +/* +* Architecture hook called when mount fails, or on unmount. +* Called with just resctrl_mount_lock held. +*/ void resctrl_arch_unmount (void );/**
fs/resctrl/rdtgroup.c +28 -7
@@ -18,7 +18,6 @@#include <linux/fs_parser.h> #include <linux/sysfs.h> #include <linux/kernfs.h> -#include <linux/once.h> #include <linux/resctrl.h> #include <linux/seq_buf.h> #include <linux/seq_file.h>
@@ -48,7 +47,14 @@ LIST_HEAD(resctrl_schema_all);*/ static LIST_HEAD (mon_data_kn_priv_list); -/* The filesystem can only be mounted once. */ +/* Mutex protecting mount/unmount operations */ +static DEFINE_MUTEX (resctrl_mount_lock); + +/* +* The filesystem can only be mounted once. +* Updated with both rdtgroup_mutex and resctrl_mount_lock held. +* Safe to read while holding either rdtgroup_mutex or resctrl_mount_lock. +*/ bool resctrl_mounted;/* Kernel fs node for "info" directory under root */
@@ -2788,18 +2794,21 @@ static int rdt_get_tree(struct fs_context *fc)struct rdt_resource *r;int ret; -DO_ONCE_SLEEPABLE (resctrl_arch_pre_mount); +mutex_lock (&resctrl_mount_lock); -cpus_read_lock (); -mutex_lock (&rdtgroup_mutex);/* * resctrl file system can only be mounted once. */ if (resctrl_mounted) { - ret = -EBUSY ; - goto out; +mutex_unlock (&resctrl_mount_lock); +return -EBUSY ; } +resctrl_arch_pre_mount (); + +cpus_read_lock (); +mutex_lock (&rdtgroup_mutex); + ret =setup_rmid_lru_list ();if (ret) goto out;
@@ -2897,6 +2906,12 @@ static int rdt_get_tree(struct fs_context *fc)rdt_last_cmd_clear ();mutex_unlock (&rdtgroup_mutex);cpus_read_unlock (); + +if (ret) +resctrl_arch_unmount (); + +mutex_unlock (&resctrl_mount_lock); +return ret; }
@@ -3169,6 +3184,8 @@ static void rdt_kill_sb(struct super_block *sb) {struct rdt_resource *r; +mutex_lock (&resctrl_mount_lock); +cpus_read_lock ();mutex_lock (&rdtgroup_mutex);
@@ -3187,6 +3204,10 @@ static void rdt_kill_sb(struct super_block *sb)kernfs_kill_sb (sb);mutex_unlock (&rdtgroup_mutex);cpus_read_unlock (); + +resctrl_arch_unmount (); + +mutex_unlock (&resctrl_mount_lock); }static struct file_system_type rdt_fs_type = {
Signature · 1 line
2.53.0
Tony Luck
maintainerRFC PATCH v5 7/7 x86/resctrl: Relax Kconfig dependency on INTEL_PMT_TELEMETRY
In reply to Tony LuckNow that AET resolves PMT symbols at runtime via the registration API, INTEL_PMT_TELEMETRY no longer needs to be built-in. Relax the Kconfig dependency so that INTEL_PMT_TELEMETRY can be configured as a loadable module.
--- arch/x86/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Kconfig +1 -1
@@ -542,7 +542,7 @@ config X86_CPU_RESCTRL config X86_CPU_RESCTRL_INTEL_AET bool "Intel Application Energy Telemetry" - depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL && INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y + depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL && INTEL_PMT_TELEMETRY != n && INTEL_TPMI != n help Enable per-RMID telemetry events in resctrl.
Signature · 1 line
2.53.0