Skip to contentSkip to conversation

x86,fs/resctrl: Support AMD Assignable Bandwidth Monitoring Counters (ABMC)

PATCH Superseded Babu Moger 3 participants 93 messages Jul 25, 2025 – Aug 12, 2025

Subsystems (3)

v16 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Babu Moger

author reviewer
#0 lore raw

v16 cover x86,fs/resctrl: Support AMD Assignable Bandwidth Monitoring Counters (ABMC)

This series adds the support for Assignable Bandwidth Monitoring Counters (ABMC). It is also called QoS RMID Pinning feature.

Series is written such that it is easier to support other assignable features supported from different vendors.

The feature details are documented in the APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). The documentation is available at

The patches are based on top of commit (6.16.0-rc7) commit 34481698fd9c ("Merge branch into tip/master: 'x86/sev'")

# Introduction

Users can create as many monitor groups as RMIDs supported by the hardware. However, the bandwidth monitoring feature on AMD systems only guarantees that RMIDs currently assigned to a processor will be tracked by hardware. The counters of any other RMIDs which are no longer being tracked will be reset to zero. The MBM event counters return "Unavailable" for the RMIDs that are not tracked by hardware. So, there can be only limited number of groups that can give guaranteed monitoring numbers. With ever changing configurations there is no way to definitely know which of these groups are being tracked during a particular time. Users do not have the option to monitor a group or set of groups for a certain period of time without worrying about counters being reset in between.

The ABMC feature allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Additionally, the user can specify the type of memory transactions (e.g., reads, writes) to be tracked by the counter for the assigned RMID.

Without ABMC enabled, monitoring will work in current 'default' mode without assignment option.

# History

Earlier implementation of ABMC had dependancy on BMEC (Bandwidth Monitoring Event Configuration). Peter had concerns with that implementation because it may be not be compatible with ARM's MPAM.

Here are the threads discussing the concerns and new interface to address the concerns.
https://lore.kernel.org/lkml/CALPaoCg97cLVVAcacnarp+880xjsedEWGJPXhYpy4P7=ky4MZw@mail.gmail.com/
https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=kVLBzhfNo0SFqt4kQGwGSGVUqvr2Dg@mail.gmail.com/

Here are the finalized requirements based on the discussion:

* BMEC and ABMC are incompatible with each other. They need to be mutually exclusive.

* Eliminate global assignment listing. The interface
/sys/fs/resctrl/info/L3_MON/mbm_assign_control is no longer required.

* Create the configuration directories at /sys/fs/resctrl/info/L3_MON/counter_configs/.
The configuration file names should be free-form, allowing users to create them as needed.

* Perform assignment listing at the group level by introducing mbm_L3_assignments
in each monitoring group level. The listing should provide the following details:

Event Configuration: Specifies the event configuration applied. This will be crucial when "mkdir" on event configuration is added in the future, leading to the creation of mon_data/mon_l3_*/<event configuration>.

Domains: Identifies the domains where the configuration is applied, supporting multi-domain setups.

Assignment Type: Indicates whether the assignment is Exclusive (e or d), Shared (s), or Unassigned (_).

Exclusive assignment: Assign the counter ID the RMID, event pair exclusively.

Shared assignment: A shared assignment applies to both soft-ABMC and ABMC. A user can designate a
"counter" (could be hardware counter or "active" RMID) as shared and that means the counter within that domain is shared between different monitor groups and actual assignment is scheduled by resctrl.

Unassigned: No longer assigned.

* Provide option to enable or disable auto assignment when new group is created.

* Keep the flexibility to support future assign options like Soft-ABMC etc.

    https://lore.kernel.org/lkml/[email protected]/

This series addresses the requirements listed above and keeping the options open for future enhancements.

# Implementation details

Create a generic interface to support user space assignment of scarce counters used for monitoring. First usage of interface is by ABMC with option to expand usage to "soft-ABMC" and MPAM counters in future.

Feature adds following interface files:

/sys/fs/resctrl/info/L3_MON/mbm_assign_mode: Reports the list of assignable monitoring features supported. The enclosed brackets indicate which feature is enabled.

/sys/fs/resctrl/info/L3_MON/num_mbm_cntrs: The maximum number of monitoring counters (total of available and assigned counters) in each domain when the system supports mbm_event mode.

/sys/fs/resctrl/info/L3_MON/available_mbm_cntrs: The number of monitoring counters available for assignment in each domain when mbm_event mode is enabled on the system.

/sys/fs/resctrl/info/L3_MON/event_configs: Contains sub-directory for each MBM event
that can be assigned to a counter.

/sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter: The type of
memory transactions tracked by the event mbm_total_bytes.

/sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter: The type of
memory transactions tracked by the event mbm_local_bytes.

/sys/fs/resctrl/mbm_L3_assignments: Per monitor group interface to list or modify
counters assigned to the group.

# Examples

a. Check if MBM assign support is available
#mount -t resctrl resctrl /sys/fs/resctrl/

# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_event]
default

mbm_event feature is detected and it is enabled.

b. Check how many assignable counters are supported.

	# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 
	0=32;1=32

c. Check how many assignable counters are available for assignment in each domain.

	# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 
	0=30;1=30

d. Check the default event configuration.

	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter 
	local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
        local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter 
	local_reads,local_non_temporal_writes,local_reads_slow_memory

e. Series adds a new interface file "mbm_L3_assignments" in each monitoring group
to list and modify that group's monitoring states.

The list is displayed in the following format:

<Event>:<Domain id>=<Assignment state>;<Domain id>=<Assignment state>

Event: A valid MBM event listed in the /sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID.

Assignment types:

_ : No counter assigned.

e : Counter assigned exclusively.

To list the default group states:
# cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on domain 0:
# echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments # cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=_;1=e
mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on all domains:
# echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
# cat /sys/fs/resctrl/mbm_L3_assignment
mbm_total_bytes:0=_;1=_
mbm_local_bytes:0=e;1=e

To assign a counter associated with the mbm_total_bytes event on all domains in exclusive mode:
# echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
# cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

g. Read the events mbm_total_bytes and mbm_local_bytes of the default group.
There is no change in reading the events with the assignment. If the event is unassigned when reading, then the read will come back as "Unassigned".

	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes
	779247936
	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes 
	765207488

h. Check the event configurations.

	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
	local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
	local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
	# cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
	local_reads,local_non_temporal_writes,local_reads_slow_memory

i. Change the event configuration for mbm_local_bytes.

	# echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
	/sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	# cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads

This will update all (across all domains of all monitor groups) counter assignments associated with the mbm_local_bytes event.

j. Now read the local event again. The first read may come back with "Unavailable"
status. The subsequent read of mbm_local_bytes will display the current value.

	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
	Unavailable
	# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
	314101

k. Users have the option to go back to 'default' mbm_assign_mode if required.
This can be done using the following command. Note that switching the mbm_assign_mode will reset all the MBM counters (and thus all MBM events) of all the resctrl groups.

	# echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
	# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
	mbm_event
	[default]

l. Unmount the resctrl filesystem.

	# umount /sys/fs/resctrl/
---
v16:
    Picked up first four patches from (Tony):
    https://lore.kernel.org/lkml/[email protected]/
    These patches have already been reviewed.

Updated Reviewed-by: tag for few patches.

Fixed the conflicts with latest cpufeatures.h and scattered.c files.

Added a new check in get_rdt_mon_resources().
Added check in resctrl_is_mon_event_enabled() before enabling.

Resetting the architectural state in resctrl_arch_config_cntr() in both assign and unassign cases now.

Function renames:
resctrl_config_cntr() -> rdtgroup_assign_cntr() rdtgroup_alloc_config_cntr() -> rdtgroup_alloc_assign_cntr()

Passed struct mevt to rdtgroup_alloc_assign_cntr so it can print event name on failure.

Function rename:
rdtgroup_free_config_cntr() -> rdtgroup_free_unassign_cntr().

Updated rdtgroup_free_unassign_cntr() to pass struct mon_evt to match rdtgroup_alloc_assign_cntr() prototype.

Removed lots of copied and unnecessary text from resctrl.h. Also removed references to LLC occupancy.
Removed arch_mon_ctx from resctrl_arch_cntr_read().

Renamed get_corrected_val() -> get_corrected_val().

Removed the call resctrl_arch_rmid_read_context_check(); Added the text about RMID_VAL_UNAVAIL error.

Squashed two patches into one.
https://lore.kernel.org/lkml/df215f02db88cad714755cd5275f20cf0ee4ae26.1752013061.git.babu.moger@amd.com/
https://lore.kernel.org/lkml/296c435e9bf63fc5031114cced00fbb4837ad327.1752013061.git.babu.moger@amd.com/

Changed is_cntr field in struct rmid_read to is_mbm_cntr. Fixed the memory leak with arch_mon_ctx. Updated the resctrl.rst user doc.

Report Unassigned only if none of the events in CTRL_MON and MON are assigned.

Moved event_filter_show() to fs/resctrl/monitor.c

Added rdtgroup_mutex in event_filter_show(). Removed extern for mbm_transactions. Not required.

Moved resctrl_process_configs() and event_filter_write() to fs/resctrl/monitor.c.

Renamed resctrl_process_configs() -> resctrl_parse_mem_transactions().

Fixed the return in resctrl_mbm_assign_on_mkdir_write().

Moved r->mon.mbm_assign_on_mkdir initialization to resctrl_mon_resource_init().

Updated resctrl.rst few corrections and consistancy.

Fixed few references of counter_configs to -> event_configs.
Renamed resctrl_process_assign() to resctrl_parse_mbm_assignment(). Moved resctrl_parse_mbm_assignment() and rdtgroup_modify_assign_state() to monitor.c.

Added new comment in resctrl_bmec_files_show() about kernfs_find_and_get failure. Added the parameter to resctrl_bmec_files_show() to pass the kernfs_node. Updated resctrl_bmec_files_show() to pass NULL for kn_fs_node.

Added a patch to add me as a reviewer on Reinette's suggestion.

v15:
1-4 Picked up Tony's tree. This will be base for both the series. rdt-aet-v5.5 branch of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git
After Reinette's comment on previous version.
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

Improved changelog in most of the patches. Thanks to Reinette. Improved the code comment in few places.

Fixed the enumeration code by adding check in resctrl_cpu_detect() during the init. Moved the fs related enumeration to resctrl_mon_resource_init().

Removed evt_cfg from struct mbm_cntr_cfg based on the discussion.
https://lore.kernel.org/lkml/[email protected]/

Removed resctrl_set_mon_evt_cfg().
Moved the event initialization to resctrl_mon_resource_init().

Changed few goto labels for consistency.

Added extra check !r->mon.mbm_cntr_assignable in mbm_cntr_get() to return error.

Added two new arch calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() implement mbm_event mode. This is kind of major change in this series.
https://lore.kernel.org/lkml/[email protected]/

Added is_cntr in rmid_read to implement resctrl_arch_cntr_read() and resctrl_arch_reset_cntr().

Removed the error setting in rdtgroup_mondata_show(). It is already done in mon_event_read() based on the discussion.
https://lore.kernel.org/lkml/[email protected]/

Changed the function name resctrl_mkdir_counter_configs() to resctrl_mkdir_event_configs(). Called resctrl_mkdir_event_configs from rdtgroup_mkdir_info_resdir().
It avoids the call kernfs_find_and_get() to get the node for info directory. Used for_each_mon_event() where applicable.

Fixed the partial initialization of val in resctrl_process_configs().
Passed mon_evt where applicable. The struct rdt_resource can be obtained from mon_evt::rid.

Fixed the static checker warning in resctrl_mbm_assign_on_mkdir_write() reported in
https://lore.kernel.org/lkml/[email protected]/

Moved resctrl_bmec_files_show() inside rdtgroup_mkdir_info_resdir().

v14:
Patch #1 is already been reviewed. Not need to review.

Patches # 2-5:
This is Tony's work. This is part of Tony's telemetry series.
https://lore.kernel.org/lkml/[email protected]/

Tony made special update for me to include in this series.
https://lore.kernel.org/lkml/[email protected]/.
We both are going to carry thesse mutliple events support patches.

Patches #6-31 are changes related to mbm_assign_mode.

Took time to check all the text comments. Taken care most of comments. Anything missing is not intentional. ):

Removed the dependancy on X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL as discussed in https://lore.kernel.org/lkml/[email protected]/
Reworked on ABMC enumeration during the init.

Updated the code comment in resctrl.h on all the prototypes.

Added lockdep_assert_cpus_held() in _resctrl_abmc_enable(). Removed inline for resctrl_arch_mbm_cntr_assign_enabled(). Added prototype descriptions for resctrl_arch_mbm_cntr_assign_enabled() and resctrl_arch_mbm_cntr_assign_set() in include/linux/resctrl.h.

Changed the name of the monitor mode to mbm_event_assign based on the discussion.
https://lore.kernel.org/lkml/[email protected]/
Updated resctrl.rst for mbm_event mode.
Changed subject line to fs/resctrl in few patches.

Removed BMEC reference internal.h.

Removed mbm_mode in mon_evt data structure as it is not required anymore. Added resctrl_get_mon_evt_cfg() and resctrl_set_mon_evt_cfg().

Removed evt_cfg parameter in resctrl_arch_config_cntr(). Get evt_cfg only when assign is required.

Updated the code documentation for mbm_cntr_alloc() and mbm_cntr_get(). Passed struct mon_evt to resctrl_assign_cntr_event() that way to avoid back and forth calls to get event details.

Passing the struct mon_evt to resctrl_free_config_cntr() and removed the need for mbm_get_mon_event() call.
Corrected the code documentation for mbm_cntr_free().

Added WARN_ON_ONCE() when cntr_id < 0.
Improved code documentation in include/linux/resctrl.h.
Added the check in mbm_update() to skip overflow handler when counter is unassigned.

Changed the term memory events to memory transactions to be consistant.

Changed the name of directory to event_configs from counter_config. Updated user doc about the memory transactions supported by assignment.

Renamed few functions resctrl_group_assign() -> rdtgroup_assign_cntr() resctrl_update_assign() -> resctrl_assign_cntr_allrdtgrp()

Added rdtgroup_mutex in resctrl_mbm_assign_on_mkdir_show().

Fixed the problem reported by Peter.
https://lore.kernel.org/lkml/CALPaoCjvUSKLKOXzF85j8mHT=eZYM-7R0=gJ3PRgOk4yuF5ZhQ@mail.gmail.com/
Updated the changelog.

Added check in rdt_mon_features_show to hide bmec related feature.

Added the call resctrl_bmec_files_show() to enable/disable files related to BMEC monitor mode is changed.

Added resctrl_set_mon_evt_cfg() to reset event configuration values when mode is changes.

Changed the name of the mbm_assign_mode's supported to mbm_event or default.
https://lore.kernel.org/lkml/[email protected]/

Added example section in user doc (resctrl.rst) on how to use mbm_assign_modes.

v13:
Removed BMEC related 2 patches which were in the previous series. It was related to optimization which can be doen later.

Patches are created on top of FS/ARCH restructure. So, major changes are due to FS/ARCH restructure. The files are split between arch/x86/kernel/cpu/resctrl/ and fs/resctrl/. So, functions are moved between these files accordingly.

Added fflag RFTYPE_RES_CACHE for mbm_assign_mode, num_mbm_cntrs, available_mbm_cntrs.

Removed the references to "mbm_assign_control".

Moved resctrl_arch_config_cntr() prototype to include/linux/resctrl.h. Changed resctrl_arch_config_cntr() to retun void from int to simplify few call sequences.

Added the event configuration details inside the evt_list in monitor domains. The avoids the need for new structure mbm_assign_config.

Passed evtid to functions resctrl_alloc_config_cntr() and resctrl_assign_cntr_event(). Event configuration value can be easily obtained from mon_evt list.

Added new patch to pass the entire struct rdtgroup to __mon_event_count(), mbm_update(), and related functions. We can easily get RMID,CLOSID etc from rdtgroup.

Added new function __cntr_id_read_phys() to handle ABMC event reading.

Added a new patch to hide BMEC related files when mbm_cntr_assign mode is enabled..

Added the call resctrl_init_evt_configuration() to setup the event configuration during init.

And few other commit message updates and user doc updates.

Removed Reviewed-by from few patches as patches have changed due to FS/ARCH restructure.

Let me know if I missed something.

v12:
This version is kind of RFC series with a new interface.

Removed Reviewed-by tag on few patches when the patch has changed.

Moved BMEC related patches (1 and 2) to beginning of the series. Removed the dependancy on BMEC to ABMC feature.

Removed the un-necessary initialization of mon_config_info structure. Changed wrmsrl instead of wrmsr to address the below comment.
https://lore.kernel.org/lkml/[email protected]/

Fixed the conflicts due to recent changes in rdt_resource data structure. Added new mbm_cfg_mask field to resctrl_mon.

Added the code to reset arch state inside _resctrl_abmc_enable().

Added the check CONFIG_RESCTRL_ASSIGN_FIXED to take care of arm platforms. This will be defined only in arm and not in x86.

Changed the code to display the max supported monitoring counters in each domain.

Fixed the struct mbm_cntr_cfg code documentation.
Moved the struct mbm_cntr_cfg definition to resctrl/internal.h as suggested by James.

Replaced seq_puts(s, ";") with seq_putc(s, ';');
Added missing rdt_last_cmd_clear() in resctrl_available_mbm_cntrs_show().

Added the check to reset the architecture-specific state only when assign is requested.

Added evt_cfg as the parameter to resctrl_arch_config_cntr() as the user will be passing the event configuration from /info/L3_MON/event_configs/.

Changed the check in resctrl_alloc_config_cntr() to reduce the indentation.
Fixed the handling error on first failure while assigning.
Added new parameter event configuration (evt_cfg) to get the event configuration from user space.

Added tte support for reading ABMC counters. This is bit involved change and affects lots of code.

New patch to support event configurations via new counter_configs method.

Removed mbm_cntr_reset() as it is not required while removing the group.

Added new patch to handle auto assign on group creation ("mbm_assign_on_mkdir")

Added couple of patches add interface for "mbm_L3_assignments" on each mon group.

Introduced mbm_cntr_free_all() and resctrl_reset_rmid_all() to clear counters and non-architectural states when monitor mode is changed.
https://lore.kernel.org/lkml/[email protected]/

Moved the resctrl_arch_mbm_cntr_assign_set_one to domain_add_cpu_mon().

Patches 17, 18, 19, 20, 21, 23, 24 are completely new to address the new interface requirement.

v11:
The commit 2937f9c361f7a ("x86/resctrl: Introduce resctrl_file_fflags_init() to initialize fflags") is already merged. Removed from the series.

Resolved minor conflicts due to code displacement in latest code.

Moved the monitoring related calls to monitor.c file when possible.
Moved some of the changes from include/linux/resctrl.h to arch/x86/kernel/cpu/resctrl/internal.h as requested by Reinette. This changes will be moved back when arch and non code is separated.

Renamed rdtgroup_mbm_assign_mode_show() to resctrl_mbm_assign_mode_show(). Renamed rdtgroup_num_mbm_cntrs_show() to resctrl_num_mbm_cntrs_show().

Moved the mon_config_info structure definition to internal.h.
Moved resctrl_arch_mon_event_config_get() and resctrl_arch_mon_event_config_set() to monitor.c file.

Moved resctrl_arch_assign_cntr() and resctrl_abmc_config_one_amd() to monitor.c. Added the code to reset the arch state in resctrl_arch_assign_cntr().
Also removed resctrl_arch_reset_rmid() inside IPI as the counters are reset from the callers.

Renamed rdtgroup_assign_cntr_event() to resctrl_assign_cntr_event(). Refactored the resctrl_assign_cntr_event().
Added functionality to exit on the first error during assignment. Simplified mbm_cntr_free().
Removed the function mbm_cntr_assigned(). Will be using mbm_cntr_get() to figure out if the counter is assigned or not.

Renamed rdtgroup_unassign_cntr_event() to resctrl_unassign_cntr_event(). Refactored the resctrl_unassign_cntr_event().

Moved mbm_cntr_reset() to monitor.c.
Added code reset non-architectural state in mbm_cntr_reset(). Added missing rdtgroup_unassign_cntrs() calls on failure path.

Domain can be NULL with SNC support so moved the unassign check in rdtgroup_mondata_show().

Renamed rdtgroup_mbm_assign_mode_write() to resctrl_mbm_assign_mode_write(). Added more details in resctrl.rst about mbm_cntr_assign mode. Re-arranged the text in resctrl.rst file in section mbm_cntr_assign.

Moved resctrl_arch_mbm_cntr_assign_set_one() to monitor.c

Added non-arch RMID reset in mbm_config_write_domain().
Removed resctrl_arch_reset_rmid() call in resctrl_abmc_config_one_amd(). Not required as reset of arch and non-arch rmid counters done from the callers. It simplies the IPI code.

Fixed printing the separator after each domain while listing the group assignments. Renamed rdtgroup_mbm_assign_control_show to resctrl_mbm_assign_control_show().

Fixed the static check warning with initializing dom_id in resctrl_process_flags()

Added change log in each patch for specific changes.

v10:
Major change is related to domain specific assignment.
Added struct mbm_cntr_cfg inside mon domains. This will handle
the domain specific assignments as discussed in below.
https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5AFgD9cQDCUg@mail.gmail.com/
I did not see the need to add cntr_id in mbm_state structure. Not used in the code. Following patches take care of these changes.
Patch 12, 13, 15, 16, 17, 18.

Added __init attribute to cache_alloc_hsw_probe(). Followed function prototype rules (preferred order is storage class before return type).

Moved the mon_config_info structure definition to resctrl.h

Added call resctrl_arch_reset_rmid() to reset the RMID in the domain inside IPI call resctrl_abmc_config_one_amd.

SMP and non-SMP call support is not required in resctrl_arch_config_cntr with new domain specific assign approach/data structure.

Assigned the counter before exposing the event files.
Moved the call rdtgroup_assign_cntrs() inside mkdir_rdt_prepare_rmid_alloc(). This is called both CNTR_MON and MON group creation.

Call mbm_cntr_reset() when unmounted to clear all the assignments.

Fixed the issue with finding the domain in multiple iterations in rdtgroup_process_flags().

Printed full error message with domain information when assign fails.

Taken care of other text comments in all the patches. Patch specific changes are in each patch.

If I missed something please point me and it is not intentional.

v9:
Patch 14 is a new addition.
Major change in patch 24.
Moved the fix patch to address __init attribute to begining of the series. Fixed all the call sequences. Added additional Fixed tags.

Added Reviewed-by where applicable.

Took care of couple of minor merge conflicts with latest code. Re-ordered the MSR in couple of instances.
Added available_mbm_cntrs (patch 14) to print the number of counter in a domain.

Used MBM_EVENT_ARRAY_INDEX macro to get the event index. Introduced rdtgroup_cntr_id_init() to initialize the cntr_id

Introduced new function resctrl_config_cntr to assign the counter, update the bitmap and reset the architectural state.
Taken care of error handling(freeing the counter) when assignment fails.

Changed rdtgroup_assign_cntrs() and rdtgroup_unassign_cntrs() to return void. Updated couple of rdtgroup_unassign_cntrs() calls properly.

Fixed problem changing the mode to mbm_cntr_assign mode when it is not supported. Added extra checks to detect if systems supports it.

https://lore.kernel.org/lkml/[email protected]/
As discussed in the above comment, introduced resctrl_mon_event_config_set to handle IPI. But sending another IPI inside IPI causes problem. Kernel reports SMP warning. So, introduced resctrl_arch_update_cntr() to send the command directly.

Fixed handling special case '//0=' and '//".
Removed extra strstr() call in rdtgroup_mbm_assign_control_write(). Added generic failure text when assignment operation fails. Corrected user documentation format texts.

v8:
Patches are getting into final stages.
Couple of changes Patch 8, Patch 19 and Patch 23.
Most of the other changes are related to rename and text message updates.

Details are in each patch. Here is the summary.

Added __init attribute to dom_data_init() in patch 8/25. Moved the mbm_cntrs_init() and mbm_cntrs_exit() functionality inside dom_data_init() and dom_data_exit() respectively.

Renamed resctrl_mbm_evt_config_init() to arch_mbm_evt_config_init() Renamed resctrl_arch_event_config_get() to resctrl_arch_mon_event_config_get().
resctrl_arch_event_config_set() to resctrl_arch_mon_event_config_set().

Rename resctrl_arch_assign_cntr to resctrl_arch_config_cntr. Renamed rdtgroup_assign_cntr() to rdtgroup_assign_cntr_event(). Added the code to return the error if rdtgroup_assign_cntr_event fails. Moved definition of MBM_EVENT_ARRAY_INDEX to resctrl/internal.h. Renamed rdtgroup_mbm_cntr_is_assigned to mbm_cntr_assigned_to_domain Added return error handling in resctrl_arch_config_cntr(). Renamed rdtgroup_assign_grp to rdtgroup_assign_cntrs.
Renamed rdtgroup_unassign_grp to rdtgroup_unassign_cntrs. Fixed the problem with unassigning the child MON groups of CTRL_MON group. Reset the internal counters after mbm_cntr_assign mode is changed. Renamed rdtgroup_mbm_cntr_reset() to mbm_cntr_reset()
Renamed resctrl_arch_mbm_cntr_assign_configure to
resctrl_arch_mbm_cntr_assign_set_one.

Used the same IPI as event update to modify the assignment. Could not do the way we discussed in the thread.
https://lore.kernel.org/lkml/[email protected]/
Needed to figure out event type to update the configuration.

Moved unassign first and assign during the assign modification. Assign none "_" takes priority. Cannot be mixed with other flags. Updated the documentation and .rst file format. htmldoc looks ok.

v7:
Major changes are related to FS and arch codes separation. Changed few interface names based on feedback.
Here are the summary and each patch contains changes specific the patch.

Removed WARN_ON for num_mbm_cntrs. Decided to dynamically allocate the bitmap. WARN_ON is not required anymore.

Renamed the function resctrl_arch_get_abmc_enabled() to resctrl_arch_mbm_cntr_assign_enabled().

Merged resctrl_arch_mbm_cntr_assign_disable, resctrl_arch_mbm_cntr_assign_disable and renamed to resctrl_arch_mbm_cntr_assign_set(). Passed the struct rdt_resource to these functions.

Removed resctrl_arch_reset_rmid_all() from arch code. This will be done from FS the caller.

Updated the descriptions/commit log in resctrl.rst to generic text. Removed ABMC references. Renamed mbm_mode to mbm_assign_mode.
Renamed mbm_control to mbm_assign_control.
Introduced mutex lock in rdtgroup_mbm_mode_show().

The 'legacy' mode is called 'default' mode.

Removed the static allocation and now allocating bitmap mbm_cntr_free_map dynamically.

Merged rdtgroup_assign_cntr(), rdtgroup_alloc_cntr() into one. Merged rdtgroup_unassign_cntr(), rdtgroup_free_cntr() into one.

Added struct rdt_resource to the interface functions resctrl_arch_assign_cntr () and resctrl_arch_unassign_cntr().
Rename rdtgroup_abmc_cfg() to resctrl_abmc_config_one_amd().

Added a new patch to fix counter assignment on event config changes.

Removed the references of ABMC from user interfaces.

Simplified the parsing (strsep(&token, "//") in rdtgroup_mbm_assign_control_write(). Added mutex lock in rdtgroup_mbm_assign_control_write() while processing.

Thomas Gleixner asked us to update https://gitlab.com/x86-cpuid.org/x86-cpuid-db.
It needs internal approval. We are working on it.

v6:
We still need to finalize few interface details on mbm_assign_mode and mbm_assign_control in case of ABMC and Soft-ABMC. We can continue the discussion with this series.

Added support for domain-id '*' to update all the domains at once. Fixed assign interface to allocate the counter if counter is not assigned.
Fixed unassign interface to free the counter if the counter is not assigned in any of the domains.

Renamed abmc_capable to mbm_cntr_assignable.

Renamed abmc_enabled to mbm_cntr_assign_enabled.
Used msr_set_bit and msr_clear_bit for msr updates.
Renamed resctrl_arch_abmc_enable() to resctrl_arch_mbm_cntr_assign_enable(). Renamed resctrl_arch_abmc_disable() to resctrl_arch_mbm_cntr_assign_disable().

Changed the display name from num_cntrs to num_mbm_cntrs.

Removed the variable mbm_cntrs_free_map_len. This is not required. Removed the call mbm_cntrs_init() in arch code. This needs to be done at higher level. Used DECLARE_BITMAP to initialize mbm_cntrs_free_map.
Removed unused config value definitions.

Introduced mbm_cntr_map to track counters at domain level. With this we dont need to send MSR read to read the counter configuration.

Separated all the counter id management to upper level in FS code.

Added checks to detect "Unassigned" before reading the RMID.

More details in each patch.

v5:
Rebase changes (because of SNC support)

Interface changes.
/sys/fs/resctrl/mbm_assign to /sys/fs/resctrl/mbm_assign_mode. /sys/fs/resctrl/mbm_assign_control to /sys/fs/resctrl/mbm_assign_control.

Added few arch specific routines.
resctrl_arch_get_abmc_enabled.
resctrl_arch_abmc_enable.
resctrl_arch_abmc_disable.

Few renames
num_cntrs_free_map -> mbm_cntrs_free_map num_cntrs_init -> mbm_cntrs_init arch_domain_mbm_evt_config -> resctrl_arch_mbm_evt_config

Introduced resctrl_arch_event_config_get and
resctrl_arch_event_config_set() to update event configuration.

Removed mon_state field mongroup. Added MON_CNTR_UNSET to initialize counters.

Renamed ctr_id to cntr_id for the hardware counter.

Report "Unassigned" in case the user attempts to read the events without assigning the counter.

ABMC is enabled during the boot up. Can be enabled or disabled later.

Fixed opcode and flags combination.

    '=_" is valid.
    "-_" amd "+_" is not valid.

Added all the comments as far as I know. If I missed something, it is not intentional.

v4:
Main change is domain specific event assignment.
Kept the ABMC feature as a default.
Dynamcic switching between ABMC and mbm_legacy is still allowed. We are still not clear about mount option.
Moved the monitoring related data in resctrl_mon structure from rdt_resource. Fixed the display of legacy and ABMC mode.
Used bimap APIs when possible.
Removed event configuration read from MSRs. We can use the internal saved data.(patch 12)
Added more comments about L3_QOS_ABMC_CFG MSR.
Added IPIs to read the assignment status for each domain (patch 18 and 19) More details in each patch.

v3:
This series adds the support for global assignment mode discussed in the thread. https://lore.kernel.org/lkml/[email protected]/
Removed the individual assignment mode and included the global assignment interface. Added following interface files.
a. /sys/fs/resctrl/info/L3_MON/mbm_assign
Used for displaying the current assignment mode and switch between ABMC and legacy mode.
b. /sys/fs/resctrl/info/L3_MON/mbm_assign_control
Used for lising the groups assignment mode and modify the assignment states.
c. Most of the changes are related to the new interface.
d. Addressed the comments from Reinette, James and Peter.
e. Hope I have addressed most of the major feedbacks discussed. If I missed
something then it is not intentional. Please feel free to comment.
f. Sending this as an RFC as per Reinette's comment. So, this is still open
for discussion.

v2:
a. Major change is the way ABMC is enabled. Earlier, user needed to remount
with -o abmc to enable ABMC feature. Removed that option now.
Now users can enable ABMC by "$echo 1 to /sys/fs/resctrl/info/L3_MON/mbm_assign_enable".

b. Added new word 21 to x86/cpufeatures.h.

c. Display unsupported if user attempts to read the events when ABMC is enabled
and event is not assigned.

d. Display monitor_state as "Unsupported" when ABMC is disabled.

e. Text updates and rebase to latest tip tree (as of Jan 18).

f. This series is still work in progress. I am yet to hear from ARM developers.

--------------------------------------------------------------------------------------

Previous revisions:
v15: https://lore.kernel.org/lkml/[email protected]/
v14: https://lore.kernel.org/lkml/[email protected]/
v13: https://lore.kernel.org/lkml/[email protected]/
v12: https://lore.kernel.org/lkml/[email protected]/
v11: https://lore.kernel.org/lkml/[email protected]/
v10: https://lore.kernel.org/lkml/[email protected]/
v9: https://lore.kernel.org/lkml/[email protected]/
v8: https://lore.kernel.org/lkml/[email protected]/
v7: https://lore.kernel.org/lkml/[email protected]/
v6: https://lore.kernel.org/lkml/[email protected]/
v5: https://lore.kernel.org/lkml/[email protected]/
v4: https://lore.kernel.org/lkml/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
----------------------------------------------------------------------------

Babu Moger (30):
x86/cpufeatures: Add support for Assignable Bandwidth Monitoring
Counters (ABMC)
x86/resctrl: Add ABMC feature in the command line options x86,fs/resctrl: Consolidate monitoring related data from rdt_resource x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details x86/resctrl: Add support to enable/disable AMD ABMC feature fs/resctrl: Introduce the interface to display monitoring modes fs/resctrl: Add resctrl file to display number of assignable counters fs/resctrl: Introduce mbm_cntr_cfg to track assignable counters per
domain
fs/resctrl: Introduce interface to display number of free MBM counters x86/resctrl: Add data structures and definitions for ABMC assignment fs/resctrl: Introduce event configuration field in struct mon_evt x86,fs/resctrl: Implement resctrl_arch_config_cntr() to assign a
counter with ABMC
fs/resctrl: Add the functionality to assign MBM events fs/resctrl: Add the functionality to unassign MBM events fs/resctrl: Pass struct rdtgroup instead of individual members fs/resctrl: Introduce counter ID read, reset calls in mbm_event mode x86/resctrl: Refactor resctrl_arch_rmid_read() x86/resctrl: Implement resctrl_arch_reset_cntr() and
resctrl_arch_cntr_read()
fs/resctrl: Support counter read/reset with mbm_event assignment mode fs/resctrl: Add definitions for MBM event configuration fs/resctrl: Add event configuration directory under info/L3_MON/ fs/resctrl: Provide interface to update the event configurations fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on
mkdir
fs/resctrl: Auto assign counters on mkdir and clean up on group
removal
fs/resctrl: Introduce mbm_L3_assignments to list assignments in a
group
fs/resctrl: Introduce the interface to modify assignments in a group fs/resctrl: Disable BMEC event configuration when mbm_event mode is
enabled
fs/resctrl: Introduce the interface to switch between monitor modes x86/resctrl: Configure mbm_event mode if supported
MAINTAINERS: resctrl: add myself as reviewer

Tony Luck (4):
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

 .../admin-guide/kernel-parameters.txt         |   2 +-
 Documentation/filesystems/resctrl.rst         | 312 +++++++++
 MAINTAINERS                                   |   1 +
 arch/x86/include/asm/cpufeatures.h            |   1 +
 arch/x86/include/asm/msr-index.h              |   2 +
 arch/x86/include/asm/resctrl.h                |  16 -
 arch/x86/kernel/cpu/resctrl/core.c            |  79 ++-
 arch/x86/kernel/cpu/resctrl/internal.h        |  56 +-
 arch/x86/kernel/cpu/resctrl/monitor.c         | 247 +++++--
 arch/x86/kernel/cpu/scattered.c               |   1 +
 fs/resctrl/ctrlmondata.c                      |  26 +-
 fs/resctrl/internal.h                         |  54 +-
 fs/resctrl/monitor.c                          | 637 ++++++++++++++++--
 fs/resctrl/rdtgroup.c                         | 588 ++++++++++++++--
 include/linux/resctrl.h                       | 148 +++-
 include/linux/resctrl_types.h                 |  18 +-
 16 files changed, 1962 insertions(+), 226 deletions(-)
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH v16 1/34 x86,fs/resctrl: Consolidate monitor event descriptions

From: Tony Luck <[email protected]>

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().

---
Picked up first four patches from:
https://lore.kernel.org/lkml/[email protected]/
These patches have already been reviewed.

---
 arch/x86/kernel/cpu/resctrl/core.c | 12 ++++--
 fs/resctrl/internal.h              | 13 ++++--
 fs/resctrl/monitor.c               | 63 +++++++++++++++---------------
 fs/resctrl/rdtgroup.c              | 11 +++---
 include/linux/resctrl.h            |  4 +-
 include/linux/resctrl_types.h      | 12 ++++--
 6 files changed, 66 insertions(+), 49 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +9 -3
index 187d527ef73b..7fcae25874fe 100644
@@ -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/internal.h +10 -3
index 0a1eedba2b03..4f315b7e9ec0 100644
@@ -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.
fs/resctrl/monitor.c +31 -32

84 lines not on this page · raw message

fs/resctrl/rdtgroup.c +6 -5
index 77d08229d855..b95501d4b5de 100644
@@ -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))
include/linux/resctrl.h +2 -2
index 6fb4894b8cfd..2944042bd84c 100644
@@ -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
index a25fb9c4070d..2dadbc54e4b3 100644
@@ -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,
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH v16 01/34] x86,fs/resctrl: Consolidate monitor event descriptions

Hi Babu,

Quoted 18 lines · Babu Moger

From: Tony Luck <[email protected]>

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().

Quoted 6 lines

Architecture code now informs file system code which events are available with resctrl_enable_mon_event().

Please add your "Signed-off-by" to the commit tags of the first four patches. When you do, ensure it follows the expected ordering
per "Ordering of commit tags" in Documentation/process/maintainer-tip.rst.

Reinette

author reviewer Reviewed-by Fenghua Yu Reviewed-by Reinette Chatre
#3 lore raw

Re: [PATCH v16 01/34] x86,fs/resctrl: Consolidate monitor event descriptions

Hi Reinette,

Quoted 24 lines · Reinette Chatre

Hi Babu,

Quoted 21 lines · Babu Moger

From: Tony Luck <[email protected]>

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().

Quoted 8 lines
Quoted 3 lines

Please add your "Signed-off-by" to the commit tags of the first four patches. When you do, ensure it follows the expected ordering
per "Ordering of commit tags" in Documentation/process/maintainer-tip.rst.

Sure. It appears I am patch handler in this case. Seems like this is a correct order.

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#4 lore raw

PATCH v16 2/34 x86,fs/resctrl: Replace architecture event enabled checks

In reply to Babu Moger

From: Tony Luck <[email protected]>

The 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.

---
Picked up first four patches from:
https://lore.kernel.org/lkml/[email protected]/
These patches have already been reviewed.

---
 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 +++++++++---------
 include/linux/resctrl.h               |  2 ++
 7 files changed, 28 insertions(+), 35 deletions(-)
arch/x86/include/asm/resctrl.h +0 -15
index feb93b50e990..b1dd5d6b87db 100644
@@ -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
index 7fcae25874fe..1a319ce9328c 100644
@@ -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
index c261558276cd..61d38517e2bf 100644
@@ -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
index d98e0d2de09f..ad7ffc6acf13 100644
@@ -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
index 2313e48de55f..9e988b2c1a22 100644
@@ -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
index b95501d4b5de..a7eeb33501da 100644
@@ -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 *d
 
 	if (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_domain
 	u32 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_domain
 			return -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);
include/linux/resctrl.h +2 -0
index 2944042bd84c..40aba6b5d4f0 100644
@@ -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);
 
 /**
Signature · 1 line
2.34.1
author reviewer
#5 lore raw

PATCH v16 3/34 x86/resctrl: Remove 'rdt_mon_features' global variable

In reply to Babu Moger

From: Tony Luck <[email protected]>

rdt_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.

---
Picked up first four patches from:
https://lore.kernel.org/lkml/[email protected]/
These patches have already been reviewed.

---
 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
index b1dd5d6b87db..575f8408a9e7 100644
@@ -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
index 1a319ce9328c..5d14f9a14eda 100644
@@ -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
index 61d38517e2bf..07f8ab097cbe 100644
@@ -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.34.1
author reviewer
#6 lore raw

PATCH v16 4/34 x86,fs/resctrl: Prepare for more monitor events

In reply to Babu Moger

From: Tony Luck <[email protected]>

There'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.

---
Picked up first four patches from:
https://lore.kernel.org/lkml/[email protected]/
These patches have already been reviewed.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 40 +++++++++++----------
 arch/x86/kernel/cpu/resctrl/internal.h |  8 ++---
 arch/x86/kernel/cpu/resctrl/monitor.c  | 36 +++++++++----------
 fs/resctrl/monitor.c                   | 13 ++++---
 fs/resctrl/rdtgroup.c                  | 50 +++++++++++++-------------
 include/linux/resctrl.h                | 23 +++++++++---
 include/linux/resctrl_types.h          |  3 ++
 7 files changed, 96 insertions(+), 77 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +22 -18
index 5d14f9a14eda..fbf019c1ff11 100644
@@ -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/internal.h +4 -4
index 5e3c41b36437..58dca892a5df 100644
@@ -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/monitor.c +17 -19
index 07f8ab097cbe..f01db2034d08 100644
@@ -161,18 +161,14 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain *hw_do
 						 u32 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
index 9e988b2c1a22..dcc6c00eb362 100644
@@ -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

include/linux/resctrl.h +19 -4
index 40aba6b5d4f0..478d7a935ca3 100644
@@ -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
index 2dadbc54e4b3..d98351663c2c 100644
@@ -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 */
Signature · 1 line
2.34.1
author reviewer
#7 lore raw

PATCH v16 5/34 x86/cpufeatures: Add support for Assignable Bandwidth Monitoring Counters (ABMC)

In reply to Babu Moger

Users can create as many monitor groups as RMIDs supported by the hardware. However, bandwidth monitoring feature on AMD system only guarantees that RMIDs currently assigned to a processor will be tracked by hardware. The counters of any other RMIDs which are no longer being tracked will be reset to zero. The MBM event counters return "Unavailable" for the RMIDs that are not tracked by hardware. So, there can be only limited number of groups that can give guaranteed monitoring numbers. With ever changing configurations there is no way to definitely know which of these groups are being tracked during a particular time. Users do not have the option to monitor a group or set of groups for a certain period of time without worrying about RMID being reset in between.

The ABMC feature allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. There is no need to worry about counters being reset during this period. Additionally, the user can specify the type of memory transactions (e.g., reads, writes) for the counter to track.

Without ABMC enabled, monitoring will work in current mode without assignment option.

The Linux resctrl subsystem provides an interface that allows monitoring of up to two memory bandwidth events per group, selected from a combination of available total and local events. When ABMC is enabled, two events will be assigned to each group by default, in line with the current interface design. Users will also have the option to configure which types of memory transactions are counted by these events.

Due to the limited number of available counters (32), users may quickly exhaust the available counters. If the system runs out of assignable ABMC counters, the kernel will report an error. In such cases, users will need to unassign one or more active counters to free up counters for new assignments. resctrl will provide options to assign or unassign events through the group-specific interface file.

The feature is detected via CPUID_Fn80000020_EBX_x00 bit 5. Bits Description
5 ABMC (Assignable Bandwidth Monitoring Counters)

The feature details are documented in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

---
Note: Checkpatch checks/warnings are ignored to maintain coding style.

v16: Fixed the conflicts with latest cpufeatures.h and scattered.c files.

v15: Minor changelog update.

v14: Removed the dependancy on X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL.
as discussed in https://lore.kernel.org/lkml/[email protected]/
Need to re-work on ABMC enumeration during the init.
Updated changelog with few text update.

v13: Updated the commit log with Linux interface details.

v12: Removed the dependancy on X86_FEATURE_BMEC.
Removed the Reviewed-by tag as patch has changed.

v11: No changes.

v10: No changes.

v9: Took care of couple of minor merge conflicts. No other changes.

v8: No changes.

v7: Removed "" from feature flags. Not required anymore.

    https://lore.kernel.org/lkml/20240817145058.GCZsC40neU4wkPXeVR@fat_crate.local/

v6: Added Reinette's Reviewed-by. Moved the Checkpatch note below ---.

v5: Minor rebase change and subject line update.

v4: Changes because of rebase. Feature word 21 has few more additions now.
Changed the text to "tracked by hardware" instead of active.

v3: Change because of rebase. Actual patch did not change.

v2: Added dependency on X86_FEATURE_BMEC.

---
 arch/x86/include/asm/cpufeatures.h | 1 +
 arch/x86/kernel/cpu/scattered.c    | 1 +
 2 files changed, 2 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
index 602957dd2609..43cba78a50e5 100644
@@ -494,6 +494,7 @@
 #define X86_FEATURE_TSA_SQ_NO		(21*32+11) /* AMD CPU not vulnerable to TSA-SQ */
 #define X86_FEATURE_TSA_L1_NO		(21*32+12) /* AMD CPU not vulnerable to TSA-L1 */
 #define X86_FEATURE_CLEAR_CPU_BUF_VM	(21*32+13) /* Clear CPU buffers using VERW before VMRUN */
+#define X86_FEATURE_ABMC		(21*32+14) /* Assignable Bandwidth Monitoring Counters */
 
 /*
  * BUG word(s)
arch/x86/kernel/cpu/scattered.c +1 -0
index b4a1f6732a3a..cdd3c3e2d4c6 100644
@@ -50,6 +50,7 @@ static const struct cpuid_bit cpuid_bits[] = {
 	{ X86_FEATURE_MBA,			CPUID_EBX,  6, 0x80000008, 0 },
 	{ X86_FEATURE_SMBA,			CPUID_EBX,  2, 0x80000020, 0 },
 	{ X86_FEATURE_BMEC,			CPUID_EBX,  3, 0x80000020, 0 },
+	{ X86_FEATURE_ABMC,			CPUID_EBX,  5, 0x80000020, 0 },
 	{ X86_FEATURE_TSA_SQ_NO,		CPUID_ECX,  1, 0x80000021, 0 },
 	{ X86_FEATURE_TSA_L1_NO,		CPUID_ECX,  2, 0x80000021, 0 },
 	{ X86_FEATURE_AMD_WORKLOAD_CLASS,	CPUID_EAX, 22, 0x80000021, 0 },
Signature · 1 line
2.34.1
maintainer Reviewed-by on v16 5/34
#8 lore raw

Re: [PATCH v16 05/34] x86/cpufeatures: Add support for Assignable Bandwidth Monitoring Counters (ABMC)

Hi Babu,

Quoted 40 lines · Babu Moger

Users can create as many monitor groups as RMIDs supported by the hardware. However, bandwidth monitoring feature on AMD system only guarantees that RMIDs currently assigned to a processor will be tracked by hardware. The counters of any other RMIDs which are no longer being tracked will be reset to zero. The MBM event counters return "Unavailable" for the RMIDs that are not tracked by hardware. So, there can be only limited number of groups that can give guaranteed monitoring numbers. With ever changing configurations there is no way to definitely know which of these groups are being tracked during a particular time. Users do not have the option to monitor a group or set of groups for a certain period of time without worrying about RMID being reset in between.

The ABMC feature allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. There is no need to worry about counters being reset during this period. Additionally, the user can specify the type of memory transactions (e.g., reads, writes) for the counter to track.

Without ABMC enabled, monitoring will work in current mode without assignment option.

The Linux resctrl subsystem provides an interface that allows monitoring of up to two memory bandwidth events per group, selected from a combination of available total and local events. When ABMC is enabled, two events will be assigned to each group by default, in line with the current interface design. Users will also have the option to configure which types of memory transactions are counted by these events.

Due to the limited number of available counters (32), users may quickly exhaust the available counters. If the system runs out of assignable ABMC counters, the kernel will report an error. In such cases, users will need to unassign one or more active counters to free up counters for new assignments. resctrl will provide options to assign or unassign events through the group-specific interface file.

The feature is detected via CPUID_Fn80000020_EBX_x00 bit 5. Bits Description
5 ABMC (Assignable Bandwidth Monitoring Counters)

Quoted 8 lines

The feature details are documented in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

---

Reinette

author reviewer
#9 lore raw

PATCH v16 6/34 x86/resctrl: Add ABMC feature in the command line options

In reply to Babu Moger

Add a kernel command-line parameter to enable or disable the exposure of the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature to resctrl.

---
v16: Added Reviewed-by tag.

v15: No changes.

v14: Slight changelog modification.

v13: Removed the Reviewed-by as the file resctrl.rst is moved to
Documentation/filesystems/resctrl.rst. In that sense patch has changed.

v12: No changes.

v11: No changes.

v10: No changes.

v9: No code changes. Added Reviewed-by.

v8: Commit message update.

v7: No changes

v6: No changes

v5: No changes

v4: No changes

v3: No changes

v2: No changes

---
 Documentation/admin-guide/kernel-parameters.txt | 2 +-
 Documentation/filesystems/resctrl.rst           | 1 +
 arch/x86/kernel/cpu/resctrl/core.c              | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
index b29c7a8dc7e6..6a74a32c9416 100644
@@ -6077,7 +6077,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, abmc.
 			E.g. to turn on cmt and turn off mba use:
 				rdt=cmt,!mba
 
Documentation/filesystems/resctrl.rst +1 -0
index c7949dd44f2f..c97fd77a107d 100644
@@ -26,6 +26,7 @@ MBM (Memory Bandwidth Monitoring)		"cqm_mbm_total", "cqm_mbm_local"
 MBA (Memory Bandwidth Allocation)		"mba"
 SMBA (Slow Memory Bandwidth Allocation)         ""
 BMEC (Bandwidth Monitoring Event Configuration) ""
+ABMC (Assignable Bandwidth Monitoring Counters) ""
 ===============================================	================================
 
 Historically, new features were made visible by default in /proc/cpuinfo. This
arch/x86/kernel/cpu/resctrl/core.c +2 -0
index fbf019c1ff11..b07b12a05886 100644
@@ -711,6 +711,7 @@ enum {
 	RDT_FLAG_MBA,
 	RDT_FLAG_SMBA,
 	RDT_FLAG_BMEC,
+	RDT_FLAG_ABMC,
 };
 
 #define RDT_OPT(idx, n, f)	\
@@ -736,6 +737,7 @@ 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_ABMC,	    "abmc",	X86_FEATURE_ABMC),
 };
 #define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options)
 
Signature · 1 line
2.34.1
author reviewer
#10 lore raw

PATCH v16 7/34 x86,fs/resctrl: Consolidate monitoring related data from rdt_resource

In reply to Babu Moger

The cache allocation and memory bandwidth allocation feature properties are consolidated into struct resctrl_cache and struct resctrl_membw respectively.

In preparation for more monitoring properties that will clobber the existing resource struct more, re-organize the monitoring specific properties to also be in a separate structure.

Also switch "bandwidth sources" term to "memory transactions" to use consistent term within resctrl for related monitoring features.

---
v16: Added the Reviewed-by tag.

v15: Updated changelog.
Minor update in code comment in resctrl.h.

v14: Updated the code comment in resctrl.h.

v13: Changes due to FS/ARCH restructure.

v12: Fixed the conflicts due to recent changes in rdt_resource data structure.
Added new mbm_cfg_mask field to resctrl_mon.
Removed Reviewed-by tag as patch has changed.

v11: No changes.

v10: No changes.

v9: No changes.

v8: Added Reviewed-by from Reinette. No other changes.

v7: Added kernel doc for data structure. Minor text update.

v6: Update commit message and update kernel doc for rdt_resource.

v5: Commit message update.
Also changes related to data structure updates does to SNC support.

v4: New patch.

---
 arch/x86/kernel/cpu/resctrl/core.c    |  4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c | 10 +++++-----
 fs/resctrl/rdtgroup.c                 |  6 +++---
 include/linux/resctrl.h               | 18 +++++++++++++-----
 4 files changed, 23 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +2 -2
index b07b12a05886..267e9206a999 100644
@@ -107,7 +107,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 
 	/* RMID are independent numbers for x86. num_rmid_idx == num_rmid */
-	return r->num_rmid;
+	return r->mon.num_rmid;
 }
 
 struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
@@ -541,7 +541,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 
 	arch_mon_domain_online(r, d);
 
-	if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) {
+	if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) {
 		mon_domain_free(hw_dom);
 		return;
 	}
arch/x86/kernel/cpu/resctrl/monitor.c +5 -5
index f01db2034d08..2558b1bdef8b 100644
@@ -130,7 +130,7 @@ static int logical_rmid_to_physical_rmid(int cpu, int lrmid)
 	if (snc_nodes_per_l3_cache == 1)
 		return lrmid;
 
-	return lrmid + (cpu_to_node(cpu) % snc_nodes_per_l3_cache) * r->num_rmid;
+	return lrmid + (cpu_to_node(cpu) % snc_nodes_per_l3_cache) * r->mon.num_rmid;
 }
 
 static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 *val)
@@ -205,7 +205,7 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *
 			continue;
 		idx = MBM_STATE_IDX(eventid);
 		memset(hw_dom->arch_mbm_states[idx], 0,
-		       sizeof(*hw_dom->arch_mbm_states[0]) * r->num_rmid);
+		       sizeof(*hw_dom->arch_mbm_states[0]) * r->mon.num_rmid);
 	}
 }
 
@@ -344,7 +344,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 
 	resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024;
 	hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache;
-	r->num_rmid = (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3_cache;
+	r->mon.num_rmid = (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3_cache;
 	hw_res->mbm_width = MBM_CNTR_WIDTH_BASE;
 
 	if (mbm_offset > 0 && mbm_offset <= MBM_CNTR_WIDTH_OFFSET_MAX)
@@ -359,7 +359,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	 *
 	 * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
 	 */
-	threshold = resctrl_rmid_realloc_limit / r->num_rmid;
+	threshold = resctrl_rmid_realloc_limit / r->mon.num_rmid;
 
 	/*
 	 * Because num_rmid may not be a power of two, round the value
@@ -373,7 +373,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
-		r->mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
+		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
 	}
 
 	r->mon_capable = true;
fs/resctrl/rdtgroup.c +3 -3
index 77336d5e4915..ca0475b75390 100644
@@ -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, "%d\n", r->mon.num_rmid);
 
 	return 0;
 }
@@ -1731,9 +1731,9 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
 	}
 
 	/* Value from user cannot be more than the supported set of events */
-	if ((val & r->mbm_cfg_mask) != val) {
+	if ((val & r->mon.mbm_cfg_mask) != val) {
 		rdt_last_cmd_printf("Invalid event configuration: max valid mask is 0x%02x\n",
-				    r->mbm_cfg_mask);
+				    r->mon.mbm_cfg_mask);
 		return -EINVAL;
 	}
 
include/linux/resctrl.h +13 -5
index 478d7a935ca3..fe2af6cb96d4 100644
@@ -255,38 +255,46 @@ enum resctrl_schema_fmt {
 	RESCTRL_SCHEMA_RANGE,
 };
 
+/**
+ * struct resctrl_mon - Monitoring related data of a resctrl resource.
+ * @num_rmid:		Number of RMIDs available.
+ * @mbm_cfg_mask:	Memory transactions that can be tracked when bandwidth
+ *			monitoring events can be configured.
+ */
+struct resctrl_mon {
+	int			num_rmid;
+	unsigned int		mbm_cfg_mask;
+};
+
 /**
  * struct rdt_resource - attributes of a resctrl resource
  * @rid:		The index of the resource
  * @alloc_capable:	Is allocation available on this machine
  * @mon_capable:	Is monitor feature available on this machine
- * @num_rmid:		Number of RMIDs available
  * @ctrl_scope:		Scope of this resource for control functions
  * @mon_scope:		Scope of this resource for monitor functions
  * @cache:		Cache allocation related data
  * @membw:		If the component has bandwidth controls, their properties.
+ * @mon:		Monitoring related data.
  * @ctrl_domains:	RCU list of all control domains for this resource
  * @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.
- * @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
  */
 struct rdt_resource {
 	int			rid;
 	bool			alloc_capable;
 	bool			mon_capable;
-	int			num_rmid;
 	enum resctrl_scope	ctrl_scope;
 	enum resctrl_scope	mon_scope;
 	struct resctrl_cache	cache;
 	struct resctrl_membw	membw;
+	struct resctrl_mon	mon;
 	struct list_head	ctrl_domains;
 	struct list_head	mon_domains;
 	char			*name;
 	enum resctrl_schema_fmt	schema_fmt;
-	unsigned int		mbm_cfg_mask;
 	bool			cdp_capable;
 };
 
Signature · 1 line
2.34.1
author reviewer
#11 lore raw

PATCH v16 8/34 x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details

In reply to Babu Moger

ABMC feature details are reported via CPUID Fn8000_0020_EBX_x5. Bits Description
15:0 MAX_ABMC Maximum Supported Assignable Bandwidth
Monitoring Counter ID + 1

The feature details are documented in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

Detect the feature and number of assignable counters supported. For backward compatibility, upon detecting the assignable counter feature, enable the mbm_total_bytes and mbm_local_bytes events that users are familiar with as part of original L3 MBM support.

---
v16: Added a new check in get_rdt_mon_resources().
Added a check resctrl_is_mon_event_enabled() before enabling.

v15: Minor update to changelog.
Added check in resctrl_cpu_detect().
Moved the resctrl_enable_mon_event() to resctrl_mon_resource_init().

v14: Updated enumeration to support ABMC regardless of MBM total and local support.
Updated the changelog accordingly.

v13: No changes.

v12: Resolved conflicts because of latest merge.
Removed Reviewed-by as the patch has changed.

v11: No changes.

v10: No changes.

v9: Added Reviewed-by tag. No code changes

v8: Used GENMASK for the mask.

v7: Removed WARN_ON for num_mbm_cntrs. Decided to dynamically allocate the
bitmap. WARN_ON is not required anymore.
Removed redundant comments.

v6: Commit message update.
Renamed abmc_capable to mbm_cntr_assignable.

v5: Name change num_cntrs to num_mbm_cntrs.
Moved abmc_capable to resctrl_mon.

v4: Removed resctrl_arch_has_abmc(). Added all the code inline. We dont
need to separate this as arch code.

v3: Removed changes related to mon_features.
Moved rdt_cpu_has to core.c and added new function resctrl_arch_has_abmc. Also moved the fields mbm_assign_capable and mbm_assign_cntrs to rdt_resource. (James)

v2: Changed the field name to mbm_assign_capable from abmc_capable.

---
 arch/x86/kernel/cpu/resctrl/core.c    |  5 ++++-
 arch/x86/kernel/cpu/resctrl/monitor.c | 11 ++++++++---
 fs/resctrl/monitor.c                  |  7 +++++++
 include/linux/resctrl.h               |  4 ++++
 4 files changed, 23 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +4 -1
index 267e9206a999..09cb5a70b1cb 100644
@@ -883,6 +883,8 @@ static __init bool get_rdt_mon_resources(void)
 		resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
 		ret = true;
 	}
+	if (rdt_cpu_has(X86_FEATURE_ABMC))
+		ret = true;
 
 	if (!ret)
 		return false;
@@ -990,7 +992,8 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
 
 	if (cpu_has(c, X86_FEATURE_CQM_OCCUP_LLC) ||
 	    cpu_has(c, X86_FEATURE_CQM_MBM_TOTAL) ||
-	    cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL)) {
+	    cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL) ||
+	    cpu_has(c, X86_FEATURE_ABMC)) {
 		u32 eax, ebx, ecx, edx;
 
 		/* QoS sub-leaf, EAX=0Fh, ECX=1 */
arch/x86/kernel/cpu/resctrl/monitor.c +8 -3
index 2558b1bdef8b..0a695ce68f46 100644
@@ -339,6 +339,7 @@ int __init rdt_get_mon_l3_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);
 	unsigned int threshold;
+	u32 eax, ebx, ecx, edx;
 
 	snc_nodes_per_l3_cache = snc_get_config();
 
@@ -368,14 +369,18 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	 */
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
 
-	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
-		u32 eax, ebx, ecx, edx;
-
+	if (rdt_cpu_has(X86_FEATURE_BMEC) || rdt_cpu_has(X86_FEATURE_ABMC)) {
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
 		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
 	}
 
+	if (rdt_cpu_has(X86_FEATURE_ABMC)) {
+		r->mon.mbm_cntr_assignable = true;
+		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
+		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
+	}
+
 	r->mon_capable = true;
 
 	return 0;
fs/resctrl/monitor.c +7 -0
index dcc6c00eb362..66c8c635f4b3 100644
@@ -924,6 +924,13 @@ int resctrl_mon_resource_init(void)
 	else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
 		mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
 
+	if (r->mon.mbm_cntr_assignable) {
+		if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+			resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
+		if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+			resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
+	}
+
 	return 0;
 }
 
include/linux/resctrl.h +4 -0
index fe2af6cb96d4..eb80cc233be4 100644
@@ -260,10 +260,14 @@ enum resctrl_schema_fmt {
  * @num_rmid:		Number of RMIDs available.
  * @mbm_cfg_mask:	Memory transactions that can be tracked when bandwidth
  *			monitoring events can be configured.
+ * @num_mbm_cntrs:	Number of assignable counters.
+ * @mbm_cntr_assignable:Is system capable of supporting counter assignment?
  */
 struct resctrl_mon {
 	int			num_rmid;
 	unsigned int		mbm_cfg_mask;
+	int			num_mbm_cntrs;
+	bool			mbm_cntr_assignable;
 };
 
 /**
Signature · 1 line
2.34.1
maintainer
#12 lore raw

Re: [PATCH v16 08/34] x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details

Hi Babu,

Quoted 18 lines · Babu Moger

ABMC feature details are reported via CPUID Fn8000_0020_EBX_x5. Bits Description
15:0 MAX_ABMC Maximum Supported Assignable Bandwidth
Monitoring Counter ID + 1

The feature details are documented in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

Detect the feature and number of assignable counters supported. For backward compatibility, upon detecting the assignable counter feature, enable the mbm_total_bytes and mbm_local_bytes events that users are familiar with as part of original L3 MBM support.

---

...

Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c +2 -0
index 267e9206a999..09cb5a70b1cb 100644
@@ -883,6 +883,8 @@ static __init bool get_rdt_mon_resources(void)
 		resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
 		ret = true;
 	}
+	if (rdt_cpu_has(X86_FEATURE_ABMC))
+		ret = true;
 
 	if (!ret)
 		return false;

arch/x86/kernel/cpu/resctrl/core.c void resctrl_cpu_detect(struct cpuinfo_x86 *c) · line 992

Quoted 1 line
arch/x86/kernel/cpu/resctrl/core.c +0 -0
@@ -990,7 +992,8 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
 

To complement the change below, shouldn't the snippet that precedes it look like:

	if (!cpu_has(c, X86_FEATURE_CQM_LLC) && !cpu_has(c, X86_FEATURE_ABMC)) {
		...
		return;
	}
Quoted 21 lines
arch/x86/kernel/cpu/resctrl/core.c +2 -1
 	if (cpu_has(c, X86_FEATURE_CQM_OCCUP_LLC) ||
 	    cpu_has(c, X86_FEATURE_CQM_MBM_TOTAL) ||
-	    cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL)) {
+	    cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL) ||
+	    cpu_has(c, X86_FEATURE_ABMC)) {
 		u32 eax, ebx, ecx, edx;
 
 		/* QoS sub-leaf, EAX=0Fh, ECX=1 */
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
index 2558b1bdef8b..0a695ce68f46 100644
@@ -339,6 +339,7 @@ int __init rdt_get_mon_l3_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);
 	unsigned int threshold;
+	u32 eax, ebx, ecx, edx;
 
 	snc_nodes_per_l3_cache = snc_get_config();
 

arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 375

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -3
@@ -368,14 +369,18 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	 */
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
 
-	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
-		u32 eax, ebx, ecx, edx;
-
+	if (rdt_cpu_has(X86_FEATURE_BMEC) || rdt_cpu_has(X86_FEATURE_ABMC)) {
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
 		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;

I interpret this mbm_cfg_mask initialization that an ABMC system will report which of the memory transactions can be monitored.
In patch #15 "fs/resctrl: Introduce event configuration field in struct mon_evt" the event configurations of memory transactions that should be monitored are hardcoded as below without taking into account what the system supports:

	resctrl_mon_resource_init() {
		...
		mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = MAX_EVT_CONFIG_BITS;
		mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
								   READS_TO_LOCAL_S_MEM |
								   NON_TEMP_WRITE_TO_LOCAL_MEM;
		...
	}

It may thus be that a system may not support all memory transactions it is configured to monitor. It seems to me that the initialization done in resctrl_mon_resource_init() needs to take r->mon.mbm_cfg_mask (what the system supports) into account? If so, then the same hardcoding done by patch #32 in resctrl_mbm_assign_mode_write() should also be changed.

Reinette

author reviewer
#13 lore raw

Re: [PATCH v16 08/34] x86,fs/resctrl: Detect Assignable Bandwidth Monitoring feature details

Hi Reinette,

Quoted 41 lines · Reinette Chatre

Hi Babu,

Quoted 18 lines · Babu Moger

ABMC feature details are reported via CPUID Fn8000_0020_EBX_x5. Bits Description
15:0 MAX_ABMC Maximum Supported Assignable Bandwidth
Monitoring Counter ID + 1

The feature details are documented in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

Detect the feature and number of assignable counters supported. For backward compatibility, upon detecting the assignable counter feature, enable the mbm_total_bytes and mbm_local_bytes events that users are familiar with as part of original L3 MBM support.

---

...

Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c +2 -0
index 267e9206a999..09cb5a70b1cb 100644
@@ -883,6 +883,8 @@ static __init bool get_rdt_mon_resources(void)
 		resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
 		ret = true;
 	}
+	if (rdt_cpu_has(X86_FEATURE_ABMC))
+		ret = true;
 
 	if (!ret)
 		return false;

arch/x86/kernel/cpu/resctrl/core.c void resctrl_cpu_detect(struct cpuinfo_x86 *c) · line 992

Quoted 1 line
arch/x86/kernel/cpu/resctrl/core.c +0 -0
@@ -990,7 +992,8 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
 

To complement the change below, shouldn't the snippet that precedes it look like:

Quoted 4 lines
	if (!cpu_has(c, X86_FEATURE_CQM_LLC) && !cpu_has(c, X86_FEATURE_ABMC)) {
		...
		return;
	}

Sure. Added now.

Quoted 39 lines
Quoted 22 lines
arch/x86/kernel/cpu/resctrl/core.c +2 -1
 	if (cpu_has(c, X86_FEATURE_CQM_OCCUP_LLC) ||
 	    cpu_has(c, X86_FEATURE_CQM_MBM_TOTAL) ||
-	    cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL)) {
+	    cpu_has(c, X86_FEATURE_CQM_MBM_LOCAL) ||
+	    cpu_has(c, X86_FEATURE_ABMC)) {
 		u32 eax, ebx, ecx, edx;
 
 		/* QoS sub-leaf, EAX=0Fh, ECX=1 */
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
index 2558b1bdef8b..0a695ce68f46 100644
@@ -339,6 +339,7 @@ int __init rdt_get_mon_l3_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);
 	unsigned int threshold;
+	u32 eax, ebx, ecx, edx;
 
 	snc_nodes_per_l3_cache = snc_get_config();
 

arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 375

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -3
@@ -368,14 +369,18 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	 */
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
 
-	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
-		u32 eax, ebx, ecx, edx;
-
+	if (rdt_cpu_has(X86_FEATURE_BMEC) || rdt_cpu_has(X86_FEATURE_ABMC)) {
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
 		r->mon.mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;

I interpret this mbm_cfg_mask initialization that an ABMC system will report which of the memory transactions can be monitored.
In patch #15 "fs/resctrl: Introduce event configuration field in struct mon_evt" the event configurations of memory transactions that should be monitored are hardcoded as below without taking into account what the system supports:

Quoted 8 lines
	resctrl_mon_resource_init() {
		...
		mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = MAX_EVT_CONFIG_BITS;
		mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
								   READS_TO_LOCAL_S_MEM |
								   NON_TEMP_WRITE_TO_LOCAL_MEM;
		...
	}

That is correct.
Changed the assignment.

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask; mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask & (READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM);

Quoted 6 lines

It may thus be that a system may not support all memory transactions it is configured to monitor. It seems to me that the initialization done in resctrl_mon_resource_init() needs to take r->mon.mbm_cfg_mask (what the system supports) into account? If so, then the same hardcoding done by patch #32 in resctrl_mbm_assign_mode_write() should also be changed.

Yes. Sure.

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#14 lore raw

PATCH v16 9/34 x86/resctrl: Add support to enable/disable AMD ABMC feature

In reply to Babu Moger

Add the functionality to enable/disable AMD ABMC feature.

AMD ABMC feature is enabled by setting enabled bit(0) in MSR L3_QOS_EXT_CFG. When the state of ABMC is changed, the MSR needs to be updated on all the logical processors in the QOS Domain.

Hardware counters will reset when ABMC state is changed.

The ABMC feature details are documented in APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

---
v16: Added Reviewed-by tag.

v15: Minor comment change in resctrl.h.

v14: Added lockdep_assert_cpus_held() in _resctrl_abmc_enable().
Removed inline for resctrl_arch_mbm_cntr_assign_enabled(). Added prototype descriptions for resctrl_arch_mbm_cntr_assign_enabled() and resctrl_arch_mbm_cntr_assign_set() in include/linux/resctrl.h.

v13: Resolved minor conflicts with recent FS/ARCH restructure.

v12: Clarified the comment on _resctrl_abmc_enable().
Added the code to reset arch state in _resctrl_abmc_enable(). Resolved the conflicts with latest merge.

v11: Moved the monitoring related calls to monitor.c file.
Moved the changes from include/linux/resctrl.h to arch/x86/kernel/cpu/resctrl/internal.h. Removed the Reviewed-by tag as patch changed. Actual code did not change.

v10: No changes.

v9: Re-ordered the MSR and added Reviewed-by tag.

v8: Commit message update and moved around the comments about L3_QOS_EXT_CFG
to _resctrl_abmc_enable.

v7: Renamed the function
resctrl_arch_get_abmc_enabled() to resctrl_arch_mbm_cntr_assign_enabled().

Merged resctrl_arch_mbm_cntr_assign_disable, resctrl_arch_mbm_cntr_assign_disable and renamed to resctrl_arch_mbm_cntr_assign_set().

Moved the function definition to linux/resctrl.h.

Passed the struct rdt_resource to these functions.
Removed resctrl_arch_reset_rmid_all() from arch code. This will be done from the caller.

v6: Renamed abmc_enabled to mbm_cntr_assign_enabled.
Used msr_set_bit and msr_clear_bit for msr updates.
Renamed resctrl_arch_abmc_enable() to resctrl_arch_mbm_cntr_assign_enable(). Renamed resctrl_arch_abmc_disable() to resctrl_arch_mbm_cntr_assign_disable(). Made _resctrl_abmc_enable to return void.

v5: Renamed resctrl_abmc_enable to resctrl_arch_abmc_enable.
Renamed resctrl_abmc_disable to resctrl_arch_abmc_disable. Introduced resctrl_arch_get_abmc_enabled to get abmc state from non-arch code.
Renamed resctrl_abmc_set_all to _resctrl_abmc_enable(). Modified commit log to make it clear about AMD ABMC feature.

v3: No changes.

v2: Few text changes in commit message.

---
 arch/x86/include/asm/msr-index.h       |  1 +
 arch/x86/kernel/cpu/resctrl/internal.h |  5 +++
 arch/x86/kernel/cpu/resctrl/monitor.c  | 45 ++++++++++++++++++++++++++
 include/linux/resctrl.h                | 20 ++++++++++++
 4 files changed, 71 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
index 7490bb5c0776..c998cf0e1375 100644
@@ -1222,6 +1222,7 @@
 /* - AMD: */
 #define MSR_IA32_MBA_BW_BASE		0xc0000200
 #define MSR_IA32_SMBA_BW_BASE		0xc0000280
+#define MSR_IA32_L3_QOS_EXT_CFG		0xc00003ff
 #define MSR_IA32_EVT_CFG_BASE		0xc0000400
 
 /* AMD-V MSRs */
arch/x86/kernel/cpu/resctrl/internal.h +5 -0
index 58dca892a5df..a79a487e639c 100644
@@ -37,6 +37,9 @@ struct arch_mbm_state {
 	u64	prev_msr;
 };
 
+/* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */
+#define ABMC_ENABLE_BIT			0
+
 /**
  * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs that share
  *			       a resource for a control function
@@ -102,6 +105,7 @@ struct msr_param {
  * @mon_scale:		cqm counter * mon_scale = occupancy in bytes
  * @mbm_width:		Monitor width, to detect and correct for overflow.
  * @cdp_enabled:	CDP state of this resource
+ * @mbm_cntr_assign_enabled:	ABMC feature is enabled
  *
  * Members of this structure are either private to the architecture
  * e.g. mbm_width, or accessed via helpers that provide abstraction. e.g.
@@ -115,6 +119,7 @@ struct rdt_hw_resource {
 	unsigned int		mon_scale;
 	unsigned int		mbm_width;
 	bool			cdp_enabled;
+	bool			mbm_cntr_assign_enabled;
 };
 
 static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r)
arch/x86/kernel/cpu/resctrl/monitor.c +45 -0

48 lines not on this page · raw message

include/linux/resctrl.h +20 -0
index eb80cc233be4..919806122c50 100644
@@ -445,6 +445,26 @@ static inline u32 resctrl_get_config_index(u32 closid,
 bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l);
 int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable);
 
+/**
+ * resctrl_arch_mbm_cntr_assign_enabled() - Check if MBM counter assignment
+ *					    mode is enabled.
+ * @r:		Pointer to the resource structure.
+ *
+ * Return:
+ * true if the assignment mode is enabled, false otherwise.
+ */
+bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r);
+
+/**
+ * resctrl_arch_mbm_cntr_assign_set() - Configure the MBM counter assignment mode.
+ * @r:		Pointer to the resource structure.
+ * @enable:	Set to true to enable, false to disable the assignment mode.
+ *
+ * Return:
+ * 0 on success, < 0 on error.
+ */
+int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable);
+
 /*
  * Update the ctrl_val and apply this config right now.
  * Must be called on one of the domain's CPUs.
Signature · 1 line
2.34.1
author reviewer
#15 lore raw

PATCH v16 10/34 fs/resctrl: Introduce the interface to display monitoring modes

In reply to Babu Moger

Introduce the resctrl file "mbm_assign_mode" to list the supported counter assignment modes.

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Each event within a resctrl group can be assigned independently in this mode.

On AMD systems "mbm_event" mode is backed by the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature and is enabled by default.

The "default" mode is the existing mode that works without the explicit counter assignment, instead relying on dynamic counter assignment by hardware that may result in hardware not dedicating a counter resulting in monitoring data reads returning "Unavailable".

Provide an interface to display the monitor modes on the system.

$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
[mbm_event]
default

Add IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED) check to support Arm64.

On x86, CONFIG_RESCTRL_ASSIGN_FIXED is not defined. On Arm64, it will be defined when the "mbm_event" mode is supported.

Add IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED) check early to ensure the user interface remains compatible with upcoming Arm64 support. IS_ENABLED() safely evaluates to 0 when the configuration is not defined.

As a result, for MPAM, the display would be either:
[default]
or
[mbm_event]

---
v16: Update with Reviewed-by tag.

v15: Minor text changes in changelog and resctrl.rst.

v14: Changed the name of the monitor mode to mbm_cntr_evt_assign based on the discussion.
https://lore.kernel.org/lkml/[email protected]/
Changed the name of the mbm_assign_mode's.
Updated resctrl.rst for mbm_event mode.
Changed subject line to fs/resctrl.

v13: Updated the commit log with motivation for adding CONFIG_RESCTRL_ASSIGN_FIXED.
Added fflag RFTYPE_RES_CACHE for mbm_assign_mode file.
Updated user doc. Removed the references to "mbm_assign_control". Resolved the conflicts with latest FS/ARCH code restructure.

v12: Minor text update in change log and user documentation.
Added the check CONFIG_RESCTRL_ASSIGN_FIXED to take care of arm platforms. This will be defined only in arm and not in x86.

v11: Renamed rdtgroup_mbm_assign_mode_show() to resctrl_mbm_assign_mode_show().
Removed few texts in resctrl.rst about AMD specific information. Updated few texts.

v10: Added few more text to user documentation clarify on the default mode.

v9: Updated user documentation based on comments.

v8: Commit message update.

v7: Updated the descriptions/commit log in resctrl.rst to generic text.
Thanks to James and Reinette.
Rename mbm_mode to mbm_assign_mode.
Introduced mutex lock in rdtgroup_mbm_mode_show().

v6: Added documentation for mbm_cntr_assign and legacy mode.
Moved mbm_mode fflags initialization to static initialization.

v5: Changed interface name to mbm_mode.
It will be always available even if ABMC feature is not supported. Added description in resctrl.rst about ABMC mode.
Fixed display abmc and legacy consistantly.

v4: Fixed the checks for legacy and abmc mode. Default it ABMC.

v3: New patch to display ABMC capability.

---
 Documentation/filesystems/resctrl.rst | 31 ++++++++++++++++++++++
 fs/resctrl/rdtgroup.c                 | 37 +++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
Documentation/filesystems/resctrl.rst +31 -0
index c97fd77a107d..b692829fec5f 100644
@@ -257,6 +257,37 @@ with the following files:
 	    # cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config
 	    0=0x30;1=0x30;3=0x15;4=0x15
 
+"mbm_assign_mode":
+	The supported counter assignment modes. The enclosed brackets indicate which mode
+	is enabled.
+	::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+	  [mbm_event]
+	  default
+
+	"mbm_event":
+
+	mbm_event mode allows users to assign a hardware counter to an RMID, event
+	pair and monitor the bandwidth usage as long as it is assigned. The hardware
+	continues to track the assigned counter until it is explicitly unassigned by
+	the user. Each event within a resctrl group can be assigned independently.
+
+	In this mode, a monitoring event can only accumulate data while it is backed
+	by a hardware counter. Use "mbm_L3_assignments" found in each CTRL_MON and MON
+	group to specify which of the events should have a counter assigned. The number
+	of counters available is described in the "num_mbm_cntrs" file. Changing the
+	mode may cause all counters on the resource to reset.
+
+	"default":
+
+	In default mode, resctrl assumes there is a hardware counter for each
+	event within every CTRL_MON and MON group. On AMD platforms, it is
+	recommended to use the mbm_event mode, if supported, to prevent reset of MBM
+	events between reads resulting from hardware re-allocating counters. This can
+	result in misleading values or display "Unavailable" if no counter is assigned
+	to the event.
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/rdtgroup.c +37 -0
index ca0475b75390..c7ca9113a12a 100644
@@ -1799,6 +1799,36 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
+					struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	bool enabled;
+
+	mutex_lock(&rdtgroup_mutex);
+	enabled = resctrl_arch_mbm_cntr_assign_enabled(r);
+
+	if (r->mon.mbm_cntr_assignable) {
+		if (enabled)
+			seq_puts(s, "[mbm_event]\n");
+		else
+			seq_puts(s, "[default]\n");
+
+		if (!IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED)) {
+			if (enabled)
+				seq_puts(s, "default\n");
+			else
+				seq_puts(s, "mbm_event\n");
+		}
+	} else {
+		seq_puts(s, "[default]\n");
+	}
+
+	mutex_unlock(&rdtgroup_mutex);
+
+	return 0;
+}
+
 /* rdtgroup information files for one cache resource. */
 static struct rftype res_common_files[] = {
 	{
@@ -1911,6 +1941,13 @@ static struct rftype res_common_files[] = {
 		.seq_show	= mbm_local_bytes_config_show,
 		.write		= mbm_local_bytes_config_write,
 	},
+	{
+		.name		= "mbm_assign_mode",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= resctrl_mbm_assign_mode_show,
+		.fflags		= RFTYPE_MON_INFO | RFTYPE_RES_CACHE,
+	},
 	{
 		.name		= "cpus",
 		.mode		= 0644,
Signature · 1 line
2.34.1
author reviewer
#16 lore raw

Re: [PATCH v16 10/34] fs/resctrl: Introduce the interface to display monitoring modes

Hi Reinette,

Quoted 159 lines · Babu Moger

Introduce the resctrl file "mbm_assign_mode" to list the supported counter assignment modes.

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Each event within a resctrl group can be assigned independently in this mode.

On AMD systems "mbm_event" mode is backed by the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature and is enabled by default.

The "default" mode is the existing mode that works without the explicit counter assignment, instead relying on dynamic counter assignment by hardware that may result in hardware not dedicating a counter resulting in monitoring data reads returning "Unavailable".

Provide an interface to display the monitor modes on the system.

$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
[mbm_event]
default

Add IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED) check to support Arm64.

On x86, CONFIG_RESCTRL_ASSIGN_FIXED is not defined. On Arm64, it will be defined when the "mbm_event" mode is supported.

Add IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED) check early to ensure the user interface remains compatible with upcoming Arm64 support. IS_ENABLED() safely evaluates to 0 when the configuration is not defined.

As a result, for MPAM, the display would be either:
[default]
or
[mbm_event]

---
v16: Update with Reviewed-by tag.

v15: Minor text changes in changelog and resctrl.rst.

v14: Changed the name of the monitor mode to mbm_cntr_evt_assign based on the discussion.
https://lore.kernel.org/lkml/[email protected]/
Changed the name of the mbm_assign_mode's.
Updated resctrl.rst for mbm_event mode.
Changed subject line to fs/resctrl.

v13: Updated the commit log with motivation for adding CONFIG_RESCTRL_ASSIGN_FIXED.
Added fflag RFTYPE_RES_CACHE for mbm_assign_mode file.
Updated user doc. Removed the references to "mbm_assign_control". Resolved the conflicts with latest FS/ARCH code restructure.

v12: Minor text update in change log and user documentation.
Added the check CONFIG_RESCTRL_ASSIGN_FIXED to take care of arm platforms. This will be defined only in arm and not in x86.

v11: Renamed rdtgroup_mbm_assign_mode_show() to resctrl_mbm_assign_mode_show().
Removed few texts in resctrl.rst about AMD specific information. Updated few texts.

v10: Added few more text to user documentation clarify on the default mode.

v9: Updated user documentation based on comments.

v8: Commit message update.

v7: Updated the descriptions/commit log in resctrl.rst to generic text.
Thanks to James and Reinette.
Rename mbm_mode to mbm_assign_mode.
Introduced mutex lock in rdtgroup_mbm_mode_show().

v6: Added documentation for mbm_cntr_assign and legacy mode.
Moved mbm_mode fflags initialization to static initialization.

v5: Changed interface name to mbm_mode.
It will be always available even if ABMC feature is not supported. Added description in resctrl.rst about ABMC mode.
Fixed display abmc and legacy consistantly.

v4: Fixed the checks for legacy and abmc mode. Default it ABMC.

v3: New patch to display ABMC capability.

---
 Documentation/filesystems/resctrl.rst | 31 ++++++++++++++++++++++
 fs/resctrl/rdtgroup.c                 | 37 +++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
Documentation/filesystems/resctrl.rst +31 -0
index c97fd77a107d..b692829fec5f 100644
@@ -257,6 +257,37 @@ with the following files:
 	    # cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config
 	    0=0x30;1=0x30;3=0x15;4=0x15
 
+"mbm_assign_mode":
+	The supported counter assignment modes. The enclosed brackets indicate which mode
+	is enabled.
+	::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+	  [mbm_event]
+	  default
+
+	"mbm_event":
+
+	mbm_event mode allows users to assign a hardware counter to an RMID, event
+	pair and monitor the bandwidth usage as long as it is assigned. The hardware
+	continues to track the assigned counter until it is explicitly unassigned by
+	the user. Each event within a resctrl group can be assigned independently.
+
+	In this mode, a monitoring event can only accumulate data while it is backed
+	by a hardware counter. Use "mbm_L3_assignments" found in each CTRL_MON and MON
+	group to specify which of the events should have a counter assigned. The number
+	of counters available is described in the "num_mbm_cntrs" file. Changing the
+	mode may cause all counters on the resource to reset.
+
+	"default":
+
+	In default mode, resctrl assumes there is a hardware counter for each
+	event within every CTRL_MON and MON group. On AMD platforms, it is
+	recommended to use the mbm_event mode, if supported, to prevent reset of MBM
+	events between reads resulting from hardware re-allocating counters. This can
+	result in misleading values or display "Unavailable" if no counter is assigned
+	to the event.
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/rdtgroup.c +19 -0
index ca0475b75390..c7ca9113a12a 100644
@@ -1799,6 +1799,36 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
+					struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	bool enabled;
+
+	mutex_lock(&rdtgroup_mutex);
+	enabled = resctrl_arch_mbm_cntr_assign_enabled(r);
+
+	if (r->mon.mbm_cntr_assignable) {
+		if (enabled)
+			seq_puts(s, "[mbm_event]\n");
+		else
+			seq_puts(s, "[default]\n");
+
+		if (!IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED)) {
+			if (enabled)
+				seq_puts(s, "default\n");
+			else

fs/resctrl/rdtgroup.c static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of, · line 1830

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+				seq_puts(s, "mbm_event\n");
+		}
+	} else {
+		seq_puts(s, "[default]\n");
+	}
+
+	mutex_unlock(&rdtgroup_mutex);
+
+	return 0;
+}

The resctrl_mbm_assign_mode_show() can also be moved to monitor.c.

What do you think?

Signature · 2 lines
Thanks
Babu Moger
maintainer
#17 lore raw

Re: [PATCH v16 10/34] fs/resctrl: Introduce the interface to display monitoring modes

Hi Babu,

Quoted 41 lines · Babu
Quoted 27 lines · Babu Moger
fs/resctrl/rdtgroup.c +19 -0
index ca0475b75390..c7ca9113a12a 100644
@@ -1799,6 +1799,36 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
+					struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	bool enabled;
+
+	mutex_lock(&rdtgroup_mutex);
+	enabled = resctrl_arch_mbm_cntr_assign_enabled(r);
+
+	if (r->mon.mbm_cntr_assignable) {
+		if (enabled)
+			seq_puts(s, "[mbm_event]\n");
+		else
+			seq_puts(s, "[default]\n");
+
+		if (!IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED)) {
+			if (enabled)
+				seq_puts(s, "default\n");
+			else

fs/resctrl/rdtgroup.c static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of, · line 1830

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+				seq_puts(s, "mbm_event\n");
+		}
+	} else {
+		seq_puts(s, "[default]\n");
+	}
+
+	mutex_unlock(&rdtgroup_mutex);
+
+	return 0;
+}

The resctrl_mbm_assign_mode_show() can also be moved to monitor.c.

Quoted 1 line

What do you think?

I agree. monitor.c is appropriate for this code.

Reinette

author reviewer
#18 lore raw

PATCH v16 11/34 fs/resctrl: Add resctrl file to display number of assignable counters

In reply to Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Create 'num_mbm_cntrs' resctrl file that displays the number of counters supported in each domain. 'num_mbm_cntrs' is only visible to user space when the system supports "mbm_event" mode.

---
v16: Added Reviewed-by tag.

v15: Changed "assign a hardware counter ID" to "assign a hardware counter"
in couple of places.

v14: Minor update to changelog and user doc (resctrl.rst).
Changed subject line to fs/resctrl.

v13: Updated the changelog.
Added fflags RFTYPE_RES_CACHE to the file num_mbm_cntrs.
Replaced seq_puts from seq_putc where applicable.
Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c/rdtgroup.c have been split between FS and ARCH directories.

v12: Changed the code to display the max supported monitoring counters in
each domain. Also updated the documentation.
Resolved the conflict with the latest code.

v11: Renamed rdtgroup_num_mbm_cntrs_show() to resctrl_num_mbm_cntrs_show().
Few monor text updates.

v10: No changes.

v9: Updated user document based on the comments.
Will add a new file available_mbm_cntrs later in the series.

v8: Commit message update and documentation update.

v7: Minor commit log text changes.

v6: No changes.

v5: Changed the display name from num_cntrs to num_mbm_cntrs.
Updated the commit message.
Moved the patch after mbm_mode is introduced.

v4: Changed the counter name to num_cntrs. And few text changes.

v3: Changed the field name to mbm_assign_cntrs.

v2: Changed the field name to mbm_assignable_counters from abmc_counter.

---
 Documentation/filesystems/resctrl.rst | 11 ++++++++++
 fs/resctrl/monitor.c                  |  2 ++
 fs/resctrl/rdtgroup.c                 | 30 +++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
Documentation/filesystems/resctrl.rst +11 -0
index b692829fec5f..4eb27530be6f 100644
@@ -288,6 +288,17 @@ with the following files:
 	result in misleading values or display "Unavailable" if no counter is assigned
 	to the event.
 
+"num_mbm_cntrs":
+	The maximum number of counters (total of available and assigned counters) in
+	each domain when the system supports mbm_event mode.
+
+	For example, on a system with maximum of 32 memory bandwidth monitoring
+	counters in each of its L3 domains:
+	::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
+	  0=32;1=32
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 66c8c635f4b3..4539b08db7b9 100644
@@ -929,6 +929,8 @@ int resctrl_mon_resource_init(void)
 			resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
 		if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
 			resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
+		resctrl_file_fflags_init("num_mbm_cntrs",
+					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +30 -0
index c7ca9113a12a..acbda73a9b9d 100644
@@ -1829,6 +1829,30 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
+				      struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *dom;
+	bool sep = false;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+		if (sep)
+			seq_putc(s, ';');
+
+		seq_printf(s, "%d=%d", dom->hdr.id, r->mon.num_mbm_cntrs);
+		sep = true;
+	}
+	seq_putc(s, '\n');
+
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+	return 0;
+}
+
 /* rdtgroup information files for one cache resource. */
 static struct rftype res_common_files[] = {
 	{
@@ -1866,6 +1890,12 @@ static struct rftype res_common_files[] = {
 		.seq_show	= rdt_default_ctrl_show,
 		.fflags		= RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
 	},
+	{
+		.name		= "num_mbm_cntrs",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= resctrl_num_mbm_cntrs_show,
+	},
 	{
 		.name		= "min_cbm_bits",
 		.mode		= 0444,
Signature · 1 line
2.34.1
author reviewer
#19 lore raw

Re: [PATCH v16 11/34] fs/resctrl: Add resctrl file to display number of assignable counters

Hi Reinette,

Quoted 115 lines · Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Create 'num_mbm_cntrs' resctrl file that displays the number of counters supported in each domain. 'num_mbm_cntrs' is only visible to user space when the system supports "mbm_event" mode.

---
v16: Added Reviewed-by tag.

v15: Changed "assign a hardware counter ID" to "assign a hardware counter"
in couple of places.

v14: Minor update to changelog and user doc (resctrl.rst).
Changed subject line to fs/resctrl.

v13: Updated the changelog.
Added fflags RFTYPE_RES_CACHE to the file num_mbm_cntrs.
Replaced seq_puts from seq_putc where applicable.
Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c/rdtgroup.c have been split between FS and ARCH directories.

v12: Changed the code to display the max supported monitoring counters in
each domain. Also updated the documentation.
Resolved the conflict with the latest code.

v11: Renamed rdtgroup_num_mbm_cntrs_show() to resctrl_num_mbm_cntrs_show().
Few monor text updates.

v10: No changes.

v9: Updated user document based on the comments.
Will add a new file available_mbm_cntrs later in the series.

v8: Commit message update and documentation update.

v7: Minor commit log text changes.

v6: No changes.

v5: Changed the display name from num_cntrs to num_mbm_cntrs.
Updated the commit message.
Moved the patch after mbm_mode is introduced.

v4: Changed the counter name to num_cntrs. And few text changes.

v3: Changed the field name to mbm_assign_cntrs.

v2: Changed the field name to mbm_assignable_counters from abmc_counter.

---
 Documentation/filesystems/resctrl.rst | 11 ++++++++++
 fs/resctrl/monitor.c                  |  2 ++
 fs/resctrl/rdtgroup.c                 | 30 +++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
Documentation/filesystems/resctrl.rst +11 -0
index b692829fec5f..4eb27530be6f 100644
@@ -288,6 +288,17 @@ with the following files:
 	result in misleading values or display "Unavailable" if no counter is assigned
 	to the event.
 
+"num_mbm_cntrs":
+	The maximum number of counters (total of available and assigned counters) in
+	each domain when the system supports mbm_event mode.
+
+	For example, on a system with maximum of 32 memory bandwidth monitoring
+	counters in each of its L3 domains:
+	::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
+	  0=32;1=32
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 66c8c635f4b3..4539b08db7b9 100644
@@ -929,6 +929,8 @@ int resctrl_mon_resource_init(void)
 			resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
 		if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
 			resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
+		resctrl_file_fflags_init("num_mbm_cntrs",
+					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +13 -0
index c7ca9113a12a..acbda73a9b9d 100644
@@ -1829,6 +1829,30 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
+				      struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *dom;
+	bool sep = false;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+		if (sep)
+			seq_putc(s, ';');

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1854

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+
+		seq_printf(s, "%d=%d", dom->hdr.id, r->mon.num_mbm_cntrs);
+		sep = true;
+	}
+	seq_putc(s, '\n');
+
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+	return 0;
+}

How about moving this also to monitor.c?

Quoted 16 lines
fs/resctrl/rdtgroup.c +6 -0
 /* rdtgroup information files for one cache resource. */
 static struct rftype res_common_files[] = {
 	{
@@ -1866,6 +1890,12 @@ static struct rftype res_common_files[] = {
 		.seq_show	= rdt_default_ctrl_show,
 		.fflags		= RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE,
 	},
+	{
+		.name		= "num_mbm_cntrs",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= resctrl_num_mbm_cntrs_show,
+	},
 	{
 		.name		= "min_cbm_bits",
 		.mode		= 0444,
Signature · 2 lines
Thanks
Babu Moger
maintainer
#20 lore raw

Re: [PATCH v16 11/34] fs/resctrl: Add resctrl file to display number of assignable counters

Hi Babu,

Quoted 26 lines · Babu
Quoted 25 lines · Babu Moger
fs/resctrl/rdtgroup.c +17 -0
index c7ca9113a12a..acbda73a9b9d 100644
@@ -1829,6 +1829,30 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
+				      struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *dom;
+	bool sep = false;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+		if (sep)
+			seq_putc(s, ';');
+
+		seq_printf(s, "%d=%d", dom->hdr.id, r->mon.num_mbm_cntrs);
+		sep = true;
+	}
Quoted 8 lines

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1854

Quoted 6 lines
fs/resctrl/rdtgroup.c +6 -0
+	seq_putc(s, '\n');
+
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+	return 0;
+}

How about moving this also to monitor.c?

Yes, this sounds good to me. This is what I had in mind when suggesting in [1] that the monitoring related handlers should be located in monitor.c

Reinette

[1] https://lore.kernel.org/lkml/[email protected]/

author reviewer
#21 lore raw

PATCH v16 12/34 fs/resctrl: Introduce mbm_cntr_cfg to track assignable counters per domain

In reply to Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Counters are assigned/unassigned at monitoring domain level.

Manage a monitoring domain's hardware counters using a per monitoring domain array of struct mbm_cntr_cfg that is indexed by the hardware counter ID. A hardware counter's configuration contains the MBM event ID and points to the monitoring group that it is assigned to, with a NULL pointer meaning that the hardware counter is available for assignment.

There is no direct way to determine which hardware counters are assigned to a particular monitoring group. Check every entry of every hardware counter configuration array in every monitoring domain to query which MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters (32 to 64).

---
v16: Added Reviewed-by tag.

v15: Minor changelog update.
Removed evt_cfg from struct mbm_cntr_cfg based on the discussion.
https://lore.kernel.org/lkml/[email protected]/

v14: Updated code documentation and changelog.
Fixed up the indentation in resctrl.h.
Changed subject line to fs/resctrl.

v13: Resolved conflicts caused by the recent FS/ARCH code restructure.
The files monitor.c/rdtgroup.c have been split between FS and ARCH directories.

v12: Fixed the struct mbm_cntr_cfg code documentation.
Removed few strange charactors in changelog.
Added the counter range for better understanding. Moved the struct mbm_cntr_cfg definition to resctrl/internal.h as suggested by James.

v11: Refined the change log based on Reinette's feedback.
Fixed few style issues.

v10: Patch changed completely to handle the counters at domain level.
https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5AFgD9cQDCUg@mail.gmail.com/
Removed Reviewed-by tag.
Did not see the need to add cntr_id in mbm_state structure. Not used in the code.

v9: Added Reviewed-by tag. No other changes.

v8: Minor commit message changes.

v7: Added check mbm_cntr_assignable for allocating bitmap mbm_cntr_map

v6: New patch to add domain level assignment.

---
 fs/resctrl/rdtgroup.c   |  8 ++++++++
 include/linux/resctrl.h | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
fs/resctrl/rdtgroup.c +8 -0
index acbda73a9b9d..a09566720d4f 100644
@@ -4086,6 +4086,7 @@ static void domain_destroy_mon_state(struct rdt_mon_domain *d)
 {
 	int idx;
 
+	kfree(d->cntr_cfg);
 	bitmap_free(d->rmid_busy_llc);
 	for_each_mbm_idx(idx) {
 		kfree(d->mbm_states[idx]);
@@ -4169,6 +4170,13 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domain
 			goto cleanup;
 	}
 
+	if (resctrl_is_mbm_enabled() && r->mon.mbm_cntr_assignable) {
+		tsize = sizeof(*d->cntr_cfg);
+		d->cntr_cfg = kcalloc(r->mon.num_mbm_cntrs, tsize, GFP_KERNEL);
+		if (!d->cntr_cfg)
+			goto cleanup;
+	}
+
 	return 0;
 cleanup:
 	bitmap_free(d->rmid_busy_llc);
include/linux/resctrl.h +15 -0
index 919806122c50..e013caba6641 100644
@@ -156,6 +156,18 @@ struct rdt_ctrl_domain {
 	u32				*mbps_val;
 };
 
+/**
+ * struct mbm_cntr_cfg - Assignable counter configuration.
+ * @evtid:		MBM event to which the counter is assigned. Only valid
+ *			if @rdtgroup is not NULL.
+ * @rdtgrp:		resctrl group assigned to the counter. NULL if the
+ *			counter is free.
+ */
+struct mbm_cntr_cfg {
+	enum resctrl_event_id	evtid;
+	struct rdtgroup		*rdtgrp;
+};
+
 /**
  * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource
  * @hdr:		common header for different domain types
@@ -168,6 +180,8 @@ struct rdt_ctrl_domain {
  * @cqm_limbo:		worker to periodically read CQM h/w counters
  * @mbm_work_cpu:	worker CPU for MBM h/w counters
  * @cqm_work_cpu:	worker CPU for CQM h/w counters
+ * @cntr_cfg:		array of assignable counters' configuration (indexed
+ *			by counter ID)
  */
 struct rdt_mon_domain {
 	struct rdt_domain_hdr		hdr;
@@ -178,6 +192,7 @@ struct rdt_mon_domain {
 	struct delayed_work		cqm_limbo;
 	int				mbm_work_cpu;
 	int				cqm_work_cpu;
+	struct mbm_cntr_cfg		*cntr_cfg;
 };
 
 /**
Signature · 1 line
2.34.1
author reviewer
#22 lore raw

PATCH v16 13/34 fs/resctrl: Introduce interface to display number of free MBM counters

In reply to Babu Moger

Introduce the "available_mbm_cntrs" resctrl file to display the number of counters available for assignment in each domain when "mbm_event" mode is enabled.

---
v16: Added Reviewed-by tag.

v15: Minor changelog text update.
Minor resctrl.rst text update and corrected the error text in resctrl_available_mbm_cntrs_show().
Changed the goto label to out_unlock for consistency.

v14: Minor changelog update.
Changed subject line to fs/resctrl.

v13: Resolved conflicts caused by the recent FS/ARCH code restructure.
The files monitor.c and rdtgroup.c file has now been split between the FS and ARCH directories.

v12: Minor change to change log.
Updated the documentation text with an example.
Replaced seq_puts(s, ";") with seq_putc(s, ';');
Added missing rdt_last_cmd_clear() in resctrl_available_mbm_cntrs_show().

v11: Rename rdtgroup_available_mbm_cntrs_show() to resctrl_available_mbm_cntrs_show().
Few minor text changes.

v10: Patch changed to handle the counters at domain level.
https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5AFgD9cQDCUg@mail.gmail.com/
So, display logic also changed now.

v9: New patch

---
 Documentation/filesystems/resctrl.rst | 11 ++++++
 fs/resctrl/monitor.c                  |  2 ++
 fs/resctrl/rdtgroup.c                 | 48 +++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
Documentation/filesystems/resctrl.rst +11 -0
index 4eb27530be6f..446736dbd97f 100644
@@ -299,6 +299,17 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
 	  0=32;1=32
 
+"available_mbm_cntrs":
+	The number of counters available for assignment in each domain when mbm_event
+	mode is enabled on the system.
+
+	For example, on a system with 30 available [hardware] assignable counters
+	in each of its L3 domains:
+	::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
+	  0=30;1=30
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 4539b08db7b9..a0b0ea45c7b4 100644
@@ -931,6 +931,8 @@ int resctrl_mon_resource_init(void)
 			resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
 		resctrl_file_fflags_init("num_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("available_mbm_cntrs",
+					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.34.1
author reviewer
#23 lore raw

Re: [PATCH v16 13/34] fs/resctrl: Introduce interface to display number of free MBM counters

Hi Reinette,

Quoted 115 lines · Babu Moger

Introduce the "available_mbm_cntrs" resctrl file to display the number of counters available for assignment in each domain when "mbm_event" mode is enabled.

---
v16: Added Reviewed-by tag.

v15: Minor changelog text update.
Minor resctrl.rst text update and corrected the error text in resctrl_available_mbm_cntrs_show().
Changed the goto label to out_unlock for consistency.

v14: Minor changelog update.
Changed subject line to fs/resctrl.

v13: Resolved conflicts caused by the recent FS/ARCH code restructure.
The files monitor.c and rdtgroup.c file has now been split between the FS and ARCH directories.

v12: Minor change to change log.
Updated the documentation text with an example.
Replaced seq_puts(s, ";") with seq_putc(s, ';');
Added missing rdt_last_cmd_clear() in resctrl_available_mbm_cntrs_show().

v11: Rename rdtgroup_available_mbm_cntrs_show() to resctrl_available_mbm_cntrs_show().
Few minor text changes.

v10: Patch changed to handle the counters at domain level.
https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5AFgD9cQDCUg@mail.gmail.com/
So, display logic also changed now.

v9: New patch

---
 Documentation/filesystems/resctrl.rst | 11 ++++++
 fs/resctrl/monitor.c                  |  2 ++
 fs/resctrl/rdtgroup.c                 | 48 +++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
Documentation/filesystems/resctrl.rst +11 -0
index 4eb27530be6f..446736dbd97f 100644
@@ -299,6 +299,17 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
 	  0=32;1=32
 
+"available_mbm_cntrs":
+	The number of counters available for assignment in each domain when mbm_event
+	mode is enabled on the system.
+
+	For example, on a system with 30 available [hardware] assignable counters
+	in each of its L3 domains:
+	::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
+	  0=30;1=30
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 4539b08db7b9..a0b0ea45c7b4 100644
@@ -931,6 +931,8 @@ int resctrl_mon_resource_init(void)
 			resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
 		resctrl_file_fflags_init("num_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("available_mbm_cntrs",
+					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +32 -0
index a09566720d4f..15d10c346307 100644
@@ -1853,6 +1853,48 @@ static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of,
+					    struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *dom;
+	bool sep = false;
+	u32 cntrs, i;
+	int ret = 0;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		rdt_last_cmd_puts("mbm_event mode is not enabled\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+		if (sep)
+			seq_putc(s, ';');
+
+		cntrs = 0;
+		for (i = 0; i < r->mon.num_mbm_cntrs; i++) {
+			if (!dom->cntr_cfg[i].rdtgrp)
+				cntrs++;
+		}
+
+		seq_printf(s, "%d=%u", dom->hdr.id, cntrs);
+		sep = true;

fs/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 1897

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+	}
+	seq_putc(s, '\n');
+
+out_unlock:
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+
+	return ret;
+}
+

This also can be moved to monitor.c. What do you think?

Quoted 16 lines
fs/resctrl/rdtgroup.c +6 -0
 /* rdtgroup information files for one cache resource. */
 static struct rftype res_common_files[] = {
 	{
@@ -1876,6 +1918,12 @@ static struct rftype res_common_files[] = {
 		.seq_show	= rdt_mon_features_show,
 		.fflags		= RFTYPE_MON_INFO,
 	},
+	{
+		.name		= "available_mbm_cntrs",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= resctrl_available_mbm_cntrs_show,
+	},
 	{
 		.name		= "num_rmids",
 		.mode		= 0444,
Signature · 2 lines
Thanks
Babu Moger
maintainer
#24 lore raw

Re: [PATCH v16 13/34] fs/resctrl: Introduce interface to display number of free MBM counters

Hi Babu,

Quoted 44 lines · Babu
Quoted 44 lines
fs/resctrl/rdtgroup.c +36 -0
index a09566720d4f..15d10c346307 100644
@@ -1853,6 +1853,48 @@ static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of,
+					    struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *dom;
+	bool sep = false;
+	u32 cntrs, i;
+	int ret = 0;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		rdt_last_cmd_puts("mbm_event mode is not enabled\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+		if (sep)
+			seq_putc(s, ';');
+
+		cntrs = 0;
+		for (i = 0; i < r->mon.num_mbm_cntrs; i++) {
+			if (!dom->cntr_cfg[i].rdtgrp)
+				cntrs++;
+		}
+
+		seq_printf(s, "%d=%u", dom->hdr.id, cntrs);
+		sep = true;
+	}
+	seq_putc(s, '\n');
+
+out_unlock:
Quoted 8 lines

fs/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 1897

Quoted 6 lines
fs/resctrl/rdtgroup.c +6 -0
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+
+	return ret;
+}
+

This also can be moved to monitor.c. What do you think?

Yes, I believe monitor.c is most appropriate for all the monitoring related handlers [1].

Reinette

[1] https://lore.kernel.org/lkml/[email protected]/

author reviewer
#25 lore raw

Re: [PATCH v16 13/34] fs/resctrl: Introduce interface to display number of free MBM counters

Hi Reinette,

Quoted 56 lines · Reinette Chatre

Hi Babu,

Quoted 44 lines · Babu
Quoted 44 lines
fs/resctrl/rdtgroup.c +36 -0
index a09566720d4f..15d10c346307 100644
@@ -1853,6 +1853,48 @@ static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of,
+					    struct seq_file *s, void *v)
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *dom;
+	bool sep = false;
+	u32 cntrs, i;
+	int ret = 0;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		rdt_last_cmd_puts("mbm_event mode is not enabled\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+		if (sep)
+			seq_putc(s, ';');
+
+		cntrs = 0;
+		for (i = 0; i < r->mon.num_mbm_cntrs; i++) {
+			if (!dom->cntr_cfg[i].rdtgrp)
+				cntrs++;
+		}
+
+		seq_printf(s, "%d=%u", dom->hdr.id, cntrs);
+		sep = true;
+	}
+	seq_putc(s, '\n');
+
+out_unlock:
Quoted 8 lines

fs/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 1897

Quoted 6 lines
fs/resctrl/rdtgroup.c +6 -0
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+
+	return ret;
+}
+

This also can be moved to monitor.c. What do you think?

Quoted 2 lines

Yes, I believe monitor.c is most appropriate for all the monitoring related handlers [1].

Sure. Will do.

Quoted 5 lines

Reinette

[1] https://lore.kernel.org/lkml/[email protected]/

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#26 lore raw

PATCH v16 14/34 x86/resctrl: Add data structures and definitions for ABMC assignment

In reply to Babu Moger

The ABMC feature allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

The ABMC feature implements an MSR L3_QOS_ABMC_CFG (C000_03FDh). ABMC counter assignment is done by setting the counter id, bandwidth source (RMID) and bandwidth configuration.

Attempts to read or write the MSR when ABMC is not enabled will result in a #GP(0) exception.

Introduce the data structures and definitions for MSR L3_QOS_ABMC_CFG (0xC000_03FDh):
=========================================================================
Bits Mnemonic Description Access Reset
Type Value
=========================================================================
63 CfgEn Configuration Enable R/W 0

62 CtrEn Enable/disable counting R/W 0

61:53 – Reserved MBZ 0

52:48 CtrID Counter Identifier R/W 0

47 IsCOS BwSrc field is a CLOSID R/W 0
(not an RMID)

46:44 – Reserved MBZ 0

43:32 BwSrc Bandwidth Source R/W 0
(RMID or CLOSID)

31:0 BwType Bandwidth configuration R/W 0
tracked by the CtrID
==========================================================================

The feature details are documented in the APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).

---
v16: Added Reviewed-by tag.

v15: Minor changelog update.

v14: Removed BMEC reference internal.h.
Updated the changelog and code documentation.

v13: Removed the Reviewed-by tag as there is commit log change to remove
BMEC reference.

v12: No changes.

v11: No changes.

v10: No changes.

v9: Removed the references of L3_QOS_ABMC_DSC.
Text changes about configuration in kernel doc.

v8: Update the configuration notes in kernel_doc.
Few commit message update.

v7: Removed the reference of L3_QOS_ABMC_DSC as it is not used anymore.
Moved the configuration notes to kernel_doc.
Adjusted the tabs for l3_qos_abmc_cfg and checkpatch seems happy.

v6: Removed all the fs related changes.
Added note on CfgEn,CtrEn.
Removed the definitions which are not used.
Removed cntr_id initialization.

v5: Moved assignment flags here (path 10/19 of v4).
Added MON_CNTR_UNSET definition to initialize cntr_id's. More details in commit log.
Renamed few fields in l3_qos_abmc_cfg for readability.

v4: Added more descriptions.
Changed the name abmc_ctr_id to ctr_id.
Added L3_QOS_ABMC_DSC. Used for reading the configuration.

v3: No changes.

v2: No changes.

---
 arch/x86/include/asm/msr-index.h       |  1 +
 arch/x86/kernel/cpu/resctrl/internal.h | 36 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
index c998cf0e1375..3ad7f37b8ad8 100644
@@ -1222,6 +1222,7 @@
 /* - AMD: */
 #define MSR_IA32_MBA_BW_BASE		0xc0000200
 #define MSR_IA32_SMBA_BW_BASE		0xc0000280
+#define MSR_IA32_L3_QOS_ABMC_CFG	0xc00003fd
 #define MSR_IA32_L3_QOS_EXT_CFG		0xc00003ff
 #define MSR_IA32_EVT_CFG_BASE		0xc0000400
 
arch/x86/kernel/cpu/resctrl/internal.h +36 -0
index a79a487e639c..6bf6042f11b6 100644
@@ -164,6 +164,42 @@ union cpuid_0x10_x_edx {
 	unsigned int full;
 };
 
+/*
+ * ABMC counters are configured by writing to L3_QOS_ABMC_CFG.
+ *
+ * @bw_type		: Event configuration that represent the memory
+ *			  transactions being tracked by the @cntr_id.
+ * @bw_src		: Bandwidth source (RMID or CLOSID).
+ * @reserved1		: Reserved.
+ * @is_clos		: @bw_src field is a CLOSID (not an RMID).
+ * @cntr_id		: Counter identifier.
+ * @reserved		: Reserved.
+ * @cntr_en		: Counting enable bit.
+ * @cfg_en		: Configuration enable bit.
+ *
+ * Configuration and counting:
+ * Counter can be configured across multiple writes to MSR. Configuration
+ * is applied only when @cfg_en = 1. Counter @cntr_id is reset when the
+ * configuration is applied.
+ * @cfg_en = 1, @cntr_en = 0 : Apply @cntr_id configuration but do not
+ *                             count events.
+ * @cfg_en = 1, @cntr_en = 1 : Apply @cntr_id configuration and start
+ *                             counting events.
+ */
+union l3_qos_abmc_cfg {
+	struct {
+		unsigned long bw_type  :32,
+			      bw_src   :12,
+			      reserved1: 3,
+			      is_clos  : 1,
+			      cntr_id  : 5,
+			      reserved : 9,
+			      cntr_en  : 1,
+			      cfg_en   : 1;
+	} split;
+	unsigned long full;
+};
+
 void rdt_ctrl_update(void *arg);
 
 int rdt_get_mon_l3_config(struct rdt_resource *r);
Signature · 1 line
2.34.1
author reviewer
#27 lore raw

PATCH v16 15/34 fs/resctrl: Introduce event configuration field in struct mon_evt

In reply to Babu Moger

When supported, mbm_event counter assignment mode allows the user to configure events to track specific types of memory transactions.

Introduce the evt_cfg field in struct mon_evt to define the type of memory transactions tracked by a monitoring event. Also add a helper function to get the evt_cfg value.

---
v16: Added Reviewed-by tag.

v15: Updated the changelog.
Removed resctrl_set_mon_evt_cfg().
Moved the event initialization to resctrl_mon_resource_init().

v14: This is updated patch from previous patch.
https://lore.kernel.org/lkml/95b7f4e9d72773e8fda327fc80b429646efc3a8a.1747349530.git.babu.moger@amd.com/
Removed mbm_mode as it is not required anymore. Added resctrl_get_mon_evt_cfg() and resctrl_set_mon_evt_cfg().

v13: New patch to handle different event configuration types with
mbm_cntr_assign mode.

---
 fs/resctrl/internal.h   | 5 +++++
 fs/resctrl/monitor.c    | 9 +++++++++
 include/linux/resctrl.h | 2 ++
 3 files changed, 16 insertions(+)
fs/resctrl/internal.h +5 -0
index 4f315b7e9ec0..db3a0f12ad77 100644
@@ -56,6 +56,10 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
  * @evtid:		event id
  * @rid:		resource id for this event
  * @name:		name of the event
+ * @evt_cfg:		Event configuration value that represents the
+ *			memory transactions (e.g., READS_TO_LOCAL_MEM,
+ *			READS_TO_REMOTE_MEM) being tracked by @evtid.
+ *			Only valid if @evtid is an MBM event.
  * @configurable:	true if the event is configurable
  * @enabled:		true if the event is enabled
  */
@@ -63,6 +67,7 @@ struct mon_evt {
 	enum resctrl_event_id	evtid;
 	enum resctrl_res_level	rid;
 	char			*name;
+	u32			evt_cfg;
 	bool			configurable;
 	bool			enabled;
 };
fs/resctrl/monitor.c +9 -0
index a0b0ea45c7b4..a089867262fa 100644
@@ -884,6 +884,11 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid)
 	       mon_event_all[eventid].enabled;
 }
 
+u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id evtid)
+{
+	return mon_event_all[evtid].evt_cfg;
+}
+
 /**
  * resctrl_mon_resource_init() - Initialise global monitoring structures.
  *
@@ -929,6 +934,10 @@ int resctrl_mon_resource_init(void)
 			resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID);
 		if (!resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
 			resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
+		mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = MAX_EVT_CONFIG_BITS;
+		mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
+								   READS_TO_LOCAL_S_MEM |
+								   NON_TEMP_WRITE_TO_LOCAL_MEM;
 		resctrl_file_fflags_init("num_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("available_mbm_cntrs",
include/linux/resctrl.h +2 -0
index e013caba6641..87daa4ca312d 100644
@@ -409,6 +409,8 @@ static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid)
 		eventid <= QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
+u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id eventid);
+
 /* Iterate over all memory bandwidth events */
 #define for_each_mbm_event_id(eventid)				\
 	for (eventid = QOS_L3_MBM_TOTAL_EVENT_ID;		\
Signature · 1 line
2.34.1
author reviewer
#28 lore raw

PATCH v16 16/34 x86,fs/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC

In reply to Babu Moger

The ABMC feature allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Implement an x86 architecture-specific handler to configure a counter. This architecture specific handler is called by resctrl fs when a counter is assigned or unassigned as well as when an already assigned counter's configuration should be updated. Configure counters by writing to the L3_QOS_ABMC_CFG MSR, specifying the counter ID, bandwidth source (RMID), and event configuration.

The feature details are documented in the APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming

    Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth
    Monitoring (ABMC).

---
v16: Updated the changelog.
Reset the architectural state in resctrl_arch_config_cntr() in both assign and unassign cases.

v15: Minor changelog update.
Added few code comments in include/linux/resctrl.h.

v14: Removed evt_cfg parameter in resctrl_arch_config_cntr(). Get evt_cfg
only when assign is required.
Minor update to changelog.

v13: Moved resctrl_arch_config_cntr() prototype to include/linux/resctrl.h.
Changed resctrl_arch_config_cntr() to retun void from int. Updated the kernal doc for the prototype.
Updated the code comment.

12: Added the check to reset the architecture-specific state only when
assign is requested.
Added evt_cfg as the parameter as the user will be passing the event configuration from /info/L3_MON/event_configs/.

v11: Moved resctrl_arch_assign_cntr() and resctrl_abmc_config_one_amd() to
monitor.c.
Added the code to reset the arch state in resctrl_arch_assign_cntr(). Also removed resctrl_arch_reset_rmid() inside IPI as the counters are reset from the callers.
Re-wrote commit message.

v10: Added call resctrl_arch_reset_rmid() to reset the RMID in the domain
inside IPI call.
SMP and non-SMP call support is not required in resctrl_arch_config_cntr with new domain specific assign approach/data structure. Commit message update.

v9: Removed the code to reset the architectural state. It will done
in another patch.

v8: Rename resctrl_arch_assign_cntr to resctrl_arch_config_cntr.

v7: Separated arch and fs functions. This patch only has arch implementation.
Added struct rdt_resource to the interface resctrl_arch_assign_cntr. Rename rdtgroup_abmc_cfg() to resctrl_abmc_config_one_amd().

v6: Removed mbm_cntr_alloc() from this patch to keep fs and arch code
separate.
Added code to update the counter assignment at domain level.

v5: Few name changes to match cntr_id.
Changed the function names to
rdtgroup_assign_cntr
resctr_arch_assign_cntr
More comments on commit log.
Added function summary.

v4: Commit message update.
User bitmap APIs where applicable. Changed the interfaces considering MPAM(arm). Added domain specific assignment.

v3: Removed the static from the prototype of rdtgroup_assign_abmc.
The function is not called directly from user anymore. These changes are related to global assignment interface.

v2: Minor text changes in commit message.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 36 +++++++++++++++++++++++++++
 include/linux/resctrl.h               | 19 ++++++++++++++
 2 files changed, 55 insertions(+)
arch/x86/kernel/cpu/resctrl/monitor.c +36 -0
index cce35a0ad455..ed295a6c5e66 100644
@@ -444,3 +444,39 @@ bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r)
 {
 	return resctrl_to_arch_res(r)->mbm_cntr_assign_enabled;
 }
+
+static void resctrl_abmc_config_one_amd(void *info)
+{
+	union l3_qos_abmc_cfg *abmc_cfg = info;
+
+	wrmsrl(MSR_IA32_L3_QOS_ABMC_CFG, abmc_cfg->full);
+}
+
+/*
+ * Send an IPI to the domain to assign the counter to RMID, event pair.
+ */
+void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			      enum resctrl_event_id evtid, u32 rmid, u32 closid,
+			      u32 cntr_id, bool assign)
+{
+	struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
+	union l3_qos_abmc_cfg abmc_cfg = { 0 };
+	struct arch_mbm_state *am;
+
+	abmc_cfg.split.cfg_en = 1;
+	abmc_cfg.split.cntr_en = assign ? 1 : 0;
+	abmc_cfg.split.cntr_id = cntr_id;
+	abmc_cfg.split.bw_src = rmid;
+	if (assign)
+		abmc_cfg.split.bw_type = resctrl_get_mon_evt_cfg(evtid);
+
+	smp_call_function_any(&d->hdr.cpu_mask, resctrl_abmc_config_one_amd, &abmc_cfg, 1);
+
+	/*
+	 * The hardware counter is reset (because cfg_en == 1) so there is no
+	 * need to record initial non-zero counts.
+	 */
+	am = get_arch_mbm_state(hw_dom, rmid, evtid);
+	if (am)
+		memset(am, 0, sizeof(*am));
+}
include/linux/resctrl.h +19 -0
index 87daa4ca312d..50e38445183a 100644
@@ -594,6 +594,25 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *
  */
 void resctrl_arch_reset_all_ctrls(struct rdt_resource *r);
 
+/**
+ * resctrl_arch_config_cntr() - Configure the counter with its new RMID
+ *				and event details.
+ * @r:			Resource structure.
+ * @d:			The domain in which counter with ID @cntr_id should be configured.
+ * @evtid:		Monitoring event type (e.g., QOS_L3_MBM_TOTAL_EVENT_ID
+ *			or QOS_L3_MBM_LOCAL_EVENT_ID).
+ * @rmid:		RMID.
+ * @closid:		CLOSID.
+ * @cntr_id:		Counter ID to configure.
+ * @assign:		True to assign the counter or update an existing assignment,
+ *			false to unassign the counter.
+ *
+ * This can be called from any CPU.
+ */
+void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			      enum resctrl_event_id evtid, u32 rmid, u32 closid,
+			      u32 cntr_id, bool assign);
+
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v16 16/34
#29 lore raw

Re: [PATCH v16 16/34] x86,fs/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC

Hi Babu,

Quoted 12 lines · Babu Moger

The ABMC feature allows users to assign a hardware counter to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Implement an x86 architecture-specific handler to configure a counter. This architecture specific handler is called by resctrl fs when a counter is assigned or unassigned as well as when an already assigned counter's configuration should be updated. Configure counters by writing to the L3_QOS_ABMC_CFG MSR, specifying the counter ID, bandwidth source (RMID), and event configuration.

Quoted 8 lines

The feature details are documented in the APM listed below [1].
[1] AMD64 Architecture Programmer's Manual Volume 2: System Programming

    Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth
    Monitoring (ABMC).

---

Reinette

author reviewer
#30 lore raw

PATCH v16 17/34 fs/resctrl: Add the functionality to assign MBM events

In reply to Babu Moger

When supported, "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned.

Add the functionality to allocate and assign a counter to an RMID, event pair in the domain.

If all the counters are in use, kernel will log the error message "Failed to allocate counter for <event> in domain <id>" in /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested. Exit on the first failure when assigning counters across all the domains.

---
v16: Function renames:
resctrl_config_cntr() -> rdtgroup_assign_cntr() rdtgroup_alloc_config_cntr() -> rdtgroup_alloc_assign_cntr()
Passed struct mevt to rdtgroup_alloc_assign_cntr so it can print event name on failure. Minor code comment update.

v15: Updated the changelog.

     Added the check !r->mon.mbm_cntr_assignable in mbm_cntr_get() to return error.
     Removed the check to verify evt_cfg in the domain as it is not required anymore.
     https://lore.kernel.org/lkml/[email protected]/
     Return success if the counter is already assigned.
     Rename resctrl_assign_cntr_event() -> rdtgroup_assign_cntr_event().
     Removed the parameter struct rdt_resource. It can be obtained from mevt->rid.

v14: Updated the changelog little bit.
Updated the code documentation for mbm_cntr_alloc() and mbm_cntr_get(). Passed struct mon_evt to resctrl_assign_cntr_event() that way to avoid back and forth calls to get event details.
Updated the code documentation about the failure when counters are exhasted. Changed subject line to fs/resctrl.

v13: Updated changelog.
Changed resctrl_arch_config_cntr() to return void instead of int. Just passing evtid is to resctrl_alloc_config_cntr() and resctrl_assign_cntr_event(). Event configuration value can be easily obtained from mon_evt list.
Introduced new function mbm_get_mon_event() to get event configuration value. Added prototype descriptions to mbm_cntr_get() and mbm_cntr_alloc(). Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c/rdtgroup.c have been split between FS and ARCH directories.

v12: Fixed typo in the subjest line.
Replaced several counters with "num_mbm_cntrs" counters.
Changed the check in resctrl_alloc_config_cntr() to reduce the indentation. Fixed the handling error on first failure.
Added domain id and event id on failure.
Fixed the return error override.
Added new parameter event configuration (evt_cfg) to get the event configuration from user space.

v11: Patch changed again quite a bit.
Moved the functions to monitor.c.
Renamed rdtgroup_assign_cntr_event() to resctrl_assign_cntr_event(). Refactored the resctrl_assign_cntr_event().
Added functionality to exit on the first error during assignment. Simplified mbm_cntr_free().
Removed the function mbm_cntr_assigned(). Will be using mbm_cntr_get() to figure out if the counter is assigned or not.
Updated commit message and code comments.

v10: Patch changed completely.
Counters are managed at the domain based on the discussion.
https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5AFgD9cQDCUg@mail.gmail.com/
Reset non-architectural MBM state.
Commit message update.

v9: Introduced new function resctrl_config_cntr to assign the counter, update
the bitmap and reset the architectural state.
Taken care of error handling(freeing the counter) when assignment fails. Moved mbm_cntr_assigned_to_domain here as it used in this patch. Minor text changes.

v8: Renamed rdtgroup_assign_cntr() to rdtgroup_assign_cntr_event().
Added the code to return the error if rdtgroup_assign_cntr_event fails. Moved definition of MBM_EVENT_ARRAY_INDEX to resctrl/internal.h. Updated typo in the comments.

v7: New patch. Moved all the FS code here.
Merged rdtgroup_assign_cntr and rdtgroup_alloc_cntr. Adde new #define MBM_EVENT_ARRAY_INDEX.

---
 fs/resctrl/internal.h |   3 +
 fs/resctrl/monitor.c  | 130 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
fs/resctrl/internal.h +3 -0
index db3a0f12ad77..419423bdabdc 100644
@@ -387,6 +387,9 @@ bool closid_allocated(unsigned int closid);
 
 int resctrl_find_cleanest_closid(void);
 
+int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
+			       struct mon_evt *mevt);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +130 -0

133 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#31 lore raw

Re: [PATCH v16 17/34] fs/resctrl: Add the functionality to assign MBM events

Hi Babu,

Quoted 8 lines · Babu Moger

When supported, "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned.

Add the functionality to allocate and assign a counter to an RMID, event pair in the domain.

If all the counters are in use, kernel will log the error message

I think dropping "kernel will" will help the text to be imperative.

Quoted 2 lines

"Failed to allocate counter for <event> in domain <id>" in /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested.

"when a new assignment is requested" can be dropped. Or alternatively:
Log the error message "Failed to allocate counter for <event> in domain <id>" in /sys/fs/resctrl/info/last_cmd_status if all the counters are in use.

Quoted 4 lines

Exit on the first failure when assigning counters across all the domains.

---

...

Quoted 10 lines
---
 fs/resctrl/internal.h |   3 +
 fs/resctrl/monitor.c  | 130 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
fs/resctrl/internal.h +0 -0
index db3a0f12ad77..419423bdabdc 100644

fs/resctrl/internal.h bool closid_allocated(unsigned int closid); · line 392

Quoted 6 lines
fs/resctrl/internal.h +3 -0
@@ -387,6 +387,9 @@ bool closid_allocated(unsigned int closid);
 
 int resctrl_find_cleanest_closid(void);
 
+int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
+			       struct mon_evt *mevt);
+

This internal.h change does not look necessary? Looking ahead this is because rdtgroup.c:rdtgroup_assign_cntrs() needs it, but rdtgroup_assign_cntrs() also belongs in monitor.c, no?

Quoted 3 lines
fs/resctrl/internal.h +0 -0
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 

...

Quoted 9 lines
fs/resctrl/internal.h +9 -0
+/*
+ * rdtgroup_alloc_assign_cntr() - Allocate a counter ID and assign it to the event
+ * pointed to by @mevt and the resctrl group @rdtgrp within the domain @d.
+ *
+ * Return:
+ * 0 on success, < 0 on failure.
+ */
+static int rdtgroup_alloc_assign_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+				      struct rdtgroup *rdtgrp, struct mon_evt *mevt)

fs/resctrl/internal.h

Quoted 10 lines
fs/resctrl/internal.h +10 -0
+{
+	int cntr_id;
+
+	/* No action required if the counter is assigned already. */
+	cntr_id = mbm_cntr_get(r, d, rdtgrp, mevt->evtid);
+	if (cntr_id >= 0)
+		return 0;
+
+	cntr_id = mbm_cntr_alloc(r, d, rdtgrp, mevt->evtid);
+	if (cntr_id <  0) {

Extra space above.

fs/resctrl/internal.h

Quoted 10 lines
fs/resctrl/internal.h +10 -0
+		rdt_last_cmd_printf("Failed to allocate counter for %s in domain %d\n",
+				    mevt->name, d->hdr.id);
+		return cntr_id;
+	}
+
+	rdtgroup_assign_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, rdtgrp->closid, cntr_id, true);
+
+	return 0;
+}
+

Reinette

author reviewer
#32 lore raw

Re: [PATCH v16 17/34] fs/resctrl: Add the functionality to assign MBM events

Hi Reinette,

Quoted 14 lines · Reinette Chatre

Hi Babu,

Quoted 8 lines · Babu Moger

When supported, "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned.

Add the functionality to allocate and assign a counter to an RMID, event pair in the domain.

If all the counters are in use, kernel will log the error message

I think dropping "kernel will" will help the text to be imperative.

Quoted 8 lines
Quoted 2 lines

"Failed to allocate counter for <event> in domain <id>" in /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested.

"when a new assignment is requested" can be dropped. Or alternatively:
Log the error message "Failed to allocate counter for <event> in domain <id>" in /sys/fs/resctrl/info/last_cmd_status if all the counters are in use.

Sure. will do.

Quoted 20 lines
Quoted 4 lines

Exit on the first failure when assigning counters across all the domains.

---

...

Quoted 13 lines
---
 fs/resctrl/internal.h |   3 +
 fs/resctrl/monitor.c  | 130 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
fs/resctrl/internal.h +0 -0
index db3a0f12ad77..419423bdabdc 100644
@@ -387,6 +387,9 @@ bool closid_allocated(unsigned int closid);
 
 int resctrl_find_cleanest_closid(void);
 
Quoted 7 lines

fs/resctrl/internal.h bool closid_allocated(unsigned int closid); · line 392

Quoted 3 lines
fs/resctrl/internal.h +3 -0
+int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
+			       struct mon_evt *mevt);
+

This internal.h change does not look necessary? Looking ahead this is because rdtgroup.c:rdtgroup_assign_cntrs() needs it, but rdtgroup_assign_cntrs() also belongs in monitor.c, no?

Yes. Brought rdtgroup_assign_cntrs() in this patch for completeness and moved everything into monitor.c.

Quoted 20 lines
Quoted 4 lines
fs/resctrl/internal.h +0 -0
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 

...

Quoted 13 lines
fs/resctrl/internal.h +13 -0
+/*
+ * rdtgroup_alloc_assign_cntr() - Allocate a counter ID and assign it to the event
+ * pointed to by @mevt and the resctrl group @rdtgrp within the domain @d.
+ *
+ * Return:
+ * 0 on success, < 0 on failure.
+ */
+static int rdtgroup_alloc_assign_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+				      struct rdtgroup *rdtgrp, struct mon_evt *mevt)
+{
+	int cntr_id;
+
+	/* No action required if the counter is assigned already. */
Quoted 8 lines

fs/resctrl/internal.h

Quoted 6 lines
fs/resctrl/internal.h +6 -0
+	cntr_id = mbm_cntr_get(r, d, rdtgrp, mevt->evtid);
+	if (cntr_id >= 0)
+		return 0;
+
+	cntr_id = mbm_cntr_alloc(r, d, rdtgrp, mevt->evtid);
+	if (cntr_id <  0) {

Extra space above.

Sure.

Quoted 14 lines

fs/resctrl/internal.h

Quoted 11 lines
fs/resctrl/internal.h +10 -0
+		rdt_last_cmd_printf("Failed to allocate counter for %s in domain %d\n",
+				    mevt->name, d->hdr.id);
+		return cntr_id;
+	}
+
+	rdtgroup_assign_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, rdtgrp->closid, cntr_id, true);
+
+	return 0;
+}
+

Reinette

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#33 lore raw

PATCH v16 18/34 fs/resctrl: Add the functionality to unassign MBM events

In reply to Babu Moger

The "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned. If all the counters are in use, the kernel logs the error message "Unable to allocate counter in domain" in /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested.

To make space for a new assignment, users must unassign an already assigned counter and retry the assignment again.

Add the functionality to unassign and free the counters in the domain.

---
v16: Function rename rdtgroup_free_config_cntr() -> rdtgroup_free_unassign_cntr().
Updated rdtgroup_free_unassign_cntr() to pass struct mon_evt to match rdtgroup_alloc_assign_cntr() prototype.

v15: Updated the changelog.

     Changed code in mbm_cntr_free to use the sizeof(*d->cntr_cfg)).
     Removed unnecessary return in resctrl_free_config_cntr().
     Rename resctrl_unassign_cntr_event() -> rdtgroup_unassign_cntr_event().
     Removed the parameter struct rdt_resource. It can be obtained from mevt->rid.

v14: Passing the struct mon_evt to resctrl_free_config_cntr() and removed
the need for mbm_get_mon_event() call.
Corrected the code documentation for mbm_cntr_free(). Changed resctrl_free_config_cntr() and resctrl_unassign_cntr_event() to return void.
Changed subject line to fs/resctrl.
Updated the changelog.

v13: Moved mbm_cntr_free() to this patch as it is used in here first.
Not required to pass evt_cfg to resctrl_unassign_cntr_event(). It is available via mbm_get_mon_event().
Resolved conflicts caused by the recent FS/ARCH code restructure. The monitor.c file has now been split between the FS and ARCH directories.

v12: Updated the commit text to make bit more clear.
Replaced several counters with "num_mbm_cntrs" counters.
Fixed typo in the subjest line.
Fixed the handling error on first failure.
Added domain id and event id on failure.
Added new parameter event configuration (evt_cfg) to provide the event from user space.

v11: Moved the functions to monitor.c.
Renamed rdtgroup_unassign_cntr_event() to resctrl_unassign_cntr_event(). Refactored the resctrl_unassign_cntr_event().
Updated commit message and code comments.

v10: Patch changed again.
Counters are managed at the domain based on the discussion.
https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5AFgD9cQDCUg@mail.gmail.com/
commit message update.

v9: Changes related to addition of new function resctrl_config_cntr().
The removed rdtgroup_mbm_cntr_is_assigned() as it was introduced already.
Text changes to take care comments.

v8: Renamed rdtgroup_mbm_cntr_is_assigned to mbm_cntr_assigned_to_domain
Added return error handling in resctrl_arch_config_cntr().

v7: Merged rdtgroup_unassign_cntr and rdtgroup_free_cntr functions.
Renamed rdtgroup_mbm_cntr_test() to rdtgroup_mbm_cntr_is_assigned(). Reworded the commit log little bit.

v6: Removed mbm_cntr_free from this patch.
Added counter test in all the domains and free if it is not assigned to any domains.

v5: Few name changes to match cntr_id.
Changed the function names to rdtgroup_unassign_cntr More comments on commit log.

v4: Added domain specific unassign feature.
Few name changes.

v3: Removed the static from the prototype of rdtgroup_unassign_abmc.
The function is not called directly from user anymore. These changes are related to global assignment interface.

v2: No changes.

---
 fs/resctrl/internal.h |  2 ++
 fs/resctrl/monitor.c  | 46 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
fs/resctrl/internal.h +2 -0
index 419423bdabdc..216588842444 100644
@@ -389,6 +389,8 @@ int resctrl_find_cleanest_closid(void);
 
 int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 			       struct mon_evt *mevt);
+void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
+				  struct mon_evt *mevt);
 
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
fs/resctrl/monitor.c +46 -0

55 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#34 lore raw

Re: [PATCH v16 18/34] fs/resctrl: Add the functionality to unassign MBM events

Hi Babu,

Quoted 4 lines · Babu Moger

The "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned. If all the counters are in use, the kernel logs the error message "Unable to allocate counter in domain" in

Needs an update to match new message.

Quoted 9 lines

/sys/fs/resctrl/info/last_cmd_status when a new assignment is requested.

To make space for a new assignment, users must unassign an already assigned counter and retry the assignment again.

Add the functionality to unassign and free the counters in the domain.

---

...

Quoted 10 lines
---
 fs/resctrl/internal.h |  2 ++
 fs/resctrl/monitor.c  | 46 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
fs/resctrl/internal.h +0 -0
index 419423bdabdc..216588842444 100644

fs/resctrl/internal.h int resctrl_find_cleanest_closid(void); · line 394

Quoted 6 lines
fs/resctrl/internal.h +2 -0
@@ -389,6 +389,8 @@ int resctrl_find_cleanest_closid(void);
 
 int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 			       struct mon_evt *mevt);
+void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
+				  struct mon_evt *mevt);
 

Similar comment as previous patch. Please try to keep all monitoring code in monitor.c. The caller rdtgroup_unassign_cntrs() can move to monitor.c and it can instead be made available via internal.h

fs/resctrl/internal.h int resctrl_find_cleanest_closid(void); · line 396

Quoted 2 lines
fs/resctrl/internal.h +0 -0
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);

Reinette

author reviewer
#35 lore raw

Re: [PATCH v16 18/34] fs/resctrl: Add the functionality to unassign MBM events

Hi Reinette,

Quoted 9 lines · Reinette Chatre

Hi Babu,

Quoted 4 lines · Babu Moger

The "mbm_event" counter assignment mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned. If all the counters are in use, the kernel logs the error message "Unable to allocate counter in domain" in

Needs an update to match new message.

Sure.

Quoted 26 lines
Quoted 10 lines

/sys/fs/resctrl/info/last_cmd_status when a new assignment is requested.

To make space for a new assignment, users must unassign an already assigned counter and retry the assignment again.

Add the functionality to unassign and free the counters in the domain.

---

...

Quoted 11 lines
---
 fs/resctrl/internal.h |  2 ++
 fs/resctrl/monitor.c  | 46 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
fs/resctrl/internal.h +0 -0
index 419423bdabdc..216588842444 100644
@@ -389,6 +389,8 @@ int resctrl_find_cleanest_closid(void);
 
Quoted 9 lines

fs/resctrl/internal.h int resctrl_find_cleanest_closid(void); · line 394

Quoted 5 lines
fs/resctrl/internal.h +2 -0
 int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 			       struct mon_evt *mevt);
+void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
+				  struct mon_evt *mevt);
 

Similar comment as previous patch. Please try to keep all monitoring code in monitor.c. The caller rdtgroup_unassign_cntrs() can move to monitor.c and it can instead be made available via internal.h

Yes. Brought rdtgroup_unassign_cntrs() in this patch for completeness and moved everything into monitor.c.

Quoted 8 lines

fs/resctrl/internal.h int resctrl_find_cleanest_closid(void); · line 396

Quoted 4 lines
fs/resctrl/internal.h +0 -0
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);

Reinette

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#36 lore raw

PATCH v16 19/34 fs/resctrl: Pass struct rdtgroup instead of individual members

In reply to Babu Moger

Reading monitoring data for a monitoring group requires both the RMID and CLOSID. The RMID and CLOSID are members of struct rdtgroup but passed separately to several functions involved in retrieving event data.

When "mbm_event" counter assignment mode is enabled, a counter ID is required to read event data. The counter ID is obtained through mbm_cntr_get(), which expects a struct rdtgroup pointer.

Provide a pointer to the struct rdtgroup as parameter to functions involved in retrieving event data to simplify access to RMID, CLOSID, and counter ID.

---
v16: Minor code comment update.

v15: Rephrased the changelog. Thanks to Reinette.

v14: Few text update to commit log.

v13: New patch to pass the entire struct rdtgroup to __mon_event_count(),
mbm_update(), and related functions.

---
 fs/resctrl/monitor.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)
fs/resctrl/monitor.c +18 -15
index 049a82729c0b..070965d45770 100644
@@ -356,9 +356,11 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_domain *d, u32 closid,
 	return state ? &state[idx] : NULL;
 }
 
-static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
+static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 {
 	int cpu = smp_processor_id();
+	u32 closid = rdtgrp->closid;
+	u32 rmid = rdtgrp->mon.rmid;
 	struct rdt_mon_domain *d;
 	struct cacheinfo *ci;
 	struct mbm_state *m;
@@ -420,8 +422,8 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
 /*
  * mbm_bw_count() - Update bw count from values previously read by
  *		    __mon_event_count().
- * @closid:	The closid used to identify the cached mbm_state.
- * @rmid:	The rmid used to identify the cached mbm_state.
+ * @rdtgrp:	resctrl group associated with the CLOSID and RMID to identify
+ *		the cached mbm_state.
  * @rr:		The struct rmid_read populated by __mon_event_count().
  *
  * Supporting function to calculate the memory bandwidth
@@ -429,9 +431,11 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
  * __mon_event_count() is compared with the chunks value from the previous
  * invocation. This must be called once per second to maintain values in MBps.
  */
-static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)
+static void mbm_bw_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 {
 	u64 cur_bw, bytes, cur_bytes;
+	u32 closid = rdtgrp->closid;
+	u32 rmid = rdtgrp->mon.rmid;
 	struct mbm_state *m;
 
 	m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
@@ -460,7 +464,7 @@ void mon_event_count(void *info)
 
 	rdtgrp = rr->rgrp;
 
-	ret = __mon_event_count(rdtgrp->closid, rdtgrp->mon.rmid, rr);
+	ret = __mon_event_count(rdtgrp, rr);
 
 	/*
 	 * For Ctrl groups read data from child monitor groups and
@@ -471,8 +475,7 @@ void mon_event_count(void *info)
 
 	if (rdtgrp->type == RDTCTRL_GROUP) {
 		list_for_each_entry(entry, head, mon.crdtgrp_list) {
-			if (__mon_event_count(entry->closid, entry->mon.rmid,
-					      rr) == 0)
+			if (__mon_event_count(entry, rr) == 0)
 				ret = 0;
 		}
 	}
@@ -603,7 +606,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
 }
 
 static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *d,
-				 u32 closid, u32 rmid, enum resctrl_event_id evtid)
+				 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid)
 {
 	struct rmid_read rr = {0};
 
@@ -617,30 +620,30 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
 		return;
 	}
 
-	__mon_event_count(closid, rmid, &rr);
+	__mon_event_count(rdtgrp, &rr);
 
 	/*
 	 * If the software controller is enabled, compute the
 	 * bandwidth for this event id.
 	 */
 	if (is_mba_sc(NULL))
-		mbm_bw_count(closid, rmid, &rr);
+		mbm_bw_count(rdtgrp, &rr);
 
 	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,
-		       u32 closid, u32 rmid)
+		       struct rdtgroup *rdtgrp)
 {
 	/*
 	 * This is protected from concurrent reads from user as both
 	 * the user and overflow handler hold the global mutex.
 	 */
 	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);
+		mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_TOTAL_EVENT_ID);
 
 	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);
+		mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
 /*
@@ -713,11 +716,11 @@ void mbm_handle_overflow(struct work_struct *work)
 	d = container_of(work, struct rdt_mon_domain, mbm_over.work);
 
 	list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
-		mbm_update(r, d, prgrp->closid, prgrp->mon.rmid);
+		mbm_update(r, d, prgrp);
 
 		head = &prgrp->mon.crdtgrp_list;
 		list_for_each_entry(crgrp, head, mon.crdtgrp_list)
-			mbm_update(r, d, crgrp->closid, crgrp->mon.rmid);
+			mbm_update(r, d, crgrp);
 
 		if (is_mba_sc(NULL))
 			update_mba_bw(prgrp, d);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v16 19/34
#37 lore raw

Re: [PATCH v16 19/34] fs/resctrl: Pass struct rdtgroup instead of individual members

Hi Babu,

Quoted 8 lines · Babu Moger

Reading monitoring data for a monitoring group requires both the RMID and CLOSID. The RMID and CLOSID are members of struct rdtgroup but passed separately to several functions involved in retrieving event data.

When "mbm_event" counter assignment mode is enabled, a counter ID is required to read event data. The counter ID is obtained through mbm_cntr_get(), which expects a struct rdtgroup pointer.

Quoted 7 lines

Provide a pointer to the struct rdtgroup as parameter to functions involved in retrieving event data to simplify access to RMID, CLOSID, and counter ID.

---

Reinette

author reviewer
#38 lore raw

PATCH v16 20/34 fs/resctrl: Introduce counter ID read, reset calls in mbm_event mode

In reply to Babu Moger

When supported, "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Introduce the architecture calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() to read and reset event counters when "mbm_event" mode is supported. Function names are chosen to match existing resctrl_arch_rmid_read() and resctrl_arch_reset_rmid().

---
v16: Updated the changelog.
Removed lots of copied and unnecessary text from resctrl.h. Also removed references to LLC occupancy.
Removed arch_mon_ctx from resctrl_arch_cntr_read().

v15: New patch to add arch calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr()
with mbm_event mode.
https://lore.kernel.org/lkml/[email protected]/

---
 include/linux/resctrl.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
include/linux/resctrl.h +38 -0
index 50e38445183a..4d37827121a6 100644
@@ -613,6 +613,44 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
 			      enum resctrl_event_id evtid, u32 rmid, u32 closid,
 			      u32 cntr_id, bool assign);
 
+/**
+ * resctrl_arch_cntr_read() - Read the event data corresponding to the counter ID
+ *			      assigned to the RMID, event pair for this resource
+ *			      and domain.
+ * @r:			Resource that the counter should be read from.
+ * @d:			Domain that the counter should be read from.
+ * @closid:		CLOSID that matches the RMID.
+ * @rmid:		RMID used for counter ID assignment.
+ * @cntr_id:		The counter ID whose event data should be read. Valid when
+ *			"mbm_event" mode is enabled and @eventid is MBM event.
+ * @eventid:		eventid used for counter ID assignment, such as
+ *			QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID.
+ * @val:		Result of the counter read in bytes.
+ *
+ * Return:
+ * 0 on success, or -EIO, -EINVAL etc on error.
+ */
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+			   u32 closid, u32 rmid, int cntr_id,
+			   enum resctrl_event_id eventid, u64 *val);
+
+/**
+ * resctrl_arch_reset_cntr() - Reset any private state associated with counter ID.
+ * @r:		The domain's resource.
+ * @d:		The counter ID's domain.
+ * @closid:	CLOSID that matches the RMID.
+ * @rmid:	RMID used for counter ID assignment.
+ * @cntr_id:	The counter ID whose event data should be reset. Valid when
+ *		"mbm_event" mode is enabled and @eventid is MBM event.
+ * @eventid:	eventid used for counter ID assignment, such as
+ *		QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID.
+ *
+ * This can be called from any CPU.
+ */
+void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			     u32 closid, u32 rmid, int cntr_id,
+			     enum resctrl_event_id eventid);
+
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 
Signature · 1 line
2.34.1
maintainer
#39 lore raw

Re: [PATCH v16 20/34] fs/resctrl: Introduce counter ID read, reset calls in mbm_event mode

Hi Babu,

Quoted 8 lines · Babu Moger

When supported, "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Introduce the architecture calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() to read and reset event counters when "mbm_event" mode is supported. Function names are chosen to match existing

(apologies if I gave you the text ... trying to polish with more focus on imperative tone now)
"Function names are chosen to match" -> "Function names match"?

Quoted 5 lines

resctrl_arch_rmid_read() and resctrl_arch_reset_rmid().

---

...

Quoted 10 lines
---
 include/linux/resctrl.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
include/linux/resctrl.h +0 -0
index 50e38445183a..4d37827121a6 100644
@@ -613,6 +613,44 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
 			      enum resctrl_event_id evtid, u32 rmid, u32 closid,

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 623

Quoted 10 lines
include/linux/resctrl.h +8 -0
 			      u32 cntr_id, bool assign);
 
+/**
+ * resctrl_arch_cntr_read() - Read the event data corresponding to the counter ID
+ *			      assigned to the RMID, event pair for this resource
+ *			      and domain.
+ * @r:			Resource that the counter should be read from.
+ * @d:			Domain that the counter should be read from.
+ * @closid:		CLOSID that matches the RMID.
+ * @rmid:		RMID used for counter ID assignment.

Can this be more specific, for example:
The RMID to which @cntr_id is assigned.

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 625

Quoted 2 lines
include/linux/resctrl.h +2 -0
+ * @cntr_id:		The counter ID whose event data should be read. Valid when
+ *			"mbm_event" mode is enabled and @eventid is MBM event.

Would the counter ID not always be valid? Specifically, resctrl_arch_cntr_read() is _only_ called when "mbm_event" mode is enabled and @eventid is _always_ an MBM event, no? If you agree, the @cntr_id description can be something like below with the calling context details moved to general function description:

@cntr_id: The counter to read.

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 627

Quoted 2 lines
include/linux/resctrl.h +2 -0
+ * @eventid:		eventid used for counter ID assignment, such as
+ *			QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID.

The "@eventid is an MBM event" can move here? For example:
The MBM event to which @cntr_id is assigned.

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 629

Quoted 2 lines
include/linux/resctrl.h +2 -0
+ * @val:		Result of the counter read in bytes.
+ *

It looks to me as though some of the @cntr_id text could move to be the function description. The description can also be expanded to include where this will be called from. For example,

Called on a CPU that belongs to domain @d when "mbm_event" mode is enabled. Called from a non-migrateable process context via smp_call_on_cpu() unless all CPUs are nohz_full, in which case it is called via IPI (smp_call_function_any()).

The goal is to make information specific. Please feel free to improve.

Quoted 7 lines
include/linux/resctrl.h +7 -0
+ * Return:
+ * 0 on success, or -EIO, -EINVAL etc on error.
+ */
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+			   u32 closid, u32 rmid, int cntr_id,
+			   enum resctrl_event_id eventid, u64 *val);
+

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 646

Quoted 10 lines
include/linux/resctrl.h +10 -0
+/**
+ * resctrl_arch_reset_cntr() - Reset any private state associated with counter ID.
+ * @r:		The domain's resource.
+ * @d:		The counter ID's domain.
+ * @closid:	CLOSID that matches the RMID.
+ * @rmid:	RMID used for counter ID assignment.
+ * @cntr_id:	The counter ID whose event data should be reset. Valid when
+ *		"mbm_event" mode is enabled and @eventid is MBM event.
+ * @eventid:	eventid used for counter ID assignment, such as
+ *		QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID.

Above should similarly be specific.

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 656

Quoted 10 lines
include/linux/resctrl.h +7 -0
+ *
+ * This can be called from any CPU.
+ */
+void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			     u32 closid, u32 rmid, int cntr_id,
+			     enum resctrl_event_id eventid);
+
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 

Reinette

author reviewer
#40 lore raw

Re: [PATCH v16 20/34] fs/resctrl: Introduce counter ID read, reset calls in mbm_event mode

Hi Reinette,

Quoted 8 lines · Reinette Chatre

Hi Babu,

Quoted 5 lines · Babu Moger

When supported, "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user.

Quoted 7 lines
Quoted 3 lines

Introduce the architecture calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() to read and reset event counters when "mbm_event" mode is supported. Function names are chosen to match existing

(apologies if I gave you the text ... trying to polish with more focus on imperative tone now)
"Function names are chosen to match" -> "Function names match"?

Looks good.

Quoted 21 lines
Quoted 6 lines

resctrl_arch_rmid_read() and resctrl_arch_reset_rmid().

---

...

Quoted 12 lines
---
 include/linux/resctrl.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
include/linux/resctrl.h +0 -0
index 50e38445183a..4d37827121a6 100644
@@ -613,6 +613,44 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
 			      enum resctrl_event_id evtid, u32 rmid, u32 closid,
 			      u32 cntr_id, bool assign);
 
Quoted 11 lines

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 623

Quoted 8 lines
include/linux/resctrl.h +8 -0
+/**
+ * resctrl_arch_cntr_read() - Read the event data corresponding to the counter ID
+ *			      assigned to the RMID, event pair for this resource
+ *			      and domain.
+ * @r:			Resource that the counter should be read from.
+ * @d:			Domain that the counter should be read from.
+ * @closid:		CLOSID that matches the RMID.
+ * @rmid:		RMID used for counter ID assignment.

Can this be more specific, for example:
The RMID to which @cntr_id is assigned.

Sure.

Quoted 10 lines

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 625

Quoted 3 lines
include/linux/resctrl.h +2 -0
+ * @cntr_id:		The counter ID whose event data should be read. Valid when
+ *			"mbm_event" mode is enabled and @eventid is MBM event.

Would the counter ID not always be valid? Specifically, resctrl_arch_cntr_read() is _only_ called when "mbm_event" mode is enabled and @eventid is _always_ an MBM event, no? If you agree, the @cntr_id description can be something like below with the calling context details moved to general function description:

@cntr_id: The counter to read.

Yes. that is fine.

Quoted 6 lines

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 627

Quoted 3 lines
include/linux/resctrl.h +2 -0
+ * @eventid:		eventid used for counter ID assignment, such as
+ *			QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID.

The "@eventid is an MBM event" can move here? For example:
The MBM event to which @cntr_id is assigned.

Sure.

Quoted 8 lines

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 629

Quoted 3 lines
include/linux/resctrl.h +2 -0
+ * @val:		Result of the counter read in bytes.
+ *

It looks to me as though some of the @cntr_id text could move to be the function description. The description can also be expanded to include where this will be called from. For example,

Quoted 5 lines

Called on a CPU that belongs to domain @d when "mbm_event" mode is enabled. Called from a non-migrateable process context via smp_call_on_cpu() unless all CPUs are nohz_full, in which case it is called via IPI (smp_call_function_any()).

The goal is to make information specific. Please feel free to improve.

Looks good.

Quoted 12 lines
Quoted 12 lines
include/linux/resctrl.h +11 -0
+ * Return:
+ * 0 on success, or -EIO, -EINVAL etc on error.
+ */
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+			   u32 closid, u32 rmid, int cntr_id,
+			   enum resctrl_event_id eventid, u64 *val);
+
+/**
+ * resctrl_arch_reset_cntr() - Reset any private state associated with counter ID.
+ * @r:		The domain's resource.
+ * @d:		The counter ID's domain.
Quoted 9 lines

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 646

Quoted 6 lines
include/linux/resctrl.h +6 -0
+ * @closid:	CLOSID that matches the RMID.
+ * @rmid:	RMID used for counter ID assignment.
+ * @cntr_id:	The counter ID whose event data should be reset. Valid when
+ *		"mbm_event" mode is enabled and @eventid is MBM event.
+ * @eventid:	eventid used for counter ID assignment, such as
+ *		QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID.

Above should similarly be specific.

Sure.

Quoted 13 lines

include/linux/resctrl.h void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 656

Quoted 10 lines
include/linux/resctrl.h +7 -0
+ *
+ * This can be called from any CPU.
+ */
+void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			     u32 closid, u32 rmid, int cntr_id,
+			     enum resctrl_event_id eventid);
+
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 

Reinette

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#41 lore raw

PATCH v16 21/34 x86/resctrl: Refactor resctrl_arch_rmid_read()

In reply to Babu Moger

resctrl_arch_rmid_read() adjusts the value obtained from MSR_IA32_QM_CTR to account for the overflow for MBM events and apply counter scaling for all the events. This logic is common to both reading an RMID and reading a hardware counter directly.

Refactor the hardware value adjustment logic into get_corrected_val() to prepare for support of reading a hardware counter.

---
v16: Rephrased the changelog.

     Fixed allignment.
     Renamed mbm_corrected_val() -> get_corrected_val().

v15: New patch to add arch calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr()
with mbm_event mode.
https://lore.kernel.org/lkml/[email protected]/

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 38 ++++++++++++++++-----------
 1 file changed, 23 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +23 -15
index ed295a6c5e66..1f77fd58e707 100644
@@ -217,24 +217,13 @@ 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,
-			   u32 unused, u32 rmid, enum resctrl_event_id eventid,
-			   u64 *val, void *ignored)
+static u64 get_corrected_val(struct rdt_resource *r, struct rdt_mon_domain *d,
+			     u32 rmid, enum resctrl_event_id eventid, u64 msr_val)
 {
 	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);
 	struct arch_mbm_state *am;
-	u64 msr_val, chunks;
-	u32 prmid;
-	int ret;
-
-	resctrl_arch_rmid_read_context_check();
-
-	prmid = logical_rmid_to_physical_rmid(cpu, rmid);
-	ret = __rmid_read_phys(prmid, eventid, &msr_val);
-	if (ret)
-		return ret;
+	u64 chunks;
 
 	am = get_arch_mbm_state(hw_dom, rmid, eventid);
 	if (am) {
@@ -246,7 +235,26 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
 		chunks = msr_val;
 	}
 
-	*val = chunks * hw_res->mon_scale;
+	return chunks * hw_res->mon_scale;
+}
+
+int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+			   u32 unused, u32 rmid, enum resctrl_event_id eventid,
+			   u64 *val, void *ignored)
+{
+	int cpu = cpumask_any(&d->hdr.cpu_mask);
+	u64 msr_val;
+	u32 prmid;
+	int ret;
+
+	resctrl_arch_rmid_read_context_check();
+
+	prmid = logical_rmid_to_physical_rmid(cpu, rmid);
+	ret = __rmid_read_phys(prmid, eventid, &msr_val);
+	if (ret)
+		return ret;
+
+	*val = get_corrected_val(r, d, rmid, eventid, msr_val);
 
 	return 0;
 }
Signature · 1 line
2.34.1
maintainer Reviewed-by on v16 21/34
#42 lore raw

Re: [PATCH v16 21/34] x86/resctrl: Refactor resctrl_arch_rmid_read()

Hi Babu,

Quoted 10 lines · Babu Moger

resctrl_arch_rmid_read() adjusts the value obtained from MSR_IA32_QM_CTR to account for the overflow for MBM events and apply counter scaling for all the events. This logic is common to both reading an RMID and reading a hardware counter directly.

Refactor the hardware value adjustment logic into get_corrected_val() to prepare for support of reading a hardware counter.

---

Reinette

author reviewer
#43 lore raw

PATCH v16 22/34 x86/resctrl: Implement resctrl_arch_reset_cntr() and resctrl_arch_cntr_read()

In reply to Babu Moger

System software can read resctrl event data for a particular resource by writing the RMID and Event Identifier (EvtID) to the QM_EVTSEL register and then reading the event data from the QM_CTR register.

In ABMC mode, the event data of a specific counter ID can be read by setting the following fields: QM_EVTSEL.ExtendedEvtID = 1, QM_EVTSEL.EvtID = L3CacheABMC (=1) and setting [RMID] to the desired counter ID. Reading QM_CTR will then return the contents of the specified counter ID. The RMID_VAL_ERROR bit will be set if the counter configuration was invalid, or if an invalid counter ID was set in the QM_EVTSEL[RMID] field. If the counter data is currently unavailable, the RMID_VAL_UNAVAIL bit will be set.

Introduce resctrl_arch_reset_cntr() and resctrl_arch_cntr_read() to reset and read event data for a specific counter.

---
v16: Updated the changelog.
Removed the call resctrl_arch_rmid_read_context_check(); Added the text about RMID_VAL_UNAVAIL error.

v15: Updated patch to add arch calls resctrl_arch_cntr_read() and resctrl_arch_reset_cntr()
with mbm_event mode.
https://lore.kernel.org/lkml/[email protected]/

v14: Updated the context in changelog. Added text in imperative tone.
Added WARN_ON_ONCE() when cntr_id < 0.
Improved code documentation in include/linux/resctrl.h.
Added the check in mbm_update() to skip overflow handler when counter is unassigned.

v13: Split the patch into 2. First one to handle the passing of rdtgroup structure to few
functions( __mon_event_count and mbm_update(). Second one to handle ABMC counter reading. Added new function __cntr_id_read_phys() to handle ABMC event reading. Updated kernel doc for resctrl_arch_reset_rmid() and resctrl_arch_rmid_read(). Resolved conflicts caused by the recent FS/ARCH code restructure.
The monitor.c file has now been split between the FS and ARCH directories.

v12: New patch to support extended event mode when ABMC is enabled.

---
 arch/x86/kernel/cpu/resctrl/internal.h |  6 +++
 arch/x86/kernel/cpu/resctrl/monitor.c  | 68 ++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +6 -0
index 6bf6042f11b6..ae4003d44df4 100644
@@ -40,6 +40,12 @@ struct arch_mbm_state {
 /* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */
 #define ABMC_ENABLE_BIT			0
 
+/*
+ * Qos Event Identifiers.
+ */
+#define ABMC_EXTENDED_EVT_ID		BIT(31)
+#define ABMC_EVT_ID			BIT(0)
+
 /**
  * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs that share
  *			       a resource for a control function
arch/x86/kernel/cpu/resctrl/monitor.c +68 -0

74 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#44 lore raw

Re: [PATCH v16 22/34] x86/resctrl: Implement resctrl_arch_reset_cntr() and resctrl_arch_cntr_read()

Hi Babu,

Quoted 1 line · Babu Moger

System software can read resctrl event data for a particular resource by

"can read" -> "reads"

Quoted 4 lines

writing the RMID and Event Identifier (EvtID) to the QM_EVTSEL register and then reading the event data from the QM_CTR register.

In ABMC mode, the event data of a specific counter ID can be read by

"can be read" -> "is read"

Quoted 2 lines

setting the following fields: QM_EVTSEL.ExtendedEvtID = 1, QM_EVTSEL.EvtID = L3CacheABMC (=1) and setting [RMID] to the desired counter ID. Reading

"[RMID]" -> "QM_EVTSEL.RMID"

Quoted 1 line

QM_CTR will then return the contents of the specified counter ID. The

"will then return" -> "then returns"

Quoted 1 line

RMID_VAL_ERROR bit will be set if the counter configuration was invalid, or

"will be set" -> "is set"
"was invalid" -> "is invalid"

Quoted 1 line

if an invalid counter ID was set in the QM_EVTSEL[RMID] field. If the

"was set" -> "is set"

"in the QM_EVTSEL[RMID] field" -> "in QM_EVTSEL.RMID"

Quoted 2 lines

counter data is currently unavailable, the RMID_VAL_UNAVAIL bit will be set.

"The RMID_VAL_UNAVAIL bit is set if the counter data is unavailable."

Please review after changes that all is coherent and in imperative tone and make same adjustments to duplicate text in patch.

Quoted 6 lines

Introduce resctrl_arch_reset_cntr() and resctrl_arch_cntr_read() to reset and read event data for a specific counter.

---

...

Quoted 37 lines
---
 arch/x86/kernel/cpu/resctrl/internal.h |  6 +++
 arch/x86/kernel/cpu/resctrl/monitor.c  | 68 ++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +6 -0
index 6bf6042f11b6..ae4003d44df4 100644
@@ -40,6 +40,12 @@ struct arch_mbm_state {
 /* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */
 #define ABMC_ENABLE_BIT			0
 
+/*
+ * Qos Event Identifiers.
+ */
+#define ABMC_EXTENDED_EVT_ID		BIT(31)
+#define ABMC_EVT_ID			BIT(0)
+
 /**
  * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs that share
  *			       a resource for a control function
arch/x86/kernel/cpu/resctrl/monitor.c +7 -0
index 1f77fd58e707..57c8409a8247 100644
@@ -259,6 +259,74 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
 	return 0;
 }
 
+static int __cntr_id_read(u32 cntr_id, u64 *val)
+{
+	u64 msr_val;
+
+	/*
+	 * QM_EVTSEL Register definition:
+	 * =======================================================

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, · line 278

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10 -0
+	 * Bits    Mnemonic        Description
+	 * =======================================================
+	 * 63:44   --              Reserved
+	 * 43:32   RMID            Resource Monitoring Identifier
+	 * 31      ExtEvtID        Extended Event Identifier
+	 * 30:8    --              Reserved
+	 * 7:0     EvtID           Event Identifier
+	 * =======================================================
+	 * The contents of a specific counter can be read by setting the
+	 * following fields in QM_EVTSEL.ExtendedEvtID(=1) and

ExtEvtID vs ExtendedEvtID ... either the definition or the text should change to use same names.
Can description of RMID be expanded to note that it may
contain RMID or counter ID?

Quoted 44 lines
arch/x86/kernel/cpu/resctrl/monitor.c +44 -0
+	 * QM_EVTSEL.EvtID = L3CacheABMC (=1) and setting [RMID] to the
+	 * desired counter ID. Reading QM_CTR will then return the
+	 * contents of the specified counter. The RMID_VAL_ERROR bit will
+	 * be set if the counter configuration was invalid, or if an invalid
+	 * counter ID was set in the QM_EVTSEL[RMID] field. If the counter
+	 * data is currently unavailable, the RMID_VAL_UNAVAIL bit will be set.
+	 */
+	wrmsr(MSR_IA32_QM_EVTSEL, ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID, cntr_id);
+	rdmsrl(MSR_IA32_QM_CTR, msr_val);
+
+	if (msr_val & RMID_VAL_ERROR)
+		return -EIO;
+	if (msr_val & RMID_VAL_UNAVAIL)
+		return -EINVAL;
+
+	*val = msr_val;
+	return 0;
+}
+
+void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			     u32 unused, u32 rmid, int cntr_id,
+			     enum resctrl_event_id eventid)
+{
+	struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
+	struct arch_mbm_state *am;
+
+	am = get_arch_mbm_state(hw_dom, rmid, eventid);
+	if (am) {
+		memset(am, 0, sizeof(*am));
+
+		/* Record any initial, non-zero count value. */
+		__cntr_id_read(cntr_id, &am->prev_msr);
+	}
+}
+
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+			   u32 unused, u32 rmid, int cntr_id,
+			   enum resctrl_event_id eventid, u64 *val)
+{
+	u64 msr_val;
+	int ret;
+
+	ret = __cntr_id_read(cntr_id, &msr_val);
+	if (ret)

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, · line 332

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7 -0
+		return ret;
+
+	*val = get_corrected_val(r, d, rmid, eventid, msr_val);
+
+	return 0;
+}
+
 /*
  * The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1
  * which indicates that RMIDs are configured in legacy mode.

code looks good.

Reinette

author reviewer
#45 lore raw

Re: [PATCH v16 22/34] x86/resctrl: Implement resctrl_arch_reset_cntr() and resctrl_arch_cntr_read()

Hi Reinette,

Quoted 7 lines · Reinette Chatre

Hi Babu,

Quoted 1 line · Babu Moger

System software can read resctrl event data for a particular resource by

"can read" -> "reads"

Sure.

Quoted 7 lines
Quoted 4 lines

writing the RMID and Event Identifier (EvtID) to the QM_EVTSEL register and then reading the event data from the QM_CTR register.

In ABMC mode, the event data of a specific counter ID can be read by

"can be read" -> "is read"

Sure.

Quoted 5 lines
Quoted 2 lines

setting the following fields: QM_EVTSEL.ExtendedEvtID = 1, QM_EVTSEL.EvtID = L3CacheABMC (=1) and setting [RMID] to the desired counter ID. Reading

"[RMID]" -> "QM_EVTSEL.RMID"

Sure.

Quoted 4 lines
Quoted 1 line

QM_CTR will then return the contents of the specified counter ID. The

"will then return" -> "then returns"

sure.

Quoted 5 lines
Quoted 1 line

RMID_VAL_ERROR bit will be set if the counter configuration was invalid, or

"will be set" -> "is set"
"was invalid" -> "is invalid"

Sure.

Quoted 3 lines
Quoted 1 line

if an invalid counter ID was set in the QM_EVTSEL[RMID] field. If the

"was set" -> "is set"

Sure.

Quoted 4 lines

"in the QM_EVTSEL[RMID] field" -> "in QM_EVTSEL.RMID"

Sure.

Quoted 7 lines
Quoted 2 lines

counter data is currently unavailable, the RMID_VAL_UNAVAIL bit will be set.

"The RMID_VAL_UNAVAIL bit is set if the counter data is unavailable."

Please review after changes that all is coherent and in imperative tone and make same adjustments to duplicate text in patch.

ok.

Quoted 52 lines
Quoted 7 lines

Introduce resctrl_arch_reset_cntr() and resctrl_arch_cntr_read() to reset and read event data for a specific counter.

---

...

Quoted 42 lines
---
 arch/x86/kernel/cpu/resctrl/internal.h |  6 +++
 arch/x86/kernel/cpu/resctrl/monitor.c  | 68 ++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +6 -0
index 6bf6042f11b6..ae4003d44df4 100644
@@ -40,6 +40,12 @@ struct arch_mbm_state {
 /* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */
 #define ABMC_ENABLE_BIT			0
 
+/*
+ * Qos Event Identifiers.
+ */
+#define ABMC_EXTENDED_EVT_ID		BIT(31)
+#define ABMC_EVT_ID			BIT(0)
+
 /**
  * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs that share
  *			       a resource for a control function
arch/x86/kernel/cpu/resctrl/monitor.c +12 -0
index 1f77fd58e707..57c8409a8247 100644
@@ -259,6 +259,74 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
 	return 0;
 }
 
+static int __cntr_id_read(u32 cntr_id, u64 *val)
+{
+	u64 msr_val;
+
+	/*
+	 * QM_EVTSEL Register definition:
+	 * =======================================================
+	 * Bits    Mnemonic        Description
+	 * =======================================================
+	 * 63:44   --              Reserved
+	 * 43:32   RMID            Resource Monitoring Identifier
+	 * 31      ExtEvtID        Extended Event Identifier
Quoted 8 lines

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, · line 278

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +5 -0
+	 * 30:8    --              Reserved
+	 * 7:0     EvtID           Event Identifier
+	 * =======================================================
+	 * The contents of a specific counter can be read by setting the
+	 * following fields in QM_EVTSEL.ExtendedEvtID(=1) and

ExtEvtID vs ExtendedEvtID ... either the definition or the text should change to use same names.

ExtendedEvtID

Quoted 2 lines

Can description of RMID be expanded to note that it may contain RMID or counter ID?

Sure.

Quoted 60 lines
Quoted 45 lines
arch/x86/kernel/cpu/resctrl/monitor.c +44 -0
+	 * QM_EVTSEL.EvtID = L3CacheABMC (=1) and setting [RMID] to the
+	 * desired counter ID. Reading QM_CTR will then return the
+	 * contents of the specified counter. The RMID_VAL_ERROR bit will
+	 * be set if the counter configuration was invalid, or if an invalid
+	 * counter ID was set in the QM_EVTSEL[RMID] field. If the counter
+	 * data is currently unavailable, the RMID_VAL_UNAVAIL bit will be set.
+	 */
+	wrmsr(MSR_IA32_QM_EVTSEL, ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID, cntr_id);
+	rdmsrl(MSR_IA32_QM_CTR, msr_val);
+
+	if (msr_val & RMID_VAL_ERROR)
+		return -EIO;
+	if (msr_val & RMID_VAL_UNAVAIL)
+		return -EINVAL;
+
+	*val = msr_val;
+	return 0;
+}
+
+void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
+			     u32 unused, u32 rmid, int cntr_id,
+			     enum resctrl_event_id eventid)
+{
+	struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
+	struct arch_mbm_state *am;
+
+	am = get_arch_mbm_state(hw_dom, rmid, eventid);
+	if (am) {
+		memset(am, 0, sizeof(*am));
+
+		/* Record any initial, non-zero count value. */
+		__cntr_id_read(cntr_id, &am->prev_msr);
+	}
+}
+
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+			   u32 unused, u32 rmid, int cntr_id,
+			   enum resctrl_event_id eventid, u64 *val)
+{
+	u64 msr_val;
+	int ret;
+
+	ret = __cntr_id_read(cntr_id, &msr_val);
+	if (ret)

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, · line 332

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7 -0
+		return ret;
+
+	*val = get_corrected_val(r, d, rmid, eventid, msr_val);
+
+	return 0;
+}
+
 /*
  * The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1
  * which indicates that RMIDs are configured in legacy mode.

code looks good.

Reinette

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#46 lore raw

PATCH v16 23/34 fs/resctrl: Support counter read/reset with mbm_event assignment mode

In reply to Babu Moger

When "mbm_event" counter assignment mode is enabled, the architecture requires a counter ID to read the event data.

Introduce an is_mbm_cntr field in struct rmid_read to indicate whether counter assignment mode is in use.

Update the logic to call resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() when the assignment mode is active. Report 'Unassigned' in case the user attempts to read the event without assigning a hardware counter.

Declare mbm_cntr_get() in fs/resctrl/internal.h to make it accessible to other functions within fs/resctrl.

---
v16: Squashed two patches here.
https://lore.kernel.org/lkml/df215f02db88cad714755cd5275f20cf0ee4ae26.1752013061.git.babu.moger@amd.com/
https://lore.kernel.org/lkml/296c435e9bf63fc5031114cced00fbb4837ad327.1752013061.git.babu.moger@amd.com/
Changed is_cntr field in struct rmid_read to is_mbm_cntr.
Fixed the memory leak with arch_mon_ctx.
Updated the resctrl.rst user doc.
Updated the changelog.
Report Unassigned only if none of the events in CTRL_MON and MON are assigned.

v15: New patch to add is_cntr in rmid_read as discussed in

     https://lore.kernel.org/lkml/[email protected]/
---
 Documentation/filesystems/resctrl.rst |  6 ++++
 fs/resctrl/ctrlmondata.c              | 22 +++++++++---
 fs/resctrl/internal.h                 |  5 +++
 fs/resctrl/monitor.c                  | 52 ++++++++++++++++++++-------
 4 files changed, 67 insertions(+), 18 deletions(-)
Documentation/filesystems/resctrl.rst +6 -0
index 446736dbd97f..4c24c5f3f4c1 100644
@@ -434,6 +434,12 @@ When monitoring is enabled all MON groups will also contain:
 	for the L3 cache they occupy). These are named "mon_sub_L3_YY"
 	where "YY" is the node number.
 
+	When the 'mbm_event' counter assignment mode is enabled, reading
+	an MBM event of a MON group returns 'Unassigned' if no hardware
+	counter is assigned to it. For CTRL_MON groups, 'Unassigned' is
+	returned if the MBM event does not have an assigned counter in the
+	CTRL_MON group nor in any of its associated MON groups.
+
 "mon_hw_id":
 	Available only with debug option. The identifier used by hardware
 	for the monitor group. On x86 this is the RMID.
fs/resctrl/ctrlmondata.c +17 -5
index ad7ffc6acf13..31787ce6ec91 100644
@@ -563,10 +563,15 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 	rr->r = r;
 	rr->d = d;
 	rr->first = first;
-	rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
-	if (IS_ERR(rr->arch_mon_ctx)) {
-		rr->err = -EINVAL;
-		return;
+	if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
+	    resctrl_is_mbm_event(evtid)) {
+		rr->is_mbm_cntr = true;
+	} else {
+		rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
+		if (IS_ERR(rr->arch_mon_ctx)) {
+			rr->err = -EINVAL;
+			return;
+		}
 	}
 
 	cpu = cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU);
@@ -582,7 +587,8 @@ 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);
+	if (rr->arch_mon_ctx)
+		resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
 }
 
 int rdtgroup_mondata_show(struct seq_file *m, void *arg)
@@ -653,10 +659,16 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 
 checkresult:
 
+	/*
+	 * -ENOENT is a special case, set only when "mbm_event" counter assignment
+	 * mode is enabled and no counter has been assigned.
+	 */
 	if (rr.err == -EIO)
 		seq_puts(m, "Error\n");
 	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
+	else if (rr.err == -ENOENT)
+		seq_puts(m, "Unassigned\n");
 	else
 		seq_printf(m, "%llu\n", rr.val);
 
fs/resctrl/internal.h +5 -0
index 216588842444..eeee83a5067a 100644
@@ -110,6 +110,8 @@ struct mon_data {
  *	   domains in @r sharing L3 @ci.id
  * @evtid: Which monitor event to read.
  * @first: Initialize MBM counter when true.
+ * @is_mbm_cntr: Is the counter valid? true if "mbm_event" counter assignment mode is
+ *	   enabled and it is an MBM event.
  * @ci_id: Cacheinfo id for L3. Only set when @d 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,
@@ -124,6 +126,7 @@ struct rmid_read {
 	struct rdt_mon_domain	*d;
 	enum resctrl_event_id	evtid;
 	bool			first;
+	bool			is_mbm_cntr;
 	unsigned int		ci_id;
 	int			err;
 	u64			val;
@@ -391,6 +394,8 @@ int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp
 			       struct mon_evt *mevt);
 void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 				  struct mon_evt *mevt);
+int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
+		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
 
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
fs/resctrl/monitor.c +39 -13

94 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#47 lore raw

Re: [PATCH v16 23/34] fs/resctrl: Support counter read/reset with mbm_event assignment mode

Hi Babu,

Quoted 6 lines · Babu Moger

When "mbm_event" counter assignment mode is enabled, the architecture requires a counter ID to read the event data.

Introduce an is_mbm_cntr field in struct rmid_read to indicate whether counter assignment mode is in use.

Quoted 7 lines

Update the logic to call resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() when the assignment mode is active. Report 'Unassigned' in case the user attempts to read the event without assigning a hardware counter.

Declare mbm_cntr_get() in fs/resctrl/internal.h to make it accessible to other functions within fs/resctrl.

From what I can tell this is not needed by this patch. It is also a hint that there may be some monitoring specific code outside of monitor.c. Looks like this is done to support later patch #29 "fs/resctrl: Introduce mbm_L3_assignments to list assignments in a group" where mbm_L3_assignments_show() should rather be in monitor.c

Quoted 4 lines

---

...

Quoted 80 lines
---
 Documentation/filesystems/resctrl.rst |  6 ++++
 fs/resctrl/ctrlmondata.c              | 22 +++++++++---
 fs/resctrl/internal.h                 |  5 +++
 fs/resctrl/monitor.c                  | 52 ++++++++++++++++++++-------
 4 files changed, 67 insertions(+), 18 deletions(-)
Documentation/filesystems/resctrl.rst +6 -0
index 446736dbd97f..4c24c5f3f4c1 100644
@@ -434,6 +434,12 @@ When monitoring is enabled all MON groups will also contain:
 	for the L3 cache they occupy). These are named "mon_sub_L3_YY"
 	where "YY" is the node number.
 
+	When the 'mbm_event' counter assignment mode is enabled, reading
+	an MBM event of a MON group returns 'Unassigned' if no hardware
+	counter is assigned to it. For CTRL_MON groups, 'Unassigned' is
+	returned if the MBM event does not have an assigned counter in the
+	CTRL_MON group nor in any of its associated MON groups.
+
 "mon_hw_id":
 	Available only with debug option. The identifier used by hardware
 	for the monitor group. On x86 this is the RMID.
fs/resctrl/ctrlmondata.c +17 -5
index ad7ffc6acf13..31787ce6ec91 100644
@@ -563,10 +563,15 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 	rr->r = r;
 	rr->d = d;
 	rr->first = first;
-	rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
-	if (IS_ERR(rr->arch_mon_ctx)) {
-		rr->err = -EINVAL;
-		return;
+	if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
+	    resctrl_is_mbm_event(evtid)) {
+		rr->is_mbm_cntr = true;
+	} else {
+		rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
+		if (IS_ERR(rr->arch_mon_ctx)) {
+			rr->err = -EINVAL;
+			return;
+		}
 	}
 
 	cpu = cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU);
@@ -582,7 +587,8 @@ 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);
+	if (rr->arch_mon_ctx)
+		resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
 }
 
 int rdtgroup_mondata_show(struct seq_file *m, void *arg)
@@ -653,10 +659,16 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 
 checkresult:
 
+	/*
+	 * -ENOENT is a special case, set only when "mbm_event" counter assignment
+	 * mode is enabled and no counter has been assigned.
+	 */
 	if (rr.err == -EIO)
 		seq_puts(m, "Error\n");
 	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
+	else if (rr.err == -ENOENT)
+		seq_puts(m, "Unassigned\n");
 	else
 		seq_printf(m, "%llu\n", rr.val);
 
fs/resctrl/internal.h +0 -0
index 216588842444..eeee83a5067a 100644

fs/resctrl/internal.h struct mon_data { · line 114

Quoted 5 lines
fs/resctrl/internal.h +2 -0
@@ -110,6 +110,8 @@ struct mon_data {
  *	   domains in @r sharing L3 @ci.id
  * @evtid: Which monitor event to read.
  * @first: Initialize MBM counter when true.
+ * @is_mbm_cntr: Is the counter valid? true if "mbm_event" counter assignment mode is
+ *	   enabled and it is an MBM event.

Since a counter may not be assigned to event being read I do not believe that "Is the counter valid?" is accurate and should rather be dropped. Rest of text looks accurate to me.

Quoted 12 lines
fs/resctrl/internal.h +1 -0
  * @ci_id: Cacheinfo id for L3. Only set when @d 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,
@@ -124,6 +126,7 @@ struct rmid_read {
 	struct rdt_mon_domain	*d;
 	enum resctrl_event_id	evtid;
 	bool			first;
+	bool			is_mbm_cntr;
 	unsigned int		ci_id;
 	int			err;
 	u64			val;

fs/resctrl/internal.h int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp · line 399

Quoted 6 lines
fs/resctrl/internal.h +2 -0
@@ -391,6 +394,8 @@ int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp
 			       struct mon_evt *mevt);
 void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 				  struct mon_evt *mevt);
+int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
+		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
 

Not necessary? mbm_cntr_get() can remain internal to monitor.c

Quoted 64 lines
fs/resctrl/internal.h +0 -0
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
fs/resctrl/monitor.c +25 -5
index 070965d45770..a8b53b0ad0b7 100644
@@ -362,13 +362,25 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 	u32 closid = rdtgrp->closid;
 	u32 rmid = rdtgrp->mon.rmid;
 	struct rdt_mon_domain *d;
+	int cntr_id = -ENOENT;
 	struct cacheinfo *ci;
 	struct mbm_state *m;
 	int err, ret;
 	u64 tval = 0;
 
+	if (rr->is_mbm_cntr) {
+		cntr_id = mbm_cntr_get(rr->r, rr->d, rdtgrp, rr->evtid);
+		if (cntr_id < 0) {
+			rr->err = -ENOENT;
+			return -EINVAL;
+		}
+	}
+
 	if (rr->first) {
-		resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
+		if (rr->is_mbm_cntr)
+			resctrl_arch_reset_cntr(rr->r, rr->d, closid, rmid, cntr_id, rr->evtid);
+		else
+			resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
 		m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
 		if (m)
 			memset(m, 0, sizeof(struct mbm_state));
@@ -379,8 +391,12 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 		/* Reading a single domain, must be on a CPU in that domain. */
 		if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask))
 			return -EINVAL;
-		rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid,
-						 rr->evtid, &tval, rr->arch_mon_ctx);
+		if (rr->is_mbm_cntr)
+			rr->err = resctrl_arch_cntr_read(rr->r, rr->d, closid, rmid, cntr_id,
+							 rr->evtid, &tval);
+		else
+			rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid,
+							 rr->evtid, &tval, rr->arch_mon_ctx);
 		if (rr->err)
 			return rr->err;
 
@@ -405,8 +421,12 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, 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,
-					     rr->evtid, &tval, rr->arch_mon_ctx);
+		if (rr->is_mbm_cntr)
+			err = resctrl_arch_cntr_read(rr->r, d, closid, rmid, cntr_id,
+						     rr->evtid, &tval);
+		else
+			err = resctrl_arch_rmid_read(rr->r, d, closid, rmid,
+						     rr->evtid, &tval, rr->arch_mon_ctx);
 		if (!err) {
 			rr->val += tval;
 			ret = 0;

fs/resctrl/monitor.c static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain * · line 637

Quoted 10 lines
fs/resctrl/monitor.c +2 -5
@@ -613,11 +633,16 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
 	rr.r = r;
 	rr.d = d;
 	rr.evtid = evtid;
-	rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
-	if (IS_ERR(rr.arch_mon_ctx)) {
-		pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-				    PTR_ERR(rr.arch_mon_ctx));
-		return;
+	if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
+	    resctrl_arch_mbm_cntr_assign_enabled(r)) {

Duplicate check?

Quoted 22 lines
fs/resctrl/monitor.c +10 -1
+		rr.is_mbm_cntr = true;
+	} else {
+		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
+		if (IS_ERR(rr.arch_mon_ctx)) {
+			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
+					    PTR_ERR(rr.arch_mon_ctx));
+			return;
+		}
 	}
 
 	__mon_event_count(rdtgrp, &rr);
@@ -629,7 +654,8 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
 	if (is_mba_sc(NULL))
 		mbm_bw_count(rdtgrp, &rr);
 
-	resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
+	if (rr.arch_mon_ctx)
+		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,

fs/resctrl/monitor.c static void rdtgroup_assign_cntr(struct rdt_resource *r, struct rdt_mon_domain * · line 1016

Quoted 10 lines
fs/resctrl/monitor.c +2 -2
@@ -983,8 +1009,8 @@ static void rdtgroup_assign_cntr(struct rdt_resource *r, struct rdt_mon_domain *
  * Return:
  * Valid counter ID on success, or -ENOENT on failure.
  */
-static int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
-			struct rdtgroup *rdtgrp, enum resctrl_event_id evtid)
+int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
+		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid)
 {
 	int cntr_id;
 

Not necessary?

Reinette

author reviewer
#48 lore raw

Re: [PATCH v16 23/34] fs/resctrl: Support counter read/reset with mbm_event assignment mode

Hi Reinette,

Quoted 14 lines · Reinette Chatre

Hi Babu,

Quoted 11 lines · Babu Moger

When "mbm_event" counter assignment mode is enabled, the architecture requires a counter ID to read the event data.

Introduce an is_mbm_cntr field in struct rmid_read to indicate whether counter assignment mode is in use.

Update the logic to call resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() when the assignment mode is active. Report 'Unassigned' in case the user attempts to read the event without assigning a hardware counter.

Quoted 8 lines
Quoted 4 lines

Declare mbm_cntr_get() in fs/resctrl/internal.h to make it accessible to other functions within fs/resctrl.

From what I can tell this is not needed by this patch. It is also a hint that

there may be some monitoring specific code outside of monitor.c. Looks like this is done to support later patch #29 "fs/resctrl: Introduce mbm_L3_assignments to list assignments in a group" where mbm_L3_assignments_show() should rather be in monitor.c

Yes. Will move all these to monitor.c.

Quoted 82 lines
Quoted 5 lines

---

...

Quoted 75 lines
---
 Documentation/filesystems/resctrl.rst |  6 ++++
 fs/resctrl/ctrlmondata.c              | 22 +++++++++---
 fs/resctrl/internal.h                 |  5 +++
 fs/resctrl/monitor.c                  | 52 ++++++++++++++++++++-------
 4 files changed, 67 insertions(+), 18 deletions(-)
Documentation/filesystems/resctrl.rst +6 -0
index 446736dbd97f..4c24c5f3f4c1 100644
@@ -434,6 +434,12 @@ When monitoring is enabled all MON groups will also contain:
 	for the L3 cache they occupy). These are named "mon_sub_L3_YY"
 	where "YY" is the node number.
 
+	When the 'mbm_event' counter assignment mode is enabled, reading
+	an MBM event of a MON group returns 'Unassigned' if no hardware
+	counter is assigned to it. For CTRL_MON groups, 'Unassigned' is
+	returned if the MBM event does not have an assigned counter in the
+	CTRL_MON group nor in any of its associated MON groups.
+
 "mon_hw_id":
 	Available only with debug option. The identifier used by hardware
 	for the monitor group. On x86 this is the RMID.
fs/resctrl/ctrlmondata.c +17 -5
index ad7ffc6acf13..31787ce6ec91 100644
@@ -563,10 +563,15 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 	rr->r = r;
 	rr->d = d;
 	rr->first = first;
-	rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
-	if (IS_ERR(rr->arch_mon_ctx)) {
-		rr->err = -EINVAL;
-		return;
+	if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
+	    resctrl_is_mbm_event(evtid)) {
+		rr->is_mbm_cntr = true;
+	} else {
+		rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
+		if (IS_ERR(rr->arch_mon_ctx)) {
+			rr->err = -EINVAL;
+			return;
+		}
 	}
 
 	cpu = cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU);
@@ -582,7 +587,8 @@ 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);
+	if (rr->arch_mon_ctx)
+		resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
 }
 
 int rdtgroup_mondata_show(struct seq_file *m, void *arg)
@@ -653,10 +659,16 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 
 checkresult:
 
+	/*
+	 * -ENOENT is a special case, set only when "mbm_event" counter assignment
+	 * mode is enabled and no counter has been assigned.
+	 */
 	if (rr.err == -EIO)
 		seq_puts(m, "Error\n");
 	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
+	else if (rr.err == -ENOENT)
+		seq_puts(m, "Unassigned\n");
 	else
 		seq_printf(m, "%llu\n", rr.val);
 
Quoted 13 lines

fs/resctrl/internal.h struct mon_data { · line 114

Quoted 10 lines
fs/resctrl/internal.h +2 -0
index 216588842444..eeee83a5067a 100644
@@ -110,6 +110,8 @@ struct mon_data {
  *	   domains in @r sharing L3 @ci.id
  * @evtid: Which monitor event to read.
  * @first: Initialize MBM counter when true.
+ * @is_mbm_cntr: Is the counter valid? true if "mbm_event" counter assignment mode is
+ *	   enabled and it is an MBM event.

Since a counter may not be assigned to event being read I do not believe that "Is the counter valid?" is accurate and should rather be dropped. Rest of text looks accurate to me.

Sure.

Quoted 13 lines
Quoted 13 lines
fs/resctrl/internal.h +1 -0
  * @ci_id: Cacheinfo id for L3. Only set when @d 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,
@@ -124,6 +126,7 @@ struct rmid_read {
 	struct rdt_mon_domain	*d;
 	enum resctrl_event_id	evtid;
 	bool			first;
+	bool			is_mbm_cntr;
 	unsigned int		ci_id;
 	int			err;
 	u64			val;
@@ -391,6 +394,8 @@ int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp
Quoted 8 lines

fs/resctrl/internal.h int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp · line 399

Quoted 6 lines
fs/resctrl/internal.h +2 -0
 			       struct mon_evt *mevt);
 void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 				  struct mon_evt *mevt);
+int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
+		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
 

Not necessary? mbm_cntr_get() can remain internal to monitor.c

Yes. Not necessary.

Quoted 69 lines
Quoted 69 lines
fs/resctrl/internal.h +0 -0
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
fs/resctrl/monitor.c +25 -6
index 070965d45770..a8b53b0ad0b7 100644
@@ -362,13 +362,25 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 	u32 closid = rdtgrp->closid;
 	u32 rmid = rdtgrp->mon.rmid;
 	struct rdt_mon_domain *d;
+	int cntr_id = -ENOENT;
 	struct cacheinfo *ci;
 	struct mbm_state *m;
 	int err, ret;
 	u64 tval = 0;
 
+	if (rr->is_mbm_cntr) {
+		cntr_id = mbm_cntr_get(rr->r, rr->d, rdtgrp, rr->evtid);
+		if (cntr_id < 0) {
+			rr->err = -ENOENT;
+			return -EINVAL;
+		}
+	}
+
 	if (rr->first) {
-		resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
+		if (rr->is_mbm_cntr)
+			resctrl_arch_reset_cntr(rr->r, rr->d, closid, rmid, cntr_id, rr->evtid);
+		else
+			resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
 		m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
 		if (m)
 			memset(m, 0, sizeof(struct mbm_state));
@@ -379,8 +391,12 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 		/* Reading a single domain, must be on a CPU in that domain. */
 		if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask))
 			return -EINVAL;
-		rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid,
-						 rr->evtid, &tval, rr->arch_mon_ctx);
+		if (rr->is_mbm_cntr)
+			rr->err = resctrl_arch_cntr_read(rr->r, rr->d, closid, rmid, cntr_id,
+							 rr->evtid, &tval);
+		else
+			rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid,
+							 rr->evtid, &tval, rr->arch_mon_ctx);
 		if (rr->err)
 			return rr->err;
 
@@ -405,8 +421,12 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, 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,
-					     rr->evtid, &tval, rr->arch_mon_ctx);
+		if (rr->is_mbm_cntr)
+			err = resctrl_arch_cntr_read(rr->r, d, closid, rmid, cntr_id,
+						     rr->evtid, &tval);
+		else
+			err = resctrl_arch_rmid_read(rr->r, d, closid, rmid,
+						     rr->evtid, &tval, rr->arch_mon_ctx);
 		if (!err) {
 			rr->val += tval;
 			ret = 0;
@@ -613,11 +633,16 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
 	rr.r = r;
 	rr.d = d;
 	rr.evtid = evtid;
-	rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
Quoted 8 lines

fs/resctrl/monitor.c static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain * · line 637

Quoted 6 lines
fs/resctrl/monitor.c +2 -4
-	if (IS_ERR(rr.arch_mon_ctx)) {
-		pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-				    PTR_ERR(rr.arch_mon_ctx));
-		return;
+	if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
+	    resctrl_arch_mbm_cntr_assign_enabled(r)) {

Duplicate check?

Yes.

Quoted 21 lines
Quoted 21 lines
fs/resctrl/monitor.c +10 -1
+		rr.is_mbm_cntr = true;
+	} else {
+		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
+		if (IS_ERR(rr.arch_mon_ctx)) {
+			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
+					    PTR_ERR(rr.arch_mon_ctx));
+			return;
+		}
 	}
 
 	__mon_event_count(rdtgrp, &rr);
@@ -629,7 +654,8 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
 	if (is_mba_sc(NULL))
 		mbm_bw_count(rdtgrp, &rr);
 
-	resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
+	if (rr.arch_mon_ctx)
+		resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
 }
 
Quoted 15 lines

fs/resctrl/monitor.c static void rdtgroup_assign_cntr(struct rdt_resource *r, struct rdt_mon_domain * · line 1016

Quoted 12 lines
fs/resctrl/monitor.c +2 -2
 static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
@@ -983,8 +1009,8 @@ static void rdtgroup_assign_cntr(struct rdt_resource *r, struct rdt_mon_domain *
  * Return:
  * Valid counter ID on success, or -ENOENT on failure.
  */
-static int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
-			struct rdtgroup *rdtgrp, enum resctrl_event_id evtid)
+int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
+		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid)
 {
 	int cntr_id;
 

Not necessary?

Yes.

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#49 lore raw

PATCH v16 24/34 fs/resctrl: Add definitions for MBM event configuration

In reply to Babu Moger

The "mbm_event" counter assignment mode allows the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The user can specify the memory transaction(s) for the counter to track.

Add the definitions for supported memory transactions (e.g., read, write, etc.) the counter can be configured with.

---
v16: Minor code comment update.

v15: Updated the changelog.
Moved NUM_MBM_TRANSACTIONS to include/linux/resctrl_types.h Changed struct mbm_config_value to struct mbm_transaction.

v14: Changed the term memory events to memory transactions to be consistant.
Changed the name of the structure to mbm_config_value(from mbm_evt_value). Changed name to memory trasactions where applicable.
Changes subject line to fs/resctrl.

v13: Updated the changelog.
Removed the definitions from resctrl_types.h and moved to internal.h. Removed mbm_assign_config definition. Configurations will be part of mon_evt list.
Resolved conflicts caused by the recent FS/ARCH code restructure. The rdtgroup.c file has now been split between the FS and ARCH directories.

v12: New patch to support event configurations via new counter_configs
method.

---
 fs/resctrl/internal.h         | 11 +++++++++++
 fs/resctrl/monitor.c          | 11 +++++++++++
 include/linux/resctrl_types.h |  3 +++
 3 files changed, 25 insertions(+)
fs/resctrl/internal.h +11 -0
index eeee83a5067a..693268bcbad2 100644
@@ -216,6 +216,17 @@ struct rdtgroup {
 	struct pseudo_lock_region	*plr;
 };
 
+/**
+ * struct mbm_transaction - Memory transaction an MBM event can be configured with.
+ * @name:	Name of memory transaction (read, write ...).
+ * @val:	The bit (eg. READS_TO_LOCAL_MEM or READS_TO_REMOTE_MEM) used to
+ *		represent the memory transaction within an event's configuration.
+ */
+struct mbm_transaction {
+	char	name[32];
+	u32	val;
+};
+
 /* rdtgroup.flags */
 #define	RDT_DELETED		1
 
fs/resctrl/monitor.c +11 -0
index a8b53b0ad0b7..16bcfeeb89e6 100644
@@ -918,6 +918,17 @@ u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id evtid)
 	return mon_event_all[evtid].evt_cfg;
 }
 
+/* Decoded values for each type of memory transaction. */
+struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
+	{"local_reads", READS_TO_LOCAL_MEM},
+	{"remote_reads", READS_TO_REMOTE_MEM},
+	{"local_non_temporal_writes", NON_TEMP_WRITE_TO_LOCAL_MEM},
+	{"remote_non_temporal_writes", NON_TEMP_WRITE_TO_REMOTE_MEM},
+	{"local_reads_slow_memory", READS_TO_LOCAL_S_MEM},
+	{"remote_reads_slow_memory", READS_TO_REMOTE_S_MEM},
+	{"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
+};
+
 /**
  * resctrl_mon_resource_init() - Initialise global monitoring structures.
  *
include/linux/resctrl_types.h +3 -0
index d98351663c2c..acfe07860b34 100644
@@ -34,6 +34,9 @@
 /* Max event bits supported */
 #define MAX_EVT_CONFIG_BITS		GENMASK(6, 0)
 
+/* Number of memory transactions that an MBM event can be configured with */
+#define NUM_MBM_TRANSACTIONS		7
+
 /* Event IDs */
 enum resctrl_event_id {
 	/* Must match value of first event below */
Signature · 1 line
2.34.1
maintainer
#50 lore raw

Re: [PATCH v16 24/34] fs/resctrl: Add definitions for MBM event configuration

Hi Babu,

Quoted 10 lines · Babu Moger

The "mbm_event" counter assignment mode allows the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The user can specify the memory transaction(s) for the counter to track.

Add the definitions for supported memory transactions (e.g., read, write, etc.) the counter can be configured with.

---

...

fs/resctrl/internal.h

Quoted 10 lines
---
 fs/resctrl/internal.h         | 11 +++++++++++
 fs/resctrl/monitor.c          | 11 +++++++++++
 include/linux/resctrl_types.h |  3 +++
 3 files changed, 25 insertions(+)
fs/resctrl/internal.h +0 -0
index eeee83a5067a..693268bcbad2 100644

Looks like only monitoring code in monitor.c needs to know about struct mbm_transaction so this can stay within monitor.c ?

Quoted 8 lines
fs/resctrl/internal.h +4 -0
@@ -216,6 +216,17 @@ struct rdtgroup {
 	struct pseudo_lock_region	*plr;
 };
 
+/**
+ * struct mbm_transaction - Memory transaction an MBM event can be configured with.
+ * @name:	Name of memory transaction (read, write ...).
+ * @val:	The bit (eg. READS_TO_LOCAL_MEM or READS_TO_REMOTE_MEM) used to

fs/resctrl/internal.h struct rdtgroup { · line 232

Quoted 10 lines
fs/resctrl/internal.h +7 -0
+ *		represent the memory transaction within an event's configuration.
+ */
+struct mbm_transaction {
+	char	name[32];
+	u32	val;
+};
+
 /* rdtgroup.flags */
 #define	RDT_DELETED		1
 

Reinette

author reviewer
#51 lore raw

Re: [PATCH v16 24/34] fs/resctrl: Add definitions for MBM event configuration

Hi Reinette,

Quoted 22 lines · Reinette Chatre

Hi Babu,

Quoted 10 lines · Babu Moger

The "mbm_event" counter assignment mode allows the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The user can specify the memory transaction(s) for the counter to track.

Add the definitions for supported memory transactions (e.g., read, write, etc.) the counter can be configured with.

---

...

Quoted 6 lines
---
 fs/resctrl/internal.h         | 11 +++++++++++
 fs/resctrl/monitor.c          | 11 +++++++++++
 include/linux/resctrl_types.h |  3 +++
 3 files changed, 25 insertions(+)
Quoted 7 lines

fs/resctrl/internal.h

Quoted 4 lines
fs/resctrl/internal.h +0 -0
index eeee83a5067a..693268bcbad2 100644

Looks like only monitoring code in monitor.c needs to know about struct mbm_transaction so this can stay within monitor.c ?

Sure.

Quoted 23 lines
Quoted 9 lines
fs/resctrl/internal.h +4 -0
@@ -216,6 +216,17 @@ struct rdtgroup {
 	struct pseudo_lock_region	*plr;
 };
 
+/**
+ * struct mbm_transaction - Memory transaction an MBM event can be configured with.
+ * @name:	Name of memory transaction (read, write ...).
+ * @val:	The bit (eg. READS_TO_LOCAL_MEM or READS_TO_REMOTE_MEM) used to

fs/resctrl/internal.h struct rdtgroup { · line 232

Quoted 10 lines
fs/resctrl/internal.h +7 -0
+ *		represent the memory transaction within an event's configuration.
+ */
+struct mbm_transaction {
+	char	name[32];
+	u32	val;
+};
+
 /* rdtgroup.flags */
 #define	RDT_DELETED		1
 

Reinette

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#52 lore raw

PATCH v16 25/34 fs/resctrl: Add event configuration directory under info/L3_MON/

In reply to Babu Moger

When "mbm_event" counter assignment mode is supported the /sys/fs/resctrl/info/L3_MON/event_configs directory contains a sub-directory for each MBM event that can be assigned to a counter. The MBM event sub-directory contains a file named "event_filter" that is used to view and modify which memory transactions the MBM event is configured with.

Create /sys/fs/resctrl/info/L3_MON/event_configs directory on resctrl mount and pre-populate it with directories for the two existing MBM events:
mbm_total_bytes and mbm_local_bytes. Create the "event_filter" file within each MBM event directory with the needed *show() that displays the memory transactions with which the MBM event is configured.

Example:

$ mount -t resctrl resctrl /sys/fs/resctrl
$ cd /sys/fs/resctrl/
$ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter
  local_reads,remote_reads,local_non_temporal_writes,
  remote_non_temporal_writes,local_reads_slow_memory,
  remote_reads_slow_memory,dirty_victim_writes_all
$ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter
  local_reads,local_non_temporal_writes,local_reads_slow_memory

---
v16: Moved event_filter_show() to fs/resctrl/monitor.c
Changed the goto label out_config to out.
Added rdtgroup_mutex in event_filter_show().
Removed extern for mbm_transactions. Not required. 0025-fs-resctrl-Add-event-configuration-directory-under 0025-fs-resctrl-Add-event-configuration-directory-under 0025-fs-resctrl-Add-event-configuration-directory-under
Added prototype rdt_kn_parent_priv() in so it can be called from monitor.c

v15: Fixed the event_filter display with proper spacing.
Updated the changelog.
Changed the function name resctrl_mkdir_counter_configs() to resctrl_mkdir_event_configs().
Called resctrl_mkdir_event_configs from rdtgroup_mkdir_info_resdir(). It avoids the call kernfs_find_and_get() to get the node for info directory. Used for_each_mon_event() where applicable.

v14: Updated the changelog with context. Thanks to Reinette.
Changed the name of directory to event_configs from counter_config. Updated user doc about the memory transactions supported by assignment. Removed mbm_mode from struct mon_evt. Not required anymore.

v13: Updated user doc (resctrl.rst).
Changed the name of the function resctrl_mkdir_info_configs to resctrl_mkdir_counter_configs().
Replaced seq_puts() with seq_putc() where applicable.
Removed RFTYPE_MON_CONFIG definition. Not required.
Changed the name of the flag RFTYPE_CONFIG to RFTYPE_ASSIGN_CONFIG. Reinette suggested RFTYPE_MBM_EVENT_CONFIG but RFTYPE_ASSIGN_CONFIG seemed shorter and pricise.
The configuration is created using evt_list.
Resolved conflicts caused by the recent FS/ARCH code restructure.
The monitor.c/rdtgroup.c files have been split between the FS and ARCH directories.

v12: New patch to hold the MBM event configurations for mbm_cntr_assign mode.

---
 Documentation/filesystems/resctrl.rst | 32 +++++++++++++++
 fs/resctrl/internal.h                 |  6 +++
 fs/resctrl/monitor.c                  | 24 +++++++++++
 fs/resctrl/rdtgroup.c                 | 58 ++++++++++++++++++++++++++-
 4 files changed, 119 insertions(+), 1 deletion(-)
Documentation/filesystems/resctrl.rst +32 -0
index 4c24c5f3f4c1..3dfc177f9792 100644
@@ -310,6 +310,38 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
 	  0=30;1=30
 
+"event_configs":
+	Directory that exists when "mbm_event" counter assignment mode is supported.
+	Contains sub-directory for each MBM event that can be assigned to a counter.
+
+	Two MBM events are supported by default: mbm_local_bytes and mbm_total_bytes.
+	Each MBM event's sub-directory contains a file named "event_filter" that is
+	used to view and modify which memory transactions the MBM event is configured
+	with.
+
+	List of memory transaction types supported:
+
+	==========================  ========================================================
+	Name			    Description
+	==========================  ========================================================
+	dirty_victim_writes_all     Dirty Victims from the QOS domain to all types of memory
+	remote_reads_slow_memory    Reads to slow memory in the non-local NUMA domain
+	local_reads_slow_memory     Reads to slow memory in the local NUMA domain
+	remote_non_temporal_writes  Non-temporal writes to non-local NUMA domain
+	local_non_temporal_writes   Non-temporal writes to local NUMA domain
+	remote_reads                Reads to memory in the non-local NUMA domain
+	local_reads                 Reads to memory in the local NUMA domain
+	==========================  ========================================================
+
+	For example::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+	  local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
+	  local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+	  local_reads,local_non_temporal_writes,local_reads_slow_memory
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/internal.h +6 -0
index 693268bcbad2..e082d8718199 100644
@@ -252,6 +252,8 @@ struct mbm_transaction {
 
 #define RFTYPE_DEBUG			BIT(10)
 
+#define RFTYPE_ASSIGN_CONFIG		BIT(11)
+
 #define RFTYPE_CTRL_INFO		(RFTYPE_INFO | RFTYPE_CTRL)
 
 #define RFTYPE_MON_INFO			(RFTYPE_INFO | RFTYPE_MON)
@@ -408,6 +410,10 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
 int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
 		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
 
+void *rdt_kn_parent_priv(struct kernfs_node *kn);
+
+int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +24 -0
index 16bcfeeb89e6..fa5f63126682 100644
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
 	{"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
 };
 
+int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+	struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+	bool sep = false;
+	int i;
+
+	mutex_lock(&rdtgroup_mutex);
+
+	for (i = 0; i < NUM_MBM_TRANSACTIONS; i++) {
+		if (mevt->evt_cfg & mbm_transactions[i].val) {
+			if (sep)
+				seq_putc(seq, ',');
+			seq_printf(seq, "%s", mbm_transactions[i].name);
+			sep = true;
+		}
+	}
+	seq_putc(seq, '\n');
+
+	mutex_unlock(&rdtgroup_mutex);
+
+	return 0;
+}
+
 /**
  * resctrl_mon_resource_init() - Initialise global monitoring structures.
  *
@@ -982,6 +1005,7 @@ int resctrl_mon_resource_init(void)
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("available_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +57 -1

86 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#53 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Babu,

Documentation/filesystems/resctrl.rst with the following files: · line 315

Quoted 12 lines · Babu Moger

---

Documentation/filesystems/resctrl.rst +3 -0
index 4c24c5f3f4c1..3dfc177f9792 100644
@@ -310,6 +310,38 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
 	  0=30;1=30
 
+"event_configs":
+	Directory that exists when "mbm_event" counter assignment mode is supported.
+	Contains sub-directory for each MBM event that can be assigned to a counter.

"Contains sub-directory" -> "Contains a sub-directory"?

Quoted 32 lines
Documentation/filesystems/resctrl.rst +29 -0
+
+	Two MBM events are supported by default: mbm_local_bytes and mbm_total_bytes.
+	Each MBM event's sub-directory contains a file named "event_filter" that is
+	used to view and modify which memory transactions the MBM event is configured
+	with.
+
+	List of memory transaction types supported:
+
+	==========================  ========================================================
+	Name			    Description
+	==========================  ========================================================
+	dirty_victim_writes_all     Dirty Victims from the QOS domain to all types of memory
+	remote_reads_slow_memory    Reads to slow memory in the non-local NUMA domain
+	local_reads_slow_memory     Reads to slow memory in the local NUMA domain
+	remote_non_temporal_writes  Non-temporal writes to non-local NUMA domain
+	local_non_temporal_writes   Non-temporal writes to local NUMA domain
+	remote_reads                Reads to memory in the non-local NUMA domain
+	local_reads                 Reads to memory in the local NUMA domain
+	==========================  ========================================================
+
+	For example::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+	  local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
+	  local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+	  local_reads,local_non_temporal_writes,local_reads_slow_memory
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy

...

Quoted 6 lines
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
 	{"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 939

Quoted 10 lines
fs/resctrl/monitor.c +8 -0
 };
 
+int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+	struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+	bool sep = false;
+	int i;
+
+	mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled. I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.
2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

Quoted 26 lines
fs/resctrl/monitor.c +16 -0
+	for (i = 0; i < NUM_MBM_TRANSACTIONS; i++) {
+		if (mevt->evt_cfg & mbm_transactions[i].val) {
+			if (sep)
+				seq_putc(seq, ',');
+			seq_printf(seq, "%s", mbm_transactions[i].name);
+			sep = true;
+		}
+	}
+	seq_putc(seq, '\n');
+
+	mutex_unlock(&rdtgroup_mutex);
+
+	return 0;
+}
+
 /**
  * resctrl_mon_resource_init() - Initialise global monitoring structures.
  *
@@ -982,6 +1005,7 @@ int resctrl_mon_resource_init(void)
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("available_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
 	}
 
 	return 0;

...

Quoted 9 lines
fs/resctrl/monitor.c +5 -0
@@ -2295,6 +2339,18 @@ static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
 		return ret;
 
 	ret = rdtgroup_add_files(kn_subdir, fflags);
+	if (ret)
+		return ret;
+
+	if ((fflags & RFTYPE_MON_INFO) == RFTYPE_MON_INFO) {
+		r = priv;

fs/resctrl/monitor.c static int rdtgroup_mkdir_info_resdir(void *priv, char *name, · line 2356

Quoted 10 lines
fs/resctrl/monitor.c +7 -0
+		if (r->mon.mbm_cntr_assignable) {
+			ret = resctrl_mkdir_event_configs(r, kn_subdir);
+			if (ret)
+				return ret;
+		}
+	}
+
 	if (!ret)
 		kernfs_activate(kn_subdir);
 

Looks like the "if (!ret)" above can be dropped to always call "kernfs_activate(kn_subdir)" on exit making it clear that this is success path and function exits early on any error.

Reinette

author reviewer
#54 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Reinette,

Quoted 14 lines · Reinette Chatre

Hi Babu,

Quoted 9 lines · Babu Moger

---

Documentation/filesystems/resctrl.rst +0 -0
index 4c24c5f3f4c1..3dfc177f9792 100644
@@ -310,6 +310,38 @@ with the following files:
  	  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
  	  0=30;1=30
 
Quoted 4 lines

Documentation/filesystems/resctrl.rst with the following files: · line 315

Quoted 3 lines
Documentation/filesystems/resctrl.rst +3 -0
+"event_configs":
+	Directory that exists when "mbm_event" counter assignment mode is supported.
+	Contains sub-directory for each MBM event that can be assigned to a counter.

"Contains sub-directory" -> "Contains a sub-directory"?

Sure.

Quoted 54 lines
Quoted 32 lines
Documentation/filesystems/resctrl.rst +29 -0
+
+	Two MBM events are supported by default: mbm_local_bytes and mbm_total_bytes.
+	Each MBM event's sub-directory contains a file named "event_filter" that is
+	used to view and modify which memory transactions the MBM event is configured
+	with.
+
+	List of memory transaction types supported:
+
+	==========================  ========================================================
+	Name			    Description
+	==========================  ========================================================
+	dirty_victim_writes_all     Dirty Victims from the QOS domain to all types of memory
+	remote_reads_slow_memory    Reads to slow memory in the non-local NUMA domain
+	local_reads_slow_memory     Reads to slow memory in the local NUMA domain
+	remote_non_temporal_writes  Non-temporal writes to non-local NUMA domain
+	local_non_temporal_writes   Non-temporal writes to local NUMA domain
+	remote_reads                Reads to memory in the non-local NUMA domain
+	local_reads                 Reads to memory in the local NUMA domain
+	==========================  ========================================================
+
+	For example::
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+	  local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
+	  local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+	  local_reads,local_non_temporal_writes,local_reads_slow_memory
+
  "max_threshold_occupancy":
  		Read/write file provides the largest value (in
  		bytes) at which a previously used LLC_occupancy

...

Quoted 6 lines
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
  	{"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 939

Quoted 10 lines
fs/resctrl/monitor.c +8 -0
  };
 
+int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+	struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+	bool sep = false;
+	int i;
+
+	mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

Quoted 9 lines

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled. I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.

Yes. I agree.

Quoted 5 lines

2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

So, initialize both total and local event configuration to default values when switched to "default mode"?

Something like this?

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;

mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM;

We are already doing that right (in patch 32)?

Quoted 43 lines
Quoted 28 lines
fs/resctrl/monitor.c +16 -0
+	for (i = 0; i < NUM_MBM_TRANSACTIONS; i++) {
+		if (mevt->evt_cfg & mbm_transactions[i].val) {
+			if (sep)
+				seq_putc(seq, ',');
+			seq_printf(seq, "%s", mbm_transactions[i].name);
+			sep = true;
+		}
+	}
+	seq_putc(seq, '\n');
+
+	mutex_unlock(&rdtgroup_mutex);
+
+	return 0;
+}
+
  /**
   * resctrl_mon_resource_init() - Initialise global monitoring structures.
   *
@@ -982,6 +1005,7 @@ int resctrl_mon_resource_init(void)
  					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
  		resctrl_file_fflags_init("available_mbm_cntrs",
  					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
  	}
 
  	return 0;

...

Quoted 13 lines
fs/resctrl/monitor.c +9 -0
@@ -2295,6 +2339,18 @@ static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
  		return ret;
 
  	ret = rdtgroup_add_files(kn_subdir, fflags);
+	if (ret)
+		return ret;
+
+	if ((fflags & RFTYPE_MON_INFO) == RFTYPE_MON_INFO) {
+		r = priv;
+		if (r->mon.mbm_cntr_assignable) {
+			ret = resctrl_mkdir_event_configs(r, kn_subdir);
+			if (ret)
+				return ret;
Quoted 8 lines

fs/resctrl/monitor.c static int rdtgroup_mkdir_info_resdir(void *priv, char *name, · line 2356

Quoted 6 lines
fs/resctrl/monitor.c +3 -0
+		}
+	}
+
  	if (!ret)
  		kernfs_activate(kn_subdir);
 

Looks like the "if (!ret)" above can be dropped to always call "kernfs_activate(kn_subdir)" on exit making it clear that this is success path and function exits early on any error.

Sure. Will do,

Thanks

Babu

maintainer
#55 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Babu,

Quoted 31 lines · Babu
Quoted 21 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 938

Quoted 10 lines
fs/resctrl/monitor.c +7 -0
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
       {"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
   };
   +int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+    struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+    bool sep = false;
+    int i;
+
+    mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

Quoted 9 lines

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled.  I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.

Quoted 1 line

Yes. I agree.

hmmm ... ok, you say that you agree but I cannot tell if you are going to do anything about it.

On a system with BMEC enabled the mbm_total_bytes_config and mbm_local_bytes_config files should be the *only* source of MBM event configuration information, no?

It may be ok to have event_filter print configuration when assignable counters are disabled if BMEC is not supported but that would require that this information will always be known for a "default" monitoring setup. While this may be true for AMD it is not obvious to me that this is universally true. Once this file exists in this form resctrl will always be required to provide data for the event configuration and it is not clear to me that this can always be guaranteed.

Quoted 8 lines
Quoted 5 lines

2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

So, initialize both total and local event configuration to default values when switched to "default mode"?

Quoted 7 lines

Something like this?

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;

mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM;

We are already doing that right (in patch 32)?

Yes, but it creates this strange dependency where the "default" monitoring mode (that has been supported long before configurable events and assignable counters came along) requires support of "assignable counter mode".

Consider it from another view, if resctrl wants to make event configuration available for the "default" mode then the "event_filter" file could always be visible when MBM local/total is supported to give users insight into what is monitored, whether assignable counters are supported or not. This is not possible on systems that do not support ABMC though, right?

Reinette

author reviewer
#56 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Reinette,

Quoted 33 lines · Reinette Chatre

Hi Babu,

Quoted 30 lines · Babu
Quoted 29 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 938

Quoted 10 lines
fs/resctrl/monitor.c +7 -0
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
       {"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
   };
   +int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+    struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+    bool sep = false;
+    int i;
+
+    mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled.  I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.

Quoted 6 lines
Quoted 1 line

Yes. I agree.

hmmm ... ok, you say that you agree but I cannot tell if you are going to do anything about it.

On a system with BMEC enabled the mbm_total_bytes_config and mbm_local_bytes_config files should be the *only* source of MBM event configuration information, no?

That is correct.

Quoted 7 lines

It may be ok to have event_filter print configuration when assignable counters are disabled if BMEC is not supported but that would require that this information will always be known for a "default" monitoring setup. While this may be true for AMD it is not obvious to me that this is universally true. Once this file exists in this form resctrl will always be required to provide data for the event configuration and it is not clear to me that this can always be guaranteed.

Yea. It is not true universally true. I don't know what these values are for Intel and ARM.

Quoted 19 lines
Quoted 8 lines
Quoted 6 lines

2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

So, initialize both total and local event configuration to default values when switched to "default mode"?

Quoted 7 lines

Something like this?

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;

mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM;

We are already doing that right (in patch 32)?

Yes, but it creates this strange dependency where the "default" monitoring mode (that has been supported long before configurable events and assignable counters came along) requires support of "assignable counter mode".

Quoted 5 lines

Consider it from another view, if resctrl wants to make event configuration available for the "default" mode then the "event_filter" file could always be visible when MBM local/total is supported to give users insight into what is monitored, whether assignable counters are supported or not. This is not possible on systems that do not support ABMC though, right?

That is correct. With BMEC, each domain can have its own settings.  So, printing the default will not be accurate.

What options do we have here.

How about adding the check if (resctrl_arch_mbm_cntr_assign_enabled())?  Only print the values when ABMC is supported else print information in "last_cmd_status".

Thanks

Babu

maintainer
#57 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Babu,

Quoted 77 lines · Babu
Quoted 31 lines · Reinette Chatre
Quoted 30 lines · Babu
Quoted 29 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 938

Quoted 10 lines
fs/resctrl/monitor.c +7 -0
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
        {"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
    };
    +int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+    struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+    bool sep = false;
+    int i;
+
+    mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled.  I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.

Quoted 6 lines
Quoted 1 line

Yes. I agree.

hmmm ... ok, you say that you agree but I cannot tell if you are going to do anything about it.

On a system with BMEC enabled the mbm_total_bytes_config and mbm_local_bytes_config files should be the *only* source of MBM event configuration information, no?

That is correct.

Quoted 7 lines

It may be ok to have event_filter print configuration when assignable counters are disabled if BMEC is not supported but that would require that this information will always be known for a "default" monitoring setup. While this may be true for AMD it is not obvious to me that this is universally true. Once this file exists in this form resctrl will always be required to provide data for the event configuration and it is not clear to me that this can always be guaranteed.

Yea. It is not true universally true. I don't know what these values are for Intel and ARM.

Quoted 19 lines
Quoted 8 lines
Quoted 6 lines

2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

So, initialize both total and local event configuration to default values when switched to "default mode"?

Quoted 7 lines

Something like this?

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;

mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM;

We are already doing that right (in patch 32)?

Yes, but it creates this strange dependency where the "default" monitoring mode (that has been supported long before configurable events and assignable counters came along) requires support of "assignable counter mode".

Quoted 5 lines

Consider it from another view, if resctrl wants to make event configuration available for the "default" mode then the "event_filter" file could always be visible when MBM local/total is supported to give users insight into what is monitored, whether assignable counters are supported or not. This is not possible on systems that do not support ABMC though, right?

Quoted 6 lines

That is correct. With BMEC, each domain can have its own settings.  So, printing the default will not be accurate.

What options do we have here.

How about adding the check if (resctrl_arch_mbm_cntr_assign_enabled())?  Only print the values when ABMC is supported else print information in "last_cmd_status".

Did you perhaps intend to write "Only print the values when ABMC is *enabled* else print information in "last_cmd_status".? If this is what you actually meant then I agree. I think doing so places clear boundary on this feature that gives us more options/flexibility for future changes.

Reinette

author reviewer
#58 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Reinette,

Quoted 77 lines · Reinette Chatre

Hi Babu,

Quoted 74 lines · Babu
Quoted 31 lines · Reinette Chatre
Quoted 30 lines · Babu
Quoted 29 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 938

Quoted 10 lines
fs/resctrl/monitor.c +7 -0
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
        {"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
    };
    +int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+    struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+    bool sep = false;
+    int i;
+
+    mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled.  I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.

Quoted 6 lines
Quoted 1 line

Yes. I agree.

hmmm ... ok, you say that you agree but I cannot tell if you are going to do anything about it.

On a system with BMEC enabled the mbm_total_bytes_config and mbm_local_bytes_config files should be the *only* source of MBM event configuration information, no?

That is correct.

Quoted 6 lines

It may be ok to have event_filter print configuration when assignable counters are disabled if BMEC is not supported but that would require that this information will always be known for a "default" monitoring setup. While this may be true for AMD it is not obvious to me that this is universally true. Once this file exists in this form resctrl will always be required to provide data for the event configuration and it is not clear to me that this can always be guaranteed.

Yea. It is not true universally true. I don't know what these values are for Intel and ARM.

Quoted 18 lines
Quoted 7 lines
Quoted 5 lines

2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

So, initialize both total and local event configuration to default values when switched to "default mode"?

Quoted 7 lines

Something like this?

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;

mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM;

We are already doing that right (in patch 32)?

Yes, but it creates this strange dependency where the "default" monitoring mode (that has been supported long before configurable events and assignable counters came along) requires support of "assignable counter mode".

Quoted 5 lines

Consider it from another view, if resctrl wants to make event configuration available for the "default" mode then the "event_filter" file could always be visible when MBM local/total is supported to give users insight into what is monitored, whether assignable counters are supported or not. This is not possible on systems that do not support ABMC though, right?

That is correct. With BMEC, each domain can have its own settings.  So, printing the default will not be accurate.

Quoted 8 lines
Quoted 4 lines

What options do we have here.

How about adding the check if (resctrl_arch_mbm_cntr_assign_enabled())?  Only print the values when ABMC is supported else print information in "last_cmd_status".

Did you perhaps intend to write "Only print the values when ABMC is *enabled* else print information in "last_cmd_status".? If this is what you actually meant then I agree. I think doing so places clear boundary on this feature that gives us more options/flexibility for future changes.

Yes. That is what I meant.  We have same check in event_filer_write(). Will add the same check in event_filter_show().

Thanks

Babu

maintainer
#59 lore raw

Re: [PATCH v16 25/34] fs/resctrl: Add event configuration directory under info/L3_MON/

Hi Babu,

Quoted 78 lines · Babu
Quoted 77 lines · Reinette Chatre
Quoted 76 lines · Babu
Quoted 31 lines · Reinette Chatre
Quoted 30 lines · Babu
Quoted 29 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
fs/resctrl/monitor.c +0 -0
index 16bcfeeb89e6..fa5f63126682 100644

fs/resctrl/monitor.c struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = { · line 938

Quoted 10 lines
fs/resctrl/monitor.c +7 -0
@@ -929,6 +929,29 @@ struct mbm_transaction mbm_transactions[NUM_MBM_TRANSACTIONS] = {
         {"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM},
     };
     +int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
+{
+    struct mon_evt *mevt = rdt_kn_parent_priv(of->kn);
+    bool sep = false;
+    int i;
+
+    mutex_lock(&rdtgroup_mutex);
+

There is inconsistency among the files introduced on how "mbm_event mode disabled" case is handled. Some files return failure from their _show()/_write() when "mbm_event mode is disabled", some don't.

The "event_filter" file always prints the MBM transactions monitored when assignable counters are supported, whether mbm_event mode is enabled or not. This means that the MBM event's configuration values are printed when "default" mode is enabled.  I have two concerns about this
1) This is potentially very confusing since switching to "default" will make the BMEC files visible that will enable the user to modify the event configurations per domain. Having this file print a global event configuration while there are potentially various different domain-specific configuration active will be confusing.

Quoted 6 lines
Quoted 1 line

Yes. I agree.

hmmm ... ok, you say that you agree but I cannot tell if you are going to do anything about it.

On a system with BMEC enabled the mbm_total_bytes_config and mbm_local_bytes_config files should be the *only* source of MBM event configuration information, no?

That is correct.

Quoted 6 lines

It may be ok to have event_filter print configuration when assignable counters are disabled if BMEC is not supported but that would require that this information will always be known for a "default" monitoring setup. While this may be true for AMD it is not obvious to me that this is universally true. Once this file exists in this form resctrl will always be required to provide data for the event configuration and it is not clear to me that this can always be guaranteed.

Yea. It is not true universally true. I don't know what these values are for Intel and ARM.

Quoted 18 lines
Quoted 7 lines
Quoted 5 lines

2) Can it be guaranteed that the MBM events will monitor the default assignable counter memory transactions when in "default" mode? It has never been possible to query which memory transactions are monitored by the default X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQM_MBM_LOCAL features so this seems to use one feature to deduce capabilities or another?

So, initialize both total and local event configuration to default values when switched to "default mode"?

Quoted 7 lines

Something like this?

mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = r->mon.mbm_cfg_mask;

mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM;

We are already doing that right (in patch 32)?

Yes, but it creates this strange dependency where the "default" monitoring mode (that has been supported long before configurable events and assignable counters came along) requires support of "assignable counter mode".

Quoted 5 lines

Consider it from another view, if resctrl wants to make event configuration available for the "default" mode then the "event_filter" file could always be visible when MBM local/total is supported to give users insight into what is monitored, whether assignable counters are supported or not. This is not possible on systems that do not support ABMC though, right?

That is correct. With BMEC, each domain can have its own settings.  So, printing the default will not be accurate.

What options do we have here.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

How about adding the check if (resctrl_arch_mbm_cntr_assign_enabled())?  Only print the values when ABMC is supported else print information in "last_cmd_status".

Did you perhaps intend to write "Only print the values when ABMC is *enabled* else print information in "last_cmd_status".? If this is what you actually meant then I agree. I think doing so places clear boundary on this feature that gives us more options/flexibility for future changes.

Yes. That is what I meant.  We have same check in event_filer_write(). Will add the same check in event_filter_show().

Thank you. This makes this specific behavior consistent and addresses the topic that started this thread:
> There is inconsistency among the files introduced on how
> "mbm_event mode disabled" case is handled."
Could you please check the final work to confirm that the new resctrl files are consistent in handling of "mbm_event mode supported" and "mbm_event mode" enabled vs disabled cases? For example, they consider same scenarios as valid/invalid and return same error code in invalid cases.

Reinette

author reviewer
#60 lore raw

PATCH v16 26/34 fs/resctrl: Provide interface to update the event configurations

In reply to Babu Moger

When "mbm_event" counter assignment mode is supported, users can modify the event configuration by writing to the 'event_filter' resctrl file. The event configurations for mbm_event mode are located in /sys/fs/resctrl/info/L3_MON/event_configs/.

Update the assignments of all CTRL_MON and MON resource groups when the event configuration is modified.

Example:

$ mount -t resctrl resctrl /sys/fs/resctrl
$ cd /sys/fs/resctrl/
$ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter
  local_reads,local_non_temporal_writes,local_reads_slow_memory
$ echo "local_reads,local_non_temporal_writes" >
  info/L3_MON/event_configs/mbm_total_bytes/event_filter
$ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter
  local_reads,local_non_temporal_writes

---
v16: Moved resctrl_process_configs() and event_filter_write()
to fs/resctrl/monitor.c.
Renamed resctrl_process_configs() -> resctrl_parse_mem_transactions(). Few minor code commnet update.

v15: Updated changelog.
Updated spacing in resctrl.rst.
Corrected the name counter_configs -> event_configs.
Changed the name rdtgroup_assign_cntr() > rdtgroup_update_cntr_event(). Removed the code to check d->cntr_cfg[cntr_id].evt_cfg.
Fixed the partial initialization of val in resctrl_process_configs(). Passed mon_evt where applicable. The struct rdt_resource can be obtained from mon_evt::rid.

v14: Passed struct mon_evt where applicable instead of just the event type.
Fixed few text corrections about memory trasaction type. Renamed few functions resctrl_group_assign() -> rdtgroup_assign_cntr() resctrl_update_assign() -> resctrl_assign_cntr_allrdtgrp() Removed few extra bases.

v13: Updated changelog for imperative mode.
Added function description in the prototype.
Updated the user doc resctrl.rst to address few feedback.
Resolved conflicts caused by the recent FS/ARCH code restructure.
The rdtgroup.c/monitor.c file has now been split between the FS and ARCH directories.

v12: New patch to modify event configurations.

---
 Documentation/filesystems/resctrl.rst |  12 +++
 fs/resctrl/internal.h                 |   4 +
 fs/resctrl/monitor.c                  | 114 ++++++++++++++++++++++++++
 fs/resctrl/rdtgroup.c                 |   3 +-
 4 files changed, 132 insertions(+), 1 deletion(-)
Documentation/filesystems/resctrl.rst +12 -0
index 3dfc177f9792..37dbad4d50f7 100644
@@ -342,6 +342,18 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
 	  local_reads,local_non_temporal_writes,local_reads_slow_memory
 
+	Modify the event configuration by writing to the "event_filter" file within
+	the "event_configs" directory. The read/write "event_filter" file contains the
+	configuration of the event that reflects which memory transactions are counted by it.
+
+	For example::
+
+	  # echo "local_reads, local_non_temporal_writes" >
+	    /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+
+	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+	   local_reads,local_non_temporal_writes
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/internal.h +4 -0
index e082d8718199..e2e3fc0c5fab 100644
@@ -409,11 +409,15 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
 				  struct mon_evt *mevt);
 int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
 		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
+void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt);
 
 void *rdt_kn_parent_priv(struct kernfs_node *kn);
 
 int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v);
 
+ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
+			   loff_t off);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +114 -0

123 lines not on this page · raw message

fs/resctrl/rdtgroup.c +2 -1
index 11fc8e362ead..c3d6540c3280 100644
@@ -2021,9 +2021,10 @@ static struct rftype res_common_files[] = {
 	},
 	{
 		.name		= "event_filter",
-		.mode		= 0444,
+		.mode		= 0644,
 		.kf_ops		= &rdtgroup_kf_single_ops,
 		.seq_show	= event_filter_show,
+		.write		= event_filter_write,
 	},
 	{
 		.name		= "mbm_assign_mode",
Signature · 1 line
2.34.1
maintainer
#61 lore raw

Re: [PATCH v16 26/34] fs/resctrl: Provide interface to update the event configurations

Hi Babu,

Quoted 1 line · Babu Moger

When "mbm_event" counter assignment mode is supported, users can modify

"supported" -> "enabled"?

Quoted 23 lines

the event configuration by writing to the 'event_filter' resctrl file. The event configurations for mbm_event mode are located in /sys/fs/resctrl/info/L3_MON/event_configs/.

Update the assignments of all CTRL_MON and MON resource groups when the event configuration is modified.

Example:

$ mount -t resctrl resctrl /sys/fs/resctrl
$ cd /sys/fs/resctrl/
$ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter
  local_reads,local_non_temporal_writes,local_reads_slow_memory
$ echo "local_reads,local_non_temporal_writes" >
  info/L3_MON/event_configs/mbm_total_bytes/event_filter
$ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter
  local_reads,local_non_temporal_writes

---

...

Quoted 7 lines
---
 Documentation/filesystems/resctrl.rst |  12 +++
 fs/resctrl/internal.h                 |   4 +
 fs/resctrl/monitor.c                  | 114 ++++++++++++++++++++++++++
 fs/resctrl/rdtgroup.c                 |   3 +-
 4 files changed, 132 insertions(+), 1 deletion(-)

...

fs/resctrl/internal.h void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt · line 412

Quoted 9 lines
fs/resctrl/internal.h +1 -0
index e082d8718199..e2e3fc0c5fab 100644
@@ -409,11 +409,15 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
 				  struct mon_evt *mevt);
 int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
 		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
+void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt);

Is there some code ordering issue in monitor.c? Looks like this function is only used in monitor.c so seeing it here is unexpected.

Quoted 15 lines
fs/resctrl/internal.h +3 -0
 void *rdt_kn_parent_priv(struct kernfs_node *kn);
 
 int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v);
 
+ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
+			   loff_t off);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +0 -0
index fa5f63126682..8efbeb910f77 100644

...

Quoted 13 lines
fs/resctrl/monitor.c +9 -0
@@ -1193,3 +1264,46 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
 		rdtgroup_free_unassign_cntr(r, d, rdtgrp, mevt);
 	}
 }
+
+/*
+ * rdtgroup_update_cntr_event - Update the counter assignments for the event
+ *				in a group.
+ * @r:		Resource to which update needs to be done.
+ * @rdtgrp:	Resctrl group.
+ * @evtid:	MBM monitor event.
+ */
+static void rdtgroup_update_cntr_event(struct rdt_resource *r, struct rdtgroup *rdtgrp,

fs/resctrl/monitor.c void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt · line 1285

Quoted 10 lines
fs/resctrl/monitor.c +10 -0
+				       enum resctrl_event_id evtid)
+{
+	struct rdt_mon_domain *d;
+	int cntr_id;
+
+	list_for_each_entry(d, &r->mon_domains, hdr.list) {
+		cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid);
+		if (cntr_id >= 0)
+			resctrl_arch_config_cntr(r, d, evtid, rdtgrp->mon.rmid,
+						 rdtgrp->closid, cntr_id, true);

Should non-arch MBM state be reset here?

fs/resctrl/monitor.c int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v · line 978

Quoted 3 lines
fs/resctrl/monitor.c +3 -0
+	}
+}
+

Reinette

author reviewer
#62 lore raw

Re: [PATCH v16 26/34] fs/resctrl: Provide interface to update the event configurations

Hi Reinette,

Quoted 5 lines · Reinette Chatre

Hi Babu,

Quoted 1 line · Babu Moger

When "mbm_event" counter assignment mode is supported, users can modify

"supported" -> "enabled"?

Sure.

Quoted 34 lines
Quoted 23 lines

the event configuration by writing to the 'event_filter' resctrl file. The event configurations for mbm_event mode are located in /sys/fs/resctrl/info/L3_MON/event_configs/.

Update the assignments of all CTRL_MON and MON resource groups when the event configuration is modified.

Example:

$ mount -t resctrl resctrl /sys/fs/resctrl
$ cd /sys/fs/resctrl/
$ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter
   local_reads,local_non_temporal_writes,local_reads_slow_memory
$ echo "local_reads,local_non_temporal_writes" >
   info/L3_MON/event_configs/mbm_total_bytes/event_filter
$ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter
   local_reads,local_non_temporal_writes

---

...

Quoted 7 lines
---
  Documentation/filesystems/resctrl.rst |  12 +++
  fs/resctrl/internal.h                 |   4 +
  fs/resctrl/monitor.c                  | 114 ++++++++++++++++++++++++++
  fs/resctrl/rdtgroup.c                 |   3 +-
  4 files changed, 132 insertions(+), 1 deletion(-)

...

Quoted 11 lines

fs/resctrl/internal.h void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt · line 412

Quoted 9 lines
fs/resctrl/internal.h +1 -0
index e082d8718199..e2e3fc0c5fab 100644
@@ -409,11 +409,15 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
  				  struct mon_evt *mevt);
  int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
  		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
+void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt);

Is there some code ordering issue in monitor.c? Looks like this function is only used in monitor.c so seeing it here is unexpected.

Yes. Not required anymore.

Quoted 34 lines
Quoted 16 lines
fs/resctrl/internal.h +3 -0
  void *rdt_kn_parent_priv(struct kernfs_node *kn);
 
  int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v);
 
+ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
+			   loff_t off);
+
  #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
  int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +0 -0
index fa5f63126682..8efbeb910f77 100644

...

Quoted 16 lines
fs/resctrl/monitor.c +12 -0
@@ -1193,3 +1264,46 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
  		rdtgroup_free_unassign_cntr(r, d, rdtgrp, mevt);
  	}
  }
+
+/*
+ * rdtgroup_update_cntr_event - Update the counter assignments for the event
+ *				in a group.
+ * @r:		Resource to which update needs to be done.
+ * @rdtgrp:	Resctrl group.
+ * @evtid:	MBM monitor event.
+ */
+static void rdtgroup_update_cntr_event(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+				       enum resctrl_event_id evtid)
+{
+	struct rdt_mon_domain *d;
Quoted 8 lines

fs/resctrl/monitor.c void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt · line 1285

Quoted 7 lines
fs/resctrl/monitor.c +7 -0
+	int cntr_id;
+
+	list_for_each_entry(d, &r->mon_domains, hdr.list) {
+		cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid);
+		if (cntr_id >= 0)
+			resctrl_arch_config_cntr(r, d, evtid, rdtgrp->mon.rmid,
+						 rdtgrp->closid, cntr_id, true);

Should non-arch MBM state be reset here?

Yes. Added it now.

Thanks

Babu

author reviewer
#63 lore raw

PATCH v16 27/34 fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on mkdir

In reply to Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.

Introduce a user-configurable option that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir.

---
v16: Fixed the return in resctrl_mbm_assign_on_mkdir_write().

v15: Fixed the static checker warning in resctrl_mbm_assign_on_mkdir_write() reported in

     https://lore.kernel.org/lkml/[email protected]/

v14: Added rdtgroup_mutex in resctrl_mbm_assign_on_mkdir_show().
Updated resctrl.rst for clarity.
Fixed squashing of few previous changes.
Added more code documentation.

v13: Added Suggested-by tag.
Resolved conflicts caused by the recent FS/ARCH code restructure.
The rdtgroup.c/monitor.c file has now been split between the FS and ARCH directories.

v12: New patch. Added after the discussion on the list.
https://lore.kernel.org/lkml/CALPaoCh8siZKjL_3yvOYGL4cF_n_38KpUFgHVGbQ86nD+Q2_SA@mail.gmail.com/

---
 Documentation/filesystems/resctrl.rst | 16 ++++++++++
 fs/resctrl/monitor.c                  |  2 ++
 fs/resctrl/rdtgroup.c                 | 43 +++++++++++++++++++++++++++
 include/linux/resctrl.h               |  3 ++
 4 files changed, 64 insertions(+)
Documentation/filesystems/resctrl.rst +16 -0
index 37dbad4d50f7..165e0d315af7 100644
@@ -354,6 +354,22 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
 	   local_reads,local_non_temporal_writes
 
+"mbm_assign_on_mkdir":
+	Determines if a counter will automatically be assigned to an RMID, event pair
+	when its associated monitor group is created via mkdir. It is enabled by default
+	on boot and users can disable by writing to the interface.
+
+	"0":
+		Auto assignment is disabled.
+	"1":
+		Auto assignment is enabled.
+
+	Example::
+
+	  # echo 0 > /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
+	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
+	  0
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 8efbeb910f77..6205bbfe08fb 100644
@@ -1077,6 +1077,8 @@ int resctrl_mon_resource_init(void)
 		resctrl_file_fflags_init("available_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
+		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
+					 RFTYPE_RES_CACHE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +43 -0

55 lines not on this page · raw message

include/linux/resctrl.h +3 -0
index 4d37827121a6..632b9ee5466a 100644
@@ -277,12 +277,15 @@ enum resctrl_schema_fmt {
  *			monitoring events can be configured.
  * @num_mbm_cntrs:	Number of assignable counters.
  * @mbm_cntr_assignable:Is system capable of supporting counter assignment?
+ * @mbm_assign_on_mkdir:True if counters should automatically be assigned to MBM
+ *			events of monitor groups created via mkdir.
  */
 struct resctrl_mon {
 	int			num_rmid;
 	unsigned int		mbm_cfg_mask;
 	int			num_mbm_cntrs;
 	bool			mbm_cntr_assignable;
+	bool			mbm_assign_on_mkdir;
 };
 
 /**
Signature · 1 line
2.34.1
maintainer
#64 lore raw

Re: [PATCH v16 27/34] fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on mkdir

Hi Babu,

Quoted 3 lines · Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.

Above implies this addition is in support of "mbm_event" mode while the implementation applies to any and all assignable counter modes, including the "default" and for example the upcoming "soft-ABMC". It is clear to me how this is used and interpreted when "mbm_event" mode is enabled, but not for the others (more below).

Quoted 8 lines

Introduce a user-configurable option that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir.

---

...

Quoted 12 lines
---
 Documentation/filesystems/resctrl.rst | 16 ++++++++++
 fs/resctrl/monitor.c                  |  2 ++
 fs/resctrl/rdtgroup.c                 | 43 +++++++++++++++++++++++++++
 include/linux/resctrl.h               |  3 ++
 4 files changed, 64 insertions(+)
Documentation/filesystems/resctrl.rst +0 -0
index 37dbad4d50f7..165e0d315af7 100644

Documentation/filesystems/resctrl.rst with the following files: · line 357

Quoted 4 lines
Documentation/filesystems/resctrl.rst +1 -0
@@ -354,6 +354,22 @@ with the following files:
 	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
 	   local_reads,local_non_temporal_writes
 
+"mbm_assign_on_mkdir":

Needs a "Exists when "mbm_event" counter assignment mode is supported."? Also needs clarification on on behavior when "mbm_event" is enabled vs. disabled.

Documentation/filesystems/resctrl.rst with the following files: · line 358

Quoted 1 line
Documentation/filesystems/resctrl.rst +1 -0
+	Determines if a counter will automatically be assigned to an RMID, event pair

"will automatically be" -> "is automatically"
"RMID, event" -> "RMID, MBM event"

Documentation/filesystems/resctrl.rst with the following files: · line 360

Quoted 2 lines
Documentation/filesystems/resctrl.rst +2 -0
+	when its associated monitor group is created via mkdir. It is enabled by default
+	on boot and users can disable by writing to the interface.

"users can disable" -> "users can disable this capability" or "can be disabled"?

This implementation enables user to read/write this file/property when "mbm_event" mode is disabled. Considering this explanation I do not think it is clear how this file reflects system behavior when in "default" mode. There is no difference between mbm_assign_on_mkdir enabled/disabled when in "default" mode, no?
Should interactions with "mbm_assign_on_mkdir" be restricted to when "mbm_event" mode is enabled? If so, the next question would likely be whether value should change during "mbm_event" enable->disable or "disable->enable". Above states clearly that it is enabled on boot and it may be reasonable to have it keep (but not always expose) user's setting when switching between modes.

Restricting it to "mbm_event" mode now gives us some flexibility when soft-ABMC follows on if/how it can/should support this. What do you think?

fs/resctrl/rdtgroup.c

Quoted 32 lines
Documentation/filesystems/resctrl.rst +12 -0
+
+	"0":
+		Auto assignment is disabled.
+	"1":
+		Auto assignment is enabled.
+
+	Example::
+
+	  # echo 0 > /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
+	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
+	  0
+
 "max_threshold_occupancy":
 		Read/write file provides the largest value (in
 		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 8efbeb910f77..6205bbfe08fb 100644
@@ -1077,6 +1077,8 @@ int resctrl_mon_resource_init(void)
 		resctrl_file_fflags_init("available_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
+		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
+					 RFTYPE_RES_CACHE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +0 -0
index c3d6540c3280..bf04235d2603 100644

Please move resctrl_mbm_assign_on_mkdir_show() and resctrl_mbm_assign_on_mkdir_write() to monitor.c

Reinette

author reviewer
#65 lore raw

Re: [PATCH v16 27/34] fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on mkdir

Hi Reinette,

Quoted 36 lines · Reinette Chatre

Hi Babu,

Quoted 3 lines · Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.

Above implies this addition is in support of "mbm_event" mode while the implementation applies to any and all assignable counter modes, including the "default" and for example the upcoming "soft-ABMC". It is clear to me how this is used and interpreted when "mbm_event" mode is enabled, but not for the others (more below).

Quoted 7 lines

Introduce a user-configurable option that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir.

---

...

Quoted 15 lines
---
  Documentation/filesystems/resctrl.rst | 16 ++++++++++
  fs/resctrl/monitor.c                  |  2 ++
  fs/resctrl/rdtgroup.c                 | 43 +++++++++++++++++++++++++++
  include/linux/resctrl.h               |  3 ++
  4 files changed, 64 insertions(+)
Documentation/filesystems/resctrl.rst +0 -0
index 37dbad4d50f7..165e0d315af7 100644
@@ -354,6 +354,22 @@ with the following files:
  	  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
  	   local_reads,local_non_temporal_writes
 
Quoted 3 lines

Documentation/filesystems/resctrl.rst with the following files: · line 357

Quoted 1 line
Documentation/filesystems/resctrl.rst +1 -0
+"mbm_assign_on_mkdir":

Needs a "Exists when "mbm_event" counter assignment mode is supported."? Also needs clarification on on behavior when "mbm_event" is enabled vs. disabled.

I think we should allow it to modify  only when "mbm_event" is enabled.

Quoted 4 lines

Documentation/filesystems/resctrl.rst with the following files: · line 358

Quoted 2 lines
Documentation/filesystems/resctrl.rst +1 -0
+	Determines if a counter will automatically be assigned to an RMID, event pair

"will automatically be" -> "is automatically"
"RMID, event" -> "RMID, MBM event"

Sure.

Quoted 3 lines

Documentation/filesystems/resctrl.rst with the following files: · line 360

Quoted 2 lines
Documentation/filesystems/resctrl.rst +2 -0
+	when its associated monitor group is created via mkdir. It is enabled by default
+	on boot and users can disable by writing to the interface.

"users can disable" -> "users can disable this capability" or "can be disabled"?

Sure.

Quoted 5 lines

This implementation enables user to read/write this file/property when "mbm_event" mode is disabled. Considering this explanation I do not think it is clear how this file reflects system behavior when in "default" mode. There is no difference between mbm_assign_on_mkdir enabled/disabled when in "default" mode, no?

Yes. So, we should only allow modifications only when mbm_event mode is enabled.

Quoted 2 lines

Should interactions with "mbm_assign_on_mkdir" be restricted to when "mbm_event" mode is enabled? If so, the next question would likely be whether value

Yes.

Quoted 6 lines

should change during "mbm_event" enable->disable or "disable->enable". Above states clearly that it is enabled on boot and it may be reasonable to have it keep (but not always expose) user's setting when switching between modes.

Restricting it to "mbm_event" mode now gives us some flexibility when soft-ABMC follows on if/how it can/should support this. What do you think?

Yes. We should restrict it to modify only when mbm_event mode is enabled.

And always enable it when switching from

"mbm_event" disable -> enable: r->mon.mbm_assign_on_mkdir = true;

"mbm_event" enable -> enable: "no need to modify as the value does not affect the behavior."

Quoted 28 lines
Quoted 28 lines
Documentation/filesystems/resctrl.rst +12 -0
+
+	"0":
+		Auto assignment is disabled.
+	"1":
+		Auto assignment is enabled.
+
+	Example::
+
+	  # echo 0 > /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
+	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir
+	  0
+
  "max_threshold_occupancy":
  		Read/write file provides the largest value (in
  		bytes) at which a previously used LLC_occupancy
fs/resctrl/monitor.c +2 -0
index 8efbeb910f77..6205bbfe08fb 100644
@@ -1077,6 +1077,8 @@ int resctrl_mon_resource_init(void)
  		resctrl_file_fflags_init("available_mbm_cntrs",
  					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
  		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
+		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
+					 RFTYPE_RES_CACHE);
  	}
 
Quoted 6 lines

fs/resctrl/rdtgroup.c

Quoted 5 lines
fs/resctrl/monitor.c +0 -0
  	return 0;
fs/resctrl/rdtgroup.c +0 -0
index c3d6540c3280..bf04235d2603 100644

Please move resctrl_mbm_assign_on_mkdir_show() and resctrl_mbm_assign_on_mkdir_write() to monitor.c

Sure.

Thanks

Babu

maintainer
#66 lore raw

Re: [PATCH v16 27/34] fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on mkdir

Hi Babu,

Quoted 60 lines · Babu

Hi Reinette,

Quoted 28 lines · Reinette Chatre

Hi Babu,

Quoted 3 lines · Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.

Above implies this addition is in support of "mbm_event" mode while the implementation applies to any and all assignable counter modes, including the "default" and for example the upcoming "soft-ABMC". It is clear to me how this is used and interpreted when "mbm_event" mode is enabled, but not for the others (more below).

Quoted 7 lines

Introduce a user-configurable option that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir.

---

...

Quoted 7 lines

---
  Documentation/filesystems/resctrl.rst | 16 ++++++++++ fs/resctrl/monitor.c                  |  2 ++ fs/resctrl/rdtgroup.c                 | 43 +++++++++++++++++++++++++++ include/linux/resctrl.h               |  3 ++

  4 files changed, 64 insertions(+)
Quoted 10 lines
Quoted 8 lines
Documentation/filesystems/resctrl.rst +0 -0
index 37dbad4d50f7..165e0d315af7 100644
@@ -354,6 +354,22 @@ with the following files:
         # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter

         local_reads,local_non_temporal_writes
  +"mbm_assign_on_mkdir":

Needs a "Exists when "mbm_event" counter assignment mode is supported."? Also needs clarification on on behavior when "mbm_event" is enabled vs. disabled.

I think we should allow it to modify  only when "mbm_event" is enabled.

Quoted 4 lines
Quoted 2 lines

+    Determines if a counter will automatically be assigned to an RMID, event pair

"will automatically be" -> "is automatically"
"RMID, event" -> "RMID, MBM event"

Sure.

Quoted 3 lines
Quoted 2 lines

+    when its associated monitor group is created via mkdir. It is enabled by default +    on boot and users can disable by writing to the interface.

"users can disable" -> "users can disable this capability" or "can be disabled"?

Sure.

Quoted 5 lines

This implementation enables user to read/write this file/property when "mbm_event" mode is disabled. Considering this explanation I do not think it is clear how this file reflects system behavior when in "default" mode. There is no difference between mbm_assign_on_mkdir enabled/disabled when in "default" mode, no?

Yes. So, we should only allow modifications only when mbm_event mode is enabled.

Quoted 2 lines

Should interactions with "mbm_assign_on_mkdir" be restricted to when "mbm_event" mode is enabled? If so, the next question would likely be whether value

Yes.

Quoted 8 lines
Quoted 6 lines

should change during "mbm_event" enable->disable or "disable->enable". Above states clearly that it is enabled on boot and it may be reasonable to have it keep (but not always expose) user's setting when switching between modes.

Restricting it to "mbm_event" mode now gives us some flexibility when soft-ABMC follows on if/how it can/should support this. What do you think?

Yes. We should restrict it to modify only when mbm_event mode is enabled.

I agree. I also think it should not be displayed with mbm_event mode is disabled. This is because it indicates to user space that counters are automatically assigned to RMID, event pairs and since "default" mode depends on hardware doing this it may not be accurate when, for example, ABMC is disabled. Alternative is to add a third value, for example "enabled", "disabled", and "undefined"(?). This sounds a bit awkward though so I think simplest may be to have this file also be consistent with the others and return error when mbm_event mode is disabled.

Quoted 7 lines

And always enable it when switching from

"mbm_event" disable -> enable:  r->mon.mbm_assign_on_mkdir = true;

"mbm_event" enable -> enable: "no need to modify as the value does not affect the behavior."

ok, please note this may need an update to the doc that currently only states "enabled by default on boot" to indicate it is also automatically enabled when enabling mbm_event mode.

Reinette

author reviewer
#67 lore raw

Re: [PATCH v16 27/34] fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on mkdir

Hi Reinette.

Quoted 67 lines · Reinette Chatre

Hi Babu,

Quoted 64 lines · Babu

Hi Reinette,

Quoted 28 lines · Reinette Chatre

Hi Babu,

Quoted 3 lines · Babu Moger

The "mbm_event" counter assignment mode allows users to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.

Above implies this addition is in support of "mbm_event" mode while the implementation applies to any and all assignable counter modes, including the "default" and for example the upcoming "soft-ABMC". It is clear to me how this is used and interpreted when "mbm_event" mode is enabled, but not for the others (more below).

Quoted 7 lines

Introduce a user-configurable option that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir.

---

...

Quoted 7 lines
---
   Documentation/filesystems/resctrl.rst | 16 ++++++++++
   fs/resctrl/monitor.c                  |  2 ++
   fs/resctrl/rdtgroup.c                 | 43 +++++++++++++++++++++++++++
   include/linux/resctrl.h               |  3 ++
   4 files changed, 64 insertions(+)
Quoted 10 lines

Documentation/filesystems/resctrl.rst with the following files: · line 356

Quoted 8 lines
Documentation/filesystems/resctrl.rst +0 -0
index 37dbad4d50f7..165e0d315af7 100644
@@ -354,6 +354,22 @@ with the following files:
         # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
          local_reads,local_non_temporal_writes
   +"mbm_assign_on_mkdir":

Needs a "Exists when "mbm_event" counter assignment mode is supported."? Also needs clarification on on behavior when "mbm_event" is enabled vs. disabled.

I think we should allow it to modify  only when "mbm_event" is enabled.

Quoted 3 lines

Documentation/filesystems/resctrl.rst with the following files: · line 358

Quoted 1 line
Documentation/filesystems/resctrl.rst +1 -0
+    Determines if a counter will automatically be assigned to an RMID, event pair

"will automatically be" -> "is automatically"
"RMID, event" -> "RMID, MBM event"

Sure.

Quoted 3 lines

Documentation/filesystems/resctrl.rst with the following files: · line 360

Quoted 2 lines
Documentation/filesystems/resctrl.rst +2 -0
+    when its associated monitor group is created via mkdir. It is enabled by default
+    on boot and users can disable by writing to the interface.

"users can disable" -> "users can disable this capability" or "can be disabled"?

Sure.

Quoted 4 lines

This implementation enables user to read/write this file/property when "mbm_event" mode is disabled. Considering this explanation I do not think it is clear how this file reflects system behavior when in "default" mode. There is no difference between mbm_assign_on_mkdir enabled/disabled when in "default" mode, no?

Yes. So, we should only allow modifications only when mbm_event mode is enabled.

Quoted 2 lines

Should interactions with "mbm_assign_on_mkdir" be restricted to when "mbm_event" mode is enabled? If so, the next question would likely be whether value

Yes.

Quoted 6 lines

should change during "mbm_event" enable->disable or "disable->enable". Above states clearly that it is enabled on boot and it may be reasonable to have it keep (but not always expose) user's setting when switching between modes.

Restricting it to "mbm_event" mode now gives us some flexibility when soft-ABMC follows on if/how it can/should support this. What do you think?

Quoted 7 lines
Quoted 1 line

Yes. We should restrict it to modify only when mbm_event mode is enabled.

I agree. I also think it should not be displayed with mbm_event mode is disabled. This is because it indicates to user space that counters are automatically assigned to RMID, event pairs and since "default" mode depends on hardware doing this it may not be accurate when, for example, ABMC is disabled. Alternative is to add a third value, for example "enabled", "disabled", and "undefined"(?). This sounds a bit awkward though so I think simplest may be to have this file also be consistent with the others and return error when mbm_event mode is disabled.

Yes. We can do that.

Quoted 9 lines
Quoted 7 lines

And always enable it when switching from

"mbm_event" disable -> enable:  r->mon.mbm_assign_on_mkdir = true;

"mbm_event" enable -> enable: "no need to modify as the value does not affect the behavior."

ok, please note this may need an update to the doc that currently only states "enabled by default on boot" to indicate it is also automatically enabled when enabling mbm_event mode.

Will add texts about it.

Thanks

Babu

author reviewer
#68 lore raw

PATCH v16 28/34 fs/resctrl: Auto assign counters on mkdir and clean up on group removal

In reply to Babu Moger

Resctrl provides a user-configurable option mbm_assign_on_mkdir that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir.

Enable mbm_assign_on_mkdir by default to automatically assign counters to the two default events (MBM total and MBM local) of a new monitoring group created via mkdir. This maintains backward compatibility with original resctrl support for these two events.

Unassign and free counters belonging to a monitoring group when the group is deleted.

Monitor group creation does not fail if a counter cannot be assigned to one or both events. There may be limited counters and users have the flexibility to modify counter assignments at a later time. Log the error message "Failed to allocate counter for <event> in domain <id>" in /sys/fs/resctrl/info/last_cmd_status when a new monitoring group is created but counter assignment failed.

---
v16: Updated the changelog. Thanks to Reinette.
Moved r->mon.mbm_assign_on_mkdir initialization to resctrl_mon_resource_init(). Minor code comment update.
Updated the Subject line to fs/resctrl:

v15: Updated the subject line.
Updated changelog to add unassign part.
Fixed the check in rdtgroup_assign_cntrs() to call assign correctly. Renamed resctrl_assign_cntr_event() -> rdtgroup_assign_cntr_event()
resctrl_unassign_cntr_event() -> rdtgroup_unassign_cntr_event().

v14: Updated the changelog with changed name mbm_event.
Update code comments with changed name mbm_event. Changed the code to reflect Tony's struct mon_evt changes.

v13: Changes due to calling of resctrl_assign_cntr_event() and resctrl_unassign_cntr_event().
It only takes evtid. evt_cfg is not required anymore.
Resolved conflicts caused by the recent FS/ARCH code restructure.
The monitor.c/rdtgroup.c files have been split between the FS and ARCH directories.

v12: Removed mbm_cntr_reset() as it is not required while removing the group.
Update the commit text.
Added r->mon_capable check in rdtgroup_assign_cntrs() and rdtgroup_unassign_cntrs.

v11: Moved mbm_cntr_reset() to monitor.c.
Added code reset non-architectural state in mbm_cntr_reset(). Added missing rdtgroup_unassign_cntrs() calls on failure path.

v10: Assigned the counter before exposing the event files.
Moved the call rdtgroup_assign_cntrs() inside mkdir_rdt_prepare_rmid_alloc(). This is called both CNTR_MON and MON group creation.
Call mbm_cntr_reset() when unmounted to clear all the assignments. Taken care of few other feedback comments.

v9: Changed rdtgroup_assign_cntrs() and rdtgroup_unassign_cntrs() to return void.
Updated couple of rdtgroup_unassign_cntrs() calls properly. Updated function comments.

v8: Renamed rdtgroup_assign_grp to rdtgroup_assign_cntrs.
Renamed rdtgroup_unassign_grp to rdtgroup_unassign_cntrs. Fixed the problem with unassigning the child MON groups of CTRL_MON group.

v7: Reworded the commit message.
Removed the reference of ABMC with mbm_cntr_assign. Renamed the function rdtgroup_assign_cntrs to rdtgroup_assign_grp.

v6: Removed the redundant comments on all the calls of
rdtgroup_assign_cntrs. Updated the commit message.
Dropped printing error message on every call of rdtgroup_assign_cntrs.

v5: Removed the code to enable/disable ABMC during the mount.
That will be another patch.
Added arch callers to get the arch specific data. Renamed fuctions to match the other abmc function. Added code comments for assignment failures.

v4: Few name changes based on the upstream discussion.
Commit message update.

v3: This is a new patch. Patch addresses the upstream comment to enable
ABMC feature by default if the feature is available.

---
 fs/resctrl/monitor.c  |  1 +
 fs/resctrl/rdtgroup.c | 70 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 2 deletions(-)
fs/resctrl/monitor.c +1 -0
index 6205bbfe08fb..5cf1b79c17f5 100644
@@ -1072,6 +1072,7 @@ int resctrl_mon_resource_init(void)
 		mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
 								   READS_TO_LOCAL_S_MEM |
 								   NON_TEMP_WRITE_TO_LOCAL_MEM;
+		r->mon.mbm_assign_on_mkdir = true;
 		resctrl_file_fflags_init("num_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("available_mbm_cntrs",
fs/resctrl/rdtgroup.c +68 -2

135 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#69 lore raw

Re: [PATCH v16 28/34] fs/resctrl: Auto assign counters on mkdir and clean up on group removal

Hi Babu,

fs/resctrl/rdtgroup.c

Quoted 21 lines · Babu Moger
---
 fs/resctrl/monitor.c  |  1 +
 fs/resctrl/rdtgroup.c | 70 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 2 deletions(-)
fs/resctrl/monitor.c +1 -0
index 6205bbfe08fb..5cf1b79c17f5 100644
@@ -1072,6 +1072,7 @@ int resctrl_mon_resource_init(void)
 		mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
 								   READS_TO_LOCAL_S_MEM |
 								   NON_TEMP_WRITE_TO_LOCAL_MEM;
+		r->mon.mbm_assign_on_mkdir = true;
 		resctrl_file_fflags_init("num_mbm_cntrs",
 					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("available_mbm_cntrs",
fs/resctrl/rdtgroup.c +0 -0
index bf04235d2603..d087ba990cd3 100644

Please move rdtgroup_assign_cntrs() and rdtgroup_unassign_cntrs() to be with counter management code in monitor.c

Reinette

author reviewer
#70 lore raw

Re: [PATCH v16 28/34] fs/resctrl: Auto assign counters on mkdir and clean up on group removal

Hi Reinette,

Quoted 19 lines · Reinette Chatre

Hi Babu,

Quoted 15 lines · Babu Moger
---
  fs/resctrl/monitor.c  |  1 +
  fs/resctrl/rdtgroup.c | 70 +++++++++++++++++++++++++++++++++++++++++--
  2 files changed, 69 insertions(+), 2 deletions(-)
fs/resctrl/monitor.c +1 -0
index 6205bbfe08fb..5cf1b79c17f5 100644
@@ -1072,6 +1072,7 @@ int resctrl_mon_resource_init(void)
  		mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
  								   READS_TO_LOCAL_S_MEM |
  								   NON_TEMP_WRITE_TO_LOCAL_MEM;
+		r->mon.mbm_assign_on_mkdir = true;
  		resctrl_file_fflags_init("num_mbm_cntrs",
Quoted 8 lines

fs/resctrl/rdtgroup.c

Quoted 6 lines
fs/resctrl/monitor.c +0 -0
  					 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
  		resctrl_file_fflags_init("available_mbm_cntrs",
fs/resctrl/rdtgroup.c +0 -0
index bf04235d2603..d087ba990cd3 100644

Please move rdtgroup_assign_cntrs() and rdtgroup_unassign_cntrs() to be with counter management code in monitor.c

Sure.  Taken care of this.

Thanks

Babu

author reviewer
#71 lore raw

PATCH v16 29/34 fs/resctrl: Introduce mbm_L3_assignments to list assignments in a group

In reply to Babu Moger

Introduce the mbm_L3_assignments resctrl file associated with CTRL_MON and MON resource groups to display the counter assignment states of the resource group when "mbm_event" counter assignment mode is enabled.

The list is displayed in the following format:
<Event>:<Domain id>=<Assignment state>;<Domain id>=<Assignment state>

Event: A valid MBM event listed in
/sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID.

The assignment state can be one of the following:

_ : No counter assigned.

e : Counter assigned exclusively.

Example:
To list the assignment states for the default group

$ cd /sys/fs/resctrl
$ cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

---
v16: Fixed minor merge conflicts with code displacement.
Changed the check with mbm_cntr_get() to "< 0" from " >=".

v15: Updated the changelog with Reinette's text.
Updated the event format list to list multiple domains. Changed the goto out_assing to out_unlock.
Updated to use new loop for_each_mon_event() instead of hardcoding.

v14: Added missed rdtgroup_kn_lock_live on failure case.
Updated the user doc resctrl.rst to clarify counter assignments. Updated the changelog.

v13: Changelog update.
Few changes in mbm_L3_assignments_show() after moving the event config to evt_list. Resolved conflicts caused by the recent FS/ARCH code restructure.
The rdtgroup.c/monitor.c files have been split between the FS and ARCH directories.

v12: New patch:
Assignment interface moved inside the group based the discussion
https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=kVLBzhfNo0SFqt4kQGwGSGVUqvr2Dg@mail.gmail.com/#t

---
 Documentation/filesystems/resctrl.rst | 28 ++++++++++++++
 fs/resctrl/monitor.c                  |  1 +
 fs/resctrl/rdtgroup.c                 | 54 +++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
Documentation/filesystems/resctrl.rst +28 -0
index 165e0d315af7..0b8ce942f112 100644
@@ -514,6 +514,34 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
 	/sys/fs/resctrl/info/L3_MON/mon_features changes the input
 	event.
 
+"mbm_L3_assignments":
+	Exists when "mbm_event" counter assignment mode is supported and lists the
+	counter assignment states of the group.
+
+	The assignment list is displayed in the following format:
+
+	<Event>:<Domain ID>=<Assignment state>;<Domain ID>=<Assignment state>
+
+	Event: A valid MBM event in the
+	       /sys/fs/resctrl/info/L3_MON/event_configs directory.
+
+	Domain ID: A valid domain ID.
+
+	Assignment states:
+
+	_ : No counter assigned.
+
+	e : Counter assigned exclusively.
+
+	Example:
+	To display the counter assignment states for the default group.
+	::
+
+	 # cd /sys/fs/resctrl
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=e;1=e
+	   mbm_local_bytes:0=e;1=e
+
 Resource allocation rules
 -------------------------
 
fs/resctrl/monitor.c +1 -0
index 5cf1b79c17f5..ebc049105949 100644
@@ -1080,6 +1080,7 @@ int resctrl_mon_resource_init(void)
 		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
 		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
 					 RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +54 -0

66 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#72 lore raw

Re: [PATCH v16 29/34] fs/resctrl: Introduce mbm_L3_assignments to list assignments in a group

Hi Babu,

Quoted 5 lines · Babu Moger

Introduce the mbm_L3_assignments resctrl file associated with CTRL_MON and MON resource groups to display the counter assignment states of the resource group when "mbm_event" counter assignment mode is enabled.

The list is displayed in the following format:

needs imperative:
"Display the list ..."

Quoted 22 lines

<Event>:<Domain id>=<Assignment state>;<Domain id>=<Assignment state>

Event: A valid MBM event listed in
/sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID.

The assignment state can be one of the following:

_ : No counter assigned.

e : Counter assigned exclusively.

Example:
To list the assignment states for the default group

$ cd /sys/fs/resctrl
$ cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

---

...

Quoted 17 lines
fs/resctrl/monitor.c +1 -0
index 5cf1b79c17f5..ebc049105949 100644
@@ -1080,6 +1080,7 @@ int resctrl_mon_resource_init(void)
 		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
 		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
 					 RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
 	}
 
 	return 0;
fs/resctrl/rdtgroup.c +0 -0
index d087ba990cd3..47716e623a9c 100644

fs/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, · line 1934

Quoted 4 lines
fs/resctrl/rdtgroup.c +1 -0
@@ -1931,6 +1931,54 @@ static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of,
 	return nbytes;
 }
 
+static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file *s, void *v)

Please move to monitor.c (then mbm_cntr_get() can be private to monitor.c also).

Quoted 8 lines
fs/resctrl/rdtgroup.c +8 -0
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+	struct rdt_mon_domain *d;
+	struct rdtgroup *rdtgrp;
+	struct mon_evt *mevt;
+	int ret = 0;
+	bool sep;
+

fs/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, · line 1952

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (!rdtgrp) {
+		ret = -ENOENT;
+		goto out_unlock;
+	}
+
+	rdt_last_cmd_clear();
+	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		rdt_last_cmd_puts("mbm_event mode is not enabled\n");
+		ret = -ENOENT;

The error returned by the files when "mbm_event" is disabled (but supported) is inconsistent. All but this one return EINVAL. Please make return code consistent.

Quoted 22 lines
fs/resctrl/rdtgroup.c +22 -0
+		goto out_unlock;
+	}
+
+	for_each_mon_event(mevt) {
+		if (mevt->rid != r->rid || !mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+			continue;
+
+		sep = false;
+		seq_printf(s, "%s:", mevt->name);
+		list_for_each_entry(d, &r->mon_domains, hdr.list) {
+			if (sep)
+				seq_putc(s, ';');
+
+			if (mbm_cntr_get(r, d, rdtgrp, mevt->evtid) < 0)
+				seq_printf(s, "%d=_", d->hdr.id);
+			else
+				seq_printf(s, "%d=e", d->hdr.id);
+
+			sep = true;
+		}
+		seq_putc(s, '\n');
+	}

fs/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, · line 1984

Quoted 10 lines
fs/resctrl/rdtgroup.c +7 -0
+
+out_unlock:
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
 /* rdtgroup information files for one cache resource. */
 static struct rftype res_common_files[] = {
 	{

Reinette

author reviewer
#73 lore raw

Re: [PATCH v16 29/34] fs/resctrl: Introduce mbm_L3_assignments to list assignments in a group

Hi Reinette,

Quoted 10 lines · Reinette Chatre

Hi Babu,

Quoted 5 lines · Babu Moger

Introduce the mbm_L3_assignments resctrl file associated with CTRL_MON and MON resource groups to display the counter assignment states of the resource group when "mbm_event" counter assignment mode is enabled.

The list is displayed in the following format:

needs imperative:
"Display the list ..."

Sure.

Quoted 46 lines
Quoted 23 lines

<Event>:<Domain id>=<Assignment state>;<Domain id>=<Assignment state>

Event: A valid MBM event listed in
/sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID.

The assignment state can be one of the following:

_ : No counter assigned.

e : Counter assigned exclusively.

Example:
To list the assignment states for the default group

$ cd /sys/fs/resctrl
$ cat /sys/fs/resctrl/mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e

---

...

Quoted 20 lines
fs/resctrl/monitor.c +1 -0
index 5cf1b79c17f5..ebc049105949 100644
@@ -1080,6 +1080,7 @@ int resctrl_mon_resource_init(void)
  		resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG);
  		resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO |
  					 RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE);
  	}
 
  	return 0;
fs/resctrl/rdtgroup.c +0 -0
index d087ba990cd3..47716e623a9c 100644
@@ -1931,6 +1931,54 @@ static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of,
  	return nbytes;
  }
 
Quoted 2 lines

fs/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, · line 1934

Quoted 1 line
fs/resctrl/rdtgroup.c +1 -0
+static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file *s, void *v)

Please move to monitor.c (then mbm_cntr_get() can be private to monitor.c also).

Sure.

Quoted 13 lines
Quoted 13 lines
fs/resctrl/rdtgroup.c +12 -0
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+	struct rdt_mon_domain *d;
+	struct rdtgroup *rdtgrp;
+	struct mon_evt *mevt;
+	int ret = 0;
+	bool sep;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (!rdtgrp) {
+		ret = -ENOENT;
+		goto out_unlock;
Quoted 8 lines

fs/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, · line 1952

Quoted 6 lines
fs/resctrl/rdtgroup.c +6 -0
+	}
+
+	rdt_last_cmd_clear();
+	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		rdt_last_cmd_puts("mbm_event mode is not enabled\n");
+		ret = -ENOENT;

The error returned by the files when "mbm_event" is disabled (but supported) is inconsistent. All but this one return EINVAL. Please make return code consistent.

Yes. Sure.

Quoted 35 lines
Quoted 23 lines
fs/resctrl/rdtgroup.c +22 -0
+		goto out_unlock;
+	}
+
+	for_each_mon_event(mevt) {
+		if (mevt->rid != r->rid || !mevt->enabled || !resctrl_is_mbm_event(mevt->evtid))
+			continue;
+
+		sep = false;
+		seq_printf(s, "%s:", mevt->name);
+		list_for_each_entry(d, &r->mon_domains, hdr.list) {
+			if (sep)
+				seq_putc(s, ';');
+
+			if (mbm_cntr_get(r, d, rdtgrp, mevt->evtid) < 0)
+				seq_printf(s, "%d=_", d->hdr.id);
+			else
+				seq_printf(s, "%d=e", d->hdr.id);
+
+			sep = true;
+		}
+		seq_putc(s, '\n');
+	}

fs/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, · line 1984

Quoted 10 lines
fs/resctrl/rdtgroup.c +7 -0
+
+out_unlock:
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
  /* rdtgroup information files for one cache resource. */
  static struct rftype res_common_files[] = {
  	{

Reinette

author reviewer
#74 lore raw

PATCH v16 30/34 fs/resctrl: Introduce the interface to modify assignments in a group

In reply to Babu Moger

Enable the mbm_l3_assignments resctrl file to be used to modify counter assignments of CTRL_MON and MON groups when the "mbm_event" counter assignment mode is enabled.

The assignment modifications are done in the following format:
<Event>:<Domain id>=<Assignment state>

Event: A valid MBM event in the
/sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID. When writing, '*' applies the changes
to all domains.

Assignment states:

_ : Unassign a counter.

e : Assign a counter exclusively.

Examples:

$ cd /sys/fs/resctrl
$ cat /sys/fs/resctrl/mbm_L3_assignments
  mbm_total_bytes:0=e;1=e
  mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on domain 0:

$ echo "mbm_total_bytes:0=_" > mbm_L3_assignments
$ cat /sys/fs/resctrl/mbm_L3_assignments
  mbm_total_bytes:0=_;1=e
  mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on all the domains:

$ echo "mbm_total_bytes:*=_" > mbm_L3_assignments
$ cat /sys/fs/resctrl/mbm_L3_assignments
  mbm_total_bytes:0=_;1=_
  mbm_local_bytes:0=e;1=e

---
v16: Updated the changelog for minor corrections.
Updated resctrl.rst few corrections and consistancy.
Fixed few references of counter_configs to > event_configs.
Renamed resctrl_process_assign() to resctrl_parse_mbm_assignment(). Moved resctrl_parse_mbm_assignment() and rdtgroup_modify_assign_state() to monitor.c.

v15: Updated the changelog little bit.
Fixed the spacing in event_filter display.
Removed the enum ASSIGN_NONE etc. Not required anymore. Moved mbm_get_mon_event_by_name() to fs/resctrl/monitor.c Used the new macro for_each_mon_event().
Renamed resctrl_get_assign_state() -> rdtgroup_modify_assign_state(). Quite a few changes in resctrl_process_assign().
Removed the found and domain variables.
Called rdtgroup_modify_assign_state() directly where applicable. Removed couple of goto statements.

v14: Fixed the problem reported by Peter.
Updated the changelog.
Updated the user doc resctrl.rst.
Added example section on how to use resctrl with mbm_assign_mode.

v13: Few changes in mbm_L3_assignments_write() after moving the event config to evt_list.
Resolved conflicts caused by the recent FS/ARCH code restructure.

v12: New patch:
Assignment interface moved inside the group based the discussion
https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=kVLBzhfNo0SFqt4kQGwGSGVUqvr2Dg@mail.gmail.com/#t

---
 Documentation/filesystems/resctrl.rst | 146 +++++++++++++++++++++++++-
 fs/resctrl/internal.h                 |   3 +
 fs/resctrl/monitor.c                  |  94 +++++++++++++++++
 fs/resctrl/rdtgroup.c                 |  48 ++++++++-
 4 files changed, 289 insertions(+), 2 deletions(-)
Documentation/filesystems/resctrl.rst +145 -1
index 0b8ce942f112..0c8701103214 100644
@@ -525,7 +525,8 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
 	Event: A valid MBM event in the
 	       /sys/fs/resctrl/info/L3_MON/event_configs directory.
 
-	Domain ID: A valid domain ID.
+	Domain ID: A valid domain ID. When writing, '*' applies the changes
+		   to all the domains.
 
 	Assignment states:
 
@@ -542,6 +543,34 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
 	   mbm_total_bytes:0=e;1=e
 	   mbm_local_bytes:0=e;1=e
 
+	Assignments can be modified by writing to the interface.
+
+	Example:
+	To unassign the counter associated with the mbm_total_bytes event on domain 0:
+	::
+
+	 # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=_;1=e
+	   mbm_local_bytes:0=e;1=e
+
+	To unassign the counter associated with the mbm_total_bytes event on all the domains:
+	::
+
+	 # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=_;1=_
+	   mbm_local_bytes:0=e;1=e
+
+	To assign a counter associated with the mbm_total_bytes event on all domains in
+	exclusive mode:
+	::
+
+	 # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=e;1=e
+	   mbm_local_bytes:0=e;1=e
+
 Resource allocation rules
 -------------------------
 
@@ -1577,6 +1606,121 @@ View the llc occupancy snapshot::
   # cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy
   11234000
 
+
+Examples on working with mbm_assign_mode
+========================================
+
+a. Check if MBM counter assignment mode is supported.
+::
+
+  # mount -t resctrl resctrl /sys/fs/resctrl/
+
+  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  [mbm_event]
+  default
+
+The "mbm_event" mode is detected and enabled.
+
+b. Check how many assignable counters are supported.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
+  0=32;1=32
+
+c. Check how many assignable counters are available for assignment in each domain.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
+  0=30;1=30
+
+d. To list the default group's assign states.
+::
+
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=e;1=e
+  mbm_local_bytes:0=e;1=e
+
+e.  To unassign the counter associated with the mbm_total_bytes event on domain 0.
+::
+
+  # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=_;1=e
+  mbm_local_bytes:0=e;1=e
+
+f. To unassign the counter associated with the mbm_total_bytes event on all domains.
+::
+
+  # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignment
+  mbm_total_bytes:0=_;1=_
+  mbm_local_bytes:0=e;1=e
+
+g. To assign a counter associated with the mbm_total_bytes event on all domains in
+exclusive mode.
+::
+
+  # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=e;1=e
+  mbm_local_bytes:0=e;1=e
+
+h. Read the events mbm_total_bytes and mbm_local_bytes of the default group. There is
+no change in reading the events with the assignment.  If the event is unassigned when
+reading, then the read will come back as "Unassigned".
+::
+
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes
+  779247936
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  765207488
+
+i. Check the event configurations.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+  local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
+  local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+  local_reads,local_non_temporal_writes,local_reads_slow_memory
+
+j. Change the event configuration for mbm_local_bytes.
+::
+
+  # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
+  /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+  local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads
+
+This will update all (across all domains of all monitor groups) counter assignments
+associated with the mbm_local_bytes event.
+
+k. Now read the local event again. The first read may come back with "Unavailable"
+status. The subsequent read of mbm_local_bytes will display the current value.
+::
+
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  Unavailable
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  314101
+
+l. Users have the option to go back to 'default' mbm_assign_mode if required. This can be
+done using the following command. Note that switching the mbm_assign_mode may reset all
+the MBM counters (and thus all MBM events) of all the resctrl groups.
+::
+
+  # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  mbm_event
+  [default]
+
+m. Unmount the resctrl filesystem.
+::
+
+  # umount /sys/fs/resctrl/
+
 Intel RDT Errata
 ================
 
fs/resctrl/internal.h +3 -0
index e2e3fc0c5fab..1350fc273258 100644
@@ -418,6 +418,9 @@ int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v
 ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
 			   loff_t off);
 
+int resctrl_parse_mbm_assignment(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+				 char *event, char *tok);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +94 -0

97 lines not on this page · raw message

fs/resctrl/rdtgroup.c +47 -1

62 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#75 lore raw

Re: [PATCH v16 30/34] fs/resctrl: Introduce the interface to modify assignments in a group

Hi Babu,

Quoted 5 lines · Babu Moger

Enable the mbm_l3_assignments resctrl file to be used to modify counter assignments of CTRL_MON and MON groups when the "mbm_event" counter assignment mode is enabled.

The assignment modifications are done in the following format:

(needs imperative)

Quoted 39 lines

<Event>:<Domain id>=<Assignment state>

Event: A valid MBM event in the
/sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID. When writing, '*' applies the changes
to all domains.

Assignment states:

_ : Unassign a counter.

e : Assign a counter exclusively.

Examples:

$ cd /sys/fs/resctrl
$ cat /sys/fs/resctrl/mbm_L3_assignments
  mbm_total_bytes:0=e;1=e
  mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on domain 0:

$ echo "mbm_total_bytes:0=_" > mbm_L3_assignments
$ cat /sys/fs/resctrl/mbm_L3_assignments
  mbm_total_bytes:0=_;1=e
  mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on all the domains:

$ echo "mbm_total_bytes:*=_" > mbm_L3_assignments
$ cat /sys/fs/resctrl/mbm_L3_assignments
  mbm_total_bytes:0=_;1=_
  mbm_local_bytes:0=e;1=e

---

...

Quoted 22 lines
---
 Documentation/filesystems/resctrl.rst | 146 +++++++++++++++++++++++++-
 fs/resctrl/internal.h                 |   3 +
 fs/resctrl/monitor.c                  |  94 +++++++++++++++++
 fs/resctrl/rdtgroup.c                 |  48 ++++++++-
 4 files changed, 289 insertions(+), 2 deletions(-)
Documentation/filesystems/resctrl.rst +2 -1
index 0b8ce942f112..0c8701103214 100644
@@ -525,7 +525,8 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
 	Event: A valid MBM event in the
 	       /sys/fs/resctrl/info/L3_MON/event_configs directory.
 
-	Domain ID: A valid domain ID.
+	Domain ID: A valid domain ID. When writing, '*' applies the changes
+		   to all the domains.
 
 	Assignment states:
 

Documentation/filesystems/resctrl.rst When the "mba_MBps" mount option is used all CTRL_MON groups will also contain: · line 549

Quoted 7 lines
Documentation/filesystems/resctrl.rst +4 -0
@@ -542,6 +543,34 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
 	   mbm_total_bytes:0=e;1=e
 	   mbm_local_bytes:0=e;1=e
 
+	Assignments can be modified by writing to the interface.
+
+	Example:
+	To unassign the counter associated with the mbm_total_bytes event on domain 0:

The alignment is off when looking at the generated html. What seems to be intended is that "Example" is some sort of heading but it ends up just being part of the sentence that follows and thus not apply to other examples that follow.
It can also be "Examples" since there are more than one.

Quoted 83 lines
Documentation/filesystems/resctrl.rst +76 -0
+	::
+
+	 # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=_;1=e
+	   mbm_local_bytes:0=e;1=e
+
+	To unassign the counter associated with the mbm_total_bytes event on all the domains:
+	::
+
+	 # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=_;1=_
+	   mbm_local_bytes:0=e;1=e
+
+	To assign a counter associated with the mbm_total_bytes event on all domains in
+	exclusive mode:
+	::
+
+	 # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=e;1=e
+	   mbm_local_bytes:0=e;1=e
+
 Resource allocation rules
 -------------------------
 
@@ -1577,6 +1606,121 @@ View the llc occupancy snapshot::
   # cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy
   11234000
 
+
+Examples on working with mbm_assign_mode
+========================================
+
+a. Check if MBM counter assignment mode is supported.
+::
+
+  # mount -t resctrl resctrl /sys/fs/resctrl/
+
+  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  [mbm_event]
+  default
+
+The "mbm_event" mode is detected and enabled.
+
+b. Check how many assignable counters are supported.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
+  0=32;1=32
+
+c. Check how many assignable counters are available for assignment in each domain.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
+  0=30;1=30
+
+d. To list the default group's assign states.
+::
+
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=e;1=e
+  mbm_local_bytes:0=e;1=e
+
+e.  To unassign the counter associated with the mbm_total_bytes event on domain 0.
+::
+
+  # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=_;1=e
+  mbm_local_bytes:0=e;1=e
+
+f. To unassign the counter associated with the mbm_total_bytes event on all domains.
+::
+
+  # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignment
+  mbm_total_bytes:0=_;1=_
+  mbm_local_bytes:0=e;1=e
+
+g. To assign a counter associated with the mbm_total_bytes event on all domains in
+exclusive mode.

Documentation/filesystems/resctrl.rst View the llc occupancy snapshot:: · line 1670

Quoted 10 lines
Documentation/filesystems/resctrl.rst +10 -0
+::
+
+  # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=e;1=e
+  mbm_local_bytes:0=e;1=e
+
+h. Read the events mbm_total_bytes and mbm_local_bytes of the default group. There is
+no change in reading the events with the assignment.  If the event is unassigned when
+reading, then the read will come back as "Unassigned".

While this example is for a single resource group the supporting text goes back and forth between being specific to one resource group and describing what happens when there are multiple resource groups (see (j)). If it is just one resource group then above is fine, but for multiple there are much more involved with the "unassigned". Same as what was mentioned during previous version.

Quoted 123 lines
Documentation/filesystems/resctrl.rst +53 -0
+::
+
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes
+  779247936
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  765207488
+
+i. Check the event configurations.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+  local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
+  local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+  local_reads,local_non_temporal_writes,local_reads_slow_memory
+
+j. Change the event configuration for mbm_local_bytes.
+::
+
+  # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
+  /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+  local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads
+
+This will update all (across all domains of all monitor groups) counter assignments
+associated with the mbm_local_bytes event.
+
+k. Now read the local event again. The first read may come back with "Unavailable"
+status. The subsequent read of mbm_local_bytes will display the current value.
+::
+
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  Unavailable
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  314101
+
+l. Users have the option to go back to 'default' mbm_assign_mode if required. This can be
+done using the following command. Note that switching the mbm_assign_mode may reset all
+the MBM counters (and thus all MBM events) of all the resctrl groups.
+::
+
+  # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  mbm_event
+  [default]
+
+m. Unmount the resctrl filesystem.
+::
+
+  # umount /sys/fs/resctrl/
+
 Intel RDT Errata
 ================
 
fs/resctrl/internal.h +3 -0
index e2e3fc0c5fab..1350fc273258 100644
@@ -418,6 +418,9 @@ int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v
 ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
 			   loff_t off);
 
+int resctrl_parse_mbm_assignment(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+				 char *event, char *tok);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +45 -0
index ebc049105949..1e4f8e3bedc6 100644
@@ -1311,3 +1311,97 @@ void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt)
 			rdtgroup_update_cntr_event(r, crgrp, mevt->evtid);
 	}
 }
+
+/*
+ * mbm_get_mon_event_by_name() - Return the mon_evt entry for the matching
+ * event name.
+ */
+static struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r, char *name)
+{
+	struct mon_evt *mevt;
+
+	for_each_mon_event(mevt) {
+		if (mevt->rid == r->rid && mevt->enabled &&
+		    resctrl_is_mbm_event(mevt->evtid) &&
+		    !strcmp(mevt->name, name))
+			return mevt;
+	}
+
+	return NULL;
+}
+
+static int rdtgroup_modify_assign_state(char *assign, struct rdt_mon_domain *d,
+					struct rdtgroup *rdtgrp, struct mon_evt *mevt)
+{
+	int ret = 0;
+
+	if (!assign || strlen(assign) != 1)
+		return -EINVAL;
+
+	switch (*assign) {
+	case 'e':
+		ret = rdtgroup_assign_cntr_event(d, rdtgrp, mevt);
+		break;
+	case '_':
+		rdtgroup_unassign_cntr_event(d, rdtgrp, mevt);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
+int resctrl_parse_mbm_assignment(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+				 char *event, char *tok)
+{

fs/resctrl/monitor.c void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt) · line 1368

Quoted 10 lines
fs/resctrl/monitor.c +10 -0
+	struct rdt_mon_domain *d;
+	unsigned long dom_id = 0;
+	char *dom_str, *id_str;
+	struct mon_evt *mevt;
+	int ret;
+
+	mevt = mbm_get_mon_event_by_name(r, event);
+	if (!mevt) {
+		rdt_last_cmd_printf("Invalid event %s\n", event);
+		return  -ENOENT;

Extra space

Quoted 44 lines
fs/resctrl/monitor.c +39 -0
+	}
+
+next:
+	if (!tok || tok[0] == '\0')
+		return 0;
+
+	/* Start processing the strings for each domain */
+	dom_str = strim(strsep(&tok, ";"));
+
+	id_str = strsep(&dom_str, "=");
+
+	/* Check for domain id '*' which means all domains */
+	if (id_str && *id_str == '*') {
+		ret = rdtgroup_modify_assign_state(dom_str, NULL, rdtgrp, mevt);
+		if (ret)
+			rdt_last_cmd_printf("Assign operation '%s:*=%s' failed\n",
+					    event, dom_str);
+		return ret;
+	} else if (!id_str || kstrtoul(id_str, 10, &dom_id)) {
+		rdt_last_cmd_puts("Missing domain id\n");
+		return -EINVAL;
+	}
+
+	/* Verify if the dom_id is valid */
+	list_for_each_entry(d, &r->mon_domains, hdr.list) {
+		if (d->hdr.id == dom_id) {
+			ret = rdtgroup_modify_assign_state(dom_str, d, rdtgrp, mevt);
+			if (ret) {
+				rdt_last_cmd_printf("Assign operation '%s:%ld=%s' failed\n",
+						    event, dom_id, dom_str);
+				return ret;
+			}
+			goto next;
+		}
+	}
+
+	rdt_last_cmd_printf("Invalid domain id %ld\n", dom_id);
+	return -EINVAL;
+}
fs/resctrl/rdtgroup.c +0 -0
index 47716e623a9c..2d2b91cd1f67 100644

fs/resctrl/rdtgroup.c static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file · line 1982

Quoted 4 lines
fs/resctrl/rdtgroup.c +1 -0
@@ -1979,6 +1979,51 @@ static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file
 	return ret;
 }
 
+static ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,

Please move to monitor.c

Reinette

author reviewer
#76 lore raw

Re: [PATCH v16 30/34] fs/resctrl: Introduce the interface to modify assignments in a group

Hi Reinette,

Quoted 9 lines · Reinette Chatre

Hi Babu,

Quoted 5 lines · Babu Moger

Enable the mbm_l3_assignments resctrl file to be used to modify counter assignments of CTRL_MON and MON groups when the "mbm_event" counter assignment mode is enabled.

The assignment modifications are done in the following format:

(needs imperative)

Sure.

Quoted 67 lines
Quoted 40 lines

<Event>:<Domain id>=<Assignment state>

Event: A valid MBM event in the
/sys/fs/resctrl/info/L3_MON/event_configs directory.

Domain ID: A valid domain ID. When writing, '*' applies the changes
to all domains.

Assignment states:

_ : Unassign a counter.

e : Assign a counter exclusively.

Examples:

$ cd /sys/fs/resctrl
$ cat /sys/fs/resctrl/mbm_L3_assignments
   mbm_total_bytes:0=e;1=e
   mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on domain 0:

$ echo "mbm_total_bytes:0=_" > mbm_L3_assignments
$ cat /sys/fs/resctrl/mbm_L3_assignments
   mbm_total_bytes:0=_;1=e
   mbm_local_bytes:0=e;1=e

To unassign the counter associated with the mbm_total_bytes event on all the domains:

$ echo "mbm_total_bytes:*=_" > mbm_L3_assignments
$ cat /sys/fs/resctrl/mbm_L3_assignments
   mbm_total_bytes:0=_;1=_
   mbm_local_bytes:0=e;1=e

---

...

Quoted 25 lines
---
  Documentation/filesystems/resctrl.rst | 146 +++++++++++++++++++++++++-
  fs/resctrl/internal.h                 |   3 +
  fs/resctrl/monitor.c                  |  94 +++++++++++++++++
  fs/resctrl/rdtgroup.c                 |  48 ++++++++-
  4 files changed, 289 insertions(+), 2 deletions(-)
Documentation/filesystems/resctrl.rst +2 -1
index 0b8ce942f112..0c8701103214 100644
@@ -525,7 +525,8 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
  	Event: A valid MBM event in the
  	       /sys/fs/resctrl/info/L3_MON/event_configs directory.
 
-	Domain ID: A valid domain ID.
+	Domain ID: A valid domain ID. When writing, '*' applies the changes
+		   to all the domains.
 
  	Assignment states:
 
@@ -542,6 +543,34 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
  	   mbm_total_bytes:0=e;1=e
  	   mbm_local_bytes:0=e;1=e
 
Quoted 8 lines

Documentation/filesystems/resctrl.rst When the "mba_MBps" mount option is used all CTRL_MON groups will also contain: · line 549

Quoted 4 lines
Documentation/filesystems/resctrl.rst +4 -0
+	Assignments can be modified by writing to the interface.
+
+	Example:
+	To unassign the counter associated with the mbm_total_bytes event on domain 0:

The alignment is off when looking at the generated html. What seems to be intended is that "Example" is some sort of heading but it ends up just being part of the sentence that follows and thus not apply to other examples that follow.
It can also be "Examples" since there are more than one.

Checking it again.

Quoted 91 lines
Quoted 91 lines
Documentation/filesystems/resctrl.rst +83 -0
+	::
+
+	 # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=_;1=e
+	   mbm_local_bytes:0=e;1=e
+
+	To unassign the counter associated with the mbm_total_bytes event on all the domains:
+	::
+
+	 # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=_;1=_
+	   mbm_local_bytes:0=e;1=e
+
+	To assign a counter associated with the mbm_total_bytes event on all domains in
+	exclusive mode:
+	::
+
+	 # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
+	 # cat /sys/fs/resctrl/mbm_L3_assignments
+	   mbm_total_bytes:0=e;1=e
+	   mbm_local_bytes:0=e;1=e
+
  Resource allocation rules
  -------------------------
 
@@ -1577,6 +1606,121 @@ View the llc occupancy snapshot::
    # cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy
    11234000
 
+
+Examples on working with mbm_assign_mode
+========================================
+
+a. Check if MBM counter assignment mode is supported.
+::
+
+  # mount -t resctrl resctrl /sys/fs/resctrl/
+
+  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  [mbm_event]
+  default
+
+The "mbm_event" mode is detected and enabled.
+
+b. Check how many assignable counters are supported.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
+  0=32;1=32
+
+c. Check how many assignable counters are available for assignment in each domain.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
+  0=30;1=30
+
+d. To list the default group's assign states.
+::
+
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=e;1=e
+  mbm_local_bytes:0=e;1=e
+
+e.  To unassign the counter associated with the mbm_total_bytes event on domain 0.
+::
+
+  # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=_;1=e
+  mbm_local_bytes:0=e;1=e
+
+f. To unassign the counter associated with the mbm_total_bytes event on all domains.
+::
+
+  # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignment
+  mbm_total_bytes:0=_;1=_
+  mbm_local_bytes:0=e;1=e
+
+g. To assign a counter associated with the mbm_total_bytes event on all domains in
+exclusive mode.
+::
+
+  # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments
+  # cat /sys/fs/resctrl/mbm_L3_assignments
+  mbm_total_bytes:0=e;1=e
+  mbm_local_bytes:0=e;1=e
+
Quoted 8 lines

Documentation/filesystems/resctrl.rst View the llc occupancy snapshot:: · line 1670

Quoted 3 lines
Documentation/filesystems/resctrl.rst +3 -0
+h. Read the events mbm_total_bytes and mbm_local_bytes of the default group. There is
+no change in reading the events with the assignment.  If the event is unassigned when
+reading, then the read will come back as "Unassigned".

While this example is for a single resource group the supporting text goes back and forth between being specific to one resource group and describing what happens when there are multiple resource groups (see (j)). If it is just one resource group then above is fine, but for multiple there are much more involved with the "unassigned". Same as what was mentioned during previous version.

Removed the "Unassigned" related text.  Also removed texts about multiple groups.

We already have details on "Unassigned" in mon_data section.

Quoted 127 lines
Quoted 127 lines
Documentation/filesystems/resctrl.rst +53 -0
+::
+
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes
+  779247936
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  765207488
+
+i. Check the event configurations.
+::
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter
+  local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes,
+  local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+  local_reads,local_non_temporal_writes,local_reads_slow_memory
+
+j. Change the event configuration for mbm_local_bytes.
+::
+
+  # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
+  /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+
+  # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter
+  local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads
+
+This will update all (across all domains of all monitor groups) counter assignments
+associated with the mbm_local_bytes event.
+
+k. Now read the local event again. The first read may come back with "Unavailable"
+status. The subsequent read of mbm_local_bytes will display the current value.
+::
+
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  Unavailable
+  # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes
+  314101
+
+l. Users have the option to go back to 'default' mbm_assign_mode if required. This can be
+done using the following command. Note that switching the mbm_assign_mode may reset all
+the MBM counters (and thus all MBM events) of all the resctrl groups.
+::
+
+  # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+  mbm_event
+  [default]
+
+m. Unmount the resctrl filesystem.
+::
+
+  # umount /sys/fs/resctrl/
+
  Intel RDT Errata
  ================
 
fs/resctrl/internal.h +3 -0
index e2e3fc0c5fab..1350fc273258 100644
@@ -418,6 +418,9 @@ int event_filter_show(struct kernfs_open_file *of, struct seq_file *seq, void *v
  ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
  			   loff_t off);
 
+int resctrl_parse_mbm_assignment(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+				 char *event, char *tok);
+
  #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
  int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
fs/resctrl/monitor.c +48 -0
index ebc049105949..1e4f8e3bedc6 100644
@@ -1311,3 +1311,97 @@ void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt)
  			rdtgroup_update_cntr_event(r, crgrp, mevt->evtid);
  	}
  }
+
+/*
+ * mbm_get_mon_event_by_name() - Return the mon_evt entry for the matching
+ * event name.
+ */
+static struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r, char *name)
+{
+	struct mon_evt *mevt;
+
+	for_each_mon_event(mevt) {
+		if (mevt->rid == r->rid && mevt->enabled &&
+		    resctrl_is_mbm_event(mevt->evtid) &&
+		    !strcmp(mevt->name, name))
+			return mevt;
+	}
+
+	return NULL;
+}
+
+static int rdtgroup_modify_assign_state(char *assign, struct rdt_mon_domain *d,
+					struct rdtgroup *rdtgrp, struct mon_evt *mevt)
+{
+	int ret = 0;
+
+	if (!assign || strlen(assign) != 1)
+		return -EINVAL;
+
+	switch (*assign) {
+	case 'e':
+		ret = rdtgroup_assign_cntr_event(d, rdtgrp, mevt);
+		break;
+	case '_':
+		rdtgroup_unassign_cntr_event(d, rdtgrp, mevt);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
+int resctrl_parse_mbm_assignment(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+				 char *event, char *tok)
+{
+	struct rdt_mon_domain *d;
+	unsigned long dom_id = 0;
+	char *dom_str, *id_str;
Quoted 8 lines

fs/resctrl/monitor.c void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt) · line 1368

Quoted 7 lines
fs/resctrl/monitor.c +7 -0
+	struct mon_evt *mevt;
+	int ret;
+
+	mevt = mbm_get_mon_event_by_name(r, event);
+	if (!mevt) {
+		rdt_last_cmd_printf("Invalid event %s\n", event);
+		return  -ENOENT;

Extra space

Sure.

Quoted 48 lines
Quoted 48 lines
fs/resctrl/monitor.c +39 -0
+	}
+
+next:
+	if (!tok || tok[0] == '\0')
+		return 0;
+
+	/* Start processing the strings for each domain */
+	dom_str = strim(strsep(&tok, ";"));
+
+	id_str = strsep(&dom_str, "=");
+
+	/* Check for domain id '*' which means all domains */
+	if (id_str && *id_str == '*') {
+		ret = rdtgroup_modify_assign_state(dom_str, NULL, rdtgrp, mevt);
+		if (ret)
+			rdt_last_cmd_printf("Assign operation '%s:*=%s' failed\n",
+					    event, dom_str);
+		return ret;
+	} else if (!id_str || kstrtoul(id_str, 10, &dom_id)) {
+		rdt_last_cmd_puts("Missing domain id\n");
+		return -EINVAL;
+	}
+
+	/* Verify if the dom_id is valid */
+	list_for_each_entry(d, &r->mon_domains, hdr.list) {
+		if (d->hdr.id == dom_id) {
+			ret = rdtgroup_modify_assign_state(dom_str, d, rdtgrp, mevt);
+			if (ret) {
+				rdt_last_cmd_printf("Assign operation '%s:%ld=%s' failed\n",
+						    event, dom_id, dom_str);
+				return ret;
+			}
+			goto next;
+		}
+	}
+
+	rdt_last_cmd_printf("Invalid domain id %ld\n", dom_id);
+	return -EINVAL;
+}
fs/resctrl/rdtgroup.c +0 -0
index 47716e623a9c..2d2b91cd1f67 100644
@@ -1979,6 +1979,51 @@ static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file
  	return ret;
  }
 
Quoted 2 lines

fs/resctrl/rdtgroup.c static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file · line 1982

Quoted 1 line
fs/resctrl/rdtgroup.c +1 -0
+static ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,

Please move to monitor.c

Sure.

Thanks

Babu

author reviewer
#77 lore raw

PATCH v16 31/34 fs/resctrl: Disable BMEC event configuration when mbm_event mode is enabled

In reply to Babu Moger

The BMEC (Bandwidth Monitoring Event Configuration) feature enables per-domain event configuration. With BMEC the MBM events are configured using the mbm_total_bytes_config or mbm_local_bytes_config files in /sys/fs/resctrl/info/L3_MON/ and the per-domain event configuration affects all monitor resource groups.

The mbm_event counter assignment mode enables counters to be assigned to RMID (i.e a monitor resource group), event pairs, with potentially unique event configurations associated with every counter.

There may be systems that support both BMEC and mbm_event counter assignment mode, but resctrl supporting both concurrently will present a conflicting interface to the user with both per-domain and per RMID, event configurations active at the same time.

The mbm_event counter assignment provides most flexibility to user space and aligns with Arm's counter support. On systems that support both, disable BMEC event configuration when mbm_event mode is enabled by hiding the mbm_total_bytes_config or mbm_local_bytes_config files when mbm_event mode is enabled. Ensure mon_features always displays accurate information about monitor features.

---
v16: Added new comment in resctrl_bmec_files_show() about kernfs_find_and_get failure.
Added the parameter to resctrl_bmec_files_show() to pass the kernfs_node.

v15: Updated the changelog.
Moved resctrl_bmec_files_show() inside rdtgroup_mkdir_info_resdir(). Removed the unnecessary kernfs_get() call.

v14: Updated the changelog for change in mbm_assign_modes.
Added check in rdt_mon_features_show to hide bmec related feature.

v13: New patch to hide BMEC related files.

---
 fs/resctrl/rdtgroup.c | 44 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
fs/resctrl/rdtgroup.c +43 -1
index 2d2b91cd1f67..1aeac350774d 100644
@@ -1150,7 +1150,8 @@ static int rdt_mon_features_show(struct kernfs_open_file *of,
 		if (mevt->rid != r->rid || !mevt->enabled)
 			continue;
 		seq_printf(seq, "%s\n", mevt->name);
-		if (mevt->configurable)
+		if (mevt->configurable &&
+		    !resctrl_arch_mbm_cntr_assign_enabled(r))
 			seq_printf(seq, "%s_config\n", mevt->name);
 	}
 
@@ -1799,6 +1800,41 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+/*
+ * resctrl_bmec_files_show() — Controls the visibility of BMEC-related resctrl
+ * files. When @show is true, the files are displayed; when false, the files
+ * are hidden.
+ * Don't treat kernfs_find_and_get failure as an error, since this function may
+ * be called regardless of whether BMEC is supported or the event is enabled.
+ */
+static void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *l3_mon_kn,
+				    bool show)
+{
+	struct kernfs_node *kn_config;
+	char name[32];
+
+	if (!l3_mon_kn) {
+		sprintf(name, "%s_MON", r->name);
+		l3_mon_kn = kernfs_find_and_get(kn_info, name);
+		if (!l3_mon_kn)
+			return;
+	}
+
+	kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_total_bytes_config");
+	if (kn_config) {
+		kernfs_show(kn_config, show);
+		kernfs_put(kn_config);
+	}
+
+	kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_local_bytes_config");
+	if (kn_config) {
+		kernfs_show(kn_config, show);
+		kernfs_put(kn_config);
+	}
+
+	kernfs_put(l3_mon_kn);
+}
+
 static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 					struct seq_file *s, void *v)
 {
@@ -2492,6 +2528,12 @@ static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
 			ret = resctrl_mkdir_event_configs(r, kn_subdir);
 			if (ret)
 				return ret;
+			/*
+			 * Hide BMEC related files if mbm_event mode
+			 * is enabled.
+			 */
+			if (resctrl_arch_mbm_cntr_assign_enabled(r))
+				resctrl_bmec_files_show(r, kn_subdir, false);
 		}
 	}
 
Signature · 1 line
2.34.1
maintainer
#78 lore raw

Re: [PATCH v16 31/34] fs/resctrl: Disable BMEC event configuration when mbm_event mode is enabled

Hi Babu,

Quoted 27 lines · Babu Moger
fs/resctrl/rdtgroup.c +23 -0
@@ -1799,6 +1800,41 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+/*
+ * resctrl_bmec_files_show() — Controls the visibility of BMEC-related resctrl
+ * files. When @show is true, the files are displayed; when false, the files
+ * are hidden.
+ * Don't treat kernfs_find_and_get failure as an error, since this function may
+ * be called regardless of whether BMEC is supported or the event is enabled.
+ */
+static void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *l3_mon_kn,
+				    bool show)
+{
+	struct kernfs_node *kn_config;
+	char name[32];
+
+	if (!l3_mon_kn) {
+		sprintf(name, "%s_MON", r->name);
+		l3_mon_kn = kernfs_find_and_get(kn_info, name);
+		if (!l3_mon_kn)
+			return;
+	}
+
+	kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_total_bytes_config");
+	if (kn_config) {
+		kernfs_show(kn_config, show);

fs/resctrl/rdtgroup.c static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of, · line 1835

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+		kernfs_put(kn_config);
+	}
+
+	kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_local_bytes_config");
+	if (kn_config) {
+		kernfs_show(kn_config, show);
+		kernfs_put(kn_config);
+	}
+
+	kernfs_put(l3_mon_kn);

Looks like this will drop an extra reference if l3_mon_kn was provided as parameter.

Reinette

author reviewer
#79 lore raw

Re: [PATCH v16 31/34] fs/resctrl: Disable BMEC event configuration when mbm_event mode is enabled

Hi Reinette,

Quoted 34 lines · Reinette Chatre

Hi Babu,

Quoted 31 lines · Babu Moger
fs/resctrl/rdtgroup.c +27 -0
@@ -1799,6 +1800,41 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+/*
+ * resctrl_bmec_files_show() — Controls the visibility of BMEC-related resctrl
+ * files. When @show is true, the files are displayed; when false, the files
+ * are hidden.
+ * Don't treat kernfs_find_and_get failure as an error, since this function may
+ * be called regardless of whether BMEC is supported or the event is enabled.
+ */
+static void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *l3_mon_kn,
+				    bool show)
+{
+	struct kernfs_node *kn_config;
+	char name[32];
+
+	if (!l3_mon_kn) {
+		sprintf(name, "%s_MON", r->name);
+		l3_mon_kn = kernfs_find_and_get(kn_info, name);
+		if (!l3_mon_kn)
+			return;
+	}
+
+	kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_total_bytes_config");
+	if (kn_config) {
+		kernfs_show(kn_config, show);
+		kernfs_put(kn_config);
+	}
+
+	kn_config = kernfs_find_and_get(l3_mon_kn, "mbm_local_bytes_config");
Quoted 9 lines

fs/resctrl/rdtgroup.c static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of, · line 1835

Quoted 6 lines
fs/resctrl/rdtgroup.c +6 -0
+	if (kn_config) {
+		kernfs_show(kn_config, show);
+		kernfs_put(kn_config);
+	}
+
+	kernfs_put(l3_mon_kn);

Looks like this will drop an extra reference if l3_mon_kn was provided as parameter.

Yes. Fixed it now.
Thanks
Babu Moger

author reviewer
#80 lore raw

PATCH v16 32/34 fs/resctrl: Introduce the interface to switch between monitor modes

In reply to Babu Moger

Resctrl subsystem can support two monitoring modes, "mbm_event" or "default". In mbm_event mode, monitoring event can only accumulate data while it is backed by a hardware counter. In "default" mode, resctrl assumes there is a hardware counter for each event within every CTRL_MON and MON group.

Introduce mbm_assign_mode resctrl file to switch between mbm_event and default modes.

Example:
To list the MBM monitor modes supported:

$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
[mbm_event]
default

To enable the "mbm_event" counter assignment mode:

$ echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode

To enable the "default" monitoring mode:

$ echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode

MBM event counters are automatically reset as part of changing the mode. Clear both architectural and non-architectural event states to prevent overflow conditions during the next event read. Also clear assignable counter configuration on all the domains.

---
v16: Minor changelog update.
Minor update in resctrl.rst.
Updated resctrl_bmec_files_show() to pass NULL for kn_fs_node.

v15: Minor changelog update.
Minir user do resctrl.rst update.
Fixed stray hunks.

v14: Updated the changelog to reflect the change in monitor mode naming.
Added the call resctrl_bmec_files_show() to enable/disable files related to BMEC.
Added resctrl_set_mon_evt_cfg() to reset event configuration values when mode is changes.

v13: Resolved the conflicts due to FS/ARCH restructure.
Introduced the new resctrl_init_evt_configuration() to initialize the event modes and configuration values.
Added the call to resctrl_bmec_files_show() hide/show BMEC related files.

v12: Fixed the documentation for a consistency.
Introduced mbm_cntr_free_all() and resctrl_reset_rmid_all() to clear counters and non-architectural states when monitor mode is changed.
https://lore.kernel.org/lkml/[email protected]/

v11: Changed the name of the function rdtgroup_mbm_assign_mode_write() to
resctrl_mbm_assign_mode_write().
Rewrote the commit message with context.
Added few more details in resctrl.rst about mbm_cntr_assign mode. Re-arranged the text in resctrl.rst file.

v10: The call mbm_cntr_reset() has been moved to earlier patch.
Minor documentation update.

v9: Fixed extra spaces in user documentation.
Fixed problem changing the mode to mbm_cntr_assign mode when it is not supported. Added extra checks to detect if systems supports it. Used the rdtgroup_cntr_id_init to initialize cntr_id.

v8: Reset the internal counters after mbm_cntr_assign mode is changed.
Renamed rdtgroup_mbm_cntr_reset() to mbm_cntr_reset() Updated the documentation to make text generic.

v7: Changed the interface name to mbm_assign_mode.
Removed the references of ABMC.
Added the changes to reset global and domain bitmaps. Added the changes to reset rmid.

v6: Changed the mode name to mbm_cntr_assign.
Moved all the FS related code here.
Added changes to reset mbm_cntr_map and resctrl group counters.

v5: Change log and mode description text correction.

v4: Minor commit text changes. Keep the default to ABMC when supported.
Fixed comments to reflect changed interface "mbm_mode".

v3: New patch to address the review comments from upstream.

---
 Documentation/filesystems/resctrl.rst | 22 +++++++-
 fs/resctrl/internal.h                 |  2 +
 fs/resctrl/monitor.c                  | 27 ++++++++++
 fs/resctrl/rdtgroup.c                 | 72 ++++++++++++++++++++++++++-
 4 files changed, 121 insertions(+), 2 deletions(-)
Documentation/filesystems/resctrl.rst +21 -1
index 0c8701103214..35bd58af5c61 100644
@@ -259,7 +259,8 @@ with the following files:
 
 "mbm_assign_mode":
 	The supported counter assignment modes. The enclosed brackets indicate which mode
-	is enabled.
+	is enabled. The MBM events associated with counters may reset when "mbm_assign_mode"
+	is changed.
 	::
 
 	  # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
@@ -279,6 +280,15 @@ with the following files:
 	of counters available is described in the "num_mbm_cntrs" file. Changing the
 	mode may cause all counters on the resource to reset.
 
+	Moving to mbm_event counter assignment mode requires users to assign the counters
+	to the events. Otherwise, the MBM event counters will return 'Unassigned' when read.
+
+	The mode is beneficial for AMD platforms that support more CTRL_MON
+	and MON groups than available hardware counters. By default, this
+	feature is enabled on AMD platforms with the ABMC (Assignable Bandwidth
+	Monitoring Counters) capability, ensuring counters remain assigned even
+	when the corresponding RMID is not actively used by any processor.
+
 	"default":
 
 	In default mode, resctrl assumes there is a hardware counter for each
@@ -288,6 +298,16 @@ with the following files:
 	result in misleading values or display "Unavailable" if no counter is assigned
 	to the event.
 
+	* To enable "mbm_event" counter assignment mode:
+	  ::
+
+	    # echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+
+	* To enable "default" monitoring mode:
+	  ::
+
+	    # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
+
 "num_mbm_cntrs":
 	The maximum number of counters (total of available and assigned counters) in
 	each domain when the system supports mbm_event mode.
fs/resctrl/internal.h +2 -0
index 1350fc273258..c666aaf7858f 100644
@@ -410,6 +410,8 @@ void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdt
 int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d,
 		 struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);
 void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt);
+void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *d);
+void mbm_cntr_free_all(struct rdt_resource *r, struct rdt_mon_domain *d);
 
 void *rdt_kn_parent_priv(struct kernfs_node *kn);
 
fs/resctrl/monitor.c +27 -0
index 1e4f8e3bedc6..a4411a128431 100644
@@ -1093,6 +1093,33 @@ void resctrl_mon_resource_exit(void)
 	dom_data_exit(r);
 }
 
+/*
+ * mbm_cntr_free_all() - Clear all the counter ID configuration details in the
+ *			 domain @d. Called when mbm_assign_mode is changed.
+ */
+void mbm_cntr_free_all(struct rdt_resource *r, struct rdt_mon_domain *d)
+{
+	memset(d->cntr_cfg, 0, sizeof(*d->cntr_cfg) * r->mon.num_mbm_cntrs);
+}
+
+/*
+ * resctrl_reset_rmid_all() - Reset all non-architecture states for all the
+ *			      supported RMIDs.
+ */
+void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *d)
+{
+	u32 idx_limit = resctrl_arch_system_num_rmid_idx();
+	enum resctrl_event_id evt;
+	int idx;
+
+	for_each_mbm_event_id(evt) {
+		if (!resctrl_is_mon_event_enabled(evt))
+			continue;
+		idx = MBM_STATE_IDX(evt);
+		memset(d->mbm_states[idx], 0, sizeof(*d->mbm_states[0]) * idx_limit);
+	}
+}
+
 /*
  * rdtgroup_assign_cntr() - Assign/unassign the counter ID for the event, RMID
  * pair in the domain.
fs/resctrl/rdtgroup.c +71 -1

86 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#81 lore raw

Re: [PATCH v16 32/34] fs/resctrl: Introduce the interface to switch between monitor modes

Hi Babu,

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1869

Quoted 10 lines · Babu Moger
fs/resctrl/rdtgroup.c +2 -0
index 1aeac350774d..68ba08e95a54 100644
@@ -1865,6 +1865,75 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 	return 0;
 }
 
+static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of,
+					     char *buf, size_t nbytes, loff_t off)

Please move to monitor.c

Quoted 41 lines
fs/resctrl/rdtgroup.c +41 -0
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *d;
+	int ret = 0;
+	bool enable;
+
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n')
+		return -EINVAL;
+
+	buf[nbytes - 1] = '\0';
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!strcmp(buf, "default")) {
+		enable = 0;
+	} else if (!strcmp(buf, "mbm_event")) {
+		if (r->mon.mbm_cntr_assignable) {
+			enable = 1;
+		} else {
+			ret = -EINVAL;
+			rdt_last_cmd_puts("mbm_event mode is not supported\n");
+			goto out_unlock;
+		}
+	} else {
+		ret = -EINVAL;
+		rdt_last_cmd_puts("Unsupported assign mode\n");
+		goto out_unlock;
+	}
+
+	if (enable != resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		ret = resctrl_arch_mbm_cntr_assign_set(r, enable);
+		if (ret)
+			goto out_unlock;
+
+		/* Update the visibility of BMEC related files */
+		resctrl_bmec_files_show(r, NULL, !enable);
+

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1920

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+		/*
+		 * Initialize the default memory transaction values for
+		 * total and local events.
+		 */
+		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
+			mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = MAX_EVT_CONFIG_BITS;
+		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+			mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
+									   READS_TO_LOCAL_S_MEM |
+									   NON_TEMP_WRITE_TO_LOCAL_MEM;

This needs to take into account the configurations that hardware supports.

Reinette

author reviewer
#82 lore raw

Re: [PATCH v16 32/34] fs/resctrl: Introduce the interface to switch between monitor modes

Hi Reinette,

Quoted 11 lines · Reinette Chatre

Hi Babu,

Quoted 8 lines · Babu Moger
fs/resctrl/rdtgroup.c +0 -0
index 1aeac350774d..68ba08e95a54 100644
@@ -1865,6 +1865,75 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
 	return 0;
 }
 
Quoted 5 lines

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1869

Quoted 2 lines
fs/resctrl/rdtgroup.c +2 -0
+static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of,
+					     char *buf, size_t nbytes, loff_t off)

Please move to monitor.c

Sure.

Quoted 46 lines
Quoted 46 lines
fs/resctrl/rdtgroup.c +46 -0
+{
+	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+	struct rdt_mon_domain *d;
+	int ret = 0;
+	bool enable;
+
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n')
+		return -EINVAL;
+
+	buf[nbytes - 1] = '\0';
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	if (!strcmp(buf, "default")) {
+		enable = 0;
+	} else if (!strcmp(buf, "mbm_event")) {
+		if (r->mon.mbm_cntr_assignable) {
+			enable = 1;
+		} else {
+			ret = -EINVAL;
+			rdt_last_cmd_puts("mbm_event mode is not supported\n");
+			goto out_unlock;
+		}
+	} else {
+		ret = -EINVAL;
+		rdt_last_cmd_puts("Unsupported assign mode\n");
+		goto out_unlock;
+	}
+
+	if (enable != resctrl_arch_mbm_cntr_assign_enabled(r)) {
+		ret = resctrl_arch_mbm_cntr_assign_set(r, enable);
+		if (ret)
+			goto out_unlock;
+
+		/* Update the visibility of BMEC related files */
+		resctrl_bmec_files_show(r, NULL, !enable);
+
+		/*
+		 * Initialize the default memory transaction values for
+		 * total and local events.
+		 */
+		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
Quoted 9 lines

fs/resctrl/rdtgroup.c static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, · line 1920

Quoted 5 lines
fs/resctrl/rdtgroup.c +5 -0
+			mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].evt_cfg = MAX_EVT_CONFIG_BITS;
+		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
+			mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].evt_cfg = READS_TO_LOCAL_MEM |
+									   READS_TO_LOCAL_S_MEM |
+									   NON_TEMP_WRITE_TO_LOCAL_MEM;

This needs to take into account the configurations that hardware supports.

Yes. Sure.

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#83 lore raw

PATCH v16 33/34 x86/resctrl: Configure mbm_event mode if supported

In reply to Babu Moger

Configure mbm_event mode on AMD platforms. On AMD platforms, it is recommended to use the mbm_event mode, if supported, to prevent the hardware from resetting counters between reads. This can result in misleading values or display "Unavailable" if no counter is assigned to the event.

The mbm_event mode, referred to as ABMC (Assignable Bandwidth Monitoring Counters) on AMD, is enabled by default when supported by the system.

Update ABMC across all logical processors within the resctrl domain to ensure proper functionality.

---
v16: Fixed a minor conflict in arch/x86/kernel/cpu/resctrl/monitor.c.

v15: Minor comment update.

v14: Updated the changelog to reflect the change in name of the monitor mode
to mbm_event.

v13 : Added the call resctrl_init_evt_configuration() to setup the event
configuration during init.
Resolved conflicts caused by the recent FS/ARCH code restructure.

v12: Moved the resctrl_arch_mbm_cntr_assign_set_one to domain_add_cpu_mon().
Updated the commit log.

v11: Commit text in imperative tone. Added few more details.
Moved resctrl_arch_mbm_cntr_assign_set_one() to monitor.c.

v10: Commit text in imperative tone.

v9: Minor code change due to merge. Actual code did not change.

v8: Renamed resctrl_arch_mbm_cntr_assign_configure to
resctrl_arch_mbm_cntr_assign_set_one.
Adde r->mon_capable check.
Commit message update.

v7: Introduced resctrl_arch_mbm_cntr_assign_configure() to configure.
Moved the default settings to rdt_get_mon_l3_config(). It should be done before the hotplug handler is called. It cannot be done at rdtgroup_init().

v6: Keeping the default enablement in arch init code for now.
This may need some discussion.
Renamed resctrl_arch_configure_abmc to resctrl_arch_mbm_cntr_assign_configure.

v5: New patch to enable ABMC by default.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 7 +++++++
 arch/x86/kernel/cpu/resctrl/internal.h | 1 +
 arch/x86/kernel/cpu/resctrl/monitor.c  | 8 ++++++++
 3 files changed, 16 insertions(+)
arch/x86/kernel/cpu/resctrl/core.c +7 -0
index 09cb5a70b1cb..bb707a762c53 100644
@@ -520,6 +520,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 		d = container_of(hdr, struct rdt_mon_domain, hdr);
 
 		cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
+		/* Update the mbm_assign_mode state for the CPU if supported */
+		if (r->mon.mbm_cntr_assignable)
+			resctrl_arch_mbm_cntr_assign_set_one(r);
 		return;
 	}
 
@@ -539,6 +542,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
 	d->ci_id = ci->id;
 	cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
 
+	/* Update the mbm_assign_mode state for the CPU if supported */
+	if (r->mon.mbm_cntr_assignable)
+		resctrl_arch_mbm_cntr_assign_set_one(r);
+
 	arch_mon_domain_online(r, d);
 
 	if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) {
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
index ae4003d44df4..ee81c2d3f058 100644
@@ -215,5 +215,6 @@ bool rdt_cpu_has(int flag);
 void __init intel_rdt_mbm_apply_quirk(void);
 
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
+void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r);
 
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +8 -0
index 57c8409a8247..61c0ac5f0be1 100644
@@ -455,6 +455,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 		r->mon.mbm_cntr_assignable = true;
 		cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
 		r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
+		hw_res->mbm_cntr_assign_enabled = true;
 	}
 
 	r->mon_capable = true;
@@ -556,3 +557,10 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
 	if (am)
 		memset(am, 0, sizeof(*am));
 }
+
+void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r)
+{
+	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+
+	resctrl_abmc_set_one_amd(&hw_res->mbm_cntr_assign_enabled);
+}
Signature · 1 line
2.34.1
maintainer
#84 lore raw

Re: [PATCH v16 33/34] x86/resctrl: Configure mbm_event mode if supported

Hi Babu,

Quoted 8 lines · Babu Moger

Configure mbm_event mode on AMD platforms. On AMD platforms, it is recommended to use the mbm_event mode, if supported, to prevent the hardware from resetting counters between reads. This can result in misleading values or display "Unavailable" if no counter is assigned to the event.

The mbm_event mode, referred to as ABMC (Assignable Bandwidth Monitoring Counters) on AMD, is enabled by default when supported by the system.

needs imperative

Quoted 6 lines

Update ABMC across all logical processors within the resctrl domain to ensure proper functionality.

---

Patch looks good.

Reinette

author reviewer
#85 lore raw

Re: [PATCH v16 33/34] x86/resctrl: Configure mbm_event mode if supported

Hi Reinette,

Quoted 9 lines · Reinette Chatre

Hi Babu,

Quoted 6 lines · Babu Moger

Configure mbm_event mode on AMD platforms. On AMD platforms, it is recommended to use the mbm_event mode, if supported, to prevent the hardware from resetting counters between reads. This can result in misleading values or display "Unavailable" if no counter is assigned to the event.

Quoted 5 lines
Quoted 2 lines

The mbm_event mode, referred to as ABMC (Assignable Bandwidth Monitoring Counters) on AMD, is enabled by default when supported by the system.

needs imperative

Sure.

Quoted 9 lines
Quoted 6 lines

Update ABMC across all logical processors within the resctrl domain to ensure proper functionality.

---

Patch looks good.

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#86 lore raw

PATCH v16 34/34 MAINTAINERS: resctrl: add myself as reviewer

In reply to Babu Moger

I have been contributing to resctrl for sometime now and I would like to help with code reviews as well.

---
v16: Reinette suggested to add me as a reviewer. I am glad to help as a reviewer.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index f697a0c51721..70a2f83145db 100644
@@ -20866,6 +20866,7 @@ M:	Tony Luck <[email protected]>
 M:	Reinette Chatre <[email protected]>
 R:	Dave Martin <[email protected]>
 R:	James Morse <[email protected]>
+R:	Babu Moger <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	Documentation/filesystems/resctrl.rst
Signature · 1 line
2.34.1
maintainer Acked-by on v16 34/34
#87 lore raw

Re: [PATCH v16 34/34] MAINTAINERS: resctrl: add myself as reviewer

Hi Babu,

Quoted 2 lines · Babu Moger

I have been contributing to resctrl for sometime now and I would like to help with code reviews as well.

You do not need to be in MAINTAINERS file to help with code reviews. I do believe it is important that you are cc'd on all future contributions since I am not able to test these new features you are enabling so having you keep an eye on the health of these areas is greatly appreciated.

Quoted 12 lines

---
v16: Reinette suggested to add me as a reviewer. I am glad to help as a reviewer.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +0 -0
index f697a0c51721..70a2f83145db 100644

MAINTAINERS M: Tony Luck <[email protected]> · line 20872

Quoted 7 lines
MAINTAINERS +1 -0
@@ -20866,6 +20866,7 @@ M:	Tony Luck <[email protected]>
 M:	Reinette Chatre <[email protected]>
 R:	Dave Martin <[email protected]>
 R:	James Morse <[email protected]>
+R:	Babu Moger <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	Documentation/filesystems/resctrl.rst

Reinette

author reviewer
#88 lore raw

Re: [PATCH v16 34/34] MAINTAINERS: resctrl: add myself as reviewer

Hi Reinette,

Quoted 10 lines · Reinette Chatre

Hi Babu,

Quoted 2 lines · Babu Moger

I have been contributing to resctrl for sometime now and I would like to help with code reviews as well.

You do not need to be in MAINTAINERS file to help with code reviews. I do believe it is important that you are cc'd on all future contributions since I am not able to test these new features you are enabling so having you keep an eye on the health of these areas is greatly appreciated.

Agreed.

Quoted 8 lines
Quoted 8 lines

---
v16: Reinette suggested to add me as a reviewer. I am glad to help as a reviewer.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

MAINTAINERS M: Tony Luck <[email protected]> · line 20872

Quoted 12 lines
MAINTAINERS +1 -0
index f697a0c51721..70a2f83145db 100644
@@ -20866,6 +20866,7 @@ M:	Tony Luck <[email protected]>
 M:	Reinette Chatre <[email protected]>
 R:	Dave Martin <[email protected]>
 R:	James Morse <[email protected]>
+R:	Babu Moger <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	Documentation/filesystems/resctrl.rst

-
Thanks
Babu Moger

maintainer
#89 lore raw
In reply to Babu Moger

Hi Babu,

Quoted 7 lines · Babu Moger

i. Change the event configuration for mbm_local_bytes.

	# echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
	/sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	# cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads

Above are some more "counter_configs" stragglers.

Also, while considering our exchange in [1], I encountered quite a few functions doing counter management work for which I believe monitor.c would be more appropriate. Centralizing MBM counter management code to monitor.c was something that you planned for this version so I may be missing why you decided to keep some of these functions in rdtgroup.c? I highlighted these functions as I noticed them.

Reinette

[1] https://lore.kernel.org/lkml/[email protected]/

#90 lore raw

Hi Reinette,,

Quoted 5 lines · Reinette Chatre

Hi Babu,

Quoted 2 lines · Babu Moger

i. Change the event configuration for mbm_local_bytes.

Quoted 7 lines
Quoted 5 lines
	# echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
	/sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	# cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
	local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads

Above are some more "counter_configs" stragglers.

Yea. Sure. Missed that.

Quoted 7 lines

Also, while considering our exchange in [1], I encountered quite a few functions doing counter management work for which I believe monitor.c would be more appropriate. Centralizing MBM counter management code to monitor.c was something that you planned for this version so I may be missing why you decided to keep some of these functions in rdtgroup.c? I highlighted these functions as I noticed them.

I looked at them. Most of the functions you mentioned are directly referenced in res_common_files[] (show or write) and some of them are even named as rdtgroup_<>. So, was not sure about moving them. Sure, I will move them one by one to monitor.c
Thanks
Babu

maintainer
#91 lore raw

Hi Babu,

Quoted 19 lines · Babu

Hi Reinette,,

Quoted 5 lines · Reinette Chatre

Hi Babu,

Quoted 2 lines · Babu Moger

i. Change the event configuration for mbm_local_bytes.

Quoted 7 lines
Quoted 5 lines
    # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
    /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
    # cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
    local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads

Above are some more "counter_configs" stragglers.

Yea. Sure. Missed that.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

Also, while considering our exchange in [1], I encountered quite a few functions doing counter management work for which I believe monitor.c would be more appropriate. Centralizing MBM counter management code to monitor.c was something that you planned for this version so I may be missing why you decided to keep some of these functions in rdtgroup.c? I highlighted these functions as I noticed them.

I looked at them. Most of the functions you mentioned are directly referenced in res_common_files[] (show or write) and some of them are even named as rdtgroup_<>. So, was not sure about moving them.

If you prefer a precedent you can compare with rdtgroup_schemata_write()/rdtgroup_schemata_show() that is directly referenced in res_common_files[] while the implementation can be found in ctrlmondata.c that is intended to contain the "Cache allocation code".

I assumed we agreed on this since I specifically highlighted the topic of the handlers in [1] and you responded to referring to the handler event_filter_show() and mentioned that you plan to consider the others. This version thus looks different from what I thought we agreed on :/

Quoted 1 line

Sure, I will move them one by one to monitor.c

[1] https://lore.kernel.org/lkml/[email protected]/

#92 lore raw

Hi Reinette,

Quoted 31 lines · Reinette Chatre

Hi Babu,

Quoted 19 lines · Babu

Hi Reinette,,

Quoted 5 lines · Reinette Chatre

Hi Babu,

Quoted 2 lines · Babu Moger

i. Change the event configuration for mbm_local_bytes.

Quoted 7 lines
Quoted 5 lines
     # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" >
     /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
     # cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter
     local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads

Above are some more "counter_configs" stragglers.

Yea. Sure. Missed that.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

Also, while considering our exchange in [1], I encountered quite a few functions doing counter management work for which I believe monitor.c would be more appropriate. Centralizing MBM counter management code to monitor.c was something that you planned for this version so I may be missing why you decided to keep some of these functions in rdtgroup.c? I highlighted these functions as I noticed them.

I looked at them. Most of the functions you mentioned are directly referenced in res_common_files[] (show or write) and some of them are even named as rdtgroup_<>. So, was not sure about moving them.

Quoted 7 lines

If you prefer a precedent you can compare with rdtgroup_schemata_write()/rdtgroup_schemata_show() that is directly referenced in res_common_files[] while the implementation can be found in ctrlmondata.c that is intended to contain the "Cache allocation code".

I assumed we agreed on this since I specifically highlighted the topic of the handlers in [1] and you responded to referring to the handler event_filter_show() and mentioned that you plan to consider the others. This version thus looks different from what I thought we agreed on :/

Looks like I misunderstood few things here. Will take care of it in next revision.

Thanks
Babu

Quoted 5 lines
Quoted 2 lines

Sure, I will move them one by one to monitor.c

[1] https://lore.kernel.org/lkml/[email protected]/