x86,fs/resctrl telemetry monitoring
Subsystems (3)
Tony Luck
maintainerv9 cover x86,fs/resctrl telemetry monitoring
This patch series also available from the rdt-aet-v9 of:git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git
Changes since v8 was posted here:
--- cover ---
"INTEL_PMT_DISCOVERY" -> "INTEL_PMT_TELEMETRY"
--- 1 ---
No change
--- 2 ---
No change
--- 3 ---
No change
--- 4 ---
No change
--- 5 ---
"The "type" field provides" -> "rdt_domain_hdr::type provides" Update final paragraph of commit message as suggested.
--- 6 ---
Code: in domain_add_cpu_mon() change WARN_ON_ONCE(1); in default case to
pr_warn_once("Unknown resource rid=%d\n", r->rid);
--- 7 ---
Code: in domain_remove_cpu_mon() move domain_header_is_valid()to
immediately before container_of() and switch check from r->rid to hard-coded RDT_RESOURCE_L3. s/list_del_rcu(&d->hdr.list);/list_del_rcu(&hdr->list);/
"separated" -> "separate"
"can skip" -> "skips"
--- 8 ---
Code: in domain_remove_cpu_ctrl() move domain_header_is_valid()
to immediately before container_of(). s/list_del_rcu(&d->hdr.list);/list_del_rcu(&hdr->list);/ (moved here from patch 9)
"refactor" -> "refactor domain_remove_cpu_ctrl()"
--- 9 ---
Change second paragraph of commit comment as suggested.
"so the rmid_read::d field is replaced" -> "so replace the L3 specific domain pointer rmid_read::d with rmid_read::hdr that points to the generic domain header"
Use imperative tone for last paragraph "Update kerneldoc for mon_data::sum ..."
--- 10 ---
Change rdt_mon_domain to rdt_l3_mon_domain in comment above logical_rmid_to_physical_rmid()
Replace entire commit comment with improved version.
--- 11 ---
"different resources" -> "a different resource"
"these functions" -> "the L3 resource specific functions"
"Two groups of functions renamed here:" -> "Rename three groups of functions:" Added rdt_get_mon_l3_config() to list of renamed functions to put the "l3" before the "mon" for consistency.
When changing names for resctrl_mon_resource_{init,exit} add the "l3_" before "mon" for consistency with other *l3_mon*" naming.
--- 12 ---
"to lower levels" -> "via the mon_data and rmid_read structures to the functions finally reading the monitoring data."
Replace 3rd paragraph of commit comment with supplied better version.
--- 13 ---
Code: In cpu_on_correct_domain() s/return -EINVAL;/return false;/
--- 14 ---
Code: Move definition of MAX_BINARY_BITS from <linux/resctrl.h> to
fs/resctrl/internal.h.
Be explicit in commit comment that the file system makes the determination on which events can be displayed in floating point format.
--- 15 ---
"asyncronnous" -> "asynchronous"
"for these drivers" -> "of these drivers"
"are called" -> "completes"
"But expectations" -> "Expectations"
"The call is made with no locks held." -> "resctrl filesystem calls the hook with no locks held."
--- 16 ---
s/CPU hotplug/CPU hot plug/
Add Reinette's RB tag.
--- 17 ---
Code:
"OOBMSM" -> "INTEL_PMT_TELEMETRY"
"INTEL_PMT_DISCOVERY" -> "INTEL_PMT_TELEMETRY"
re-wrap comment for get_pmt_feature() to use 80 columns. "OOBMSM discovery" -> "INTEL_PMT_TELEMETRY"
Add the intel_pmt_put_feature_group() calls to intel_aet_exit() to match the intel_pmt_get_regions_by_feature() calls in get_pmt_feature() using a new macro for_each_enabled_event_group().
Rename discover_events() to enable_events()
Add period at end of help text in arch/x86/Kconfig.
"Data for telemetry events is collected by each CPU and sent" ->
"Each CPU collects data for telemetry events that it sends"
"is changed" -> "changes"
"or when two milliseconds have elapsed" -> "or when a two millisecond timer expires" "mad" -> "made"
"Enumeration of support for telemetry events is done" ->
"The INTEL_PMT_TELEMETRY driver enumerates support for telemetry events." Drop references to INTEL_PMT_DISCOVERY driver.
Merge last two paragraphs of commit message.
Reformat commit to use more of page width.
Add maintainer note about checkpatch complaints for DEFINE_FREE()
--- 18 ---
Dropped. See new patch 0019
--- 19 ---
Dropped. See new patch 0019
--- 20 ---
Now 0018
Rewrite opening paragraph to avoid "continuation of the subject"
Add note/link on the source of the XML files that describe events.
--- 21 ---
Now 0019
Drop "vague first sentence" of second paragraph.
--- NEW 0020 ---
Replaces most of parts 18/32 and 19/32.
Contains skip_this_region() from patch 18/32, but skips all the code to count regions and allocat pkg_mmio_info[]. The active_event_groups list is also removed in this refactor.
Also includes event enabling code from 22/32
--- 22 ---
Now 0021
Modify intel_aet_read_event() to dig into pmt_event::pfg to find the MMIO base addresses that v8 patch stored in the pkg_mmio_info[] structures.
--- 23 ---
Now 0022
Add domain_header_is_valid() check in domain_remove_cpu_mon() before using container_of().
"There are structures" -> "There are per domain structures ..."
Replace my commit fix description with better version from Reinette.
--- 24 ---
Now 0023
Unparseable last sentence of commit message replaced with details and examples.
--- 25 ---
Now 0024
RMIDS -> RMIDs
"Adjusted downwards ..." -> "May be adjusted downwards ..." check_rmid_count() -> all_regions_have_sufficient_rmid()
"Potentially disable" -> "Disable"
Add comment:
/* e->num_rmids only adjusted lower if user forces an unusable region to be usable */
--- 26 ---
Now 0025
Add "during resctrl initialization" and "during resctrl exit" to commit background statement.
Add "closid_num_dirty_rmid[]" to be specific about what is being allocated/freed.
--- 27 ---
Now 0026
"mon capable" -> "mon_capable" (three times)
"alloc capable" -> "alloc_capable" "rdt_l3_mon_domain::states[]" -> "rdt_l3_mon_domain::mbm_states[] and +rdt_l3_mon_domain::rmid_busy_llc"
"the number of RMIDs" -> "the system's number of RMIDs"
--- 28 ---
Now 0027
Add comment to setup_rmid_lru_list() to note that rmid_ptrs[] is allocated of first mount and is reused on subsequent mounts. It is freed in resctrl_exit().
Lock/unlock rdtgroup_mutex around body of free_rmid_lru_list()
Rewrite commit based on suggestions with some modifications to explain why error paths in rdt_get_tree() do not call free_rmid_lru_list().
--- 29 ---
Now 0028
TODO: recheck for use of "CPU hot plug notifiers" may have been called "hooks", "callbacks", and "handlers" through this series.
--- 30 ---
Now 0029
"a resource" -> "a monitoring resource"
--- 31 ---
Now 0030
"last_update_timestamp" -> "agg_last_update_timestamp" in commit comment
Move creation of debugfs files to the end of enable_events().
Rewrite to work based on event_group::pfg since event_group::pkginfo[] is gone.
--- 32 ---
Now 0031
Describe "num_rmids" file values independently for L3 and telemetry. Move the note about upper bound on directory creation to its own paragraph to say it is the smaller of reported "num_rmids" values.
"or of a processor package" -> "another for each processor package"
Change paragraph about contents of subdirectories of mon_data to give example file names instead of hard coding specifics.
Improve documentation for "core_energy" to make it clear that is is collected per logical CPU and the "core" in the name refers to the scope of the energy collection.
Fix debugfs documentation to match implementation.
prescence -> presence
will vary -> may vary last_update_timestamp -> agg_last_update_timestamp
Simplify commit comment as suggested.
Background
----------
On Intel systems that support per-RMID telemetry monitoring each logical processor keeps a local count for various events. When the IA32_PQR_ASSOC.RMID value for the logical processor changes (or when a two millisecond counter expires) these event counts are transmitted to an event aggregator on the same package as the processor together with the current RMID value. The event counters are reset to zero to begin counting again.
Each aggregator takes the incoming event counts and adds them to cumulative counts for each event for each RMID. Note that there can be multiple aggregators on each package with no architectural association between logical processors and an aggregator.
All of these aggregated counters can be read by an operating system from the MMIO space of the Out Of Band Management Service Module (OOBMSM) device(s) on a system. Any counter can be read from any logical processor.
Intel publishes details for each processor generation showing which events are counted by each logical processor and the offsets for each accumulated counter value within the MMIO space in XML files here:
https://github.com/intel/Intel-PMT.
For example there are two energy related telemetry events for the Clearwater Forest family of processors and the MMIO space looks like this:
Offset RMID Event ------ ---- ----- 0x0000 0 core_energy 0x0008 0 activity 0x0010 1 core_energy 0x0018 1 activity ... 0x23F0 575 core_energy 0x23F8 575 activity
In addition the XML file provides the units (Joules for core_energy, Farads for activity) and the type of data (fixed-point binary with bit 63 used to indicate the data is valid, and the low 18 bits as a binary fraction).
Finally, each XML file provides a 32-bit unique id (or guid) that is used as an index to find the correct XML description file for each telemetry implementation.
The INTEL_PMT_TELEMETRY driver provides intel_pmt_get_regions_by_feature() to enumerate the aggregator instances (also referred to as "telemetry regions" in this series) on a platform. It provides:
1) guid - so resctrl can determine which events are supported
2) MMIO base address of counters
3) package id
Resctrl accumulates counts from all aggregators on a package in order to provide a consistent user interface across processor generations.
Directory structure for the telemetry events looks like this:
$ tree /sys/fs/resctrl/mon_data/
/sys/fs/resctrl/mon_data/
mon_data
├── mon_PERF_PKG_00
│ ├── activity
│ └── core_energy
└── mon_PERF_PKG_01
├── activity
└── core_energyReading the "core_energy" file from some resctrl mon_data directory shows the cumulative energy (in Joules) used by all tasks that ran with the RMID associated with that directory on a given package. Note that "core_energy" reports only energy consumed by CPU cores (data processing units, L1/L2 caches, etc.). It does not include energy used in the "uncore" (L3 cache, on package devices, etc.), or used by memory or I/O devices.
Tony Luck (31):
x86,fs/resctrl: Consolidate monitor event descriptions x86,fs/resctrl: Replace architecture event enabled checks x86/resctrl: Remove 'rdt_mon_features' global variable x86,fs/resctrl: Prepare for more monitor events x86,fs/resctrl: Improve domain type checking
x86/resctrl: Move L3 initialization into new helper function x86,fs/resctrl: Refactor domain_remove_cpu_mon() ready for new domain
types
x86/resctrl: Clean up domain_remove_cpu_ctrl() x86,fs/resctrl: Use struct rdt_domain_hdr instead of struct
rdt_mon_domain
x86,fs/resctrl: Rename struct rdt_mon_domain and rdt_hw_mon_domain x86,fs/resctrl: Rename some L3 specific functions fs/resctrl: Make event details accessible to functions when reading
events
x86,fs/resctrl: Handle events that can be read from any CPU x86,fs/resctrl: Support binary fixed point event counters x86,fs/resctrl: Add an architectural hook called for each mount x86,fs/resctrl: Add and initialize rdt_resource for package scope
monitor
x86/resctrl: Discover hardware telemetry events x86,fs/resctrl: Fill in details of events for guid 0x26696143 and
0x26557651
x86,fs/resctrl: Add architectural event pointer x86/resctrl: Find and enable usable telemetry events x86/resctrl: Read telemetry events
x86/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG x86/resctrl: Add energy/perf choices to rdt boot option x86/resctrl: Handle number of RMIDs supported by telemetry resources fs/resctrl: Move allocation/free of closid_num_dirty_rmid fs,x86/resctrl: Compute number of RMIDs as minimum across resources fs/resctrl: Move RMID initialization to first mount x86/resctrl: Enable RDT_RESOURCE_PERF_PKG
fs/resctrl: Provide interface to create architecture specific debugfs
area
x86/resctrl: Add debugfs files to show telemetry aggregator status x86,fs/resctrl: Update Documentation for package events
.../admin-guide/kernel-parameters.txt | 2 +- Documentation/filesystems/resctrl.rst | 99 ++++- include/linux/resctrl.h | 87 +++- include/linux/resctrl_types.h | 26 +- arch/x86/include/asm/resctrl.h | 16 - arch/x86/kernel/cpu/resctrl/internal.h | 58 ++- fs/resctrl/internal.h | 71 +++- arch/x86/kernel/cpu/resctrl/core.c | 315 +++++++++++---- arch/x86/kernel/cpu/resctrl/intel_aet.c | 381 ++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 80 ++-- fs/resctrl/ctrlmondata.c | 123 +++++- fs/resctrl/monitor.c | 315 ++++++++------- fs/resctrl/rdtgroup.c | 272 ++++++++----- arch/x86/Kconfig | 13 + arch/x86/kernel/cpu/resctrl/Makefile | 1 + 15 files changed, 1400 insertions(+), 459 deletions(-) create mode 100644 arch/x86/kernel/cpu/resctrl/intel_aet.c
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
Signature · 1 line
2.50.1
Tony Luck
maintainerPATCH v9 1/31 x86,fs/resctrl: Consolidate monitor event descriptions
There are currently only three monitor events, all associated with the RDT_RESOURCE_L3 resource. Growing support for additional events will be easier with some restructuring to have a single point in file system code where all attributes of all events are defined.
Place all event descriptions into an array mon_event_all[]. Doing this has the beneficial side effect of removing the need for rdt_resource::evt_list.
Add resctrl_event_id::QOS_FIRST_EVENT for a lower bound on range checks for event ids and as the starting index to scan mon_event_all[].
Drop the code that builds evt_list and change the two places where the list is scanned to scan mon_event_all[] instead using a new helper macro for_each_mon_event().
Architecture code now informs file system code which events are available with resctrl_enable_mon_event().
--- include/linux/resctrl.h | 4 +- include/linux/resctrl_types.h | 12 ++++-- fs/resctrl/internal.h | 13 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++-- fs/resctrl/monitor.c | 63 +++++++++++++++--------------- fs/resctrl/rdtgroup.c | 11 +++--- 6 files changed, 66 insertions(+), 49 deletions(-)
include/linux/resctrl.h +2 -2
@@ -269,7 +269,6 @@ enum resctrl_schema_fmt {* @mon_domains: RCU list of all monitor domains for this resource * @name: Name to use in "schemata" file. * @schema_fmt: Which format string and parser is used for this schema. -* @evt_list: List of monitoring events * @mbm_cfg_mask: Bandwidth sources that can be tracked when bandwidth * monitoring events can be configured. * @cdp_capable: Is the CDP feature available on this resource
@@ -287,7 +286,6 @@ struct rdt_resource {struct list_head mon_domains;char *name;enum resctrl_schema_fmt schema_fmt; -struct list_head evt_list;unsigned int mbm_cfg_mask;bool cdp_capable; };
@@ -372,6 +370,8 @@ 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); +void resctrl_enable_mon_event (enum resctrl_event_id eventid); +bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt);/**
include/linux/resctrl_types.h +8 -4
@@ -34,11 +34,15 @@/* Max event bits supported */ #define MAX_EVT_CONFIG_BITS GENMASK(6, 0) -/* -* Event IDs, the values match those used to program IA32_QM_EVTSEL before -* reading IA32_QM_CTR on RDT systems. -*/ +/* Event IDs */ enum resctrl_event_id { +/* Must match value of first event below */ +QOS_FIRST_EVENT =0x01 , + +/* +* These values match those used to program IA32_QM_EVTSEL before +* reading IA32_QM_CTR on RDT systems. +*/ QOS_L3_OCCUP_EVENT_ID =0x01 ,QOS_L3_MBM_TOTAL_EVENT_ID =0x02 ,QOS_L3_MBM_LOCAL_EVENT_ID =0x03 ,
fs/resctrl/internal.h +10 -3
@@ -52,19 +52,26 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc) }/** -* struct mon_evt - Entry in the event list of a resource +* struct mon_evt - Properties of a monitor event * @evtid: event id +* @rid: resource id for this event * @name: name of the event * @configurable: true if the event is configurable -* @list: entry in &rdt_resource->evt_list +* @enabled: true if the event is enabled */ struct mon_evt {enum resctrl_event_id evtid; +enum resctrl_res_level rid;char *name;bool configurable; -struct list_head list; +bool enabled; }; +extern struct mon_evt mon_event_all[QOS_NUM_EVENTS ]; + +#define for_each_mon_event (mevt) for (mevt = &mon_event_all[QOS_FIRST_EVENT]; \ + mevt < &mon_event_all[QOS_NUM_EVENTS]; mevt++) +/** * struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list.
arch/x86/kernel/cpu/resctrl/core.c +9 -3
@@ -864,12 +864,18 @@ static __init bool get_rdt_mon_resources(void) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) +if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) { +resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID ); rdt_mon_features |= (1 <<QOS_L3_OCCUP_EVENT_ID ); -if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) + } +if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) { +resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID ); rdt_mon_features |= (1 <<QOS_L3_MBM_TOTAL_EVENT_ID ); -if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) + } +if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) { +resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID ); rdt_mon_features |= (1 <<QOS_L3_MBM_LOCAL_EVENT_ID ); + }if (!rdt_mon_features)return false;
fs/resctrl/monitor.c +31 -32
84 lines not on this page · raw message
fs/resctrl/rdtgroup.c +6 -5
@@ -1152,7 +1152,9 @@ static int rdt_mon_features_show(struct kernfs_open_file *of,struct rdt_resource *r =rdt_kn_parent_priv (of->kn);struct mon_evt *mevt; -list_for_each_entry (mevt, &r->evt_list, list) { +for_each_mon_event (mevt) { +if (mevt->rid != r->rid || !mevt->enabled) +continue ;seq_printf (seq,"%s\n" , mevt->name);if (mevt->configurable)seq_printf (seq,"%s_config\n" , mevt->name);
@@ -3057,10 +3059,9 @@ static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain *d,struct mon_evt *mevt;int ret, domid; -if (WARN_ON (list_empty (&r->evt_list))) -return -EPERM ; - -list_for_each_entry (mevt, &r->evt_list, list) { +for_each_mon_event (mevt) { +if (mevt->rid != r->rid || !mevt->enabled) +continue ; domid = do_sum ? d->ci_id : d->hdr.id; priv =mon_get_kn_priv (r->rid, domid, mevt, do_sum);if (WARN_ON_ONCE (!priv))
Signature · 1 line
2.50.1
Tony Luck
maintainerPATCH v9 2/31 x86,fs/resctrl: Replace architecture event enabled checks
In reply to Tony LuckThe resctrl file system now has complete knowledge of the status of every event. So there is no need for per-event function calls to check.
Replace each of the resctrl_arch_is_{event}enabled() calls with resctrl_is_mon_event_enabled(QOS_{EVENT}).
No functional change.
--- include/linux/resctrl.h | 2 ++ arch/x86/include/asm/resctrl.h | 15 --------------- arch/x86/kernel/cpu/resctrl/core.c | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- fs/resctrl/ctrlmondata.c | 4 ++-- fs/resctrl/monitor.c | 16 +++++++++++----- fs/resctrl/rdtgroup.c | 18 +++++++++--------- 7 files changed, 28 insertions(+), 35 deletions(-)
include/linux/resctrl.h +2 -0
@@ -372,6 +372,8 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);void resctrl_enable_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);/**
arch/x86/include/asm/resctrl.h +0 -15
@@ -84,21 +84,6 @@ static inline void resctrl_arch_disable_mon(void)static_branch_dec_cpuslocked (&rdt_enable_key); } -static inline bool resctrl_arch_is_llc_occupancy_enabled (void ) -{ -return (rdt_mon_features & (1 <<QOS_L3_OCCUP_EVENT_ID )); -} - -static inline bool resctrl_arch_is_mbm_total_enabled (void ) -{ -return (rdt_mon_features & (1 <<QOS_L3_MBM_TOTAL_EVENT_ID )); -} - -static inline bool resctrl_arch_is_mbm_local_enabled (void ) -{ -return (rdt_mon_features & (1 <<QOS_L3_MBM_LOCAL_EVENT_ID )); -} -/* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR *
arch/x86/kernel/cpu/resctrl/core.c +2 -2
@@ -402,13 +402,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *hw_dom) {size_t tsize; -if (resctrl_arch_is_mbm_total_enabled ()) { +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID )) { tsize =sizeof (*hw_dom->arch_mbm_total); hw_dom->arch_mbm_total =kcalloc (num_rmid, tsize,GFP_KERNEL );if (!hw_dom->arch_mbm_total)return -ENOMEM ; } -if (resctrl_arch_is_mbm_local_enabled ()) { +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )) { tsize =sizeof (*hw_dom->arch_mbm_local); hw_dom->arch_mbm_local =kcalloc (num_rmid, tsize,GFP_KERNEL );if (!hw_dom->arch_mbm_local) {
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -207,11 +207,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain * {struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); -if (resctrl_arch_is_mbm_total_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID ))memset (hw_dom->arch_mbm_total,0 ,sizeof (*hw_dom->arch_mbm_total) * r->num_rmid); -if (resctrl_arch_is_mbm_local_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID ))memset (hw_dom->arch_mbm_local,0 ,sizeof (*hw_dom->arch_mbm_local) * r->num_rmid); }
fs/resctrl/ctrlmondata.c +2 -2
@@ -473,12 +473,12 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,rdt_last_cmd_clear ();if (!strcmp (buf,"mbm_local_bytes" )) { -if (resctrl_arch_is_mbm_local_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )) rdtgrp->mba_mbps_event =QOS_L3_MBM_LOCAL_EVENT_ID ;else ret = -EINVAL ; }else if (!strcmp (buf,"mbm_total_bytes" )) { -if (resctrl_arch_is_mbm_total_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID )) rdtgrp->mba_mbps_event =QOS_L3_MBM_TOTAL_EVENT_ID ;else ret = -EINVAL ;
fs/resctrl/monitor.c +11 -5
@@ -336,7 +336,7 @@ void free_rmid(u32 closid, u32 rmid) entry =__rmid_entry (idx); -if (resctrl_arch_is_llc_occupancy_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID ))add_rmid_to_limbo (entry);else list_add_tail (&entry->list, &rmid_free_lru);
@@ -637,10 +637,10 @@ static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,* This is protected from concurrent reads from user as both * the user and overflow handler hold the global mutex. */ -if (resctrl_arch_is_mbm_total_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID ))mbm_update_one_event (r, d, closid, rmid,QOS_L3_MBM_TOTAL_EVENT_ID ); -if (resctrl_arch_is_mbm_local_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID ))mbm_update_one_event (r, d, closid, rmid,QOS_L3_MBM_LOCAL_EVENT_ID ); }
@@ -879,6 +879,12 @@ void resctrl_enable_mon_event(enum resctrl_event_id eventid) mon_event_all[eventid].enabled = true; } +bool resctrl_is_mon_event_enabled (enum resctrl_event_id eventid) +{ +return eventid >=QOS_FIRST_EVENT && eventid <QOS_NUM_EVENTS && + mon_event_all[eventid].enabled; +} +/** * resctrl_mon_resource_init() - Initialise global monitoring structures. *
@@ -914,9 +920,9 @@ int resctrl_mon_resource_init(void) RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } -if (resctrl_arch_is_mbm_local_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )) mba_mbps_default_event =QOS_L3_MBM_LOCAL_EVENT_ID ; -else if (resctrl_arch_is_mbm_total_enabled ()) +else if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID )) mba_mbps_default_event =QOS_L3_MBM_TOTAL_EVENT_ID ;return 0 ;
fs/resctrl/rdtgroup.c +9 -9
@@ -123,8 +123,8 @@ void rdt_staged_configs_clear(void)static bool resctrl_is_mbm_enabled (void ) { -return (resctrl_arch_is_mbm_total_enabled () || -resctrl_arch_is_mbm_local_enabled ()); +return (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID ) || +resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )); }static bool resctrl_is_mbm_event (int e)
@@ -196,7 +196,7 @@ static int closid_alloc(void)lockdep_assert_held (&rdtgroup_mutex);if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID ) && -resctrl_arch_is_llc_occupancy_enabled ()) { +resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID )) { cleanest_closid =resctrl_find_cleanest_closid ();if (cleanest_closid <0 )return cleanest_closid;
@@ -4051,7 +4051,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *dif (resctrl_is_mbm_enabled ())cancel_delayed_work (&d->mbm_over); -if (resctrl_arch_is_llc_occupancy_enabled () &&has_busy_rmid (d)) { +if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID ) &&has_busy_rmid (d)) {/* * When a package is going down, forcefully * decrement rmid->ebusy. There is no way to know
@@ -4087,12 +4087,12 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domainu32 idx_limit =resctrl_arch_system_num_rmid_idx ();size_t tsize; -if (resctrl_arch_is_llc_occupancy_enabled ()) { +if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID )) { d->rmid_busy_llc =bitmap_zalloc (idx_limit,GFP_KERNEL );if (!d->rmid_busy_llc)return -ENOMEM ; } -if (resctrl_arch_is_mbm_total_enabled ()) { +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID )) { tsize =sizeof (*d->mbm_total); d->mbm_total =kcalloc (idx_limit, tsize,GFP_KERNEL );if (!d->mbm_total) {
@@ -4100,7 +4100,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domainreturn -ENOMEM ; } } -if (resctrl_arch_is_mbm_local_enabled ()) { +if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )) { tsize =sizeof (*d->mbm_local); d->mbm_local =kcalloc (idx_limit, tsize,GFP_KERNEL );if (!d->mbm_local) {
@@ -4145,7 +4145,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d) RESCTRL_PICK_ANY_CPU); } -if (resctrl_arch_is_llc_occupancy_enabled ()) +if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID ))INIT_DELAYED_WORK (&d->cqm_limbo, cqm_handle_limbo);/*
@@ -4220,7 +4220,7 @@ void resctrl_offline_cpu(unsigned int cpu)cancel_delayed_work (&d->mbm_over);mbm_setup_overflow_handler (d,0 , cpu); } -if (resctrl_arch_is_llc_occupancy_enabled () && +if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID ) && cpu == d->cqm_work_cpu &&has_busy_rmid (d)) {cancel_delayed_work (&d->cqm_limbo);cqm_setup_limbo_handler (d,0 , cpu);
Signature · 1 line
2.50.1
Tony Luck
maintainerPATCH v9 3/31 x86/resctrl: Remove 'rdt_mon_features' global variable
In reply to Tony Luckrdt_mon_features is used as a bitmask of enabled monitor events. A monitor event's status is now maintained in mon_evt::enabled with all monitor events' mon_evt structures found in the filesystem's mon_event_all[] array.
Remove the remaining uses of rdt_mon_features.
--- arch/x86/include/asm/resctrl.h | 1 - arch/x86/kernel/cpu/resctrl/core.c | 9 +++++---- arch/x86/kernel/cpu/resctrl/monitor.c | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-)
arch/x86/include/asm/resctrl.h +0 -1
@@ -44,7 +44,6 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);extern bool rdt_alloc_capable;extern bool rdt_mon_capable; -extern unsigned int rdt_mon_features;DECLARE_STATIC_KEY_FALSE (rdt_enable_key);DECLARE_STATIC_KEY_FALSE (rdt_alloc_enable_key);
arch/x86/kernel/cpu/resctrl/core.c +5 -4
@@ -863,21 +863,22 @@ static __init bool get_rdt_alloc_resources(void)static __init bool get_rdt_mon_resources (void ) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +bool ret = false;if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) {resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID ); - rdt_mon_features |= (1 <<QOS_L3_OCCUP_EVENT_ID ); + ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) {resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID ); - rdt_mon_features |= (1 <<QOS_L3_MBM_TOTAL_EVENT_ID ); + ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) {resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID ); - rdt_mon_features |= (1 <<QOS_L3_MBM_LOCAL_EVENT_ID ); + ret = true; } -if (!rdt_mon_features) +if (!ret)return false;return !rdt_get_mon_l3_config (r);
arch/x86/kernel/cpu/resctrl/monitor.c +0 -5
@@ -31,11 +31,6 @@*/ bool rdt_mon_capable; -/* -* Global to indicate which monitoring events are enabled. -*/ -unsigned int rdt_mon_features; -#define CF (cf) ((unsigned long)(1048576 * (cf) + 0.5))static int snc_nodes_per_l3_cache =1 ;
Signature · 1 line
2.50.1
Tony Luck
maintainerPATCH v9 4/31 x86,fs/resctrl: Prepare for more monitor events
In reply to Tony LuckThere's a rule in computer programming that objects appear zero, once, or many times. So code accordingly.
There are two MBM events and resctrl is coded with a lot of
if (local)
do one thing
if (total)
do a different thing
Change the rdt_mon_domain and rdt_hw_mon_domain structures to hold arrays of pointers to per event data instead of explicit fields for total and local bandwidth.
Simplify by coding for many events using loops on which are enabled.
Move resctrl_is_mbm_event() to <linux/resctrl.h> so it can be used more widely. Also provide a for_each_mbm_event_id() helper macro.
Cleanup variable names in functions touched to consistently use "eventid" for those with type enum resctrl_event_id.
--- include/linux/resctrl.h | 23 +++++++++--- include/linux/resctrl_types.h | 3 ++ arch/x86/kernel/cpu/resctrl/internal.h | 8 ++--- arch/x86/kernel/cpu/resctrl/core.c | 40 +++++++++++---------- arch/x86/kernel/cpu/resctrl/monitor.c | 36 +++++++++---------- fs/resctrl/monitor.c | 13 ++++--- fs/resctrl/rdtgroup.c | 50 +++++++++++++------------- 7 files changed, 96 insertions(+), 77 deletions(-)
include/linux/resctrl.h +19 -4
@@ -161,8 +161,9 @@ struct rdt_ctrl_domain {* @hdr: common header for different domain types * @ci_id: cache info id for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold -* @mbm_total: saved state for MBM total bandwidth -* @mbm_local: saved state for MBM local bandwidth +* @mbm_states: Per-event pointer to the MBM event's saved state. +* An MBM event's state is an array of struct mbm_state +* indexed by RMID on x86 or combined CLOSID, RMID on Arm. * @mbm_over: worker to periodically read MBM h/w counters * @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters
@@ -172,8 +173,7 @@ struct rdt_mon_domain {struct rdt_domain_hdr hdr;unsigned int ci_id;unsigned long *rmid_busy_llc; -struct mbm_state *mbm_total; -struct mbm_state *mbm_local; +struct mbm_state *mbm_states[QOS_NUM_L3_MBM_EVENTS ];struct delayed_work mbm_over;struct delayed_work cqm_limbo;int mbm_work_cpu;
@@ -376,6 +376,21 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid);bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt); +static inline bool resctrl_is_mbm_event (enum resctrl_event_id eventid) +{ +return (eventid >=QOS_L3_MBM_TOTAL_EVENT_ID && + eventid <=QOS_L3_MBM_LOCAL_EVENT_ID ); +} + +/* Iterate over all memory bandwidth events */ +#define for_each_mbm_event_id (eventid) \ + for (eventid = QOS_L3_MBM_TOTAL_EVENT_ID; \ + eventid <= QOS_L3_MBM_LOCAL_EVENT_ID; eventid++) + +/* Iterate over memory bandwidth arrays in domain structures */ +#define for_each_mbm_idx (idx) \ + for (idx = 0; idx < QOS_NUM_L3_MBM_EVENTS; idx++) +/** * resctrl_arch_mon_event_config_write() - Write the config for an event. * @config_info: struct resctrl_mon_config_info describing the resource, domain
include/linux/resctrl_types.h +3 -0
@@ -51,4 +51,7 @@ enum resctrl_event_id { QOS_NUM_EVENTS, }; +#define QOS_NUM_L3_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTAL_EVENT_ID + 1) +#define MBM_STATE_IDX (evt) ((evt) - QOS_L3_MBM_TOTAL_EVENT_ID) +#endif /* __LINUX_RESCTRL_TYPES_H */
arch/x86/kernel/cpu/resctrl/internal.h +4 -4
@@ -54,15 +54,15 @@ struct rdt_hw_ctrl_domain {* struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs that share * a resource for a monitor function * @d_resctrl: Properties exposed to the resctrl file system -* @arch_mbm_total: arch private state for MBM total bandwidth -* @arch_mbm_local: arch private state for MBM local bandwidth +* @arch_mbm_states: Per-event pointer to the MBM event's saved state. +* An MBM event's state is an array of struct arch_mbm_state +* indexed by RMID on x86. * * Members of this structure are accessed via helpers that provide abstraction. */ struct rdt_hw_mon_domain {struct rdt_mon_domain d_resctrl; -struct arch_mbm_state *arch_mbm_total; -struct arch_mbm_state *arch_mbm_local; +struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS ]; };static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom (struct rdt_ctrl_domain *r)
arch/x86/kernel/cpu/resctrl/core.c +22 -18
@@ -365,8 +365,10 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain *hw_dom)static void mon_domain_free (struct rdt_hw_mon_domain *hw_dom) { -kfree (hw_dom->arch_mbm_total); -kfree (hw_dom->arch_mbm_local); +int idx; + +for_each_mbm_idx (idx) +kfree (hw_dom->arch_mbm_states[idx]);kfree (hw_dom); }
@@ -400,25 +402,27 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_ctrl_domain **/ static int arch_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_mon_domain *hw_dom) { -size_t tsize; - -if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID )) { - tsize =sizeof (*hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =kcalloc (num_rmid, tsize,GFP_KERNEL ); -if (!hw_dom->arch_mbm_total) -return -ENOMEM ; - } -if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )) { - tsize =sizeof (*hw_dom->arch_mbm_local); - hw_dom->arch_mbm_local =kcalloc (num_rmid, tsize,GFP_KERNEL ); -if (!hw_dom->arch_mbm_local) { -kfree (hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =NULL ; -return -ENOMEM ; - } +size_t tsize =sizeof (*hw_dom->arch_mbm_states[0 ]); +enum resctrl_event_id eventid; +int idx; + +for_each_mbm_event_id (eventid) { +if (!resctrl_is_mon_event_enabled (eventid)) +continue ; + idx =MBM_STATE_IDX (eventid); + hw_dom->arch_mbm_states[idx] =kcalloc (num_rmid, tsize,GFP_KERNEL ); +if (!hw_dom->arch_mbm_states[idx]) + goto cleanup; }return 0 ; +cleanup: +for_each_mbm_idx (idx) { +kfree (hw_dom->arch_mbm_states[idx]); + hw_dom->arch_mbm_states[idx] =NULL ; + } + +return -ENOMEM ; }static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope)
arch/x86/kernel/cpu/resctrl/monitor.c +17 -19
@@ -161,18 +161,14 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain *hw_dou32 rmid, enum resctrl_event_id eventid) { - switch (eventid) { - case QOS_L3_OCCUP_EVENT_ID: - return NULL; -case QOS_L3_MBM_TOTAL_EVENT_ID : -return &hw_dom->arch_mbm_total[rmid]; -case QOS_L3_MBM_LOCAL_EVENT_ID : -return &hw_dom->arch_mbm_local[rmid]; -default : -/* Never expect to get here */ -WARN_ON_ONCE (1 ); + struct arch_mbm_state *state; + +if (!resctrl_is_mbm_event (eventid))return NULL ; - } + + state = hw_dom->arch_mbm_states[MBM_STATE_IDX (eventid)]; + +return state ? &state[rmid] :NULL ; } void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d,
@@ -201,14 +197,16 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d,void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) {struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); - -if (resctrl_is_mon_event_enabled (QOS_L3_MBM_TOTAL_EVENT_ID )) -memset (hw_dom->arch_mbm_total,0 , -sizeof (*hw_dom->arch_mbm_total) * r->num_rmid); - -if (resctrl_is_mon_event_enabled (QOS_L3_MBM_LOCAL_EVENT_ID )) -memset (hw_dom->arch_mbm_local,0 , -sizeof (*hw_dom->arch_mbm_local) * r->num_rmid); +enum resctrl_event_id eventid; +int idx; + +for_each_mbm_event_id (eventid) { +if (!resctrl_is_mon_event_enabled (eventid)) +continue ; + idx =MBM_STATE_IDX (eventid); +memset (hw_dom->arch_mbm_states[idx],0 , +sizeof (*hw_dom->arch_mbm_states[0 ]) * r->num_rmid); + } }static u64 mbm_overflow_count (u64 prev_msr,u64 cur_msr,unsigned int width)
fs/resctrl/monitor.c +6 -7
@@ -346,15 +346,14 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid); +struct mbm_state *state; -switch (evtid) { -case QOS_L3_MBM_TOTAL_EVENT_ID : -return &d->mbm_total[idx]; -case QOS_L3_MBM_LOCAL_EVENT_ID : -return &d->mbm_local[idx]; -default : +if (!resctrl_is_mbm_event (evtid))return NULL ; - } + + state = d->mbm_states[MBM_STATE_IDX (evtid)]; + +return state ? &state[idx] :NULL ; }static int __mon_event_count (u32 closid,u32 rmid,struct rmid_read *rr)
fs/resctrl/rdtgroup.c +25 -25
78 lines not on this page · raw message
Signature · 1 line
2.50.1
Tony Luck
maintainerPATCH v9 5/31 x86,fs/resctrl: Improve domain type checking
In reply to Tony LuckThe rdt_domain_hdr structure is used in both control and monitor domain structures to provide common methods for operations such as adding a CPU to a domain, removing a CPU from a domain, accessing the mask of all CPUs in a domain.
rdt_domain_hdr::type provides a simple check whether a domain is a control or monitor domain so that programming errors operating on domains will be quickly caught. This is insufficient to catch errors when other resources besides L3 support monitor events.
Add rdt_domain_hdr::rid to contain the resource id and initialize it as part of domain structure allocation done by CPU online handler. Call domain_header_is_valid() to sanity check both the type and resource id before using container_of() to get a pointer to the associated domain.
--- include/linux/resctrl.h | 9 +++++++++ arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++---- fs/resctrl/ctrlmondata.c | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-)
include/linux/resctrl.h +9 -0
@@ -131,15 +131,24 @@ enum resctrl_domain_type {* @list: all instances of this resource * @id: unique id for this instance * @type: type of this instance +* @rid: resource id for this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr {struct list_head list;int id;enum resctrl_domain_type type; +enum resctrl_res_level rid;struct cpumask cpu_mask; }; +static inline bool domain_header_is_valid (struct rdt_domain_hdr *hdr, +enum resctrl_domain_type type, +enum resctrl_res_level rid) +{ +return !WARN_ON_ONCE (hdr->type != type || hdr->rid != rid); +} +/** * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource * @hdr: common header for different domain types
arch/x86/kernel/cpu/resctrl/core.c +6 -4
@@ -459,7 +459,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) hdr =resctrl_find_domain (&r->ctrl_domains, id, &add_pos);if (hdr) { -if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN )) +if (!domain_header_is_valid (hdr,RESCTRL_CTRL_DOMAIN , r->rid))return ; d = container_of(hdr, struct rdt_ctrl_domain, hdr);
@@ -476,6 +476,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) d = &hw_dom->d_resctrl; d->hdr.id = id; d->hdr.type =RESCTRL_CTRL_DOMAIN ; + d->hdr.rid = r->rid;cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);
@@ -515,7 +516,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) hdr =resctrl_find_domain (&r->mon_domains, id, &add_pos);if (hdr) { -if (WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid))return ; d = container_of(hdr, struct rdt_mon_domain, hdr);
@@ -530,6 +531,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) d = &hw_dom->d_resctrl; d->hdr.id = id; d->hdr.type =RESCTRL_MON_DOMAIN ; + d->hdr.rid = r->rid; ci =get_cpu_cacheinfo_level (cpu,RESCTRL_L3_CACHE );if (!ci) {pr_warn_once ("Can't find L3 cache for CPU:%d resource %s\n" , cpu, r->name);
@@ -586,7 +588,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)return ; } -if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN )) +if (!domain_header_is_valid (hdr,RESCTRL_CTRL_DOMAIN , r->rid))return ; d = container_of(hdr, struct rdt_ctrl_domain, hdr);
@@ -632,7 +634,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)return ; } -if (WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid))return ; d = container_of(hdr, struct rdt_mon_domain, hdr);
fs/resctrl/ctrlmondata.c +1 -1
@@ -643,7 +643,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)* the resource to find the domain with "domid". */ hdr =resctrl_find_domain (&r->mon_domains, domid,NULL ); -if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { +if (!hdr || !domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , resid)) { ret = -ENOENT ; goto out; }
Signature · 1 line
2.50.1
Re: [PATCH v9 05/31] x86,fs/resctrl: Improve domain type checking
Hi Tony,
Quoted 11 lines · Tony Luck
The
rdt_domain_hdrstructure is used in both control and monitor domain structures to provide common methods for operations such as adding a CPU to a domain, removing a CPU from a domain, accessing the mask of all CPUs in a domain.
rdt_domain_hdr::typeprovides a simple check whether a domain is a control or monitor domain so that programming errors operating on domains will be quickly caught. This is insufficient to catch errors when other resources besides L3 support monitor events.
Quoted 7 lines
Add
rdt_domain_hdr::ridto contain the resource id and initialize it as part of domain structure allocation done by CPU online handler. Calldomain_header_is_valid()to sanity check both the type and resource id before usingcontainer_of()to get a pointer to the associated domain.Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 6/31 x86/resctrl: Move L3 initialization into new helper function
In reply to Tony LuckAll resctrl monitor events are associated with the L3 resource, but this is about to change.
To prepare for additional types of monitoring domains, move open coded L3 resource monitoring domain initialization from domain_add_cpu_mon() into a new helper l3_mon_domain_setup() called by domain_add_cpu_mon().
--- arch/x86/kernel/cpu/resctrl/core.c | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +34 -22
@@ -496,34 +496,13 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) } } -static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +static void l3_mon_domain_setup (int cpu,int id,struct rdt_resource *r,struct list_head *add_pos) { -int id =get_domain_id_from_scope (cpu, r->mon_scope); -struct list_head *add_pos =NULL ;struct rdt_hw_mon_domain *hw_dom; -struct rdt_domain_hdr *hdr;struct rdt_mon_domain *d;struct cacheinfo *ci;int err; -lockdep_assert_held (&domain_list_lock); - -if (id <0 ) { -pr_warn_once ("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n" , - cpu, r->mon_scope, r->name); -return ; - } - - hdr =resctrl_find_domain (&r->mon_domains, id, &add_pos); -if (hdr) { -if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid)) -return ; - d = container_of(hdr, struct rdt_mon_domain, hdr); - -cpumask_set_cpu (cpu, &d->hdr.cpu_mask); -return ; - } - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu));if (!hw_dom)return ;
@@ -558,6 +537,39 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) } } +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->mon_scope); +struct list_head *add_pos =NULL ; +struct rdt_domain_hdr *hdr; + +lockdep_assert_held (&domain_list_lock); + +if (id <0 ) { +pr_warn_once ("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->mon_scope, r->name); +return ; + } + + hdr =resctrl_find_domain (&r->mon_domains, id, &add_pos); +if (hdr) { +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid)) +return ; +cpumask_set_cpu (cpu, &hdr->cpu_mask); + +return ; + } + +switch (r->rid) { +case RDT_RESOURCE_L3 : +l3_mon_domain_setup (cpu, id, r, add_pos); +break ; +default : +pr_warn_once ("Unknown resource rid=%d\n" , r->rid); +break ; + } +} +static void domain_add_cpu (int cpu,struct rdt_resource *r) {if (r->alloc_capable)
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 06/31] x86/resctrl: Move L3 initialization into new helper function
Hi Tony,
Quoted 56 lines · Tony Luck
--- arch/x86/kernel/cpu/resctrl/core.c | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-)arch/x86/kernel/cpu/resctrl/core.c +9
-22@@ -496,34 +496,13 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) } } -static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +static void l3_mon_domain_setup (int cpu,int id,struct rdt_resource *r,struct list_head *add_pos) { -int id =get_domain_id_from_scope (cpu, r->mon_scope); -struct list_head *add_pos =NULL ;struct rdt_hw_mon_domain *hw_dom; -struct rdt_domain_hdr *hdr;struct rdt_mon_domain *d;struct cacheinfo *ci;int err; -lockdep_assert_held (&domain_list_lock); - -if (id <0 ) { -pr_warn_once ("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n" , - cpu, r->mon_scope, r->name); -return ; - } - - hdr =resctrl_find_domain (&r->mon_domains, id, &add_pos); -if (hdr) { -if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid)) -return ; - d = container_of(hdr, struct rdt_mon_domain, hdr); - -cpumask_set_cpu (cpu, &d->hdr.cpu_mask); -return ; - } - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu));if (!hw_dom)return ;@@ -558,6 +537,39 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) } } +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->mon_scope); +struct list_head *add_pos =NULL ; +struct rdt_domain_hdr *hdr; + +lockdep_assert_held (&domain_list_lock); +
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 557
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+if (id <0 ) { +pr_warn_once ("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->mon_scope, r->name); +return ; + } + + hdr =resctrl_find_domain (&r->mon_domains, id, &add_pos); +if (hdr) { +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid)) +return ;
tl;dr Drop this domain_header_is_valid() check?
Same topic of inconsistent use of domain_header_is_valid() as v8 [1].
I expect that domain_header_is_valid() will always precede a container_of() that retrieves the structure that contains the header, that is clear and explicitly documented in patch #5 changelog. Should domain_header_is_valid() also be used when just operating on the header as is done here? I do not think it is practical to consistently do so, especially when later in series the header is passed around more.
Note how domain_add_cpu_mon() here uses domain_header_is_valid() as sanity chek before accessing the header but the changes to domain_remove_cpu_mon() and domain_remove_cpu_ctrl() that follow in patches 7 and 8 don't. Without a clear pattern and such inconsistent use folks that follow this work with changes may be confused and we'll end up with these checks just scattered randomly.
Reinette
Tony Luck
maintainerPATCH v9 7/31 x86,fs/resctrl: Refactor domain_remove_cpu_mon() ready for new domain types
In reply to Tony LuckAll monitoring events are associated with the L3 resource.
The RDT_RESOURCE_L3 resource carries a lot of state in the domain structures which needs to be dealt with when a domain is taken offline by removing the last CPU in the domain.
New telemetry events will be associated with a new package scoped resource with new domain structures.
Refactor domain_remove_cpu_mon() so all the L3 processing is separate from general actions of clearing the CPU bit in the mask and removing sub-directories from the mon_data directory.
resctrl_offline_mon_domain() continues to remove domain specific directories and files from the "mon_data" directories, but skips the L3 resource specific cleanup when called for other resource types.
--- arch/x86/kernel/cpu/resctrl/core.c | 21 +++++++++++++-------- fs/resctrl/rdtgroup.c | 5 ++++- 2 files changed, 17 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +13 -8
@@ -646,20 +646,25 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)return ; } -if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN , r->rid)) +cpumask_clear_cpu (cpu, &hdr->cpu_mask); +if (!cpumask_empty (&hdr->cpu_mask))return ; - d = container_of(hdr, struct rdt_mon_domain, hdr); - hw_dom =resctrl_to_arch_mon_dom (d); +switch (r->rid) { +case RDT_RESOURCE_L3 : +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return ; -cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); -if (cpumask_empty (&d->hdr.cpu_mask)) { + d = container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =resctrl_to_arch_mon_dom (d);resctrl_offline_mon_domain (r, d); -list_del_rcu (&d->hdr.list); +list_del_rcu (&hdr->list);synchronize_rcu ();mon_domain_free (hw_dom); - -return ; +break ; +default : +pr_warn_once ("Unknown resource rid=%d\n" , r->rid); +break ; } }
fs/resctrl/rdtgroup.c +4 -1
@@ -4047,6 +4047,9 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *dif (resctrl_mounted &&resctrl_arch_mon_capable ())rmdir_mondata_subdir_allrdtgrp (r, d); +if (r->rid !=RDT_RESOURCE_L3 ) + goto out_unlock; +if (resctrl_is_mbm_enabled ())cancel_delayed_work (&d->mbm_over);if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID ) &&has_busy_rmid (d)) {
@@ -4063,7 +4066,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d }domain_destroy_mon_state (d); - +out_unlock:mutex_unlock (&rdtgroup_mutex); }
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 07/31] x86,fs/resctrl: Refactor domain_remove_cpu_mon() ready for new domain types
Hi Tony,
Quoted 9 lines · Tony Luck
All monitoring events are associated with the L3 resource.
The
RDT_RESOURCE_L3resource carries a lot of state in the domain structures which needs to be dealt with when a domain is taken offline by removing the last CPU in the domain.New telemetry events will be associated with a new package scoped resource with new domain structures.
Quoted 7 lines
Refactor
domain_remove_cpu_mon()so all the L3 processing is separate from general actions of clearing the CPU bit in the mask and removing sub-directories from themon_datadirectory.
resctrl_offline_mon_domain()continues to remove domain specific directories and files from the "mon_data" directories, but skips the L3 resource specific cleanup when called for other resource types.
This part does not seem to be related to this change since up to here this is all about refactoring L3 support while the final part starts to add support for a new resource under the guise of "L3 refactoring".
The resctrl_offline_mon_domain() change looks more appropriate for patch #9 "x86,fs/resctrl: Use struct rdt_domain_hdr instead of struct rdt_mon_domain" where the change makes clear to which code only a RDT_RESOURCE_L3 domain can belong and matches the change to resctrl_online_mon_domain() in same patch. This is not ideal though since even in patch #9 this seems to be PERF_PKG enabling code (in both resctrl_online_mon_domain() and resctrl_offline_mon_domain()) added under another guise of refactoring.
I think it could also be argued that the related changes (code flow changes to support only files for PERF_PKG) to resctrl_online_mon_domain() and resctrl_offline_mon_domain() belongs in patch 22 since only then is support for PERF_PKG added and indeed is when it is explicit that "Support the PERF_PKG resource in the CPU online/offline handlers."
Doing so will keep refactoring as-is ... it is just refactoring existing flow, and then code flow changes come later when actual enabling is done.
Reinette
Tony Luck
maintainerPATCH v9 8/31 x86/resctrl: Clean up domain_remove_cpu_ctrl()
In reply to Tony LuckFor symmetry with domain_remove_cpu_mon() refactor domain_remove_cpu_ctrl() to take an early return when removing a CPU does not empty the domain.
--- arch/x86/kernel/cpu/resctrl/core.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +14 -15
@@ -600,28 +600,27 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)return ; } +cpumask_clear_cpu (cpu, &hdr->cpu_mask); +if (!cpumask_empty (&hdr->cpu_mask)) +return ; +if (!domain_header_is_valid (hdr,RESCTRL_CTRL_DOMAIN , r->rid))return ; d = container_of(hdr, struct rdt_ctrl_domain, hdr); hw_dom =resctrl_to_arch_ctrl_dom (d); -cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); -if (cpumask_empty (&d->hdr.cpu_mask)) { -resctrl_offline_ctrl_domain (r, d); -list_del_rcu (&d->hdr.list); -synchronize_rcu (); - -/* -* rdt_ctrl_domain "d" is going to be freed below, so clear -* its pointer from pseudo_lock_region struct. -*/ -if (d->plr) - d->plr->d =NULL ; -ctrl_domain_free (hw_dom); +resctrl_offline_ctrl_domain (r, d); +list_del_rcu (&hdr->list); +synchronize_rcu (); -return ; - } +/* +* rdt_ctrl_domain "d" is going to be freed below, so clear +* its pointer from pseudo_lock_region struct. +*/ +if (d->plr) + d->plr->d =NULL ; +ctrl_domain_free (hw_dom); }static void domain_remove_cpu_mon (int cpu,struct rdt_resource *r)
Signature · 1 line
2.50.1
Re: [PATCH v9 08/31] x86/resctrl: Clean up domain_remove_cpu_ctrl()
Hi Tony,
Quoted 6 lines · Tony Luck
For symmetry with
domain_remove_cpu_mon()refactordomain_remove_cpu_ctrl()to take an early return when removing a CPU does not empty the domain.Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 9/31 x86,fs/resctrl: Use struct rdt_domain_hdr instead of struct rdt_mon_domain
In reply to Tony LuckAll monitoring events are associated with the L3 resource and it made sense to use the L3 specific "struct rdt_mon_domain *" arguments to functions manipulating domains.
Telemetry events will be tied to another resource. This requires the functions that manipulate domains to not be L3 specific.
Change the calling sequence to use the generic struct rdt_domain_hdr for domain addition and deletion to preserve as much common code as possible. This will simplify enabling of enumeration of domains for events in other resources.
Make the same change to allow reading events in other resources. In this case the code flow passes from mon_event_read() via smp_call*() eventually to __mon_event_count() so replace the L3 specific domain pointer rmid_read::d with rmid_read::hdr that points to the generic domain header.
Update kerneldoc for mon_data::sum to note that it is only used for RDT_RESOURCE_L3.
--- include/linux/resctrl.h | 8 +- fs/resctrl/internal.h | 14 ++-- arch/x86/kernel/cpu/resctrl/core.c | 4 +- arch/x86/kernel/cpu/resctrl/monitor.c | 18 ++++- fs/resctrl/ctrlmondata.c | 14 ++-- fs/resctrl/monitor.c | 30 +++++--- fs/resctrl/rdtgroup.c | 103 ++++++++++++++++++-------- 7 files changed, 128 insertions(+), 63 deletions(-)
include/linux/resctrl.h +4 -4
@@ -452,9 +452,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type);int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain_hdr *hdr);void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain_hdr *hdr);void resctrl_online_cpu (unsigned int cpu);void resctrl_offline_cpu (unsigned int cpu);
@@ -462,7 +462,7 @@ void resctrl_offline_cpu(unsigned int cpu);* resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid * for this resource and domain. * @r: resource that the counter should be read from. -* @d: domain that the counter should be read from. +* @hdr: Header of domain that the counter should be read from. * @closid: closid that matches the rmid. Depending on the architecture, the * counter may match traffic of both @closid and @rmid, or @rmid * only.
@@ -483,7 +483,7 @@ void resctrl_offline_cpu(unsigned int cpu);* Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain_hdr *hdr,u32 closid,u32 rmid,enum resctrl_event_id eventid,u64 *val,void *arch_mon_ctx);
fs/resctrl/internal.h +7 -7
@@ -77,8 +77,8 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS];* @list: Member of the global @mon_data_kn_priv_list list. * @rid: Resource id associated with the event file. * @evtid: Event id associated with the event file. -* @sum: Set when event must be summed across multiple -* domains. +* @sum: Set for RDT_RESOURCE_L3 when event must be summed +* across multiple domains. * @domid: When @sum is zero this is the domain to which * the event file belongs. When @sum is one this * is the id of the L3 cache that all domains to be
@@ -101,22 +101,22 @@ struct mon_data {* resource group then its event count is summed with the count from all * its child resource groups. * @r: Resource describing the properties of the event being read. -* @d: Domain that the counter should be read from. If NULL then sum all +* @hdr: Header of domain that the counter should be read from. If NULL then sum all * domains in @r sharing L3 @ci.id * @evtid: Which monitor event to read. * @first: Initialize MBM counter when true. -* @ci_id: Cacheinfo id for L3. Only set when @d is NULL. Used when summing domains. +* @ci_id: Cacheinfo id for L3. Only set when @hdr is NULL. Used when summing domains. * @err: Error encountered when reading counter. * @val: Returned value of event counter. If @rgrp is a parent resource group, * @val includes the sum of event counts from its child resource groups. -* If @d is NULL, @val includes the sum of all domains in @r sharing @ci.id, +* If @hdr is NULL, @val includes the sum of all domains in @r sharing @ci.id, * (summed across child resource groups if @rgrp is a parent resource group). * @arch_mon_ctx: Hardware monitor allocated for this read request (MPAM only). */ struct rmid_read {struct rdtgroup *rgrp;struct rdt_resource *r; -struct rdt_mon_domain *d; +struct rdt_domain_hdr *hdr;enum resctrl_event_id evtid;bool first;unsigned int ci_id;
@@ -352,7 +352,7 @@ void mon_event_count(void *info);int rdtgroup_mondata_show (struct seq_file *m,void *arg);void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_mon_domain *d,struct rdtgroup *rdtgrp, +struct rdt_domain_hdr *hdr,struct rdtgroup *rdtgrp,cpumask_t *cpumask,int evtid,int first);int resctrl_mon_resource_init (void );
arch/x86/kernel/cpu/resctrl/core.c +2 -2
@@ -529,7 +529,7 @@ static void l3_mon_domain_setup(int cpu, int id, struct rdt_resource *r, structlist_add_tail_rcu (&d->hdr.list, add_pos); - err =resctrl_online_mon_domain (r, d); + err =resctrl_online_mon_domain (r, &d->hdr);if (err) {list_del_rcu (&d->hdr.list);synchronize_rcu ();
@@ -656,7 +656,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) d = container_of(hdr, struct rdt_mon_domain, hdr); hw_dom =resctrl_to_arch_mon_dom (d); -resctrl_offline_mon_domain (r, d); +resctrl_offline_mon_domain (r, hdr);list_del_rcu (&hdr->list);synchronize_rcu ();mon_domain_free (hw_dom);
arch/x86/kernel/cpu/resctrl/monitor.c +14 -4
@@ -217,20 +217,30 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain_hdr *hdr,u32 unused,u32 rmid,enum resctrl_event_id eventid,u64 *val,void *ignored) { -struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); -struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -int cpu =cpumask_any (&d->hdr.cpu_mask); +int cpu =cpumask_any (&hdr->cpu_mask); +struct rdt_hw_mon_domain *hw_dom; +struct rdt_hw_resource *hw_res;struct arch_mbm_state *am; +struct rdt_mon_domain *d;u64 msr_val, chunks;u32 prmid;int ret;resctrl_arch_rmid_read_context_check (); +if (r->rid !=RDT_RESOURCE_L3 ) +return -EINVAL ; + +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return -EINVAL ; + + d = container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =resctrl_to_arch_mon_dom (d); + hw_res =resctrl_to_arch_res (r); prmid =logical_rmid_to_physical_rmid (cpu, rmid); ret =__rmid_read_phys (prmid, eventid, &msr_val);if (ret)
fs/resctrl/ctrlmondata.c +9 -5
@@ -547,7 +547,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_mon_domain *d,struct rdtgroup *rdtgrp, +struct rdt_domain_hdr *hdr,struct rdtgroup *rdtgrp,cpumask_t *cpumask,int evtid,int first) {int cpu;
@@ -561,7 +561,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->rgrp = rdtgrp; rr->evtid = evtid; rr->r = r; - rr->d = d; + rr->hdr = hdr; rr->first = first; rr->arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r, evtid);if (IS_ERR (rr->arch_mon_ctx)) {
@@ -592,7 +592,6 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)enum resctrl_event_id evtid;struct rdt_domain_hdr *hdr;struct rmid_read rr = {0 }; -struct rdt_mon_domain *d;struct rdtgroup *rdtgrp;int domid, cpu, ret =0 ;struct rdt_resource *r;
@@ -617,6 +616,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r =resctrl_arch_get_resource (resid);if (md->sum) { +struct rdt_mon_domain *d; + +if (WARN_ON_ONCE (resid !=RDT_RESOURCE_L3 )) { + ret = -EIO ; + goto out; + }/* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the
@@ -647,8 +652,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_mon_domain, hdr); -mon_event_read (&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); +mon_event_read (&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evtid, false); } checkresult:
fs/resctrl/monitor.c +20 -10
@@ -159,7 +159,7 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)break ; entry =__rmid_entry (idx); -if (resctrl_arch_rmid_read (r, d, entry->closid, entry->rmid, +if (resctrl_arch_rmid_read (r, &d->hdr, entry->closid, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val, arch_mon_ctx)) { rmid_dirty = true;
@@ -365,19 +365,22 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)int err, ret;u64 tval =0 ; -if (rr->first) { -resctrl_arch_reset_rmid (rr->r, rr->d, closid, rmid, rr->evtid); - m =get_mbm_state (rr->d, closid, rmid, rr->evtid); +if (rr->r->rid ==RDT_RESOURCE_L3 && rr->first) { +if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return -EINVAL ; + d = container_of(rr->hdr, struct rdt_mon_domain, hdr); +resctrl_arch_reset_rmid (rr->r, d, closid, rmid, rr->evtid); + m =get_mbm_state (d, closid, rmid, rr->evtid);if (m)memset (m,0 ,sizeof (struct mbm_state ));return 0 ; } -if (rr->d) { +if (rr->hdr) {/* Reading a single domain, must be on a CPU in that domain. */ -if (!cpumask_test_cpu (cpu, &rr->d->hdr.cpu_mask)) +if (!cpumask_test_cpu (cpu, &rr->hdr->cpu_mask))return -EINVAL ; - rr->err =resctrl_arch_rmid_read (rr->r, rr->d, closid, rmid, + rr->err =resctrl_arch_rmid_read (rr->r, rr->hdr, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx);if (rr->err)return rr->err;
@@ -387,6 +390,9 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)return 0 ; } +if (WARN_ON_ONCE (rr->r->rid !=RDT_RESOURCE_L3 )) +return -EINVAL ; +/* Summing domains that share a cache, must be on a CPU for that cache. */ ci =get_cpu_cacheinfo_level (cpu,RESCTRL_L3_CACHE );if (!ci || ci->id != rr->ci_id)
@@ -403,7 +409,7 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)list_for_each_entry (d, &rr->r->mon_domains, hdr.list) {if (d->ci_id != rr->ci_id)continue ; - err =resctrl_arch_rmid_read (rr->r, d, closid, rmid, + err =resctrl_arch_rmid_read (rr->r, &d->hdr, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx);if (!err) { rr->val += tval;
@@ -432,9 +438,13 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)static void mbm_bw_count (u32 closid,u32 rmid,struct rmid_read *rr) {u64 cur_bw, bytes, cur_bytes; +struct rdt_mon_domain *d;struct mbm_state *m; - m =get_mbm_state (rr->d, closid, rmid, rr->evtid); +if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return ; + d = container_of(rr->hdr, struct rdt_mon_domain, hdr); + m =get_mbm_state (d, closid, rmid, rr->evtid);if (WARN_ON_ONCE (!m))return ;
@@ -608,7 +618,7 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *struct rmid_read rr = {0 }; rr.r = r; - rr.d = d; + rr.hdr = &d->hdr; rr.evtid = evtid; rr.arch_mon_ctx =resctrl_arch_mon_ctx_alloc (rr.r, rr.evtid);if (IS_ERR (rr.arch_mon_ctx)) {
fs/resctrl/rdtgroup.c +72 -31
244 lines not on this page · raw message
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 09/31] x86,fs/resctrl: Use struct rdt_domain_hdr instead of struct rdt_mon_domain
Hi Tony,
On 8/29/25 12:33 PM, Tony Luck wrote:
...
Quoted 20 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-4@@ -217,20 +217,30 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain_hdr *hdr,u32 unused,u32 rmid,enum resctrl_event_id eventid,u64 *val,void *ignored) { -struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); -struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -int cpu =cpumask_any (&d->hdr.cpu_mask); +int cpu =cpumask_any (&hdr->cpu_mask); +struct rdt_hw_mon_domain *hw_dom; +struct rdt_hw_resource *hw_res;struct arch_mbm_state *am;
arch/x86/kernel/cpu/resctrl/monitor.c static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width) · line 237
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-0+struct rdt_mon_domain *d;u64 msr_val, chunks;u32 prmid;int ret;resctrl_arch_rmid_read_context_check (); +if (r->rid !=RDT_RESOURCE_L3 ) +return -EINVAL ; +
What is benefit of these additional errors added? From what I understand it is in the "should never happen" category that the domain_header_is_valid() that follows already handles?
Quoted 42 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return -EINVAL ; + + d = container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =resctrl_to_arch_mon_dom (d); + hw_res =resctrl_to_arch_res (r); prmid =logical_rmid_to_physical_rmid (cpu, rmid); ret =__rmid_read_phys (prmid, eventid, &msr_val);if (ret)fs/resctrl/ctrlmondata.c +2
-3@@ -547,7 +547,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_mon_domain *d,struct rdtgroup *rdtgrp, +struct rdt_domain_hdr *hdr,struct rdtgroup *rdtgrp,cpumask_t *cpumask,int evtid,int first) {int cpu;@@ -561,7 +561,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->rgrp = rdtgrp; rr->evtid = evtid; rr->r = r; - rr->d = d; + rr->hdr = hdr; rr->first = first; rr->arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r, evtid);if (IS_ERR (rr->arch_mon_ctx)) {@@ -592,7 +592,6 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)enum resctrl_event_id evtid;struct rdt_domain_hdr *hdr;struct rmid_read rr = {0 }; -struct rdt_mon_domain *d;struct rdtgroup *rdtgrp;int domid, cpu, ret =0 ;struct rdt_resource *r;
fs/resctrl/ctrlmondata.c int rdtgroup_mondata_show(struct seq_file *m, void *arg) · line 624
Quoted 9 lines
fs/resctrl/ctrlmondata.c +6
-0@@ -617,6 +616,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r =resctrl_arch_get_resource (resid);if (md->sum) { +struct rdt_mon_domain *d; + +if (WARN_ON_ONCE (resid !=RDT_RESOURCE_L3 )) { + ret = -EIO ; + goto out; + }
Apart from what is described in changelog this patch also adds a couple of new warnings that seems to focus on the SNC code. Could the changelog please add a motivation for how these fit in with the change as described?
fs/resctrl/ctrlmondata.c int rdtgroup_mondata_show(struct seq_file *m, void *arg) · line 650
Quoted 8 lines
fs/resctrl/ctrlmondata.c +0
-1/* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the @@ -647,8 +652,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_mon_domain, hdr);
Above change introduces domain_header_is_valid() inconsistency by keeping the check but removing the "checked" container_of(). Again I'll try to point these out as I see them but I would like to repeat my request made in v8 that you review the related changes to ensure the pattern is consistent.
Quoted 48 lines
fs/resctrl/ctrlmondata.c +1
-1-mon_event_read (&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); +mon_event_read (&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evtid, false); } checkresult:fs/resctrl/monitor.c +10
-7@@ -159,7 +159,7 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)break ; entry =__rmid_entry (idx); -if (resctrl_arch_rmid_read (r, d, entry->closid, entry->rmid, +if (resctrl_arch_rmid_read (r, &d->hdr, entry->closid, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val, arch_mon_ctx)) { rmid_dirty = true;@@ -365,19 +365,22 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)int err, ret;u64 tval =0 ; -if (rr->first) { -resctrl_arch_reset_rmid (rr->r, rr->d, closid, rmid, rr->evtid); - m =get_mbm_state (rr->d, closid, rmid, rr->evtid); +if (rr->r->rid ==RDT_RESOURCE_L3 && rr->first) { +if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return -EINVAL ; + d = container_of(rr->hdr, struct rdt_mon_domain, hdr); +resctrl_arch_reset_rmid (rr->r, d, closid, rmid, rr->evtid); + m =get_mbm_state (d, closid, rmid, rr->evtid);if (m)memset (m,0 ,sizeof (struct mbm_state ));return 0 ; } -if (rr->d) { +if (rr->hdr) {/* Reading a single domain, must be on a CPU in that domain. */ -if (!cpumask_test_cpu (cpu, &rr->d->hdr.cpu_mask)) +if (!cpumask_test_cpu (cpu, &rr->hdr->cpu_mask))return -EINVAL ; - rr->err =resctrl_arch_rmid_read (rr->r, rr->d, closid, rmid, + rr->err =resctrl_arch_rmid_read (rr->r, rr->hdr, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx);if (rr->err)return rr->err;
fs/resctrl/monitor.c static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) · line 395
Quoted 6 lines
fs/resctrl/monitor.c +3
-0@@ -387,6 +390,9 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)return 0 ; } +if (WARN_ON_ONCE (rr->r->rid !=RDT_RESOURCE_L3 )) +return -EINVAL ; +
Another SNC related warning.
Quoted 51 lines
fs/resctrl/monitor.c +7
-3/* Summing domains that share a cache, must be on a CPU for that cache. */ ci =get_cpu_cacheinfo_level (cpu,RESCTRL_L3_CACHE );if (!ci || ci->id != rr->ci_id)@@ -403,7 +409,7 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)list_for_each_entry (d, &rr->r->mon_domains, hdr.list) {if (d->ci_id != rr->ci_id)continue ; - err =resctrl_arch_rmid_read (rr->r, d, closid, rmid, + err =resctrl_arch_rmid_read (rr->r, &d->hdr, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx);if (!err) { rr->val += tval;@@ -432,9 +438,13 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)static void mbm_bw_count (u32 closid,u32 rmid,struct rmid_read *rr) {u64 cur_bw, bytes, cur_bytes; +struct rdt_mon_domain *d;struct mbm_state *m; - m =get_mbm_state (rr->d, closid, rmid, rr->evtid); +if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) +return ; + d = container_of(rr->hdr, struct rdt_mon_domain, hdr); + m =get_mbm_state (d, closid, rmid, rr->evtid);if (WARN_ON_ONCE (!m))return ;@@ -608,7 +618,7 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *struct rmid_read rr = {0 }; rr.r = r; - rr.d = d; + rr.hdr = &d->hdr; rr.evtid = evtid; rr.arch_mon_ctx =resctrl_arch_mon_ctx_alloc (rr.r, rr.evtid);if (IS_ERR (rr.arch_mon_ctx)) {fs/resctrl/rdtgroup.c +2
-1@@ -2887,7 +2887,8 @@ static void rmdir_all_sub(void)* @rid: The resource id for the event file being created. * @domid: The domain id for the event file being created. * @mevt: The type of event file being created. -* @do_sum: Whether SNC summing monitors are being created. +* @do_sum: Whether SNC summing monitors are being created. Only set +* when @rid == RDT_RESOURCE_L3. */ static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid, struct mon_evt *mevt,
fs/resctrl/rdtgroup.c static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid, · line 2902
Quoted 5 lines
fs/resctrl/rdtgroup.c +2
-0@@ -2897,6 +2898,9 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid,lockdep_assert_held (&rdtgroup_mutex); +if (WARN_ON_ONCE (do_sum && rid !=RDT_RESOURCE_L3 )) +return NULL ;
... and another new SNC warning. Could you please help reader understand how these changes fit with the domain -> header conversion?
fs/resctrl/rdtgroup.c static void mon_rmdir_one_subdir(struct kernfs_node *pkn, char *name, char *subn · line 3029
Quoted 7 lines
fs/resctrl/rdtgroup.c +1
-0+list_for_each_entry (priv, &mon_data_kn_priv_list, list) {if (priv->rid == rid && priv->domid == domid && priv->sum == do_sum && priv->evtid == mevt->evtid)@@ -3024,17 +3028,27 @@ static void mon_rmdir_one_subdir(struct kernfs_node *pkn, char *name, char *subn* when last domain being summed is removed. */
Reinette
Tony Luck
maintainerPATCH v9 10/31 x86,fs/resctrl: Rename struct rdt_mon_domain and rdt_hw_mon_domain
In reply to Tony LuckAll monitoring events are associated with the L3 resource. The per L3 domain resctrl fs monitoring state is maintained in the generically named struct rdt_mon_domain while the per L3 domain architecture specific monitoring state is maintained in the generically named struct rdt_hw_mon_domain.
Upcoming telemetry event monitoring will be tied to another resource and requires new domain structures.
Rename the L3 resource specific domain data structures to include "l3_" in their names to avoid confusion between the different resource specific domain structures:rdt_mon_domain -> rdt_l3_mon_domainrdt_hw_mon_domain -> rdt_hw_l3_mon_domain
No functional change.
--- include/linux/resctrl.h | 16 ++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 16 ++++++------ fs/resctrl/internal.h | 8 +++--- arch/x86/kernel/cpu/resctrl/core.c | 14 +++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 20 +++++++------- fs/resctrl/ctrlmondata.c | 2 +- fs/resctrl/monitor.c | 34 ++++++++++++------------ fs/resctrl/rdtgroup.c | 36 +++++++++++++------------- 8 files changed, 73 insertions(+), 73 deletions(-)
include/linux/resctrl.h +8 -8
@@ -166,7 +166,7 @@ struct rdt_ctrl_domain { };/** -* struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource +* struct rdt_l3_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @ci_id: cache info id for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold
@@ -178,7 +178,7 @@ struct rdt_ctrl_domain {* @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters */ -struct rdt_mon_domain { +struct rdt_l3_mon_domain {struct rdt_domain_hdr hdr;unsigned int ci_id;unsigned long *rmid_busy_llc;
@@ -334,10 +334,10 @@ struct resctrl_cpu_defaults { };struct resctrl_mon_config_info { -struct rdt_resource *r; -struct rdt_mon_domain *d; -u32 evtid; -u32 mon_config; +struct rdt_resource *r; +struct rdt_l3_mon_domain *d; +u32 evtid; +u32 mon_config; };/**
@@ -530,7 +530,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_l3_mon_domain *d,u32 closid,u32 rmid,enum resctrl_event_id eventid);
@@ -543,7 +543,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_l3_mon_domain *d);/** * resctrl_arch_reset_all_ctrls() - Reset the control for each CLOSID to its
arch/x86/kernel/cpu/resctrl/internal.h +8 -8
@@ -51,17 +51,17 @@ struct rdt_hw_ctrl_domain { };/** -* struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs that share -* a resource for a monitor function -* @d_resctrl: Properties exposed to the resctrl file system +* struct rdt_hw_l3_mon_domain - Arch private attributes of a set of CPUs that share +* a resource for a monitor function +* @d_resctrl: Properties exposed to the resctrl file system * @arch_mbm_states: Per-event pointer to the MBM event's saved state. * An MBM event's state is an array of struct arch_mbm_state * indexed by RMID on x86. * * Members of this structure are accessed via helpers that provide abstraction. */ -struct rdt_hw_mon_domain { -struct rdt_mon_domain d_resctrl; +struct rdt_hw_l3_mon_domain { +struct rdt_l3_mon_domain d_resctrl;struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS ]; };
@@ -70,9 +70,9 @@ static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct rdt_ctr return container_of(r, struct rdt_hw_ctrl_domain, d_resctrl); } -static inline struct rdt_hw_mon_domain *resctrl_to_arch_mon_dom (struct rdt_mon_domain *r) +static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom (struct rdt_l3_mon_domain *r) { - return container_of(r, struct rdt_hw_mon_domain, d_resctrl); + return container_of(r, struct rdt_hw_l3_mon_domain, d_resctrl); }/**
@@ -124,7 +124,7 @@ static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *rextern struct rdt_hw_resource rdt_resources_all[]; -void arch_mon_domain_online (struct rdt_resource *r,struct rdt_mon_domain *d); +void arch_mon_domain_online (struct rdt_resource *r,struct rdt_l3_mon_domain *d);/* CPUID.(EAX=10H, ECX=ResID=1).EAX */ union cpuid_0x10_1_eax {
fs/resctrl/internal.h +4 -4
@@ -357,7 +357,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,int resctrl_mon_resource_init (void ); -void mbm_setup_overflow_handler (struct rdt_mon_domain *dom, +void mbm_setup_overflow_handler (struct rdt_l3_mon_domain *dom,unsigned long delay_ms,int exclude_cpu);
@@ -365,14 +365,14 @@ void mbm_handle_overflow(struct work_struct *work);bool is_mba_sc (struct rdt_resource *r); -void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms, +void cqm_setup_limbo_handler (struct rdt_l3_mon_domain *dom,unsigned long delay_ms,int exclude_cpu);void cqm_handle_limbo (struct work_struct *work); -bool has_busy_rmid (struct rdt_mon_domain *d); +bool has_busy_rmid (struct rdt_l3_mon_domain *d); -void __check_limbo (struct rdt_mon_domain *d,bool force_free); +void __check_limbo (struct rdt_l3_mon_domain *d,bool force_free);void resctrl_file_fflags_init (const char *config,unsigned long fflags);
arch/x86/kernel/cpu/resctrl/core.c +7 -7
@@ -363,7 +363,7 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain *hw_dom)kfree (hw_dom); } -static void mon_domain_free (struct rdt_hw_mon_domain *hw_dom) +static void mon_domain_free (struct rdt_hw_l3_mon_domain *hw_dom) {int idx;
@@ -400,7 +400,7 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_ctrl_domain ** @num_rmid: The size of the MBM counter array * @hw_dom: The domain that owns the allocated arrays */ -static int arch_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_mon_domain *hw_dom) +static int arch_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_l3_mon_domain *hw_dom) {size_t tsize =sizeof (*hw_dom->arch_mbm_states[0 ]);enum resctrl_event_id eventid;
@@ -498,8 +498,8 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r)static void l3_mon_domain_setup (int cpu,int id,struct rdt_resource *r,struct list_head *add_pos) { -struct rdt_hw_mon_domain *hw_dom; -struct rdt_mon_domain *d; +struct rdt_hw_l3_mon_domain *hw_dom; +struct rdt_l3_mon_domain *d;struct cacheinfo *ci;int err;
@@ -626,9 +626,9 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)static void domain_remove_cpu_mon (int cpu,struct rdt_resource *r) {int id =get_domain_id_from_scope (cpu, r->mon_scope); -struct rdt_hw_mon_domain *hw_dom; +struct rdt_hw_l3_mon_domain *hw_dom; +struct rdt_l3_mon_domain *d;struct rdt_domain_hdr *hdr; -struct rdt_mon_domain *d;lockdep_assert_held (&domain_list_lock);
@@ -654,7 +654,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return ; - d = container_of(hdr, struct rdt_mon_domain, hdr); + d = container_of(hdr, struct rdt_l3_mon_domain, hdr); hw_dom =resctrl_to_arch_mon_dom (d);resctrl_offline_mon_domain (r, hdr);list_del_rcu (&hdr->list);
arch/x86/kernel/cpu/resctrl/monitor.c +10 -10
@@ -109,7 +109,7 @@ static inline u64 get_corrected_mbm_count(u32 rmid, unsigned long val)* * In RMID sharing mode there are fewer "logical RMID" values available * to accumulate data ("physical RMIDs" are divided evenly between SNC -* nodes that share an L3 cache). Linux creates an rdt_mon_domain for +* nodes that share an L3 cache). Linux creates an rdt_l3_mon_domain for * each SNC node. * * The value loaded into IA32_PQR_ASSOC is the "logical RMID".
@@ -157,7 +157,7 @@ static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 *val)return 0 ; } -static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_mon_domain *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_l3_mon_domain *hw_dom,u32 rmid,enum resctrl_event_id eventid) {
@@ -171,11 +171,11 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain *hw_doreturn state ? &state[rmid] :NULL ; } -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_l3_mon_domain *d,u32 unused,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); +struct rdt_hw_l3_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);int cpu =cpumask_any (&d->hdr.cpu_mask);struct arch_mbm_state *am;u32 prmid;
@@ -194,9 +194,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d,* Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_l3_mon_domain *d) { -struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); +struct rdt_hw_l3_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);enum resctrl_event_id eventid;int idx;
@@ -222,10 +222,10 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr, u64 *val, void *ignored) {int cpu =cpumask_any (&hdr->cpu_mask); -struct rdt_hw_mon_domain *hw_dom; +struct rdt_hw_l3_mon_domain *hw_dom;struct rdt_hw_resource *hw_res; +struct rdt_l3_mon_domain *d;struct arch_mbm_state *am; -struct rdt_mon_domain *d;u64 msr_val, chunks;u32 prmid;int ret;
@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return -EINVAL ; - d = container_of(hdr, struct rdt_mon_domain, hdr); + d = container_of(hdr, struct rdt_l3_mon_domain, hdr); hw_dom =resctrl_to_arch_mon_dom (d); hw_res =resctrl_to_arch_res (r); prmid =logical_rmid_to_physical_rmid (cpu, rmid);
@@ -275,7 +275,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,* must adjust RMID counter numbers based on SNC node. See * logical_rmid_to_physical_rmid() for code that does this. */ -void arch_mon_domain_online (struct rdt_resource *r,struct rdt_mon_domain *d) +void arch_mon_domain_online (struct rdt_resource *r,struct rdt_l3_mon_domain *d) {if (snc_nodes_per_l3_cache >1 )msr_clear_bit (MSR_RMID_SNC_CONFIG ,0 );
fs/resctrl/ctrlmondata.c +1 -1
@@ -616,7 +616,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r =resctrl_arch_get_resource (resid);if (md->sum) { -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;if (WARN_ON_ONCE (resid !=RDT_RESOURCE_L3 )) { ret = -EIO ;
fs/resctrl/monitor.c +17 -17
@@ -130,7 +130,7 @@ static void limbo_release_entry(struct rmid_entry *entry)* decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo (struct rdt_mon_domain *d,bool force_free) +void __check_limbo (struct rdt_l3_mon_domain *d,bool force_free) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 );u32 idx_limit =resctrl_arch_system_num_rmid_idx ();
@@ -188,7 +188,7 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)resctrl_arch_mon_ctx_free (r,QOS_L3_OCCUP_EVENT_ID , arch_mon_ctx); } -bool has_busy_rmid (struct rdt_mon_domain *d) +bool has_busy_rmid (struct rdt_l3_mon_domain *d) {u32 idx_limit =resctrl_arch_system_num_rmid_idx ();
@@ -289,7 +289,7 @@ int alloc_rmid(u32 closid)static void add_rmid_to_limbo (struct rmid_entry *entry) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;u32 idx;lockdep_assert_held (&rdtgroup_mutex);
@@ -342,7 +342,7 @@ void free_rmid(u32 closid, u32 rmid)list_add_tail (&entry->list, &rmid_free_lru); } -static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 closid, +static struct mbm_state *get_mbm_state (struct rdt_l3_mon_domain *d,u32 closid,u32 rmid,enum resctrl_event_id evtid) {u32 idx =resctrl_arch_rmid_idx_encode (closid, rmid);
@@ -359,7 +359,7 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_domain *d, u32 closid,static int __mon_event_count (u32 closid,u32 rmid,struct rmid_read *rr) {int cpu =smp_processor_id (); -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;struct cacheinfo *ci;struct mbm_state *m;int err, ret;
@@ -368,7 +368,7 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)if (rr->r->rid ==RDT_RESOURCE_L3 && rr->first) {if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return -EINVAL ; - d = container_of(rr->hdr, struct rdt_mon_domain, hdr); + d = container_of(rr->hdr, struct rdt_l3_mon_domain, hdr);resctrl_arch_reset_rmid (rr->r, d, closid, rmid, rr->evtid); m =get_mbm_state (d, closid, rmid, rr->evtid);if (m)
@@ -438,12 +438,12 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)static void mbm_bw_count (u32 closid,u32 rmid,struct rmid_read *rr) {u64 cur_bw, bytes, cur_bytes; -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;struct mbm_state *m;if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return ; - d = container_of(rr->hdr, struct rdt_mon_domain, hdr); + d = container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); m =get_mbm_state (d, closid, rmid, rr->evtid);if (WARN_ON_ONCE (!m))return ;
@@ -544,7 +544,7 @@ static struct rdt_ctrl_domain *get_ctrl_domain_from_cpu(int cpu,* throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidth. */ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) +static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_l3_mon_domain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data;
@@ -612,7 +612,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)resctrl_arch_update_one (r_mba, dom_mba, closid,CDP_NONE , new_msr_val); } -static void mbm_update_one_event (struct rdt_resource *r,struct rdt_mon_domain *d, +static void mbm_update_one_event (struct rdt_resource *r,struct rdt_l3_mon_domain *d,u32 closid,u32 rmid,enum resctrl_event_id evtid) {struct rmid_read rr = {0 };
@@ -639,7 +639,7 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *resctrl_arch_mon_ctx_free (rr.r, rr.evtid, rr.arch_mon_ctx); } -static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d, +static void mbm_update (struct rdt_resource *r,struct rdt_l3_mon_domain *d,u32 closid,u32 rmid) {/*
@@ -660,12 +660,12 @@ static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,void cqm_handle_limbo (struct work_struct *work) {unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL ); -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;cpus_read_lock ();mutex_lock (&rdtgroup_mutex); - d = container_of(work, struct rdt_mon_domain, cqm_limbo.work); + d = container_of(work, struct rdt_l3_mon_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -688,7 +688,7 @@ void cqm_handle_limbo(struct work_struct *work)* @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms, +void cqm_setup_limbo_handler (struct rdt_l3_mon_domain *dom,unsigned long delay_ms,int exclude_cpu) {unsigned long delay =msecs_to_jiffies (delay_ms);
@@ -705,7 +705,7 @@ void mbm_handle_overflow(struct work_struct *work) {unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL );struct rdtgroup *prgrp, *crgrp; -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;struct list_head *head;struct rdt_resource *r;
@@ -720,7 +720,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); - d = container_of(work, struct rdt_mon_domain, mbm_over.work); + d = container_of(work, struct rdt_l3_mon_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {mbm_update (r, d, prgrp->closid, prgrp->mon.rmid);
@@ -754,7 +754,7 @@ void mbm_handle_overflow(struct work_struct *work)* @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms, +void mbm_setup_overflow_handler (struct rdt_l3_mon_domain *dom,unsigned long delay_ms,int exclude_cpu) {unsigned long delay =msecs_to_jiffies (delay_ms);
fs/resctrl/rdtgroup.c +18 -18
@@ -1617,7 +1617,7 @@ static void mondata_config_read(struct resctrl_mon_config_info *mon_info)static int mbm_config_show (struct seq_file *s,struct rdt_resource *r,u32 evtid) {struct resctrl_mon_config_info mon_info; -struct rdt_mon_domain *dom; +struct rdt_l3_mon_domain *dom;bool sep = false;cpus_read_lock ();
@@ -1665,7 +1665,7 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of, }static void mbm_config_write_domain (struct rdt_resource *r, -struct rdt_mon_domain *d,u32 evtid,u32 val) +struct rdt_l3_mon_domain *d,u32 evtid,u32 val) {struct resctrl_mon_config_info mon_info = {0 };
@@ -1706,8 +1706,8 @@ static void mbm_config_write_domain(struct rdt_resource *r,static int mon_config_write (struct rdt_resource *r,char *tok,u32 evtid) {char *dom_str =NULL , *id_str; +struct rdt_l3_mon_domain *d;unsigned long dom_id, val; -struct rdt_mon_domain *d;/* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held ();
@@ -2581,7 +2581,7 @@ static int rdt_get_tree(struct fs_context *fc) {struct rdt_fs_context *ctx =rdt_fc2context (fc);unsigned long flags =RFTYPE_CTRL_BASE ; -struct rdt_mon_domain *dom; +struct rdt_l3_mon_domain *dom;struct rdt_resource *r;int ret;
@@ -3036,11 +3036,11 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,char name[32 ];if (r->rid ==RDT_RESOURCE_L3 ) { -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return ; - d = container_of(hdr, struct rdt_mon_domain, hdr); + d = container_of(hdr, struct rdt_l3_mon_domain, hdr);/* SNC mode? */ if (r->mon_scope ==RESCTRL_L3_NODE ) {
@@ -3100,11 +3100,11 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,if (r->rid ==RDT_RESOURCE_L3 ) { snc_mode = r->mon_scope ==RESCTRL_L3_NODE ;if (snc_mode) { -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return -EINVAL ; - d = container_of(hdr, struct rdt_mon_domain, hdr); + d = container_of(hdr, struct rdt_l3_mon_domain, hdr); domid = d->ci_id; } }
@@ -4040,7 +4040,7 @@ static void rdtgroup_setup_default(void)mutex_unlock (&rdtgroup_mutex); } -static void domain_destroy_mon_state (struct rdt_mon_domain *d) +static void domain_destroy_mon_state (struct rdt_l3_mon_domain *d) {int idx;
@@ -4063,7 +4063,7 @@ void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_domainvoid resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain_hdr *hdr) { -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;mutex_lock (&rdtgroup_mutex);
@@ -4080,7 +4080,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hif (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) goto out_unlock; - d = container_of(hdr, struct rdt_mon_domain, hdr); + d = container_of(hdr, struct rdt_l3_mon_domain, hdr);if (resctrl_is_mbm_enabled ())cancel_delayed_work (&d->mbm_over);if (resctrl_is_mon_event_enabled (QOS_L3_OCCUP_EVENT_ID ) &&has_busy_rmid (d)) {
@@ -4114,7 +4114,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h* * Returns 0 for success, or -ENOMEM. */ -static int domain_setup_mon_state (struct rdt_resource *r,struct rdt_mon_domain *d) +static int domain_setup_mon_state (struct rdt_resource *r,struct rdt_l3_mon_domain *d) {u32 idx_limit =resctrl_arch_system_num_rmid_idx ();size_t tsize =sizeof (*d->mbm_states[0 ]);
@@ -4165,7 +4165,7 @@ int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_domain *dint resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain_hdr *hdr) { -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;int err = -EINVAL ;mutex_lock (&rdtgroup_mutex);
@@ -4176,7 +4176,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdrif (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 )) goto out_unlock; - d = container_of(hdr, struct rdt_mon_domain, hdr); + d = container_of(hdr, struct rdt_l3_mon_domain, hdr); err =domain_setup_mon_state (r, d);if (err) goto out_unlock;
@@ -4225,10 +4225,10 @@ static void clear_childcpus(struct rdtgroup *r, unsigned int cpu) } } -static struct rdt_mon_domain *get_mon_domain_from_cpu (int cpu, -struct rdt_resource *r) +static struct rdt_l3_mon_domain *get_mon_domain_from_cpu (int cpu, +struct rdt_resource *r) { -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;lockdep_assert_cpus_held ();
@@ -4244,7 +4244,7 @@ static struct rdt_mon_domain *get_mon_domain_from_cpu(int cpu,void resctrl_offline_cpu (unsigned int cpu) {struct rdt_resource *l3 =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -struct rdt_mon_domain *d; +struct rdt_l3_mon_domain *d;struct rdtgroup *rdtgrp;mutex_lock (&rdtgroup_mutex);
Signature · 1 line
2.50.1
Re: [PATCH v9 10/31] x86,fs/resctrl: Rename struct rdt_mon_domain and rdt_hw_mon_domain
Hi Tony,
Quoted 15 lines · Tony Luck
All monitoring events are associated with the L3 resource. The per L3 domain resctrl fs monitoring state is maintained in the generically named struct
rdt_mon_domainwhile the per L3 domain architecture specific monitoring state is maintained in the generically named structrdt_hw_mon_domain.Upcoming telemetry event monitoring will be tied to another resource and requires new domain structures.
Rename the L3 resource specific domain data structures to include "
l3_" in their names to avoid confusion between the different resource specific domain structures:rdt_mon_domain->rdt_l3_mon_domainrdt_hw_mon_domain->rdt_hw_l3_mon_domain
Quoted 4 lines
No functional change.
Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 11/31 x86,fs/resctrl: Rename some L3 specific functions
In reply to Tony LuckAll monitor functions are tied to the RDT_RESOURCE_L3 resource, so generic function names to setup and tear down domains makes sense.
With the arrival of monitor events tied to new domains associated with a different resource it would be clearer if the L3 resource specific functions are more accurately named.
Rename three groups of functions:
Functions that allocate/free architecture per-RMID MBM state information:arch_domain_mbm_alloc() -> l3_mon_domain_mbm_alloc()mon_domain_free() -> l3_mon_domain_free()
Functions that allocate/free filesystem per-RMID MBM state information:domain_setup_mon_state() -> domain_setup_l3_mon_state()domain_destroy_mon_state() -> domain_destroy_l3_mon_state()
Initialization/exit:rdt_get_mon_l3_config() -> rdt_get_l3_mon_config()resctrl_mon_resource_init() -> resctrl_l3_mon_resource_init()resctrl_mon_resource_exit() -> resctrl_l3_mon_resource_exit()
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- fs/resctrl/internal.h | 6 +++--- arch/x86/kernel/cpu/resctrl/core.c | 18 +++++++++--------- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- fs/resctrl/monitor.c | 6 +++--- fs/resctrl/rdtgroup.c | 22 +++++++++++----------- 6 files changed, 28 insertions(+), 28 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
@@ -161,7 +161,7 @@ union cpuid_0x10_x_edx {void rdt_ctrl_update (void *arg); -int rdt_get_mon_l3_config (struct rdt_resource *r); +int rdt_get_l3_mon_config (struct rdt_resource *r);bool rdt_cpu_has (int flag);
fs/resctrl/internal.h +3 -3
@@ -345,7 +345,9 @@ int alloc_rmid(u32 closid);void free_rmid (u32 closid,u32 rmid); -void resctrl_mon_resource_exit (void ); +int resctrl_l3_mon_resource_init (void ); + +void resctrl_l3_mon_resource_exit (void );void mon_event_count (void *info);
@@ -355,8 +357,6 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_domain_hdr *hdr, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first); -int resctrl_mon_resource_init (void ); -void mbm_setup_overflow_handler (struct rdt_l3_mon_domain *dom,unsigned long delay_ms,int exclude_cpu);
arch/x86/kernel/cpu/resctrl/core.c +9 -9
@@ -363,7 +363,7 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain *hw_dom)kfree (hw_dom); } -static void mon_domain_free (struct rdt_hw_l3_mon_domain *hw_dom) +static void l3_mon_domain_free (struct rdt_hw_l3_mon_domain *hw_dom) {int idx;
@@ -396,11 +396,11 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_ctrl_domain * }/** -* arch_domain_mbm_alloc() - Allocate arch private storage for the MBM counters +* l3_mon_domain_mbm_alloc() - Allocate arch private storage for the MBM counters * @num_rmid: The size of the MBM counter array * @hw_dom: The domain that owns the allocated arrays */ -static int arch_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_l3_mon_domain *hw_dom) +static int l3_mon_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_l3_mon_domain *hw_dom) {size_t tsize =sizeof (*hw_dom->arch_mbm_states[0 ]);enum resctrl_event_id eventid;
@@ -514,7 +514,7 @@ static void l3_mon_domain_setup(int cpu, int id, struct rdt_resource *r, struct ci =get_cpu_cacheinfo_level (cpu,RESCTRL_L3_CACHE );if (!ci) {pr_warn_once ("Can't find L3 cache for CPU:%d resource %s\n" , cpu, r->name); -mon_domain_free (hw_dom); +l3_mon_domain_free (hw_dom);return ; } d->ci_id = ci->id;
@@ -522,8 +522,8 @@ static void l3_mon_domain_setup(int cpu, int id, struct rdt_resource *r, structarch_mon_domain_online (r, d); -if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -mon_domain_free (hw_dom); +if (l3_mon_domain_mbm_alloc (r->num_rmid, hw_dom)) { +l3_mon_domain_free (hw_dom);return ; }
@@ -533,7 +533,7 @@ static void l3_mon_domain_setup(int cpu, int id, struct rdt_resource *r, structif (err) {list_del_rcu (&d->hdr.list);synchronize_rcu (); -mon_domain_free (hw_dom); +l3_mon_domain_free (hw_dom); } }
@@ -659,7 +659,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)resctrl_offline_mon_domain (r, hdr);list_del_rcu (&hdr->list);synchronize_rcu (); -mon_domain_free (hw_dom); +l3_mon_domain_free (hw_dom);break ;default :pr_warn_once ("Unknown resource rid=%d\n" , r->rid);
@@ -903,7 +903,7 @@ static __init bool get_rdt_mon_resources(void)if (!ret)return false; -return !rdt_get_mon_l3_config (r); +return !rdt_get_l3_mon_config (r); }static __init void __check_quirks_intel (void )
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -344,7 +344,7 @@ static __init int snc_get_config(void)return ret; } -int __init rdt_get_mon_l3_config (struct rdt_resource *r) +int __init rdt_get_l3_mon_config (struct rdt_resource *r) {unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r);
fs/resctrl/monitor.c +3 -3
@@ -895,7 +895,7 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid) }/** -* resctrl_mon_resource_init() - Initialise global monitoring structures. +* resctrl_l3_mon_resource_init() - Initialise global monitoring structures. * * Allocate and initialise global monitor resources that do not belong to a * specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists.
@@ -906,7 +906,7 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid)* * Returns 0 for success, or -ENOMEM. */ -int resctrl_mon_resource_init (void ) +int resctrl_l3_mon_resource_init (void ) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 );int ret;
@@ -937,7 +937,7 @@ int resctrl_mon_resource_init(void)return 0 ; } -void resctrl_mon_resource_exit (void ) +void resctrl_l3_mon_resource_exit (void ) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 );
fs/resctrl/rdtgroup.c +11 -11
@@ -4040,7 +4040,7 @@ static void rdtgroup_setup_default(void)mutex_unlock (&rdtgroup_mutex); } -static void domain_destroy_mon_state (struct rdt_l3_mon_domain *d) +static void domain_destroy_l3_mon_state (struct rdt_l3_mon_domain *d) {int idx;
@@ -4096,13 +4096,13 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hcancel_delayed_work (&d->cqm_limbo); } -domain_destroy_mon_state (d); +domain_destroy_l3_mon_state (d); out_unlock:mutex_unlock (&rdtgroup_mutex); }/** -* domain_setup_mon_state() - Initialise domain monitoring structures. +* domain_setup_l3_mon_state() - Initialise domain monitoring structures. * @r: The resource for the newly online domain. * @d: The newly online domain. *
@@ -4110,11 +4110,11 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h* Called when the first CPU of a domain comes online, regardless of whether * the filesystem is mounted. * During boot this may be called before global allocations have been made by -* resctrl_mon_resource_init(). +* resctrl_l3_mon_resource_init(). * * Returns 0 for success, or -ENOMEM. */ -static int domain_setup_mon_state (struct rdt_resource *r,struct rdt_l3_mon_domain *d) +static int domain_setup_l3_mon_state (struct rdt_resource *r,struct rdt_l3_mon_domain *d) {u32 idx_limit =resctrl_arch_system_num_rmid_idx ();size_t tsize =sizeof (*d->mbm_states[0 ]);
@@ -4177,7 +4177,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr goto out_unlock; d = container_of(hdr, struct rdt_l3_mon_domain, hdr); - err =domain_setup_mon_state (r, d); + err =domain_setup_l3_mon_state (r, d);if (err) goto out_unlock;
@@ -4294,13 +4294,13 @@ int resctrl_init(void)thread_throttle_mode_init (); - ret =resctrl_mon_resource_init (); + ret =resctrl_l3_mon_resource_init ();if (ret)return ret; ret =sysfs_create_mount_point (fs_kobj,"resctrl" );if (ret) { -resctrl_mon_resource_exit (); +resctrl_l3_mon_resource_exit ();return ret; }
@@ -4335,7 +4335,7 @@ int resctrl_init(void) cleanup_mountpoint:sysfs_remove_mount_point (fs_kobj,"resctrl" ); -resctrl_mon_resource_exit (); +resctrl_l3_mon_resource_exit ();return ret; }
@@ -4371,7 +4371,7 @@ static bool resctrl_online_domains_exist(void)* When called by the architecture code, all CPUs and resctrl domains must be * offline. This ensures the limbo and overflow handlers are not scheduled to * run, meaning the data structures they access can be freed by -* resctrl_mon_resource_exit(). +* resctrl_l3_mon_resource_exit(). * * After resctrl_exit() returns, the architecture code should return an * error from all resctrl_arch_ functions that can do this.
@@ -4398,5 +4398,5 @@ void resctrl_exit(void)* it can be used to umount resctrl. */ -resctrl_mon_resource_exit (); +resctrl_l3_mon_resource_exit (); }
Signature · 1 line
2.50.1
Re: [PATCH v9 11/31] x86,fs/resctrl: Rename some L3 specific functions
Hi Tony,
Quoted 13 lines · Tony Luck
All monitor functions are tied to the
RDT_RESOURCE_L3resource, so generic function names to setup and tear down domains makes sense.With the arrival of monitor events tied to new domains associated with a different resource it would be clearer if the L3 resource specific functions are more accurately named.
Rename three groups of functions:
Functions that allocate/free architecture per-RMID MBM state information:
arch_domain_mbm_alloc()->l3_mon_domain_mbm_alloc()mon_domain_free()->l3_mon_domain_free()
Quoted 6 lines
Functions that allocate/free filesystem per-RMID MBM state information:
domain_setup_mon_state()->domain_setup_l3_mon_state()domain_destroy_mon_state()->domain_destroy_l3_mon_state()Initialization/exit:
rdt_get_mon_l3_config()->rdt_get_l3_mon_config()
Thank you for catching and adding this to have all around consistent naming.
Quoted 5 lines
resctrl_mon_resource_init()->resctrl_l3_mon_resource_init()resctrl_mon_resource_exit()->resctrl_l3_mon_resource_exit()Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 12/31 fs/resctrl: Make event details accessible to functions when reading events
In reply to Tony LuckAll details about a monitor event are kept in the mon_evt structure.
Upper levels of code only provide the event id via the mon_data and rmid_read structures to the functions finally reading the monitoring data.
The event id is sufficient for reading existing monitoring event data that requires programming of event id into MSR when reading the counter. Reading monitoring data from MMIO requires more context to be able to read the correct memory. struct mon_evt is the appropriate place for this event specific context.
Change the mon_data and rmid_read structures to hold a pointer to the mon_evt structure instead of just taking a copy of the event id.
No functional change.
--- fs/resctrl/internal.h | 10 +++++----- fs/resctrl/ctrlmondata.c | 16 ++++++++-------- fs/resctrl/monitor.c | 17 +++++++++-------- fs/resctrl/rdtgroup.c | 6 +++--- 4 files changed, 25 insertions(+), 24 deletions(-)
fs/resctrl/internal.h +5 -5
@@ -76,7 +76,7 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS];* struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list. * @rid: Resource id associated with the event file. -* @evtid: Event id associated with the event file. +* @evt: Event structure associated with the event file. * @sum: Set for RDT_RESOURCE_L3 when event must be summed * across multiple domains. * @domid: When @sum is zero this is the domain to which
@@ -90,7 +90,7 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS];struct mon_data {struct list_head list;enum resctrl_res_level rid; -enum resctrl_event_id evtid; +struct mon_evt *evt;int domid;bool sum; };
@@ -103,7 +103,7 @@ struct mon_data {* @r: Resource describing the properties of the event being read. * @hdr: Header of domain that the counter should be read from. If NULL then sum all * domains in @r sharing L3 @ci.id -* @evtid: Which monitor event to read. +* @evt: Which monitor event to read. * @first: Initialize MBM counter when true. * @ci_id: Cacheinfo id for L3. Only set when @hdr is NULL. Used when summing domains. * @err: Error encountered when reading counter.
@@ -117,7 +117,7 @@ struct rmid_read {struct rdtgroup *rgrp;struct rdt_resource *r;struct rdt_domain_hdr *hdr; -enum resctrl_event_id evtid; +struct mon_evt *evt;bool first;unsigned int ci_id;int err;
@@ -355,7 +355,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg);void mon_event_read (struct rmid_read *rr,struct rdt_resource *r,struct rdt_domain_hdr *hdr,struct rdtgroup *rdtgrp, -cpumask_t *cpumask,int evtid,int first); +cpumask_t *cpumask,struct mon_evt *evt,int first); void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delay_ms,
fs/resctrl/ctrlmondata.c +8 -8
@@ -548,7 +548,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,void mon_event_read (struct rmid_read *rr,struct rdt_resource *r,struct rdt_domain_hdr *hdr,struct rdtgroup *rdtgrp, -cpumask_t *cpumask,int evtid,int first) +cpumask_t *cpumask,struct mon_evt *evt,int first) {int cpu;
@@ -559,11 +559,11 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,* Setup the parameters to pass to mon_event_count() to read the data. */ rr->rgrp = rdtgrp; - rr->evtid = evtid; + rr->evt = evt; rr->r = r; rr->hdr = hdr; rr->first = first; - rr->arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r, evtid); + rr->arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r, evt->evtid);if (IS_ERR (rr->arch_mon_ctx)) { rr->err = -EINVAL ;return ;
@@ -582,20 +582,20 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,else smp_call_on_cpu (cpu, smp_mon_event_count, rr, false); -resctrl_arch_mon_ctx_free (r, evtid, rr->arch_mon_ctx); +resctrl_arch_mon_ctx_free (r, evt->evtid, rr->arch_mon_ctx); }int rdtgroup_mondata_show (struct seq_file *m,void *arg) {struct kernfs_open_file *of = m->private;enum resctrl_res_level resid; -enum resctrl_event_id evtid;struct rdt_domain_hdr *hdr;struct rmid_read rr = {0 };struct rdtgroup *rdtgrp;int domid, cpu, ret =0 ;struct rdt_resource *r;struct cacheinfo *ci; +struct mon_evt *evt;struct mon_data *md; rdtgrp =rdtgroup_kn_lock_live (of->kn);
@@ -612,7 +612,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) resid = md->rid; domid = md->domid; - evtid = md->evtid; + evt = md->evt; r =resctrl_arch_get_resource (resid);if (md->sum) {
@@ -636,7 +636,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)if (!ci)continue ;mon_event_read (&rr, r,NULL , rdtgrp, - &ci->shared_cpu_map, evtid, false); + &ci->shared_cpu_map, evt, false); goto checkresult; } }
@@ -652,7 +652,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } -mon_event_read (&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evtid, false); +mon_event_read (&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evt, false); } checkresult:
fs/resctrl/monitor.c +9 -8
@@ -369,8 +369,8 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return -EINVAL ; d = container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); -resctrl_arch_reset_rmid (rr->r, d, closid, rmid, rr->evtid); - m =get_mbm_state (d, closid, rmid, rr->evtid); +resctrl_arch_reset_rmid (rr->r, d, closid, rmid, rr->evt->evtid); + m =get_mbm_state (d, closid, rmid, rr->evt->evtid);if (m)memset (m,0 ,sizeof (struct mbm_state ));return 0 ;
@@ -381,7 +381,7 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)if (!cpumask_test_cpu (cpu, &rr->hdr->cpu_mask))return -EINVAL ; rr->err =resctrl_arch_rmid_read (rr->r, rr->hdr, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx);if (rr->err)return rr->err;
@@ -410,7 +410,7 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)if (d->ci_id != rr->ci_id)continue ; err =resctrl_arch_rmid_read (rr->r, &d->hdr, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx);if (!err) { rr->val += tval; ret =0 ;
@@ -444,7 +444,7 @@ static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)if (!domain_header_is_valid (rr->hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return ; d = container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); - m =get_mbm_state (d, closid, rmid, rr->evtid); + m =get_mbm_state (d, closid, rmid, rr->evt->evtid);if (WARN_ON_ONCE (!m))return ;
@@ -615,12 +615,13 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_l3_mon_domain *dom_mstatic void mbm_update_one_event (struct rdt_resource *r,struct rdt_l3_mon_domain *d,u32 closid,u32 rmid,enum resctrl_event_id evtid) { +struct mon_evt *evt = &mon_event_all[evtid];struct rmid_read rr = {0 }; rr.r = r; rr.hdr = &d->hdr; - rr.evtid = evtid; - rr.arch_mon_ctx =resctrl_arch_mon_ctx_alloc (rr.r, rr.evtid); + rr.evt = evt; + rr.arch_mon_ctx =resctrl_arch_mon_ctx_alloc (rr.r, evt->evtid);if (IS_ERR (rr.arch_mon_ctx)) {pr_warn_ratelimited ("Failed to allocate monitor context: %ld" ,PTR_ERR (rr.arch_mon_ctx));
@@ -636,7 +637,7 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon_domaiif (is_mba_sc (NULL ))mbm_bw_count (closid, rmid, &rr); -resctrl_arch_mon_ctx_free (rr.r, rr.evtid, rr.arch_mon_ctx); +resctrl_arch_mon_ctx_free (rr.r, evt->evtid, rr.arch_mon_ctx); } static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
fs/resctrl/rdtgroup.c +3 -3
@@ -2903,7 +2903,7 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid,list_for_each_entry (priv, &mon_data_kn_priv_list, list) {if (priv->rid == rid && priv->domid == domid && - priv->sum == do_sum && priv->evtid == mevt->evtid) + priv->sum == do_sum && priv->evt == mevt)return priv; }
@@ -2914,7 +2914,7 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid, priv->rid = rid; priv->domid = domid; priv->sum = do_sum; - priv->evtid = mevt->evtid; + priv->evt = mevt;list_add_tail (&priv->list, &mon_data_kn_priv_list);return priv;
@@ -3079,7 +3079,7 @@ static int mon_add_all_files(struct kernfs_node *kn, struct rdt_domain_hdr *hdr,return ret;if (r->rid ==RDT_RESOURCE_L3 && !do_sum &&resctrl_is_mbm_event (mevt->evtid)) -mon_event_read (&rr, r, hdr, prgrp, &hdr->cpu_mask, mevt->evtid, true); +mon_event_read (&rr, r, hdr, prgrp, &hdr->cpu_mask, mevt, true); }return 0 ;
Signature · 1 line
2.50.1
Re: [PATCH v9 12/31] fs/resctrl: Make event details accessible to functions when reading events
Hi Tony,
Quoted 11 lines · Tony Luck
All details about a monitor event are kept in the
mon_evtstructure.Upper levels of code only provide the event id via the
mon_dataandrmid_readstructures to the functions finally reading the monitoring data.The event id is sufficient for reading existing monitoring event data that requires programming of event id into MSR when reading the counter. Reading monitoring data from MMIO requires more context to be able to read the correct memory. struct
mon_evtis the appropriate place for this event specific context.
Quoted 8 lines
Change the
mon_dataandrmid_readstructures to hold a pointer to themon_evtstructure instead of just taking a copy of the event id.No functional change.
Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 13/31 x86,fs/resctrl: Handle events that can be read from any CPU
In reply to Tony Luckresctrl assumes that monitor events can only be read from a CPU in the cpumask_t set of each domain.
This is true for x86 events accessed with an MSR interface, but may not be true for other access methods such as MMIO.
Add a flag to struct mon_evt to indicate if the event can be read on any CPU.
Architecture uses resctrl_enable_mon_event() to enable an event and set the flag appropriately.
Bypass all the smp_call*() code for events that can be read on any CPU and call mon_event_count() directly from mon_event_read().
Add a test for events that can be read from any domain to skip checks in __mon_event_count() that the read is being done from a CPU in the correct domain or cache scope.
--- include/linux/resctrl.h | 2 +- fs/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++-- fs/resctrl/ctrlmondata.c | 7 +++- fs/resctrl/monitor.c | 53 ++++++++++++++++++++++-------- 5 files changed, 51 insertions(+), 19 deletions(-)
include/linux/resctrl.h +1 -1
@@ -379,7 +379,7 @@ 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); -void resctrl_enable_mon_event (enum resctrl_event_id eventid); +void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu);bool resctrl_is_mon_event_enabled (enum resctrl_event_id eventid);
fs/resctrl/internal.h +2 -0
@@ -57,6 +57,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)* @rid: resource id for this event * @name: name of the event * @configurable: true if the event is configurable +* @any_cpu: true if the event can be read from any CPU * @enabled: true if the event is enabled */ struct mon_evt {
@@ -64,6 +65,7 @@ struct mon_evt {enum resctrl_res_level rid;char *name;bool configurable; +bool any_cpu;bool enabled; };
arch/x86/kernel/cpu/resctrl/core.c +3 -3
@@ -888,15 +888,15 @@ static __init bool get_rdt_mon_resources(void)bool ret = false;if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) { -resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID ); +resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID , false); ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) { -resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID ); +resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID , false); ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) { -resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID ); +resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID , false); ret = true; }
fs/resctrl/ctrlmondata.c +6 -1
@@ -569,6 +569,11 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,return ; } +if (evt->any_cpu) { +mon_event_count (rr); + goto out_ctx_free; + } + cpu =cpumask_any_housekeeping (cpumask,RESCTRL_PICK_ANY_CPU );/*
@@ -581,7 +586,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,smp_call_function_any (cpumask, mon_event_count, rr,1 ); elsesmp_call_on_cpu (cpu ,smp_mon_event_count ,rr ,false ); - +out_ctx_free:resctrl_arch_mon_ctx_free (r, evt->evtid, rr->arch_mon_ctx); }
fs/resctrl/monitor.c +39 -14
91 lines not on this page · raw message
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 13/31] x86,fs/resctrl: Handle events that can be read from any CPU
Hi Tony,
Quoted 25 lines · Tony Luck
fs/resctrl/monitor.c +17
-0@@ -356,15 +356,47 @@ static struct mbm_state *get_mbm_state(struct rdt_l3_mon_domain *d, u32 closid,return state ? &state[idx] :NULL ; } +/* +* Called from preemptible context via a direct call of mon_event_count() for +* events that can be read on any CPU. +* Called from preemptible but non-migratable process context (mon_event_count() +* via smp_call_on_cpu()) OR non-preemptible context (mon_event_count() via +* smp_call_function_any()) for events that need to be read on a specific CPU. +*/ +static bool cpu_on_correct_domain (struct rmid_read *rr) +{ +struct cacheinfo *ci; +int cpu; + +/* Any CPU is OK for this event */ +if (rr->evt->any_cpu) +return true; + + cpu =smp_processor_id ();
fs/resctrl/monitor.c static struct mbm_state *get_mbm_state(struct rdt_l3_mon_domain *d, u32 closid, · line 385
Quoted 10 lines
fs/resctrl/monitor.c +10
-0+ +/* Single domain. Must be on a CPU in that domain. */ +if (rr->hdr) +return cpumask_test_cpu (cpu, &rr->hdr->cpu_mask); + +if (WARN_ON_ONCE (rr->r->rid !=RDT_RESOURCE_L3 )) +return false; + +/* Summing domains that share a cache, must be on a CPU for that cache. */ + ci =get_cpu_cacheinfo_level (cpu,RESCTRL_L3_CACHE );
This patch itself looks good to me. I do expect this patch to look different after the rebase since get_cpu_cacheinfo_level() is no longer called. I peeked at the new version [1] and the series looks significantly different. The thing that I wanted to check was if you kept the WARN_ON_ONCE(), which you did. Do you think it is still necessary since there is no longer a get_cpu_cacheinfo_level() with a hardcoded L3 resource? Otherwise I assume that this check falls into the same category as the earlier SNC related warnings and was not actually a check for the RESCTRL_L3_CACHE that followed above?
Reinette
Tony Luck
maintainerPATCH v9 14/31 x86,fs/resctrl: Support binary fixed point event counters
In reply to Tony Luckresctrl assumes that all monitor events can be displayed as unsigned decimal integers.
Hardware architecture counters may provide some telemetry events with greater precision where the event is not a simple count, but is a measurement of some sort (e.g. Joules for energy consumed).
Add a new argument to resctrl_enable_mon_event() for architecture code to inform the file system that the value for a counter is a fixed-point value with a specific number of binary places.
Only allow architecture to use floating point format on events that the file system has marked with mon_evt::is_floating_point.
Display fixed point values with values rounded to an appropriate number of decimal places for the precision of the number of binary places provided. Add one extra decimal place for every three additional binary places, except for low precision binary values where exact representation is possible:
1 binary place is 0.0 or 0.5. => 1 decimal place
2 binary places is 0.0, 0.25, 0.5, 0.75 => 2 decimal places
3 binary places is 0.0, 0.125, etc. => 3 decimal places
--- include/linux/resctrl.h | 3 +- fs/resctrl/internal.h | 8 +++ arch/x86/kernel/cpu/resctrl/core.c | 6 +-- fs/resctrl/ctrlmondata.c | 84 ++++++++++++++++++++++++++++++ fs/resctrl/monitor.c | 10 +++- 5 files changed, 105 insertions(+), 6 deletions(-)
include/linux/resctrl.h +2 -1
@@ -379,7 +379,8 @@ 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); -void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu); +void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu, +unsigned int binary_bits);bool resctrl_is_mon_event_enabled (enum resctrl_event_id eventid);
fs/resctrl/internal.h +8 -0
@@ -58,6 +58,9 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)* @name: name of the event * @configurable: true if the event is configurable * @any_cpu: true if the event can be read from any CPU +* @is_floating_point: event values are displayed in floating point format +* @binary_bits: number of fixed-point binary bits from architecture, +* only valid if @is_floating_point is true * @enabled: true if the event is enabled */ struct mon_evt {
@@ -66,6 +69,8 @@ struct mon_evt {char *name;bool configurable;bool any_cpu; +bool is_floating_point; +unsigned int binary_bits;bool enabled; };
@@ -74,6 +79,9 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS];#define for_each_mon_event (mevt) for (mevt = &mon_event_all[QOS_FIRST_EVENT]; \ mevt < &mon_event_all[QOS_NUM_EVENTS]; mevt++) +/* Limit for mon_evt::binary_bits */ +#define MAX_BINARY_BITS 27 +/** * struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list.
arch/x86/kernel/cpu/resctrl/core.c +3 -3
@@ -888,15 +888,15 @@ static __init bool get_rdt_mon_resources(void)bool ret = false;if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) { -resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID , false); +resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID , false,0 ); ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) { -resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID , false); +resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID , false,0 ); ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) { -resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID , false); +resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID , false,0 ); ret = true; }
fs/resctrl/ctrlmondata.c +84 -0
102 lines not on this page · raw message
fs/resctrl/monitor.c +8 -2
@@ -901,16 +901,22 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] = { }, }; -void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu) +void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu,unsigned int binary_bits) { -if (WARN_ON_ONCE (eventid <QOS_FIRST_EVENT || eventid >=QOS_NUM_EVENTS )) +if (WARN_ON_ONCE (eventid <QOS_FIRST_EVENT || eventid >=QOS_NUM_EVENTS || + binary_bits >MAX_BINARY_BITS ))return ;if (mon_event_all[eventid].enabled) {pr_warn ("Duplicate enable for event %d\n" , eventid);return ; } +if (binary_bits && !mon_event_all[eventid].is_floating_point) { +pr_warn ("Event %d may not be floating point\n" , eventid); +return ; + } mon_event_all[eventid].any_cpu = any_cpu; + mon_event_all[eventid].binary_bits = binary_bits; mon_event_all[eventid].enabled = true; }
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 14/31] x86,fs/resctrl: Support binary fixed point event counters
Hi Tony,
Quoted 13 lines · Tony Luck
resctrl assumes that all monitor events can be displayed as unsigned decimal integers.
Hardware architecture counters may provide some telemetry events with greater precision where the event is not a simple count, but is a measurement of some sort (e.g. Joules for energy consumed).
Add a new argument to
resctrl_enable_mon_event()for architecture code to inform the file system that the value for a counter is a fixed-point value with a specific number of binary places.
Only allow architecture to use floating point format on events that the file system has marked withmon_evt::is_floating_point.
Quoted 7 lines
Display fixed point values with values rounded to an appropriate number of decimal places for the precision of the number of binary places provided. Add one extra decimal place for every three additional binary places, except for low precision binary values where exact representation is possible:
1 binary place is 0.0 or 0.5. => 1 decimal place
nit: "0.5." -> "0.5"
Quoted 5 lines
2 binary places is 0.0, 0.25, 0.5, 0.75 => 2 decimal places
3 binary places is 0.0, 0.125, etc. => 3 decimal placesSigned-off-by Tony Luck <[email protected]>---
| Reviewed-by: Reinette Chatre <[email protected]>
Reinette
Tony Luck
maintainerPATCH v9 15/31 x86,fs/resctrl: Add an architectural hook called for each mount
In reply to Tony LuckEnumeration of Intel telemetry events is an asynchronous process involving several mutually dependent drivers added as auxiliary devices during the device_initcall() phase of Linux boot. The process finishes after the probe functions of these drivers completes. But this happens after resctrl_arch_late_init() is executed.
Tracing the enumeration process shows that it does complete a full seven seconds before the earliest possible mount of the resctrl file system (when included in /etc/fstab for automatic mount by systemd).
Add a hook at the beginning of the mount code that will be used to check for telemetry events and initialize if any are found.
Call the hook on every attempted mount. Expectations are that most actions (like enumeration) will only need to be performed on the first call.
resctrl filesystem calls the hook with no locks held. Architecture code is responsible for any required locking.
--- include/linux/resctrl.h | 6 ++++++ arch/x86/kernel/cpu/resctrl/core.c | 9 +++++++++ fs/resctrl/rdtgroup.c | 2 ++ 3 files changed, 17 insertions(+)
include/linux/resctrl.h +6 -0
@@ -459,6 +459,12 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hvoid resctrl_online_cpu (unsigned int cpu);void resctrl_offline_cpu (unsigned int cpu); +/* +* Architecture hook called at beginning of each file system mount attempt. +* No locks are held. +*/ +void resctrl_arch_pre_mount (void ); +/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid * for this resource and domain.
arch/x86/kernel/cpu/resctrl/core.c +9 -0
@@ -718,6 +718,15 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)return 0 ; } +void resctrl_arch_pre_mount (void ) +{ +static atomic_t only_once =ATOMIC_INIT (0 ); +int old =0 ; + +if (!atomic_try_cmpxchg (&only_once, &old,1 )) +return ; +} +enum {RDT_FLAG_CMT ,RDT_FLAG_MBM_TOTAL ,
fs/resctrl/rdtgroup.c +2 -0
@@ -2585,6 +2585,8 @@ static int rdt_get_tree(struct fs_context *fc)struct rdt_resource *r;int ret; +resctrl_arch_pre_mount (); +cpus_read_lock ();mutex_lock (&rdtgroup_mutex);/*
Signature · 1 line
2.50.1
Re: [PATCH v9 15/31] x86,fs/resctrl: Add an architectural hook called for each mount
Hi Tony,
Quoted 17 lines · Tony Luck
Enumeration of Intel telemetry events is an asynchronous process involving several mutually dependent drivers added as auxiliary devices during the
device_initcall()phase of Linux boot. The process finishes after the probe functions of these drivers completes. But this happens afterresctrl_arch_late_init()is executed.Tracing the enumeration process shows that it does complete a full seven seconds before the earliest possible mount of the resctrl file system (when included in
/etc/fstabfor automatic mount by systemd).Add a hook at the beginning of the mount code that will be used to check for telemetry events and initialize if any are found.
Call the hook on every attempted mount. Expectations are that most actions (like enumeration) will only need to be performed on the first call.
Quoted 5 lines
resctrl filesystem calls the hook with no locks held. Architecture code is responsible for any required locking.
Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 16/31 x86,fs/resctrl: Add and initialize rdt_resource for package scope monitor
In reply to Tony LuckAdd a new PERF_PKG resource and introduce package level scope for monitoring telemetry events so that CPU hot plug notifiers can build domains at the package granularity.
Use the physical package ID available via topology_physical_package_id() to identify the monitoring domains with package level scope. This enables user space to use:
/sys/devices/system/cpu/cpuX/topology/physical_package_id
to identify the monitoring domain a CPU is associated with.
--- include/linux/resctrl.h | 2 ++ fs/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++++++ fs/resctrl/rdtgroup.c | 2 ++ 4 files changed, 16 insertions(+)
include/linux/resctrl.h +2 -0
@@ -53,6 +53,7 @@ enum resctrl_res_level {RDT_RESOURCE_L2 ,RDT_RESOURCE_MBA ,RDT_RESOURCE_SMBA , +RDT_RESOURCE_PERF_PKG ,/* Must be the last */ RDT_NUM_RESOURCES,
@@ -252,6 +253,7 @@ enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 ,RESCTRL_L3_NODE , + RESCTRL_PACKAGE, };/**
fs/resctrl/internal.h +2 -0
@@ -243,6 +243,8 @@ struct rdtgroup {#define RFTYPE_DEBUG BIT(10) +#define RFTYPE_RES_PERF_PKG BIT(11) +#define RFTYPE_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL)#define RFTYPE_MON_INFO (RFTYPE_INFO | RFTYPE_MON)
arch/x86/kernel/cpu/resctrl/core.c +10 -0
@@ -100,6 +100,14 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { .schema_fmt = RESCTRL_SCHEMA_RANGE, }, }, + [RDT_RESOURCE_PERF_PKG ] = + { + .r_resctrl = { + .name ="PERF_PKG" , + .mon_scope =RESCTRL_PACKAGE , + .mon_domains =mon_domain_init (RDT_RESOURCE_PERF_PKG ), + }, + }, };u32 resctrl_arch_system_num_rmid_idx (void )
@@ -433,6 +441,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return get_cpu_cacheinfo_id (cpu, scope);case RESCTRL_L3_NODE :return cpu_to_node (cpu); +case RESCTRL_PACKAGE : +return topology_physical_package_id (cpu);default :break ; }
fs/resctrl/rdtgroup.c +2 -0
@@ -2195,6 +2195,8 @@ static unsigned long fflags_from_resource(struct rdt_resource *r)case RDT_RESOURCE_MBA :case RDT_RESOURCE_SMBA :return RFTYPE_RES_MB ; +case RDT_RESOURCE_PERF_PKG : +return RFTYPE_RES_PERF_PKG ; }return WARN_ON_ONCE (1 );
Signature · 1 line
2.50.1
Tony Luck
maintainerPATCH v9 17/31 x86/resctrl: Discover hardware telemetry events
In reply to Tony LuckEach CPU collects data for telemetry events that it sends to a nearby telemetry event aggregator either when the value of IA32_PQR_ASSOC.RMID changed, or when a two millisecond timer expires.
The telemetry event aggregators maintain per-RMID per-event counts of the total seen for all the CPUs. There may be more than one telemetry event aggregator per package.
Each telemetry event aggregator is responsible for a specific group of events. E.g. on the Intel Clearwater Forest CPU there are two types of aggregators. One type tracks a pair of energy related events. The other type tracks a subset of "perf" type events.
The event counts are made available to Linux in a region of MMIO space for each aggregator. All details about the layout of counters in each aggregator MMIO region are described in XML files published by Intel and made available in a GitHub repository: https://github.com/intel/Intel-PMT.
The key to matching a specific telemetry aggregator to the XML file that describes the MMIO layout is a 32-bit value. The Linux telemetry subsystem refers to this as a "guid" while the XML files call it a "uniqueid".
Each XML file provides the following information:
1) Which telemetry events are included in the group.
2) The order in which the event counters appear for each RMID.
3) The value type of each event counter (integer or fixed-point).
4) The number of RMIDs supported.
5) Which additional aggregator status registers are included.
6) The total size of the MMIO region for this aggregator.
The INTEL_PMT_TELEMETRY driver enumerates support for telemetry events. This driver provides intel_pmt_get_regions_by_feature() to list all available telemetry event aggregators. The list includes the "guid", the base address in MMIO space for the region where the event counters are exposed, and the package id where the CPUs that report to this aggregator are located.
Add a new Kconfig option CONFIG_X86_CPU_RESCTRL_INTEL_AET for the Intel specific parts of telemetry code. This depends on the INTEL_PMT_TELEMETRY and INTEL_TPMI drivers being built-in to the kernel for enumeration of telemetry features.
Call intel_pmt_get_regions_by_feature() for each pmt_feature_id that indicates per-RMID telemetry.
Save the returned pmt_feature_group pointers with guids that are known to resctrl for use at run time. Those pointers are returned to the INTEL_PMT_TELEMETRY subsystem at resctrl_arch_exit() time.
---
Note that checkpatch complains about this:
DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *,
if (!IS_ERR_OR_NULL(_T)) intel_pmt_put_feature_group(_T))
with:
CHECK: Alignment should match open parenthesis
But if the alignment is fixed, it then complains:
WARNING: Statements should start on a tabstop
--- arch/x86/kernel/cpu/resctrl/internal.h | 8 ++ arch/x86/kernel/cpu/resctrl/core.c | 5 + arch/x86/kernel/cpu/resctrl/intel_aet.c | 133 ++++++++++++++++++++++++ arch/x86/Kconfig | 13 +++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 5 files changed, 160 insertions(+) create mode 100644 arch/x86/kernel/cpu/resctrl/intel_aet.c
arch/x86/kernel/cpu/resctrl/internal.h +8 -0
@@ -169,4 +169,12 @@ void __init intel_rdt_mbm_apply_quirk(void);void rdt_domain_reconfigure_cdp (struct rdt_resource *r); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET +bool intel_aet_get_events (void ); +void __exit intel_aet_exit(void); +#else +static inline bool intel_aet_get_events (void ) {return false; } +static inline void __exit intel_aet_exit(void) { } +#endif +#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/core.c +5 -0
@@ -735,6 +735,9 @@ void resctrl_arch_pre_mount(void)if (!atomic_try_cmpxchg (&only_once, &old,1 ))return ; + +if (!intel_aet_get_events ()) +return ; }enum {
@@ -1087,6 +1090,8 @@ 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 new file +133 -0
133 lines not on this page · raw message
arch/x86/Kconfig +13 -0
@@ -525,6 +525,19 @@ config X86_CPU_RESCTRL Say N if unsure. +config X86_CPU_RESCTRL_INTEL_AET + bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y + depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + help + Enable per-RMID telemetry events in resctrl. + + Intel feature that collects per-RMID execution data + about energy consumption, measure of frequency independent + activity and other performance metrics. Data is aggregated + per package. + + Say N if unsure. + config X86_FRED bool "Flexible Return and Event Delivery" depends on X86_64
arch/x86/kernel/cpu/resctrl/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o +obj-$(CONFIG_X86_CPU_RESCTRL_INTEL_AET) += intel_aet.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) += pseudo_lock.o # To allow define_trace.h's recursive include:
Signature · 1 line
2.50.1
Re: [PATCH v9 17/31] x86/resctrl: Discover hardware telemetry events
Quoted 42 lines · Tony Luck
Each CPU collects data for telemetry events that it sends to a nearby telemetry event aggregator either when the value of IA32_PQR_ASSOC.RMID changed, or when a two millisecond timer expires.
The telemetry event aggregators maintain per-RMID per-event counts of the total seen for all the CPUs. There may be more than one telemetry event aggregator per package.
Each telemetry event aggregator is responsible for a specific group of events. E.g. on the Intel Clearwater Forest CPU there are two types of aggregators. One type tracks a pair of energy related events. The other type tracks a subset of "perf" type events.
The event counts are made available to Linux in a region of MMIO space for each aggregator. All details about the layout of counters in each aggregator MMIO region are described in XML files published by Intel and made available in a GitHub repository: https://github.com/intel/Intel-PMT.
The key to matching a specific telemetry aggregator to the XML file that describes the MMIO layout is a 32-bit value. The Linux telemetry subsystem refers to this as a "guid" while the XML files call it a "uniqueid".
Each XML file provides the following information:
1) Which telemetry events are included in the group.
2) The order in which the event counters appear for each RMID.
3) The value type of each event counter (integer or fixed-point).
4) The number of RMIDs supported.
5) Which additional aggregator status registers are included.
6) The total size of the MMIO region for this aggregator.The
INTEL_PMT_TELEMETRYdriver enumerates support for telemetry events. This driver providesintel_pmt_get_regions_by_feature()to list all available telemetry event aggregators. The list includes the "guid", the base address in MMIO space for the region where the event counters are exposed, and the package id where the CPUs that report to this aggregator are located.Add a new
KconfigoptionCONFIG_X86_CPU_RESCTRL_INTEL_AETfor the Intel specific parts of telemetry code. This depends on theINTEL_PMT_TELEMETRYandINTEL_TPMIdrivers being built-in to the kernel for enumeration of telemetry features.
Quoted 5 lines
Call
intel_pmt_get_regions_by_feature()for eachpmt_feature_idthat indicates per-RMID telemetry.Save the returned
pmt_feature_grouppointers with guids that are known to resctrl for use at run time. Those pointers are returned to the
Extra space
Quoted 120 lines
INTEL_PMT_TELEMETRYsubsystem atresctrl_arch_exit()time.Signed-off-by Tony Luck <[email protected]>---
Note that checkpatch complains about this:DEFINE_FREE(intel_pmt_put_feature_group, struct
pmt_feature_group*,if (!IS_ERR_OR_NULL(_T)) intel_pmt_put_feature_group(_T))with:
CHECK: Alignment should match open parenthesisBut if the alignment is fixed, it then complains:
WARNING: Statements should start on a tabstop--- arch/x86/kernel/cpu/resctrl/internal.h | 8 ++ arch/x86/kernel/cpu/resctrl/core.c | 5 + arch/x86/kernel/cpu/resctrl/intel_aet.c | 133 ++++++++++++++++++++++++ arch/x86/Kconfig | 13 +++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 5 files changed, 160 insertions(+) create mode 100644 arch/x86/kernel/cpu/resctrl/intel_aet.carch/x86/kernel/cpu/resctrl/internal.h +8
-0@@ -169,4 +169,12 @@ void __init intel_rdt_mbm_apply_quirk(void);void rdt_domain_reconfigure_cdp (struct rdt_resource *r); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET +bool intel_aet_get_events (void ); +void __exit intel_aet_exit(void); +#else +static inline bool intel_aet_get_events (void ) {return false; } +static inline void __exit intel_aet_exit(void) { } +#endif +#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/core.c +5
-0@@ -735,6 +735,9 @@ void resctrl_arch_pre_mount(void)if (!atomic_try_cmpxchg (&only_once, &old,1 ))return ; + +if (!intel_aet_get_events ()) +return ; }enum {@@ -1087,6 +1090,8 @@ 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 new file +51
-0@@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Resource Director Technology(RDT) +* - Intel Application Energy Telemetry +* +* Copyright (C) 2025 Intel Corporation +* +* Author: +* Tony Luck <[email protected]> +*/ + +#define pr_fmt (fmt) "resctrl: " fmt + +#include <linux/cleanup.h> +#include <linux/cpu.h> +#include <linux/intel_vsec.h> +#include <linux/resctrl.h> + +#include "internal.h" + +/** +* struct event_group - All information about a group of telemetry events. +* @pfg: Points to the aggregated telemetry space information +* within the INTEL_PMT_TELEMETRY driver that contains data for all +* telemetry regions. +* @guid: Unique number per XML description file. +*/ +struct event_group { +/* Data fields for additional structures to manage this group. */ +struct pmt_feature_group *pfg; + +/* Remaining fields initialized from XML file. */ +u32 guid; +}; + +/* +* Link: https://github.com/intel/Intel-PMT +* File: xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xml +*/ +static struct event_group energy_0x26696143 = { + .guid =0x26696143 , +}; + +/* +* Link: https://github.com/intel/Intel-PMT +* File: xml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xml +*/ +static struct event_group perf_0x26557651 = { + .guid =0x26557651 , +}; +
arch/x86/kernel/cpu/resctrl/intel_aet.c line 61
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +10
-0+static struct event_group *known_energy_event_groups[] = { + &energy_0x26696143, +}; + +static struct event_group *known_perf_event_groups[] = { + &perf_0x26557651, +}; + +#define for_each_enabled_event_group (_peg, _grp) \ + for (_peg = _grp; _peg < &_grp[ARRAY_SIZE(_grp)]; _peg++) \
+ linux/array_size.h
Wouldn't it be wiser to protect the args even if the current users seem fine?
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +5
-0+if ((*_peg)->pfg) + +/* Stub for now */ +static bool enable_events(struct event_group *e, struct pmt_feature_group *p) +{
arch/x86/kernel/cpu/resctrl/intel_aet.c line 76
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +10
-0+return false; +} + +DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, + if (!IS_ERR_OR_NULL(_T)) +intel_pmt_put_feature_group (_T)) + +/* +* Make a request to the INTEL_PMT_TELEMETRY driver for the pmt_feature_group +* for a specific feature. If there is one the returned structure has an array
Missing comma?
arch/x86/kernel/cpu/resctrl/intel_aet.c line 89
Quoted 13 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +13
-0+* of telemetry_region structures. Each describes one telemetry aggregator. +* Try to use every telemetry aggregator with a known guid. +*/ +static bool get_pmt_feature (enum pmt_feature_id feature,struct event_group **evgs, +unsigned int num_evg) +{ + struct pmt_feature_group *p __free(intel_pmt_put_feature_group) = NULL; +struct event_group **peg; +int ret; + + p =intel_pmt_get_regions_by_feature (feature); + +if (IS_ERR_OR_NULL (p))
+ linux/err.h
arch/x86/kernel/cpu/resctrl/intel_aet.c line 94
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +5
-0+return false; + +for (peg = evgs; peg < &evgs[num_evg]; peg++) { + ret =enable_events (*peg, p); +if (ret) {
This is super misleading. You place a bool returning function's return value into "int ret" and then use the value like bool.
Quoted 76 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +39
-0+ (*peg)->pfg =no_free_ptr (p); +return true; + } + } + +return false; +} + +/* +* Ask INTEL_PMT_TELEMETRY driver for all the RMID based telemetry groups +* that it supports. +*/ +bool intel_aet_get_events (void ) +{ +bool ret1, ret2; + + ret1 =get_pmt_feature (FEATURE_PER_RMID_ENERGY_TELEM , + known_energy_event_groups, +ARRAY_SIZE (known_energy_event_groups)); + ret2 =get_pmt_feature (FEATURE_PER_RMID_PERF_TELEM , + known_perf_event_groups, +ARRAY_SIZE (known_perf_event_groups)); + +return ret1 || ret2; +} + +void __exit intel_aet_exit(void) +{ +struct event_group **peg; + +for_each_enabled_event_group (peg, known_energy_event_groups) { +intel_pmt_put_feature_group ((*peg)->pfg); + (*peg)->pfg =NULL ; + } +for_each_enabled_event_group (peg, known_perf_event_groups) { +intel_pmt_put_feature_group ((*peg)->pfg); + (*peg)->pfg =NULL ; + } +}arch/x86/Kconfig +13
-0@@ -525,6 +525,19 @@ config X86_CPU_RESCTRL Say N if unsure. +config X86_CPU_RESCTRL_INTEL_AET + bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y + depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + help + Enable per-RMID telemetry events in resctrl. + + Intel feature that collects per-RMID execution data + about energy consumption, measure of frequency independent + activity and other performance metrics. Data is aggregated + per package. + + Say N if unsure. + config X86_FRED bool "Flexible Return and Event Delivery" depends on X86_64arch/x86/kernel/cpu/resctrl/Makefile +1
-0@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o +obj-$(CONFIG_X86_CPU_RESCTRL_INTEL_AET) += intel_aet.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) += pseudo_lock.o # To allow define_trace.h's recursive include:
Signature · 1 line
i.
Luck, Tony
maintainerRe: [PATCH v9 17/31] x86/resctrl: Discover hardware telemetry events
Ilpo,
Thanks for looking at these patches. Applied all your suggestions for this part. Updated patch below. Also pushed togit://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git rdt-aet-v10-wip
-Tony
From c717ab20b7781eec8b6dcf711eb0e2f8255aef8c Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Mon, 25 Aug 2025 10:45:34 -0700
Subject: [PATCH 17/31] x86/resctrl: Discover hardware telemetry events
Each CPU collects data for telemetry events that it sends to a nearby telemetry event aggregator either when the value of IA32_PQR_ASSOC.RMID changed, or when a two millisecond timer expires.
The telemetry event aggregators maintain per-RMID per-event counts of the total seen for all the CPUs. There may be more than one telemetry event aggregator per package.
Each telemetry event aggregator is responsible for a specific group of events. E.g. on the Intel Clearwater Forest CPU there are two types of aggregators. One type tracks a pair of energy related events. The other type tracks a subset of "perf" type events.
The event counts are made available to Linux in a region of MMIO space for each aggregator. All details about the layout of counters in each aggregator MMIO region are described in XML files published by Intel and made available in a GitHub repository: https://github.com/intel/Intel-PMT.
The key to matching a specific telemetry aggregator to the XML file that describes the MMIO layout is a 32-bit value. The Linux telemetry subsystem refers to this as a "guid" while the XML files call it a "uniqueid".
Each XML file provides the following information:
1) Which telemetry events are included in the group.
2) The order in which the event counters appear for each RMID.
3) The value type of each event counter (integer or fixed-point).
4) The number of RMIDs supported.
5) Which additional aggregator status registers are included.
6) The total size of the MMIO region for this aggregator.
The INTEL_PMT_TELEMETRY driver enumerates support for telemetry events. This driver provides intel_pmt_get_regions_by_feature() to list all available telemetry event aggregators. The list includes the "guid", the base address in MMIO space for the region where the event counters are exposed, and the package id where the CPUs that report to this aggregator are located.
Add a new Kconfig option CONFIG_X86_CPU_RESCTRL_INTEL_AET for the Intel specific parts of telemetry code. This depends on the INTEL_PMT_TELEMETRY and INTEL_TPMI drivers being built-in to the kernel for enumeration of telemetry features.
Call intel_pmt_get_regions_by_feature() for each pmt_feature_id that indicates per-RMID telemetry.
Save the returned pmt_feature_group pointers with guids that are known to resctrl for use at run time. Those pointers are returned to the INTEL_PMT_TELEMETRY subsystem at resctrl_arch_exit() time.
---
Note that checkpatch complains about this:
DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *,
if (!IS_ERR_OR_NULL(_T)) intel_pmt_put_feature_group(_T))
with:
CHECK: Alignment should match open parenthesis
But if the alignment is fixed, it then complains:
WARNING: Statements should start on a tabstop
--- arch/x86/kernel/cpu/resctrl/internal.h | 8 ++ arch/x86/kernel/cpu/resctrl/core.c | 5 + arch/x86/kernel/cpu/resctrl/intel_aet.c | 140 ++++++++++++++++++++++++ arch/x86/Kconfig | 13 +++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 5 files changed, 167 insertions(+) create mode 100644 arch/x86/kernel/cpu/resctrl/intel_aet.c
arch/x86/kernel/cpu/resctrl/internal.h +8 -0
@@ -169,4 +169,12 @@ void __init intel_rdt_mbm_apply_quirk(void);void rdt_domain_reconfigure_cdp (struct rdt_resource *r); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET +bool intel_aet_get_events (void ); +void __exit intel_aet_exit(void); +#else +static inline bool intel_aet_get_events (void ) {return false; } +static inline void __exit intel_aet_exit(void) { } +#endif +#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/core.c +5 -0
@@ -735,6 +735,9 @@ void resctrl_arch_pre_mount(void)if (!atomic_try_cmpxchg (&only_once, &old,1 ))return ; + +if (!intel_aet_get_events ()) +return ; }enum {
@@ -1087,6 +1090,8 @@ 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 new file +140 -0
140 lines not on this page · raw message
arch/x86/Kconfig +13 -0
@@ -525,6 +525,19 @@ config X86_CPU_RESCTRL Say N if unsure. +config X86_CPU_RESCTRL_INTEL_AET + bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y + depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + help + Enable per-RMID telemetry events in resctrl. + + Intel feature that collects per-RMID execution data + about energy consumption, measure of frequency independent + activity and other performance metrics. Data is aggregated + per package. + + Say N if unsure. + config X86_FRED bool "Flexible Return and Event Delivery" depends on X86_64
arch/x86/kernel/cpu/resctrl/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o +obj-$(CONFIG_X86_CPU_RESCTRL_INTEL_AET) += intel_aet.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) += pseudo_lock.o # To allow define_trace.h's recursive include:
Signature · 1 line
2.51.0
Reinette Chatre
maintainerRe: [PATCH v9 17/31] x86/resctrl: Discover hardware telemetry events
Hi Tony,
Quoted 9 lines · Tony
Ilpo,
Thanks for looking at these patches. Applied all your suggestions for this part. Updated patch below. Also pushed to
git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.gitrdt-aet-v10-wip-Tony
Quoted 8 lines
From
c717ab20b7781eec8b6dcf711eb0e2f8255aef8cMon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Mon, 25 Aug 2025 10:45:34 -0700
Subject: [PATCH 17/31] x86/resctrl: Discover hardware telemetry eventsEach CPU collects data for telemetry events that it sends to a nearby telemetry event aggregator either when the value of IA32_PQR_ASSOC.RMID changed, or when a two millisecond timer expires.
"changed" -> "changes" (repeated from v8)
Quoted 4 lines
The telemetry event aggregators maintain per-RMID per-event counts of the total seen for all the CPUs. There may be more than one telemetry event aggregator per package.
... and if there are more than one telemetry event aggregator per package do they *all* maintain per-RMID per-event counts of the total seen for all the CPUs? Above is not clear about this.
Quoted 10 lines
Each telemetry event aggregator is responsible for a specific group of events. E.g. on the Intel Clearwater Forest CPU there are two types of aggregators. One type tracks a pair of energy related events. The other type tracks a subset of "perf" type events.
The event counts are made available to Linux in a region of MMIO space for each aggregator. All details about the layout of counters in each aggregator MMIO region are described in XML files published by Intel and made available in a GitHub repository: https://github.com/intel/Intel-PMT.
I expect the usage of "Link:" will clarify but until then we can keep using it based on guidance in maintainer-tip.rst. For example, "made available in a GitHub repository [1]." with the "Link:" tag added to end of commit tags as:
Link: https://github.com/intel/Intel-PMT # [1]
Quoted 5 lines
The key to matching a specific telemetry aggregator to the XML file that describes the MMIO layout is a 32-bit value. The Linux telemetry subsystem refers to this as a "guid" while the XML files call it a "uniqueid".
Quoted 7 lines
Each XML file provides the following information:
1) Which telemetry events are included in the group.
2) The order in which the event counters appear for each RMID.
3) The value type of each event counter (integer or fixed-point).
4) The number of RMIDs supported.
5) Which additional aggregator status registers are included.
6) The total size of the MMIO region for this aggregator.
"this aggregator" -> "an aggregator"? As in, all aggregators matching "guid" will have same MMIO size, the MMIO size is not unique per aggregator associated with the event group?
Quoted 7 lines
The
INTEL_PMT_TELEMETRYdriver enumerates support for telemetry events. This driver providesintel_pmt_get_regions_by_feature()to list all available telemetry event aggregators. The list includes the "guid", the base address in MMIO space for the region where the event counters are exposed, and the package id where the CPUs that report to this aggregator are located.
Please note this switches from earlier "The telemetry event aggregators maintain per-RMID per-event counts of the total seen for *all* the CPUs." to here (singular) "package id where the CPUs that report to this aggregator are located." Please maintain consistent descriptions to make the architecture easier to understand.
Quoted 8 lines
Add a new
KconfigoptionCONFIG_X86_CPU_RESCTRL_INTEL_AETfor the Intel specific parts of telemetry code. This depends on theINTEL_PMT_TELEMETRYandINTEL_TPMIdrivers being built-in to the kernel for enumeration of telemetry features.Call
intel_pmt_get_regions_by_feature()for eachpmt_feature_idthat indicates per-RMID telemetry.
"for each pmt_feature_id that indicates per-RMID telemetry" -> "for each per-RMID telemetry feature ID/id"? (goal is for changelog to be less of a description of the code and more what the code does)
Quoted 2 lines
Save the returned
pmt_feature_grouppointers with guids that are known
All guids are saved, no? Not just those known to resctrl?
Quoted 1 line
to resctrl for use at run time. Those pointers are returned to the
"Return those pointers ..." (but see below)
Quoted 1 line
INTEL_PMT_TELEMETRYsubsystem atresctrl_arch_exit()time.
This does still sound as though resctrl obtains a pointer to a data structure within INTEL_PMT_TELEMETRY. I think it will be helpful to highlight that resctrl obtains a fresh copy of the whole datastructure for its private use ... and not document the code so detailed when describing this.
For example (please correct where wrong),
Use INTEL_PMT_TELEMETRY's intel_pmt_get_regions_by_feature() with each per-RMID telemetry feature id to obtain a private copy of struct pmt_feature_group that contains all discovered/enumerated telemetry aggregator data for all event groups (known and unknown to resctrl) of that feature id. Further processing on this structure will enable all supported events in resctrl. Return the structure to INTEL_PMT_TELEMETRY at resctrl exit time.
Quoted 3 lines
Signed-off-by Tony Luck <[email protected]>---
...
Quoted 28 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +22
-0@@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Resource Director Technology(RDT) +* - Intel Application Energy Telemetry +* +* Copyright (C) 2025 Intel Corporation +* +* Author: +* Tony Luck <[email protected]> +*/ + +#define pr_fmt (fmt) "resctrl: " fmt + +#include <linux/array_size.h> +#include <linux/cleanup.h> +#include <linux/cpu.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/intel_pmt_features.h> +#include <linux/intel_vsec.h> +#include <linux/overflow.h> +#include <linux/resctrl.h>
arch/x86/kernel/cpu/resctrl/intel_aet.c line 32
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +10
-0+#include <linux/stddef.h> +#include <linux/types.h> + +#include "internal.h" + +/** +* struct event_group - All information about a group of telemetry events. +* @pfg: Points to the aggregated telemetry space information +* within the INTEL_PMT_TELEMETRY driver that contains data for all +* telemetry regions.
We since learned that this is not the case, no?
Considering the new usage I also think it will be helpful to add a usage snippet like:
"Valid if system supports the event group, NULL otherwise."
While doing so, please keep the columns consistently under 80 chars.
Quoted 40 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +40
-0+* @guid: Unique number per XML description file. +*/ +struct event_group { +/* Data fields for additional structures to manage this group. */ +struct pmt_feature_group *pfg; + +/* Remaining fields initialized from XML file. */ +u32 guid; +}; + +/* +* Link: https://github.com/intel/Intel-PMT +* File: xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xml +*/ +static struct event_group energy_0x26696143 = { + .guid =0x26696143 , +}; + +/* +* Link: https://github.com/intel/Intel-PMT +* File: xml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xml +*/ +static struct event_group perf_0x26557651 = { + .guid =0x26557651 , +}; + +static struct event_group *known_energy_event_groups[] = { + &energy_0x26696143, +}; + +static struct event_group *known_perf_event_groups[] = { + &perf_0x26557651, +}; + +#define for_each_enabled_event_group (_peg, _grp) \ + for (_peg = (_grp); _peg < &_grp[ARRAY_SIZE(_grp)]; _peg++) \ + if ((*_peg)->pfg) + +/* Stub for now */ +static bool enable_events (struct event_group *e,struct pmt_feature_group *p)
arch/x86/kernel/cpu/resctrl/intel_aet.c line 82
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +10
-0+{ +return false; +} + +DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, + if (!IS_ERR_OR_NULL(_T)) +intel_pmt_put_feature_group (_T)) + +/* +* Make a request to the INTEL_PMT_TELEMETRY driver for the pmt_feature_group
"for the pmt_feature_group" -> "for a copy of the pmt_feature_group"?
Quoted 63 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +58
-0+* for a specific feature. If there is one, the returned structure has an array +* of telemetry_region structures. Each describes one telemetry aggregator. +* Try to use every telemetry aggregator with a known guid. +*/ +static bool get_pmt_feature (enum pmt_feature_id feature,struct event_group **evgs, +unsigned int num_evg) +{ + struct pmt_feature_group *p __free(intel_pmt_put_feature_group) = NULL; +struct event_group **peg; +bool ret; + + p =intel_pmt_get_regions_by_feature (feature); + +if (IS_ERR_OR_NULL (p)) +return false; + +for (peg = evgs; peg < &evgs[num_evg]; peg++) { + ret =enable_events (*peg, p); +if (ret) { + (*peg)->pfg =no_free_ptr (p); +return true; + } + } + +return false; +} + +/* +* Ask INTEL_PMT_TELEMETRY driver for all the RMID based telemetry groups +* that it supports. +*/ +bool intel_aet_get_events (void ) +{ +bool ret1, ret2; + + ret1 =get_pmt_feature (FEATURE_PER_RMID_ENERGY_TELEM , + known_energy_event_groups, +ARRAY_SIZE (known_energy_event_groups)); + ret2 =get_pmt_feature (FEATURE_PER_RMID_PERF_TELEM , + known_perf_event_groups, +ARRAY_SIZE (known_perf_event_groups)); + +return ret1 || ret2; +} + +void __exit intel_aet_exit(void) +{ +struct event_group **peg; + +for_each_enabled_event_group (peg, known_energy_event_groups) { +intel_pmt_put_feature_group ((*peg)->pfg); + (*peg)->pfg =NULL ; + } +for_each_enabled_event_group (peg, known_perf_event_groups) { +intel_pmt_put_feature_group ((*peg)->pfg); + (*peg)->pfg =NULL ; + } +}arch/x86/Kconfig +0
-0
arch/x86/Kconfig config X86_CPU_RESCTRL · line 530
Quoted 6 lines
arch/x86/Kconfig +3
-0@@ -525,6 +525,19 @@ config X86_CPU_RESCTRL Say N if unsure. +config X86_CPU_RESCTRL_INTEL_AET + bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y + depends on X86_CPU_RESCTRL && CPU_SUP_INTEL
Could you please help me understand why both the "depends on" and "if" syntax is needed? With the above the config menu displays:
│ Depends on: X86_64 [=y] && X86_CPU_RESCTRL [=y] && CPU_SUP_INTEL [=y] │ Visible if: X86_64 [=y] && X86_CPU_RESCTRL [=y] && CPU_SUP_INTEL [=y] && INTEL_PMT_TELEMETRY [=y]=y [=y] && INTEL_TPMI [=y]=y [=y]
According to scripts/kconfig/menu.c the visibility usually matches the dependencies and that seems to be what is intended? The changelog only mentions dependencies so it is not clear why there may be a need for some unique visibility?
Reinette
Tony Luck
maintainerPATCH v9 18/31 x86,fs/resctrl: Fill in details of events for guid 0x26696143 and 0x26557651
In reply to Tony LuckThe Intel Clearwater Forest CPU supports two RMID-based pmt feature groups documented in the xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xml and xml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xml files in the Intel PMT GIT repository here:
The offsets in MMIO space are arranged in groups for each RMID.
E.g the "energy" counters for guid 0x26696143 are arranged like this:
MMIO offset:0x0000 Counter for RMID 0 PMT_EVENT_ENERGY
MMIO offset:0x0008 Counter for RMID 0 PMT_EVENT_ACTIVITY
MMIO offset:0x0010 Counter for RMID 1 PMT_EVENT_ENERGY
MMIO offset:0x0018 Counter for RMID 1 PMT_EVENT_ACTIVITY
...
MMIO offset:0x23F0 Counter for RMID 575 PMT_EVENT_ENERGY
MMIO offset:0x23F8 Counter for RMID 575 PMT_EVENT_ACTIVITYDefine these events in the file system code and add the events to the event_group structures.
PMT_EVENT_ENERGY and PMT_EVENT_ACTIVITY are produced in fixed point format. File system code must output as floating point values.
--- include/linux/resctrl_types.h | 11 +++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 41 +++++++++++++++++++++++++ fs/resctrl/monitor.c | 35 ++++++++++++--------- 3 files changed, 72 insertions(+), 15 deletions(-)
include/linux/resctrl_types.h +11 -0
@@ -47,6 +47,17 @@ enum resctrl_event_id {QOS_L3_MBM_TOTAL_EVENT_ID =0x02 ,QOS_L3_MBM_LOCAL_EVENT_ID =0x03 , +/* Intel Telemetry Events */ +PMT_EVENT_ENERGY , +PMT_EVENT_ACTIVITY , +PMT_EVENT_STALLS_LLC_HIT , +PMT_EVENT_C1_RES , +PMT_EVENT_UNHALTED_CORE_CYCLES , +PMT_EVENT_STALLS_LLC_MISS , +PMT_EVENT_AUTO_C6_RES , +PMT_EVENT_UNHALTED_REF_CYCLES , +PMT_EVENT_UOPS_RETIRED , +/* Must be the last */ QOS_NUM_EVENTS, };
arch/x86/kernel/cpu/resctrl/intel_aet.c +41 -0
73 lines not on this page · raw message
fs/resctrl/monitor.c +20 -15
@@ -878,27 +878,32 @@ static void dom_data_exit(struct rdt_resource *r)mutex_unlock (&rdtgroup_mutex); } +#define MON_EVENT (_eventid, _name, _res, _fp) \ + [_eventid] = { \ + .name = _name, \ + .evtid = _eventid, \ + .rid = _res, \ + .is_floating_point = _fp, \ +} +/* * All available events. Architecture code marks the ones that * are supported by a system using resctrl_enable_mon_event() * to set .enabled. */ struct mon_evt mon_event_all[QOS_NUM_EVENTS ] = { - [QOS_L3_OCCUP_EVENT_ID ] = { - .name ="llc_occupancy" , - .evtid =QOS_L3_OCCUP_EVENT_ID , - .rid =RDT_RESOURCE_L3 , - }, - [QOS_L3_MBM_TOTAL_EVENT_ID ] = { - .name ="mbm_total_bytes" , - .evtid =QOS_L3_MBM_TOTAL_EVENT_ID , - .rid =RDT_RESOURCE_L3 , - }, - [QOS_L3_MBM_LOCAL_EVENT_ID ] = { - .name ="mbm_local_bytes" , - .evtid =QOS_L3_MBM_LOCAL_EVENT_ID , - .rid =RDT_RESOURCE_L3 , - }, +MON_EVENT (QOS_L3_OCCUP_EVENT_ID ,"llc_occupancy" ,RDT_RESOURCE_L3 , false), +MON_EVENT (QOS_L3_MBM_TOTAL_EVENT_ID ,"mbm_total_bytes" ,RDT_RESOURCE_L3 , false), +MON_EVENT (QOS_L3_MBM_LOCAL_EVENT_ID ,"mbm_local_bytes" ,RDT_RESOURCE_L3 , false), +MON_EVENT (PMT_EVENT_ENERGY ,"core_energy" ,RDT_RESOURCE_PERF_PKG , true), +MON_EVENT (PMT_EVENT_ACTIVITY ,"activity" ,RDT_RESOURCE_PERF_PKG , true), +MON_EVENT (PMT_EVENT_STALLS_LLC_HIT ,"stalls_llc_hit" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_C1_RES ,"c1_res" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_UNHALTED_CORE_CYCLES ,"unhalted_core_cycles" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_STALLS_LLC_MISS ,"stalls_llc_miss" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_AUTO_C6_RES ,"c6_res" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_UNHALTED_REF_CYCLES ,"unhalted_ref_cycles" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_UOPS_RETIRED ,"uops_retired" ,RDT_RESOURCE_PERF_PKG , false), };void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu,unsigned int binary_bits)
Signature · 1 line
2.50.1
Re: [PATCH v9 18/31] x86,fs/resctrl: Fill in details of events for guid 0x26696143 and 0x26557651
Quoted 90 lines · Tony Luck
The Intel Clearwater Forest CPU supports two RMID-based pmt feature groups documented in the
xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xmlandxml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xmlfiles in the Intel PMT GIT repository here:The offsets in MMIO space are arranged in groups for each RMID.
E.g the "energy" counters for guid
0x26696143are arranged like this:MMIO offset:0x0000 Counter for RMID 0 PMT_EVENT_ENERGY MMIO offset:0x0008 Counter for RMID 0 PMT_EVENT_ACTIVITY MMIO offset:0x0010 Counter for RMID 1 PMT_EVENT_ENERGY MMIO offset:0x0018 Counter for RMID 1 PMT_EVENT_ACTIVITY ... MMIO offset:0x23F0 Counter for RMID 575 PMT_EVENT_ENERGY MMIO offset:0x23F8 Counter for RMID 575 PMT_EVENT_ACTIVITYDefine these events in the file system code and add the events to the
event_groupstructures.
PMT_EVENT_ENERGYandPMT_EVENT_ACTIVITYare produced in fixed point format. File system code must output as floating point values.Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl_types.h | 11 +++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 41 +++++++++++++++++++++++++ fs/resctrl/monitor.c | 35 ++++++++++++--------- 3 files changed, 72 insertions(+), 15 deletions(-)include/linux/resctrl_types.h +11
-0@@ -47,6 +47,17 @@ enum resctrl_event_id {QOS_L3_MBM_TOTAL_EVENT_ID =0x02 ,QOS_L3_MBM_LOCAL_EVENT_ID =0x03 , +/* Intel Telemetry Events */ +PMT_EVENT_ENERGY , +PMT_EVENT_ACTIVITY , +PMT_EVENT_STALLS_LLC_HIT , +PMT_EVENT_C1_RES , +PMT_EVENT_UNHALTED_CORE_CYCLES , +PMT_EVENT_STALLS_LLC_MISS , +PMT_EVENT_AUTO_C6_RES , +PMT_EVENT_UNHALTED_REF_CYCLES , +PMT_EVENT_UOPS_RETIRED , +/* Must be the last */ QOS_NUM_EVENTS, };arch/x86/kernel/cpu/resctrl/intel_aet.c +18
-0@@ -18,12 +18,30 @@#include "internal.h" +/** +* struct pmt_event - Telemetry event. +* @id: Resctrl event id. +* @idx: Counter index within each per-RMID block of counters. +* @bin_bits: Zero for integer valued events, else number bits in fraction +* part of fixed-point. +*/ +struct pmt_event { +enum resctrl_event_id id; +unsigned int idx; +unsigned int bin_bits; +}; + +#define EVT (_id, _idx, _bits) { .id = _id, .idx = _idx, .bin_bits = _bits } +/** * struct event_group - All information about a group of telemetry events. * @pfg: Points to the aggregated telemetry space information * within the INTEL_PMT_TELEMETRY driver that contains data for all * telemetry regions. * @guid: Unique number per XML description file. +* @mmio_size: Number of bytes of MMIO registers for this group. +* @num_events: Number of events in this group. +* @evts: Array of event descriptors. */ struct event_group {/* Data fields for additional structures to manage this group. */
arch/x86/kernel/cpu/resctrl/intel_aet.c struct event_group { · line 52
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +1
-0@@ -31,14 +49,26 @@ struct event_group {/* Remaining fields initialized from XML file. */ u32 guid; +size_t mmio_size;
+ linux/types.h, although it should probably have been added in patch 17 already.
arch/x86/kernel/cpu/resctrl/intel_aet.c struct event_group { · line 54
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +2
-0+unsigned int num_events; + struct pmt_event evts[] __counted_by(num_events);
#include for __counted_by()?
Quoted 91 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +20
-0}; +#define XML_MMIO_SIZE (num_rmids, num_events, num_extra_status) \ + (((num_rmids) * (num_events) + (num_extra_status)) * sizeof(u64)) +/* * Link: https://github.com/intel/Intel-PMT * File: xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xml */ static struct event_group energy_0x26696143 = { .guid =0x26696143 , + .mmio_size =XML_MMIO_SIZE (576 ,2 ,3 ), + .num_events =2 , + .evts = { +EVT (PMT_EVENT_ENERGY ,0 ,18 ), +EVT (PMT_EVENT_ACTIVITY ,1 ,18 ), + } };/* @@ -47,6 +77,17 @@ static struct event_group energy_0x26696143 = {*/ static struct event_group perf_0x26557651 = { .guid =0x26557651 , + .mmio_size =XML_MMIO_SIZE (576 ,7 ,3 ), + .num_events =7 , + .evts = { +EVT (PMT_EVENT_STALLS_LLC_HIT ,0 ,0 ), +EVT (PMT_EVENT_C1_RES ,1 ,0 ), +EVT (PMT_EVENT_UNHALTED_CORE_CYCLES ,2 ,0 ), +EVT (PMT_EVENT_STALLS_LLC_MISS ,3 ,0 ), +EVT (PMT_EVENT_AUTO_C6_RES ,4 ,0 ), +EVT (PMT_EVENT_UNHALTED_REF_CYCLES ,5 ,0 ), +EVT (PMT_EVENT_UOPS_RETIRED ,6 ,0 ), + } };static struct event_group *known_energy_event_groups[] = {fs/resctrl/monitor.c +20
-15@@ -878,27 +878,32 @@ static void dom_data_exit(struct rdt_resource *r)mutex_unlock (&rdtgroup_mutex); } +#define MON_EVENT (_eventid, _name, _res, _fp) \ + [_eventid] = { \ + .name = _name, \ + .evtid = _eventid, \ + .rid = _res, \ + .is_floating_point = _fp, \ +} +/* * All available events. Architecture code marks the ones that * are supported by a system using resctrl_enable_mon_event() * to set .enabled. */ struct mon_evt mon_event_all[QOS_NUM_EVENTS ] = { - [QOS_L3_OCCUP_EVENT_ID ] = { - .name ="llc_occupancy" , - .evtid =QOS_L3_OCCUP_EVENT_ID , - .rid =RDT_RESOURCE_L3 , - }, - [QOS_L3_MBM_TOTAL_EVENT_ID ] = { - .name ="mbm_total_bytes" , - .evtid =QOS_L3_MBM_TOTAL_EVENT_ID , - .rid =RDT_RESOURCE_L3 , - }, - [QOS_L3_MBM_LOCAL_EVENT_ID ] = { - .name ="mbm_local_bytes" , - .evtid =QOS_L3_MBM_LOCAL_EVENT_ID , - .rid =RDT_RESOURCE_L3 , - }, +MON_EVENT (QOS_L3_OCCUP_EVENT_ID ,"llc_occupancy" ,RDT_RESOURCE_L3 , false), +MON_EVENT (QOS_L3_MBM_TOTAL_EVENT_ID ,"mbm_total_bytes" ,RDT_RESOURCE_L3 , false), +MON_EVENT (QOS_L3_MBM_LOCAL_EVENT_ID ,"mbm_local_bytes" ,RDT_RESOURCE_L3 , false), +MON_EVENT (PMT_EVENT_ENERGY ,"core_energy" ,RDT_RESOURCE_PERF_PKG , true), +MON_EVENT (PMT_EVENT_ACTIVITY ,"activity" ,RDT_RESOURCE_PERF_PKG , true), +MON_EVENT (PMT_EVENT_STALLS_LLC_HIT ,"stalls_llc_hit" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_C1_RES ,"c1_res" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_UNHALTED_CORE_CYCLES ,"unhalted_core_cycles" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_STALLS_LLC_MISS ,"stalls_llc_miss" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_AUTO_C6_RES ,"c6_res" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_UNHALTED_REF_CYCLES ,"unhalted_ref_cycles" ,RDT_RESOURCE_PERF_PKG , false), +MON_EVENT (PMT_EVENT_UOPS_RETIRED ,"uops_retired" ,RDT_RESOURCE_PERF_PKG , false), };void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu,unsigned int binary_bits)
Signature · 1 line
i.
Reinette Chatre
maintainerRe: [PATCH v9 18/31] x86,fs/resctrl: Fill in details of events for guid 0x26696143 and 0x26557651
In reply to Tony LuckHi Tony,
Quoted 1 line · Tony Luck
The Intel Clearwater Forest CPU supports two RMID-based pmt feature
"pmt" -> "PMT"
Quoted 3 lines
groups documented in the
xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xmlandxml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xmlfiles in the Intel PMT GIT repository here:
"GIT repository here:" -> "GIT repository [1]."
Quoted 2 lines
Move to end of tags and add reference:
Link: https://github.com/intel/Intel-PMT # [1]
Quoted 2 lines
The offsets in MMIO space are arranged in groups for each RMID.
"The offsets" -> "The event counter offsets"?
Quoted 10 lines
E.g the "energy" counters for guid
0x26696143are arranged like this:MMIO offset:0x0000 Counter for RMID 0 PMT_EVENT_ENERGY MMIO offset:0x0008 Counter for RMID 0 PMT_EVENT_ACTIVITY MMIO offset:0x0010 Counter for RMID 1 PMT_EVENT_ENERGY MMIO offset:0x0018 Counter for RMID 1 PMT_EVENT_ACTIVITY ... MMIO offset:0x23F0 Counter for RMID 575 PMT_EVENT_ENERGY MMIO offset:0x23F8 Counter for RMID 575 PMT_EVENT_ACTIVITY
To help understand the added XML_MMIO_SIZE() macro I think it will be helpful to mention the status registers and add them in the above depiction.
Quoted 9 lines
Define these events in the file system code and add the events to the
event_groupstructures.
PMT_EVENT_ENERGYandPMT_EVENT_ACTIVITYare produced in fixed point format. File system code must output as floating point values.Signed-off-by Tony Luck <[email protected]>---
Code looks good to me.
Reinette
Tony Luck
maintainerPATCH v9 19/31 x86,fs/resctrl: Add architectural event pointer
In reply to Tony LuckThe resctrl file system layer passes the domain, RMID, and event id to resctrl_arch_rmid_read() to fetch an event counter.
Fetching a telemetry event counter requires additional information that is private to the architecture, for example, the offset into MMIO space from where counter should be read.
Add mon_evt::arch_priv void pointer. Architecture code can initialize this when marking each event enabled.
File system code passes this pointer to resctrl_arch_rmid_read().
--- include/linux/resctrl.h | 7 +++++-- fs/resctrl/internal.h | 4 ++++ arch/x86/kernel/cpu/resctrl/core.c | 6 +++--- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- fs/resctrl/monitor.c | 14 ++++++++++---- 5 files changed, 23 insertions(+), 10 deletions(-)
include/linux/resctrl.h +5 -2
@@ -382,7 +382,7 @@ u32 resctrl_arch_system_num_rmid_idx(void);int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid);void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu, -unsigned int binary_bits); +unsigned int binary_bits,void *arch_priv);bool resctrl_is_mon_event_enabled (enum resctrl_event_id eventid);
@@ -477,6 +477,9 @@ void resctrl_arch_pre_mount(void);* only. * @rmid: rmid of the counter to read. * @eventid: eventid to read, e.g. L3 occupancy. +* @arch_priv: Architecture private data for this event. +* The @arch_priv provided by the architecture via +* resctrl_enable_mon_event(). * @val: result of the counter read in bytes. * @arch_mon_ctx: An architecture specific value from * resctrl_arch_mon_ctx_alloc(), for MPAM this identifies
@@ -494,7 +497,7 @@ void resctrl_arch_pre_mount(void);*/ int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain_hdr *hdr,u32 closid,u32 rmid,enum resctrl_event_id eventid, -u64 *val,void *arch_mon_ctx); +void *arch_priv,u64 *val,void *arch_mon_ctx);/** * resctrl_arch_rmid_read_context_check() - warn about invalid contexts
fs/resctrl/internal.h +4 -0
@@ -62,6 +62,9 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)* @binary_bits: number of fixed-point binary bits from architecture, * only valid if @is_floating_point is true * @enabled: true if the event is enabled +* @arch_priv: Architecture private data for this event. +* The @arch_priv provided by the architecture via +* resctrl_enable_mon_event(). */ struct mon_evt {enum resctrl_event_id evtid;
@@ -72,6 +75,7 @@ struct mon_evt {bool is_floating_point;unsigned int binary_bits;bool enabled; +void *arch_priv; };extern struct mon_evt mon_event_all[QOS_NUM_EVENTS ];
arch/x86/kernel/cpu/resctrl/core.c +3 -3
@@ -910,15 +910,15 @@ static __init bool get_rdt_mon_resources(void)bool ret = false;if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) { -resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID , false,0 ); +resctrl_enable_mon_event (QOS_L3_OCCUP_EVENT_ID , false,0 ,NULL ); ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_TOTAL )) { -resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID , false,0 ); +resctrl_enable_mon_event (QOS_L3_MBM_TOTAL_EVENT_ID , false,0 ,NULL ); ret = true; }if (rdt_cpu_has (X86_FEATURE_CQM_MBM_LOCAL )) { -resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID , false,0 ); +resctrl_enable_mon_event (QOS_L3_MBM_LOCAL_EVENT_ID , false,0 ,NULL ); ret = true; }
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -219,7 +219,7 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain_hdr *hdr,u32 unused,u32 rmid,enum resctrl_event_id eventid, -u64 *val,void *ignored) +void *arch_priv,u64 *val,void *ignored) {int cpu =cpumask_any (&hdr->cpu_mask);struct rdt_hw_l3_mon_domain *hw_dom;
fs/resctrl/monitor.c +10 -4
@@ -137,9 +137,11 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)struct rmid_entry *entry;u32 idx, cur_idx =1 ;void *arch_mon_ctx; +void *arch_priv;bool rmid_dirty;u64 val =0 ; + arch_priv = mon_event_all[QOS_L3_OCCUP_EVENT_ID ].arch_priv; arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r,QOS_L3_OCCUP_EVENT_ID );if (IS_ERR (arch_mon_ctx)) { pr_warn_ratelimited("Failed to allocate monitor context: %ld",
@@ -160,7 +162,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free) entry =__rmid_entry (idx);if (resctrl_arch_rmid_read (r, &d->hdr, entry->closid, entry->rmid, -QOS_L3_OCCUP_EVENT_ID , &val, +QOS_L3_OCCUP_EVENT_ID , arch_priv, &val, arch_mon_ctx)) { rmid_dirty = true; }else {
@@ -411,7 +413,8 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)if (rr->hdr) {/* Single domain. */ rr->err =resctrl_arch_rmid_read (rr->r, rr->hdr, closid, rmid, - rr->evt->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, rr->evt->arch_priv, + &tval, rr->arch_mon_ctx);if (rr->err)return rr->err;
@@ -434,7 +437,8 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)if (d->ci_id != rr->ci_id)continue ; err =resctrl_arch_rmid_read (rr->r, &d->hdr, closid, rmid, - rr->evt->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, rr->evt->arch_priv, + &tval, rr->arch_mon_ctx);if (!err) { rr->val += tval; ret =0 ;
@@ -906,7 +910,8 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] = { MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", RDT_RESOURCE_PERF_PKG, false), }; -void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu,unsigned int binary_bits) +void resctrl_enable_mon_event (enum resctrl_event_id eventid,bool any_cpu, +unsigned int binary_bits,void *arch_priv) {if (WARN_ON_ONCE (eventid <QOS_FIRST_EVENT || eventid >=QOS_NUM_EVENTS || binary_bits >MAX_BINARY_BITS ))
@@ -922,6 +927,7 @@ void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, unsig mon_event_all[eventid].any_cpu = any_cpu; mon_event_all[eventid].binary_bits = binary_bits; + mon_event_all[eventid].arch_priv = arch_priv; mon_event_all[eventid].enabled = true; }
Signature · 1 line
2.50.1
Re: [PATCH v9 19/31] x86,fs/resctrl: Add architectural event pointer
Hi Tony,
Quoted 7 lines · Tony Luck
The resctrl file system layer passes the domain, RMID, and event id to
resctrl_arch_rmid_read()to fetch an event counter.Fetching a telemetry event counter requires additional information that is private to the architecture, for example, the offset into MMIO space from where counter should be read.
Quoted 8 lines
Add
mon_evt::arch_privvoid pointer. Architecture code can initialize this when marking each event enabled.File system code passes this pointer to
resctrl_arch_rmid_read().Suggested-by Reinette Chatre <[email protected]>Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v9 20/31 x86/resctrl: Find and enable usable telemetry events
In reply to Tony LuckThe INTEL_PMT driver provides telemetry region structures of the types requested by resctrl.
Scan these structures to discover which pass sanity checks:
1) They have guid known to resctrl.
2) They have a valid package ID.
3) The enumerated size of the MMIO region matches the expected value from the XML description file.
4) At least one region passes the above checks.
Enable the active events in resctrl filesystem to make them available to user space. Pass a pointer to the pmt_event structure of the event within the struct event_group that resctrl stores in mon_evt::arch_priv. resctrl passes this pointer back when asking to read the event data which enables the data to be found in MMIO.
--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 36 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/intel_aet.c +34 -2
@@ -102,12 +102,44 @@ static struct event_group *known_perf_event_groups[] = {for (_peg = _grp; _peg < &_grp[ARRAY_SIZE (_grp)]; _peg++) \if ((*_peg)->pfg) -/* Stub for now */ -static bool enable_events(struct event_group *e, struct pmt_feature_group *p) +static bool skip_this_region(struct telemetry_region *tr, struct event_group *e) { +if (tr->guid != e->guid) +return true; +if (tr->plat_info.package_id >=topology_max_packages ()) { +pr_warn_once ("Bad package %d in guid 0x%x\n" , tr->plat_info.package_id, + tr->guid); +return true; + } +if (tr->size != e->mmio_size) { +pr_warn_once ("MMIO space wrong size (%zu bytes) for guid 0x%x. Expected %zu bytes.\n" , + tr->size, e->guid, e->mmio_size); +return true; + } +return false; } +static bool enable_events (struct event_group *e,struct pmt_feature_group *p) +{ +bool usable_events = false; + +for (int i =0 ; i < p->count; i++) { +if (skip_this_region (&p->regions[i], e)) +continue ; + usable_events = true; + } + +if (!usable_events) +return false; + +for (int j =0 ; j < e->num_events; j++) +resctrl_enable_mon_event (e->evts[j].id, true, + e->evts[j].bin_bits, &e->evts[j]); + +return true; +} + DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, if (!IS_ERR_OR_NULL(_T))intel_pmt_put_feature_group (_T))
Signature · 1 line
2.50.1
Re: [PATCH v9 20/31] x86/resctrl: Find and enable usable telemetry events
Quoted 27 lines · Tony Luck
The
INTEL_PMTdriver provides telemetry region structures of the types requested by resctrl.Scan these structures to discover which pass sanity checks:
1) They have guid known to resctrl.
2) They have a valid package ID.
3) The enumerated size of the MMIO region matches the expected value from the XML description file.
4) At least one region passes the above checks.Enable the active events in resctrl filesystem to make them available to user space. Pass a pointer to the
pmt_eventstructure of the event within the structevent_groupthat resctrl stores inmon_evt::arch_priv. resctrl passes this pointer back when asking to read the event data which enables the data to be found in MMIO.Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 36 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/intel_aet.c +0
-0
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 105
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +1
-2@@ -102,12 +102,44 @@ static struct event_group *known_perf_event_groups[] = {for (_peg = _grp; _peg < &_grp[ARRAY_SIZE (_grp)]; _peg++) \if ((*_peg)->pfg) -/* Stub for now */ -static bool enable_events(struct event_group *e, struct pmt_feature_group *p) +static bool skip_this_region(struct telemetry_region *tr, struct event_group *e)
skip_telem_region? It would get rid of vague "this" in the name.
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 116
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +10
-0{ +if (tr->guid != e->guid) +return true; +if (tr->plat_info.package_id >=topology_max_packages ()) { +pr_warn_once ("Bad package %d in guid 0x%x\n" , tr->plat_info.package_id, + tr->guid); +return true; + } +if (tr->size != e->mmio_size) { +pr_warn_once ("MMIO space wrong size (%zu bytes) for guid 0x%x. Expected %zu bytes.\n" , + tr->size, e->guid, e->mmio_size);
Are _once warranted in these two cases? Do we call this function for the same guid and region combination more than once?
+ include for pr_*().
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +3
-0+return true; + } +return false;
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 130
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +8
-0} +static bool enable_events (struct event_group *e,struct pmt_feature_group *p) +{ +bool usable_events = false; + +for (int i =0 ; i < p->count; i++) { +if (skip_this_region (&p->regions[i], e)) +continue ; + usable_events = true;
Do you need to loop beyond asserting this?
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +12
-0+ } + +if (!usable_events) +return false; + +for (int j =0 ; j < e->num_events; j++) +resctrl_enable_mon_event (e->evts[j].id, true, + e->evts[j].bin_bits, &e->evts[j]); + +return true; +} + DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, if (!IS_ERR_OR_NULL(_T))intel_pmt_put_feature_group (_T))
Signature · 1 line
i.
Luck, Tony
maintainerRe: [PATCH v9 20/31] x86/resctrl: Find and enable usable telemetry events
Quoted 32 lines · Ilpo Järvinen
Quoted 30 lines · Tony Luck
The
INTEL_PMTdriver provides telemetry region structures of the types requested by resctrl.Scan these structures to discover which pass sanity checks:
1) They have guid known to resctrl.
2) They have a valid package ID.
3) The enumerated size of the MMIO region matches the expected value from the XML description file.
4) At least one region passes the above checks.Enable the active events in resctrl filesystem to make them available to user space. Pass a pointer to the
pmt_eventstructure of the event within the structevent_groupthat resctrl stores inmon_evt::arch_priv. resctrl passes this pointer back when asking to read the event data which enables the data to be found in MMIO.Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 36 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/intel_aet.c +0
-0@@ -102,12 +102,44 @@ static struct event_group *known_perf_event_groups[] = {for (_peg = _grp; _peg < &_grp[ARRAY_SIZE (_grp)]; _peg++) \if ((*_peg)->pfg)
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 105
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +1
-2-/* Stub for now */ -static bool enable_events (struct event_group *e,struct pmt_feature_group *p) +static bool skip_this_region (struct telemetry_region *tr,struct event_group *e)
skip_telem_region? It would get rid of vague "this" in the name.
Yes. Much better name.
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 116
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +10
-0{ +if (tr->guid != e->guid) +return true; +if (tr->plat_info.package_id >=topology_max_packages ()) { +pr_warn_once ("Bad package %d in guid 0x%x\n" , tr->plat_info.package_id, + tr->guid); +return true; + } +if (tr->size != e->mmio_size) { +pr_warn_once ("MMIO space wrong size (%zu bytes) for guid 0x%x. Expected %zu bytes.\n" , + tr->size, e->guid, e->mmio_size);Are
_oncewarranted in these two cases? Do we call this function for the same guid and region combination more than once?
I think they are "can't happen". Dropping the "_once" would provide a more complete picture if they actually do happen.
Quoted 9 lines
+ include for pr_*().
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +3
-0+return true; + } +return false; }
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 130
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +8
-0+static bool enable_events (struct event_group *e,struct pmt_feature_group *p) +{ +bool usable_events = false; + +for (int i =0 ; i < p->count; i++) { +if (skip_this_region (&p->regions[i], e)) +continue ; + usable_events = true;Do you need to loop beyond asserting this?
Also don't expect a mix of usable/unusable regions. But if it does happen, then check all the regions. So I'm leaving this as-is.
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +8
-0+ } + +if (!usable_events) +return false; + +for (int j =0 ; j < e->num_events; j++) +resctrl_enable_mon_event (e->evts[j].id, true, + e->evts[j].bin_bits, &e->evts[j]);
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 145
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +4
-0+ +return true; +} + DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, if (!IS_ERR_OR_NULL(_T))intel_pmt_put_feature_group (_T))
Updated patch with changes applied below. Also pushed togit://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git rdt-aet-v10-wip
-Tony
From 19f90ec0c526791be589fe3ff4797536f7e9e9c9 Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Mon, 25 Aug 2025 10:47:06 -0700
Subject: [PATCH 20/31] x86/resctrl: Find and enable usable telemetry events
The INTEL_PMT driver provides telemetry region structures of the types requested by resctrl.
Scan these structures to discover which pass sanity checks:
1) They have guid known to resctrl.
2) They have a valid package ID.
3) The enumerated size of the MMIO region matches the expected value from the XML description file.
4) At least one region passes the above checks.
Enable the active events in resctrl filesystem to make them available to user space. Pass a pointer to the pmt_event structure of the event within the struct event_group that resctrl stores in mon_evt::arch_priv. resctrl passes this pointer back when asking to read the event data which enables the data to be found in MMIO.
--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/intel_aet.c +36 -2
@@ -20,9 +20,11 @@#include <linux/intel_pmt_features.h> #include <linux/intel_vsec.h> #include <linux/overflow.h> +#include <linux/printk.h> #include <linux/resctrl.h> #include <linux/resctrl_types.h> #include <linux/stddef.h> +#include <linux/topology.h> #include <linux/types.h> #include "internal.h"
@@ -111,12 +113,44 @@ static struct event_group *known_perf_event_groups[] = {for (_peg = (_grp); _peg < &_grp[ARRAY_SIZE (_grp)]; _peg++) \if ((*_peg)->pfg) -/* Stub for now */ -static bool enable_events(struct event_group *e, struct pmt_feature_group *p) +static bool skip_telem_region(struct telemetry_region *tr, struct event_group *e) { +if (tr->guid != e->guid) +return true; +if (tr->plat_info.package_id >=topology_max_packages ()) { +pr_warn ("Bad package %d in guid 0x%x\n" , tr->plat_info.package_id, + tr->guid); +return true; + } +if (tr->size != e->mmio_size) { +pr_warn ("MMIO space wrong size (%zu bytes) for guid 0x%x. Expected %zu bytes.\n" , + tr->size, e->guid, e->mmio_size); +return true; + } +return false; } +static bool enable_events (struct event_group *e,struct pmt_feature_group *p) +{ +bool usable_events = false; + +for (int i =0 ; i < p->count; i++) { +if (skip_telem_region (&p->regions[i], e)) +continue ; + usable_events = true; + } + +if (!usable_events) +return false; + +for (int j =0 ; j < e->num_events; j++) +resctrl_enable_mon_event (e->evts[j].id, true, + e->evts[j].bin_bits, &e->evts[j]); + +return true; +} + DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, if (!IS_ERR_OR_NULL(_T))intel_pmt_put_feature_group (_T))
Signature · 1 line
2.51.0
Reinette Chatre
maintainerRe: [PATCH v9 20/31] x86/resctrl: Find and enable usable telemetry events
Hi Tony,
Quoted 4 lines · Tony
Updated patch with changes applied below. Also pushed to
git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.gitrdt-aet-v10-wip
Quoted 8 lines
-Tony
From
19f90ec0c526791be589fe3ff4797536f7e9e9c9Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Mon, 25 Aug 2025 10:47:06 -0700
Subject: [PATCH 20/31] x86/resctrl: Find and enable usable telemetry eventsThe
INTEL_PMTdriver provides telemetry region structures of the
"INTEL_PMT" -> "INTEL_PMT_TELEMETRY"
Quoted 9 lines
types requested by resctrl.
Scan these structures to discover which pass sanity checks:
1) They have guid known to resctrl.
2) They have a valid package ID.
3) The enumerated size of the MMIO region matches the expected value from the XML description file.
4) At least one region passes the above checks.
Above describes how resctrl determines "valid" telemetry regions.
Quoted 2 lines
Enable the active events in resctrl filesystem to make them available to
This jumps from "valid telemetry regions" to "active events" without a connection between the two.
Quoted 28 lines
user space. Pass a pointer to the
pmt_eventstructure of the event within the structevent_groupthat resctrl stores inmon_evt::arch_priv. resctrl passes this pointer back when asking to read the event data which enables the data to be found in MMIO.Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/intel_aet.c +2
-0@@ -20,9 +20,11 @@#include <linux/intel_pmt_features.h> #include <linux/intel_vsec.h> #include <linux/overflow.h> +#include <linux/printk.h> #include <linux/resctrl.h> #include <linux/resctrl_types.h> #include <linux/stddef.h> +#include <linux/topology.h> #include <linux/types.h> #include "internal.h" @@ -111,12 +113,44 @@ static struct event_group *known_perf_event_groups[] = {for (_peg = (_grp); _peg < &_grp[ARRAY_SIZE (_grp)]; _peg++) \
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 121
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +5
-2if ((*_peg)->pfg) -/* Stub for now */ -static bool enable_events(struct event_group *e, struct pmt_feature_group *p) +static bool skip_telem_region(struct telemetry_region *tr, struct event_group *e) { +if (tr->guid != e->guid) +return true; +if (tr->plat_info.package_id >=topology_max_packages ()) { + pr_warn("Bad package %d in guid 0x%x\n", tr->plat_info.package_id,
%d -> %u?
arch/x86/kernel/cpu/resctrl/intel_aet.c static struct event_group *known_perf_event_groups[] = { · line 133
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +9
-0+ tr->guid); +return true; + } +if (tr->size != e->mmio_size) { +pr_warn ("MMIO space wrong size (%zu bytes) for guid 0x%x. Expected %zu bytes.\n" , + tr->size, e->guid, e->mmio_size); +return true; + } +return false; }
Reinette
Tony Luck
maintainerPATCH v9 21/31 x86/resctrl: Read telemetry events
In reply to Tony LuckTelemetry events are enumerated by the INTEL_PMT_TELEMETRY subsystem. resctrl enables events with resctrl_enable_mon_event() passing a pointer to the pmt_event structure for the event within the struct event_group. The file system stores it in mon_evt::arch_priv.
Clear the address field of regions that did not pass the checks in skip_this_region() so they will not be used by intel_aet_read_event(). This is safe to do because intel_pmt_get_regions_by_feature() allocates a new pmt_feature_group structure to return to each caller and only makes use of the pmt_feature_group::kref field when intel_pmt_put_feature_group() returns the structure.
Add a check to resctrl_arch_rmid_read() for resource id RDT_RESOURCE_PERF_PKG and directly call intel_aet_read_event() passing the enum resctrl_event_id for the event and the arch_priv pointer that was supplied when the event was enabled.
There may be multiple aggregators tracking each package, so scan all of them and add up all counters. Aggregators may return an invalid data indication if they have received no records for a given RMID. Return success to the user if one or more aggregators provide valid data.
Resctrl now uses readq() so depends on X86_64. Update Kconfig.
--- arch/x86/kernel/cpu/resctrl/internal.h | 7 ++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 53 ++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 63 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +7 -0
@@ -172,9 +172,16 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r);#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void); +int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val);#else static inline bool intel_aet_get_events (void ) {return false; } static inline void __exit intel_aet_exit(void) { } +static inline int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val) +{ +return -EINVAL ; +}#endif #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/intel_aet.c +52 -1
69 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/monitor.c +3 -0
@@ -232,6 +232,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,resctrl_arch_rmid_read_context_check (); +if (r->rid ==RDT_RESOURCE_PERF_PKG ) +return intel_aet_read_event (hdr->id, rmid, eventid, arch_priv, val); +if (r->rid !=RDT_RESOURCE_L3 )return -EINVAL ;
arch/x86/Kconfig +1 -1
@@ -527,7 +527,7 @@ config X86_CPU_RESCTRL config X86_CPU_RESCTRL_INTEL_AET bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y - depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL help Enable per-RMID telemetry events in resctrl.
Signature · 1 line
2.50.1
Re: [PATCH v9 21/31] x86/resctrl: Read telemetry events
Quoted 66 lines · Tony Luck
Telemetry events are enumerated by the
INTEL_PMT_TELEMETRYsubsystem. resctrl enables events withresctrl_enable_mon_event()passing a pointer to thepmt_eventstructure for the event within the structevent_group. The file system stores it inmon_evt::arch_priv.Clear the address field of regions that did not pass the checks in
skip_this_region()so they will not be used byintel_aet_read_event(). This is safe to do becauseintel_pmt_get_regions_by_feature()allocates a newpmt_feature_groupstructure to return to each caller and only makes use of thepmt_feature_group::kreffield whenintel_pmt_put_feature_group()returns the structure.Add a check to
resctrl_arch_rmid_read()for resource idRDT_RESOURCE_PERF_PKGand directly callintel_aet_read_event()passing the enumresctrl_event_idfor the event and thearch_privpointer that was supplied when the event was enabled.There may be multiple aggregators tracking each package, so scan all of them and add up all counters. Aggregators may return an invalid data indication if they have received no records for a given RMID. Return success to the user if one or more aggregators provide valid data.
Resctrl now uses
readq()so depends onX86_64. UpdateKconfig.Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 7 ++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 53 ++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 63 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/internal.h +7
-0@@ -172,9 +172,16 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r);#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void); +int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val);#else static inline bool intel_aet_get_events (void ) {return false; } static inline void __exit intel_aet_exit(void) { } +static inline int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val) +{ +return -EINVAL ; +}#endif #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/intel_aet.c +1
-0@@ -14,6 +14,7 @@#include <linux/cleanup.h> #include <linux/cpu.h> #include <linux/intel_vsec.h> +#include <linux/io.h> #include <linux/resctrl.h> #include "internal.h"
arch/x86/kernel/cpu/resctrl/intel_aet.c static bool enable_events(struct event_group *e, struct pmt_feature_group *p) · line 134
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +6
-1@@ -125,8 +126,14 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)bool usable_events = false;for (int i =0 ; i < p->count; i++) { -if (skip_this_region (&p->regions[i], e)) +if (skip_this_region (&p->regions[i], e)) { +/* +* Clear addr so that intel_aet_read_event() will +* skip this region. +*/ + p->regions[i].addr =NULL ;
As this is at least semi-hacky, I suggest you move it into own function and add a bit longer comment to the function (along the lines what the changelog also states why it works).
arch/x86/kernel/cpu/resctrl/intel_aet.c void __exit intel_aet_exit(void) · line 216
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +4
-0continue ; + } usable_events = true; }@@ -204,3 +211,47 @@ void __exit intel_aet_exit(void) (*peg)->pfg =NULL ; } } + +#define DATA_VALID BIT_ULL(63) +#define DATA_BITS GENMASK_ULL(62, 0)
+ linux/bits.h
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +9
-0+ +/* +* Read counter for an event on a domain (summing all aggregators +* on the domain). If an aggregator hasn't received any data for a +* specific RMID, the MMIO read indicates that data is not valid. +* Return success if at least one aggregator has valid data. +*/ +int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id eventid, +void *arch_priv,u64 *val)
arch/x86/kernel/cpu/resctrl/intel_aet.c void __exit intel_aet_exit(void) · line 235
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +10
-0+{ +struct pmt_event *pevt = arch_priv; +struct event_group *e; +bool valid = false; +u64 evtcount; +void *pevt0; +int idx; + + pevt0 = pevt - pevt->idx; + e = container_of(pevt0, struct event_group, evts);
+ linux/container_of.h
Quoted 50 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +22
-0+ idx = rmid * e->num_events; + idx += pevt->idx; + +if (idx *sizeof (u64) +sizeof (u64) > e->mmio_size) { +pr_warn_once ("MMIO index %d out of range\n" , idx); +return -EIO ; + } + +for (int i =0 ; i < e->pfg->count; i++) { +if (!e->pfg->regions[i].addr) +continue ; +if (e->pfg->regions[i].plat_info.package_id != domid) +continue ; + evtcount =readq (e->pfg->regions[i].addr + idx *sizeof (u64)); +if (!(evtcount &DATA_VALID )) +continue ; + *val += evtcount &DATA_BITS ; + valid = true; + } + +return valid ?0 : -EINVAL ; +}arch/x86/kernel/cpu/resctrl/monitor.c +3
-0@@ -232,6 +232,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,resctrl_arch_rmid_read_context_check (); +if (r->rid ==RDT_RESOURCE_PERF_PKG ) +return intel_aet_read_event (hdr->id, rmid, eventid, arch_priv, val); +if (r->rid !=RDT_RESOURCE_L3 )return -EINVAL ;arch/x86/Kconfig +1
-1@@ -527,7 +527,7 @@ config X86_CPU_RESCTRL config X86_CPU_RESCTRL_INTEL_AET bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y - depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL help Enable per-RMID telemetry events in resctrl.
Signature · 1 line
i.
Luck, Tony
maintainerRe: [PATCH v9 21/31] x86/resctrl: Read telemetry events
Quoted 15 lines · Ilpo Järvinen
Review static bool enable_events(struct event_group *e, struct pmt_feature_group *p) · line 134
Quoted 11 lines
(quoted diff) +6
-1@@ -125,8 +126,14 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p) bool usable_events = false; for (int i = 0; i < p->count; i++) { - if (skip_this_region(&p->regions[i], e)) + if (skip_this_region(&p->regions[i], e)) { + /* + * Clear addr so that intel_aet_read_event() will + * skip this region. + */ + p->regions[i].addr = NULL;As this is at least semi-hacky, I suggest you move it into own function and add a bit longer comment to the function (along the lines what the changelog also states why it works).
Agreed. See new mark_telem_region_unusable() in updated patch below. Also pushed togit://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git rdt-aet-v10-wip
-Tony
P.S. In addition to all the extra #include files you suggested, I found a few others missing. So those are added as needed in the series.
From 163824a2e10de9f63e20f0bc9f86b8c14f58bfcb Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Mon, 25 Aug 2025 10:47:06 -0700
Subject: [PATCH 21/31] x86/resctrl: Read telemetry events
Telemetry events are enumerated by the INTEL_PMT_TELEMETRY subsystem. resctrl enables events with resctrl_enable_mon_event() passing a pointer to the pmt_event structure for the event within the struct event_group. The file system stores it in mon_evt::arch_priv.
Mark regions that did not pass the checks in skip_telemetry_region() so they will not be used by intel_aet_read_event().
Add a check to resctrl_arch_rmid_read() for resource id RDT_RESOURCE_PERF_PKG and directly call intel_aet_read_event() passing the enum resctrl_event_id for the event and the arch_priv pointer that was supplied when the event was enabled.
There may be multiple aggregators tracking each package, so scan all of them and add up all counters. Aggregators may return an invalid data indication if they have received no records for a given RMID. Return success to the user if one or more aggregators provide valid data.
Resctrl now uses readq() so depends on X86_64. Update Kconfig.
--- arch/x86/kernel/cpu/resctrl/internal.h | 7 +++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 65 ++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 75 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +7 -0
@@ -172,9 +172,16 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r);#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void); +int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val);#else static inline bool intel_aet_get_events (void ) {return false; } static inline void __exit intel_aet_exit(void) { } +static inline int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val) +{ +return -EINVAL ; +}#endif #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/intel_aet.c +64 -1
93 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/monitor.c +3 -0
@@ -232,6 +232,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,resctrl_arch_rmid_read_context_check (); +if (r->rid ==RDT_RESOURCE_PERF_PKG ) +return intel_aet_read_event (hdr->id, rmid, eventid, arch_priv, val); +if (r->rid !=RDT_RESOURCE_L3 )return -EINVAL ;
arch/x86/Kconfig +1 -1
@@ -527,7 +527,7 @@ config X86_CPU_RESCTRL config X86_CPU_RESCTRL_INTEL_AET bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y - depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL help Enable per-RMID telemetry events in resctrl.
Signature · 1 line
2.51.0
Reinette Chatre
maintainerRe: [PATCH v9 21/31] x86/resctrl: Read telemetry events
Hi Tony,
Quoted 14 lines · Tony
Agreed. See new
mark_telem_region_unusable()in updated patch below. Also pushed togit://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.gitrdt-aet-v10-wip-Tony
P.S. In addition to all the extra #include files you suggested, I found a few others missing. So those are added as needed in the series.From
163824a2e10de9f63e20f0bc9f86b8c14f58bfcbMon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Mon, 25 Aug 2025 10:47:06 -0700
Subject: [PATCH 21/31] x86/resctrl: Read telemetry events
Quoted 4 lines
Telemetry events are enumerated by the
INTEL_PMT_TELEMETRYsubsystem. resctrl enables events withresctrl_enable_mon_event()passing a pointer to thepmt_eventstructure for the event within the structevent_group. The file system stores it inmon_evt::arch_priv.
This is getting to be very detailed description of code as opposed to what the code does ... hmmm ... looks like I already made an attempt with a proposal in v8 that was just ignored without any reason. <sigh>
Quoted 3 lines
Mark regions that did not pass the checks in
skip_telemetry_region()so they will not be used byintel_aet_read_event().
Apart from skip_telemetry_region() -> skip_telem_region() I think this should lighten up on the code details. Compare with, for example:
Mark telemetry regions that did not pass the sanity checks by clearing their MMIO address fields so that they will not be used when reading events.
(i.e, more about what the code does instead of actual code)
Quoted 5 lines
Add a check to
resctrl_arch_rmid_read()for resource idRDT_RESOURCE_PERF_PKGand directly callintel_aet_read_event()passing the enumresctrl_event_idfor the event and thearch_privpointer that was supplied when the event was enabled.
Also heavy on code details while written as though reader is familiar with function (intel_aet_read_event()) introduced in this patch. Compare with, for example:
Introduce intel_aet_read_event() to read telemetry events for resource RDT_RESOURCE_PERF_PKG. There may be multiple aggregators ...
Quoted 21 lines
There may be multiple aggregators tracking each package, so scan all of them and add up all counters. Aggregators may return an invalid data indication if they have received no records for a given RMID. Return success to the user if one or more aggregators provide valid data.
Resctrl now uses
readq()so depends onX86_64. UpdateKconfig.Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 7 +++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 65 ++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 75 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h void rdt_domain_reconfigure_cdp(struct rdt_resource *r); · line 175
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/internal.h +1
-0@@ -172,9 +172,16 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r);#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void); +int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id evtid,
Patch 24 goes through effort of making RMID unsigned while intel_aet_read_event() casts an unsigned RMID to signed?
Quoted 81 lines
arch/x86/kernel/cpu/resctrl/internal.h +6
-0+ void *arch_priv, u64 *val);#else static inline bool intel_aet_get_events (void ) {return false; } static inline void __exit intel_aet_exit(void) { } +static inline int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid, +void *arch_priv,u64 *val) +{ +return -EINVAL ; +}#endif #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/intel_aet.c +33
-1@@ -12,13 +12,17 @@#define pr_fmt (fmt) "resctrl: " fmt#include <linux/array_size.h> +#include <linux/bits.h> #include <linux/cleanup.h> #include <linux/compiler_types.h> +#include <linux/container_of.h> #include <linux/cpu.h> #include <linux/err.h> +#include <linux/errno.h> #include <linux/init.h> #include <linux/intel_pmt_features.h> #include <linux/intel_vsec.h> +#include <linux/io.h> #include <linux/overflow.h> #include <linux/printk.h> #include <linux/resctrl.h> @@ -131,13 +135,28 @@ static bool skip_telem_region(struct telemetry_region *tr, struct event_group *ereturn false; } +/* +* Clear the address field of regions that did not pass the checks in +* skip_telem_region() so they will not be used by intel_aet_read_event(). +* This is safe to do because intel_pmt_get_regions_by_feature() allocates +* a new pmt_feature_group structure to return to each caller and only makes +* use of the pmt_feature_group::kref field when intel_pmt_put_feature_group() +* returns the structure. +*/ +static void mark_telem_region_unusable (struct telemetry_region *tr) +{ + tr->addr =NULL ; +} +static bool enable_events (struct event_group *e,struct pmt_feature_group *p) {bool usable_events = false;for (int i =0 ; i < p->count; i++) { -if (skip_telem_region (&p->regions[i], e)) +if (skip_telem_region (&p->regions[i], e)) { +mark_telem_region_unusable (&p->regions[i]);continue ; + } usable_events = true; }@@ -215,3 +234,47 @@ void __exit intel_aet_exit(void) (*peg)->pfg =NULL ; } } + +#define DATA_VALID BIT_ULL(63) +#define DATA_BITS GENMASK_ULL(62, 0) + +/* +* Read counter for an event on a domain (summing all aggregators +* on the domain). If an aggregator hasn't received any data for a +* specific RMID, the MMIO read indicates that data is not valid. +* Return success if at least one aggregator has valid data. +*/ +int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id eventid, +void *arch_priv,u64 *val) +{
arch/x86/kernel/cpu/resctrl/intel_aet.c void __exit intel_aet_exit(void) · line 259
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +10
-0+struct pmt_event *pevt = arch_priv; +struct event_group *e; +bool valid = false; +u64 evtcount; +void *pevt0; +int idx; + + pevt0 = pevt - pevt->idx; + e = container_of(pevt0, struct event_group, evts); + idx = rmid * e->num_events;
Looks like idx can also be unsigned (since rmid and num_events are unsigned) and should be printed with %u?
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +11
-0+ idx += pevt->idx; + +if (idx *sizeof (u64) +sizeof (u64) > e->mmio_size) { +pr_warn_once ("MMIO index %d out of range\n" , idx); +return -EIO ; + } + +for (int i =0 ; i < e->pfg->count; i++) { +if (!e->pfg->regions[i].addr) +continue ; +if (e->pfg->regions[i].plat_info.package_id != domid)
arch/x86/kernel/cpu/resctrl/intel_aet.c void __exit intel_aet_exit(void) · line 280
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +10
-0+continue ; + evtcount =readq (e->pfg->regions[i].addr + idx *sizeof (u64)); +if (!(evtcount &DATA_VALID )) +continue ; + *val += evtcount &DATA_BITS ; + valid = true; + } + +return valid ?0 : -EINVAL ; +}
Reinette
Tony Luck
maintainerPATCH v9 22/31 x86/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG
In reply to Tony LuckThe L3 resource has several requirements for domains. There are per-domain structures that hold the 64-bit values of counters, and elements to keep track of the overflow and limbo threads.
None of these are needed for the PERF_PKG resource. The hardware counters are wide enough that they do not wrap around for decades.
Define a new rdt_perf_pkg_mon_domain structure which just consists of the standard rdt_domain_hdr to keep track of domain id and CPU mask.
Support the PERF_PKG resource in the CPU online/offline handlers. Allocate and initialize the rdt_perf_pkg_mon_domain structure when the first CPU of a domain comes online and do necessary cleanup when the last CPU of a domain goes offline.
--- arch/x86/kernel/cpu/resctrl/internal.h | 13 +++++++++++++ arch/x86/kernel/cpu/resctrl/core.c | 12 ++++++++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +13 -0
@@ -75,6 +75,14 @@ static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom(struct rdt_l3 return container_of(r, struct rdt_hw_l3_mon_domain, d_resctrl); } +/** +* struct rdt_perf_pkg_mon_domain - CPUs sharing an package scoped resctrl monitor resource +* @hdr: common header for different domain types +*/ +struct rdt_perf_pkg_mon_domain { +struct rdt_domain_hdr hdr; +}; +/** * struct msr_param - set a range of MSRs from a domain * @res: The resource to use
@@ -174,6 +182,8 @@ bool intel_aet_get_events(void); void __exit intel_aet_exit(void);int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid,void *arch_priv,u64 *val); +void intel_aet_setup_mon_domain (int cpu,int id,struct rdt_resource *r, +struct list_head *add_pos);#else static inline bool intel_aet_get_events (void ) {return false; } static inline void __exit intel_aet_exit(void) { }
@@ -182,6 +192,9 @@ static inline int intel_aet_read_event(int domid, int rmid, enum resctrl_event_i {return -EINVAL ; } + +static inline void intel_aet_setup_mon_domain (int cpu,int id,struct rdt_resource *r, +struct list_head *add_pos) { }#endif #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/core.c +12 -0
@@ -574,6 +574,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)case RDT_RESOURCE_L3 :l3_mon_domain_setup (cpu, id, r, add_pos);break ; +case RDT_RESOURCE_PERF_PKG : +intel_aet_setup_mon_domain (cpu, id, r, add_pos); +break ;default :pr_warn_once ("Unknown resource rid=%d\n" , r->rid);break ;
@@ -671,6 +674,15 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)synchronize_rcu ();l3_mon_domain_free (hw_dom);break ; +case RDT_RESOURCE_PERF_PKG : +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_PERF_PKG )) +return ; + +resctrl_offline_mon_domain (r, hdr); +list_del_rcu (&hdr->list); +synchronize_rcu (); +kfree (container_of (hdr ,struct rdt_perf_pkg_mon_domain ,hdr )); +break ;default :pr_warn_once ("Unknown resource rid=%d\n" , r->rid);break ;
arch/x86/kernel/cpu/resctrl/intel_aet.c +24 -0
@@ -255,3 +255,27 @@ int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id eventid,return valid ?0 : -EINVAL ; } + +void intel_aet_setup_mon_domain (int cpu,int id,struct rdt_resource *r, +struct list_head *add_pos) +{ +struct rdt_perf_pkg_mon_domain *d; +int err; + + d =kzalloc_node (sizeof (*d),GFP_KERNEL ,cpu_to_node (cpu)); +if (!d) +return ; + + d->hdr.id = id; + d->hdr.type =RESCTRL_MON_DOMAIN ; + d->hdr.rid = r->rid; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask); +list_add_tail_rcu (&d->hdr.list, add_pos); + + err =resctrl_online_mon_domain (r, &d->hdr); +if (err) { +list_del_rcu (&d->hdr.list); +synchronize_rcu (); +kfree (d); + } +}
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 22/31] x86/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG
Hi Tony,
Quoted 5 lines · Tony Luck
arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom(struct rdt_l3 · line 83
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/internal.h +6
-0@@ -75,6 +75,14 @@ static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom(struct rdt_l3 return container_of(r, struct rdt_hw_l3_mon_domain, d_resctrl); } +/** +* struct rdt_perf_pkg_mon_domain - CPUs sharing an package scoped resctrl monitor resource +* @hdr: common header for different domain types +*/ +struct rdt_perf_pkg_mon_domain { +struct rdt_domain_hdr hdr;
Please use tabs to align struct member names.
Quoted 29 lines
arch/x86/kernel/cpu/resctrl/internal.h +7
-0+}; +/** * struct msr_param - set a range of MSRs from a domain * @res: The resource to use @@ -174,6 +182,8 @@ bool intel_aet_get_events(void); void __exit intel_aet_exit(void);int intel_aet_read_event (int domid,int rmid,enum resctrl_event_id evtid,void *arch_priv,u64 *val); +void intel_aet_setup_mon_domain (int cpu,int id,struct rdt_resource *r, +struct list_head *add_pos);#else static inline bool intel_aet_get_events (void ) {return false; } static inline void __exit intel_aet_exit(void) { }@@ -182,6 +192,9 @@ static inline int intel_aet_read_event(int domid, int rmid, enum resctrl_event_i {return -EINVAL ; } + +static inline void intel_aet_setup_mon_domain (int cpu,int id,struct rdt_resource *r, +struct list_head *add_pos) { }#endif #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 578
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0@@ -574,6 +574,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)case RDT_RESOURCE_L3 :l3_mon_domain_setup (cpu, id, r, add_pos);break ; +case RDT_RESOURCE_PERF_PKG : +intel_aet_setup_mon_domain (cpu, id, r, add_pos);
This can easily be consistent with existing naming (l3_mon_domain_setup()), intel_aet_setup_mon_domain() -> intel_aet_mon_domain_setup()?
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) · line 681
Quoted 13 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0+break ;default :pr_warn_once ("Unknown resource rid=%d\n" , r->rid);break ;@@ -671,6 +674,15 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)synchronize_rcu ();l3_mon_domain_free (hw_dom);break ; +case RDT_RESOURCE_PERF_PKG : +if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_PERF_PKG )) +return ; + +resctrl_offline_mon_domain (r, hdr);
As mentioned earlier I think that including changes to resctrl_offline_mon_domain() to support being called with RDT_RESOURCE_PERF_PKG as part of this patch will be much easier to follow than sneaking it in with the L3 refactoring.
Quoted 23 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+list_del_rcu (&hdr->list); +synchronize_rcu (); +kfree (container_of(hdr ,struct rdt_perf_pkg_mon_domain ,hdr )); +break ;default :pr_warn_once ("Unknown resource rid=%d\n" , r->rid);break ;arch/x86/kernel/cpu/resctrl/intel_aet.c +8
-0@@ -255,3 +255,27 @@ int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id eventid,return valid ?0 : -EINVAL ; } + +void intel_aet_setup_mon_domain (int cpu,int id,struct rdt_resource *r, +struct list_head *add_pos) +{ +struct rdt_perf_pkg_mon_domain *d; +int err; + + d =kzalloc_node (sizeof (*d),GFP_KERNEL ,cpu_to_node (cpu));
arch/x86/kernel/cpu/resctrl/intel_aet.c int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id eventid, · line 275
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +10
-0+if (!d) +return ; + + d->hdr.id = id; + d->hdr.type =RESCTRL_MON_DOMAIN ; + d->hdr.rid = r->rid; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask); +list_add_tail_rcu (&d->hdr.list, add_pos); + + err =resctrl_online_mon_domain (r, &d->hdr);
Same with the resctrl_online_mon_domain() changes.
arch/x86/kernel/cpu/resctrl/intel_aet.c int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id eventid, · line 281
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +6
-0+if (err) { +list_del_rcu (&d->hdr.list); +synchronize_rcu (); +kfree (d); + } +}
Reinette
Tony Luck
maintainerPATCH v9 23/31 x86/resctrl: Add energy/perf choices to rdt boot option
In reply to Tony LuckLegacy resctrl features are enumerated by X86_FEATURE_* flags. These may be overridden by quirks to disable features in the case of errata.
Users can use kernel command line options to either disable a feature, or to force enable a feature that was disabled by a quirk.
Provide similar functionality for hardware features that do not have an X86_FEATURE_* flag.
Unlike other features that are tied to X86_FEATURE_* flags, these must be queried by name. Add rdt_is_feature_enabled() to check whether quirks or kernel command line have disabled a feature.
Users may force a feature to be disabled. E.g. "rdt=!perf" will ensure that none of the perf telemetry events are enabled.
Resctrl architecture code may disable a feature that does not provide full functionality. Users may override that decision. E.g. "rdt=energy" will enable any available energy telemetry events even if they do not provide full functionality.
starting # with '#' will be ignored, and an empty message
aborts the commit. # # Date: Mon Aug 11 09:36:45 2025
-0700 # # On branch rdt-aet-v9-wip # Changes to be committed:
modified: arch/x86/kernel/cpu/resctrl/core.c # modified:arch/x86/kernel/cpu/resctrl/internal.h # # Untracked files: #
[email protected] # cscope-x86.out #
cscope-x86.out.in # cscope-x86.out.po # v8/ #
--- .../admin-guide/kernel-parameters.txt | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
@@ -6154,7 +6154,7 @@ rdt= [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec. + mba, smba, bmec, energy, perf. E.g. to turn on cmt and turn off mba use: rdt=cmt,!mba
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -177,6 +177,8 @@ void __init intel_rdt_mbm_apply_quirk(void);void rdt_domain_reconfigure_cdp (struct rdt_resource *r); +bool rdt_is_feature_enabled (char *name); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void);
arch/x86/kernel/cpu/resctrl/core.c +30 -0
@@ -763,6 +763,8 @@ enum {RDT_FLAG_MBA ,RDT_FLAG_SMBA ,RDT_FLAG_BMEC , +RDT_FLAG_ENERGY , + RDT_FLAG_PERF, };#define RDT_OPT (idx, n, f) \
@@ -788,6 +790,8 @@ static struct rdt_options rdt_options[] __ro_after_init = {RDT_OPT (RDT_FLAG_MBA ,"mba" ,X86_FEATURE_MBA ),RDT_OPT (RDT_FLAG_SMBA ,"smba" ,X86_FEATURE_SMBA ),RDT_OPT (RDT_FLAG_BMEC ,"bmec" ,X86_FEATURE_BMEC ), +RDT_OPT (RDT_FLAG_ENERGY ,"energy" ,0 ), + RDT_OPT(RDT_FLAG_PERF, "perf", 0), };#define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options)
@@ -837,6 +841,32 @@ bool rdt_cpu_has(int flag)return ret; } +/* +* Hardware features that do not have X86_FEATURE_* bits. +* There is no "hardware does not support this at all" case. +* Assume that the caller has already determined that hardware +* support is present and just needs to check if the feature has been +* disabled by a quirk that has not been overridden by a command +* line option. +*/ +bool rdt_is_feature_enabled (char *name) +{ +struct rdt_options *o; +bool ret = true; + +for (o = rdt_options; o < &rdt_options[NUM_RDT_OPTIONS ]; o++) { +if (!strcmp (name, o->name)) { +if (o->force_off) + ret = false; +if (o->force_on) + ret = true; +break ; + } + } + +return ret; +} +bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt) {if (!rdt_cpu_has (X86_FEATURE_BMEC ))
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 23/31] x86/resctrl: Add energy/perf choices to rdt boot option
Hi Tony,
Quoted 5 lines · Tony Luck
Legacy resctrl features are enumerated by X86_FEATURE_* flags. These may be overridden by quirks to disable features in the case of errata.
Users can use kernel command line options to either disable a feature, or to force enable a feature that was disabled by a quirk.
Above two sentences can be merged into a paragraph.
Quoted 7 lines
Provide similar functionality for hardware features that do not have an X86_FEATURE_* flag.
Unlike other features that are tied to X86_FEATURE_* flags, these must be queried by name. Add
rdt_is_feature_enabled()to check whether quirks or kernel command line have disabled a feature.
Above two sentences can be merged into a paragraph.
Quoted 11 lines
Users may force a feature to be disabled. E.g. "rdt=!perf" will ensure that none of the perf telemetry events are enabled.
Resctrl architecture code may disable a feature that does not provide full functionality. Users may override that decision. E.g. "rdt=energy" will enable any available energy telemetry events even if they do not provide full functionality.
Signed-off-by Tony Luck <[email protected]>
Quoted 7 lines
starting # with '#' will be ignored, and an empty message
aborts the commit. # # Date: Mon Aug 11 09:36:45 2025
-0700 # # On branch rdt-aet-v9-wip # Changes to be committed:
modified:arch/x86/kernel/cpu/resctrl/core.c# modified:arch/x86/kernel/cpu/resctrl/internal.h# # Untracked files: #
[email protected] # cscope-x86.out #
cscope-x86.out.in # cscope-x86.out.po # v8/ #
Mangled changelog.
Quoted 55 lines
--- .../admin-guide/kernel-parameters.txt | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)Documentation/admin-guide/kernel-parameters.txt +1
-1@@ -6154,7 +6154,7 @@ rdt= [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec. + mba, smba, bmec, energy, perf. E.g. to turn on cmt and turn off mba use: rdt=cmt,!mbaarch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -177,6 +177,8 @@ void __init intel_rdt_mbm_apply_quirk(void);void rdt_domain_reconfigure_cdp (struct rdt_resource *r); +bool rdt_is_feature_enabled (char *name); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void);arch/x86/kernel/cpu/resctrl/core.c +4
-0@@ -763,6 +763,8 @@ enum {RDT_FLAG_MBA ,RDT_FLAG_SMBA ,RDT_FLAG_BMEC , +RDT_FLAG_ENERGY , + RDT_FLAG_PERF, };#define RDT_OPT (idx, n, f) \@@ -788,6 +790,8 @@ static struct rdt_options rdt_options[] __ro_after_init = {RDT_OPT (RDT_FLAG_MBA ,"mba" ,X86_FEATURE_MBA ),RDT_OPT (RDT_FLAG_SMBA ,"smba" ,X86_FEATURE_SMBA ),RDT_OPT (RDT_FLAG_BMEC ,"bmec" ,X86_FEATURE_BMEC ), +RDT_OPT (RDT_FLAG_ENERGY ,"energy" ,0 ), + RDT_OPT(RDT_FLAG_PERF, "perf", 0), };#define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options)
arch/x86/kernel/cpu/resctrl/core.c bool rdt_cpu_has(int flag) · line 850
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0@@ -837,6 +841,32 @@ bool rdt_cpu_has(int flag)return ret; } +/* +* Hardware features that do not have X86_FEATURE_* bits. +* There is no "hardware does not support this at all" case. +* Assume that the caller has already determined that hardware +* support is present and just needs to check if the feature has been +* disabled by a quirk that has not been overridden by a command +* line option.
Another recurring topic. Please do not unnecessarily trim comments to be so far under 80 columns.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c +12
-0+*/ +bool rdt_is_feature_enabled (char *name) +{ +struct rdt_options *o; +bool ret = true; + +for (o = rdt_options; o < &rdt_options[NUM_RDT_OPTIONS ]; o++) { +if (!strcmp (name, o->name)) { +if (o->force_off) + ret = false; +if (o->force_on) + ret = true;
arch/x86/kernel/cpu/resctrl/core.c bool rdt_cpu_has(int flag) · line 872
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0+break ; + } + } + +return ret; +} +bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt) {if (!rdt_cpu_has (X86_FEATURE_BMEC ))
Reinette
Tony Luck
maintainerPATCH v9 24/31 x86/resctrl: Handle number of RMIDs supported by telemetry resources
In reply to Tony LuckThere are now three meanings for "number of RMIDs":
1) The number for legacy features enumerated by CPUID leaf 0xF. This is the maximum number of distinct values that can be loaded into the IA32_PQR_ASSOC MSR. Note that systems with Sub-NUMA Cluster mode enabled will force scaling down the CPUID enumerated value by the number of SNC nodes per L3-cache.
2) The number of registers in MMIO space for each event. This is enumerated in the XML files and is the value initialized into event_group::num_rmids. This will be overwritten with a lower value if hardware does not support all these registers at the same time (see next case).
3) The number of "hardware counters" (this isn't a strictly accurate description of how things work, but serves as a useful analogy that does describe the limitations) feeding to those MMIO registers. This is enumerated in telemetry_region::num_rmids returned from the call to intel_pmt_get_regions_by_feature()
Event groups with insufficient "hardware counters" to track all RMIDs are difficult for users to use, since the system may reassign "hardware counters" at any time. This means that users cannot reliably collect two consecutive event counts to compute the rate at which events are occurring.
Use rdt_set_feature_disabled() to mark any under-resourced event groups (those with telemetry_region::num_rmids < event_group::num_rmids) as unusable. Note that the rdt_options[] structure must now be writable at run-time. The request to disable will be overridden if the user explicitly requests to enable using the "rdt=" Linux boot argument.
Scan all enabled event groups and assign the RDT_RESOURCE_PERF_PKG resource "num_rmids" value to the smallest of these values as this value will be used later to compare against the number of RMIDs supported by other resources.
N.B. Changed type of rdt_resource::num_rmid to u32 to match type of event_group::num_rmids so that min(r->num_rmid, e->num_rmids) won't complain about mixing signed and unsigned types. Print r->num_rmid as unsigned value in rdt_num_rmids_show().
--- include/linux/resctrl.h | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 18 +++++++++- arch/x86/kernel/cpu/resctrl/intel_aet.c | 47 +++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 2 +- 5 files changed, 68 insertions(+), 3 deletions(-)
include/linux/resctrl.h +1 -1
@@ -288,7 +288,7 @@ struct rdt_resource {int rid;bool alloc_capable;bool mon_capable; -int num_rmid; +u32 num_rmid;enum resctrl_scope ctrl_scope;enum resctrl_scope mon_scope;struct resctrl_cache cache;
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -179,6 +179,8 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r);bool rdt_is_feature_enabled (char *name); +void rdt_set_feature_disabled (char *name); +#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events (void ); void __exit intel_aet_exit(void);
arch/x86/kernel/cpu/resctrl/core.c +17 -1
@@ -779,7 +779,7 @@ struct rdt_options {bool force_off, force_on; }; -static struct rdt_options rdt_options[]__ro_after_init = { +static struct rdt_options rdt_options[] = {RDT_OPT (RDT_FLAG_CMT ,"cmt" ,X86_FEATURE_CQM_OCCUP_LLC ),RDT_OPT (RDT_FLAG_MBM_TOTAL ,"mbmtotal" ,X86_FEATURE_CQM_MBM_TOTAL ),RDT_OPT (RDT_FLAG_MBM_LOCAL ,"mbmlocal" ,X86_FEATURE_CQM_MBM_LOCAL ),
@@ -841,6 +841,22 @@ bool rdt_cpu_has(int flag)return ret; } +/* +* Can be called during feature enumeration if sanity check of +* a feature's parameters indicates problems with the feature. +*/ +void rdt_set_feature_disabled (char *name) +{ +struct rdt_options *o; + +for (o = rdt_options; o < &rdt_options[NUM_RDT_OPTIONS ]; o++) { +if (!strcmp (name, o->name)) { + o->force_off = true; +return ; + } + } +} +/* * Hardware features that do not have X86_FEATURE_* bits. * There is no "hardware does not support this at all" case.
arch/x86/kernel/cpu/resctrl/intel_aet.c +47 -0
109 lines not on this page · raw message
fs/resctrl/rdtgroup.c +1 -1
@@ -1135,7 +1135,7 @@ static int rdt_num_rmids_show(struct kernfs_open_file *of, {struct rdt_resource *r =rdt_kn_parent_priv (of->kn); -seq_printf (seq,"%d\n" , r->num_rmid); +seq_printf (seq,"%u\n" , r->num_rmid);return 0 ; }
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 24/31] x86/resctrl: Handle number of RMIDs supported by telemetry resources
Hi Tony,
Quoted 8 lines · Tony Luck
There are now three meanings for "number of RMIDs":
1) The number for legacy features enumerated by CPUID leaf
0xF. This is the maximum number of distinct values that can be loaded into theIA32_PQR_ASSOCMSR. Note that systems with Sub-NUMA Cluster mode enabled will force scaling down the CPUID enumerated value by the number of SNC nodes per L3-cache.
Quoted 5 lines
2) The number of registers in MMIO space for each event. This is enumerated in the XML files and is the value initialized into
event_group::num_rmids. This will be overwritten with a lower value if hardware does not support all these registers at the same time (see next case).
Same comment as v8. :(
Quoted 7 lines
3) The number of "hardware counters" (this isn't a strictly accurate description of how things work, but serves as a useful analogy that does describe the limitations) feeding to those MMIO registers. This is enumerated in
telemetry_region::num_rmidsreturned from the call tointel_pmt_get_regions_by_feature()
Quoted 7 lines
Event groups with insufficient "hardware counters" to track all RMIDs are difficult for users to use, since the system may reassign "hardware counters" at any time. This means that users cannot reliably collect two consecutive event counts to compute the rate at which events are occurring.
Use
rdt_set_feature_disabled()to mark any under-resourced event groups
Use -> Introduce
Quoted 4 lines
(those with
telemetry_region::num_rmids<event_group::num_rmids) as unusable. Note that the rdt_options[] structure must now be writable at run-time. The request to disable will be overridden if the user explicitly requests to enable using the "rdt=" Linux boot argument.
Can add snippet here about how values are adjusted in this case.
Quoted 5 lines
Scan all enabled event groups and assign the
RDT_RESOURCE_PERF_PKGresource "num_rmids" value to the smallest of these values as this value will be used later to compare against the number of RMIDs supported by other resources.
can append "... to determine how many monitoring resource groups are supported."
Quoted 2 lines
N.B. Changed type of
rdt_resource::num_rmidto u32 to match type of
Same comment as v8. :(
Quoted 6 lines
event_group::num_rmidsso thatmin(r->num_rmid, e->num_rmids)won't complain about mixing signed and unsigned types. Printr->num_rmidas unsigned value inrdt_num_rmids_show().Signed-off-by Tony Luck <[email protected]>---
...
Quoted 13 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +1
-0@@ -15,6 +15,7 @@#include <linux/cpu.h> #include <linux/intel_vsec.h> #include <linux/io.h> +#include <linux/minmax.h> #include <linux/resctrl.h> #include "internal.h"
arch/x86/kernel/cpu/resctrl/intel_aet.c struct pmt_event { · line 45
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +2
-0@@ -36,20 +37,26 @@ struct pmt_event {/** * struct event_group - All information about a group of telemetry events. +* @name: Name for this group (used by boot rdt= option) * @pfg: Points to the aggregated telemetry space information * within the INTEL_PMT_TELEMETRY driver that contains data for all * telemetry regions. * @guid: Unique number per XML description file. +* @num_rmids: Number of RMIDs supported by this group. May be djusted downwards
djusted -> adjusted
Also, please stay within 80 columns.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +2
-0+* if enumeration from intel_pmt_get_regions_by_feature() indicates +* fewer RMIDs can be tracked simultaneously. * @mmio_size: Number of bytes of MMIO registers for this group. * @num_events: Number of events in this group. * @evts: Array of event descriptors. */ struct event_group {
arch/x86/kernel/cpu/resctrl/intel_aet.c struct pmt_event { · line 62
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +2
-0/* Data fields for additional structures to manage this group. */ +char *name;struct pmt_feature_group *pfg;/* Remaining fields initialized from XML file. */ u32 guid; +u32 num_rmids;size_t mmio_size;unsigned int num_events; struct pmt_event evts[] __counted_by(num_events);
Reinette
Tony Luck
maintainerPATCH v9 25/31 fs/resctrl: Move allocation/free of closid_num_dirty_rmid
In reply to Tony Luckclosid_num_dirty_rmid[] is allocated in dom_data_init() during resctrl initialization and freed by dom_data_exit() during resctrl exit giving it the same life cycle as rmid_ptrs[].
Move closid_num_dirty_rmid[] allocaction/free out to resctrl_l3_mon_resource_init() and resctrl_l3_mon_resource_exit() in preparation for rmid_ptrs[] to be allocated on resctrl mount in support of the new telemetry events.
--- fs/resctrl/monitor.c | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-)
fs/resctrl/monitor.c +28 -28
@@ -805,36 +805,14 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delstatic int dom_data_init (struct rdt_resource *r) {u32 idx_limit =resctrl_arch_system_num_rmid_idx (); -u32 num_closid =resctrl_arch_get_num_closid (r);struct rmid_entry *entry =NULL ;int err =0 , i;u32 idx;mutex_lock (&rdtgroup_mutex); -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -u32 *tmp; - -/* -* If the architecture hasn't provided a sanitised value here, -* this may result in larger arrays than necessary. Resctrl will -* use a smaller system wide value based on the resources in -* use. -*/ - tmp =kcalloc (num_closid,sizeof (*tmp),GFP_KERNEL ); -if (!tmp) { - err = -ENOMEM ; - goto out_unlock; - } - - closid_num_dirty_rmid = tmp; - } rmid_ptrs =kcalloc (idx_limit,sizeof (struct rmid_entry ),GFP_KERNEL );if (!rmid_ptrs) { -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } err = -ENOMEM ; goto out_unlock; }
@@ -870,11 +848,6 @@ static void dom_data_exit(struct rdt_resource *r)if (!r->mon_capable) goto out_unlock; -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } -kfree (rmid_ptrs); rmid_ptrs =NULL ;
@@ -957,9 +930,31 @@ int resctrl_l3_mon_resource_init(void)if (!r->mon_capable)return 0 ; +if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { +u32 num_closid =resctrl_arch_get_num_closid (r); +u32 *tmp; + +/* +* If the architecture hasn't provided a sanitised value here, +* this may result in larger arrays than necessary. Resctrl will +* use a smaller system wide value based on the resources in +* use. +*/ + tmp =kcalloc (num_closid,sizeof (*tmp),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + + closid_num_dirty_rmid = tmp; + } + ret =dom_data_init (r); -if (ret) +if (ret) { +if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { +kfree (closid_num_dirty_rmid); + closid_num_dirty_rmid =NULL ; + }return ret; + }if (resctrl_arch_is_evt_configurable (QOS_L3_MBM_TOTAL_EVENT_ID )) { mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID ].configurable = true;
@@ -984,5 +979,10 @@ void resctrl_l3_mon_resource_exit(void) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); +if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { +kfree (closid_num_dirty_rmid); + closid_num_dirty_rmid =NULL ; + } +dom_data_exit (r); }
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 25/31] fs/resctrl: Move allocation/free of closid_num_dirty_rmid
Hi Tony,
In subject:closid_num_dirty_rmid -> closid_num_dirty_rmid[]
Quoted 19 lines · Tony Luck
closid_num_dirty_rmid[] is allocated in
dom_data_init()during resctrl initialization and freed bydom_data_exit()during resctrl exit giving it the same life cycle as rmid_ptrs[].Move closid_num_dirty_rmid[] allocaction/free out to
resctrl_l3_mon_resource_init()andresctrl_l3_mon_resource_exit()in preparation for rmid_ptrs[] to be allocated on resctrl mount in support of the new telemetry events.Signed-off-by Tony Luck <[email protected]>--- fs/resctrl/monitor.c | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-)fs/resctrl/monitor.c +0
-0
fs/resctrl/monitor.c void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long del · line 812
Quoted 9 lines
fs/resctrl/monitor.c +0
-1@@ -805,36 +805,14 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delstatic int dom_data_init (struct rdt_resource *r) {u32 idx_limit =resctrl_arch_system_num_rmid_idx (); -u32 num_closid =resctrl_arch_get_num_closid (r);struct rmid_entry *entry =NULL ;int err =0 , i;u32 idx;mutex_lock (&rdtgroup_mutex);
mutex is held during original allocation code below ...
Quoted 28 lines
fs/resctrl/monitor.c +0
-21-if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -u32 *tmp; - -/* -* If the architecture hasn't provided a sanitised value here, -* this may result in larger arrays than necessary. Resctrl will -* use a smaller system wide value based on the resources in -* use. -*/ - tmp =kcalloc (num_closid,sizeof (*tmp),GFP_KERNEL ); -if (!tmp) { - err = -ENOMEM ; - goto out_unlock; - } - - closid_num_dirty_rmid = tmp; - } rmid_ptrs =kcalloc (idx_limit,sizeof (struct rmid_entry ),GFP_KERNEL );if (!rmid_ptrs) { -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } err = -ENOMEM ; goto out_unlock; }
fs/resctrl/monitor.c static void dom_data_exit(struct rdt_resource *r) · line 877
Quoted 8 lines
fs/resctrl/monitor.c +0
-5@@ -870,11 +848,6 @@ static void dom_data_exit(struct rdt_resource *r)if (!r->mon_capable) goto out_unlock; -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } -
mutex is held in original free code ...
Quoted 13 lines
fs/resctrl/monitor.c +6
-0kfree (rmid_ptrs); rmid_ptrs =NULL ;@@ -957,9 +930,31 @@ int resctrl_l3_mon_resource_init(void)if (!r->mon_capable)return 0 ; +if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { +u32 num_closid =resctrl_arch_get_num_closid (r); +u32 *tmp; + +/* +* If the architecture hasn't provided a sanitised value here,
fs/resctrl/monitor.c int resctrl_l3_mon_resource_init(void) · line 948
Quoted 10 lines
fs/resctrl/monitor.c +10
-0+* this may result in larger arrays than necessary. Resctrl will +* use a smaller system wide value based on the resources in +* use. +*/ + tmp =kcalloc (num_closid,sizeof (*tmp),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + + closid_num_dirty_rmid = tmp; + }
mutex no longer held during allocation ... no mention in changelog why this is ok?
Quoted 14 lines
fs/resctrl/monitor.c +7
-1+ ret =dom_data_init (r); -if (ret) +if (ret) { +if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { +kfree (closid_num_dirty_rmid); + closid_num_dirty_rmid =NULL ; + }return ret; + }if (resctrl_arch_is_evt_configurable (QOS_L3_MBM_TOTAL_EVENT_ID )) { mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID ].configurable = true;
fs/resctrl/monitor.c void resctrl_l3_mon_resource_exit(void) · line 981
Quoted 3 lines
fs/resctrl/monitor.c +0
-0@@ -984,5 +979,10 @@ void resctrl_l3_mon_resource_exit(void) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 );
If you also use the "if (!r->mon_capable)" check as is done in original code then resctrl_l3_mon_resource_exit() will be symmetrical with resctrl_l3_mon_resource_init(). Since resctrl_l3_mon_resource_exit() is _always_ called, whether monitoring is enabled or not, adding this check will also make the code easier to follow and not require that reader knows how closid_num_dirty_rmid[] is connected.
Another benefit of keeping this check is that it forces the function to remain L3 resource specific (not just by name) and not seemingly become generic later in series ("fs/resctrl: Move RMID initialization to first mount")
fs/resctrl/monitor.c int resctrl_l3_mon_resource_init(void) · line 955
Quoted 4 lines
fs/resctrl/monitor.c +4
-0+if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { +kfree (closid_num_dirty_rmid); + closid_num_dirty_rmid =NULL ; + }
... now freed without mutex without mention in changelog?
fs/resctrl/monitor.c void resctrl_l3_mon_resource_exit(void) · line 988
Quoted 3 lines
fs/resctrl/monitor.c +1
-0+dom_data_exit (r); }
Reinette
Luck, Tony
maintainerRe: [PATCH v9 25/31] fs/resctrl: Move allocation/free of closid_num_dirty_rmid
Quoted 46 lines · Reinette Chatre
Hi Tony,
In subject:
closid_num_dirty_rmid-> closid_num_dirty_rmid[]Quoted 19 lines · Tony Luck
closid_num_dirty_rmid[] is allocated in
dom_data_init()during resctrl initialization and freed bydom_data_exit()during resctrl exit giving it the same life cycle as rmid_ptrs[].Move closid_num_dirty_rmid[] allocaction/free out to
resctrl_l3_mon_resource_init()andresctrl_l3_mon_resource_exit()in preparation for rmid_ptrs[] to be allocated on resctrl mount in support of the new telemetry events.Signed-off-by Tony Luck <[email protected]>--- fs/resctrl/monitor.c | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-)fs/resctrl/monitor.c +0
-0fs/resctrl/monitor.c void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long del · line 812
Quoted 9 lines
fs/resctrl/monitor.c +0
-1@@ -805,36 +805,14 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delstatic int dom_data_init (struct rdt_resource *r) {u32 idx_limit =resctrl_arch_system_num_rmid_idx (); -u32 num_closid =resctrl_arch_get_num_closid (r);struct rmid_entry *entry =NULL ;int err =0 , i;u32 idx;mutex_lock (&rdtgroup_mutex);mutex is held during original allocation code below ...
Quoted 9 lines
fs/resctrl/monitor.c +0
-9-if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -u32 *tmp; - -/* -* If the architecture hasn't provided a sanitised value here, -* this may result in larger arrays than necessary. Resctrl will -* use a smaller system wide value based on the resources in -* use. -*/
Quoted 8 lines
fs/resctrl/monitor.c void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long del · line 830
Quoted 8 lines
fs/resctrl/monitor.c +0
-8- tmp =kcalloc (num_closid,sizeof (*tmp),GFP_KERNEL ); -if (!tmp) { - err = -ENOMEM ; - goto out_unlock; - } - - closid_num_dirty_rmid = tmp; - }
James,
While refactoring code, I missed moving the mutex_lock(&rdtgroup_mutex); that was protecting the allocation of "closid_num_dirty_rmid[]" ... and Reinette caught this change.
But looking at the code, I'm not at all sure what protection is needed for the allocation/free of this array. The current calling sequence for allocation is:
Linux late_init
resctrl_arch_late_init() resctrl_init() resctrl_l3_mon_resource_init dom_data_init()
which doesn't appear to provide any scope for other CPUs to come in and start using closid_num_dirty_rmid[]
The free path also seems safe too, as all resctrl functions should be shutdown before calling:
resctrl_arch_exit()
resctrl_exit() resctrl_l3_mon_resource_exit() dom_data_exit()
and if they were not, holding the rdtgroup_mutex around:
kfree(closid_num_dirty_rmid); closid_num_dirty_rmid = NULL;
would do nothing to prevent some still active resctrl function from tripping over a NULL pointer.
So, unless I'm missing something, I'm planning to address Reinette's find by documenting inmy commit message that holding rdtgroup_mutex has always been unnecessary, so it is dropped as part of this refactor.
-Tony
Luck, Tony
maintainerRe: [PATCH v9 25/31] fs/resctrl: Move allocation/free of closid_num_dirty_rmid
Quoted 32 lines · Tony
James,
While refactoring code, I missed moving the
mutex_lock(&rdtgroup_mutex); that was protecting the allocation of "closid_num_dirty_rmid[]" ... and Reinette caught this change.But looking at the code, I'm not at all sure what protection is needed for the allocation/free of this array. The current calling sequence for allocation is:
Linux
late_initresctrl_arch_late_init() resctrl_init() resctrl_l3_mon_resource_init dom_data_init()which doesn't appear to provide any scope for other CPUs to come in and start using closid_num_dirty_rmid[]
The free path also seems safe too, as all resctrl functions should be shutdown before calling:
resctrl_arch_exit()resctrl_exit() resctrl_l3_mon_resource_exit() dom_data_exit()and if they were not, holding the
rdtgroup_mutexaround:kfree(closid_num_dirty_rmid); closid_num_dirty_rmid = NULL;
Quoted 7 lines
would do nothing to prevent some still active resctrl function from tripping over a NULL pointer.
So, unless I'm missing something, I'm planning to address Reinette's find by documenting inmy commit message that holding
rdtgroup_mutexhas always been unnecessary, so it is dropped as part of this refactor.
James,
Cancel this request. Reinette pointed me at the discussions last year about allocation[1] and free[2] where you descibed how memory ordering on ARM might be a concern and the mutex makes it obvious that the access to closid_num_dirty_rmid is safe.
-Tony
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Tony Luck
maintainerPATCH v9 26/31 fs,x86/resctrl: Compute number of RMIDs as minimum across resources
In reply to Tony Luckresctrl assumes that only the L3 resource supports monitor events, so it simply takes the rdt_resource::num_rmid from RDT_RESOURCE_L3 as the system's number of RMIDs.
The addition of telemetry events in a different resource breaks that assumption.
Compute the number of available RMIDs as the minimum value across all mon_capable resources (analogous to how the number of CLOSIDs is computed across alloc_capable resources).
Note that mount time enumeration of the telemetry resource means that this number can be reduced. If this happens, then some memory will be wasted as the allocations for rdt_l3_mon_domain::states[] will be larger than needed.
--- arch/x86/kernel/cpu/resctrl/core.c | 15 +++++++++++++-- fs/resctrl/rdtgroup.c | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +13 -2
@@ -110,12 +110,23 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { }, }; +/** +* resctrl_arch_system_num_rmid_idx - Compute number of supported RMIDs +* (minimum across all mon_capable resource) +* +* Return: Number of supported RMIDs at time of call. Note that mount time +* enumeration of resources may reduce the number. +*/ u32 resctrl_arch_system_num_rmid_idx (void ) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +u32 num_rmids =U32_MAX ; +struct rdt_resource *r; + +for_each_mon_capable_rdt_resource (r) + num_rmids =min (num_rmids, r->num_rmid);/* RMID are independent numbers for x86. num_rmid_idx == num_rmid */ -return r->num_rmid; +return num_rmids ==U32_MAX ?0 : num_rmids; }struct rdt_resource *resctrl_arch_get_resource (enum resctrl_res_level l)
fs/resctrl/rdtgroup.c +5 -0
@@ -4116,6 +4116,11 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h* During boot this may be called before global allocations have been made by * resctrl_l3_mon_resource_init(). * +* This routine is called at resctrl init time. The number of supported RMIDs +* may be reduced if additional mon_capable resources are enumerated at mount +* time. This means the rdt_l3_mon_domain::mbm_states[] and +* rdt_l3_mon_domain::rmid_busy_llc allocations may be larger than needed. +* * Returns 0 for success, or -ENOMEM. */ static int domain_setup_l3_mon_state (struct rdt_resource *r,struct rdt_l3_mon_domain *d)
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 26/31] fs,x86/resctrl: Compute number of RMIDs as minimum across resources
Hi Tony,
Quoted 7 lines · Tony Luck
resctrl assumes that only the L3 resource supports monitor events, so it simply takes the
rdt_resource::num_rmidfromRDT_RESOURCE_L3as the system's number of RMIDs.The addition of telemetry events in a different resource breaks that assumption.
Quoted 7 lines
Compute the number of available RMIDs as the minimum value across all
mon_capableresources (analogous to how the number of CLOSIDs is computed acrossalloc_capableresources).Note that mount time enumeration of the telemetry resource means that this number can be reduced. If this happens, then some memory will be wasted as the allocations for rdt_l3_mon_domain::states[] will be
Same comment as v8. :(
Quoted 43 lines
larger than needed.
Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/core.c | 15 +++++++++++++-- fs/resctrl/rdtgroup.c | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/core.c +13
-2@@ -110,12 +110,23 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { }, }; +/** +* resctrl_arch_system_num_rmid_idx - Compute number of supported RMIDs +* (minimum across all mon_capable resource) +* +* Return: Number of supported RMIDs at time of call. Note that mount time +* enumeration of resources may reduce the number. +*/ u32 resctrl_arch_system_num_rmid_idx (void ) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +u32 num_rmids =U32_MAX ; +struct rdt_resource *r; + +for_each_mon_capable_rdt_resource (r) + num_rmids =min (num_rmids, r->num_rmid);/* RMID are independent numbers for x86. num_rmid_idx == num_rmid */ -return r->num_rmid; +return num_rmids ==U32_MAX ?0 : num_rmids; }struct rdt_resource *resctrl_arch_get_resource (enum resctrl_res_level l)fs/resctrl/rdtgroup.c +0
-0
fs/resctrl/rdtgroup.c void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h · line 4119
Quoted 4 lines
fs/resctrl/rdtgroup.c +1
-0@@ -4116,6 +4116,11 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h* During boot this may be called before global allocations have been made by * resctrl_l3_mon_resource_init(). * +* This routine is called at resctrl init time. The number of supported RMIDs
Regarding "This routine is called at resctrl init time.":domain_setup_l3_mon_state() is called during CPU online that can occur *any* time after resctrl init, including after resctrl mount.
How about "Called during CPU online that may run as soon as CPU online callbacks are set up during resctrl initialization."? (Or use "CPU hot plug notifiers are registered", whatever terms you decide to use consistently.)
fs/resctrl/rdtgroup.c void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h · line 4126
Quoted 7 lines
fs/resctrl/rdtgroup.c +4
-0+* may be reduced if additional mon_capable resources are enumerated at mount +* time. This means the rdt_l3_mon_domain::mbm_states[] and +* rdt_l3_mon_domain::rmid_busy_llc allocations may be larger than needed. +* * Returns 0 for success, or -ENOMEM. */ static int domain_setup_l3_mon_state (struct rdt_resource *r,struct rdt_l3_mon_domain *d)
Reinette
Tony Luck
maintainerPATCH v9 27/31 fs/resctrl: Move RMID initialization to first mount
In reply to Tony LuckL3 monitor features are enumerated during resctrl initialization and rmid_ptrs[] that tracks all RMIDs and depends on the number of supported RMIDs is allocated during this time.
Telemetry monitor features are enumerated during first resctrl mount and may support a different number of RMIDs compared to L3 monitor features.
Delay allocation and initialization of rmid_ptrs[] until first mount. Since the number of RMIDs cannot change on later mounts, keep the same set of rmid_ptrs[] until resctrl_exit().
Rename routines to match what they now do:dom_data_init() -> setup_rmid_lru_list()dom_data_exit() -> free_rmid_lru_list()
--- fs/resctrl/internal.h | 4 ++++ fs/resctrl/monitor.c | 50 ++++++++++++++----------------------------- fs/resctrl/rdtgroup.c | 7 ++++++ 3 files changed, 27 insertions(+), 34 deletions(-)
fs/resctrl/internal.h +4 -0
@@ -357,6 +357,10 @@ int closids_supported(void);void closid_free (int closid); +int setup_rmid_lru_list (void ); + +void free_rmid_lru_list (void ); +int alloc_rmid (u32 closid);void free_rmid (u32 closid,u32 rmid);
fs/resctrl/monitor.c +16 -34
107 lines not on this page · raw message
fs/resctrl/rdtgroup.c +7 -0
@@ -2599,6 +2599,12 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } +if (resctrl_arch_mon_capable ()) { + ret =setup_rmid_lru_list (); +if (ret) + goto out; + } + ret =rdtgroup_setup_root (ctx);if (ret) goto out;
@@ -4408,4 +4414,5 @@ void resctrl_exit(void)*/ resctrl_l3_mon_resource_exit (); +free_rmid_lru_list (); }
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 27/31] fs/resctrl: Move RMID initialization to first mount
Hi Tony,
Quoted 10 lines · Tony Luck
L3 monitor features are enumerated during resctrl initialization and rmid_ptrs[] that tracks all RMIDs and depends on the number of supported RMIDs is allocated during this time.
Telemetry monitor features are enumerated during first resctrl mount and may support a different number of RMIDs compared to L3 monitor features.
Delay allocation and initialization of rmid_ptrs[] until first mount. Since the number of RMIDs cannot change on later mounts, keep the same set of rmid_ptrs[] until
resctrl_exit().
Another strong reason is that the limbo handler keeps running after resctrl is unmounted and may likely need to access rmid_ptrs[] as it keeps tracking busy RMIDs after unmount.
Quoted 80 lines
Rename routines to match what they now do:
dom_data_init()->setup_rmid_lru_list()dom_data_exit()->free_rmid_lru_list()Signed-off-by Tony Luck <[email protected]>--- fs/resctrl/internal.h | 4 ++++ fs/resctrl/monitor.c | 50 ++++++++++++++----------------------------- fs/resctrl/rdtgroup.c | 7 ++++++ 3 files changed, 27 insertions(+), 34 deletions(-)fs/resctrl/internal.h +4
-0@@ -357,6 +357,10 @@ int closids_supported(void);void closid_free (int closid); +int setup_rmid_lru_list (void ); + +void free_rmid_lru_list (void ); +int alloc_rmid (u32 closid);void free_rmid (u32 closid,u32 rmid);fs/resctrl/monitor.c +13
-12@@ -802,20 +802,24 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delschedule_delayed_work_on (cpu, &dom->mbm_over, delay); } -static int dom_data_init (struct rdt_resource *r) +int setup_rmid_lru_list (void ) {u32 idx_limit =resctrl_arch_system_num_rmid_idx ();struct rmid_entry *entry =NULL ; -int err =0 , i;u32 idx; +int i; -mutex_lock (&rdtgroup_mutex); +/* +* Called on every mount, but the number of RMIDs cannot change +* after the first mount, so keep using the same set of rmid_ptrs[] +* until resctrl_exit(). +*/ +if (rmid_ptrs) +return 0 ; rmid_ptrs =kcalloc (idx_limit,sizeof (struct rmid_entry ),GFP_KERNEL ); -if (!rmid_ptrs) { - err = -ENOMEM ; - goto out_unlock; - } +if (!rmid_ptrs) +return -ENOMEM ;for (i =0 ; i < idx_limit; i++) { entry = &rmid_ptrs[i];@@ -828,30 +832,21 @@ static int dom_data_init(struct rdt_resource *r)/* * RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID are special and * are always allocated. These are used for the rdtgroup_default -* control group, which will be setup later in resctrl_init(). +* control group, which was setup earlier in rdtgroup_setup_default(). */ idx =resctrl_arch_rmid_idx_encode (RESCTRL_RESERVED_CLOSID ,RESCTRL_RESERVED_RMID ); entry =__rmid_entry (idx);list_del (&entry->list); -out_unlock: -mutex_unlock (&rdtgroup_mutex); - -return err; +return 0 ;
fs/resctrl/monitor.c static int dom_data_init(struct rdt_resource *r) · line 850
Quoted 10 lines
fs/resctrl/monitor.c +1
-5} -static void dom_data_exit (struct rdt_resource *r) +void free_rmid_lru_list (void ) {mutex_lock (&rdtgroup_mutex); - -if (!r->mon_capable) - goto out_unlock; -
Can use resctrl_arch_mon_capable() instead to keep this check while maintaining symmetry with setup_rmid_lru_list() that will make this easier to follow? Having the resctrl_arch_mon_capable() check within setup_rmid_lru_list() will also help.
Quoted 42 lines
fs/resctrl/monitor.c +2
-13kfree (rmid_ptrs); rmid_ptrs =NULL ; - -out_unlock:mutex_unlock (&rdtgroup_mutex); }@@ -914,7 +909,8 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid)* resctrl_l3_mon_resource_init() - Initialise global monitoring structures. * * Allocate and initialise global monitor resources that do not belong to a -* specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists. +* specific domain. i.e. the closid_num_dirty_rmid[] used to find the CLOSID +* with the cleanest set of RMIDs. * Called once during boot after the struct rdt_resource's have been configured * but before the filesystem is mounted. * Resctrl's cpuhp callbacks may be called before this point to bring a domain @@ -925,7 +921,6 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid)int resctrl_l3_mon_resource_init (void ) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -int ret;if (!r->mon_capable)return 0 ;@@ -947,15 +942,6 @@ int resctrl_l3_mon_resource_init(void) closid_num_dirty_rmid = tmp; } - ret =dom_data_init (r); -if (ret) { -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } -return ret; - } -if (resctrl_arch_is_evt_configurable (QOS_L3_MBM_TOTAL_EVENT_ID )) { mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID ].configurable = true; resctrl_file_fflags_init("mbm_total_bytes_config",
fs/resctrl/monitor.c int resctrl_l3_mon_resource_init(void) · line 981
Quoted 5 lines
fs/resctrl/monitor.c +0
-2@@ -977,12 +963,8 @@ int resctrl_l3_mon_resource_init(void)void resctrl_l3_mon_resource_exit (void ) { -struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -
As mentioned earlier, please try to maintain symmetry with resctrl_l3_mon_resource_init().
Quoted 12 lines
fs/resctrl/monitor.c +0
-2if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) {kfree (closid_num_dirty_rmid); closid_num_dirty_rmid =NULL ; } - -dom_data_exit (r); }fs/resctrl/rdtgroup.c +0
-0
fs/resctrl/rdtgroup.c static int rdt_get_tree(struct fs_context *fc) · line 2606
Quoted 8 lines
fs/resctrl/rdtgroup.c +5
-0@@ -2599,6 +2599,12 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } +if (resctrl_arch_mon_capable ()) { + ret =setup_rmid_lru_list (); +if (ret) + goto out; + }
As mentioned earlier, please try to make code symmetrical to make this easier to understand. As this is written the reader sees that setup_rmid_lru_list() needs to be protected by resctrl_arch_mon_capable() while free_rmid_lru_list() can always be called whether system is monitoring capable or not. This creates confusion that symmetrical code can help with.
fs/resctrl/rdtgroup.c void resctrl_exit(void) · line 4418
Quoted 10 lines
fs/resctrl/rdtgroup.c +2
-0+ ret =rdtgroup_setup_root (ctx);if (ret) goto out;@@ -4408,4 +4414,5 @@ void resctrl_exit(void)*/ resctrl_l3_mon_resource_exit (); +free_rmid_lru_list (); }
Reinette
Tony Luck
maintainerPATCH v9 28/31 x86/resctrl: Enable RDT_RESOURCE_PERF_PKG
In reply to Tony LuckThe RDT_RESOURCE_PERF_PKG resource is not marked as "mon_capable" during early resctrl initialization. This means that the domain lists for the resource are not built when the CPU hot plug notifiers are registered.
Set the global rdt_mon_capable (to cover the case when none of the L3 monitor events are enabled).
Mark the resource as mon_capable and call domain_add_cpu_mon() for each online CPU to build the domain lists in the first call to the resctrl_arch_pre_mount() hook.
--- arch/x86/kernel/cpu/resctrl/core.c | 17 ++++++++++++++++- arch/x86/kernel/cpu/resctrl/intel_aet.c | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/core.c +16 -1
@@ -753,14 +753,29 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)void resctrl_arch_pre_mount (void ) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG ].r_resctrl;static atomic_t only_once =ATOMIC_INIT (0 ); -int old =0 ; +int cpu, old =0 ;if (!atomic_try_cmpxchg (&only_once, &old,1 ))return ;if (!intel_aet_get_events ())return ; + +if (!r->mon_capable) +return ; + +/* +* Late discovery of telemetry events means the domains for the +* resource were not built. Do that now. +*/ +cpus_read_lock (); +mutex_lock (&domain_list_lock); +for_each_online_cpu (cpu) +domain_add_cpu_mon (cpu, r); +mutex_unlock (&domain_list_lock); +cpus_read_unlock (); }enum {
arch/x86/kernel/cpu/resctrl/intel_aet.c +5 -0
@@ -182,6 +182,9 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)if (!usable_events)return false; + r->mon_capable = true; + rdt_mon_capable = true; +if (r->num_rmid) r->num_rmid =min (r->num_rmid, e->num_rmids);else
@@ -191,6 +194,8 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)resctrl_enable_mon_event (e->evts[j].id, true, e->evts[j].bin_bits, &e->evts[j]); +pr_info ("%s %s monitoring detected\n" , r->name, e->name); +return true; }
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 28/31] x86/resctrl: Enable RDT_RESOURCE_PERF_PKG
Hi Tony,
Quoted 10 lines · Tony Luck
The
RDT_RESOURCE_PERF_PKGresource is not marked as "mon_capable" during early resctrl initialization. This means that the domain lists for the resource are not built when the CPU hot plug notifiers are registered.Set the global
rdt_mon_capable(to cover the case when none of the L3 monitor events are enabled).Mark the resource as
mon_capableand calldomain_add_cpu_mon()for each online CPU to build the domain lists in the first call to theresctrl_arch_pre_mount()hook.
This just describes what can be seen in patch.
Reinette
Tony Luck
maintainerPATCH v9 29/31 fs/resctrl: Provide interface to create architecture specific debugfs area
In reply to Tony LuckAll files below /sys/fs/resctrl are considered user ABI.
This leaves no place for architectures to provide additional interfaces.
Add resctrl_debugfs_mon_info_arch_mkdir() which creates a directory in the debugfs file system for a monitoring resource. Naming follows the layout of the main resctrl hierarchy:
/sys/kernel/debug/resctrl/info/{resource}_MON/{arch}The {arch} last level directory name matches the output of the user level "uname -m" command.
Architecture code may use this directory for debug information, or for minor tuning of features. It must not be used for basic feature enabling as debugfs may not be configured/mounted on production systems.
--- include/linux/resctrl.h | 9 +++++++++ fs/resctrl/rdtgroup.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
include/linux/resctrl.h +9 -0
@@ -569,6 +569,15 @@ void resctrl_arch_reset_all_ctrls(struct rdt_resource *r);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit; +/** +* resctrl_debugfs_mon_info_arch_mkdir() - Create a debugfs info directory. +* Removed by resctrl_exit(). +* @r: Resource (must be mon_capable). +* +* Return: dentry pointer on success, or NULL on error. +*/ +struct dentry *resctrl_debugfs_mon_info_arch_mkdir (struct rdt_resource *r); +int resctrl_init (void );void resctrl_exit (void );
fs/resctrl/rdtgroup.c +29 -0
@@ -24,6 +24,7 @@#include <linux/sched/task.h> #include <linux/slab.h> #include <linux/user_namespace.h> +#include <linux/utsname.h> #include <uapi/linux/magic.h>
@@ -75,6 +76,8 @@ static void rdtgroup_destroy_root(void);struct dentry *debugfs_resctrl; +static struct dentry *debugfs_resctrl_info; +/* * 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
@@ -4355,6 +4358,31 @@ int resctrl_init(void)return ret; } +/* +* Create /sys/kernel/debug/resctrl/info/{r->name}_MON/{arch} directory +* by request for architecture to use for debugging or minor tuning. +* Basic functionality of features must not be controlled by files +* added to this directory as debugfs may not be configured/mounted +* on production systems. +*/ +struct dentry *resctrl_debugfs_mon_info_arch_mkdir (struct rdt_resource *r) +{ +struct dentry *moninfodir; +char name[32 ]; + +if (!r->mon_capable) +return NULL ; + +if (!debugfs_resctrl_info) + debugfs_resctrl_info =debugfs_create_dir ("info" , debugfs_resctrl); + +sprintf (name,"%s_MON" , r->name); + + moninfodir =debugfs_create_dir (name, debugfs_resctrl_info); + +return debugfs_create_dir (utsname ()->machine, moninfodir); +} +static bool resctrl_online_domains_exist (void ) {struct rdt_resource *r;
@@ -4406,6 +4434,7 @@ void resctrl_exit(void)debugfs_remove_recursive (debugfs_resctrl); debugfs_resctrl =NULL ; + debugfs_resctrl_info =NULL ;unregister_filesystem (&rdt_fs_type);/*
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 29/31] fs/resctrl: Provide interface to create architecture specific debugfs area
Hi Tony,
Quoted 5 lines · Tony Luck
include/linux/resctrl.h +0
-0
include/linux/resctrl.h void resctrl_arch_reset_all_ctrls(struct rdt_resource *r); · line 577
Quoted 9 lines
include/linux/resctrl.h +6
-0@@ -569,6 +569,15 @@ void resctrl_arch_reset_all_ctrls(struct rdt_resource *r);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit; +/** +* resctrl_debugfs_mon_info_arch_mkdir() - Create a debugfs info directory. +* Removed by resctrl_exit(). +* @r: Resource (must be mon_capable). +* +* Return: dentry pointer on success, or NULL on error.
NULL is returned if resource is not monitoring capable, otherwise it returns debugfs_create_dir() which is ERR_PTR(-ERROR) on failure.
Reinette
Tony Luck
maintainerPATCH v9 30/31 x86/resctrl: Add debugfs files to show telemetry aggregator status
In reply to Tony LuckEach telemetry aggregator provides three status registers at the top end of MMIO space after all the per-RMID per-event counters:
data_loss_count: This counts the number of times that this aggregator failed to accumulate a counter value supplied by a CPU core.
data_loss_timestamp: This is a "timestamp" from a free running 25MHz uncore timer indicating when the most recent data loss occurred.
last_update_timestamp: Another 25MHz timestamp indicating when the most recent counter update was successfully applied.
Create files in /sys/kernel/debug/resctrl/info/PERF_PKG_MON/x86_64/ to display the value of each of these status registers for each aggregator in each enabled event group. The prefix for each file name describes the type of aggregator and its location. The suffix is one of the three strings listed above. An example name is:
energy_pkg0_agg2_data_loss_count
These files are removed along with all other debugfs entries by the call to debugfs_remove_recursive() in resctrl_exit().
--- arch/x86/kernel/cpu/resctrl/intel_aet.c | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
arch/x86/kernel/cpu/resctrl/intel_aet.c +48 -0
@@ -13,6 +13,7 @@#include <linux/cleanup.h> #include <linux/cpu.h> +#include <linux/debugfs.h> #include <linux/intel_vsec.h> #include <linux/io.h> #include <linux/minmax.h>
@@ -148,9 +149,50 @@ static bool all_regions_have_sufficient_rmid(struct event_group *e, struct pmt_freturn true; } +static int status_read (void *priv,u64 *val) +{ +void __iomem *info = (void __iomem *)priv; + + *val =readq (info); + +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (status_fops, status_read,NULL ,"%llu\n" ); + +static void make_status_files (struct dentry *dir,struct event_group *e,int pkg, +int instance,void *info_end) +{ +char name[64 ]; + +sprintf (name,"%s_pkg%d_agg%d_data_loss_count" , e->name, pkg, instance); +debugfs_create_file (name,0400 , dir, info_end -24 , &status_fops); + +sprintf (name,"%s_pkg%d_agg%d_data_loss_timestamp" , e->name, pkg, instance); +debugfs_create_file (name,0400 , dir, info_end -16 , &status_fops); + +sprintf (name,"%s_pkg%d_agg%d_last_update_timestamp" , e->name, pkg, instance); +debugfs_create_file (name,0400 , dir, info_end -8 , &status_fops); +} + +static void create_debug_event_status_files (struct dentry *dir,struct event_group *e, +struct pmt_feature_group *p) +{ +void *info_end; + +for (int i =0 ; i < p->count; i++) { +if (!p->regions[i].addr) +continue ; + info_end = (void __force *)p->regions[i].addr + e->mmio_size; +make_status_files (dir, e, p->regions[i].plat_info.package_id, + i, info_end); + } +} +static bool enable_events (struct event_group *e,struct pmt_feature_group *p) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG ].r_resctrl; +static struct dentry *infodir;bool usable_events = false;/* Disable feature if insufficient RMIDs */
@@ -194,6 +236,12 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)resctrl_enable_mon_event (e->evts[j].id, true, e->evts[j].bin_bits, &e->evts[j]); +if (!infodir) + infodir =resctrl_debugfs_mon_info_arch_mkdir (r); + +if (infodir) +create_debug_event_status_files (infodir, e, p); +pr_info ("%s %s monitoring detected\n" , r->name, e->name);return true;
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 30/31] x86/resctrl: Add debugfs files to show telemetry aggregator status
Hi Tony,
arch/x86/kernel/cpu/resctrl/intel_aet.c static bool enable_events(struct event_group *e, struct pmt_feature_group *p) · line 242
Quoted 8 lines · Tony Luck
arch/x86/kernel/cpu/resctrl/intel_aet.c +4
-0@@ -194,6 +236,12 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)resctrl_enable_mon_event (e->evts[j].id, true, e->evts[j].bin_bits, &e->evts[j]); +if (!infodir) + infodir =resctrl_debugfs_mon_info_arch_mkdir (r); + +if (infodir)
if (!IS_ERR_OR_NULL(infodir))?
arch/x86/kernel/cpu/resctrl/intel_aet.c static bool enable_events(struct event_group *e, struct pmt_feature_group *p) · line 247
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/intel_aet.c +2
-0+create_debug_event_status_files (infodir, e, p); +pr_info ("%s %s monitoring detected\n" , r->name, e->name);return true;
Reinette
Tony Luck
maintainerPATCH v9 31/31 x86,fs/resctrl: Update Documentation for package events
In reply to Tony LuckUpdate resctrl filesystem documentation with the details about the resctrl files that support telemetry events.
--- Documentation/filesystems/resctrl.rst | 99 +++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 13 deletions(-)
Documentation/filesystems/resctrl.rst +86 -13
@@ -167,13 +167,12 @@ with respect to allocation: bandwidth percentages are directly applied to the threads running on the core -If RDT monitoring is available there will be an "L3_MON" directory +If L3 monitoring is available there will be an "L3_MON" directory with the following files: "num_rmids": - The number of RMIDs available. This is the - upper bound for how many "CTRL_MON" + "MON" - groups can be created. + The number of RMIDs supported by hardware for + L3 monitoring events. "mon_features": Lists the monitoring events if
@@ -261,6 +260,19 @@ with the following files: bytes) at which a previously used LLC_occupancy counter can be considered for re-use. +If telemetry monitoring is available there will be an "PERF_PKG_MON" directory +with the following files: + +"num_rmids": + The number of RMIDs supported by hardware for + telemetry monitoring events. + +"mon_features": + Lists the telemetry monitoring events that are enabled on this system. + +The upper bound for how many "CTRL_MON" + "MON" can be created +is the smaller of the "num_rmids" values. + Finally, in the top level of the "info" directory there is a file named "last_cmd_status". This is reset with every "command" issued via the file system (making new directories or writing to any of the
@@ -366,15 +378,38 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", - "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these - files provide a read out of the current value of the event for - all tasks in the group. In CTRL_MON groups these files provide - the sum for all tasks in the CTRL_MON group and all tasks in - MON groups. Please see example section for more details on usage. + This contains a set of directories, one for each instance + of an L3 cache, another for each processor package. The L3 cache + directories are named "mon_L3_00", "mon_L3_01" etc. The + package directories "mon_PERF_PKG_00", "mon_PERF_PKG_01" etc. + + Within each directory there is one file per event. For + example the L3 directories may contain "llc_occupancy", "mbm_total_bytes", + and "mbm_local_bytes". The PERF_PKG directories may contain "core_energy", + "activity", etc. + + "core energy" reports a floating point number for the energy (in Joules) + consumed by cores (registers, arithmetic units, TLB and L1/L2 caches) + during execution of instructions summed across all logical CPUs on a + package for the current RMID. + + "activity" also reports a floating point value (in Farads). + This provides an estimate of work done independent of the + frequency that the CPUs used for execution. + + Note that these two counters only measure energy/activity + in the "core" of the CPU (arithmetic units, TLB, L1 and L2 + caches, etc.). They do not include L3 cache, memory, I/O + devices etc. + + All other events report decimal integer values. + + In a MON group these files provide a read out of the current + value of the event for all tasks in the group. In CTRL_MON groups + these files provide the sum for all tasks in the CTRL_MON group + and all tasks in MON groups. Please see example section for more + details on usage. + On systems with Sub-NUMA Cluster (SNC) enabled there are extra directories for each node (located within the "mon_L3_XX" directory for the L3 cache they occupy). These are named "mon_sub_L3_YY"
@@ -1300,6 +1335,44 @@ Example with C:: resctrl_release_lock(fd); } +Debugfs +======= +In addition to the use of debugfs for tracing of pseudo-locking +performance, architecture code may create debugfs directories +associated with monitoring features for a specific resource. + +The full pathname for these is in the form: + + /sys/kernel/debug/resctrl/info/{resource_name}_MON/{arch}/ + +The presence, names, and format of these files will vary +between architectures even if the same resource is present. + +PERF_PKG_MON/x86_64 +------------------- +Three files are present per telemetry aggregator instance +that show when and how often the hardware has failed to +collect and accumulate data from the CPUs. The prefix of +each file name describes the type ("energy" or "perf") which +processor package it belongs to, and the instance number of +the aggregator. For example: "energy_pkg1_agg2". + +The suffix describes which data is reported in the file and +is one of: + +data_loss_count: + This counts the number of times that this aggregator + failed to accumulate a counter value supplied by a CPU. + +data_loss_timestamp: + This is a "timestamp" from a free running 25MHz uncore + timer indicating when the most recent data loss occurred. + +last_update_timestamp: + Another 25MHz timestamp indicating when the + most recent counter update was successfully applied. + + Examples for RDT Monitoring along with allocation usage ======================================================= Reading monitored data
Signature · 1 line
2.50.1
Reinette Chatre
maintainerRe: [PATCH v9 31/31] x86,fs/resctrl: Update Documentation for package events
Hi Tony,
Quoted 35 lines · Tony Luck
Update resctrl filesystem documentation with the details about the resctrl files that support telemetry events.
Signed-off-by Tony Luck <[email protected]>--- Documentation/filesystems/resctrl.rst | 99 +++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 13 deletions(-)Documentation/filesystems/resctrl.rst +5
-4@@ -167,13 +167,12 @@ with respect to allocation: bandwidth percentages are directly applied to the threads running on the core -If RDT monitoring is available there will be an "L3_MON" directory +If L3 monitoring is available there will be an "L3_MON" directory with the following files: "num_rmids": - The number of RMIDs available. This is the - upper bound for how many "CTRL_MON" + "MON" - groups can be created. + The number of RMIDs supported by hardware for + L3 monitoring events. "mon_features": Lists the monitoring events if@@ -261,6 +260,19 @@ with the following files: bytes) at which a previously used LLC_occupancy counter can be considered for re-use. +If telemetry monitoring is available there will be an "PERF_PKG_MON" directory +with the following files:
Documentation/filesystems/resctrl.rst with the following files: · line 274
Quoted 10 lines
Documentation/filesystems/resctrl.rst +10
-0+ +"num_rmids": + The number of RMIDs supported by hardware for + telemetry monitoring events. + +"mon_features": + Lists the telemetry monitoring events that are enabled on this system. + +The upper bound for how many "CTRL_MON" + "MON" can be created +is the smaller of the "num_rmids" values.
To be specific this can be "smaller of the L3_MON and PERF_PKG_MON "num_rmids" values."
Quoted 9 lines
Documentation/filesystems/resctrl.rst +1
-1+ Finally, in the top level of the "info" directory there is a file named "last_cmd_status". This is reset with every "command" issued via the file system (making new directories or writing to any of the@@ -366,15 +378,38 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by
Documentation/filesystems/resctrl.rst When control is enabled all CTRL_MON groups will also contain: · line 382
Quoted 10 lines
Documentation/filesystems/resctrl.rst +2
-8- RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", - "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these - files provide a read out of the current value of the event for - all tasks in the group. In CTRL_MON groups these files provide - the sum for all tasks in the CTRL_MON group and all tasks in - MON groups. Please see example section for more details on usage. + This contains a set of directories, one for each instance + of an L3 cache, another for each processor package. The L3 cache
... so two sets of directories? I am not able to parse.
Documentation/filesystems/resctrl.rst When control is enabled all CTRL_MON groups will also contain: · line 389
Quoted 7 lines
Documentation/filesystems/resctrl.rst +7
-0+ directories are named "mon_L3_00", "mon_L3_01" etc. The + package directories "mon_PERF_PKG_00", "mon_PERF_PKG_01" etc. + + Within each directory there is one file per event. For + example the L3 directories may contain "llc_occupancy", "mbm_total_bytes", + and "mbm_local_bytes". The PERF_PKG directories may contain "core_energy", + "activity", etc.
It can help to append information how user can exactly know which files can be expected (by looking at mon_features file).
Quoted 31 lines
Documentation/filesystems/resctrl.rst +24
-0+ + "core energy" reports a floating point number for the energy (in Joules) + consumed by cores (registers, arithmetic units, TLB and L1/L2 caches) + during execution of instructions summed across all logical CPUs on a + package for the current RMID. + + "activity" also reports a floating point value (in Farads). + This provides an estimate of work done independent of the + frequency that the CPUs used for execution. + + Note that these two counters only measure energy/activity + in the "core" of the CPU (arithmetic units, TLB, L1 and L2 + caches, etc.). They do not include L3 cache, memory, I/O + devices etc. + + All other events report decimal integer values. + + In a MON group these files provide a read out of the current + value of the event for all tasks in the group. In CTRL_MON groups + these files provide the sum for all tasks in the CTRL_MON group + and all tasks in MON groups. Please see example section for more + details on usage. + On systems with Sub-NUMA Cluster (SNC) enabled there are extra directories for each node (located within the "mon_L3_XX" directory for the L3 cache they occupy). These are named "mon_sub_L3_YY"@@ -1300,6 +1335,44 @@ Example with C:: resctrl_release_lock(fd); } +Debugfs
Documentation/filesystems/resctrl.rst Example with C:: · line 1348
Quoted 10 lines
Documentation/filesystems/resctrl.rst +10
-0+======= +In addition to the use of debugfs for tracing of pseudo-locking +performance, architecture code may create debugfs directories +associated with monitoring features for a specific resource. + +The full pathname for these is in the form: + + /sys/kernel/debug/resctrl/info/{resource_name}_MON/{arch}/ + +The presence, names, and format of these files will vary
Same comment as in v8.
Documentation/filesystems/resctrl.rst Example with C:: · line 1354
Quoted 6 lines
Documentation/filesystems/resctrl.rst +6
-0+between architectures even if the same resource is present. + +PERF_PKG_MON/x86_64 +------------------- +Three files are present per telemetry aggregator instance +that show when and how often the hardware has failed to
Sounds like all three files are related to failures, but I do not believe they are.
Documentation/filesystems/resctrl.rst Example with C:: · line 1358
Quoted 4 lines
Documentation/filesystems/resctrl.rst +4
-0+collect and accumulate data from the CPUs. The prefix of +each file name describes the type ("energy" or "perf") which +processor package it belongs to, and the instance number of +the aggregator. For example: "energy_pkg1_agg2".
The "instance number" is assigned/enumerated by INTEL_PMT_TELEMETRY. Does this have consistent and clear meaning to user space?
Reinette
Luck, Tony
maintainerApplied changes from Ilpo's review of parts 17..22
Updated patches posted as replies to Ilpo's emails.
Also found some other missing #include, so added those too.
Updated series at:
git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git rdt-aet-v10-wip
-Tony