x86/resctrl : Support AMD Assignable Bandwidth Monitoring Counters (ABMC)
Subsystems (3)
Babu Moger
reviewerv11 cover x86/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 commitd361b84d51bfe (tip/master) Merge branch into tip/master: 'x86/tdx'
# Introduction
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 for certain point of time. Users do not have the option to monitor a group or set of groups for certain period of time without worrying about counter being reset in between.
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually. There is no need to worry about counters being reset during this period. Additionally, the user can specify a bitmask identifying the specific bandwidth types from the given source to track with the counter.
Without ABMC enabled, monitoring will work in current 'default' mode without assignment option.
# Linux Implementation
Create a generic interface aimed 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: Reports the number of monitoring counters available for assignment.
/sys/fs/resctrl/info/L3_MON/available_mbm_cntrs: Reports the number of monitoring counters free in each domain.
/sys/fs/resctrl/info/L3_MON/mbm_assign_control: Reports the resctrl group and monitor status of each group. Assignment state can be updated by writing to the interface.
# Examples
a. Check if ABMC support is available
#mount -t resctrl resctrl /sys/fs/resctrl/
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign]
default
ABMC feature is detected and it is enabled.
b. Check how many ABMC counters are available.
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32
c. Check how many ABMC counters are available in each domain.
# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=30;1=30
d. Create few resctrl groups.
# mkdir /sys/fs/resctrl/mon_groups/child_default_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp/mon_groups/child_non_default_mon_grp
e. This series adds a new interface file /sys/fs/resctrl/info/L3_MON/mbm_assign_control
to list and modify any group's monitoring states. File provides single place to list monitoring states of all the resctrl groups. It makes it easier for user space to learn about the used counters without needing to traverse all the groups thus reducing the number of file system calls.
The list follows the following format:
"<CTRL_MON group>/<MON group>/<domain_id>=<flags>"
Format for specific type of groups:
* Default CTRL_MON group:
"//<domain_id>=<flags>"
* Non-default CTRL_MON group:
"<CTRL_MON group>//<domain_id>=<flags>"
* Child MON group of default CTRL_MON group:
"/<MON group>/<domain_id>=<flags>"
* Child MON group of non-default CTRL_MON group:
"<CTRL_MON group>/<MON group>/<domain_id>=<flags>"
Flags can be one of the following:
t MBM total event is enabled.
l MBM local event is enabled.
tl Both total and local MBM events are enabled. _ None of the MBM events are enabled
Examples:
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=tl;1=tl non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl //0=tl;1=tl
/child_default_mon_grp/0=tl;1=tl
There are four groups and all the groups have local and total event enabled on domain 0 and 1.
f. Update the group assignment states using the interface file /sys/fs/resctrl/info/L3_MON/mbm_assign_control.
The write format is similar to the above list format with addition of opcode for the assignment operation.
“<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>”
* Default CTRL_MON group:
"//<domain_id><opcode><flags>"
* Non-default CTRL_MON group:
"<CTRL_MON group>//<domain_id><opcode><flags>"
* Child MON group of default CTRL_MON group:
"/<MON group>/<domain_id><opcode><flags>"
* Child MON group of non-default CTRL_MON group:
"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Opcode can be one of the following:
= Update the assignment to match the flags.
+ Assign a new MBM event without impacting existing assignments.
- Unassign a MBM event from currently assigned events.
Flags can be one of the following:
t MBM total event.
l MBM local event.
tl Both total and local MBM events.
_ None of the MBM events. Only works with '=' opcode. This flag cannot be combined with other flags.
Initial group status:
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=tl;1=tl non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl //0=tl;1=tl
/child_default_mon_grp/0=tl;1=tl
To update the default group to enable only total event on domain 0:
# echo "//0=t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control
Assignment status after the update:
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=tl;1=tl non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl //0=t;1=tl
/child_default_mon_grp/0=tl;1=tl
To update the MON group child_default_mon_grp to remove total event on domain 1:
# echo "/child_default_mon_grp/1-t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control
Assignment status after the update:
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=tl;1=tl non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl //0=t;1=tl
/child_default_mon_grp/0=tl;1=l
To update the MON group non_default_ctrl_mon_grp/child_non_default_mon_grp to remove both local and total events on domain 1:
# echo "non_default_ctrl_mon_grp/child_non_default_mon_grp/1=_" >
/sys/fs/resctrl/info/L3_MON/mbm_assign_control
Assignment status after the update:
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=tl;1=tl non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ //0=t;1=tl
/child_default_mon_grp/0=tl;1=l
To update the default group to add a local event domain 0. # echo "//0+l" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control
Assignment status after the update:
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=tl;1=tl non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ //0=tl;1=tl
/child_default_mon_grp/0=tl;1=l
To update the non default CTRL_MON group non_default_ctrl_mon_grp to unassign all the MBM events on all the domains.
# echo "non_default_ctrl_mon_grp//*=_" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control
Assignment status after the update:
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control non_default_ctrl_mon_grp//0=_;1=_ non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ //0=tl;1=tl
/child_default_mon_grp/0=tl;1=l
g. Read the event mbm_total_bytes and mbm_local_bytes of the default group.
There is no change in reading the events with ABMC. 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 bandwidth configuration for the group. Note that bandwidth
configuration has a domain scope. Total event defaults to 0x7F (to count all the events) and local event defaults to 0x15 (to count all the local numa events). The event bitmap decoding is available at
https://www.kernel.org/doc/Documentation/x86/resctrl.rst
in section "mbm_total_bytes_config", "mbm_local_bytes_config":
#cat /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config 0=0x7f;1=0x7f #cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config 0=0x15;1=0x15
i. Change the bandwidth source for domain 0 for the total event to count only reads.
Note that this change effects total events on the domain 0.
#echo 0=0x33 > /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config #cat /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config 0=0x33;1=0x7F
j. Now read the total event again. The first read may come back with "Unavailable"
status. The subsequent read of mbm_total_bytes will display only the read events.
#cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes Unavailable #cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes 314101
k. Users will 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 of all resctrl groups.
# echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode mbm_cntr_assign [default]
l. Unmount the resctrl
#umount /sys/fs/resctrl/
---
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:
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 (23):
x86/resctrl: Add __init attribute to functions called from
resctrl_late_init()
x86/cpufeatures: Add support for Assignable Bandwidth Monitoring
Counters (ABMC)
x86/resctrl: Add ABMC feature in the command line options x86/resctrl: Consolidate monitoring related data from rdt_resource x86/resctrl: Detect Assignable Bandwidth Monitoring feature details x86/resctrl: Add support to enable/disable AMD ABMC feature x86/resctrl: Introduce the interface to display monitor mode x86/resctrl: Introduce interface to display number of monitoring
counters
x86/resctrl: Introduce mbm_total_cfg and mbm_local_cfg in struct
rdt_hw_mon_domain
x86/resctrl: Remove MSR reading of event configuration value x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at
domain
x86/resctrl: Introduce interface to display number of free counters x86/resctrl: Add data structures and definitions for ABMC assignment x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter
with ABMC
x86/resctrl: Add the functionality to assigm MBM events x86/resctrl: Add the functionality to unassigm MBM events x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is
enabled
x86/resctrl: Report "Unassigned" for MBM events in mbm_cntr_assign
mode
x86/resctrl: Introduce the interface to switch between monitor modes x86/resctrl: Configure mbm_cntr_assign mode if supported x86/resctrl: Update assignments on event configuration changes x86/resctrl: Introduce interface to list assignment states of all the
groups
x86/resctrl: Introduce interface to modify assignment states of the
groups
.../admin-guide/kernel-parameters.txt | 2 +- Documentation/arch/x86/resctrl.rst | 242 +++++++ arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 2 + arch/x86/kernel/cpu/cpuid-deps.c | 3 + arch/x86/kernel/cpu/resctrl/core.c | 23 +- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 13 + arch/x86/kernel/cpu/resctrl/internal.h | 91 ++- arch/x86/kernel/cpu/resctrl/monitor.c | 402 +++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 620 ++++++++++++++++-- arch/x86/kernel/cpu/scattered.c | 1 + include/linux/resctrl.h | 34 +- 12 files changed, 1350 insertions(+), 84 deletions(-)
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 1/23 x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
resctrl_late_init() has the __init attribute, but some of the functions called from it do not have the __init attribute.
Add the __init attribute to all the functions in the call sequences to maintain consistency throughout.
---
v11: No changes.
v10: Text changes.
Added __init attribute to cache_alloc_hsw_probe() Followed function prototype rules (preferred order is storage class before return type).
v9: Moved the patch to the begining of the series.
Fixed all the call sequences. Added additional Fixed tags.
v8: New patch.
--- arch/x86/kernel/cpu/resctrl/core.c | 10 +++++----- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +5 -5
@@ -145,7 +145,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)* is always 20 on hsw server parts. The minimum cache bitmask length * allowed for HSW server is always 2 bits. Hardcode all of them. */ -static inline void cache_alloc_hsw_probe (void ) +static inline __init void cache_alloc_hsw_probe (void ) {struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3 ];struct rdt_resource *r = &hw_res->r_resctrl;
@@ -277,7 +277,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)return true; } -static void rdt_get_cache_alloc_cfg (int idx,struct rdt_resource *r) +static __init void rdt_get_cache_alloc_cfg (int idx,struct rdt_resource *r) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r);union cpuid_0x10_1_eax eax;
@@ -296,7 +296,7 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r) r->alloc_capable = true; } -static void rdt_get_cdp_config (int level) +static __init void rdt_get_cdp_config (int level) {/* * By default, CDP is disabled. CDP can be enabled by mount parameter
@@ -306,12 +306,12 @@ static void rdt_get_cdp_config(int level) rdt_resources_all[level].r_resctrl.cdp_capable = true; } -static void rdt_get_cdp_l3_config (void ) +static __init void rdt_get_cdp_l3_config (void ) {rdt_get_cdp_config (RDT_RESOURCE_L3 ); } -static void rdt_get_cdp_l2_config (void ) +static __init void rdt_get_cdp_l2_config (void ) {rdt_get_cdp_config (RDT_RESOURCE_L2 ); }
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
@@ -634,7 +634,7 @@ int closids_supported(void);void closid_free (int closid);int alloc_rmid (u32 closid);void free_rmid (u32 closid,u32 rmid); -int rdt_get_mon_l3_config (struct rdt_resource *r); +int __init rdt_get_mon_l3_config (struct rdt_resource *r); void __exit rdt_put_mon_l3_config(void);bool __init rdt_cpu_has (int flag);void mon_event_count (void *info);
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -979,7 +979,7 @@ void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long delay_schedule_delayed_work_on (cpu, &dom->mbm_over, delay); } -static int dom_data_init (struct rdt_resource *r) +static __init int dom_data_init (struct rdt_resource *r) {u32 idx_limit =resctrl_arch_system_num_rmid_idx ();u32 num_closid =resctrl_arch_get_num_closid (r);
@@ -1077,7 +1077,7 @@ static struct mon_evt mbm_local_event = {* because as per the SDM the total and local memory bandwidth * are enumerated as part of L3 monitoring. */ -static void l3_mon_evt_init (struct rdt_resource *r) +static __init void l3_mon_evt_init (struct rdt_resource *r) {INIT_LIST_HEAD (&r->evt_list);
Signature · 1 line
2.34.1
Re: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Hi Babu,
Quoted 6 lines · Babu Moger
resctrl_late_init()has the__initattribute, but some of the functions called from it do not have the__initattribute.Add the
__initattribute to all the functions in the call sequences to maintain consistency throughout.
Quoted 6 lines
Fixes 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")Fixes def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")Fixes bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")Suggested-by Reinette Chatre <[email protected]>Signed-off-by Babu Moger <[email protected]>---
Thank you.
Reinette
Dave Martin
reviewerRe: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
In reply to Babu MogerHi,
Quoted 5 lines · Babu Moger
resctrl_late_init()has the__initattribute, but some of the functions called from it do not have the__initattribute.Add the
__initattribute to all the functions in the call sequences to maintain consistency throughout.
(BTW, did you just find these cases by inspection, or were you getting build warnings?
Even with CONFIG_DEBUG_SECTION_MISMATCH=y, I struggle to get build warnings about section mismatches on inlined functions. Even building with -fno-inline doesn't flag them all up (though I don't think this suppresses all inlining).
If you have a way of tracking these cases down automatically, I'd be interested to know so that I can apply it elsewhere.)
Cheers
---Dave
Quoted 7 lines
Fixes 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")Fixes def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")Fixes bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")Suggested-by Reinette Chatre <[email protected]>Signed-off-by Babu Moger <[email protected]>---
[...]
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1@@ -145,7 +145,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)* is always 20 on hsw server parts. The minimum cache bitmask length * allowed for HSW server is always 2 bits. Hardcode all of them. */ -static inline void cache_alloc_hsw_probe (void ) +static inline __init void cache_alloc_hsw_probe (void ) {struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3 ];struct rdt_resource *r = &hw_res->r_resctrl;@@ -277,7 +277,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
[...]
Moger, Babu
reviewerRe: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Hi Dave,
Quoted 12 lines · Dave Martin
Hi,
Quoted 5 lines · Babu Moger
resctrl_late_init()has the__initattribute, but some of the functions called from it do not have the__initattribute.Add the
__initattribute to all the functions in the call sequences to maintain consistency throughout.(BTW, did you just find these cases by inspection, or were you getting build warnings?
Quoted 7 lines
Even with
CONFIG_DEBUG_SECTION_MISMATCH=y, I struggle to get build warnings about section mismatches on inlined functions. Even building with -fno-inline doesn't flag them all up (though I don't think this suppresses all inlining).If you have a way of tracking these cases down automatically, I'd be interested to know so that I can apply it elsewhere.)
It is mostly by code inspection at this point.
You can refer to this commit [1].
We used to see section mismatch warnings when non-init functions call __init functions.
MODPOST Module.symvers
WARNING: modpost: vmlinux: section mismatch in reference:rdt_get_mon_l3_config+0x2b5 (section: .text) -> rdt_cpu_has (section:
.init.text)
WARNING: modpost: vmlinux: section mismatch in reference:rdt_get_mon_l3_config+0x408 (section: .text) -> rdt_cpu_has (section:
.init.text)
Quoted 32 lines
Cheers
---DaveQuoted 7 lines
Fixes 6a445edce657 ("x86/intel_rdt/cqm: Add RDT monitoring initialization")Fixes def10853930a ("x86/intel_rdt: Add two new resources for L2 Code and Data Prioritization (CDP)")Fixes bd334c86b5d7 ("x86/resctrl: Add __init attribute to rdt_get_mon_l3_config()")Suggested-by Reinette Chatre <[email protected]>Signed-off-by Babu Moger <[email protected]>---
[...]
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1@@ -145,7 +145,7 @@ u32 resctrl_arch_system_num_rmid_idx(void)* is always 20 on hsw server parts. The minimum cache bitmask length * allowed for HSW server is always 2 bits. Hardcode all of them. */ -static inline void cache_alloc_hsw_probe (void ) +static inline __init void cache_alloc_hsw_probe (void ) {struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3 ];struct rdt_resource *r = &hw_res->r_resctrl;@@ -277,7 +277,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)[...]
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerRe: [PATCH v11 01/23] x86/resctrl: Add __init attribute to functions called from resctrl_late_init()
Hi,
Quoted 39 lines · Babu
Hi Dave,
Quoted 12 lines · Dave Martin
Hi,
Quoted 5 lines · Babu Moger
resctrl_late_init()has the__initattribute, but some of the functions called from it do not have the__initattribute.Add the
__initattribute to all the functions in the call sequences to maintain consistency throughout.(BTW, did you just find these cases by inspection, or were you getting build warnings?
Quoted 7 lines
Even with
CONFIG_DEBUG_SECTION_MISMATCH=y, I struggle to get build warnings about section mismatches on inlined functions. Even building with -fno-inline doesn't flag them all up (though I don't think this suppresses all inlining).If you have a way of tracking these cases down automatically, I'd be interested to know so that I can apply it elsewhere.)
It is mostly by code inspection at this point.
You can refer to this commit [1].
We used to see section mismatch warnings when non-init functions call
__initfunctions.MODPOST Module.symvers
WARNING: modpost: vmlinux: section mismatch in reference:rdt_get_mon_l3_config+0x2b5(section: .text) ->rdt_cpu_has(section:
.init.text)
WARNING: modpost: vmlinux: section mismatch in reference:rdt_get_mon_l3_config+0x408(section: .text) ->rdt_cpu_has(section:
.init.text)
Quoted 2 lines
Right.
No problem with this patch, but I'll bear in mind for the future that CONFIG_DEBUG_SECTION_MISMATCH has limitations...
Cheers
---Dave
Babu Moger
reviewerPATCH v11 2/23 x86/cpufeatures: Add support for Assignable Bandwidth Monitoring Counters (ABMC)
In reply to Babu MogerUsers 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 for certain point of time. Users do not have the option to monitor a group or set of groups for certain period of time without worrying about RMID being reset in between.
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually. There is no need to worry about counters being reset during this period. Additionally, the user can specify a bitmask identifying the specific bandwidth types from the given source to track with the counter.
Without ABMC enabled, monitoring will work in current mode without assignment option.
Linux resctrl subsystem provides the interface to count maximum of two memory bandwidth events per group, from a combination of available total and local events. Keeping the current interface, users can enable a maximum of 2 ABMC counters per group. User will also have the option to enable only one counter to the group. If the system runs out of assignable ABMC counters, kernel will display an error. Users need to disable an already enabled counter to make space for new assignments.
The feature can be 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.
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/cpuid-deps.c | 3 +++ arch/x86/kernel/cpu/scattered.c | 1 + 3 files changed, 5 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -483,6 +483,7 @@#define X86_FEATURE_AMD_FAST_CPPC (21*32 + 5)/* Fast CPPC */ #define X86_FEATURE_AMD_HETEROGENEOUS_CORES (21*32 + 6)/* Heterogeneous Core Topology */ #define X86_FEATURE_AMD_WORKLOAD_CLASS (21*32 + 7)/* Workload Classification */ +#define X86_FEATURE_ABMC (21*32 + 8)/* Assignable Bandwidth Monitoring Counters */ /* * BUG word(s)
arch/x86/kernel/cpu/cpuid-deps.c +3 -0
@@ -70,6 +70,9 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_CQM_MBM_LOCAL, X86_FEATURE_CQM_LLC }, { X86_FEATURE_BMEC, X86_FEATURE_CQM_MBM_TOTAL }, { X86_FEATURE_BMEC, X86_FEATURE_CQM_MBM_LOCAL }, + { X86_FEATURE_ABMC, X86_FEATURE_CQM_MBM_TOTAL }, + { X86_FEATURE_ABMC, X86_FEATURE_CQM_MBM_LOCAL }, + { X86_FEATURE_ABMC, X86_FEATURE_BMEC }, { X86_FEATURE_AVX512_BF16, X86_FEATURE_AVX512VL }, { X86_FEATURE_AVX512_FP16, X86_FEATURE_AVX512BW }, { X86_FEATURE_ENQCMD, X86_FEATURE_XSAVES },
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -49,6 +49,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_AMD_WORKLOAD_CLASS, CPUID_EAX, 22, 0x80000021, 0 }, { X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 },
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 3/23 x86/resctrl: Add ABMC feature in the command line options
In reply to Babu MogerAdd the command line option to enable or disable exposing the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature to resctrl.
---
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/arch/x86/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
@@ -5854,7 +5854,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/arch/x86/resctrl.rst +1 -0
@@ -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
@@ -811,6 +811,7 @@ enum {RDT_FLAG_MBA ,RDT_FLAG_SMBA ,RDT_FLAG_BMEC , + RDT_FLAG_ABMC, };#define RDT_OPT (idx, n, f) \
@@ -836,6 +837,7 @@ static struct rdt_options rdt_options[] __initdata = {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
Babu Moger
reviewerPATCH v11 4/23 x86/resctrl: Consolidate monitoring related data from rdt_resource
In reply to Babu MogerThe 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.
---
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 | 18 +++++++++--------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 ++++---- include/linux/resctrl.h | 16 ++++++++++++---- 4 files changed, 27 insertions(+), 19 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +2 -2
@@ -124,7 +124,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; }/*
@@ -627,7 +627,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 +9 -9
@@ -222,7 +222,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)
@@ -297,11 +297,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *if (is_mbm_total_enabled ())memset (hw_dom->arch_mbm_total,0 , -sizeof (*hw_dom->arch_mbm_total) * r->num_rmid); +sizeof (*hw_dom->arch_mbm_total) * r->mon.num_rmid);if (is_mbm_local_enabled ())memset (hw_dom->arch_mbm_local,0 , -sizeof (*hw_dom->arch_mbm_local) * r->num_rmid); +sizeof (*hw_dom->arch_mbm_local) * r->mon.num_rmid); }static u64 mbm_overflow_count (u64 prev_msr,u64 cur_msr,unsigned int width)
@@ -1079,14 +1079,14 @@ static struct mon_evt mbm_local_event = {*/ static __init void l3_mon_evt_init (struct rdt_resource *r) { -INIT_LIST_HEAD (&r->evt_list); +INIT_LIST_HEAD (&r->mon.evt_list);if (is_llc_occupancy_enabled ()) -list_add_tail (&llc_occupancy_event.list, &r->evt_list); +list_add_tail (&llc_occupancy_event.list, &r->mon.evt_list);if (is_mbm_total_enabled ()) -list_add_tail (&mbm_total_event.list, &r->evt_list); +list_add_tail (&mbm_total_event.list, &r->mon.evt_list);if (is_mbm_local_enabled ()) -list_add_tail (&mbm_local_event.list, &r->evt_list); +list_add_tail (&mbm_local_event.list, &r->mon.evt_list); }/*
@@ -1183,7 +1183,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 )
@@ -1198,7 +1198,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
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -4
@@ -1106,7 +1106,7 @@ static int rdt_num_rmids_show(struct kernfs_open_file *of, {struct rdt_resource *r = of->kn->parent->priv; -seq_printf (seq,"%d\n" , r->num_rmid); +seq_printf (seq,"%d\n" , r->mon.num_rmid);return 0 ; }
@@ -1117,7 +1117,7 @@ static int rdt_mon_features_show(struct kernfs_open_file *of,struct rdt_resource *r = of->kn->parent->priv;struct mon_evt *mevt; -list_for_each_entry (mevt, &r->evt_list, list) { +list_for_each_entry (mevt, &r->mon.evt_list, list) {seq_printf (seq,"%s\n" , mevt->name);if (mevt->configurable)seq_printf (seq,"%s_config\n" , mevt->name);
@@ -3068,13 +3068,13 @@ static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain *d,struct mon_evt *mevt;int ret; -if (WARN_ON (list_empty (&r->evt_list))) +if (WARN_ON (list_empty (&r->mon.evt_list)))return -EPERM ; priv.u.rid = r->rid; priv.u.domid = do_sum ? d->ci->id : d->hdr.id; priv.u.sum = do_sum; -list_for_each_entry (mevt, &r->evt_list, list) { +list_for_each_entry (mevt, &r->mon.evt_list, list) { priv.u.evtid = mevt->evtid; ret =mon_addfile (kn, mevt->name, priv.priv);if (ret)
include/linux/resctrl.h +12 -4
@@ -182,16 +182,26 @@ enum resctrl_scope { RESCTRL_L3_NODE, }; +/** +* struct resctrl_mon - Monitoring related data of a resctrl resource +* @num_rmid: Number of RMIDs available +* @evt_list: List of monitoring events +*/ +struct resctrl_mon { +int num_rmid; +struct list_head evt_list; +}; +/** * 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.
@@ -199,7 +209,6 @@ enum resctrl_scope {* @default_ctrl: Specifies default cache cbm or memory B/W percent. * @format_str: Per resource format string to show domain value * @parse_ctrlval: Per resource function pointer to parse control values -* @evt_list: List of monitoring events * @fflags: flags to choose base and info files * @cdp_capable: Is the CDP feature available on this resource */
@@ -207,11 +216,11 @@ 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;
@@ -221,7 +230,6 @@ struct rdt_resource {int (*parse_ctrlval)(struct rdt_parse_data *data,struct resctrl_schema *s,struct rdt_ctrl_domain *d); -struct list_head evt_list;unsigned long fflags;bool cdp_capable; };
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 5/23 x86/resctrl: Detect Assignable Bandwidth Monitoring feature details
In reply to Babu MogerABMC 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 monitoring counters supported.
---
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/monitor.c | 6 ++++++ include/linux/resctrl.h | 4 ++++ 2 files changed, 10 insertions(+)
arch/x86/kernel/cpu/resctrl/monitor.c +6 -0
@@ -1228,6 +1228,12 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)resctrl_file_fflags_init ("mbm_local_bytes_config" ,RFTYPE_MON_INFO |RFTYPE_RES_CACHE ); } + +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 ; + } }l3_mon_evt_init (r);
include/linux/resctrl.h +4 -0
@@ -185,10 +185,14 @@ enum resctrl_scope {/** * struct resctrl_mon - Monitoring related data of a resctrl resource * @num_rmid: Number of RMIDs available +* @num_mbm_cntrs: Number of assignable monitoring counters +* @mbm_cntr_assignable:Is system capable of supporting monitor assignment? * @evt_list: List of monitoring events */ struct resctrl_mon {int num_rmid; +int num_mbm_cntrs; +bool mbm_cntr_assignable;struct list_head evt_list; };
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 6/23 x86/resctrl: Add support to enable/disable AMD ABMC feature
In reply to Babu MogerAdd 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).
---
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/core.c | 5 ++++ arch/x86/kernel/cpu/resctrl/internal.h | 7 +++++ arch/x86/kernel/cpu/resctrl/monitor.c | 36 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1197,6 +1197,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/core.c +5 -0
@@ -405,6 +405,11 @@ void rdt_ctrl_update(void *arg) hw_res->msr_update (m); } +bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r) +{ +return resctrl_to_arch_res (r)->mbm_cntr_assign_enabled; +} +/* * rdt_find_domain - Search for a domain id in a resource domain list. *
arch/x86/kernel/cpu/resctrl/internal.h +7 -0
@@ -56,6 +56,9 @@/* Max event bits supported */ #define MAX_EVT_CONFIG_BITS GENMASK(6, 0) +/* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */ +#define ABMC_ENABLE_BIT 0 +/** * cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that * aren't marked nohz_full
@@ -479,6 +482,7 @@ struct rdt_parse_data {* @mbm_cfg_mask: Bandwidth sources that can be tracked when Bandwidth * Monitoring Event Configuration (BMEC) is supported. * @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.
@@ -493,6 +497,7 @@ struct rdt_hw_resource {unsigned int mbm_width;unsigned int mbm_cfg_mask;bool cdp_enabled; +bool mbm_cntr_assign_enabled; };static inline struct rdt_hw_resource *resctrl_to_arch_res (struct rdt_resource *r)
@@ -658,4 +663,6 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags);void rdt_staged_configs_clear (void );bool closid_allocated (unsigned int closid);int resctrl_find_cleanest_closid (void ); +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable); +bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +36 -0
@@ -1261,3 +1261,39 @@ void __init intel_rdt_mbm_apply_quirk(void) mbm_cf_rmidthreshold = mbm_cf_table[cf_index].rmidthreshold; mbm_cf = mbm_cf_table[cf_index].cf; } + +static void resctrl_abmc_set_one_amd (void *arg) +{ +bool *enable = arg; + +if (*enable) +msr_set_bit (MSR_IA32_L3_QOS_EXT_CFG ,ABMC_ENABLE_BIT ); +else +msr_clear_bit (MSR_IA32_L3_QOS_EXT_CFG ,ABMC_ENABLE_BIT ); +} + +/* +* Update L3_QOS_EXT_CFG MSR on all the CPUs associated with the monitor +* domain. +*/ +static void _resctrl_abmc_enable (struct rdt_resource *r,bool enable) +{ +struct rdt_mon_domain *d; + +list_for_each_entry (d, &r->mon_domains, hdr.list) +on_each_cpu_mask (&d->hdr.cpu_mask, + resctrl_abmc_set_one_amd, &enable,1 ); +} + +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable) +{ +struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); + +if (r->mon.mbm_cntr_assignable && + hw_res->mbm_cntr_assign_enabled != enable) { +_resctrl_abmc_enable (r, enable); + hw_res->mbm_cntr_assign_enabled = enable; + } + +return 0 ; +}
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
Hi Babu,
Quoted 7 lines · 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.
I find that the state management in this series is organized better and easier to understand. I do think that it can be simplified more and a hint to this is that it is mentioned here but not done in the code introduced here but instead required from the caller. It seems simpler to me that the architectural state can just be reset at the same time as enable/disable of ABMC?
Quoted 9 lines
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).---
...
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-0@@ -1261,3 +1261,39 @@ void __init intel_rdt_mbm_apply_quirk(void) mbm_cf_rmidthreshold = mbm_cf_table[cf_index].rmidthreshold; mbm_cf = mbm_cf_table[cf_index].cf; } + +static void resctrl_abmc_set_one_amd (void *arg) +{ +bool *enable = arg;
arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1277
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+ +if (*enable) +msr_set_bit (MSR_IA32_L3_QOS_EXT_CFG ,ABMC_ENABLE_BIT ); +else +msr_clear_bit (MSR_IA32_L3_QOS_EXT_CFG ,ABMC_ENABLE_BIT ); +} + +/* +* Update L3_QOS_EXT_CFG MSR on all the CPUs associated with the monitor +* domain.
All monitor domains are impacted and above does not clearly state "why". How about
* ABMC enable/disable requires update of L3_QOS_EXT_CFG MSR on all the CPUs
* associated with all monitor domains.
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c +8
-0+*/ +static void _resctrl_abmc_enable (struct rdt_resource *r,bool enable) +{ +struct rdt_mon_domain *d; + +list_for_each_entry (d, &r->mon_domains, hdr.list) +on_each_cpu_mask (&d->hdr.cpu_mask, + resctrl_abmc_set_one_amd, &enable,1 );
arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1295
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+} + +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable) +{ +struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); + +if (r->mon.mbm_cntr_assignable && + hw_res->mbm_cntr_assign_enabled != enable) { +_resctrl_abmc_enable (r, enable); + hw_res->mbm_cntr_assign_enabled = enable;
Added benefit of resetting architectural state within this if statement (perhaps simpler to be done within _resctrl_abmc_enable()) is that it will not be done unnecessarily if ABMC is already in requested state.
arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1299
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-0+ } + +return 0 ; +}
Reinette
Re: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
Hi Reinette,
Quoted 9 lines · Reinette Chatre
Hi Babu,
Quoted 6 lines · 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.
Quoted 8 lines
Quoted 1 line
Hardware counters will reset when ABMC state is changed.
I find that the state management in this series is organized better and easier to understand. I do think that it can be simplified more and a hint to this is that it is mentioned here but not done in the code introduced here but instead required from the caller. It seems simpler to me that the architectural state can just be reset at the same time as enable/disable of ABMC?
Right now, it is done from mbm_cntr_reset(). It does both arch and non-arch state reset for all the RMIDs in all the domains. It is called in two places.
1 rdtgroup.c resctrl_mbm_assign_mode_write -> mbm_cntr_reset(); 2 rdtgroup.c rdt_kill_sb()-> mbm_cntr_reset();
I will have to introduce another function to reset RMIDs in all the domains. Also, make sure it is called from both these places.
list_for_each_entry(dom, &r->mon_domains, hdr.list)
resctrl_arch_reset_rmid_all(r, dom);
I feel current code is much more cleaner. What do you think?
Quoted 32 lines
Quoted 10 lines
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).---
...
Quoted 19 lines
arch/x86/kernel/cpu/resctrl/monitor.c +11
-0@@ -1261,3 +1261,39 @@ void __init intel_rdt_mbm_apply_quirk(void) mbm_cf_rmidthreshold = mbm_cf_table[cf_index].rmidthreshold; mbm_cf = mbm_cf_table[cf_index].cf; } + +static void resctrl_abmc_set_one_amd (void *arg) +{ +bool *enable = arg; + +if (*enable) +msr_set_bit (MSR_IA32_L3_QOS_EXT_CFG ,ABMC_ENABLE_BIT ); +else +msr_clear_bit (MSR_IA32_L3_QOS_EXT_CFG ,ABMC_ENABLE_BIT ); +} +
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1277
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3
-0+/* +* Update L3_QOS_EXT_CFG MSR on all the CPUs associated with the monitor +* domain. All monitor domains are impacted and above does not clearly state "why". How about
* ABMC enable/disable requires update ofL3_QOS_EXT_CFGMSR on all the CPUs
* associated with all monitor domains.
Sure.
Quoted 16 lines
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/monitor.c +14
-0+*/ +static void _resctrl_abmc_enable (struct rdt_resource *r,bool enable) +{ +struct rdt_mon_domain *d; + +list_for_each_entry (d, &r->mon_domains, hdr.list) +on_each_cpu_mask (&d->hdr.cpu_mask, + resctrl_abmc_set_one_amd, &enable,1 ); +} + +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable) +{ +struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); +
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1295
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-0+if (r->mon.mbm_cntr_assignable && + hw_res->mbm_cntr_assign_enabled != enable) { +_resctrl_abmc_enable (r, enable); + hw_res->mbm_cntr_assign_enabled = enable;Added benefit of resetting architectural state within this if statement (perhaps simpler to be done within
_resctrl_abmc_enable()) is that it will not be done unnecessarily if ABMC is already in requested state.
It will be
list_for_each_entry(dom, &r->mon_domains, hdr.list)
resctrl_arch_reset_rmid_all(r, dom);Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1299
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-0+ } + +return 0 ; +}Reinette
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
Hi Babu,
Quoted 21 lines · Babu
Hi Reinette,
Quoted 9 lines · Reinette Chatre
Hi Babu,
Quoted 6 lines · 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.Quoted 8 lines
Quoted 1 line
Hardware counters will reset when ABMC state is changed.
I find that the state management in this series is organized better and easier to understand. I do think that it can be simplified more and a hint to this is that it is mentioned here but not done in the code introduced here but instead required from the caller. It seems simpler to me that the architectural state can just be reset at the same time as enable/disable of ABMC?
Quoted 3 lines
Right now, it is done from
mbm_cntr_reset(). It does both arch and non-arch state reset for all the RMIDs in all the domains. It is called in two places.1
rdtgroup.cresctrl_mbm_assign_mode_write->mbm_cntr_reset();
Please see my response to this usage in the related patch:
https://lore.kernel.org/lkml/[email protected]/
In summary, I find mbm_cntr_reset() ended up being a catch-all for random cleanup and creates confusion with the other mbm_cntr_*() calls.
Quoted 1 line
2
rdtgroup.crdt_kill_sb()->mbm_cntr_reset();
Please see my response to this usage in the related patch:
https://lore.kernel.org/lkml/[email protected]/
In summary, it does not solve the problem it originally set out to solve and it can be eliminated.
Quoted 5 lines
I will have to introduce another function to reset RMIDs in all the domains. Also, make sure it is called from both these places.
list_for_each_entry(dom, &r->mon_domains, hdr.list)resctrl_arch_reset_rmid_all(r, dom);
I do not see need for new functions, except the one I mention in
https://lore.kernel.org/lkml/[email protected]/
that suggests a new helper for reset of architectural state that does not exist and ends up being open coded in two places in this series.
With only one place (resctrl_mbm_assign_mode_write()) remaining that needs all state reset I think it will be easier to understand if the state reset is open coded within it, replacing mbm_cntr_reset() with:
list_for_each_entry(dom, &r->mon_domains, hdr.list) {
mbm_cntr_free_all()
resctrl_reset_rmid_all() // Just for architectural state
}I would not insist on reset of architectural state within the architectural helper. I find that it is best for architecture to maintain its state but I also see there are many precedent for resctrl explicitly managing the state.
Quoted 1 line
I feel current code is much more cleaner. What do you think?
It is better that previous versions, yes.
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
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).---
...
...
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
+ */
arch/x86/kernel/cpu/resctrl/monitor.c +13
-0+static void _resctrl_abmc_enable (struct rdt_resource *r,bool enable) +{ + struct rdt_mon_domain *d; + + list_for_each_entry(d, &r->mon_domains, hdr.list) + on_each_cpu_mask(&d->hdr.cpu_mask, + resctrl_abmc_set_one_amd, &enable, 1); +} + +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable) +{ + struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); +Quoted 8 lines
Quoted 4 lines
+ if (
r->mon.mbm_cntr_assignable&&
+hw_res->mbm_cntr_assign_enabled!= enable) { +_resctrl_abmc_enable(r, enable);
+hw_res->mbm_cntr_assign_enabled= enable;Added benefit of resetting architectural state within this if statement (perhaps simpler to be done within
_resctrl_abmc_enable()) is that it will not be done unnecessarily if ABMC is already in requested state.
Quoted 3 lines
It will be
list_for_each_entry(dom, &r->mon_domains, hdr.list)resctrl_arch_reset_rmid_all(r, dom);
I am not sure if you are actually planning a new loop here ... as I suggested above this can be added to _resctrl_abmc_enable() where there is already a loop over all monitor domains and all that is needed is to add a call to resctrl_arch_reset_rmid_all(r, dom). Even so, as I mentioned above, if after fixing automatic counter unassignment you still find that resetting architectural and non-architectural state together then we can go with that to match the other flows (eg. mbm_config_write_domain()).
Reinette
Re: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
Hi Reinette,
Lots of things in here.
Quoted 24 lines · Reinette Chatre
Hi Babu,
Quoted 21 lines · Babu
Hi Reinette,
Quoted 17 lines · Reinette Chatre
Hi Babu,
Quoted 7 lines · 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.
I find that the state management in this series is organized better and easier to understand. I do think that it can be simplified more and a hint to this is that it is mentioned here but not done in the code introduced here but instead required from the caller. It seems simpler to me that the architectural state can just be reset at the same time as enable/disable of ABMC?
Quoted 7 lines
Quoted 3 lines
Right now, it is done from
mbm_cntr_reset(). It does both arch and non-arch state reset for all the RMIDs in all the domains. It is called in two places.1
rdtgroup.cresctrl_mbm_assign_mode_write->mbm_cntr_reset();Please see my response to this usage in the related patch:
https://lore.kernel.org/lkml/[email protected]/
In summary, I findmbm_cntr_reset()ended up being a catch-all for random cleanup and creates confusion with the other mbm_cntr_*() calls.
Yes. It should work. Will respond that comment later.
Quoted 5 lines
Quoted 1 line
2
rdtgroup.crdt_kill_sb()->mbm_cntr_reset();Please see my response to this usage in the related patch:
https://lore.kernel.org/lkml/[email protected]/
In summary, it does not solve the problem it originally set out to solve and it can be eliminated.
Yes. Should be fine. mbm_cntr_reset() can be completely removed. Will respond that comment later.
Quoted 12 lines
Quoted 6 lines
I will have to introduce another function to reset RMIDs in all the domains. Also, make sure it is called from both these places.
list_for_each_entry(dom, &r->mon_domains, hdr.list)
resctrl_arch_reset_rmid_all(r, dom);I do not see need for new functions, except the one I mention in
https://lore.kernel.org/lkml/[email protected]/
that suggests a new helper for reset of architectural state that does not exist and ends up being open coded in two places in this series.
Quoted 8 lines
With only one place (
resctrl_mbm_assign_mode_write()) remaining that needs all state reset I think it will be easier to understand if the state reset is open coded within it, replacingmbm_cntr_reset()with:list_for_each_entry(dom, &r->mon_domains, hdr.list) { mbm_cntr_free_all() resctrl_reset_rmid_all() // Just for architectural state }
You meant "Just for non-architectural state" ?
Quoted 49 lines
I would not insist on reset of architectural state within the architectural helper. I find that it is best for architecture to maintain its state but I also see there are many precedent for resctrl explicitly managing the state.
Quoted 1 line
I feel current code is much more cleaner. What do you think?
It is better that previous versions, yes.
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
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).---
...
...
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
+ */
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0+static void _resctrl_abmc_enable (struct rdt_resource *r,bool enable) +{ + struct rdt_mon_domain *d; + + list_for_each_entry(d, &r->mon_domains, hdr.list) + on_each_cpu_mask(&d->hdr.cpu_mask, + resctrl_abmc_set_one_amd, &enable, 1);arch/x86/kernel/cpu/resctrl/monitor.c void __init intel_rdt_mbm_apply_quirk(void) · line 1295
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+} + +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable) +{ + struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); + + if (r->mon.mbm_cntr_assignable && + hw_res->mbm_cntr_assign_enabled != enable) { + _resctrl_abmc_enable(r, enable); + hw_res->mbm_cntr_assign_enabled = enable;Added benefit of resetting architectural state within this if statement (perhaps simpler to be done within
_resctrl_abmc_enable()) is that it will not be done unnecessarily if ABMC is already in requested state.
Quoted 8 lines
Quoted 3 lines
It will be
list_for_each_entry(dom, &r->mon_domains, hdr.list)resctrl_arch_reset_rmid_all(r, dom);I am not sure if you are actually planning a new loop here ... as I suggested above this can be added to
_resctrl_abmc_enable()where there is already a loop over all monitor domains and all that is needed is to add a call toresctrl_arch_reset_rmid_all(r, dom).
Sure.
Quoted 5 lines
Even so, as I mentioned above, if after fixing automatic counter unassignment you still find that resetting architectural and non-architectural state together then we can go with that to match the other flows (eg.
mbm_config_write_domain()).
Sure.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
Hi Babu,
Quoted 21 lines · Babu
Quoted 20 lines · Reinette Chatre
Quoted 9 lines · Babu
Quoted 1 line · Reinette Chatre
On 1/22/25 12:20 PM, Babu Moger wrote:
I will have to introduce another function to reset RMIDs in all the domains. Also, make sure it is called from both these places.
list_for_each_entry(dom, &r->mon_domains, hdr.list)resctrl_arch_reset_rmid_all(r, dom);I do not see need for new functions, except the one I mention in
https://lore.kernel.org/lkml/[email protected]/
that suggests a new helper for reset of architectural state that does not exist and ends up being open coded in two places in this series.With only one place (
resctrl_mbm_assign_mode_write()) remaining that needs all state reset I think it will be easier to understand if the state reset is open coded within it, replacingmbm_cntr_reset()with:
Quoted 6 lines
Quoted 4 lines
list_for_each_entry(dom,
&r->mon_domains, hdr.list) {mbm_cntr_free_all()
resctrl_reset_rmid_all()// Just for architectural state }You meant "Just for non-architectural state" ?
Yes, thank you, what a confusion causing typo.
Reinette
James Morse
reviewerRe: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
In reply to Babu MogerHi Babu,
Quoted 19 lines · 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).arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h void resctrl_file_fflags_init(const char *config, unsigned long fflags); · line 668
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -658,4 +663,6 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags);void rdt_staged_configs_clear (void );bool closid_allocated (unsigned int closid);int resctrl_find_cleanest_closid (void ); +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable); +bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
A minor nit - but could these be added to include/linux/resctrl.h instead? This is where they need to end up after the arch/fs split, and its harmless to do it from the beginning.
Thanks,
James
Reinette Chatre
maintainerRe: [PATCH v11 06/23] x86/resctrl: Add support to enable/disable AMD ABMC feature
Hi James,
Quoted 17 lines · James Morse
Hi Babu,
Quoted 12 lines · 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).
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/internal.h void resctrl_file_fflags_init(const char *config, unsigned long fflags); · line 668
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -658,4 +663,6 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags);void rdt_staged_configs_clear (void );bool closid_allocated (unsigned int closid);int resctrl_find_cleanest_closid (void ); +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable); +bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ A minor nit - but could these be added to
include/linux/resctrl.hinstead? This is where they need to end up after thearch/fssplit, and its harmless to do it from the beginning.
These prototypes were moved back to the internal header to follow guidance from Boris that was received during recent software controller enhancement. Boris advised [1] that items needed by other architecture should only be moved to include/linux/resctrl.h when that support is added.
Reinette
[1] https://lore.kernel.org/lkml/20241209222047.GKZ1dtPxIu5_Hxs1fp@fat_crate.local/
Babu Moger
reviewerPATCH v11 7/23 x86/resctrl: Introduce the interface to display monitor mode
In reply to Babu MogerIntroduce the interface file "mbm_assign_mode" to list monitor modes supported.
The "mbm_cntr_assign" mode provides the option to assign a counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.
On AMD systems "mbm_cntr_assign" is backed by the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature and is enabled by default.
The "default" mode is the existing monitoring 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 mode on the system.
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] default
---
v11: Renamed rdtgroup_mbm_assign_mode_show() to resctrl_mbm_assign_mode_show().
Removed few texts in resctrl.rst about AMD specific informati0n. 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/arch/x86/resctrl.rst | 26 +++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 31 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
Documentation/arch/x86/resctrl.rst +26 -0
@@ -257,6 +257,32 @@ 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": + Reports the list of monitoring modes supported. The enclosed brackets + indicate which mode is enabled. + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_cntr_assign] + default + + "mbm_cntr_assign": + + In mbm_cntr_assign, monitoring event can only accumulate data while + it is backed by a hardware counter. The user-space is able to specify + which of the events in CTRL_MON or MON groups should have a counter + assigned using the "mbm_assign_control" file. The number of counters + available is described in the "num_mbm_cntrs" file. Changing the mode + may cause all counters on a 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 mbm_cntr_assign mode if supported, because reading + "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if + there is no counter associated with that event. + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy
arch/x86/kernel/cpu/resctrl/rdtgroup.c +31 -0
@@ -854,6 +854,30 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of,return ret; } +static int resctrl_mbm_assign_mode_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{ +struct rdt_resource *r = of->kn->parent->priv; + +mutex_lock (&rdtgroup_mutex); + +if (r->mon.mbm_cntr_assignable) { +if (resctrl_arch_mbm_cntr_assign_enabled (r)) { +seq_puts (s,"[mbm_cntr_assign]\n" ); +seq_puts (s,"default\n" ); + }else { +seq_puts (s,"mbm_cntr_assign\n" ); +seq_puts (s,"[default]\n" ); + } + }else { +seq_puts (s,"[default]\n" ); + } + +mutex_unlock (&rdtgroup_mutex); + +return 0 ; +} +#ifdef CONFIG_PROC_CPU_RESCTRL /*
@@ -1910,6 +1934,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, + }, { .name = "cpus", .mode = 0644,
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 07/23] x86/resctrl: Introduce the interface to display monitor mode
Hi Babu,
Quoted 7 lines · Babu Moger
Introduce the interface file "
mbm_assign_mode" to list monitor modes supported.The "
mbm_cntr_assign" mode provides the option to assign a counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.On AMD systems "
mbm_cntr_assign" is backed by the ABMC (Assignable
""mbm_cntr_assign" is backed" -> ""mbm_cntr_assign" mode is backed"?
Quoted 31 lines
Bandwidth Monitoring Counters) hardware feature and is enabled by default.
The "default" mode is the existing monitoring 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 mode on the system.
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] defaultSigned-off-by Babu Moger <[email protected]>---
--- Documentation/arch/x86/resctrl.rst | 26 +++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 31 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)Documentation/arch/x86/resctrl.rst +2
-0@@ -257,6 +257,32 @@ 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": + Reports the list of monitoring modes supported. The enclosed brackets
Documentation/arch/x86/resctrl.rst with the following files: · line 271
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +10
-0+ indicate which mode is enabled. + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_cntr_assign] + default + + "mbm_cntr_assign": + + In mbm_cntr_assign, monitoring event can only accumulate data while
"In mbm_cntr_assign, monitoring event" -> "In mbm_cntr_assign mode, a monitoring event"?
Documentation/arch/x86/resctrl.rst with the following files: · line 283
Quoted 12 lines
Documentation/arch/x86/resctrl.rst +12
-0+ it is backed by a hardware counter. The user-space is able to specify + which of the events in CTRL_MON or MON groups should have a counter + assigned using the "mbm_assign_control" file. The number of counters + available is described in the "num_mbm_cntrs" file. Changing the mode + may cause all counters on a 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 mbm_cntr_assign mode if supported, because reading + "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if
Reinette
Re: [PATCH v11 07/23] x86/resctrl: Introduce the interface to display monitor mode
Hi Reinette,
Quoted 6 lines · Reinette Chatre
Hi Babu,
Quoted 3 lines · Babu Moger
Introduce the interface file "
mbm_assign_mode" to list monitor modes supported.
Quoted 6 lines
Quoted 4 lines
The "
mbm_cntr_assign" mode provides the option to assign a counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.On AMD systems "
mbm_cntr_assign" is backed by the ABMC (Assignable""
mbm_cntr_assign" is backed" -> ""mbm_cntr_assign" mode is backed"?
Sure.
Quoted 30 lines
Quoted 30 lines
Bandwidth Monitoring Counters) hardware feature and is enabled by default.
The "default" mode is the existing monitoring 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 mode on the system.
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] defaultSigned-off-by Babu Moger <[email protected]>---
--- Documentation/arch/x86/resctrl.rst | 26 +++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 31 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)Documentation/arch/x86/resctrl.rst +0
-0@@ -257,6 +257,32 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config 0=0x30;1=0x30;3=0x15;4=0x15
Quoted 14 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 271
Quoted 12 lines
Documentation/arch/x86/resctrl.rst +12
-0+"mbm_assign_mode": + Reports the list of monitoring modes supported. The enclosed brackets + indicate which mode is enabled. + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_cntr_assign] + default + + "mbm_cntr_assign": + + In mbm_cntr_assign, monitoring event can only accumulate data while"In
mbm_cntr_assign, monitoring event" -> "Inmbm_cntr_assignmode, a monitoring event"?
Sure.
Quoted 16 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 283
Quoted 13 lines
Documentation/arch/x86/resctrl.rst +12
-0+ it is backed by a hardware counter. The user-space is able to specify + which of the events in CTRL_MON or MON groups should have a counter + assigned using the "mbm_assign_control" file. The number of counters + available is described in the "num_mbm_cntrs" file. Changing the mode + may cause all counters on a 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 mbm_cntr_assign mode if supported, because reading + "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' ifReinette
Thanks
Babu
James Morse
reviewerRe: [PATCH v11 07/23] x86/resctrl: Introduce the interface to display monitor mode
In reply to Babu MogerHi Babu,
Quoted 42 lines · Babu Moger
Introduce the interface file "
mbm_assign_mode" to list monitor modes supported.The "
mbm_cntr_assign" mode provides the option to assign a counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.On AMD systems "
mbm_cntr_assign" is backed by the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature and is enabled by default.The "default" mode is the existing monitoring 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 mode on the system.
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] defaultDocumentation/arch/x86/resctrl.rst +15
-0@@ -257,6 +257,32 @@ 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": + Reports the list of monitoring modes supported. The enclosed brackets + indicate which mode is enabled. + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_cntr_assign] + default + + "mbm_cntr_assign": + + In mbm_cntr_assign, monitoring event can only accumulate data while + it is backed by a hardware counter. The user-space is able to specify + which of the events in CTRL_MON or MON groups should have a counter + assigned using the "mbm_assign_control" file. The number of counters
Documentation/arch/x86/resctrl.rst with the following files: · line 284
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +9
-0+ available is described in the "num_mbm_cntrs" file. Changing the mode + may cause all counters on a 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 mbm_cntr_assign mode if supported, because reading + "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if + there is no counter associated with that event.
But if you read a value instead of "Unavailable", that doesn't mean the value is correct. For two reads that succeed, the counter may have been reset in the middle.
I'm suggesting something like:
| it is recommended to use mbm_cntr_assign mode if supported, to avoid counters | being re-allocated by hardware. This can cause a misleading value to be read, | or if no counter is associated with that event "Unavailable".
Quoted 16 lines
Documentation/arch/x86/resctrl.rst +0
-0"max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancyarch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-0@@ -854,6 +854,30 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of,return ret; } +static int resctrl_mbm_assign_mode_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{ +struct rdt_resource *r = of->kn->parent->priv; +
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_rmid_show(struct kernfs_open_file *of, · line 871
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+mutex_lock (&rdtgroup_mutex); + +if (r->mon.mbm_cntr_assignable) { +if (resctrl_arch_mbm_cntr_assign_enabled (r)) { +seq_puts (s,"[mbm_cntr_assign]\n" ); +seq_puts (s,"default\n" ); + }else { +seq_puts (s,"mbm_cntr_assign\n" ); +seq_puts (s,"[default]\n" ); + }
What do you think to an architecture being able to opt-out of this flexibility?
If there aren't enough counters I can expose what the hardware has through this interface
- but if user-space turns it off ... then what?
For MPAM this would need to be some best-effort software allocation strategy that I'd rather not write - its not a problem that can be solved, and any value that is reported is likely to be wrong. For ABMC platforms, existing stable kernels expose a value, so being able to preserve the existing behaviour makes sense. MPAM doesn't have this problem.
Something like this:
----------%<----------
@@ -861,16 +861,21 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open _file *of,
struct seq_file *s, void *v)
{
struct rdt_resource *r = of->kn->parent->priv;+ bool enabled = resctrl_arch_mbm_cntr_assign_enabled(r);
mutex_lock(&rdtgroup_mutex);
if (r->mon.mbm_cntr_assignable) {
- if (resctrl_arch_mbm_cntr_assign_enabled(r)) {
+ if (enabled)
seq_puts(s, "[mbm_cntr_assign]\n");- seq_puts(s, "default\n");
- } else {
- seq_puts(s, "mbm_cntr_assign\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_cntr_assign\n");
}
} else {
seq_puts(s, "[default]\n");----------%<----------
x86 wouldn't define CONFIG_RESCTRL_ASSIGN_FIXED, arm64 would, meaning for MPAM the file would be either:
| [default]
or
| [mbm_cntr_assign]
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_rmid_show(struct kernfs_open_file *of, · line 879
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-0+ }else { +seq_puts (s,"[default]\n" ); + } + +mutex_unlock (&rdtgroup_mutex); + +return 0 ; +}
Thanks,
James
Re: [PATCH v11 07/23] x86/resctrl: Introduce the interface to display monitor mode
Hi James,
Quoted 59 lines · James Morse
Hi Babu,
Quoted 42 lines · Babu Moger
Introduce the interface file "
mbm_assign_mode" to list monitor modes supported.The "
mbm_cntr_assign" mode provides the option to assign a counter to an RMID, event pair and monitor the bandwidth as long as it is assigned.On AMD systems "
mbm_cntr_assign" is backed by the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature and is enabled by default.The "default" mode is the existing monitoring 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 mode on the system.
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] defaultDocumentation/arch/x86/resctrl.rst +15
-0@@ -257,6 +257,32 @@ 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": + Reports the list of monitoring modes supported. The enclosed brackets + indicate which mode is enabled. + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_cntr_assign] + default + + "mbm_cntr_assign": + + In mbm_cntr_assign, monitoring event can only accumulate data while + it is backed by a hardware counter. The user-space is able to specify + which of the events in CTRL_MON or MON groups should have a counter + assigned using the "mbm_assign_control" file. The number of countersDocumentation/arch/x86/resctrl.rst with the following files: · line 284
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +9
-0+ available is described in the "num_mbm_cntrs" file. Changing the mode + may cause all counters on a 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 mbm_cntr_assign mode if supported, because reading + "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if + there is no counter associated with that event.But if you read a value instead of "Unavailable", that doesn't mean the value is correct. For two reads that succeed, the counter may have been reset in the middle.
Quoted 5 lines
I'm suggesting something like:
| it is recommended to use mbm_cntr_assign mode if supported, to avoid counters | being re-allocated by hardware. This can cause a misleading value to be read, | or if no counter is associated with that event "Unavailable".
Looks good with slight modification.
On AMD platforms, it is recommended to use the mbm_cntr_assign 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 67 lines
Quoted 17 lines
Documentation/arch/x86/resctrl.rst +0
-0"max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancyarch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-0@@ -854,6 +854,30 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of,return ret; } +static int resctrl_mbm_assign_mode_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{ +struct rdt_resource *r = of->kn->parent->priv; +arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_rmid_show(struct kernfs_open_file *of, · line 871
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+mutex_lock (&rdtgroup_mutex); + +if (r->mon.mbm_cntr_assignable) { +if (resctrl_arch_mbm_cntr_assign_enabled (r)) { +seq_puts (s,"[mbm_cntr_assign]\n" ); +seq_puts (s,"default\n" ); + }else { +seq_puts (s,"mbm_cntr_assign\n" ); +seq_puts (s,"[default]\n" ); + }What do you think to an architecture being able to opt-out of this flexibility?
If there aren't enough counters I can expose what the hardware has through this interface
- but if user-space turns it off ... then what?For MPAM this would need to be some best-effort software allocation strategy that I'd rather not write - its not a problem that can be solved, and any value that is reported is likely to be wrong. For ABMC platforms, existing stable kernels expose a value, so being able to preserve the existing behaviour makes sense. MPAM doesn't have this problem.
Something like this:
----------%<----------(quoted diff) +9
-4@@ -861,16 +861,21 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open _file *of, struct seq_file *s, void *v) { struct rdt_resource *r = of->kn->parent->priv; + bool enabled = resctrl_arch_mbm_cntr_assign_enabled(r); mutex_lock(&rdtgroup_mutex); if (r->mon.mbm_cntr_assignable) { - if (resctrl_arch_mbm_cntr_assign_enabled(r)) { + if (enabled) seq_puts(s, "[mbm_cntr_assign]\n"); - seq_puts(s, "default\n"); - } else { - seq_puts(s, "mbm_cntr_assign\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_cntr_assign\n"); } } else {seq_puts(s, "[default]\n");
Quoted 8 lines
----------%<----------
x86 wouldn't define
CONFIG_RESCTRL_ASSIGN_FIXED, arm64 would, meaning for MPAM the file would be either:
| [default]
or
| [mbm_cntr_assign]
Looks good mostly.
resctrl_arch_mbm_cntr_assign_enabled(r) needs to be called with the lock.
Also, there is no reference of CONFIG_RESCTRL_ASSIGN_FIXED in this series. Hope that is not an issue.
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10 -4
@@ -858,16 +858,22 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, struct seq_file *s, void *v) { struct rdt_resource *r = of->kn->parent->priv; +bool enabled;mutex_lock (&rdtgroup_mutex); + enabled =resctrl_arch_mbm_cntr_assign_enabled (r);if (r->mon.mbm_cntr_assignable) { -if (resctrl_arch_mbm_cntr_assign_enabled (r)) { +if (enabled)seq_puts (s,"[mbm_cntr_assign]\n" ); -seq_puts (s,"default\n" ); - }else { -seq_puts (s,"mbm_cntr_assign\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_cntr_assign\n" ); } }else {seq_puts (s,"[default]\n" );
Quoted 13 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_rmid_show(struct kernfs_open_file *of, · line 879
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-0+ }else { +seq_puts (s,"[default]\n" ); + } + +mutex_unlock (&rdtgroup_mutex); + +return 0 ; +}Thanks,
Quoted 2 lines
James
Thanks
Babu
Babu Moger
reviewerPATCH v11 8/23 x86/resctrl: Introduce interface to display number of monitoring counters
In reply to Babu MogerThe mbm_cntr_assign mode provides an option to the user to assign a counter to an RMID, event pair and monitor the bandwidth as long as the counter is assigned. Number of assignments depend on number of monitoring counters available.
Provide the interface to display the number of monitoring counters supported. The resctrl file 'num_mbm_cntrs' is visible to user space when the system supports mbm_cntr_assign mode.
---
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/arch/x86/resctrl.rst | 16 ++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 1 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+)
Documentation/arch/x86/resctrl.rst +16 -0
@@ -283,6 +283,22 @@ with the following files: "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event. +"num_mbm_cntrs": + The number of monitoring counters available for assignment when the + system supports mbm_cntr_assign mode. + :: + + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs + 32 + + The resctrl file system supports tracking up to two memory bandwidth + events per monitoring group: mbm_total_bytes and/or mbm_local_bytes. + Up to two counters can be assigned per monitoring group, one for each + memory bandwidth event. More monitoring groups can be tracked by + assigning one counter per monitoring group. However, doing so limits + memory bandwidth tracking to a single memory bandwidth event per + monitoring group. + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
@@ -1233,6 +1233,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 ; +resctrl_file_fflags_init ("num_mbm_cntrs" ,RFTYPE_MON_INFO ); } }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +16 -0
@@ -878,6 +878,16 @@ 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 = of->kn->parent->priv; + +seq_printf (s,"%d\n" , r->mon.num_mbm_cntrs); + +return 0 ; +} +#ifdef CONFIG_PROC_CPU_RESCTRL /*
@@ -1941,6 +1951,12 @@ static struct rftype res_common_files[] = { .seq_show = resctrl_mbm_assign_mode_show, .fflags = RFTYPE_MON_INFO, }, + { + .name = "num_mbm_cntrs", + .mode = 0444, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = resctrl_num_mbm_cntrs_show, + }, { .name = "cpus", .mode = 0644,
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 08/23] x86/resctrl: Introduce interface to display number of monitoring counters
Hi Babu,
Quoted 11 lines · Babu Moger
The
mbm_cntr_assignmode provides an option to the user to assign a counter to an RMID, event pair and monitor the bandwidth as long as the counter is assigned. Number of assignments depend on number of monitoring counters available.Provide the interface to display the number of monitoring counters supported. The resctrl file '
num_mbm_cntrs' is visible to user space when the system supportsmbm_cntr_assignmode.Signed-off-by Babu Moger <[email protected]>---
...
Quoted 14 lines
Documentation/arch/x86/resctrl.rst +6
-0@@ -283,6 +283,22 @@ with the following files: "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event. +"num_mbm_cntrs": + The number of monitoring counters available for assignment when the + system supports mbm_cntr_assign mode. + :: + + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
Documentation/arch/x86/resctrl.rst with the following files: · line 301
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +10
-0+ 32 + + The resctrl file system supports tracking up to two memory bandwidth + events per monitoring group: mbm_total_bytes and/or mbm_local_bytes. + Up to two counters can be assigned per monitoring group, one for each + memory bandwidth event. More monitoring groups can be tracked by + assigning one counter per monitoring group. However, doing so limits + memory bandwidth tracking to a single memory bandwidth event per + monitoring group. +
This text needs an update to reflect the switch to per-domain counter assignment.
Reinette
Re: [PATCH v11 08/23] x86/resctrl: Introduce interface to display number of monitoring counters
Hi Reinette,
Quoted 35 lines · Reinette Chatre
Hi Babu,
Quoted 11 lines · Babu Moger
The
mbm_cntr_assignmode provides an option to the user to assign a counter to an RMID, event pair and monitor the bandwidth as long as the counter is assigned. Number of assignments depend on number of monitoring counters available.Provide the interface to display the number of monitoring counters supported. The resctrl file '
num_mbm_cntrs' is visible to user space when the system supportsmbm_cntr_assignmode.Signed-off-by Babu Moger <[email protected]>---
...
Quoted 18 lines
Documentation/arch/x86/resctrl.rst +10
-0@@ -283,6 +283,22 @@ with the following files: "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event. +"num_mbm_cntrs": + The number of monitoring counters available for assignment when the + system supports mbm_cntr_assign mode. + :: + + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs + 32 + + The resctrl file system supports tracking up to two memory bandwidth + events per monitoring group: mbm_total_bytes and/or mbm_local_bytes.
Quoted 8 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 301
Quoted 6 lines
Documentation/arch/x86/resctrl.rst +6
-0+ Up to two counters can be assigned per monitoring group, one for each + memory bandwidth event. More monitoring groups can be tracked by + assigning one counter per monitoring group. However, doing so limits + memory bandwidth tracking to a single memory bandwidth event per + monitoring group. +This text needs an update to reflect the switch to per-domain counter assignment.
Does this look ok? Just added domain in the text.
"The number of monitoring counters available in each domain for assignment when the system supports mbm_cntr_assign mode. ::
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32
The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group: mbm_total_bytes and/or mbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."
Thanks
Babu
Re: [PATCH v11 08/23] x86/resctrl: Introduce interface to display number of monitoring counters
Hi Reinette,
Quoted 4 lines · Babu
Does this look ok? Just added domain in the text.
"The number of monitoring counters available in each domain for assignment when the system supports
mbm_cntr_assignmode. ::
Quoted 8 lines
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group:mbm_total_bytesand/ormbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."
Revised again:
"The number of monitoring counters available in each domain for assignment when the system supports mbm_cntr_assign mode. For example, on a system with 32 monitoring counters:
::
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32
The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group: mbm_total_bytes and/or mbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v11 08/23] x86/resctrl: Introduce interface to display number of monitoring counters
Hi Babu,
Quoted 16 lines · Babu
Hi Reinette,
Quoted 4 lines · Babu
Does this look ok? Just added domain in the text.
"The number of monitoring counters available in each domain for assignment when the system supports
mbm_cntr_assignmode. ::Quoted 8 lines
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group:mbm_total_bytesand/ormbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."
Quoted 3 lines
Revised again:
"The number of monitoring counters available in each domain for assignment when the system supports
mbm_cntr_assignmode. For example, on a system with 32 monitoring counters:
I think we need to be careful with "available" since all these counters may not be available. That is why "available_mbm_cntrs" exist.
How about something like (please feel free to improve):
"The maximum number of monitoring counters (total of available and assigned counters)
in each domain when the system supports mbm_cntr_assign mode."
Could you please make the "For example" a new paragraph (this follows existing style in the docs). It could also be made more specific, for example,
"For example, on a system with 32 monitoring counters in each domain:"
Quoted 4 lines
::
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32
The rest of the documentation seems like a repeat of what can be found in the "mbm_assign_mode" section right above it. It does not look as though any information will be lost by dropping the text below?
Quoted 8 lines
The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group:mbm_total_bytesand/ormbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."Thanks
Babu
Reinette
Moger, Babu
reviewerRe: [PATCH v11 08/23] x86/resctrl: Introduce interface to display number of monitoring counters
Hi Reinette,
Quoted 21 lines · Reinette Chatre
Hi Babu,
Quoted 18 lines · Babu
Hi Reinette,
Quoted 4 lines · Babu
Does this look ok? Just added domain in the text.
"The number of monitoring counters available in each domain for assignment when the system supports
mbm_cntr_assignmode. ::Quoted 8 lines
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group:mbm_total_bytesand/ormbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."Revised again:
Quoted 8 lines
Quoted 1 line
"The number of monitoring counters available in each domain for assignment when the system supports
mbm_cntr_assignmode. For example, on a system with 32 monitoring counters:I think we need to be careful with "available" since all these counters may not be available. That is why "
available_mbm_cntrs" exist.How about something like (please feel free to improve):
"The maximum number of monitoring counters (total of available and assigned counters)
in each domain when the system supportsmbm_cntr_assignmode."
Sure.
Quoted 4 lines
Could you please make the "For example" a new paragraph (this follows existing style in the docs). It could also be made more specific, for example,
"For example, on a system with 32 monitoring counters in each domain:"
Yes.
Quoted 9 lines
Quoted 5 lines
::
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32The rest of the documentation seems like a repeat of what can be found in the "
mbm_assign_mode" section right above it. It does not look as though any information will be lost by dropping the text below?
Sure.
Quoted 12 lines
Quoted 9 lines
The resctrl file system supports tracking up to two memory bandwidth
events per monitoring group:mbm_total_bytesand/ormbm_local_bytes.
Up to two counters can be assigned per monitoring group, one for each
memory bandwidth event in each domain. More monitoring groups can be tracked by assigning one counter per monitoring group. However, doing so limits memory bandwidth tracking to a single memory bandwidth event per monitoring group."Thanks
BabuReinette
Signature · 2 lines
Thanks Babu Moger
Babu Moger
reviewerPATCH v11 9/23 x86/resctrl: Introduce mbm_total_cfg and mbm_local_cfg in struct rdt_hw_mon_domain
In reply to Babu MogerIf the BMEC (Bandwidth Monitoring Event Configuration) feature is supported, the bandwidth events can be configured to track specific events. The event configuration is domain specific. ABMC (Assignable Bandwidth Monitoring Counters) feature needs event configuration information to assign a hardware counter to an RMID. Event configurations are not stored in resctrl but instead always read from or written to hardware directly when prompted by user space.
Read the event configuration from the hardware during the domain initialization. Save the configuration value in struct rdt_hw_mon_domain, so it can be used for counter assignment.
---
v11: Resolved minor conflicts due to code displacement. Actual code didnt
change.
v10: Conflicts due to code displacement. Actual code didnt change.
v9: Added Reviewed-by tag. No other changes.
v8: Renamed resctrl_mbm_evt_config_init() to arch_mbm_evt_config_init()
Minor commit message update.
v7: Fixed initializing INVALID_CONFIG_VALUE to mbm_local_cfg in case of error.
v6: Renamed resctrl_arch_mbm_evt_config -> resctrl_mbm_evt_config_init
Initialized value to INVALID_CONFIG_VALUE if it is not configurable. Minor commit message update.
v5: Exported mon_event_config_index_get.
Renamed arch_domain_mbm_evt_config to resctrl_arch_mbm_evt_config.
v4: Read the configuration information from the hardware to initialize.
Added few commit messages.
Fixed the tab spaces.
v3: Minor changes related to rebase in mbm_config_write_domain.
v2: No changes.
--- arch/x86/kernel/cpu/resctrl/core.c | 2 ++ arch/x86/kernel/cpu/resctrl/internal.h | 9 +++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 26 ++++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +--- 4 files changed, 38 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -632,6 +632,8 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)arch_mon_domain_online (r, d); +arch_mbm_evt_config_init (hw_dom); +if (arch_domain_mbm_alloc (r->mon.num_rmid, hw_dom)) {mon_domain_free (hw_dom);return ;
arch/x86/kernel/cpu/resctrl/internal.h +9 -0
@@ -56,6 +56,9 @@/* Max event bits supported */ #define MAX_EVT_CONFIG_BITS GENMASK(6, 0) +#define INVALID_CONFIG_VALUE U32_MAX +#define INVALID_CONFIG_INDEX UINT_MAX +/* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */ #define ABMC_ENABLE_BIT 0
@@ -403,6 +406,8 @@ struct rdt_hw_ctrl_domain {* @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 +* @mbm_total_cfg: MBM total bandwidth configuration +* @mbm_local_cfg: MBM local bandwidth configuration * * Members of this structure are accessed via helpers that provide abstraction. */
@@ -410,6 +415,8 @@ 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; +u32 mbm_total_cfg; +u32 mbm_local_cfg; };static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom (struct rdt_ctrl_domain *r)
@@ -665,4 +672,6 @@ bool closid_allocated(unsigned int closid);int resctrl_find_cleanest_closid (void );int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable);bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r); +void arch_mbm_evt_config_init (struct rdt_hw_mon_domain *hw_dom); +unsigned int mon_event_config_index_get (u32 evtid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +26 -0
@@ -1244,6 +1244,32 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)return 0 ; } +void arch_mbm_evt_config_init (struct rdt_hw_mon_domain *hw_dom) +{ +unsigned int index; +u64 msrval; + +/* +* Read the configuration registers QOS_EVT_CFG_n, where <n> is +* the BMEC event number (EvtID). +*/ +if (mbm_total_event.configurable) { + index =mon_event_config_index_get (QOS_L3_MBM_TOTAL_EVENT_ID ); +rdmsrl (MSR_IA32_EVT_CFG_BASE + index, msrval); + hw_dom->mbm_total_cfg = msrval &MAX_EVT_CONFIG_BITS ; + }else { + hw_dom->mbm_total_cfg =INVALID_CONFIG_VALUE ; + } + +if (mbm_local_event.configurable) { + index =mon_event_config_index_get (QOS_L3_MBM_LOCAL_EVENT_ID ); +rdmsrl (MSR_IA32_EVT_CFG_BASE + index, msrval); + hw_dom->mbm_local_cfg = msrval &MAX_EVT_CONFIG_BITS ; + }else { + hw_dom->mbm_local_cfg =INVALID_CONFIG_VALUE ; + } +} + void __exit rdt_put_mon_l3_config(void) {dom_data_exit ();
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -3
@@ -1591,8 +1591,6 @@ struct mon_config_info {u32 mon_config; }; -#define INVALID_CONFIG_INDEX UINT_MAX -/** * mon_event_config_index_get - get the hardware index for the * configurable event
@@ -1602,7 +1600,7 @@ struct mon_config_info {* 1 for evtid == QOS_L3_MBM_LOCAL_EVENT_ID * INVALID_CONFIG_INDEX for invalid evtid */ -static inline unsigned int mon_event_config_index_get (u32 evtid) +unsigned int mon_event_config_index_get (u32 evtid) {switch (evtid) {case QOS_L3_MBM_TOTAL_EVENT_ID :
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 10/23 x86/resctrl: Remove MSR reading of event configuration value
In reply to Babu MogerThe event configuration is domain specific and initialized during domain initialization. The values are stored in struct rdt_hw_mon_domain.
It is not required to read the configuration register every time user asks for it. Use the value stored in struct rdt_hw_mon_domain instead.
Introduce resctrl_arch_mon_event_config_get() and resctrl_arch_mon_event_config_set() to get/set architecture domain specific mbm_total_cfg/mbm_local_cfg values.
---
v11: 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.
Renamed local variable from val to config_val.
v10: Moved the mon_config_info structure definition to resctrl.h.
v9: Removed QOS_L3_OCCUP_EVENT_ID switch case in resctrl_arch_mon_event_config_set.
Fixed a unnecessary space.
v8: 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().
v7: Removed check if (val == INVALID_CONFIG_VALUE) as resctrl_arch_event_config_get
already prints warning.
Kept the Event config value definitions as is.
v6: Fixed inconstancy with types. Made all the types to u32 for config
value.
Removed few rdt_last_cmd_puts as it is not necessary. Removed unused config value definitions.
Few more updates to commit message.
v5: Introduced resctrl_arch_event_config_get and
resctrl_arch_event_config_get() based on our discussion.
https://lore.kernel.org/lkml/[email protected]/
v4: New patch.
--- arch/x86/kernel/cpu/resctrl/internal.h | 15 +++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 46 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 61 +++++--------------------- 3 files changed, 72 insertions(+), 50 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +15 -0
@@ -605,6 +605,18 @@ union cpuid_0x10_x_edx {unsigned int full; }; +/** +* struct mon_config_info - Monitoring event configuratiin details +* @d: Domain for the event +* @evtid: Event type +* @mon_config: Event configuration value +*/ +struct mon_config_info { +struct rdt_mon_domain *d; +enum resctrl_event_id evtid; +u32 mon_config; +}; +void rdt_last_cmd_clear (void );void rdt_last_cmd_puts (const char *s);__printf (1 ,2 )
@@ -674,4 +686,7 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable);bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);void arch_mbm_evt_config_init (struct rdt_hw_mon_domain *hw_dom);unsigned int mon_event_config_index_get (u32 evtid); +void resctrl_arch_mon_event_config_set (void *info); +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, +enum resctrl_event_id eventid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +46 -0
49 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11 -50
106 lines not on this page · raw message
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Hi Babu,
Quoted 24 lines · Babu Moger
The event configuration is domain specific and initialized during domain initialization. The values are stored in struct
rdt_hw_mon_domain.It is not required to read the configuration register every time user asks for it. Use the value stored in struct
rdt_hw_mon_domaininstead.Introduce
resctrl_arch_mon_event_config_get()andresctrl_arch_mon_event_config_set()to get/set architecture domain specific mbm_total_cfg/mbm_local_cfg values.Signed-off-by Babu Moger <[email protected]>---
--- arch/x86/kernel/cpu/resctrl/internal.h | 15 +++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 46 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 61 +++++--------------------- 3 files changed, 72 insertions(+), 50 deletions(-)arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h union cpuid_0x10_x_edx { · line 609
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -605,6 +605,18 @@ union cpuid_0x10_x_edx {unsigned int full; }; +/** +* struct mon_config_info - Monitoring event configuratiin details
Same typo as previous version.
Quoted 65 lines
arch/x86/kernel/cpu/resctrl/internal.h +13
-0+* @d: Domain for the event +* @evtid: Event type +* @mon_config: Event configuration value +*/ +struct mon_config_info { +struct rdt_mon_domain *d; +enum resctrl_event_id evtid; +u32 mon_config; +}; +void rdt_last_cmd_clear (void );void rdt_last_cmd_puts (const char *s);__printf (1 ,2 )@@ -674,4 +686,7 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable);bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);void arch_mbm_evt_config_init (struct rdt_hw_mon_domain *hw_dom);unsigned int mon_event_config_index_get (u32 evtid); +void resctrl_arch_mon_event_config_set (void *info); +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, +enum resctrl_event_id eventid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/monitor.c +36
-0@@ -1324,3 +1324,49 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable)return 0 ; } + +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, +enum resctrl_event_id eventid) +{ +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); + +switch (eventid) { +case QOS_L3_OCCUP_EVENT_ID : +break ; +case QOS_L3_MBM_TOTAL_EVENT_ID : +return hw_dom->mbm_total_cfg; +case QOS_L3_MBM_LOCAL_EVENT_ID : +return hw_dom->mbm_local_cfg; + } + +/* Never expect to get here */ +WARN_ON_ONCE (1 ); + +return INVALID_CONFIG_VALUE ; +} + +void resctrl_arch_mon_event_config_set (void *info) +{ +struct mon_config_info *mon_info = info; +struct rdt_hw_mon_domain *hw_dom; +unsigned int index; + + index =mon_event_config_index_get (mon_info->evtid); +if (index ==INVALID_CONFIG_INDEX ) +return ; + +wrmsr (MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config,0 ); + + hw_dom =resctrl_to_arch_mon_dom (mon_info->d); + +switch (mon_info->evtid) {
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) · line 1372
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+case QOS_L3_MBM_TOTAL_EVENT_ID : + hw_dom->mbm_total_cfg = mon_info->mon_config; +break ; +case QOS_L3_MBM_LOCAL_EVENT_ID : + hw_dom->mbm_local_cfg = mon_info->mon_config; +break ; +default : +break ; + } +}
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get() -> May run on CPU that does not belong to domain. resctrl_arch_mon_event_config_set() -> Runs on CPU that belongs to domain.
...
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0
-7@@ -1683,33 +1653,23 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of,return 0 ; } -static void mon_event_config_write (void *info) -{ -struct mon_config_info *mon_info = info; -unsigned int index; - - index =mon_event_config_index_get (mon_info->evtid); -if (index ==INVALID_CONFIG_INDEX ) {
arch/x86/kernel/cpu/resctrl/monitor.c static int mbm_local_bytes_config_show(struct kernfs_open_file *of, · line 1660
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0
-5-pr_warn_once ("Invalid event id %d\n" , mon_info->evtid); -return ; - } -wrmsr (MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config,0 ); -}static void mbm_config_write_domain (struct rdt_resource *r,struct rdt_mon_domain *d,u32 evtid,u32 val) {struct mon_config_info mon_info = {0 };
As discussed in previous version it is unnecessary to explicitly initialize the structure if it is fully initialized in the code. This avoids need for future cleanups like commit 29eaa7958367 ("x86/resctrl: Slightly clean-up mbm_config_show()")
Reinette
Luck, Tony
maintainerRE: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Quoted 7 lines
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.
Here's a vague data point about the future to help with speculation.
I have something coming along the pipeline that also can run on any CPU.
I am contemplating a flag in the rdt_resource structure (in appropriate substructure resctrl_cache/resctrl_membw) to indicate "domain" vs. "any" for operations.
Would something like that be useful here?
-Tony
Reinette Chatre
maintainerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Hi Tony,
Quoted 8 lines · Tony
Quoted 7 lines
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.
Quoted 8 lines
Here's a vague data point about the future to help with speculation.
I have something coming along the pipeline that also can run on any CPU.
I am contemplating a flag in the
rdt_resourcestructure (in appropriate substructure resctrl_cache/resctrl_membw) to indicate "domain" vs. "any" for operations.Would something like that be useful here?
hmm ... I cannot envision how this may look. Could you please elaborate?
You mention "a" (singular) flag in rdt_resource while this scenario involves different ops having different scope. This makes me think that this flag may have to be per operation that in turn would need additional infrastructure to manage and track operations.
These "arch" functions are evolving as the work to support MPAM is done and so far I think it has been quite ad-hoc to just refactor arch specific code into "arch" helpers instead of keeping track of which scope they are running in. This currently requires any arch implementing an "arch" helper to be well aware of how resctrl will call it.
Reinette
Luck, Tony
maintainerRE: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Quoted 24 lines
Quoted 8 lines
Quoted 7 lines
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.Quoted 8 lines
Here's a vague data point about the future to help with speculation.
I have something coming along the pipeline that also can run on any CPU.
I am contemplating a flag in the
rdt_resourcestructure (in appropriate substructure resctrl_cache/resctrl_membw) to indicate "domain" vs. "any" for operations.Would something like that be useful here?
hmm ... I cannot envision how this may look. Could you please elaborate?
You mention "a" (singular) flag in
rdt_resourcewhile this scenario involves different ops having different scope. This makes me think that this flag may have to be per operation that in turn would need additional infrastructure to manage and track operations.
Quoted 5 lines
These "arch" functions are evolving as the work to support MPAM is done and so far I think it has been quite ad-hoc to just refactor arch specific code into "arch" helpers instead of keeping track of which scope they are running in. This currently requires any arch implementing an "arch" helper to be well aware of how resctrl will call it.
Reinette,
I haven't fleshed it out yet. One option would be to have a "choose_cpu_mask()" function that takes resource and domain parameters (and given your comment about this case an operation code). Then use that as the mask in an smp_call*().
Operations that can run anywhere would return a mask with just bit for the current CPU. Those tied to a domain, a copy of the domain mask.
-Tony
James Morse
reviewerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Hi Tony, Reinette,
Quoted 11 lines · Tony
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.Here's a vague data point about the future to help with speculation.
I have something coming along the pipeline that also can run on any CPU.
RISC-V has this - all their controls/monitors are accessible from any CPU. Some MPAM platforms can do this too - but the code has to be structured for those that need the IPI.
Having this be something resctrl can be told sounds like a great idea.
It sounds like all or nothing suits x86/riscv.
The MPAM driver has an accessibility cpumask for each thing it accesses that determines if it needs to do an IPI.
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
I am contemplating a flag in the
rdt_resourcestructure (in appropriate substructure resctrl_cache/resctrl_membw) to indicate "domain" vs. "any" for operations.Would something like that be useful here?
hmm ... I cannot envision how this may look. Could you please elaborate?
You mention "a" (singular) flag in
rdt_resourcewhile this scenario involves different ops having different scope. This makes me think that this flag may have to be per operation that in turn would need additional infrastructure to manage and track operations.
Quoted 5 lines
Quoted 5 lines
These "arch" functions are evolving as the work to support MPAM is done and so far I think it has been quite ad-hoc to just refactor arch specific code into "arch" helpers instead of keeping track of which scope they are running in. This currently requires any arch implementing an "arch" helper to be well aware of how resctrl will call it.
This is how APIs in linux evolve - only the immediate problem needs solving. Arch code being aware how resctrl uses a function shouldn't be surprising - it is the only user.
Quoted 6 lines
I haven't fleshed it out yet. One option would be to have a "
choose_cpu_mask()" function that takes resource and domain parameters (and given your comment about this case an operation code). Then use that as the mask in an smp_call*().Operations that can run anywhere would return a mask with just bit for the current CPU.
That sounds like extra work. We already have a cpumask, if you set it to the cpu_possible mask at boot, then smp_call_function() and friends will always prefer the current CPU, and it all falls out in the wash.
Thanks,
James
Dave Martin
reviewerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
In reply to Reinette ChatreQuoted 27 lines · Reinette Chatre
Hi Tony,
Quoted 8 lines · Tony
Quoted 7 lines
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.Quoted 8 lines
Here's a vague data point about the future to help with speculation.
I have something coming along the pipeline that also can run on any CPU.
I am contemplating a flag in the
rdt_resourcestructure (in appropriate substructure resctrl_cache/resctrl_membw) to indicate "domain" vs. "any" for operations.Would something like that be useful here?
hmm ... I cannot envision how this may look. Could you please elaborate?
You mention "a" (singular) flag in
rdt_resourcewhile this scenario involves different ops having different scope. This makes me think that this flag may have to be per operation that in turn would need additional infrastructure to manage and track operations.
Quoted 7 lines
These "arch" functions are evolving as the work to support MPAM is done and so far I think it has been quite ad-hoc to just refactor arch specific code into "arch" helpers instead of keeping track of which scope they are running in. This currently requires any arch implementing an "arch" helper to be well aware of how resctrl will call it.
Reinette
For MPAM, we must typically do all configuration access from a CPU in a power domain that depends on the power domain of the relevant MPAM MSC, including reads of the configuration.
In the MPAM case, the required topology knowledge is not necessarily identical to the resctrl domain topology, so it doesn't feel right to have the resctrl core code making the decisions.
So, in the interest of keeping the arch interface simple, should cross- calling be delegated to the arch code, at least for now?
Cheers
---Dave
James Morse
reviewerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Hi Dave,
Quoted 32 lines · Dave Martin
Quoted 25 lines · Reinette Chatre
Quoted 8 lines · Tony
Quoted 7 lines
This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.Quoted 8 lines
Here's a vague data point about the future to help with speculation.
I have something coming along the pipeline that also can run on any CPU.
I am contemplating a flag in the
rdt_resourcestructure (in appropriate substructure resctrl_cache/resctrl_membw) to indicate "domain" vs. "any" for operations.Would something like that be useful here?
hmm ... I cannot envision how this may look. Could you please elaborate?
You mention "a" (singular) flag in
rdt_resourcewhile this scenario involves different ops having different scope. This makes me think that this flag may have to be per operation that in turn would need additional infrastructure to manage and track operations.Quoted 5 lines
These "arch" functions are evolving as the work to support MPAM is done and so far I think it has been quite ad-hoc to just refactor arch specific code into "arch" helpers instead of keeping track of which scope they are running in. This currently requires any arch implementing an "arch" helper to be well aware of how resctrl will call it.
Quoted 3 lines
For MPAM, we must typically do all configuration access from a CPU in a power domain that depends on the power domain of the relevant MPAM MSC, including reads of the configuration.
This is the worst case - but the firmware can describe an MSC as being globally accessible.
Quoted 3 lines
In the MPAM case, the required topology knowledge is not necessarily identical to the resctrl domain topology, so it doesn't feel right to have the resctrl core code making the decisions.
This is up to the MPAM driver to hide. The upshot is that for some calls resctrl needs to schedule work so that the MPAM driver can in turn IPI to get the rest of the work done. The changes for this are already upstream.
Quoted 2 lines
So, in the interest of keeping the arch interface simple, should cross- calling be delegated to the arch code, at least for now?
That's invasive on top of what we already have. Take smp_mon_event_count() as an example, there is a bunch of work that resctrl can do on a CPU that can access the hardware registers. If the cpumask was hidden, then we'd either need more IPI, or to allocate a structure that can describe a long list of monitors to read.
Thanks,
James
Re: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
In reply to Reinette ChatreHi Reinette,
Quoted 30 lines · Reinette Chatre
Hi Babu,
Quoted 27 lines · Babu Moger
The event configuration is domain specific and initialized during domain initialization. The values are stored in struct
rdt_hw_mon_domain.It is not required to read the configuration register every time user asks for it. Use the value stored in struct
rdt_hw_mon_domaininstead.Introduce
resctrl_arch_mon_event_config_get()andresctrl_arch_mon_event_config_set()to get/set architecture domain specific mbm_total_cfg/mbm_local_cfg values.Signed-off-by Babu Moger <[email protected]>---
--- arch/x86/kernel/cpu/resctrl/internal.h | 15 +++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 46 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 61 +++++--------------------- 3 files changed, 72 insertions(+), 50 deletions(-)arch/x86/kernel/cpu/resctrl/internal.h +0
-0@@ -605,6 +605,18 @@ union cpuid_0x10_x_edx {unsigned int full; };
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/internal.h union cpuid_0x10_x_edx { · line 609
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-0+/** +* struct mon_config_info - Monitoring event configuratiin details Same typo as previous version.
I am really sorry about this.
Quoted 82 lines
Quoted 66 lines
arch/x86/kernel/cpu/resctrl/internal.h +13
-0+* @d: Domain for the event +* @evtid: Event type +* @mon_config: Event configuration value +*/ +struct mon_config_info { +struct rdt_mon_domain *d; +enum resctrl_event_id evtid; +u32 mon_config; +}; +void rdt_last_cmd_clear (void );void rdt_last_cmd_puts (const char *s);__printf (1 ,2 )@@ -674,4 +686,7 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable);bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);void arch_mbm_evt_config_init (struct rdt_hw_mon_domain *hw_dom);unsigned int mon_event_config_index_get (u32 evtid); +void resctrl_arch_mon_event_config_set (void *info); +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, +enum resctrl_event_id eventid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/monitor.c +36
-0@@ -1324,3 +1324,49 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable)return 0 ; } + +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, +enum resctrl_event_id eventid) +{ +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); + +switch (eventid) { +case QOS_L3_OCCUP_EVENT_ID : +break ; +case QOS_L3_MBM_TOTAL_EVENT_ID : +return hw_dom->mbm_total_cfg; +case QOS_L3_MBM_LOCAL_EVENT_ID : +return hw_dom->mbm_local_cfg; + } + +/* Never expect to get here */ +WARN_ON_ONCE (1 ); + +return INVALID_CONFIG_VALUE ; +} + +void resctrl_arch_mon_event_config_set (void *info) +{ +struct mon_config_info *mon_info = info; +struct rdt_hw_mon_domain *hw_dom; +unsigned int index; + + index =mon_event_config_index_get (mon_info->evtid); +if (index ==INVALID_CONFIG_INDEX ) +return ; + +wrmsr (MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config,0 ); + + hw_dom =resctrl_to_arch_mon_dom (mon_info->d); + +switch (mon_info->evtid) {arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) · line 1372
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+case QOS_L3_MBM_TOTAL_EVENT_ID : + hw_dom->mbm_total_cfg = mon_info->mon_config; +break ; +case QOS_L3_MBM_LOCAL_EVENT_ID : + hw_dom->mbm_local_cfg = mon_info->mon_config; +break ; +default : +break ; + } +}This new arch API has sharp corners because of asymmetry of where resctrl runs the arch function. I do not think it is required to change this since we can only speculate about how this may be used in the future but I do think it will be helpful to add comments that highlight:
Quoted 2 lines
resctrl_arch_mon_event_config_get()-> May run on CPU that does not belong to domain.resctrl_arch_mon_event_config_set()-> Runs on CPU that belongs to domain.
Sure. will do.
Quoted 20 lines
...
Quoted 17 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0
-12@@ -1683,33 +1653,23 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of,return 0 ; } -static void mon_event_config_write (void *info) -{ -struct mon_config_info *mon_info = info; -unsigned int index; - - index =mon_event_config_index_get (mon_info->evtid); -if (index ==INVALID_CONFIG_INDEX ) { -pr_warn_once ("Invalid event id %d\n" , mon_info->evtid); -return ; - } -wrmsr (MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config,0 ); -}
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c static int mbm_local_bytes_config_show(struct kernfs_open_file *of, · line 1660
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0
-0static void mbm_config_write_domain (struct rdt_resource *r,struct rdt_mon_domain *d,u32 evtid,u32 val) {struct mon_config_info mon_info = {0 };As discussed in previous version it is unnecessary to explicitly initialize the structure if it is fully initialized in the code. This avoids need for future cleanups like commit
29eaa7958367("x86/resctrl: Slightly clean-upmbm_config_show()")
Yes. Need to change it.
thanks
Babu
Re: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
In reply to Babu MogerQuoted 30 lines · Babu Moger
arch/x86/kernel/cpu/resctrl/monitor.c +22
-0@@ -1324,3 +1324,49 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable)return 0 ; } + +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, +enum resctrl_event_id eventid) +{ +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); + +switch (eventid) { +case QOS_L3_OCCUP_EVENT_ID : +break ; +case QOS_L3_MBM_TOTAL_EVENT_ID : +return hw_dom->mbm_total_cfg; +case QOS_L3_MBM_LOCAL_EVENT_ID : +return hw_dom->mbm_local_cfg; + } + +/* Never expect to get here */ +WARN_ON_ONCE (1 ); + +return INVALID_CONFIG_VALUE ; +} + +void resctrl_arch_mon_event_config_set (void *info)
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) · line 1358
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+{ +struct mon_config_info *mon_info = info; +struct rdt_hw_mon_domain *hw_dom; +unsigned int index; + + index =mon_event_config_index_get (mon_info->evtid); +if (index ==INVALID_CONFIG_INDEX ) +return ; + +wrmsr (MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config,0 );
This is the existing code, however it would be better to use wrmsrl() when the higher 32-bit are all 0s:
wrmsrl(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config);
Thanks!
Xin
Reinette Chatre
maintainerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Hi Xin,
Quoted 44 lines · Xin Li
Quoted 29 lines · Babu Moger
arch/x86/kernel/cpu/resctrl/monitor.c +22
-0@@ -1324,3 +1324,49 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) return 0; } + +u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d, + enum resctrl_event_id eventid) +{ + struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d); + + switch (eventid) { + case QOS_L3_OCCUP_EVENT_ID: + break; + case QOS_L3_MBM_TOTAL_EVENT_ID: + return hw_dom->mbm_total_cfg; + case QOS_L3_MBM_LOCAL_EVENT_ID: + return hw_dom->mbm_local_cfg; + } + + /* Never expect to get here */ + WARN_ON_ONCE(1); + + return INVALID_CONFIG_VALUE; +} + +void resctrl_arch_mon_event_config_set (void *info)arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) · line 1357
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+{ + struct mon_config_info *mon_info = info; + struct rdt_hw_mon_domain *hw_dom; + unsigned int index; + + index = mon_event_config_index_get(mon_info->evtid); + if (index == INVALID_CONFIG_INDEX) + return; + + wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);This is the existing code, however it would be better to use
wrmsrl()when the higher 32-bit are all 0s:
Quoted 2 lines
wrmsrl(MSR_IA32_EVT_CFG_BASE + index,
mon_info->mon_config);
Could you please elaborate what makes this change better?
Thank you!
Reinette
Re: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Quoted 7 lines · Reinette Chatre
Quoted 6 lines
Quoted 1 line
+
wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);This is the existing code, however it would be better to use
wrmsrl()when the higher 32-bit are all 0s:wrmsrl(MSR_IA32_EVT_CFG_BASE + index,
mon_info->mon_config);Could you please elaborate what makes this change better?
In short, it takes one less argument, and doesn't pass an argument of 0.
The longer story is that hpa and I are refactoring the MSR access APIs
to accommodate the immediate form of MSR access instructions. And we
are not happy about that there are too many MSR access APIs and their
uses are *random*. The native wrmsr() and wrmsrl() are essentially the same and the only difference is that wrmsr() passes a 64-bit value to be written into a MSR in *2* u32 arguments. But we already have struct msr
defined in asm/shared/msr.h as:
struct msr {
union {
struct {
u32 l;
u32 h;
};
u64 q;
};
};it's more natural to do the same job with this data structure in most cases. And we want to remove wrmsr() and only keep wrmsrl(), thus a developer won't have to figure out which one is better to use :-P.
For that to happen, one cleanup is to replace wrmsr(msr, low, 0) with wrmsrl(msr, low) (low is automatically converted to u64 from u32).
However, I'm fine if Babu wants to keep it as-is.
Thanks!
Xin
Moger, Babu
reviewerRe: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Hi Xin,
Quoted 28 lines · Xin Li
Quoted 7 lines · Reinette Chatre
Quoted 6 lines
Quoted 1 line
+
wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);This is the existing code, however it would be better to use
wrmsrl()when the higher 32-bit are all 0s:wrmsrl(MSR_IA32_EVT_CFG_BASE + index,
mon_info->mon_config);Could you please elaborate what makes this change better?
In short, it takes one less argument, and doesn't pass an argument of 0.
The longer story is that hpa and I are refactoring the MSR access APIs to accommodate the immediate form of MSR access instructions. And we are not happy about that there are too many MSR access APIs and their uses are *random*. The native
wrmsr()andwrmsrl()are essentially the same and the only difference is thatwrmsr()passes a 64-bit value to be written into a MSR in *2* u32 arguments. But we already have struct msr defined inasm/shared/msr.has:
struct msr {
union {
struct {
u32 l;
u32 h;
};
u64 q;
};
};
Quoted 8 lines
it's more natural to do the same job with this data structure in most cases. And we want to remove
wrmsr()and only keepwrmsrl(), thus a developer won't have to figure out which one is better to use :-P.For that to happen, one cleanup is to replace
wrmsr(msr, low, 0)withwrmsrl(msr, low)(low is automatically converted to u64 from u32).However, I'm fine if Babu wants to keep it as-is.
Thanks for the explanation. Changed it to use wrmsrl().
Signature · 2 lines
Thanks Babu Moger
Re: [PATCH v11 10/23] x86/resctrl: Remove MSR reading of event configuration value
Quoted 35 lines · Babu
Hi Xin,
Quoted 32 lines · Xin Li
Quoted 7 lines · Reinette Chatre
Quoted 6 lines
Quoted 1 line
+
wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);This is the existing code, however it would be better to use
wrmsrl()when the higher 32-bit are all 0s:wrmsrl(MSR_IA32_EVT_CFG_BASE + index,
mon_info->mon_config);Could you please elaborate what makes this change better?
In short, it takes one less argument, and doesn't pass an argument of 0.
The longer story is that hpa and I are refactoring the MSR access APIs to accommodate the immediate form of MSR access instructions. And we are not happy about that there are too many MSR access APIs and their uses are *random*. The native
wrmsr()andwrmsrl()are essentially the same and the only difference is thatwrmsr()passes a 64-bit value to be written into a MSR in *2* u32 arguments. But we already have struct msr defined inasm/shared/msr.has:
struct msr {
union {
struct {
u32 l;
u32 h;
};
u64 q;
};
};it's more natural to do the same job with this data structure in most cases. And we want to remove
wrmsr()and only keepwrmsrl(), thus a developer won't have to figure out which one is better to use :-P.
Quoted 7 lines
Quoted 4 lines
For that to happen, one cleanup is to replace
wrmsr(msr, low, 0)withwrmsrl(msr, low)(low is automatically converted to u64 from u32).However, I'm fine if Babu wants to keep it as-is.
Thanks for the explanation. Changed it to use
wrmsrl().
You're welcome. And thanks for making the change.
Babu Moger
reviewerPATCH v11 11/23 x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
In reply to Babu MogerIn mbm_cntr_assign mode hardware counters are assigned/unassigned to an MBM event of a monitor group. Hardware 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.
---
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.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 11 +++++++++++ include/linux/resctrl.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11 -0
@@ -4009,6 +4009,7 @@ static void __init rdtgroup_setup_default(void)static void domain_destroy_mon_state (struct rdt_mon_domain *d) { +kfree (d->cntr_cfg);bitmap_free (d->rmid_busy_llc);kfree (d->mbm_total);kfree (d->mbm_local);
@@ -4082,6 +4083,16 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domainreturn -ENOMEM ; } } +if (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) { +bitmap_free (d->rmid_busy_llc); +kfree (d->mbm_total); +kfree (d->mbm_local); +return -ENOMEM ; + } + }return 0 ; }
include/linux/resctrl.h +14 -0
@@ -94,6 +94,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. +* @rdtgroup: 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
@@ -105,6 +117,7 @@ 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: assignable counters configuration */ struct rdt_mon_domain {struct rdt_domain_hdr hdr;
@@ -116,6 +129,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
Reinette Chatre
maintainerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Hi Babu,
Quoted 7 lines · Babu Moger
In
mbm_cntr_assignmode hardware counters are assigned/unassigned to an MBM event of a monitor group. Hardware 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_cfgthat is indexed by the hardware
counter ID. A hardware counter's configuration contains the MBM event
Something strange in this changelog with a few random \t in the text.
Quoted 4 lines
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
... another \t above
Quoted 2 lines
to a particular monitoring group. Check every entry of every hardware
counter configuration array in every monitoring domain to query which
... one more \t above
Quoted 2 lines
MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters.
It is not obvious what "very small number" means. Is it possible to give a range to help reader understand the motivation?
Quoted 49 lines
Suggested-by Peter Newman <[email protected]>Signed-off-by Babu Moger <[email protected]>---
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 11 +++++++++++ include/linux/resctrl.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+)arch/x86/kernel/cpu/resctrl/rdtgroup.c +11
-0@@ -4009,6 +4009,7 @@ static void __init rdtgroup_setup_default(void)static void domain_destroy_mon_state (struct rdt_mon_domain *d) { +kfree (d->cntr_cfg);bitmap_free (d->rmid_busy_llc);kfree (d->mbm_total);kfree (d->mbm_local);@@ -4082,6 +4083,16 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domainreturn -ENOMEM ; } } +if (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) { +bitmap_free (d->rmid_busy_llc); +kfree (d->mbm_total); +kfree (d->mbm_local); +return -ENOMEM ; + } + }return 0 ; }include/linux/resctrl.h +2
-0@@ -94,6 +94,18 @@ struct rdt_ctrl_domain {u32 *mbps_val; }; +/** +* struct mbm_cntr_cfg - assignable counter configuration
include/linux/resctrl.h struct rdt_ctrl_domain { · line 108
Quoted 10 lines
include/linux/resctrl.h +10
-0+* @evtid: MBM event to which the counter is assigned. Only valid +* if @rdtgroup is not NULL. +* @rdtgroup: resctrl group assigned to the counter. NULL if the +* counter is free. +*/ +struct mbm_cntr_cfg { +enum resctrl_event_id evtid; +struct rdtgroup *rdtgrp; +}; +
$ scripts/kernel-doc -v -none include/linux/resctrl.h ... include/linux/resctrl.h:107: warning: Function parameter or struct member 'rdtgrp' not described in 'mbm_cntr_cfg' include/linux/resctrl.h:107: warning: Excess struct member 'rdtgroup' description in 'mbm_cntr_cfg' ...
Quoted 12 lines
include/linux/resctrl.h +1
-0/** * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types @@ -105,6 +117,7 @@ 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: assignable counters configuration */ struct rdt_mon_domain {struct rdt_domain_hdr hdr;
include/linux/resctrl.h struct rdt_mon_domain { · line 135
Quoted 7 lines
include/linux/resctrl.h +1
-0@@ -116,6 +129,7 @@ struct rdt_mon_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; +struct mbm_cntr_cfg *cntr_cfg; };/**
Reinette
Re: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Hi Reinette,
Quoted 7 lines · Reinette Chatre
Hi Babu,
Quoted 4 lines · Babu Moger
In
mbm_cntr_assignmode hardware counters are assigned/unassigned to an MBM event of a monitor group. Hardware counters are assigned/unassigned at monitoring domain level.
Quoted 5 lines
Quoted 3 lines
Manage a monitoring domain's hardware counters using a per monitoring domain array of struct
mbm_cntr_cfgthat is indexed by the hardware
counter ID. A hardware counter's configuration contains the MBM eventSomething strange in this changelog with a few random \t in the text.
Not sure how it got in there. I can only see with "set list" option.
I Will remove it.
Quoted 7 lines
Quoted 5 lines
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
... another \t above
Sure.
Quoted 5 lines
Quoted 3 lines
to a particular monitoring group. Check every entry of every hardware
counter configuration array in every monitoring domain to query which... one more \t above
Sure
Quoted 6 lines
Quoted 3 lines
MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters.
It is not obvious what "very small number" means. Is it possible to give a range to help reader understand the motivation?
How about?
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).
Quoted 57 lines
Quoted 57 lines
Suggested-by Peter Newman <[email protected]>Signed-off-by Babu Moger <[email protected]>---
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 11 +++++++++++ include/linux/resctrl.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+)arch/x86/kernel/cpu/resctrl/rdtgroup.c +11
-0@@ -4009,6 +4009,7 @@ static void __init rdtgroup_setup_default(void)static void domain_destroy_mon_state (struct rdt_mon_domain *d) { +kfree (d->cntr_cfg);bitmap_free (d->rmid_busy_llc);kfree (d->mbm_total);kfree (d->mbm_local);@@ -4082,6 +4083,16 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domainreturn -ENOMEM ; } } +if (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) { +bitmap_free (d->rmid_busy_llc); +kfree (d->mbm_total); +kfree (d->mbm_local); +return -ENOMEM ; + } + }return 0 ; }include/linux/resctrl.h +9
-0@@ -94,6 +94,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. +* @rdtgroup: resctrl group assigned to the counter. NULL if the +* counter is free. +*/ +struct mbm_cntr_cfg { +enum resctrl_event_id evtid;
Quoted 8 lines
include/linux/resctrl.h struct rdt_ctrl_domain { · line 108
Quoted 3 lines
include/linux/resctrl.h +3
-0+struct rdtgroup *rdtgrp; +}; +$ scripts/kernel-doc -v -none include/linux/resctrl.h ... include/linux/resctrl.h:107: warning: Function parameter or struct member 'rdtgrp' not described in 'mbm_cntr_cfg' include/linux/resctrl.h:107: warning: Excess struct member 'rdtgroup' description in 'mbm_cntr_cfg'
Yes. Will fix this.
Quoted 20 lines
...
Quoted 18 lines
/**
* structrdt_mon_domain- group of CPUs sharing a resctrl monitor resource
* @hdr: common header for different domain typesinclude/linux/resctrl.h +2
-0@@ -105,6 +117,7 @@ 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: assignable counters configuration */ struct rdt_mon_domain {struct rdt_domain_hdr hdr;@@ -116,6 +129,7 @@ struct rdt_mon_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; +struct mbm_cntr_cfg *cntr_cfg; };
Quoted 5 lines
include/linux/resctrl.h struct rdt_mon_domain { · line 135
Quoted 1 line
include/linux/resctrl.h +0
-0/** Reinette
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Hi Babu,
Quoted 14 lines · Babu
Quoted 6 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
to a particular monitoring group. Check every entry of every hardware counter configuration array in every monitoring domain to query which
... one more \t above
Sure
Quoted 4 lines
Quoted 3 lines
MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters.
Quoted 7 lines
Quoted 2 lines
It is not obvious what "very small number" means. Is it possible to give a range to help reader understand the motivation?
How about?
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).
Yes, thank you. This helps to understand the claim.
Reinette
Dave Martin
reviewerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Hi,
Quoted 5 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu
Quoted 1 line · Reinette Chatre
On 1/22/25 12:20 PM, Babu Moger wrote:
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters.
It is not obvious what "very small number" means. Is it possible to give a range to help reader understand the motivation?
Quoted 8 lines
Quoted 4 lines
How about?
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).
Yes, thank you. This helps to understand the claim.
Reinette
Do these queries only happen when userspace reads an mbm_assign_control file?
It might be worth documenting somewhere that writing and (especially) reading an mbm_assign_control file is not intended to be super-fast.
It feels like userspace should not generally rely on reading mbm_assign_control files except for diagnostic purposes, or occasional read-modify-write transformations. Or do expect some other usage model that makes this a hotter path?
Cheers
---Dave
Moger, Babu
reviewerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Hi Dave,
Quoted 22 lines · Dave Martin
Hi,
Quoted 5 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu
Quoted 1 line · Reinette Chatre
On 1/22/25 12:20 PM, Babu Moger wrote:
[...]
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters.
It is not obvious what "very small number" means. Is it possible to give a range to help reader understand the motivation?
How about?
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).
Quoted 6 lines
Quoted 3 lines
Yes, thank you. This helps to understand the claim.
Reinette
Do these queries only happen when userspace reads an
mbm_assign_controlfile?
Yes. All these queries are initiated by userspace in the form of individual assignments or creating a group(mkdir).
Quoted 3 lines
It might be worth documenting somewhere that writing and (especially) reading an
mbm_assign_controlfile is not intended to be super-fast.
We can drop the last sentence if it is creating confusion.
Quoted 8 lines
It feels like userspace should not generally rely on reading
mbm_assign_controlfiles except for diagnostic purposes, or occasional read-modify-write transformations. Or do expect some other usage model that makes this a hotter path?Cheers
---Dave
Our earlier interface was intended to query each group separately. After the input from Peter, we changed it to batched query. One query from userspace can list all the assignments. I am not aware of any other usage model.
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Quoted 48 lines · Babu
Hi Dave,
Quoted 22 lines · Dave Martin
Hi,
Quoted 5 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu
Quoted 1 line · Reinette Chatre
On 1/22/25 12:20 PM, Babu Moger wrote:
[...]
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters.
It is not obvious what "very small number" means. Is it possible to give a range to help reader understand the motivation?
How about?
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).
Quoted 6 lines
Quoted 3 lines
Yes, thank you. This helps to understand the claim.
Reinette
Do these queries only happen when userspace reads an
mbm_assign_controlfile?Yes. All these queries are initiated by userspace in the form of individual assignments or creating a group(mkdir).
Quoted 3 lines
It might be worth documenting somewhere that writing and (especially) reading an
mbm_assign_controlfile is not intended to be super-fast.We can drop the last sentence if it is creating confusion.
Quoted 6 lines
It feels like userspace should not generally rely on reading
mbm_assign_controlfiles except for diagnostic purposes, or occasional read-modify-write transformations. Or do expect some other usage model that makes this a hotter path?
Quoted 7 lines
Quoted 2 lines
Cheers
---DaveOur earlier interface was intended to query each group separately. After the input from Peter, we changed it to batched query. One query from userspace can list all the assignments. I am not aware of any other usage model.
Right, that's what I thought.
I'll defer to Reinette on whether it's important to keep the statement about rationale -- it might indeed be easier to drop it if it just raises more questions.
Cheers
---Dave
James Morse
reviewerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
In reply to Babu MogerHi Babu,
Quoted 25 lines · Babu Moger
In
mbm_cntr_assignmode hardware counters are assigned/unassigned to an MBM event of a monitor group. Hardware 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_cfgthat 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.include/linux/resctrl.h +1
-0@@ -94,6 +94,18 @@ struct rdt_ctrl_domain {u32 *mbps_val; }; +/**
include/linux/resctrl.h struct rdt_ctrl_domain { · line 107
Quoted 10 lines
include/linux/resctrl.h +10
-0+* struct mbm_cntr_cfg - assignable counter configuration +* @evtid: MBM event to which the counter is assigned. Only valid +* if @rdtgroup is not NULL. +* @rdtgroup: 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 rdtgroup here suggests this shouldn't be something the arch code is touching.
If its not needed by any arch specific code, (I couldn't find a resctrl_arch helper that takes this) - could it be moved to resctrl's internal.h.
(If this does need to be visible to the arch code, one option would be to replace rdtgroup with the closid/rmid, and a valid flag so that memset() continues to reset these entries)
Thanks,
James
Reinette Chatre
maintainerRe: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Hi James,
Quoted 41 lines · James Morse
Hi Babu,
Quoted 25 lines · Babu Moger
In
mbm_cntr_assignmode hardware counters are assigned/unassigned to an MBM event of a monitor group. Hardware 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_cfgthat 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.include/linux/resctrl.h +1
-0@@ -94,6 +94,18 @@ struct rdt_ctrl_domain {u32 *mbps_val; }; +/** include/linux/resctrl.h struct rdt_ctrl_domain { · line 107
Quoted 10 lines
include/linux/resctrl.h +10
-0+* struct mbm_cntr_cfg - assignable counter configuration +* @evtid: MBM event to which the counter is assigned. Only valid +* if @rdtgroup is not NULL. +* @rdtgroup: 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 rdtgroup here suggests this shouldn't be something the arch code is touching.
Quoted 6 lines
If its not needed by any arch specific code, (I couldn't find a
resctrl_archhelper that takes this) - could it be moved to resctrl'sinternal.h.(If this does need to be visible to the arch code, one option would be to replace rdtgroup with the closid/rmid, and a valid flag so that
memset()continues to reset these entries)
Thank you for catching this!
Reinette
Re: [PATCH v11 11/23] x86/resctrl: Introduce mbm_cntr_cfg to track assignable counters at domain
Quoted 47 lines · Reinette Chatre
Hi James,
Quoted 44 lines · James Morse
Hi Babu,
Quoted 25 lines · Babu Moger
In
mbm_cntr_assignmode hardware counters are assigned/unassigned to an MBM event of a monitor group. Hardware 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_cfgthat 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.include/linux/resctrl.h +1
-0@@ -94,6 +94,18 @@ struct rdt_ctrl_domain {u32 *mbps_val; }; +/** include/linux/resctrl.h struct rdt_ctrl_domain { · line 107
Quoted 10 lines
include/linux/resctrl.h +10
-0+* struct mbm_cntr_cfg - assignable counter configuration +* @evtid: MBM event to which the counter is assigned. Only valid +* if @rdtgroup is not NULL. +* @rdtgroup: 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 rdtgroup here suggests this shouldn't be something the arch code is touching.
If its not needed by any arch specific code, (I couldn't find a
resctrl_archhelper that takes this) - could it be moved to resctrl'sinternal.h.
Quoted 9 lines
Quoted 3 lines
(If this does need to be visible to the arch code, one option would be to replace rdtgroup with the closid/rmid, and a valid flag so that
memset()continues to reset these entries)Thank you for catching this!
Reinette
Sure. Will move it to arch/x86/kernel/cpu/resctrl/internal.h.
thanks
Babu
Babu Moger
reviewerPATCH v11 12/23 x86/resctrl: Introduce interface to display number of free counters
In reply to Babu MogerProvide the interface to display the number of monitoring counters available for assignment in each domain when mbm_cntr_assign is enabled.
---
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/arch/x86/resctrl.rst | 8 +++++ arch/x86/kernel/cpu/resctrl/monitor.c | 1 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 46 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+)
Documentation/arch/x86/resctrl.rst +8 -0
@@ -299,6 +299,14 @@ with the following files: memory bandwidth tracking to a single memory bandwidth event per monitoring group. +"available_mbm_cntrs": + The number of monitoring counters available for assignment in each + domain when mbm_cntr_assign mode is enabled on the system. + :: + + # 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
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
@@ -1234,6 +1234,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)cpuid_count (0x80000020 ,5 , &eax, &ebx, &ecx, &edx); r->mon.num_mbm_cntrs = (ebx &GENMASK (15 ,0 )) +1 ;resctrl_file_fflags_init ("num_mbm_cntrs" ,RFTYPE_MON_INFO ); +resctrl_file_fflags_init ("available_mbm_cntrs" ,RFTYPE_MON_INFO ); } }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +46 -0
58 lines not on this page · raw message
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 12/23] x86/resctrl: Introduce interface to display number of free counters
Hi Babu,
Quoted 2 lines · Babu Moger
Provide the interface to display the number of monitoring counters available for assignment in each domain when
mbm_cntr_assignis enabled.
"when mbm_cntr_assign is enabled" -> "when mbm_cntr_assign mode is enabled"?
Quoted 16 lines
Signed-off-by Babu Moger <[email protected]>---
--- Documentation/arch/x86/resctrl.rst | 8 +++++ arch/x86/kernel/cpu/resctrl/monitor.c | 1 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 46 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+)Documentation/arch/x86/resctrl.rst +0
-0
Documentation/arch/x86/resctrl.rst with the following files: · line 306
Quoted 8 lines
Documentation/arch/x86/resctrl.rst +5
-0@@ -299,6 +299,14 @@ with the following files: memory bandwidth tracking to a single memory bandwidth event per monitoring group. +"available_mbm_cntrs": + The number of monitoring counters available for assignment in each + domain when mbm_cntr_assign mode is enabled on the system. + :: +
Documentation jumps in with some hardcoded values that may cause confusion. It looks to be missing something like (and looking back this also applies to "num_mbm_cntrs"):
"For example, on a system with 30 available monitoring/(hardware?) counters in each of its L3 domains:"
Quoted 30 lines
Documentation/arch/x86/resctrl.rst +3
-0+ # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs + 0=30;1=30 + "max_threshold_occupancy":Documentation/arch/x86/resctrl.rst +0
-0Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancyarch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1234,6 +1234,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)cpuid_count (0x80000020 ,5 , &eax, &ebx, &ecx, &edx); r->mon.num_mbm_cntrs = (ebx &GENMASK (15 ,0 )) +1 ;resctrl_file_fflags_init ("num_mbm_cntrs" ,RFTYPE_MON_INFO ); +resctrl_file_fflags_init ("available_mbm_cntrs" ,RFTYPE_MON_INFO ); } }arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0@@ -888,6 +888,46 @@ 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)
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 902
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+{ +struct rdt_resource *r = of->kn->parent->priv; +struct rdt_mon_domain *dom; +bool sep = false; +u32 cntrs, i; +int ret =0 ; + +cpus_read_lock (); +mutex_lock (&rdtgroup_mutex); +
Missing rdt_last_cmd_clear()?
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 911
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9
-0+if (!resctrl_arch_mbm_cntr_assign_enabled (r)) { +rdt_last_cmd_puts ("mbm_cntr_assign mode is not enabled\n" ); + ret = -EINVAL ; + goto unlock_cntrs_show; + } + +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +if (sep) +seq_puts (s,";" );
The one character prints can be simplified with a seq_putc().
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 919
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-0+ + cntrs =0 ; +for (i =0 ; i < r->mon.num_mbm_cntrs; i++) { +if (!dom->cntr_cfg[i].rdtgrp) + cntrs++; + } + +seq_printf (s,"%d=%d" , dom->hdr.id, cntrs);
I expect cntrs to need %u?
Quoted 17 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11
-0+ sep = true; + } +seq_puts (s,"\n" ); + +unlock_cntrs_show: +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); + +return ret; +} +#ifdef CONFIG_PROC_CPU_RESCTRL /* @@ -1916,6 +1956,12 @@ static struct rftype res_common_files[] = { .kf_ops = &rdtgroup_kf_single_ops, .seq_show = resctrl_num_mbm_cntrs_show,
arch/x86/kernel/cpu/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 1967
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-0}, + { + .name = "available_mbm_cntrs", + .mode = 0444, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = resctrl_available_mbm_cntrs_show, + }, { .name = "cpus", .mode = 0644,
Reinette
Re: [PATCH v11 12/23] x86/resctrl: Introduce interface to display number of free counters
Hi Reinette,
Quoted 7 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu Moger
Provide the interface to display the number of monitoring counters available for assignment in each domain when
mbm_cntr_assignis enabled."when
mbm_cntr_assignis enabled" -> "whenmbm_cntr_assignmode is enabled"?
Sure.
Quoted 20 lines
Quoted 20 lines
Signed-off-by Babu Moger <[email protected]>---
--- Documentation/arch/x86/resctrl.rst | 8 +++++ arch/x86/kernel/cpu/resctrl/monitor.c | 1 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 46 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+)Documentation/arch/x86/resctrl.rst +0
-0@@ -299,6 +299,14 @@ with the following files: memory bandwidth tracking to a single memory bandwidth event per monitoring group.
Quoted 11 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 306
Quoted 5 lines
Documentation/arch/x86/resctrl.rst +5
-0+"available_mbm_cntrs": + The number of monitoring counters available for assignment in each + domain when mbm_cntr_assign mode is enabled on the system. + :: +Documentation jumps in with some hardcoded values that may cause confusion. It looks to be missing something like (and looking back this also applies to "
num_mbm_cntrs"):
"For example, on a system with 30 available monitoring/(hardware?) counters in each of its L3 domains:"
Sure.
Quoted 30 lines
Quoted 30 lines
Documentation/arch/x86/resctrl.rst +3
-0+ # 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_occupancyarch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1234,6 +1234,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)cpuid_count (0x80000020 ,5 , &eax, &ebx, &ecx, &edx); r->mon.num_mbm_cntrs = (ebx &GENMASK (15 ,0 )) +1 ;resctrl_file_fflags_init ("num_mbm_cntrs" ,RFTYPE_MON_INFO ); +resctrl_file_fflags_init ("available_mbm_cntrs" ,RFTYPE_MON_INFO ); } }arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -888,6 +888,46 @@ static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,return 0 ; }
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 902
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +12
-0+static int resctrl_available_mbm_cntrs_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{ +struct rdt_resource *r = of->kn->parent->priv; +struct rdt_mon_domain *dom; +bool sep = false; +u32 cntrs, i; +int ret =0 ; + +cpus_read_lock (); +mutex_lock (&rdtgroup_mutex); +Missing
rdt_last_cmd_clear()?
Yes.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 911
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9
-0+if (!resctrl_arch_mbm_cntr_assign_enabled (r)) { +rdt_last_cmd_puts ("mbm_cntr_assign mode is not enabled\n" ); + ret = -EINVAL ; + goto unlock_cntrs_show; + } + +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +if (sep) +seq_puts (s,";" );The one character prints can be simplified with a
seq_putc().
Sure.
seq_putc(s, ';');
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, · line 919
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-0+ + cntrs =0 ; +for (i =0 ; i < r->mon.num_mbm_cntrs; i++) { +if (!dom->cntr_cfg[i].rdtgrp) + cntrs++; + } + +seq_printf (s,"%d=%d" , dom->hdr.id, cntrs);I expect cntrs to need %u?
Sure.
Quoted 14 lines
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11
-0+ sep = true; + } +seq_puts (s,"\n" ); + +unlock_cntrs_show: +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); + +return ret; +} +#ifdef CONFIG_PROC_CPU_RESCTRL
Quoted 17 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0/* @@ -1916,6 +1956,12 @@ static struct rftype res_common_files[] = { .kf_ops = &rdtgroup_kf_single_ops, .seq_show = resctrl_num_mbm_cntrs_show,arch/x86/kernel/cpu/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 1967
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-0}, + { + .name = "available_mbm_cntrs", + .mode = 0444, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = resctrl_available_mbm_cntrs_show, + }, { .name = "cpus", .mode = 0644,Reinette
Thanks
Babu
Dave Martin
reviewerRe: [PATCH v11 12/23] x86/resctrl: Introduce interface to display number of free counters
Quoted 6 lines · Babu
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
On 1/22/25 12:20 PM, Babu Moger wrote:
[...]
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +3
-0@@ -299,6 +299,14 @@ with the following files: memory bandwidth tracking to a single memory bandwidth event per monitoring group. +"available_mbm_cntrs": + The number of monitoring counters available for assignment in each + domain when mbm_cntr_assign mode is enabled on the system.Quoted 8 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 305
Quoted 2 lines
Documentation/arch/x86/resctrl.rst +2
-0+ :: +Documentation jumps in with some hardcoded values that may cause confusion. It looks to be missing something like (and looking back this also applies to "
num_mbm_cntrs"):
"For example, on a system with 30 available monitoring/(hardware?) counters in each of its L3 domains:"
Quoted 1 line
Sure.
It could make sense to write something like
"... 30 available [hardware] memory bandwidth counters in each ..."
MPAM has different kinds of counters, at least in theory.
(No big deal, though.)
Cheers
---Dave
Babu Moger
reviewerPATCH v11 13/23 x86/resctrl: Add data structures and definitions for ABMC assignment
In reply to Babu MogerThe ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as the counter is assigned. The bandwidth events will be tracked by the hardware until the user changes the configuration. Each resctrl group can configure maximum two counters, one for total event and one for local event.
The ABMC feature implements an MSR L3_QOS_ABMC_CFG (C000_03FDh). Configuration is done by setting the counter id, bandwidth source (RMID) and bandwidth configuration supported by BMEC (Bandwidth Monitoring Event 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
to track for this counter
==========================================================================
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).
---
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 | 35 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1197,6 +1197,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 +35 -0
@@ -617,6 +617,41 @@ struct mon_config_info {u32 mon_config; }; +/* +* ABMC counters are configured by writing to L3_QOS_ABMC_CFG. +* @bw_type : Bandwidth configuration (supported by BMEC) +* 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_last_cmd_clear (void );void rdt_last_cmd_puts (const char *s);__printf (1 ,2 )
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 14/23 x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC
In reply to Babu MogerThe ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually.
Implement an architecture-specific handler to assign and unassign the counter. 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).---
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/internal.h | 3 ++ arch/x86/kernel/cpu/resctrl/monitor.c | 42 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +3 -0
@@ -724,4 +724,7 @@ unsigned int mon_event_config_index_get(u32 evtid);void resctrl_arch_mon_event_config_set (void *info);u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d,enum resctrl_event_id eventid); +int 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);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +42 -0
45 lines not on this page · raw message
Signature · 1 line
2.34.1
Dave Martin
reviewerRe: [PATCH v11 14/23] x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC
Quoted 18 lines · Babu Moger
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually.
Implement an architecture-specific handler to assign and unassign the counter. Configure counters by writing to the
L3_QOS_ABMC_CFGMSR, 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 ProgrammingPublication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).---
[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0
-0@@ -1371,3 +1371,45 @@ void resctrl_arch_mon_event_config_set(void *info)
[...]
Quoted 19 lines
arch/x86/kernel/cpu/resctrl/monitor.c +19
-0+/* +* Send an IPI to the domain to assign the counter to RMID, event pair. +*/ +int 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; + +/* Update the event configuration from the domain */ +if (evtid ==QOS_L3_MBM_TOTAL_EVENT_ID ) + abmc_cfg.split.bw_type = hw_dom->mbm_total_cfg;
arch/x86/kernel/cpu/resctrl/monitor.c void resctrl_arch_mon_event_config_set(void *info) · line 1410
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+else + abmc_cfg.split.bw_type = hw_dom->mbm_local_cfg; + +smp_call_function_any (&d->hdr.cpu_mask, resctrl_abmc_config_one_amd, &abmc_cfg,1 ); + +/* +* Reset the architectural state so that reading of hardware +* counter is not considered as an overflow in next update. +*/ + am =get_arch_mbm_state (hw_dom, rmid, evtid);
Is this necessary when unassigning the counter, or only when assigning?
arch/x86/kernel/cpu/resctrl/monitor.c void resctrl_arch_mon_event_config_set(void *info) · line 1415
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +5
-0+if (am) +memset (am,0 ,sizeof (*am)); + +return 0 ; +}
[...]
Cheers
---Dave
Moger, Babu
reviewerRe: [PATCH v11 14/23] x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC
Hi Dave,
Quoted 53 lines · Dave Martin
Quoted 18 lines · Babu Moger
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually.
Implement an architecture-specific handler to assign and unassign the counter. Configure counters by writing to the
L3_QOS_ABMC_CFGMSR, 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 ProgrammingPublication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).---
[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0
-0@@ -1371,3 +1371,45 @@ void resctrl_arch_mon_event_config_set(void *info)[...]
Quoted 23 lines
arch/x86/kernel/cpu/resctrl/monitor.c +23
-0+/* +* Send an IPI to the domain to assign the counter to RMID, event pair. +*/ +int 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; + +/* Update the event configuration from the domain */ +if (evtid ==QOS_L3_MBM_TOTAL_EVENT_ID ) + abmc_cfg.split.bw_type = hw_dom->mbm_total_cfg; +else + abmc_cfg.split.bw_type = hw_dom->mbm_local_cfg; + +smp_call_function_any (&d->hdr.cpu_mask, resctrl_abmc_config_one_amd, &abmc_cfg,1 );
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c void resctrl_arch_mon_event_config_set(void *info) · line 1410
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ +/* +* Reset the architectural state so that reading of hardware +* counter is not considered as an overflow in next update. +*/ + am =get_arch_mbm_state (hw_dom, rmid, evtid);Is this necessary when unassigning the counter, or only when assigning?
Yes. It is only required when assigning. Will add a check. thanks
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/monitor.c void resctrl_arch_mon_event_config_set(void *info) · line 1415
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +5
-0+if (am) +memset (am,0 ,sizeof (*am)); + +return 0 ; +}[...]
Cheers
---Dave
Signature · 2 lines
Thanks Babu Moger
James Morse
reviewerRe: [PATCH v11 14/23] x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC
In reply to Babu MogerHi Babu,
Quoted 20 lines · Babu Moger
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually.
Implement an architecture-specific handler to assign and unassign the counter. Configure counters by writing to the
L3_QOS_ABMC_CFGMSR, 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 ProgrammingPublication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h unsigned int mon_event_config_index_get(u32 evtid); · line 730
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/internal.h +3
-0@@ -724,4 +724,7 @@ unsigned int mon_event_config_index_get(u32 evtid);void resctrl_arch_mon_event_config_set (void *info);u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d,enum resctrl_event_id eventid); +int 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);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
Could this be added to include/linux/resctrl.h instead? Its where it needs to end up eventually.
Thanks,
James
Re: [PATCH v11 14/23] x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC
Hi James,
Quoted 18 lines · James Morse
Hi Babu,
Quoted 14 lines · Babu Moger
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually.
Implement an architecture-specific handler to assign and unassign the counter. Configure counters by writing to the
L3_QOS_ABMC_CFGMSR, 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 ProgrammingPublication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC).
Quoted 17 lines
arch/x86/kernel/cpu/resctrl/internal.h unsigned int mon_event_config_index_get(u32 evtid); · line 730
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/internal.h +3
-0@@ -724,4 +724,7 @@ unsigned int mon_event_config_index_get(u32 evtid);void resctrl_arch_mon_event_config_set (void *info);u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d,enum resctrl_event_id eventid); +int 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);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ Could this be added to
include/linux/resctrl.hinstead? Its where it needs to end up eventually.
As Reinette already mentioned in [1], Boris wanted this moved when arch/fs code separation integrated. Lets keep it in resctrl/internal.h for now.
[1] https://lore.kernel.org/lkml/[email protected]/
Thanks
Babu
Quoted 4 lines
Thanks,
James
Babu Moger
reviewerPATCH v11 15/23 x86/resctrl: Add the functionality to assigm MBM events
In reply to Babu MogerThe mbm_cntr_assign mode offers several counters that can be assigned to an RMID, event pair and monitor the bandwidth as long as it is assigned.
Add the functionality to allocate and assign the counters to RMID, event pair in the domain.
If all counters are in use, the kernel will show an error message: "Out of MBM assignable counters" when a new assignment is requested. Exit on the first failure when assigning counters across all the domains. Report the error in /sys/fs/resctrl/info/last_cmd_status.
---
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.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/monitor.c | 105 +++++++++++++++++++++++++ 2 files changed, 107 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -727,4 +727,6 @@ u32 resctrl_arch_mon_event_config_get(struct rdt_mon_domain *d,int 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); +int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +105 -0
108 lines not on this page · raw message
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 15/23] x86/resctrl: Add the functionality to assigm MBM events
Hi Babu,
subject: "assigm" -> "assign"
Quoted 1 line · Babu Moger
The
mbm_cntr_assignmode offers several counters that can be assigned
This "several counters" contradicts the "very small number of assignable counters" used in earlier patch to justify how counters are managed.
Quoted 13 lines
to an RMID, event pair and monitor the bandwidth as long as it is assigned.
Add the functionality to allocate and assign the counters to RMID, event pair in the domain.
If all counters are in use, the kernel will show an error message: "Out of MBM assignable counters" when a new assignment is requested. Exit on the first failure when assigning counters across all the domains. Report the error in
/sys/fs/resctrl/info/last_cmd_status.Signed-off-by Babu Moger <[email protected]>---
..
Quoted 75 lines
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/monitor.c | 105 +++++++++++++++++++++++++ 2 files changed, 107 insertions(+)arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -727,4 +727,6 @@ u32 resctrl_arch_mon_event_config_get(struct rdt_mon_domain *d,int 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); +int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/monitor.c +51
-0@@ -1413,3 +1413,108 @@ int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,return 0 ; } + +/* +* Configure the counter for the event, RMID pair for the domain. Reset the +* non-architectural state to clear all the event counters. +*/ +static int resctrl_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 mbm_state *m; +int ret; + + ret =resctrl_arch_config_cntr (r, d, evtid, rmid, closid, cntr_id, assign); +if (ret) +return ret; + + m =get_mbm_state (d, closid, rmid, evtid); +if (m) +memset (m,0 ,sizeof (struct mbm_state )); + +return ret; +} + +static int mbm_cntr_get (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id; + +for (cntr_id =0 ; cntr_id < r->mon.num_mbm_cntrs; cntr_id++) { +if (d->cntr_cfg[cntr_id].rdtgrp == rdtgrp && + d->cntr_cfg[cntr_id].evtid == evtid) +return cntr_id; + } + +return -ENOENT ; +} + +static int mbm_cntr_alloc (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id; + +for (cntr_id =0 ; cntr_id < r->mon.num_mbm_cntrs; cntr_id++) { +if (!d->cntr_cfg[cntr_id].rdtgrp) { + d->cntr_cfg[cntr_id].rdtgrp = rdtgrp; + d->cntr_cfg[cntr_id].evtid = evtid; +return cntr_id; + } + } + +return -ENOSPC ;
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1476
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+} + +static void mbm_cntr_free (struct rdt_mon_domain *d,int cntr_id) +{ +memset (&d->cntr_cfg[cntr_id],0 ,sizeof (struct mbm_cntr_cfg )); +} + +/* +* Allocate a fresh counter and configure the event if not assigned already +* else return success.
I find this confusing. I think the "else return success" can just be dropped.
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1483
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0+*/ +static int resctrl_alloc_config_cntr (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id, ret =0 ; + +if (mbm_cntr_get (r, d, rdtgrp, evtid) == -ENOENT ) {
This can be simplified while reducing a level of indent with:
/* No need to allocate and configure if counter already assigned to this event. */ if (mbm_cntr_get(r, d, rdtgrp, evtid) >= 0) return 0;
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1486
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3
-0+ cntr_id =mbm_cntr_alloc (r, d, rdtgrp, evtid); +if (cntr_id <0 ) { + rdt_last_cmd_printf("Domain %d is Out of MBM assignable counter\n",
"Domain %d is Out of MBM assignable counter" -> "Domain %d is out of MBM assignable counters" or, the message can be something like "Unable to allocate counter in domain %d" to not assume the error and just return the error directly. resctrl_process_flags() can in turn not override the error resulting in -ENOSPC returned to userspace that can be interpreted appropriately instead of always returning -EINVAL and requiring user space to check last_cmd_status?
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1488
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-0+ d->hdr.id); +return -ENOSPC ;
Please do not override error of a function.
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1494
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ } + + ret =resctrl_config_cntr (r, d, evtid, rdtgrp->mon.rmid, rdtgrp->closid, + cntr_id, true); +if (ret) { +rdt_last_cmd_printf ("Assignment failed on domain %d\n" , d->hdr.id);
I assume this targets the scenario when user space requests "all" domains to be changed and the error message in resctrl_process_flags() will then print "*" instead of the actual domain ID. If this is the goal to give more detail to error then the event can be displayed also?
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1505
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/monitor.c +11
-0+mbm_cntr_free (d, cntr_id); + } + } + +return ret; +} + +/* +* Assign a hardware counter to event @evtid of group @rdtgrp. +* Counter will be assigned to all the domains if @d is NULL else +* the counter will be assigned to @d.
Please use available 80 chars.
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1514
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +9
-0+*/ +int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int ret =0 ; + +if (!d) { +list_for_each_entry (d, &r->mon_domains, hdr.list) + ret =resctrl_alloc_config_cntr (r, d, rdtgrp, evtid);
This does not "exit on first failure" as the changelog claims. It actually looks like as long as the last domain succeeds, while all other domains fail, this request is considered successful.
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1520
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ }else { + ret =resctrl_alloc_config_cntr (r, d, rdtgrp, evtid); + } + +return ret; +}
Reinette
Re: [PATCH v11 15/23] x86/resctrl: Add the functionality to assigm MBM events
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
subject: "assigm" -> "assign"
Sure.
Quoted 6 lines · Babu Moger
Quoted 1 line
The
mbm_cntr_assignmode offers several counters that can be assignedThis "several counters" contradicts the "very small number of assignable counters" used in earlier patch to justify how counters are managed.
How about?
The mbm_cntr_assign mode offers "num_mbm_cntrs" number of counters that can be assigned to an RMID, event pair and monitor the bandwidth as long as it is assigned.
Quoted 96 lines
Quoted 14 lines
to an RMID, event pair and monitor the bandwidth as long as it is assigned.
Add the functionality to allocate and assign the counters to RMID, event pair in the domain.
If all counters are in use, the kernel will show an error message: "Out of MBM assignable counters" when a new assignment is requested. Exit on the first failure when assigning counters across all the domains. Report the error in
/sys/fs/resctrl/info/last_cmd_status.Signed-off-by Babu Moger <[email protected]>---
..
Quoted 79 lines
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/monitor.c | 105 +++++++++++++++++++++++++ 2 files changed, 107 insertions(+)arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -727,4 +727,6 @@ u32 resctrl_arch_mon_event_config_get(struct rdt_mon_domain *d,int 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); +int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/monitor.c +55
-0@@ -1413,3 +1413,108 @@ int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,return 0 ; } + +/* +* Configure the counter for the event, RMID pair for the domain. Reset the +* non-architectural state to clear all the event counters. +*/ +static int resctrl_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 mbm_state *m; +int ret; + + ret =resctrl_arch_config_cntr (r, d, evtid, rmid, closid, cntr_id, assign); +if (ret) +return ret; + + m =get_mbm_state (d, closid, rmid, evtid); +if (m) +memset (m,0 ,sizeof (struct mbm_state )); + +return ret; +} + +static int mbm_cntr_get (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id; + +for (cntr_id =0 ; cntr_id < r->mon.num_mbm_cntrs; cntr_id++) { +if (d->cntr_cfg[cntr_id].rdtgrp == rdtgrp && + d->cntr_cfg[cntr_id].evtid == evtid) +return cntr_id; + } + +return -ENOENT ; +} + +static int mbm_cntr_alloc (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id; + +for (cntr_id =0 ; cntr_id < r->mon.num_mbm_cntrs; cntr_id++) { +if (!d->cntr_cfg[cntr_id].rdtgrp) { + d->cntr_cfg[cntr_id].rdtgrp = rdtgrp; + d->cntr_cfg[cntr_id].evtid = evtid; +return cntr_id; + } + } + +return -ENOSPC ; +} + +static void mbm_cntr_free (struct rdt_mon_domain *d,int cntr_id) +{
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1476
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+memset (&d->cntr_cfg[cntr_id],0 ,sizeof (struct mbm_cntr_cfg )); +} + +/* +* Allocate a fresh counter and configure the event if not assigned already +* else return success. I find this confusing. I think the "else return success" can just be dropped.
Sure.
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1483
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0+*/ +static int resctrl_alloc_config_cntr (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id, ret =0 ; + +if (mbm_cntr_get (r, d, rdtgrp, evtid) == -ENOENT ) {This can be simplified while reducing a level of indent with:
Quoted 3 lines
/* No need to allocate and configure if counter already assigned to this event. */ if (mbm_cntr_get(r, d, rdtgrp, evtid) >= 0) return 0;
Sure.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1486
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3
-0+ cntr_id =mbm_cntr_alloc (r, d, rdtgrp, evtid); +if (cntr_id <0 ) { + rdt_last_cmd_printf("Domain %d is Out of MBM assignable counter\n","Domain %d is Out of MBM assignable counter" -> "Domain %d is out of MBM assignable counters" or, the message can be something like "Unable to allocate counter in domain %d" to not
Yes. "Unable to allocate counter in domain %d" sounds better.
Quoted 4 lines
assume the error and just return the error directly.
resctrl_process_flags()can in turn not override the error resulting in-ENOSPCreturned to userspace that can be interpreted appropriately instead of always returning-EINVALand requiring user space to checklast_cmd_status?
Sure.
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1488
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-0+ d->hdr.id); +return -ENOSPC ;Please do not override error of a function.
Ok
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1494
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ } + + ret =resctrl_config_cntr (r, d, evtid, rdtgrp->mon.rmid, rdtgrp->closid, + cntr_id, true); +if (ret) { +rdt_last_cmd_printf ("Assignment failed on domain %d\n" , d->hdr.id);I assume this targets the scenario when user space requests "all" domains to be changed and the error message in
resctrl_process_flags()will then print "*" instead of the actual domain ID. If this is the goal to give more detail to error then the event can be displayed also?
Sure. Will change it to.
rdt_last_cmd_printf("Assignment of event %d failed on domain %d\n", d->hdr.id, evtid);
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1505
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/monitor.c +11
-0+mbm_cntr_free (d, cntr_id); + } + } + +return ret; +} + +/* +* Assign a hardware counter to event @evtid of group @rdtgrp. +* Counter will be assigned to all the domains if @d is NULL else +* the counter will be assigned to @d. Please use available 80 chars.
Sure.
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1514
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +9
-0+*/ +int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int ret =0 ; + +if (!d) { +list_for_each_entry (d, &r->mon_domains, hdr.list) + ret =resctrl_alloc_config_cntr (r, d, rdtgrp, evtid);This does not "exit on first failure" as the changelog claims. It actually looks like as long as the last domain succeeds, while all other domains fail, this request is considered successful.
Yes. That is correct. I have to check return status in each loop. Will fix it.
list_for_each_entry(d, &r->mon_domains, hdr.list) {
ret = resctrl_alloc_config_cntr(r, d, rdtgrp, evtid);
if (ret)
return ret;
}Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1520
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ }else { + ret =resctrl_alloc_config_cntr (r, d, rdtgrp, evtid); + } + +return ret; +}Reinette
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v11 15/23] x86/resctrl: Add the functionality to assigm MBM events
Hi Babu,
Quoted 4 lines · Babu
Hi Reinette,
Quoted 1 line · Reinette Chatre
On 1/22/25 12:20 PM, Babu Moger wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
The
mbm_cntr_assignmode offers several counters that can be assignedThis "several counters" contradicts the "very small number of assignable counters" used in earlier patch to justify how counters are managed.
How about?
The
mbm_cntr_assignmode offers "num_mbm_cntrs" number of counters that can be assigned to an RMID, event pair and monitor the bandwidth as long as it is assigned.
Sure. The word "several" can just be dropped from original also. The concern is not the language but instead that the description moves from "several" in one patch and then "limited" in the next patch.
...
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+ }
+
+ ret = resctrl_config_cntr(r, d, evtid,rdtgrp->mon.rmid,rdtgrp->closid, +cntr_id, true);
+ if (ret) {
+rdt_last_cmd_printf("Assignment failed on domain %d\n", d->hdr.id);
Quoted 8 lines
Quoted 4 lines
I assume this targets the scenario when user space requests "all" domains to be changed and the error message in
resctrl_process_flags()will then print "*" instead of the actual domain ID. If this is the goal to give more detail to error then the event can be displayed also?Sure. Will change it to.
rdt_last_cmd_printf("Assignment of event %d failed on domain %d\n", d->hdr.id, evtid);
ok, printing the event ID should be OK since the ID will be part of resctrl fs and not architecture specific. Please just swap last two parameters.
Reinette
Babu Moger
reviewerPATCH v11 16/23 x86/resctrl: Add the functionality to unassigm MBM events
In reply to Babu MogerThe mbm_cntr_assign mode provides a limited number of hardware counters that can be assigned to an RMID, event pair to monitor bandwidth while assigned. If all counters are in use, the kernel will show an error
message: "Out of MBM assignable counters" 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.
---
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.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/monitor.c | 39 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -729,4 +729,6 @@ int resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, u32 cntr_id, bool assign);int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid); +int resctrl_unassign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +39 -0
@@ -1518,3 +1518,42 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d,return ret; } + +/* +* Unassign and free the counter if assigned else return success. +*/ +static int resctrl_free_config_cntr (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id, ret =0 ; + + cntr_id =mbm_cntr_get (r, d, rdtgrp, evtid); +if (cntr_id != -ENOENT ) { + ret =resctrl_config_cntr (r, d, evtid, rdtgrp->mon.rmid, + rdtgrp->closid, cntr_id, false); +if (!ret) +mbm_cntr_free (d, cntr_id); + } + +return ret; +} + +/* +* Unassign a hardware counter associated with @evtid from the domain and +* the group. Unassign the counters from all the domains if @d is NULL else +* unassign from @d. +*/ +int resctrl_unassign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int ret =0 ; + +if (!d) { +list_for_each_entry (d, &r->mon_domains, hdr.list) + ret =resctrl_free_config_cntr (r, d, rdtgrp, evtid); + }else { + ret =resctrl_free_config_cntr (r, d, rdtgrp, evtid); + } + +return ret; +}
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 16/23] x86/resctrl: Add the functionality to unassigm MBM events
Hi Babu,
subject: unassigm -> unassign
Quoted 1 line · Babu Moger
The
mbm_cntr_assignmode provides a limited number of hardware counters
(now back to "limited number of hardware counters")
Quoted 4 lines
that can be assigned to an RMID, event pair to monitor bandwidth while assigned. If all counters are in use, the kernel will show an error
message: "Out of MBM assignable counters" when a new assignment is requested. To make space for a new assignment, users must unassign an
To me "kernel will show an error" implies the kernel ring buffer. Please make the message accurate and mention that it will be in last_cmd_status while also considering to use -ENOSPC to help user space.
Quoted 1 line
already assigned counter and retry the assignment again..
".." -> "."
Quoted 4 lines
Add the functionality to unassign and free the counters in the domain.
Signed-off-by Babu Moger <[email protected]>
...
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1518,3 +1518,42 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d,return ret; } +
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1531
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+/* +* Unassign and free the counter if assigned else return success. +*/ +static int resctrl_free_config_cntr (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id, ret =0 ; + + cntr_id =mbm_cntr_get (r, d, rdtgrp, evtid); +if (cntr_id != -ENOENT ) {
This can be simplified and indent level reduced with:
cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid); if (cntr_id < 0) return ret;
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/monitor.c +12
-0+ ret =resctrl_config_cntr (r, d, evtid, rdtgrp->mon.rmid, + rdtgrp->closid, cntr_id, false); +if (!ret) +mbm_cntr_free (d, cntr_id); + } + +return ret; +} + +/* +* Unassign a hardware counter associated with @evtid from the domain and +* the group. Unassign the counters from all the domains if @d is NULL else
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1553
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+* unassign from @d. +*/ +int resctrl_unassign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int ret =0 ; + +if (!d) { +list_for_each_entry (d, &r->mon_domains, hdr.list) + ret =resctrl_free_config_cntr (r, d, rdtgrp, evtid);
Same issue as previous patch wrt error handling.
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1559
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ }else { + ret =resctrl_free_config_cntr (r, d, rdtgrp, evtid); + } + +return ret; +}
Reinette
Moger, Babu
reviewerRe: [PATCH v11 16/23] x86/resctrl: Add the functionality to unassigm MBM events
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
subject: unassigm -> unassign
Sure.
Quoted 5 lines · Babu Moger
Quoted 1 line
The
mbm_cntr_assignmode provides a limited number of hardware counters(now back to "limited number of hardware counters")
How about?
The mbm_cntr_assign mode provides "num_mbm_cntrs" number of hardware counters
Quoted 9 lines
Quoted 5 lines
that can be assigned to an RMID, event pair to monitor bandwidth while assigned. If all counters are in use, the kernel will show an error
message: "Out of MBM assignable counters" when a new assignment is requested. To make space for a new assignment, users must unassign anTo me "kernel will show an error" implies the kernel ring buffer. Please make the message accurate and mention that it will be in
last_cmd_statuswhile also considering to use-ENOSPCto help user space.
If all the counters are in use, the kernel will log 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.
Quoted 5 lines
Quoted 2 lines
already assigned counter and retry the assignment again..
".." -> "."
Sure.
Quoted 29 lines
Quoted 4 lines
Add the functionality to unassign and free the counters in the domain.
Signed-off-by Babu Moger <[email protected]>...
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1518,3 +1518,42 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d,return ret; } +arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1531
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+/* +* Unassign and free the counter if assigned else return success. +*/ +static int resctrl_free_config_cntr (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid) +{ +int cntr_id, ret =0 ; + + cntr_id =mbm_cntr_get (r, d, rdtgrp, evtid); +if (cntr_id != -ENOENT ) {This can be simplified and indent level reduced with:
Quoted 4 lines
cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid); if (cntr_id < 0) return ret;
Sure.
Quoted 16 lines
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/monitor.c +16
-0+ ret =resctrl_config_cntr (r, d, evtid, rdtgrp->mon.rmid, + rdtgrp->closid, cntr_id, false); +if (!ret) +mbm_cntr_free (d, cntr_id); + } + +return ret; +} + +/* +* Unassign a hardware counter associated with @evtid from the domain and +* the group. Unassign the counters from all the domains if @d is NULL else +* unassign from @d. +*/ +int resctrl_unassign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid)
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1553
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+{ +int ret =0 ; + +if (!d) { +list_for_each_entry (d, &r->mon_domains, hdr.list) + ret =resctrl_free_config_cntr (r, d, rdtgrp, evtid);Same issue as previous patch wrt error handling.
Yes.
list_for_each_entry(d, &r->mon_domains, hdr.list) {
ret = resctrl_free_config_cntr(r, d, rdtgrp, evtid);
if (ret)
return ret;
}Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, · line 1559
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-0+ }else { + ret =resctrl_free_config_cntr (r, d, rdtgrp, evtid); + } + +return ret; +}Reinette
Signature · 2 lines
Thanks Babu Moger
Reinette Chatre
maintainerRe: [PATCH v11 16/23] x86/resctrl: Add the functionality to unassigm MBM events
Hi Babu,
Quoted 10 lines · Babu
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
subject: unassigm -> unassign
Sure.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines · Babu Moger
Quoted 1 line
The
mbm_cntr_assignmode provides a limited number of hardware counters(now back to "limited number of hardware counters")
How about?
The
mbm_cntr_assignmode provides "num_mbm_cntrs" number of hardware counters
ok.
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
that can be assigned to an RMID, event pair to monitor bandwidth while assigned. If all counters are in use, the kernel will show an error
message: "Out of MBM assignable counters" when a new assignment is requested. To make space for a new assignment, users must unassign anTo me "kernel will show an error" implies the kernel ring buffer. Please make the message accurate and mention that it will be in
last_cmd_statuswhile also considering to use-ENOSPCto help user space.
Quoted 6 lines
If all the counters are in use, the kernel will log the error message "Unable to allocate counter in domain" in
/sys/fs/resctrl/info/last_cmd_statuswhen a new assignment is requested. To make space for a new assignment, users must unassign an already assigned counter and retry the assignment again.
This is better, but can user space receive -ENOSPC to avoid needing to check and parse last_cmd_status on every error?
Reinette
Re: [PATCH v11 16/23] x86/resctrl: Add the functionality to unassigm MBM events
Hi Reinette,
Quoted 42 lines · Reinette Chatre
Hi Babu,
Quoted 10 lines · Babu
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
subject: unassigm -> unassign
Sure.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines · Babu Moger
Quoted 1 line
The
mbm_cntr_assignmode provides a limited number of hardware counters(now back to "limited number of hardware counters")
How about?
The
mbm_cntr_assignmode provides "num_mbm_cntrs" number of hardware countersok.
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
that can be assigned to an RMID, event pair to monitor bandwidth while assigned. If all counters are in use, the kernel will show an error
message: "Out of MBM assignable counters" when a new assignment is requested. To make space for a new assignment, users must unassign anTo me "kernel will show an error" implies the kernel ring buffer. Please make the message accurate and mention that it will be in
last_cmd_statuswhile also considering to use-ENOSPCto help user space.Quoted 6 lines
If all the counters are in use, the kernel will log the error message "Unable to allocate counter in domain" in
/sys/fs/resctrl/info/last_cmd_statuswhen a new assignment is requested. To make space for a new assignment, users must unassign an already assigned counter and retry the assignment again.
Quoted 2 lines
This is better, but can user space receive
-ENOSPCto avoid needing to check and parselast_cmd_statuson every error?
Yes. There was a problem in passing the error in resctrl_process_flags(). Took care of it now.
Thanks
Babu
Babu Moger
reviewerPATCH v11 17/23 x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
In reply to Babu MogerAssign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
---
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.
--- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 27 +++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 63 +++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
@@ -731,4 +731,5 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, enum resctrl_event_id evtid);int resctrl_unassign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid); +void mbm_cntr_reset (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +27 -0
@@ -1557,3 +1557,30 @@ int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *dreturn ret; } + +void mbm_cntr_reset (struct rdt_resource *r) +{ +u32 idx_limit =resctrl_arch_system_num_rmid_idx (); +struct rdt_mon_domain *dom; + +/* +* Reset the domain counter configuration. Hardware counters +* will reset after switching the monitor mode. So, reset the +* architectural amd non-architectural state so that reading +* of hardware counter is not considered as an overflow in the +* next update. +*/ +if (is_mbm_enabled () && r->mon.mbm_cntr_assignable) { +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +memset (dom->cntr_cfg,0 , +sizeof (*dom->cntr_cfg) * r->mon.num_mbm_cntrs); +if (is_mbm_total_enabled ()) +memset (dom->mbm_total,0 , +sizeof (struct mbm_state ) * idx_limit); +if (is_mbm_local_enabled ()) +memset (dom->mbm_local,0 , +sizeof (struct mbm_state ) * idx_limit); +resctrl_arch_reset_rmid_all (r, dom); + } + } +}
arch/x86/kernel/cpu/resctrl/rdtgroup.c +61 -2
128 lines not on this page · raw message
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Babu,
Quoted 21 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
Signed-off-by Babu Moger <[email protected]>---
arch/x86/kernel/cpu/resctrl/monitor.c +0
-0@@ -1557,3 +1557,30 @@ int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *dreturn ret; }
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 1569
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+ +void mbm_cntr_reset (struct rdt_resource *r) +{ +u32 idx_limit =resctrl_arch_system_num_rmid_idx (); +struct rdt_mon_domain *dom; + +/* +* Reset the domain counter configuration. Hardware counters +* will reset after switching the monitor mode. So, reset the +* architectural amd non-architectural state so that reading
"amd" -> "and"
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0+* of hardware counter is not considered as an overflow in the +* next update. +*/ +if (is_mbm_enabled () && r->mon.mbm_cntr_assignable) { +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +memset (dom->cntr_cfg,0 , +sizeof (*dom->cntr_cfg) * r->mon.num_mbm_cntrs);
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 1586
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+if (is_mbm_total_enabled ()) +memset (dom->mbm_total,0 , +sizeof (struct mbm_state ) * idx_limit); +if (is_mbm_local_enabled ()) +memset (dom->mbm_local,0 , +sizeof (struct mbm_state ) * idx_limit); +resctrl_arch_reset_rmid_all (r, dom); + } + } +}
I looked back at the previous versions to better understand how this function came about and I do not think it actually solves the problem it aims to solve.
rdtgroup_unassign_cntrs() can fail and when it does the counter is not free'd. That leaves a monitoring domain's array with an entry that points to a resource group that no longer exists (unless it is the default resource group) since rdtgroup_unassign_cntrs() does not check the return and proceeds to remove the resource group. mbm_cntr_reset() is called on umount of resctrl but rdtgroup_unassign_cntrs() is called on every group remove and those scenarios are not handled.
To address this I believe that I need to go back on a previous request to have resctrl_arch_config_cntr() return an error code. AMD does not need this and it is difficult to predict what will work for MPAM. I originally wanted to be flexible here but this appears to be impractical. With a new requirement that resctrl_arch_config_cntr() always succeeds the counter will in turn always be free'd and not leave dangling pointers. I believe doing so eliminates the need for mbm_cntr_reset() as used in this patch. My apologies for the misdirection. We can re-evaluate these flows if MPAM needs anything different.
Quoted 31 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +23
-0@@ -2687,6 +2687,46 @@ static void schemata_list_destroy(void) } } +/* +* Called when a new group is created. If "mbm_cntr_assign" mode is enabled, +* counters are automatically assigned. Each group can accommodate two counters: +* one for the total event and one for the local event. Assignments may fail +* due to the limited number of counters. However, it is not necessary to fail +* the group creation and thus no failure is returned. Users have the option +* to modify the counter assignments after the group has been created. +*/ +static void rdtgroup_assign_cntrs (struct rdtgroup *rdtgrp) +{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + +if (!resctrl_arch_mbm_cntr_assign_enabled (r)) +return ; + +if (is_mbm_total_enabled ()) +resctrl_assign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); + +if (is_mbm_local_enabled ()) +resctrl_assign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +} + +/*
arch/x86/kernel/cpu/resctrl/rdtgroup.c static void schemata_list_destroy(void) · line 2722
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+* Called when a group is deleted. Counters are unassigned if it was in +* assigned state. +*/ +static void rdtgroup_unassign_cntrs (struct rdtgroup *rdtgrp) +{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + +if (!resctrl_arch_mbm_cntr_assign_enabled (r)) +return ; +
It looks to me as though there are a couple of places (rmdir_all_sub(), rdt_kill_sb(), and rdtgroup_rmdir_ctrl()) where rdtgroup_unassign_cntrs() could be called on a system that does not support monitoring and/or only supports cache allocation monitoring.
In these paths it is only the architecture's resctrl_arch_mbm_cntr_assign_enabled(r) that gates the resctrl flow. I think rdtgroup_unassign_cntrs() and to match rdtgroup_assign_cntrs() can do with at least a r->mon_capable check.
Quoted 93 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +26
-2+if (is_mbm_total_enabled ()) +resctrl_unassign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); + +if (is_mbm_local_enabled ()) +resctrl_unassign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +} +static int rdt_get_tree (struct fs_context *fc) {struct rdt_fs_context *ctx =rdt_fc2context (fc);@@ -2741,6 +2781,8 @@ static int rdt_get_tree(struct fs_context *fc)if (ret <0 ) goto out_info; +rdtgroup_assign_cntrs (&rdtgroup_default); + ret =mkdir_mondata_all (rdtgroup_default.kn, &rdtgroup_default, &kn_mondata);if (ret <0 )@@ -2779,8 +2821,10 @@ static int rdt_get_tree(struct fs_context *fc)if (resctrl_arch_mon_capable ())kernfs_remove (kn_mondata); out_mongrp: -if (resctrl_arch_mon_capable ()) +if (resctrl_arch_mon_capable ()) { +rdtgroup_unassign_cntrs (&rdtgroup_default);kernfs_remove (kn_mongrp); + } out_info:kernfs_remove (kn_info); out_schemata_free:@@ -2956,6 +3000,7 @@ static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp) head = &rdtgrp->mon.crdtgrp_list;list_for_each_entry_safe (sentry, stmp, head, mon.crdtgrp_list) { +rdtgroup_unassign_cntrs (sentry);free_rmid (sentry->closid, sentry->mon.rmid);list_del (&sentry->mon.crdtgrp_list);@@ -2996,6 +3041,8 @@ static void rmdir_all_sub(void)cpumask_or (&rdtgroup_default.cpu_mask, &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); +rdtgroup_unassign_cntrs (rdtgrp); +free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);kernfs_remove (rdtgrp->kn);@@ -3027,6 +3074,8 @@ static void rdt_kill_sb(struct super_block *sb)for_each_alloc_capable_rdt_resource (r)reset_all_ctrls (r);rmdir_all_sub (); +rdtgroup_unassign_cntrs (&rdtgroup_default); +mbm_cntr_reset (&rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl);rdt_pseudo_lock_release (); rdtgroup_default.mode =RDT_MODE_SHAREABLE ;schemata_list_destroy ();@@ -3490,9 +3539,12 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp) } rdtgrp->mon.rmid = ret; +rdtgroup_assign_cntrs (rdtgrp); + ret =mkdir_mondata_all (rdtgrp->kn, rdtgrp, &rdtgrp->mon.mon_data_kn);if (ret) {rdt_last_cmd_puts ("kernfs subdir error\n" ); +rdtgroup_unassign_cntrs (rdtgrp);free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);return ret; }@@ -3502,8 +3554,10 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp)static void mkdir_rdt_prepare_rmid_free (struct rdtgroup *rgrp) { -if (resctrl_arch_mon_capable ()) +if (resctrl_arch_mon_capable ()) { +rdtgroup_unassign_cntrs (rgrp);free_rmid (rgrp->closid, rgrp->mon.rmid); + } } static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,@@ -3764,6 +3818,9 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)update_closid_rmid (tmpmask,NULL ); rdtgrp->flags =RDT_DELETED ; + +rdtgroup_unassign_cntrs (rdtgrp); +free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);/*
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) · line 3874
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0@@ -3810,6 +3867,8 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)cpumask_or (tmpmask, tmpmask, &rdtgrp->cpu_mask);update_closid_rmid (tmpmask,NULL ); +rdtgroup_unassign_cntrs (rdtgrp); +free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);closid_free (rdtgrp->closid);
Reinette
Moger, Babu
reviewerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Reinette,
Quoted 22 lines · Reinette Chatre
Hi Babu,
Quoted 19 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
Signed-off-by Babu Moger <[email protected]>---
arch/x86/kernel/cpu/resctrl/monitor.c +0
-0@@ -1557,3 +1557,30 @@ int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 1569
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0return ret; } + +void mbm_cntr_reset (struct rdt_resource *r) +{ +u32 idx_limit =resctrl_arch_system_num_rmid_idx (); +struct rdt_mon_domain *dom; + +/* +* Reset the domain counter configuration. Hardware counters +* will reset after switching the monitor mode. So, reset the +* architectural amd non-architectural state so that reading "amd" -> "and"
Sure.
Quoted 30 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0+* of hardware counter is not considered as an overflow in the +* next update. +*/ +if (is_mbm_enabled () && r->mon.mbm_cntr_assignable) { +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +memset (dom->cntr_cfg,0 , +sizeof (*dom->cntr_cfg) * r->mon.num_mbm_cntrs);arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 1586
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+if (is_mbm_total_enabled ()) +memset (dom->mbm_total,0 , +sizeof (struct mbm_state ) * idx_limit); +if (is_mbm_local_enabled ()) +memset (dom->mbm_local,0 , +sizeof (struct mbm_state ) * idx_limit); +resctrl_arch_reset_rmid_all (r, dom); + } + } +}I looked back at the previous versions to better understand how this function came about and I do not think it actually solves the problem it aims to solve.
rdtgroup_unassign_cntrs()can fail and when it does the counter is not free'd. That leaves a monitoring domain's array with an entry that points to a resource group that no longer exists (unless it is the default resource group) sincerdtgroup_unassign_cntrs()does not check the return and proceeds to remove the resource group.mbm_cntr_reset()is called on umount of resctrl butrdtgroup_unassign_cntrs()is called on every group remove and those scenarios are not handled.
Quoted 8 lines
To address this I believe that I need to go back on a previous request to have
resctrl_arch_config_cntr()return an error code. AMD does not need this and it is difficult to predict what will work for MPAM. I originally wanted to be flexible here but this appears to be impractical. With a new requirement thatresctrl_arch_config_cntr()always succeeds the counter will in turn always be free'd and not leave dangling pointers. I believe doing so eliminates the need formbm_cntr_reset()as used in this patch. My apologies for the misdirection. We can re-evaluate these flows if MPAM needs anything different.
So, new requirement is to free the counter even if the resctrl_arch_config_cntr() call fails. That way after calling rdtgroup_unassign_cntrs() the counter is freed and it is in clean state. So, we dont need to call mbm_cntr_reset() in the end to clear all the entries.
Here is the call sequence.
rdtgroup_unassign_cntrs() -> resctrl_unassign_cntr_event() -> resctrl_free_config_cntr() -> resctrl_config_cntr() -> resctrl_arch_config_cntr().
So, only change here is.
/*
* Unassign and free the counter if assigned else return success. */
static int resctrl_free_config_cntr(struct rdt_resource *r,
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, enum resctrl_event_id evtid)
{
int cntr_id, ret = 0;
cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid);
if (cntr_id < 0)return ret;
/* Unassign and free the counter*/
ret = resctrl_config_cntr(r, d, evtid, rdtgrp->mon.rmid,
rdtgrp->closid, cntr_id, false);
mbm_cntr_free(d, cntr_id);
return ret;
}Quoted 47 lines
Quoted 32 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +23
-0@@ -2687,6 +2687,46 @@ static void schemata_list_destroy(void) } } +/* +* Called when a new group is created. If "mbm_cntr_assign" mode is enabled, +* counters are automatically assigned. Each group can accommodate two counters: +* one for the total event and one for the local event. Assignments may fail +* due to the limited number of counters. However, it is not necessary to fail +* the group creation and thus no failure is returned. Users have the option +* to modify the counter assignments after the group has been created. +*/ +static void rdtgroup_assign_cntrs (struct rdtgroup *rdtgrp) +{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + +if (!resctrl_arch_mbm_cntr_assign_enabled (r)) +return ; + +if (is_mbm_total_enabled ()) +resctrl_assign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); + +if (is_mbm_local_enabled ()) +resctrl_assign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +} + +/* arch/x86/kernel/cpu/resctrl/rdtgroup.c static void schemata_list_destroy(void) · line 2722
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+* Called when a group is deleted. Counters are unassigned if it was in +* assigned state. +*/ +static void rdtgroup_unassign_cntrs (struct rdtgroup *rdtgrp) +{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + +if (!resctrl_arch_mbm_cntr_assign_enabled (r)) +return ; +It looks to me as though there are a couple of places (
rmdir_all_sub(),rdt_kill_sb(), andrdtgroup_rmdir_ctrl()) whererdtgroup_unassign_cntrs()could be called on a system that does not support monitoring and/or only supports cache allocation monitoring.
Quoted 3 lines
In these paths it is only the architecture's
resctrl_arch_mbm_cntr_assign_enabled(r)that gates the resctrl flow. I thinkrdtgroup_unassign_cntrs()and to matchrdtgroup_assign_cntrs()can do with at least ar->mon_capablecheck.
ok. Will add following check.
if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r))
return;
Quoted 105 lines
Quoted 94 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +26
-2+if (is_mbm_total_enabled ()) +resctrl_unassign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); + +if (is_mbm_local_enabled ()) +resctrl_unassign_cntr_event (r,NULL , rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +} +static int rdt_get_tree (struct fs_context *fc) {struct rdt_fs_context *ctx =rdt_fc2context (fc);@@ -2741,6 +2781,8 @@ static int rdt_get_tree(struct fs_context *fc)if (ret <0 ) goto out_info; +rdtgroup_assign_cntrs (&rdtgroup_default); + ret =mkdir_mondata_all (rdtgroup_default.kn, &rdtgroup_default, &kn_mondata);if (ret <0 )@@ -2779,8 +2821,10 @@ static int rdt_get_tree(struct fs_context *fc)if (resctrl_arch_mon_capable ())kernfs_remove (kn_mondata); out_mongrp: -if (resctrl_arch_mon_capable ()) +if (resctrl_arch_mon_capable ()) { +rdtgroup_unassign_cntrs (&rdtgroup_default);kernfs_remove (kn_mongrp); + } out_info:kernfs_remove (kn_info); out_schemata_free:@@ -2956,6 +3000,7 @@ static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp) head = &rdtgrp->mon.crdtgrp_list;list_for_each_entry_safe (sentry, stmp, head, mon.crdtgrp_list) { +rdtgroup_unassign_cntrs (sentry);free_rmid (sentry->closid, sentry->mon.rmid);list_del (&sentry->mon.crdtgrp_list);@@ -2996,6 +3041,8 @@ static void rmdir_all_sub(void)cpumask_or (&rdtgroup_default.cpu_mask, &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); +rdtgroup_unassign_cntrs (rdtgrp); +free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);kernfs_remove (rdtgrp->kn);@@ -3027,6 +3074,8 @@ static void rdt_kill_sb(struct super_block *sb)for_each_alloc_capable_rdt_resource (r)reset_all_ctrls (r);rmdir_all_sub (); +rdtgroup_unassign_cntrs (&rdtgroup_default); +mbm_cntr_reset (&rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl);rdt_pseudo_lock_release (); rdtgroup_default.mode =RDT_MODE_SHAREABLE ;schemata_list_destroy ();@@ -3490,9 +3539,12 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp) } rdtgrp->mon.rmid = ret; +rdtgroup_assign_cntrs (rdtgrp); + ret =mkdir_mondata_all (rdtgrp->kn, rdtgrp, &rdtgrp->mon.mon_data_kn);if (ret) {rdt_last_cmd_puts ("kernfs subdir error\n" ); +rdtgroup_unassign_cntrs (rdtgrp);free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);return ret; }@@ -3502,8 +3554,10 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp)static void mkdir_rdt_prepare_rmid_free (struct rdtgroup *rgrp) { -if (resctrl_arch_mon_capable ()) +if (resctrl_arch_mon_capable ()) { +rdtgroup_unassign_cntrs (rgrp);free_rmid (rgrp->closid, rgrp->mon.rmid); + } } static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,@@ -3764,6 +3818,9 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)update_closid_rmid (tmpmask,NULL ); rdtgrp->flags =RDT_DELETED ; + +rdtgroup_unassign_cntrs (rdtgrp); +free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);/* arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) · line 3874
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0@@ -3810,6 +3867,8 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)cpumask_or (tmpmask, tmpmask, &rdtgrp->cpu_mask);update_closid_rmid (tmpmask,NULL ); +rdtgroup_unassign_cntrs (rdtgrp); +free_rmid (rdtgrp->closid, rdtgrp->mon.rmid);closid_free (rdtgrp->closid);Reinette
Signature · 2 lines
Thanks Babu Moger
Reinette Chatre
maintainerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Babu,
Quoted 42 lines · Babu
Quoted 32 lines · Reinette Chatre
Quoted 7 lines · Babu Moger
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0+* of hardware counter is not considered as an overflow in the +* next update. +*/ +if (is_mbm_enabled () && r->mon.mbm_cntr_assignable) { +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +memset (dom->cntr_cfg,0 , +sizeof (*dom->cntr_cfg) * r->mon.num_mbm_cntrs);arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 1586
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10
-0+if (is_mbm_total_enabled ()) +memset (dom->mbm_total,0 , +sizeof (struct mbm_state ) * idx_limit); +if (is_mbm_local_enabled ()) +memset (dom->mbm_local,0 , +sizeof (struct mbm_state ) * idx_limit); +resctrl_arch_reset_rmid_all (r, dom); + } + } +}I looked back at the previous versions to better understand how this function came about and I do not think it actually solves the problem it aims to solve.
rdtgroup_unassign_cntrs()can fail and when it does the counter is not free'd. That leaves a monitoring domain's array with an entry that points to a resource group that no longer exists (unless it is the default resource group) sincerdtgroup_unassign_cntrs()does not check the return and proceeds to remove the resource group.mbm_cntr_reset()is called on umount of resctrl butrdtgroup_unassign_cntrs()is called on every group remove and those scenarios are not handled.Quoted 8 lines
To address this I believe that I need to go back on a previous request to have
resctrl_arch_config_cntr()return an error code. AMD does not need this and it is difficult to predict what will work for MPAM. I originally wanted to be flexible here but this appears to be impractical. With a new requirement thatresctrl_arch_config_cntr()always succeeds the counter will in turn always be free'd and not leave dangling pointers. I believe doing so eliminates the need formbm_cntr_reset()as used in this patch. My apologies for the misdirection. We can re-evaluate these flows if MPAM needs anything different.
Quoted 2 lines
So, new requirement is to free the counter even if the
resctrl_arch_config_cntr()call fails. That way after calling
No. Quoting above: "new requirement that resctrl_arch_config_cntr() always succeeds". As I see it this will eliminate a lot of error checking on the calling path, not ignore errors.
Reinette
Dave Martin
reviewerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
In reply to Babu MogerHi,
Quoted 9 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
If we are doing this, should turning mbm_cntr_assign mode on also trigger auto-assingment for all extant monitoring groups?
Either way though, this auto-assignment feels like a potential nuisance for userspace.
If the userspace use-case requires too many monitoring groups for the available counters, then the kernel will auto-assign counters to a random subset of groups which may or may not be the ones that userspace wanted to monitor; then userspace must manually look for the assigned counters and unassign some of them before they can be assigned where userspace actually wanted them.
This is not impossible for userspace to cope with, but it feels awkward.
Is there a way to inhibit auto-assignment?
Or could automatic assignments be considered somehow "weak", so that new explicit assignments can steal automatically assigned counters without the need to unassign them explicitly?
[...]
Cheers
---Dave
Re: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Dave,
Quoted 27 lines · Dave Martin
Hi,
Quoted 9 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
If we are doing this, should turning
mbm_cntr_assignmode on also trigger auto-assingment for all extant monitoring groups?Either way though, this auto-assignment feels like a potential nuisance for userspace.
If the userspace use-case requires too many monitoring groups for the available counters, then the kernel will auto-assign counters to a random subset of groups which may or may not be the ones that userspace wanted to monitor; then userspace must manually look for the assigned counters and unassign some of them before they can be assigned where userspace actually wanted them.
Quoted 8 lines
This is not impossible for userspace to cope with, but it feels awkward.
Is there a way to inhibit auto-assignment?
Or could automatic assignments be considered somehow "weak", so that new explicit assignments can steal automatically assigned counters without the need to unassign them explicitly?
We had an incomplete discussion about this early on[1]. I guess I didn't revisit it because I found it was trivial to add a flag that inhibits the assignment behavior during mkdir and had moved on to bigger issues.
If an agent creating directories isn't coordinated with the agent managing counters, a series of creating and destroying a group could prevent a monitor assignment from ever succeeding because it's not possible to atomically discover the name of the new directory that stole the previously-available counter and reassign it.
However, if the counter-manager can get all the counters assigned once and only move them with atomic reassignments, it will become impossible to snatch them with a mkdir.
-Peter
[1] https://lore.kernel.org/lkml/CALPaoCihfQ9VtLYzyHB9-PsQzXLc06BW8bzhBXwj9-i+Q8RVFQ@mail.gmail.com/
Reinette Chatre
maintainerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Dave and Peter,
Quoted 22 lines · Peter Newman
Hi Dave,
Quoted 19 lines · Dave Martin
Hi,
Quoted 9 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
If we are doing this, should turning
mbm_cntr_assignmode on also trigger auto-assingment for all extant monitoring groups?Either way though, this auto-assignment feels like a potential nuisance for userspace.
hmmm ... this auto-assignment was created with the goal to help userspace. In mbm_cntr_assign mode the user will only see data when a counter is assigned to an event. mbm_cntr_assign mode is selected as default on a system that supports ABMC. Without auto assignment a user will thus see different behavior when reading the monitoring events when the user switches to a kernel with assignable counter support: Before assignable counter support events will have data, with assignable counter support the events will not have data.
I understood that interfaces should not behave differently when user space switches kernels and that is what the auto assignment aims to solve.
Quoted 13 lines
Quoted 13 lines
If the userspace use-case requires too many monitoring groups for the available counters, then the kernel will auto-assign counters to a random subset of groups which may or may not be the ones that userspace wanted to monitor; then userspace must manually look for the assigned counters and unassign some of them before they can be assigned where userspace actually wanted them.
This is not impossible for userspace to cope with, but it feels awkward.
Is there a way to inhibit auto-assignment?
Quoted 8 lines
Quoted 3 lines
Or could automatic assignments be considered somehow "weak", so that new explicit assignments can steal automatically assigned counters without the need to unassign them explicitly?
We had an incomplete discussion about this early on[1]. I guess I didn't revisit it because I found it was trivial to add a flag that inhibits the assignment behavior during mkdir and had moved on to bigger issues.
Could you please remind me how a user will set this flag?
Quoted 11 lines
If an agent creating directories isn't coordinated with the agent managing counters, a series of creating and destroying a group could prevent a monitor assignment from ever succeeding because it's not possible to atomically discover the name of the new directory that stole the previously-available counter and reassign it.
However, if the counter-manager can get all the counters assigned once and only move them with atomic reassignments, it will become impossible to snatch them with a mkdir.
You have many points that makes auto-assignment not be ideal but I remain concerned that not doing something like this will break existing users who are not as familiar with resctrl internals.
Reinette
Re: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Reinette,
Quoted 55 lines · Reinette Chatre
Hi Dave and Peter,
Quoted 22 lines · Peter Newman
Hi Dave,
Quoted 19 lines · Dave Martin
Hi,
Quoted 9 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
If we are doing this, should turning
mbm_cntr_assignmode on also trigger auto-assingment for all extant monitoring groups?Either way though, this auto-assignment feels like a potential nuisance for userspace.
hmmm ... this auto-assignment was created with the goal to help userspace. In
mbm_cntr_assignmode the user will only see data when a counter is assigned to an event.mbm_cntr_assignmode is selected as default on a system that supports ABMC. Without auto assignment a user will thus see different behavior when reading the monitoring events when the user switches to a kernel with assignable counter support: Before assignable counter support events will have data, with assignable counter support the events will not have data.I understood that interfaces should not behave differently when user space switches kernels and that is what the auto assignment aims to solve.
Quoted 17 lines
Quoted 16 lines
If the userspace use-case requires too many monitoring groups for the available counters, then the kernel will auto-assign counters to a random subset of groups which may or may not be the ones that userspace wanted to monitor; then userspace must manually look for the assigned counters and unassign some of them before they can be assigned where userspace actually wanted them.
This is not impossible for userspace to cope with, but it feels awkward.
Is there a way to inhibit auto-assignment?
Or could automatic assignments be considered somehow "weak", so that new explicit assignments can steal automatically assigned counters without the need to unassign them explicitly?
Quoted 6 lines
Quoted 4 lines
We had an incomplete discussion about this early on[1]. I guess I didn't revisit it because I found it was trivial to add a flag that inhibits the assignment behavior during mkdir and had moved on to bigger issues.
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with kstrtobool()), defaulting to true?"
After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
Quoted 8 lines
Quoted 8 lines
If an agent creating directories isn't coordinated with the agent managing counters, a series of creating and destroying a group could prevent a monitor assignment from ever succeeding because it's not possible to atomically discover the name of the new directory that stole the previously-available counter and reassign it.
Quoted 8 lines
Quoted 4 lines
However, if the counter-manager can get all the counters assigned once and only move them with atomic reassignments, it will become impossible to snatch them with a mkdir.
You have many points that makes auto-assignment not be ideal but I remain concerned that not doing something like this will break existing users who are not as familiar with resctrl internals.
I agree auto-assignment should be the default. I just want an official way to turn it off.
Thanks!
-Peter
[1] https://lore.kernel.org/lkml/CALPaoCiJ9ELXkij-zsAhxC1hx8UUR+KMPJH6i8c8AT6_mtXs+Q@mail.gmail.com/
Dave Martin
reviewerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Quoted 97 lines · Peter Newman
Hi Reinette,
Quoted 55 lines · Reinette Chatre
Hi Dave and Peter,
Quoted 22 lines · Peter Newman
Hi Dave,
Quoted 19 lines · Dave Martin
Hi,
Quoted 9 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
If we are doing this, should turning
mbm_cntr_assignmode on also trigger auto-assingment for all extant monitoring groups?Either way though, this auto-assignment feels like a potential nuisance for userspace.
hmmm ... this auto-assignment was created with the goal to help userspace. In
mbm_cntr_assignmode the user will only see data when a counter is assigned to an event.mbm_cntr_assignmode is selected as default on a system that supports ABMC. Without auto assignment a user will thus see different behavior when reading the monitoring events when the user switches to a kernel with assignable counter support: Before assignable counter support events will have data, with assignable counter support the events will not have data.I understood that interfaces should not behave differently when user space switches kernels and that is what the auto assignment aims to solve.
Quoted 17 lines
Quoted 16 lines
If the userspace use-case requires too many monitoring groups for the available counters, then the kernel will auto-assign counters to a random subset of groups which may or may not be the ones that userspace wanted to monitor; then userspace must manually look for the assigned counters and unassign some of them before they can be assigned where userspace actually wanted them.
This is not impossible for userspace to cope with, but it feels awkward.
Is there a way to inhibit auto-assignment?
Or could automatic assignments be considered somehow "weak", so that new explicit assignments can steal automatically assigned counters without the need to unassign them explicitly?
Quoted 6 lines
Quoted 4 lines
We had an incomplete discussion about this early on[1]. I guess I didn't revisit it because I found it was trivial to add a flag that inhibits the assignment behavior during mkdir and had moved on to bigger issues.
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
Quoted 8 lines
Quoted 8 lines
If an agent creating directories isn't coordinated with the agent managing counters, a series of creating and destroying a group could prevent a monitor assignment from ever succeeding because it's not possible to atomically discover the name of the new directory that stole the previously-available counter and reassign it.
Quoted 8 lines
Quoted 4 lines
However, if the counter-manager can get all the counters assigned once and only move them with atomic reassignments, it will become impossible to snatch them with a mkdir.
You have many points that makes auto-assignment not be ideal but I remain concerned that not doing something like this will break existing users who are not as familiar with resctrl internals.
Quoted 8 lines
I agree auto-assignment should be the default. I just want an official way to turn it off.
Thanks!
-Peter[1] https://lore.kernel.org/lkml/CALPaoCiJ9ELXkij-zsAhxC1hx8UUR+KMPJH6i8c8AT6_mtXs+Q@mail.gmail.com/
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
What about the question re whether turning mbm_cntr_assign mode on should trigger auto-assignment?
Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Cheers
---Dave
Reinette Chatre
maintainerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Dave,
Quoted 119 lines · Dave Martin
Quoted 97 lines · Peter Newman
Hi Reinette,
Quoted 55 lines · Reinette Chatre
Hi Dave and Peter,
Quoted 22 lines · Peter Newman
Hi Dave,
Quoted 19 lines · Dave Martin
Hi,
Quoted 9 lines · Babu Moger
Assign/unassign counters on resctrl group creation/deletion. Two counters are required per group, one for MBM total event and one for MBM local event.
There are a limited number of counters available for assignment. If these counters are exhausted, the kernel will display the error message: "Out of MBM assignable counters". However, it is not necessary to fail the creation of a group due to assignment failures. Users have the flexibility to modify the assignments at a later time.
If we are doing this, should turning
mbm_cntr_assignmode on also trigger auto-assingment for all extant monitoring groups?Either way though, this auto-assignment feels like a potential nuisance for userspace.
hmmm ... this auto-assignment was created with the goal to help userspace. In
mbm_cntr_assignmode the user will only see data when a counter is assigned to an event.mbm_cntr_assignmode is selected as default on a system that supports ABMC. Without auto assignment a user will thus see different behavior when reading the monitoring events when the user switches to a kernel with assignable counter support: Before assignable counter support events will have data, with assignable counter support the events will not have data.I understood that interfaces should not behave differently when user space switches kernels and that is what the auto assignment aims to solve.
Quoted 17 lines
Quoted 16 lines
If the userspace use-case requires too many monitoring groups for the available counters, then the kernel will auto-assign counters to a random subset of groups which may or may not be the ones that userspace wanted to monitor; then userspace must manually look for the assigned counters and unassign some of them before they can be assigned where userspace actually wanted them.
This is not impossible for userspace to cope with, but it feels awkward.
Is there a way to inhibit auto-assignment?
Or could automatic assignments be considered somehow "weak", so that new explicit assignments can steal automatically assigned counters without the need to unassign them explicitly?
Quoted 6 lines
Quoted 4 lines
We had an incomplete discussion about this early on[1]. I guess I didn't revisit it because I found it was trivial to add a flag that inhibits the assignment behavior during mkdir and had moved on to bigger issues.
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
Quoted 8 lines
Quoted 8 lines
If an agent creating directories isn't coordinated with the agent managing counters, a series of creating and destroying a group could prevent a monitor assignment from ever succeeding because it's not possible to atomically discover the name of the new directory that stole the previously-available counter and reassign it.
Quoted 8 lines
Quoted 4 lines
However, if the counter-manager can get all the counters assigned once and only move them with atomic reassignments, it will become impossible to snatch them with a mkdir.
You have many points that makes auto-assignment not be ideal but I remain concerned that not doing something like this will break existing users who are not as familiar with resctrl internals.
Quoted 8 lines
I agree auto-assignment should be the default. I just want an official way to turn it off.
Thanks!
-Peter[1] https://lore.kernel.org/lkml/CALPaoCiJ9ELXkij-zsAhxC1hx8UUR+KMPJH6i8c8AT6_mtXs+Q@mail.gmail.com/
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
Quoted 6 lines
What about the question re whether turning
mbm_cntr_assignmode on should trigger auto-assignment?Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Connecting to what you start off by saying I also see auto-assignment as the way to provide a smooth transition for "non-ABMC-aware" users.
To me a user that turns this mode off and then on again can be considered as a user that is "ABMC-aware" and turning it "off and then on again" seems like an intuitive way to get to a "clean slate" wrt counter assignments. This may also be a convenient way for an "ABMC-aware" user space to unassign all counters and thus also helpful if resctrl supports the flag that Peter proposed. The flag seems to already keep something like this in its context with a name of "mbm_assign_on_mkdir" that could be interpreted as "only auto assign on mkdir"?
I am not taking a stand for one or the other approach but instead trying to be more specific about pros/cons. Could you please provide more insight in the use case you have in mind so that we can see how resctrl could behave with few surprises?
Reinette
Dave Martin
reviewerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi,
Quoted 8 lines · Reinette Chatre
Hi Dave,
Quoted 5 lines · Dave Martin
Quoted 4 lines · Peter Newman
Hi Reinette,
On Wed, Feb 19, 2025 at 6:55 PM Reinette Chatre
<[email protected]> wrote:
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
[...]
Quoted 15 lines
Quoted 15 lines
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
What about the question re whether turning
mbm_cntr_assignmode on should trigger auto-assignment?
Quoted 6 lines
Quoted 3 lines
Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Connecting to what you start off by saying I also see auto-assignment as the way to provide a smooth transition for "non-ABMC-aware" users.
I agree, and having this on by default also helps non-ABMC-aware users.
Quoted 9 lines
To me a user that turns this mode off and then on again can be considered as a user that is "ABMC-aware" and turning it "off and then on again" seems like an intuitive way to get to a "clean slate" wrt counter assignments. This may also be a convenient way for an "ABMC-aware" user space to unassign all counters and thus also helpful if resctrl supports the flag that Peter proposed. The flag seems to already keep something like this in its context with a name of "
mbm_assign_on_mkdir" that could be interpreted as "only auto assign on mkdir"?
Yes, that's reasonable. It could be a good idea to document this behaviour of switching the mbm_cntr_assign mode, if we think it is useful and people are likely to rely on it.
Since mkdir is an implementation detail of the resctrl interface, I'd be tempted to go for a more generic name, say, "mbm_assign_new_mon_groups". But that's just bikeshedding. The proposed behaviour seems fine.
Either way, if this is not included in this series, it could be added later without breaking anything.
Quoted 6 lines
I am not taking a stand for one or the other approach but instead trying to be more specific about pros/cons. Could you please provide more insight in the use case you have in mind so that we can see how resctrl could behave with few surprises?
Reinette
I don't have a strong view either.
I don't have a concrete use case here -- I was just trying to imagine the experience of an ABMC-aware user who wants full control over what counters get assigned.
I agree that the convenience of the non-ABMC-aware user should probably take priority over that of the ABMC-aware user, at least in situations where the expected behaviour is achievable (i.e., where we didn't run out of counters to auto-assign.)
Cheers
---Dave
Re: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi All,
Quoted 70 lines · Dave Martin
Hi,
Quoted 8 lines · Reinette Chatre
Hi Dave,
Quoted 5 lines · Dave Martin
Quoted 4 lines · Peter Newman
Hi Reinette,
On Wed, Feb 19, 2025 at 6:55 PM Reinette Chatre
<[email protected]> wrote:[...]
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
[...]
Quoted 15 lines
Quoted 15 lines
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
What about the question re whether turning
mbm_cntr_assignmode on should trigger auto-assignment?Quoted 6 lines
Quoted 3 lines
Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Connecting to what you start off by saying I also see auto-assignment as the way to provide a smooth transition for "non-ABMC-aware" users.
I agree, and having this on by default also helps non-ABMC-aware users.
Quoted 9 lines
To me a user that turns this mode off and then on again can be considered as a user that is "ABMC-aware" and turning it "off and then on again" seems like an intuitive way to get to a "clean slate" wrt counter assignments. This may also be a convenient way for an "ABMC-aware" user space to unassign all counters and thus also helpful if resctrl supports the flag that Peter proposed. The flag seems to already keep something like this in its context with a name of "
mbm_assign_on_mkdir" that could be interpreted as "only auto assign on mkdir"?Yes, that's reasonable. It could be a good idea to document this behaviour of switching the
mbm_cntr_assignmode, if we think it is useful and people are likely to rely on it.
Quoted 7 lines
Since mkdir is an implementation detail of the resctrl interface, I'd be tempted to go for a more generic name, say, "
mbm_assign_new_mon_groups". But that's just bikeshedding. The proposed behaviour seems fine.Either way, if this is not included in this series, it could be added later without breaking anything.
How about more generic "mbm_cntr_assign_auto" ?
We can add it as part of "struct resctrl_mon" and set it "on" when ABMC is detected. It will be part of check in rdtgroup_assign_cntrs() which is called when new groups are created. Also, provide user interface to disable it. Seems simple to me.
Thanks
Babu
Quoted 23 lines
Quoted 8 lines
I am not taking a stand for one or the other approach but instead trying to be more specific about pros/cons. Could you please provide more insight in the use case you have in mind so that we can see how resctrl could behave with few surprises?
Reinette
I don't have a strong view either.
I don't have a concrete use case here -- I was just trying to imagine the experience of an ABMC-aware user who wants full control over what counters get assigned.
I agree that the convenience of the non-ABMC-aware user should probably take priority over that of the ABMC-aware user, at least in situations where the expected behaviour is achievable (i.e., where we didn't run out of counters to auto-assign.)
Cheers
---Dave
Reinette Chatre
maintainerRe: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Babu,
Quoted 78 lines · Babu
Hi All,
Quoted 75 lines · Dave Martin
Hi,
Quoted 8 lines · Reinette Chatre
Hi Dave,
Quoted 5 lines · Dave Martin
Quoted 4 lines · Peter Newman
Hi Reinette,
On Wed, Feb 19, 2025 at 6:55 PM Reinette Chatre
<[email protected]> wrote:[...]
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
[...]
Quoted 15 lines
Quoted 15 lines
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
What about the question re whether turning
mbm_cntr_assignmode on should trigger auto-assignment?Quoted 6 lines
Quoted 3 lines
Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Connecting to what you start off by saying I also see auto-assignment as the way to provide a smooth transition for "non-ABMC-aware" users.
I agree, and having this on by default also helps non-ABMC-aware users.
Quoted 9 lines
To me a user that turns this mode off and then on again can be considered as a user that is "ABMC-aware" and turning it "off and then on again" seems like an intuitive way to get to a "clean slate" wrt counter assignments. This may also be a convenient way for an "ABMC-aware" user space to unassign all counters and thus also helpful if resctrl supports the flag that Peter proposed. The flag seems to already keep something like this in its context with a name of "
mbm_assign_on_mkdir" that could be interpreted as "only auto assign on mkdir"?Yes, that's reasonable. It could be a good idea to document this behaviour of switching the
mbm_cntr_assignmode, if we think it is useful and people are likely to rely on it.Since mkdir is an implementation detail of the resctrl interface, I'd be tempted to go for a more generic name, say, "mbm_assign_new_mon_groups". But that's just bikeshedding. The proposed behaviour seems fine.
Quoted 4 lines
Quoted 2 lines
Either way, if this is not included in this series, it could be added later without breaking anything.
How about more generic "
mbm_cntr_assign_auto" ?
I would like to be careful to not make it _too_ generic. Dave already pointed out that users may be surprised that counters are not auto-assigned when switching between the different modes so using the the name to help highlight when this auto-assignment can be expected to happen seems very useful.
Reinette
Re: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Reinette,
Quoted 84 lines · Reinette Chatre
Hi Babu,
Quoted 81 lines · Babu
Hi All,
Quoted 77 lines · Dave Martin
Hi,
Quoted 8 lines · Reinette Chatre
Hi Dave,
Quoted 5 lines · Dave Martin
Quoted 4 lines · Peter Newman
Hi Reinette,
On Wed, Feb 19, 2025 at 6:55 PM Reinette Chatre
<[email protected]> wrote:[...]
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
[...]
Quoted 15 lines
Quoted 15 lines
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
What about the question re whether turning
mbm_cntr_assignmode on should trigger auto-assignment?Quoted 6 lines
Quoted 3 lines
Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Connecting to what you start off by saying I also see auto-assignment as the way to provide a smooth transition for "non-ABMC-aware" users.
I agree, and having this on by default also helps non-ABMC-aware users.
Quoted 9 lines
To me a user that turns this mode off and then on again can be considered as a user that is "ABMC-aware" and turning it "off and then on again" seems like an intuitive way to get to a "clean slate" wrt counter assignments. This may also be a convenient way for an "ABMC-aware" user space to unassign all counters and thus also helpful if resctrl supports the flag that Peter proposed. The flag seems to already keep something like this in its context with a name of "
mbm_assign_on_mkdir" that could be interpreted as "only auto assign on mkdir"?Yes, that's reasonable. It could be a good idea to document this behaviour of switching the
mbm_cntr_assignmode, if we think it is useful and people are likely to rely on it.Since mkdir is an implementation detail of the resctrl interface, I'd be tempted to go for a more generic name, say, "mbm_assign_new_mon_groups". But that's just bikeshedding. The proposed behaviour seems fine.
Either way, if this is not included in this series, it could be added later without breaking anything.
Quoted 6 lines
Quoted 1 line
How about more generic "
mbm_cntr_assign_auto" ?I would like to be careful to not make it _too_ generic. Dave already pointed out that users may be surprised that counters are not auto-assigned when switching between the different modes so using the the name to help highlight when this auto-assignment can be expected to happen seems very useful.
In that case "mbm_assign_on_mkdir" seems on point and precise. Thanks
Babu
Re: [PATCH v11 17/23] x86/resctrl: Auto assign/unassign counters when mbm_cntr_assign is enabled
Hi Babu,
Quoted 90 lines · Babu
Hi Reinette,
Quoted 86 lines · Reinette Chatre
Hi Babu,
Quoted 82 lines · Babu
Hi All,
Quoted 70 lines · Dave Martin
Hi,
Quoted 8 lines · Reinette Chatre
Hi Dave,
Quoted 5 lines · Dave Martin
Quoted 4 lines · Peter Newman
Hi Reinette,
On Wed, Feb 19, 2025 at 6:55 PM Reinette Chatre
<[email protected]> wrote:[...]
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Could you please remind me how a user will set this flag?
Quoting my original suggestion[1]:
"info/L3_MON/mbm_assign_on_mkdir?
boolean (parsed with
kstrtobool()), defaulting to true?"After mount, any groups that got counters on creation would have to be cleaned up, but at least that can be done with forward progress once the flag is cleared.
I was able to live with that as long as there aren't users polling for resctrl to be mounted and immediately creating groups. For us, a single container manager service manages resctrl.
[...]
Quoted 15 lines
Quoted 15 lines
+1
That's basically my position -- the auto-assignment feels like a _potential_ nuisance for ABMC-aware users, but it depends on what they are trying to do. Migration of non-ABMC-aware users will be easier for basic use cases if auto-assignment occurs by default (as in this series).
Having an explicit way to turn this off seems perfectly reasonable (and could be added later on, if not provided in this series).
What about the question re whether turning
mbm_cntr_assignmode on should trigger auto-assignment?Quoted 6 lines
Quoted 3 lines
Currently turning this mode off and then on again has the effect of removing all automatic assignments for extant groups. This feels surprising and/or unintentional (?)
Connecting to what you start off by saying I also see auto-assignment as the way to provide a smooth transition for "non-ABMC-aware" users.
I agree, and having this on by default also helps non-ABMC-aware users.
Quoted 9 lines
To me a user that turns this mode off and then on again can be considered as a user that is "ABMC-aware" and turning it "off and then on again" seems like an intuitive way to get to a "clean slate" wrt counter assignments. This may also be a convenient way for an "ABMC-aware" user space to unassign all counters and thus also helpful if resctrl supports the flag that Peter proposed. The flag seems to already keep something like this in its context with a name of "
mbm_assign_on_mkdir" that could be interpreted as "only auto assign on mkdir"?Yes, that's reasonable. It could be a good idea to document this behaviour of switching the
mbm_cntr_assignmode, if we think it is useful and people are likely to rely on it.Quoted 7 lines
Since mkdir is an implementation detail of the resctrl interface, I'd be tempted to go for a more generic name, say, "
mbm_assign_new_mon_groups". But that's just bikeshedding. The proposed behaviour seems fine.Either way, if this is not included in this series, it could be added later without breaking anything.
How about more generic "
mbm_cntr_assign_auto" ?
Quoted 7 lines
Quoted 4 lines
I would like to be careful to not make it _too_ generic. Dave already pointed out that users may be surprised that counters are not auto-assigned when switching between the different modes so using the the name to help highlight when this auto-assignment can be expected to happen seems very useful.
In that case "
mbm_assign_on_mkdir" seems on point and precise. Thanks
It also looks like counters are not assigned when a domain is hotplugged, so explicitly stating that it's on mkdir gets us off the hook for that.
-Peter
Babu Moger
reviewerPATCH v11 18/23 x86/resctrl: Report "Unassigned" for MBM events in mbm_cntr_assign mode
In reply to Babu MogerIn mbm_cntr_assign mode, the hardware counter should be assigned to read the MBM events.
Report 'Unassigned' in case the user attempts to read the events without assigning the counter.
---
v11: Domain can be NULL with SNC support so moved the unassign check in
rdtgroup_mondata_show().
v10: Moved the code to check the assign state inside mon_event_read().
Fixed few text comments.
v9: Used is_mbm_event() to check the event type.
Minor user documentation update.
v8: Used MBM_EVENT_ARRAY_INDEX to get the index for the MBM event.
Documentation update to make the text generic.
v7: Moved the documentation under "mon_data".
Updated the text little bit.
v6: Added more explaination in the resctrl.rst
Added checks to detect "Unassigned" before reading RMID.
v5: New patch.
--- Documentation/arch/x86/resctrl.rst | 10 ++++++++++ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 13 +++++++++++++ arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- 4 files changed, 27 insertions(+), 2 deletions(-)
Documentation/arch/x86/resctrl.rst +10 -0
@@ -431,6 +431,16 @@ 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 supported the mbm_cntr_assign mode allows users to assign a + counter to mon_hw_id, event pair enabling bandwidth monitoring for + as long as the counter remains assigned. The hardware will continue + tracking the assigned mon_hw_id until the user manually unassigns + it, ensuring that counters are not reset during this period. With + a limited number of counters, the system may run out of assignable + counters. In that case, MBM event counters will return 'Unassigned' + when the event is read. Users must manually assign a counter to read + the events. + "mon_hw_id": Available only with debug option. The identifier used by hardware for the monitor group. On x86 this is the RMID.
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +13 -0
@@ -679,6 +679,17 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } d = container_of(hdr, struct rdt_mon_domain, hdr); + +/* +* Report 'Unassigned' if the mbm_cntr_assign mode is enabled and +* counter is unassigned +*/ +if (resctrl_arch_mbm_cntr_assign_enabled (r) &&is_mbm_event (evtid) && + (mbm_cntr_get (r, d, rdtgrp, evtid) == -ENOENT )) { + rr.err = -ENOENT ; + goto checkresult; + } +mon_event_read (&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); }
@@ -688,6 +699,8 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)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);
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -732,4 +732,6 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d,int resctrl_unassign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid);void mbm_cntr_reset (struct rdt_resource *r); +int mbm_cntr_get (struct rdt_resource *r,struct rdt_mon_domain *d, +struct rdtgroup *rdtgrp,enum resctrl_event_id evtid);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -1436,8 +1436,8 @@ static int resctrl_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,return ret; } -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;
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 18/23] x86/resctrl: Report "Unassigned" for MBM events in mbm_cntr_assign mode
Hi Babu,
Quoted 14 lines · Babu Moger
In
mbm_cntr_assignmode, the hardware counter should be assigned to read the MBM events.Report 'Unassigned' in case the user attempts to read the events without assigning the counter.
Signed-off-by Babu Moger <[email protected]>---
Documentation/arch/x86/resctrl.rst +0
-0
Documentation/arch/x86/resctrl.rst When monitoring is enabled all MON groups will also contain: · line 434
Quoted 4 lines
Documentation/arch/x86/resctrl.rst +1
-0@@ -431,6 +431,16 @@ 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 supported the mbm_cntr_assign mode allows users to assign a
Same comment as previous version.
Documentation/arch/x86/resctrl.rst When monitoring is enabled all MON groups will also contain: · line 446
Quoted 12 lines
Documentation/arch/x86/resctrl.rst +9
-0+ counter to mon_hw_id, event pair enabling bandwidth monitoring for + as long as the counter remains assigned. The hardware will continue + tracking the assigned mon_hw_id until the user manually unassigns + it, ensuring that counters are not reset during this period. With + a limited number of counters, the system may run out of assignable + counters. In that case, MBM event counters will return 'Unassigned' + when the event is read. Users must manually assign a counter to read + the events. + "mon_hw_id": Available only with debug option. The identifier used by hardware for the monitor group. On x86 this is the RMID.
Reinette
Moger, Babu
reviewerRe: [PATCH v11 18/23] x86/resctrl: Report "Unassigned" for MBM events in mbm_cntr_assign mode
Hi Reinette,
Quoted 20 lines · Reinette Chatre
Hi Babu,
Quoted 17 lines · Babu Moger
In
mbm_cntr_assignmode, the hardware counter should be assigned to read the MBM events.Report 'Unassigned' in case the user attempts to read the events without assigning the counter.
Signed-off-by Babu Moger <[email protected]>---
Documentation/arch/x86/resctrl.rst +0
-0@@ -431,6 +431,16 @@ 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.
Quoted 3 lines
Documentation/arch/x86/resctrl.rst When monitoring is enabled all MON groups will also contain: · line 434
Quoted 1 line
Documentation/arch/x86/resctrl.rst +1
-0+ When supported the mbm_cntr_assign mode allows users to assign aSame comment as previous version.
Sorry about that.
"mbm_cntr_assign mode allows users to assign a"
Quoted 16 lines
Documentation/arch/x86/resctrl.rst When monitoring is enabled all MON groups will also contain: · line 446
Quoted 13 lines
Documentation/arch/x86/resctrl.rst +9
-0+ counter to mon_hw_id, event pair enabling bandwidth monitoring for + as long as the counter remains assigned. The hardware will continue + tracking the assigned mon_hw_id until the user manually unassigns + it, ensuring that counters are not reset during this period. With + a limited number of counters, the system may run out of assignable + counters. In that case, MBM event counters will return 'Unassigned' + when the event is read. Users must manually assign a counter to read + the events. + "mon_hw_id": Available only with debug option. The identifier used by hardware for the monitor group. On x86 this is the RMID.Reinette
Signature · 2 lines
Thanks Babu Moger
Babu Moger
reviewerPATCH v11 19/23 x86/resctrl: Introduce the interface to switch between monitor modes
In reply to Babu MogerResctrl subsystem can support two monitoring modes, 'mbm_cntr_assign' or 'default'. In mbm_cntr_assign, 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 interface to switch between mbm_cntr_assign and default modes.
$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] default
To enable the "mbm_cntr_assign" mode:
$ echo "mbm_cntr_assign" > /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.
---
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/arch/x86/resctrl.rst | 25 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 50 +++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-)
Documentation/arch/x86/resctrl.rst +24 -1
@@ -259,7 +259,10 @@ with the following files: "mbm_assign_mode": Reports the list of monitoring modes supported. The enclosed brackets - indicate which mode is enabled. + indicate which mode is enabled. The MBM events (mbm_total_bytes and/or + mbm_local_bytes) associated with counters may reset when "mbm_assign_mode" + is changed. + :: # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
@@ -275,6 +278,16 @@ with the following files: available is described in the "num_mbm_cntrs" file. Changing the mode may cause all counters on a resource to reset. + Moving to mbm_cntr_assign mode require 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
@@ -283,6 +296,16 @@ with the following files: "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event. + * To enable "mbm_cntr_assign" mode: + :: + + # echo "mbm_cntr_assign" > /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 number of monitoring counters available for assignment when the system supports mbm_cntr_assign mode.
arch/x86/kernel/cpu/resctrl/rdtgroup.c +49 -1
64 lines not on this page · raw message
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 19/23] x86/resctrl: Introduce the interface to switch between monitor modes
Hi Babu,
Quoted 48 lines · Babu Moger
Resctrl subsystem can support two monitoring modes, '
mbm_cntr_assign' or 'default'. Inmbm_cntr_assign, 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 everyCTRL_MONand MON group.Introduce interface to switch between
mbm_cntr_assignand default modes.$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] defaultTo enable the "
mbm_cntr_assign" mode:$ echo "mbm_cntr_assign" > /sys/fs/resctrl/info/L3_MON/mbm_assign_modeTo enable the default monitoring mode:
$ echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_modeMBM 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.
Signed-off-by Babu Moger <[email protected]>---
--- Documentation/arch/x86/resctrl.rst | 25 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 50 +++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-)Documentation/arch/x86/resctrl.rst +4
-1@@ -259,7 +259,10 @@ with the following files: "mbm_assign_mode": Reports the list of monitoring modes supported. The enclosed brackets - indicate which mode is enabled. + indicate which mode is enabled. The MBM events (mbm_total_bytes and/or + mbm_local_bytes) associated with counters may reset when "mbm_assign_mode" + is changed. + :: # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode
Documentation/arch/x86/resctrl.rst with the following files: · line 283
Quoted 6 lines
Documentation/arch/x86/resctrl.rst +3
-0@@ -275,6 +278,16 @@ with the following files: available is described in the "num_mbm_cntrs" file. Changing the mode may cause all counters on a resource to reset. + Moving to mbm_cntr_assign mode require users to assign the counters to + the events. Otherwise, the MBM event counters will return "Unassigned" + when read.
Again ... please be consistent in using single or double quotes for information returned from file.
Quoted 14 lines
Documentation/arch/x86/resctrl.rst +7
-0+ + 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@@ -283,6 +296,16 @@ with the following files: "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event.
Documentation/arch/x86/resctrl.rst with the following files: · line 308
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +10
-0+ * To enable "mbm_cntr_assign" mode: + :: + + # echo "mbm_cntr_assign" > /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 +
Please be consistent in the documentation.
To enable "mbm_cntr_assign" mode:
To enable "default" mode:
or
To enable "mbm_cntr_assign" monitoring mode:
To enable "default" monitoring mode:
or
...?
Quoted 39 lines
Documentation/arch/x86/resctrl.rst +0
-0"num_mbm_cntrs": The number of monitoring counters available for assignment when the system supports mbm_cntr_assign mode.arch/x86/kernel/cpu/resctrl/rdtgroup.c +28
-0@@ -928,6 +928,53 @@ static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of,return ret; } +static ssize_t resctrl_mbm_assign_mode_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdt_resource *r = of->kn->parent->priv; +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_cntr_assign" )) { +if (r->mon.mbm_cntr_assignable) { + enable =1 ; + }else { + ret = -EINVAL ; +rdt_last_cmd_puts ("mbm_cntr_assign mode is not supported\n" ); + goto write_exit; + }
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, · line 968
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ }else { + ret = -EINVAL ; +rdt_last_cmd_puts ("Unsupported assign mode\n" ); + goto write_exit; + } + +if (enable !=resctrl_arch_mbm_cntr_assign_enabled (r)) { + ret =resctrl_arch_mbm_cntr_assign_set (r, enable); +if (!ret) +mbm_cntr_reset (r);
The following APIs interact with the MBM assignable counters:
mbm_cntr_alloc()mbm_cntr_get()mbm_cntr_free()
mbm_cntr_reset() appears to be related but does significantly more than interact with the MBM assignable counters and that creates a confusing API.
How about introducing mbm_cntr_free_all() that _only_ releases all MBM assignable counters and match with mbm_cntr_free() that releases a single MBM assignable counter? mbm_cntr_free_all() lives with the other functions operating on MBM assignable counters, thus not hiding its functionality in other parts of resctrl.
This series open codes reset of non-architectural state in two places, within mbm_cntr_reset() and within mbm_config_write_domain(). That can be turned into a new helper that only resets architectural state, for example resctrl_reset_rmid_all() to match existing resctrl_arch_reset_rmid_all().
resctrl_arch_mbm_cntr_assign_set() can also reset any architectural state leaving mbm_cntr_free_all() and resctrl_reset_rmid_all() to be called here and from within mbm_config_write_domain().
What do you think?
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9
-0+ } + +write_exit: +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); + +return ret ?: nbytes; +} +#ifdef CONFIG_PROC_CPU_RESCTRL /* @@ -1945,9 +1992,10 @@ static struct rftype res_common_files[] = { },
arch/x86/kernel/cpu/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 2001
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-1{ .name = "mbm_assign_mode", - .mode = 0444, + .mode = 0644, .kf_ops = &rdtgroup_kf_single_ops, .seq_show = resctrl_mbm_assign_mode_show, + .write = resctrl_mbm_assign_mode_write, .fflags = RFTYPE_MON_INFO, }, {
Reinette
Moger, Babu
reviewerRe: [PATCH v11 19/23] x86/resctrl: Introduce the interface to switch between monitor modes
Hi Reinette,
Quoted 54 lines · Reinette Chatre
Hi Babu,
Quoted 51 lines · Babu Moger
Resctrl subsystem can support two monitoring modes, '
mbm_cntr_assign' or 'default'. Inmbm_cntr_assign, 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 everyCTRL_MONand MON group.Introduce interface to switch between
mbm_cntr_assignand default modes.$ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] defaultTo enable the "
mbm_cntr_assign" mode:$ echo "mbm_cntr_assign" > /sys/fs/resctrl/info/L3_MON/mbm_assign_modeTo enable the default monitoring mode:
$ echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_modeMBM 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.
Signed-off-by Babu Moger <[email protected]>---
--- Documentation/arch/x86/resctrl.rst | 25 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 50 +++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-)Documentation/arch/x86/resctrl.rst +4
-1@@ -259,7 +259,10 @@ with the following files: "mbm_assign_mode": Reports the list of monitoring modes supported. The enclosed brackets - indicate which mode is enabled. + indicate which mode is enabled. The MBM events (mbm_total_bytes and/or + mbm_local_bytes) associated with counters may reset when "mbm_assign_mode" + is changed. + :: # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode@@ -275,6 +278,16 @@ with the following files: available is described in the "num_mbm_cntrs" file. Changing the mode may cause all counters on a resource to reset.
Quoted 6 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 283
Quoted 3 lines
Documentation/arch/x86/resctrl.rst +3
-0+ Moving to mbm_cntr_assign mode require users to assign the counters to + the events. Otherwise, the MBM event counters will return "Unassigned" + when read.Again ... please be consistent in using single or double quotes for information returned from file.
ok. Will change it to 'Unassigned'.
Quoted 28 lines
Quoted 15 lines
Documentation/arch/x86/resctrl.rst +7
-0+ + 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@@ -283,6 +296,16 @@ with the following files: "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event.Documentation/arch/x86/resctrl.rst with the following files: · line 308
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +10
-0+ * To enable "mbm_cntr_assign" mode: + :: + + # echo "mbm_cntr_assign" > /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 +Please be consistent in the documentation.
Quoted 5 lines
To enable "
mbm_cntr_assign" mode:
To enable "default" mode:
or
To enable "mbm_cntr_assign" monitoring mode:
To enable "default" monitoring mode:
This sounds (monitoring mode) better.
Quoted 77 lines
or
...?Quoted 39 lines
Documentation/arch/x86/resctrl.rst +0
-0"num_mbm_cntrs": The number of monitoring counters available for assignment when the system supports mbm_cntr_assign mode.arch/x86/kernel/cpu/resctrl/rdtgroup.c +28
-0@@ -928,6 +928,53 @@ static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of,return ret; } +static ssize_t resctrl_mbm_assign_mode_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdt_resource *r = of->kn->parent->priv; +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_cntr_assign" )) { +if (r->mon.mbm_cntr_assignable) { + enable =1 ; + }else { + ret = -EINVAL ; +rdt_last_cmd_puts ("mbm_cntr_assign mode is not supported\n" ); + goto write_exit; + }arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, · line 968
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ }else { + ret = -EINVAL ; +rdt_last_cmd_puts ("Unsupported assign mode\n" ); + goto write_exit; + } + +if (enable !=resctrl_arch_mbm_cntr_assign_enabled (r)) { + ret =resctrl_arch_mbm_cntr_assign_set (r, enable); +if (!ret) +mbm_cntr_reset (r);The following APIs interact with the MBM assignable counters:
mbm_cntr_alloc()mbm_cntr_get()mbm_cntr_free()
mbm_cntr_reset()appears to be related but does significantly more than interact with the MBM assignable counters and that creates a confusing API.How about introducing
mbm_cntr_free_all()that _only_ releases all MBM assignable counters and match withmbm_cntr_free()that releases a single MBM assignable counter?mbm_cntr_free_all()lives with the other functions operating on MBM assignable counters, thus not hiding its functionality in other parts of resctrl.This series open codes reset of non-architectural state in two places, within
mbm_cntr_reset()and withinmbm_config_write_domain(). That can be turned into a new helper that only resets architectural state, for exampleresctrl_reset_rmid_all()to match existingresctrl_arch_reset_rmid_all().
Quoted 5 lines
resctrl_arch_mbm_cntr_assign_set()can also reset any architectural state leavingmbm_cntr_free_all()andresctrl_reset_rmid_all()to be called here and from withinmbm_config_write_domain().What do you think?
Sounds like a good code separation. It should be fine. Will let you know if there are any issues.
Quoted 28 lines
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9
-0+ } + +write_exit: +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); + +return ret ?: nbytes; +} +#ifdef CONFIG_PROC_CPU_RESCTRL /* @@ -1945,9 +1992,10 @@ static struct rftype res_common_files[] = { },arch/x86/kernel/cpu/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 2001
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-1{ .name = "mbm_assign_mode", - .mode = 0444, + .mode = 0644, .kf_ops = &rdtgroup_kf_single_ops, .seq_show = resctrl_mbm_assign_mode_show, + .write = resctrl_mbm_assign_mode_write, .fflags = RFTYPE_MON_INFO, }, {Reinette
Signature · 2 lines
Thanks Babu Moger
Babu Moger
reviewerPATCH v11 20/23 x86/resctrl: Configure mbm_cntr_assign mode if supported
In reply to Babu MogerConfigure mbm_cntr_assign mode on AMD platforms. On AMD platforms, it is recommended to use mbm_cntr_assign mode if supported, because reading "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event.
The mbm_cntr_assign 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.
---
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/internal.h | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 8 ++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++++ 3 files changed, 13 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
@@ -734,4 +734,5 @@ int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *dvoid mbm_cntr_reset (struct rdt_resource *r);int mbm_cntr_get (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid); +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
@@ -1233,6 +1233,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;resctrl_file_fflags_init ("num_mbm_cntrs" ,RFTYPE_MON_INFO );resctrl_file_fflags_init ("available_mbm_cntrs" ,RFTYPE_MON_INFO ); }
@@ -1313,6 +1314,13 @@ static void _resctrl_abmc_enable(struct rdt_resource *r, bool enable) resctrl_abmc_set_one_amd, &enable, 1); } +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); +} +int resctrl_arch_mbm_cntr_assign_set (struct rdt_resource *r,bool enable) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -0
@@ -4302,9 +4302,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)void resctrl_online_cpu (unsigned int cpu) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r);mutex_unlock (&rdtgroup_mutex); }
Signature · 1 line
2.34.1
James Morse
reviewerRe: [PATCH v11 20/23] x86/resctrl: Configure mbm_cntr_assign mode if supported
Hi Babu,
Quoted 4 lines · Babu Moger
Configure
mbm_cntr_assignmode on AMD platforms. On AMD platforms, it is recommended to usembm_cntr_assignmode if supported, because reading "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event.
(If you agree with my comment on patch 7, it would be good to update this wording to match.)
Quoted 11 lines
The
mbm_cntr_assignmode, 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.
arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 738
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/internal.h +1
-0@@ -734,4 +734,5 @@ int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *dvoid mbm_cntr_reset (struct rdt_resource *r);int mbm_cntr_get (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid); +void resctrl_arch_mbm_cntr_assign_set_one (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */
Could this be put in include/linux/resctrl.h, its where it needs to end up eventually.
This sequence has me confused:
arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 1237
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1233,6 +1233,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;
Here the arch code sets ABMC to be enabled by default at boot.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -4302,9 +4302,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)void resctrl_online_cpu (unsigned int cpu)
arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d) · line 4313
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r);mutex_unlock (&rdtgroup_mutex); }
But here, resctrl has to call back to the arch code to make sure the hardware is in the same state as hw_res->mbm_cntr_assign_enabled.
Could this be done in resctrl_arch_online_cpu() instead? That way resctrl doesn't get CPUs in an inconsistent state that it has to fix up...
Thanks,
James
Moger, Babu
reviewerRe: [PATCH v11 20/23] x86/resctrl: Configure mbm_cntr_assign mode if supported
Hi James,
Quoted 10 lines · James Morse
Hi Babu,
Quoted 4 lines · Babu Moger
Configure
mbm_cntr_assignmode on AMD platforms. On AMD platforms, it is recommended to usembm_cntr_assignmode if supported, because reading "mbm_total_bytes" or "mbm_local_bytes" will report 'Unavailable' if there is no counter associated with that event.(If you agree with my comment on patch 7, it would be good to update this wording to match.)
Sure.
Quoted 6 lines
Quoted 6 lines
The
mbm_cntr_assignmode, referred to as ABMC (Assignable Bandwidth Monitoring Counters) on AMD, is enabled by default when supported by the system.
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/internal.h int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d · line 738
Quoted 12 lines
Update ABMC across all logical processors within the resctrl domain to ensure proper functionality.
arch/x86/kernel/cpu/resctrl/internal.h +1
-0@@ -734,4 +734,5 @@ int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *dvoid mbm_cntr_reset (struct rdt_resource *r);int mbm_cntr_get (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid); +void resctrl_arch_mbm_cntr_assign_set_one (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ Could this be put in
include/linux/resctrl.h, its where it needs to end up eventually.
As Reinette already mentioned in [1], Boris wanted this moved when arch/fs code separation integrated. Lets keep it in resctrl/internal.h for now.
[1]
https://lore.kernel.org/lkml/[email protected]/
Quoted 39 lines
This sequence has me confused:
arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 1237
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1233,6 +1233,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;Here the arch code sets ABMC to be enabled by default at boot.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -4302,9 +4302,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)void resctrl_online_cpu (unsigned int cpu)arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d) · line 4313
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r);mutex_unlock (&rdtgroup_mutex); }But here, resctrl has to call back to the arch code to make sure the hardware is in the same state as
hw_res->mbm_cntr_assign_enabled.
Quoted 3 lines
Could this be done in
resctrl_arch_online_cpu()instead? That way resctrl doesn't get CPUs in an inconsistent state that it has to fix up...
Sure. Here is the diff.
(quoted diff) +0 -0
b/arch/x86/kernel/cpu/resctrl/core.c
index 22399f19810f..f48b298413bc 100644
arch/x86/kernel/cpu/resctrl/core.c +6 -0
@@ -771,6 +771,12 @@ static int resctrl_arch_online_cpu(unsigned int cpu)domain_add_cpu (cpu, r);mutex_unlock (&domain_list_lock); + r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r); +mutex_unlock (&rdtgroup_mutex); +clear_closid_rmid (cpu);resctrl_online_cpu (cpu);
Signature · 2 lines
Thanks Babu Moger
Reinette Chatre
maintainerRe: [PATCH v11 20/23] x86/resctrl: Configure mbm_cntr_assign mode if supported
Hi James and Babu,
Quoted 43 lines · Babu
Hi James,
Quoted 40 lines · James Morse
Hi Babu,
On 22/01/2025 20:20, Babu Moger wrote:
This sequence has me confused:
arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 1237
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1233,6 +1233,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;Here the arch code sets ABMC to be enabled by default at boot.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -4302,9 +4302,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)void resctrl_online_cpu (unsigned int cpu)arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d) · line 4313
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r);mutex_unlock (&rdtgroup_mutex); }But here, resctrl has to call back to the arch code to make sure the hardware is in the same state as
hw_res->mbm_cntr_assign_enabled.
Another scenario needing to be supported by this flow is when CPUs come online later ... after resctrl is mounted and potentially after the user modified the assignable counter mode.
Quoted 3 lines
Quoted 3 lines
Could this be done in
resctrl_arch_online_cpu()instead? That way resctrl doesn't get CPUs in an inconsistent state that it has to fix up...
Could you please elaborate the inconsistent state that would need to be fixed up?
Quoted 11 lines
Quoted 1 line
Sure. Here is the diff.
arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -771,6 +771,12 @@ static int resctrl_arch_online_cpu(unsigned int cpu)domain_add_cpu (cpu, r);
arch/x86/kernel/cpu/resctrl/core.c static int resctrl_arch_online_cpu(unsigned int cpu) · line 781
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0mutex_unlock (&domain_list_lock); + r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r); +mutex_unlock (&rdtgroup_mutex); +clear_closid_rmid (cpu);resctrl_online_cpu (cpu);
This would require every architecture to duplicate the above, no?
Also, please note there is more appropriate domain_add_cpu_mon().
Reinette
Moger, Babu
reviewerRe: [PATCH v11 20/23] x86/resctrl: Configure mbm_cntr_assign mode if supported
Hi Reinette,
Quoted 47 lines · Reinette Chatre
Hi James and Babu,
Quoted 43 lines · Babu
Hi James,
Quoted 40 lines · James Morse
Hi Babu,
On 22/01/2025 20:20, Babu Moger wrote:
This sequence has me confused:
arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 1237
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1233,6 +1233,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;Here the arch code sets ABMC to be enabled by default at boot.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -4302,9 +4302,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)void resctrl_online_cpu (unsigned int cpu)arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d) · line 4313
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r);mutex_unlock (&rdtgroup_mutex); }But here, resctrl has to call back to the arch code to make sure the hardware is in the same state as
hw_res->mbm_cntr_assign_enabled.
Quoted 3 lines
Another scenario needing to be supported by this flow is when CPUs come online later ... after resctrl is mounted and potentially after the user modified the assignable counter mode.
If the user modifies the assignable counter mode. It is recorded in mbm_cntr_assign_enabled already. When the new CPU comes online, the hotplug handler(resctrl_arch_online_cpu) is will update the CPU to the new mode after checking mbm_cntr_assign_enabled.
Are you talking about different case here? Please elaborate.
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines
Could this be done in
resctrl_arch_online_cpu()instead? That way resctrl doesn't get CPUs in an inconsistent state that it has to fix up...Could you please elaborate the inconsistent state that would need to be fixed up?
Quoted 11 lines
Quoted 1 line
Sure. Here is the diff.
arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -771,6 +771,12 @@ static int resctrl_arch_online_cpu(unsigned int cpu)domain_add_cpu (cpu, r);arch/x86/kernel/cpu/resctrl/core.c static int resctrl_arch_online_cpu(unsigned int cpu) · line 781
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0mutex_unlock (&domain_list_lock); + r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r); +mutex_unlock (&rdtgroup_mutex); +clear_closid_rmid (cpu);resctrl_online_cpu (cpu);This would require every architecture to duplicate the above, no?
Quoted 1 line
Also, please note there is more appropriate
domain_add_cpu_mon().
Yes. This may be better place to add this code. Will wait once James clarifies on "inconsistent state".
Signature · 2 lines
Thanks Babu Moger
Reinette Chatre
maintainerRe: [PATCH v11 20/23] x86/resctrl: Configure mbm_cntr_assign mode if supported
Hi Babu,
Quoted 55 lines · Babu
Hi Reinette,
Quoted 47 lines · Reinette Chatre
Hi James and Babu,
Quoted 43 lines · Babu
Hi James,
Quoted 40 lines · James Morse
Hi Babu,
On 22/01/2025 20:20, Babu Moger wrote:
This sequence has me confused:
arch/x86/kernel/cpu/resctrl/monitor.c int __init rdt_get_mon_l3_config(struct rdt_resource *r) · line 1237
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-0@@ -1233,6 +1233,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;Here the arch code sets ABMC to be enabled by default at boot.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -4302,9 +4302,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)void resctrl_online_cpu (unsigned int cpu)arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d) · line 4313
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0{ +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +if (r->mon_capable && r->mon.mbm_cntr_assignable) +resctrl_arch_mbm_cntr_assign_set_one (r);mutex_unlock (&rdtgroup_mutex); }But here, resctrl has to call back to the arch code to make sure the hardware is in the same state as
hw_res->mbm_cntr_assign_enabled.Quoted 3 lines
Another scenario needing to be supported by this flow is when CPUs come online later ... after resctrl is mounted and potentially after the user modified the assignable counter mode.
Quoted 6 lines
If the user modifies the assignable counter mode. It is recorded in
mbm_cntr_assign_enabledalready. When the new CPU comes online, the hotplughandler(resctrl_arch_online_cpu)is will update the CPU to the new mode after checkingmbm_cntr_assign_enabled.Are you talking about different case here? Please elaborate.
I am talking about the same case. James started with "This sequence has me confused" with "Here the arch code sets ABMC to be enabled by default at boot." snippet not seemingly matching with later snippet where "resctrl has to call back to the arch code". My goal was to highlight why resctrl would need to call back into arch code even though arch code establishes the default.
Reinette
Babu Moger
reviewerPATCH v11 21/23 x86/resctrl: Update assignments on event configuration changes
In reply to Babu MogerWhen BMEC (Bandwidth Monitoring Event Configuration) is supported, resctrl provides option to configure events by writing to the interfaces /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config or /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config.
Update MBM event assignments for all monitor groups in the affected domains whenever the event configuration is changed.
---
v11:
Added non-arch RMID reset code in mbm_config_write_domain() which was missing. 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.
Updated the code comments with Reinette's feedback.
Updated the commit message in imperative mode.
v10: Code changed completely with domain specific counter assignment.
Rewrite the commit message.
Added few more code comments.
v9: Again patch changed completely based on the comment.
https://lore.kernel.org/lkml/[email protected]/
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.
v8: Patch changed completely.
Updated the assignment on same IPI as the event is updated. 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.
v7: New patch to update the assignments. Missed it earlier.
--- arch/x86/kernel/cpu/resctrl/internal.h | 4 +- arch/x86/kernel/cpu/resctrl/monitor.c | 58 ++++++++++++++++++++++---- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 10 ++++- 3 files changed, 61 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +3 -1
@@ -607,11 +607,13 @@ union cpuid_0x10_x_edx {/** * struct mon_config_info - Monitoring event configuratiin details +* @r: Resource for monitoring * @d: Domain for the event * @evtid: Event type * @mon_config: Event configuration value */ struct mon_config_info { +struct rdt_resource *r;struct rdt_mon_domain *d;enum resctrl_event_id evtid;u32 mon_config;
@@ -721,12 +723,12 @@ int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable);bool resctrl_arch_mbm_cntr_assign_enabled (struct rdt_resource *r);void arch_mbm_evt_config_init (struct rdt_hw_mon_domain *hw_dom);unsigned int mon_event_config_index_get (u32 evtid); -void resctrl_arch_mon_event_config_set (void *info);u32 resctrl_arch_mon_event_config_get (struct rdt_mon_domain *d,enum resctrl_event_id eventid);int 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); +void resctrl_mon_event_config_set (void *info);int resctrl_assign_cntr_event (struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,enum resctrl_event_id evtid); int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d,
arch/x86/kernel/cpu/resctrl/monitor.c +50 -8
79 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8 -2
@@ -1740,10 +1740,10 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of,return 0 ; } -static void mbm_config_write_domain (struct rdt_resource *r,struct rdt_mon_domain *d,u32 evtid,u32 val) { +u32 idx_limit =resctrl_arch_system_num_rmid_idx ();struct mon_config_info mon_info = {0 };u32 config_val;
@@ -1755,6 +1755,7 @@ static void mbm_config_write_domain(struct rdt_resource *r,if (config_val ==INVALID_CONFIG_VALUE || config_val == val)return ; + mon_info.r = r; mon_info.d = d; mon_info.evtid = evtid; mon_info.mon_config = val;
@@ -1766,7 +1767,7 @@ static void mbm_config_write_domain(struct rdt_resource *r,* on one CPU is observed by all the CPUs in the domain. */ smp_call_function_any (&d->hdr.cpu_mask, - resctrl_arch_mon_event_config_set, + resctrl_mon_event_config_set, &mon_info,1 );/*
@@ -1779,6 +1780,11 @@ static void mbm_config_write_domain(struct rdt_resource *r,* mbm_local and mbm_total counts for all the RMIDs. */ resctrl_arch_reset_rmid_all (r, d); + +if (is_mbm_total_enabled ()) +memset (d->mbm_total,0 ,sizeof (struct mbm_state ) * idx_limit); +if (is_mbm_local_enabled ()) +memset (d->mbm_local,0 ,sizeof (struct mbm_state ) * idx_limit); }static int mon_config_write (struct rdt_resource *r,char *tok,u32 evtid)
Signature · 1 line
2.34.1
Babu Moger
reviewerPATCH v11 22/23 x86/resctrl: Introduce interface to list assignment states of all the groups
In reply to Babu MogerProvide the interface to list the assignment states of all the resctrl groups in mbm_cntr_assign mode.
Example:
$ mount -t resctrl resctrl /sys/fs/resctrl/ $ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control //0=tl;1=tl
List follows the following format:
"<CTRL_MON group>/<MON group>/<domain_id>=<flags>"
Format for specific type of groups:
- Default CTRL_MON group:
"//<domain_id>=<flags>"
- Non-default CTRL_MON group:
"<CTRL_MON group>//<domain_id>=<flags>"
- Child MON group of default CTRL_MON group:
"/<MON group>/<domain_id>=<flags>"
- Child MON group of non-default CTRL_MON group:
"<CTRL_MON group>/<MON group>/<domain_id>=<flags>"
Flags can be one of the following:
t MBM total event is assigned
l MBM local event is assigned
tl Both total and local MBM events are assigned
_ None of the MBM events are assigned
---
v11: Fixed printing the separator after each domain while listing the group assignments.
Renamed rdtgroup_mbm_assign_control_show to resctrl_mbm_assign_control_show().
v10: Changes mostly due to domain specific counter assignment.
v9: Minor parameter update in resctrl_mbm_event_assigned().
v8: Moved resctrl_mbm_event_assigned() in here as it is first used here.
Moved rdt_last_cmd_clear() before making any call. Updated the commit log.
Corrected the doc format.
v7: Renamed the interface name from 'mbm_control' to 'mbm_assign_control'
to match 'mbm_assign_mode'.
Removed Arch references from FS code.
Added rdt_last_cmd_clear() before the command processing. Added rdtgroup_mutex before all the calls.
Removed references of ABMC from FS code.
v6: The domain specific assignment can be determined looking at mbm_cntr_map.
Removed rdtgroup_abmc_dom_cfg() and rdtgroup_abmc_dom_state(). Removed the switch statement for the domain_state detection. Determined the flags incremently.
Removed special handling of default group while printing..
v5: Replaced "assignment flags" with "flags".
Changes related to mon structure.
Changes related renaming the interface from mbm_assign_control to mbm_control.
v4: Added functionality to query domain specific assigment in.
rdtgroup_abmc_dom_state().
v3: New patch.
Addresses the feedback to provide the global assignment interface.
https://lore.kernel.org/lkml/[email protected]/
--- Documentation/arch/x86/resctrl.rst | 44 ++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 1 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 81 ++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)
Documentation/arch/x86/resctrl.rst +44 -0
@@ -330,6 +330,50 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=30;1=30 +"mbm_assign_control": + Reports the resctrl group and monitor status of each group. + + List follows the following format: + "<CTRL_MON group>/<MON group>/<domain_id>=<flags>" + + Format for specific type of groups: + + * Default CTRL_MON group: + "//<domain_id>=<flags>" + + * Non-default CTRL_MON group: + "<CTRL_MON group>//<domain_id>=<flags>" + + * Child MON group of default CTRL_MON group: + "/<MON group>/<domain_id>=<flags>" + + * Child MON group of non-default CTRL_MON group: + "<CTRL_MON group>/<MON group>/<domain_id>=<flags>" + + Flags can be one of the following: + :: + + t MBM total event is assigned. + l MBM local event is assigned. + tl Both MBM total and local events are assigned. + _ None of the MBM events are assigned. + + Examples: + :: + + # mkdir /sys/fs/resctrl/mon_groups/child_default_mon_grp + # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp + # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp/mon_groups/child_non_default_mon_grp + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=tl;1=tl + /child_default_mon_grp/0=tl;1=tl + + There are four resctrl groups. All the groups have total and local MBM events + assigned on domain 0 and 1. + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
@@ -1236,6 +1236,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) hw_res->mbm_cntr_assign_enabled = true;resctrl_file_fflags_init ("num_mbm_cntrs" ,RFTYPE_MON_INFO );resctrl_file_fflags_init ("available_mbm_cntrs" ,RFTYPE_MON_INFO ); +resctrl_file_fflags_init ("mbm_assign_control" ,RFTYPE_MON_INFO ); } }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +81 -0
93 lines not on this page · raw message
Signature · 1 line
2.34.1
Dave Martin
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Quoted 2 lines · Babu Moger
Provide the interface to list the assignment states of all the resctrl groups in
mbm_cntr_assignmode.
[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -975,6 +975,81 @@ static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of,
[...]
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0+static int resctrl_mbm_assign_control_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{
[...]
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +14
-0+list_for_each_entry (rdtg, &rdt_all_groups, rdtgroup_list) { +seq_printf (s,"%s//" , rdtg->kn->name); + + sep = false; +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +if (sep) +seq_puts (s,";" ); + +seq_printf (s,"%d=%s" , dom->hdr.id, +rdtgroup_mon_state_to_str (r, dom, rdtg, str)); + + sep = true; + } +seq_putc (s,'\n' );
arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, · line 1041
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ +list_for_each_entry (crg, &rdtg->mon.crdtgrp_list, mon.crdtgrp_list) { +seq_printf (s,"%s/%s/" , rdtg->kn->name, crg->kn->name); + + sep = false; +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +if (sep) +seq_puts (s,";" ); +seq_printf (s,"%d=%s" , dom->hdr.id, +rdtgroup_mon_state_to_str (r, dom, crg, str));
Unlike the other resctrl files, it looks like the total size of this data will scale up with the number of existing monitoring groups and the lengths of the group names (in addition to the number of monitoring domains).
So, this can easily be more than a page, overflowing internal limits in the seq_file and kernfs code.
Do we need to track some state between read() calls? This can be done by overriding the kernfs .open() and .release() methods and hanging some state data (or an rdtgroup_file pointer) on of->priv.
Also, if we allow the data to be read out in chunks, then we would either have to snapshot all the data in one go and stash the unread tail in the kernel, or we would need to move over to RCU-based enumeration or similar -- otherwise releasing rdtgroup_mutex in the middle of the enumeration in order to return data to userspace is going to be a problem...
arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, · line 1051
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ sep = true; + } +seq_putc (s,'\n' ); + } + } + +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); +return 0 ; +}
[...]
Cheers
---Dave
Moger, Babu
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Hi Dave,
Quoted 57 lines · Dave Martin
Quoted 2 lines · Babu Moger
Provide the interface to list the assignment states of all the resctrl groups in
mbm_cntr_assignmode.[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -975,6 +975,81 @@ static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of,[...]
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0+static int resctrl_mbm_assign_control_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{[...]
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +14
-0+list_for_each_entry (rdtg, &rdt_all_groups, rdtgroup_list) { +seq_printf (s,"%s//" , rdtg->kn->name); + + sep = false; +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +if (sep) +seq_puts (s,";" ); + +seq_printf (s,"%d=%s" , dom->hdr.id, +rdtgroup_mon_state_to_str (r, dom, rdtg, str)); + + sep = true; + } +seq_putc (s,'\n' );arch/x86/kernel/cpu/resctrl/rdtgroup.c
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ +list_for_each_entry (crg, &rdtg->mon.crdtgrp_list, mon.crdtgrp_list) { +seq_printf (s,"%s/%s/" , rdtg->kn->name, crg->kn->name); + + sep = false; +list_for_each_entry (dom, &r->mon_domains, hdr.list) { +if (sep) +seq_puts (s,";" ); +seq_printf (s,"%d=%s" , dom->hdr.id, +rdtgroup_mon_state_to_str (r, dom, crg, str));Unlike the other resctrl files, it looks like the total size of this data will scale up with the number of existing monitoring groups and the lengths of the group names (in addition to the number of monitoring domains).
So, this can easily be more than a page, overflowing internal limits in the
seq_fileand kernfs code.Do we need to track some state between
read()calls? This can be done by overriding the kernfs .open() and .release() methods and hanging some state data (or anrdtgroup_filepointer) onof->priv.
Quoted 6 lines
Also, if we allow the data to be read out in chunks, then we would either have to snapshot all the data in one go and stash the unread tail in the kernel, or we would need to move over to RCU-based enumeration or similar -- otherwise releasing
rdtgroup_mutexin the middle of the enumeration in order to return data to userspace is going to be a problem...
Good catch.
I see similar buffer overflow is handled by calling seq_buf_clear() (look at process_durations() or in show_user_instructions()).
How about handling this by calling rdt_last_cmd_clear() before printing each group?
(quoted diff) +0 -0
b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 484d6009869f..1828f59eb723 100644
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
@@ -1026,6 +1026,7 @@ static int resctrl_mbm_assign_control_show(struct
kernfs_open_file *of,
}
list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) {
+ rdt_last_cmd_clear();
seq_printf(s, "%s//", rdtg->kn->name);
sep = false;
@@ -1041,6 +1042,7 @@ static int resctrl_mbm_assign_control_show(struct
kernfs_open_file *of,
seq_putc(s, '\n');
list_for_each_entry(crg, &rdtg->mon.crdtgrp_list,
mon.crdtgrp_list) {
+ rdt_last_cmd_clear();
seq_printf(s, "%s/%s/", rdtg->kn->name,crg->kn->name);
sep = false;
Quoted 17 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ sep = true; + } +seq_putc (s,'\n' ); + } + } + +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); +return 0 ; +}[...]
Cheers
---Dave
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Hi,
Quoted 6 lines · Babu
Hi Dave,
Quoted 3 lines · Dave Martin
Quoted 2 lines · Babu Moger
Provide the interface to list the assignment states of all the resctrl groups in
mbm_cntr_assignmode.
[...]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3
-0+static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{
[...]
Quoted 19 lines
Quoted 12 lines
Unlike the other resctrl files, it looks like the total size of this data will scale up with the number of existing monitoring groups and the lengths of the group names (in addition to the number of monitoring domains).
So, this can easily be more than a page, overflowing internal limits in the
seq_fileand kernfs code.Do we need to track some state between
read()calls? This can be done by overriding the kernfs .open() and .release() methods and hanging some state data (or anrdtgroup_filepointer) onof->priv.Quoted 6 lines
Also, if we allow the data to be read out in chunks, then we would either have to snapshot all the data in one go and stash the unread tail in the kernel, or we would need to move over to RCU-based enumeration or similar -- otherwise releasing
rdtgroup_mutexin the middle of the enumeration in order to return data to userspace is going to be a problem...
Quoted 7 lines
Good catch.
I see similar buffer overflow is handled by calling
seq_buf_clear()(look atprocess_durations()or inshow_user_instructions()).How about handling this by calling
rdt_last_cmd_clear()before printing each group?
Does this work?
Once seq_buf_has_overflowed() returns nonzero, data has been lost, no? So far as I can see, show_user_instructions() just gives up on printing the affected line, while process_durations() tries to anticipate overflow and prints out the accumulated text to dmesg before clearing the buffer.
In our case, we cannot send more data to userspace than was requested in the read() call, so we might have nowhere to drain the seq_buf contents to in order to free up space.
sysfs "expects" userspace to do a big enough read() that this problem doesn't happen. In practice this is OK because people usually read through a buffered I/O layer like stdio, and in realistic implementations the user-side I/O buffer is large enough to hide this issue.
But mbm_assign_control data is dynamically generated and potentially much bigger than a typical sysfs file.
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-0@@ -1026,6 +1026,7 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, }list_for_each_entry (rdtg, &rdt_all_groups, rdtgroup_list) { +rdt_last_cmd_clear ();seq_printf (s,"%s//" , rdtg->kn->name);sep = false;
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct · line 1047
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-0@@ -1041,6 +1042,7 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of,seq_putc (s,'\n' );list_for_each_entry (crg, &rdtg->mon.crdtgrp_list, mon.crdtgrp_list) { +rdt_last_cmd_clear ();
I don't see how this helps.
Surely last_cmd_status has nothing to do with s?
[...]
Cheers
---Dave
Moger, Babu
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Hi Dave,
Quoted 45 lines · Dave Martin
Hi,
Quoted 6 lines · Babu
Hi Dave,
Quoted 3 lines · Dave Martin
Quoted 2 lines · Babu Moger
Provide the interface to list the assignment states of all the resctrl groups in
mbm_cntr_assignmode.[...]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3
-0+static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{[...]
Quoted 19 lines
Quoted 12 lines
Unlike the other resctrl files, it looks like the total size of this data will scale up with the number of existing monitoring groups and the lengths of the group names (in addition to the number of monitoring domains).
So, this can easily be more than a page, overflowing internal limits in the
seq_fileand kernfs code.Do we need to track some state between
read()calls? This can be done by overriding the kernfs .open() and .release() methods and hanging some state data (or anrdtgroup_filepointer) onof->priv.Quoted 6 lines
Also, if we allow the data to be read out in chunks, then we would either have to snapshot all the data in one go and stash the unread tail in the kernel, or we would need to move over to RCU-based enumeration or similar -- otherwise releasing
rdtgroup_mutexin the middle of the enumeration in order to return data to userspace is going to be a problem...Quoted 7 lines
Good catch.
I see similar buffer overflow is handled by calling
seq_buf_clear()(look atprocess_durations()or inshow_user_instructions()).How about handling this by calling
rdt_last_cmd_clear()before printing each group?
Quoted 7 lines
Does this work?
Once
seq_buf_has_overflowed()returns nonzero, data has been lost, no? So far as I can see,show_user_instructions()just gives up on printing the affected line, whileprocess_durations()tries to anticipate overflow and prints out the accumulated text to dmesg before clearing the buffer.
Yea. Agree,
Quoted 5 lines
In our case, we cannot send more data to userspace than was requested in the
read()call, so we might have nowhere to drain theseq_bufcontents to in order to free up space.
Quoted 8 lines
sysfs "expects" userspace to do a big enough
read()that this problem doesn't happen. In practice this is OK because people usually read through a buffered I/O layer like stdio, and in realistic implementations the user-side I/O buffer is large enough to hide this issue.But
mbm_assign_controldata is dynamically generated and potentially much bigger than a typical sysfs file.
I have no idea how to handle this case. We may have to live with this problem. Let us know if there are any ideas.
Quoted 20 lines
Quoted 20 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-0@@ -1026,6 +1026,7 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, }list_for_each_entry (rdtg, &rdt_all_groups, rdtgroup_list) { +rdt_last_cmd_clear ();seq_printf (s,"%s//" , rdtg->kn->name);sep = false;arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -1041,6 +1042,7 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of,seq_putc (s,'\n' );
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct · line 1047
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-0list_for_each_entry (crg, &rdtg->mon.crdtgrp_list, mon.crdtgrp_list) { +rdt_last_cmd_clear ();I don't see how this helps.
Surely
last_cmd_statushas nothing to do with s?
Correct. Clearly, I misunderstood the problem.
Quoted 6 lines
[...]
Cheers
---Dave
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Quoted 6 lines · Babu
Hi Dave,
Quoted 3 lines · Dave Martin
Hi,
On Wed, Feb 19, 2025 at 03:09:51PM -0600, Moger, Babu wrote:
[...]
Quoted 29 lines
Quoted 8 lines
Quoted 7 lines
Good catch.
I see similar buffer overflow is handled by calling
seq_buf_clear()(look atprocess_durations()or inshow_user_instructions()).How about handling this by calling
rdt_last_cmd_clear()before printing each group?Quoted 7 lines
Does this work?
Once
seq_buf_has_overflowed()returns nonzero, data has been lost, no? So far as I can see,show_user_instructions()just gives up on printing the affected line, whileprocess_durations()tries to anticipate overflow and prints out the accumulated text to dmesg before clearing the buffer.Yea. Agree,
Quoted 11 lines
In our case, we cannot send more data to userspace than was requested in the
read()call, so we might have nowhere to drain theseq_bufcontents to in order to free up space.sysfs "expects" userspace to do a big enough
read()that this problem doesn't happen. In practice this is OK because people usually read through a buffered I/O layer like stdio, and in realistic implementations the user-side I/O buffer is large enough to hide this issue.
Quoted 5 lines
Quoted 2 lines
But
mbm_assign_controldata is dynamically generated and potentially much bigger than a typical sysfs file.I have no idea how to handle this case. We may have to live with this problem. Let us know if there are any ideas.
I think the current implication is that this will work for now provided that the generated text fits in a page.
Reinette, what's your view on accepting this limitation in the interest of stabilising this series, and tidying up this corner case later?
As for writes to this file, we're unlikely to hit the limit unless there are a lot of RMIDs available and many groups with excessively long names.
This looks perfectly fixable, but it might be better to settle the design of this series first before we worry too much about it.
[...]
Cheers
---Dave
Reinette Chatre
maintainerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Hi Dave,
Quoted 49 lines · Dave Martin
Quoted 6 lines · Babu
Hi Dave,
Quoted 3 lines · Dave Martin
Hi,
On Wed, Feb 19, 2025 at 03:09:51PM -0600, Moger, Babu wrote:
[...]
Quoted 29 lines
Quoted 8 lines
Quoted 7 lines
Good catch.
I see similar buffer overflow is handled by calling
seq_buf_clear()(look atprocess_durations()or inshow_user_instructions()).How about handling this by calling
rdt_last_cmd_clear()before printing each group?Quoted 7 lines
Does this work?
Once
seq_buf_has_overflowed()returns nonzero, data has been lost, no? So far as I can see,show_user_instructions()just gives up on printing the affected line, whileprocess_durations()tries to anticipate overflow and prints out the accumulated text to dmesg before clearing the buffer.Yea. Agree,
Quoted 11 lines
In our case, we cannot send more data to userspace than was requested in the
read()call, so we might have nowhere to drain theseq_bufcontents to in order to free up space.sysfs "expects" userspace to do a big enough
read()that this problem doesn't happen. In practice this is OK because people usually read through a buffered I/O layer like stdio, and in realistic implementations the user-side I/O buffer is large enough to hide this issue.Quoted 5 lines
Quoted 2 lines
But
mbm_assign_controldata is dynamically generated and potentially much bigger than a typical sysfs file.I have no idea how to handle this case. We may have to live with this problem. Let us know if there are any ideas.
I think the current implication is that this will work for now provided that the generated text fits in a page.
Quoted 6 lines
Reinette, what's your view on accepting this limitation in the interest of stabilising this series, and tidying up this corner case later?
As for writes to this file, we're unlikely to hit the limit unless there are a lot of RMIDs available and many groups with excessively long names.
I am more concerned about reads to this file. If only 4K writes are supported then user space can reconfigure the system in page sized portions. It may not be efficient if the user wants to reconfigure the entire system but it will work. The problem with reads is that if larger than 4K reads are required but not supported then it will be impossible for user space to learn state of the system.
We may already be at that limit. Peter described [1] how AMD systems already have 32 L3 monitoring domains and 256 RMIDs. With conservative resource group names of 10 characters I see one line per monitoring group that could look like below and thus easily be above 200 characters:
resgroupAA/mongroupAA/0=tl;1=tl;2=tl;3=tl;4=tl;5=tl;6=tl;7=tl;8=tl;9=tl;10=tl;11=tl;12=tl;13=tl;14=tl;15=tl;16=tl;17=tl;18=tl;19=tl;20=tl;21=tl;22=tl;23=tl;24=tl;25=tl;26=tl;27=tl;28=tl;29=tl;30=tl;31=tl;32=tl
Multiplying that with the existing possible 256 monitor groups the limit is exceeded today.
I understand that all domains having "tl" flags are not possible today, but even if that is changed to "_" the resulting display still looks to easily exceed a page when many RMIDs are in use.
Quoted 3 lines
This looks perfectly fixable, but it might be better to settle the design of this series first before we worry too much about it.
I think it fair to delay support of writing more than a page of data but it looks to me like we need a solution to support displaying more than a page of data to user space.
Reinette
Dave Martin
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Quoted 7 lines · Reinette Chatre
Hi Dave,
Quoted 4 lines · Dave Martin
Quoted 3 lines · Babu
Hi Dave,
On 2/20/25 09:44, Dave Martin wrote:
[...]
Quoted 29 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
But
mbm_assign_controldata is dynamically generated and potentially much bigger than a typical sysfs file.I have no idea how to handle this case. We may have to live with this problem. Let us know if there are any ideas.
I think the current implication is that this will work for now provided that the generated text fits in a page.
Quoted 6 lines
Reinette, what's your view on accepting this limitation in the interest of stabilising this series, and tidying up this corner case later?
As for writes to this file, we're unlikely to hit the limit unless there are a lot of RMIDs available and many groups with excessively long names.
I am more concerned about reads to this file. If only 4K writes are supported then user space can reconfigure the system in page sized portions. It may not be efficient if the user wants to reconfigure the entire system but it will work. The problem with reads is that if larger than 4K reads are required but not supported then it will be impossible for user space to learn state of the system.
We may already be at that limit. Peter described [1] how AMD systems already have 32 L3 monitoring domains and 256 RMIDs. With conservative resource group names of 10 characters I see one line per monitoring group that could look like below and thus easily be above 200 characters:
Quoted 4 lines
resgroupAA/mongroupAA/0=tl;1=tl;2=tl;3=tl;4=tl;5=tl;6=tl;7=tl;8=tl;9=tl;10=tl;11=tl;12=tl;13=tl;14=tl;15=tl;16=tl;17=tl;18=tl;19=tl;20=tl;21=tl;22=tl;23=tl;24=tl;25=tl;26=tl;27=tl;28=tl;29=tl;30=tl;31=tl;32=tl
Multiplying that with the existing possible 256 monitor groups the limit is exceeded today.
That's useful to know. I guess we probably shouldn't just kick this issue down the road, then -- at least on the read side (as you say).
Quoted 8 lines
I understand that all domains having "tl" flags are not possible today, but even if that is changed to "_" the resulting display still looks to easily exceed a page when many RMIDs are in use.
Quoted 3 lines
This looks perfectly fixable, but it might be better to settle the design of this series first before we worry too much about it.
Quoted 7 lines
I think it fair to delay support of writing more than a page of data but it looks to me like we need a solution to support displaying more than a page of data to user space.
Reinette
Ack; if I can't find an off-the-shelf solution for this, I'll try to hack something as minimal as possible to provide the required behaviour, but I won't try to make it optimal or pretty for now.
It has just occurred to be that ftrace has large, multi-line text files in sysfs, so I'll try to find out how they handle that there. Maybe there is some infrastructure we can re-use.
Either way, hopefully that will move the discussion forward (unless someone else comes up with a better idea first!)
Cheers
---Dave
Luck, Tony
maintainerRE: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Quoted 3 lines
It has just occurred to be that ftrace has large, multi-line text files in sysfs, so I'll try to find out how they handle that there. Maybe there is some infrastructure we can re-use.
Resctrl was built on top of "kernfs" because that was a simple base that met needs at the time.
Do we need to look at either extending capabilities of kernfs? Or move to sysfs?
-Tony
Dave Martin
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Hi,
Quoted 15 lines · Dave Martin
Hi Tony,
Quoted 11 lines · Tony
Quoted 3 lines
It has just occurred to be that ftrace has large, multi-line text files in sysfs, so I'll try to find out how they handle that there. Maybe there is some infrastructure we can re-use.
Resctrl was built on top of "kernfs" because that was a simple base that met needs at the time.
Do we need to look at either extending capabilities of kernfs? Or move to sysfs?
-Tony
Quoted 8 lines
I took a look at what ftrace does: it basically rolls its own buffering implementation, sufficient for its needs.
The ftrace code is internal and not trivial to pick up and plonk into resctrl. We also have another possible requirement that ftrace doesn't have (whole-file atomicity). But ftrace's example at least confirms that there is probably no off-the-shelf implementation for this in the kernel.
[...]
After having spent a bit of time looking into this, I think we are probably OK, at least for reading these files.
seq_file will loop over the file's show() callback, growing the seq_file buffer until show() can run without overrunning the buffer.
This means that the show() callback receives a buffer that is magically big enough, but there may be some "speculative" calls whose output never goes to userspace. Once seq_file has the data, it deals with the userspace- facing I/O buffering internally, so we shouldn't have to worry about that.
I'll try to hack up a test next week to confirm that this works.
The seq_file approach appears sound, but may be inefficient if the initial guess at the buffer size (= PAGE_SIZE) is frequently too small. (There is single_open_size() though, which allows the buffer to be preallocated with a specified size and may be useful.)
seq_file doesn't help with the write side at all, but I think we agreed that handling large file writes properly is less urgent.
Cheers
---Dave
Luck, Tony
maintainerRE: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Quoted 10 lines
After having spent a bit of time looking into this, I think we are probably OK, at least for reading these files.
seq_filewill loop over the file'sshow()callback, growing theseq_filebuffer untilshow()can run without overrunning the buffer.This means that the
show()callback receives a buffer that is magically big enough, but there may be some "speculative" calls whose output never goes to userspace. Onceseq_filehas the data, it deals with the userspace- facing I/O buffering internally, so we shouldn't have to worry about that.
Doesn't this depend on the size of the user read(2) syscall request?
If the total size of the resctrl file is very large, we have a potential issue:
1) User asks for 4KB, owns the resctrl mutex.
2) resctrl uses seq_file and fills with more than 4KB
3) User gets the first 4KB, releases the resctrl mutex
4) Some other pending resctrl operation now gets the mutex and makes changes that affect the contents of this file
5) User asks for next 4K (when it reaquires resctrl mutex)
6) resctrl uses seq_file() to construct new image of file incorporating changes because of step 4
7) User gets the second 4KB from the seq_file buffer (which doesn't fit cleanly next to data it got in step 3).
-Tony
Dave Martin
reviewerRe: [PATCH v11 22/23] x86/resctrl: Introduce interface to list assignment states of all the groups
Quoted 6 lines · Tony
Quoted 6 lines
After having spent a bit of time looking into this, I think we are probably OK, at least for reading these files.
seq_filewill loop over the file'sshow()callback, growing theseq_filebuffer untilshow()can run without overrunning the buffer.
Quoted 6 lines
Quoted 4 lines
This means that the
show()callback receives a buffer that is magically big enough, but there may be some "speculative" calls whose output never goes to userspace. Onceseq_filehas the data, it deals with the userspace- facing I/O buffering internally, so we shouldn't have to worry about that.Doesn't this depend on the size of the user read(2) syscall request?
Yes and no.
If I've understood correctly:
To service a given read() call, seq_file calls down into the backend to generate some whole record, then copies it out to userspace, then repeats this process so long as there is any space left in the user buffer.
For resctrl files, we don't implement a seq_file iterator: there is no .next(), no .llseek(), and we don't implement any notion of file position. So our _show() functions generate a single big record that contains the whole dump -- frequently multiple lines of text.
(This might or might not be desirable, but it is at least simple.)
If a _show() function in resctrl holds rdtgroup_mutex throughout, then whatever it dumps will be dumped atomically with respect to other resctrl operations that take this mutex.
So, to flesh out your scenario:
Quoted 2 lines
If the total size of the resctrl file is very large, we have a potential issue:
Let's say it's 5KB.
Quoted 1 line
1) User asks for 4KB, owns the resctrl mutex.
(Note, rdtgroup_mutex is only held temporarily inside the resctrlfs backend to these operations; at the start of the process, it is not held.)
Quoted 1 line
2) resctrl uses
seq_fileand fills with more than 4KB
(It's actually seq_file that uses resctrl here via callbacks: seq_file sits in between the VFS layer and resctrl.)
When a .show() callback is called, resctrl doesn't know how much data to generate; it just writes stuff out with seq_printf() etc.
If there's too much to fit in the default seq_file buffer, the data gets truncated and the seq_file will get internally marked as having overflowed. resctrl could check for this condition in order to avoid formatting text that will get thrown away due to truncation, but this is not required. When the .show() callback returns, the seq_file implementation will respond to the overflow by growing the buffer and retrying the whole thing until this doesn't occur (see the loop preceding the "Fill" label in seq_file.c:seq_read_iter().)
This terminates with a seq_file buffer that contains all the output (untruncated), or with an -ENOMEM failure (which would be punted to userspace).
So, assuming nothing went wrong, the seq_file buffer now has the 5KB of data. rdtgroup_mutex is not held (it was only held in the _show() callback).
Quoted 1 line
3) User gets the first 4KB, releases the resctrl mutex
Userspace gets the first 4KB, and seq_file's notion of the file position is advanced by this amount, and the generated text is kept in the seq_file's buffer.
Quoted 1 line
4) Some other pending resctrl operation now gets the mutex and makes changes that affect the contents of this file
The un-read data remains buffered in seq_file. Other resctrl operations can happen, so the buffered data may become stale, but it is still an atomic snapshot.
Quoted 1 line
5) User asks for next 4K (when it reaquires resctrl mutex)
If an iterator is implemented, seq_file might try to generate another record to fill the requested space. But we don't have an iterator, so the generated data remains as-is.
Quoted 1 line
6) resctrl uses
seq_file()to construct new image of file incorporating changes because of step 4
I think this happens only if the file is reopened or lseek()'d, and only if .llseek() is wired up in struct file_operations. Resctrl doesn't seem to do this (whether by accident or by design).
So userspace just sees a non-seekable file.
Quoted 1 line
7) User gets the second 4KB from the
seq_filebuffer (which doesn't fit cleanly next to data it got in step 3).
Userspace gets the final 1K of the data that was generated in response to the original read() call.
If userspace tries to read again, it will get EOF (again, because we don't have an iterator -- meaning that no additional records can be generated).
I haven't traced in detail through the code, but that's my understanding.
Cheers
---Dave
Babu Moger
reviewerPATCH v11 23/23 x86/resctrl: Introduce interface to modify assignment states of the groups
In reply to Babu MogerWhen mbm_cntr_assign mode is enabled, users can designate which of the MBM events in the CTRL_MON or MON groups should have counters assigned.
Provide an interface for assigning MBM events by writing to the file:/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.
Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Format for specific type of groups:
* Default CTRL_MON group:
"//<domain_id><opcode><flags>"
* Non-default CTRL_MON group:
"<CTRL_MON group>//<domain_id><opcode><flags>"
* Child MON group of default CTRL_MON group:
"/<MON group>/<domain_id><opcode><flags>"
* Child MON group of non-default CTRL_MON group:
"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Domain_id '*' will apply the flags on all the domains.
Opcode can be one of the following:
= Update the assignment to match the flags
+ Assign a new MBM event without impacting existing assignments.
- Unassign a MBM event from currently assigned events.
Assignment flags can be one of the following:
t MBM total event
l MBM local event
tl Both total and local MBM events
_ None of the MBM events. Valid only with '=' opcode. This flag cannot
be combined with other flags.
---
v11: Fixed the static check warning with initializing dom_id in resctrl_process_flags().
v10: Fixed the issue with finding the domain in multiple iterations.
Printed error message with domain information when assign fails. Changed the variables to unsigned for processing assign state. Taken care of few format corrections.
v9: Fixed handling special case '//0=' and '//".
Removed extra strstr() call.
Added generic failure text when assignment operation fails. Corrected user documentation format texts.
v8: Moved unassign as the first action 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: Simplified the parsing (strsep(&token, "//") in rdtgroup_mbm_assign_control_write().
Added mutex lock in rdtgroup_mbm_assign_control_write() while processing. Renamed rdtgroup_find_grp to rdtgroup_find_grp_by_name.
Fixed rdtgroup_str_to_mon_state to return error for invalid flags. Simplified the calls rdtgroup_assign_cntr by merging few functions earlier. Removed ABMC reference in FS code.
Reinette commented about handling the combination of flags like 'lt_' and '_lt'. Not sure if we need to change the behaviour here. Processed them sequencially right now. Users have the liberty to pass the flags. Restricting it might be a problem later.
v6: Added support assign all if domain id is '*'
Fixed the allocation of counter id if it not assigned already.
v5: Interface name changed from mbm_assign_control to mbm_control.
Fixed opcode and flags combination.
'=_" is valid.
"-_" amd "+_" is not valid.
Minor message update.
Renamed the function with prefix - rdtgroup_. Corrected few documentation mistakes.
Rebase related changes after SNC support.
v4: Added domain specific assignments. Fixed the opcode parsing.
v3: New patch.
Addresses the feedback to provide the global assignment interface.
--- Documentation/arch/x86/resctrl.rst | 116 +++++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 10 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 241 ++++++++++++++++++++++++- 3 files changed, 365 insertions(+), 2 deletions(-)
Documentation/arch/x86/resctrl.rst +115 -1
@@ -356,7 +356,8 @@ with the following files: t MBM total event is assigned. l MBM local event is assigned. tl Both MBM total and local events are assigned. - _ None of the MBM events are assigned. + _ None of the MBM events are assigned. Only works with opcode '=' for write + and cannot be combined with other flags. Examples: ::
@@ -374,6 +375,119 @@ with the following files: There are four resctrl groups. All the groups have total and local MBM events assigned on domain 0 and 1. + Assignment state can be updated by writing to "mbm_assign_control". + + Format is similar to the list format with addition of opcode for the + assignment operation. + + "<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>" + + Format for each type of group: + + * Default CTRL_MON group: + "//<domain_id><opcode><flags>" + + * Non-default CTRL_MON group: + "<CTRL_MON group>//<domain_id><opcode><flags>" + + * Child MON group of default CTRL_MON group: + "/<MON group>/<domain_id><opcode><flags>" + + * Child MON group of non-default CTRL_MON group: + "<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>" + + Domain_id '*' will apply the flags to all the domains. + + Opcode can be one of the following: + :: + + = Update the assignment to match the MBM event. + + Assign a new MBM event without impacting existing assignments. + - Unassign a MBM event from currently assigned events. + + Examples: + Initial group status: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=tl;1=tl + /child_default_mon_grp/0=tl;1=tl + + To update the default group to assign only total MBM event on domain 0: + :: + + # echo "//0=t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=t;1=tl + /child_default_mon_grp/0=tl;1=tl + + To update the MON group child_default_mon_grp to remove total MBM event on domain 1: + :: + + # echo "/child_default_mon_grp/1-t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=t;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the MON group non_default_ctrl_mon_grp/child_non_default_mon_grp to unassign + both local and total MBM events on domain 1: + :: + + # echo "non_default_ctrl_mon_grp/child_non_default_mon_grp/1=_" > + /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ + //0=t;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the default group to add a local MBM event domain 0: + :: + + # echo "//0+l" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ + //0=tl;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the non default CTRL_MON group non_default_ctrl_mon_grp to unassign all the + MBM events on all the domains: + :: + + # echo "non_default_ctrl_mon_grp//*=_" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=_;1=_ + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ + //0=tl;1=tl + /child_default_mon_grp/0=tl;1=l + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy
arch/x86/kernel/cpu/resctrl/internal.h +10 -0
@@ -62,6 +62,16 @@/* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */ #define ABMC_ENABLE_BIT 0 +/* +* Assignment flags for mbm_cntr_assign mode +*/ +enum { +ASSIGN_NONE =0 , +ASSIGN_TOTAL =BIT (QOS_L3_MBM_TOTAL_EVENT_ID ), +ASSIGN_LOCAL =BIT (QOS_L3_MBM_LOCAL_EVENT_ID ), +ASSIGN_INVALID , +}; +/** * cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that * aren't marked nohz_full
arch/x86/kernel/cpu/resctrl/rdtgroup.c +240 -1
255 lines not on this page · raw message
Signature · 1 line
2.34.1
Reinette Chatre
maintainerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi Babu,
Quoted 183 lines · Babu Moger
When
mbm_cntr_assignmode is enabled, users can designate which of the MBM events in theCTRL_MONor MON groups should have counters assigned.Provide an interface for assigning MBM events by writing to the file:
/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MONgroup>/<MON group>/<domain_id><opcode><flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:"//<domain_id><opcode><flags>"* Non-default
CTRL_MONgroup:"<CTRL_MON group>//<domain_id><opcode><flags>"* Child MON group of default
CTRL_MONgroup:"/<MON group>/<domain_id><opcode><flags>"* Child MON group of non-default
CTRL_MONgroup:"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Domain_id'*' will apply the flags on all the domains.Opcode can be one of the following:
= Update the assignment to match the flags
+ Assign a new MBM event without impacting existing assignments.
- Unassign a MBM event from currently assigned events.Assignment flags can be one of the following:
t MBM total event
l MBM local event
tl Both total and local MBM events
_ None of the MBM events. Valid only with '=' opcode. This flag cannot
be combined with other flags.Signed-off-by Babu Moger <[email protected]>---
v11: Fixed the static check warning with initializingdom_idinresctrl_process_flags().v10: Fixed the issue with finding the domain in multiple iterations.
Printed error message with domain information when assign fails. Changed the variables to unsigned for processing assign state. Taken care of few format corrections.v9: Fixed handling special case '//0=' and '//".
Removed extrastrstr()call.
Added generic failure text when assignment operation fails. Corrected user documentation format texts.v8: Moved unassign as the first action 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: Simplified the parsing (
strsep(&token, "//")inrdtgroup_mbm_assign_control_write().
Added mutex lock inrdtgroup_mbm_assign_control_write()while processing. Renamedrdtgroup_find_grptordtgroup_find_grp_by_name.
Fixedrdtgroup_str_to_mon_stateto return error for invalid flags. Simplified the callsrdtgroup_assign_cntrby merging few functions earlier. Removed ABMC reference in FS code.
Reinette commented about handling the combination of flags like 'lt_' and '_lt'. Not sure if we need to change the behaviour here. Processed them sequencially right now. Users have the liberty to pass the flags. Restricting it might be a problem later.v6: Added support assign all if domain id is '*'
Fixed the allocation of counter id if it not assigned already.v5: Interface name changed from
mbm_assign_controltombm_control.
Fixed opcode and flags combination.
'=_" is valid.
"-_" amd "+_" is not valid.
Minor message update.
Renamed the function with prefix -rdtgroup_. Corrected few documentation mistakes.
Rebase related changes after SNC support.v4: Added domain specific assignments. Fixed the opcode parsing.
v3: New patch.
Addresses the feedback to provide the global assignment interface.--- Documentation/arch/x86/resctrl.rst | 116 +++++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 10 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 241 ++++++++++++++++++++++++- 3 files changed, 365 insertions(+), 2 deletions(-)Documentation/arch/x86/resctrl.rst +77
-1@@ -356,7 +356,8 @@ with the following files: t MBM total event is assigned. l MBM local event is assigned. tl Both MBM total and local events are assigned. - _ None of the MBM events are assigned. + _ None of the MBM events are assigned. Only works with opcode '=' for write + and cannot be combined with other flags. Examples: ::@@ -374,6 +375,119 @@ with the following files: There are four resctrl groups. All the groups have total and local MBM events assigned on domain 0 and 1. + Assignment state can be updated by writing to "mbm_assign_control". + + Format is similar to the list format with addition of opcode for the + assignment operation. + + "<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>" + + Format for each type of group: + + * Default CTRL_MON group: + "//<domain_id><opcode><flags>" + + * Non-default CTRL_MON group: + "<CTRL_MON group>//<domain_id><opcode><flags>" + + * Child MON group of default CTRL_MON group: + "/<MON group>/<domain_id><opcode><flags>" + + * Child MON group of non-default CTRL_MON group: + "<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>" + + Domain_id '*' will apply the flags to all the domains. + + Opcode can be one of the following: + :: + + = Update the assignment to match the MBM event. + + Assign a new MBM event without impacting existing assignments. + - Unassign a MBM event from currently assigned events. + + Examples: + Initial group status: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=tl;1=tl + /child_default_mon_grp/0=tl;1=tl + + To update the default group to assign only total MBM event on domain 0: + :: + + # echo "//0=t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=t;1=tl + /child_default_mon_grp/0=tl;1=tl + + To update the MON group child_default_mon_grp to remove total MBM event on domain 1: + :: + + # echo "/child_default_mon_grp/1-t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=t;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the MON group non_default_ctrl_mon_grp/child_non_default_mon_grp to unassign + both local and total MBM events on domain 1: + :: + + # echo "non_default_ctrl_mon_grp/child_non_default_mon_grp/1=_" > + /sys/fs/resctrl/info/L3_MON/mbm_assign_control +
Documentation/arch/x86/resctrl.rst with the following files: · line 462
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +10
-0+ Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ + //0=t;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the default group to add a local MBM event domain 0:
"local MBM event domain 0" -> "local MBM event on domain 0"?
Taking a step back to look at the completed "mbm_assign_control" section it is noteworthy that all this work is about assigning counters to events but after this large section is complete the word "counter" does not appear a single time.
The section starts with a brief:
"Reports the resctrl group and monitor status of each group." and then moves to terms like "assigning events"/"assignment status" without defining what that means.
Instead of rewriting this, what do you think of adding some definition of what "assignment state" means to the start of the section. For example, (I am sure it can be improved):
"Use "mbm_assign_control" to manage monitoring counter assignment to monitoring events when mbm_cntr_assign_mode is enabled."
Reinette
Moger, Babu
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi Reinette,
Quoted 190 lines · Reinette Chatre
Hi Babu,
Quoted 187 lines · Babu Moger
When
mbm_cntr_assignmode is enabled, users can designate which of the MBM events in theCTRL_MONor MON groups should have counters assigned.Provide an interface for assigning MBM events by writing to the file:
/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MONgroup>/<MON group>/<domain_id><opcode><flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:"//<domain_id><opcode><flags>"* Non-default
CTRL_MONgroup:"<CTRL_MON group>//<domain_id><opcode><flags>"* Child MON group of default
CTRL_MONgroup:"/<MON group>/<domain_id><opcode><flags>"* Child MON group of non-default
CTRL_MONgroup:"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Domain_id'*' will apply the flags on all the domains.Opcode can be one of the following:
= Update the assignment to match the flags
+ Assign a new MBM event without impacting existing assignments.
- Unassign a MBM event from currently assigned events.Assignment flags can be one of the following:
t MBM total event
l MBM local event
tl Both total and local MBM events
_ None of the MBM events. Valid only with '=' opcode. This flag cannot
be combined with other flags.Signed-off-by Babu Moger <[email protected]>---
v11: Fixed the static check warning with initializingdom_idinresctrl_process_flags().v10: Fixed the issue with finding the domain in multiple iterations.
Printed error message with domain information when assign fails. Changed the variables to unsigned for processing assign state. Taken care of few format corrections.v9: Fixed handling special case '//0=' and '//".
Removed extrastrstr()call.
Added generic failure text when assignment operation fails. Corrected user documentation format texts.v8: Moved unassign as the first action 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: Simplified the parsing (
strsep(&token, "//")inrdtgroup_mbm_assign_control_write().
Added mutex lock inrdtgroup_mbm_assign_control_write()while processing. Renamedrdtgroup_find_grptordtgroup_find_grp_by_name.
Fixedrdtgroup_str_to_mon_stateto return error for invalid flags. Simplified the callsrdtgroup_assign_cntrby merging few functions earlier. Removed ABMC reference in FS code.
Reinette commented about handling the combination of flags like 'lt_' and '_lt'. Not sure if we need to change the behaviour here. Processed them sequencially right now. Users have the liberty to pass the flags. Restricting it might be a problem later.v6: Added support assign all if domain id is '*'
Fixed the allocation of counter id if it not assigned already.v5: Interface name changed from
mbm_assign_controltombm_control.
Fixed opcode and flags combination.
'=_" is valid.
"-_" amd "+_" is not valid.
Minor message update.
Renamed the function with prefix -rdtgroup_. Corrected few documentation mistakes.
Rebase related changes after SNC support.v4: Added domain specific assignments. Fixed the opcode parsing.
v3: New patch.
Addresses the feedback to provide the global assignment interface.--- Documentation/arch/x86/resctrl.rst | 116 +++++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 10 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 241 ++++++++++++++++++++++++- 3 files changed, 365 insertions(+), 2 deletions(-)Documentation/arch/x86/resctrl.rst +81
-1@@ -356,7 +356,8 @@ with the following files: t MBM total event is assigned. l MBM local event is assigned. tl Both MBM total and local events are assigned. - _ None of the MBM events are assigned. + _ None of the MBM events are assigned. Only works with opcode '=' for write + and cannot be combined with other flags. Examples: ::@@ -374,6 +375,119 @@ with the following files: There are four resctrl groups. All the groups have total and local MBM events assigned on domain 0 and 1. + Assignment state can be updated by writing to "mbm_assign_control". + + Format is similar to the list format with addition of opcode for the + assignment operation. + + "<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>" + + Format for each type of group: + + * Default CTRL_MON group: + "//<domain_id><opcode><flags>" + + * Non-default CTRL_MON group: + "<CTRL_MON group>//<domain_id><opcode><flags>" + + * Child MON group of default CTRL_MON group: + "/<MON group>/<domain_id><opcode><flags>" + + * Child MON group of non-default CTRL_MON group: + "<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>" + + Domain_id '*' will apply the flags to all the domains. + + Opcode can be one of the following: + :: + + = Update the assignment to match the MBM event. + + Assign a new MBM event without impacting existing assignments. + - Unassign a MBM event from currently assigned events. + + Examples: + Initial group status: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=tl;1=tl + /child_default_mon_grp/0=tl;1=tl + + To update the default group to assign only total MBM event on domain 0: + :: + + # echo "//0=t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=t;1=tl + /child_default_mon_grp/0=tl;1=tl + + To update the MON group child_default_mon_grp to remove total MBM event on domain 1: + :: + + # echo "/child_default_mon_grp/1-t" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=tl + //0=t;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the MON group non_default_ctrl_mon_grp/child_non_default_mon_grp to unassign + both local and total MBM events on domain 1: + :: + + # echo "non_default_ctrl_mon_grp/child_non_default_mon_grp/1=_" > + /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control
Quoted 8 lines
Documentation/arch/x86/resctrl.rst with the following files: · line 462
Quoted 6 lines
Documentation/arch/x86/resctrl.rst +6
-0+ non_default_ctrl_mon_grp//0=tl;1=tl + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=tl;1=_ + //0=t;1=tl + /child_default_mon_grp/0=tl;1=l + + To update the default group to add a local MBM event domain 0:"local MBM event domain 0" -> "local MBM event on domain 0"?
Sure.
Quoted 11 lines
Taking a step back to look at the completed "
mbm_assign_control" section it is noteworthy that all this work is about assigning counters to events but after this large section is complete the word "counter" does not appear a single time.The section starts with a brief:
"Reports the resctrl group and monitor status of each group." and then moves to terms like "assigning events"/"assignment status" without defining what that means.
Quoted 6 lines
Instead of rewriting this, what do you think of adding some definition of what "assignment state" means to the start of the section. For example, (I am sure it can be improved):
"Use "
mbm_assign_control" to manage monitoring counter assignment to monitoring events whenmbm_cntr_assign_modeis enabled."
Sure.
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
In reply to Babu MogerHi,
Quoted 10 lines · Babu Moger
When
mbm_cntr_assignmode is enabled, users can designate which of the MBM events in theCTRL_MONor MON groups should have counters assigned.Provide an interface for assigning MBM events by writing to the file:
/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MONgroup>/<MON group>/<domain_id><opcode><flags>"
[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -1050,6 +1050,244 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of,
[...]
Quoted 24 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +24
-0+static ssize_t resctrl_mbm_assign_control_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdt_resource *r = of->kn->parent->priv; +char *token, *cmon_grp, *mon_grp; +enum rdt_group_type rtype; +int ret; + +/* 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 (!resctrl_arch_mbm_cntr_assign_enabled (r)) { +rdt_last_cmd_puts ("mbm_cntr_assign mode is not enabled\n" ); +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); +return -EINVAL ;
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, · line 1267
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ } + +while ((token =strsep (&buf,"\n" )) !=NULL ) { +/* +* The write command follows the following format: +* “<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>” +* Extract the CTRL_MON group. +*/ + cmon_grp =strsep (&token,"/" ); +
As when reading this file, I think that the data can grow larger than a page and get split into multiple write() calls.
I don't currently think the file needs to be redesigned, but there are some concerns about how userspace will work with it that need to be sorted out.
Every monitoring group can contribute a line to this file:
CTRL_GROUP / MON_GROUP / DOMAIN = [t][l] [ ; DOMAIN = [t][l] ]* LF
so, 2 * (NAME_MAX + 1) + NUM_DOMAINS * 5 - 1 + 1
NAME_MAX on Linux is 255, so with, say, up to 16 domains, that's about 600 bytes per monitoring group in the worst case.
We don't need to have many control and monitoring groups for this to grow potentially over 4K.
We could simply place a limit on how much userspace is allowed to write to this file in one go, although this restriction feels difficult for userspace to follow -- but maybe this is workable in the short term, on current systems (?)
Otherwise, since we expect this interface to be written using scripting languages, I think we need to be prepared to accept fully-buffered I/O. That means that the data may be cut at random places, not necessarily at newlines. (For smaller files such as schemata this is not such an issue, since the whole file is likely to be small enough to fit into the default stdio buffers -- this is how sysfs gets away with it IIUC.)
For fully-buffered I/O, we may have to cache an incomplete line in between write() calls. If there is a dangling incomplete line when the file is closed then it is hard to tell userspace, because people often don't bother to check the return value of close(), fclose() etc. However, since it's an ABI violation for userspace to end this file with a partial line, I think it's sufficient to report that via last_cmd_status. (Making close() return -EIO still seems a good idea though, just in case userspace is listening.)
I hacked up something a bit like this so that schemata could be written interactively from the shell, so I can try to port that onto this series as an illustration, if it helps.
Cheers
---Dave
Luck, Tony
maintainerRE: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Quoted 3 lines
I hacked up something a bit like this so that schemata could be written interactively from the shell, so I can try to port that onto this series as an illustration, if it helps.
Note that schemata will accept writes that just change the bits you want to change.
So from the shell:
# cat schemata MB:0=100;1=100 L3:0=fff;1=fff
# echo "MB:1=90" > schemata
# cat schemata MB:0=100;1= 90 L3:0=fff;1=fff
-Tony
Dave Martin
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
[Dropped Cc: [email protected] <[email protected]> (bounces)]
Quoted 12 lines · Tony
Quoted 3 lines
I hacked up something a bit like this so that schemata could be written interactively from the shell, so I can try to port that onto this series as an illustration, if it helps.
Note that schemata will accept writes that just change the bits you want to change.
So from the shell:
# cat schemata MB:0=100;1=100 L3:0=fff;1=fff
Quoted 8 lines
# echo "MB:1=90" > schemata# cat schemata MB:0=100;1= 90 L3:0=fff;1=fff-Tony
Yes, but not:
# {
p=:
echo -n MB
for ((d = 0; d < 2; d++)); do
echo -n "$p$d=100"
p=';'
done
echo} >schemata
(Or at least, it depends on the shell. Each simple command that generates output can result in a separate write() call -- certainly there is no guarantee that it won't.)
Doing the same thing from C will "work", because by default I/O on the schemata file will be fully buffered in userspace... unless the whole output exceeds the default buffer size.
The difference from sysfs here is that it would be insane to write a small, single formatted value in pieces when it is natural to generate it from a single format specifier -- whereas the syntax of some of resctrl's files has a multilevel internal structure that has to be built up in a piecemeal fashion (whether or not it is written to the file in one go).
I'm not saying that this is an issue for realistic uses though, and anyway, the schemata file is nothing to do with this series.
Cheers
---Dave
Re: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
In reply to Dave MartinHi Dave,
Quoted 92 lines · Dave Martin
Hi,
Quoted 10 lines · Babu Moger
When
mbm_cntr_assignmode is enabled, users can designate which of the MBM events in theCTRL_MONor MON groups should have counters assigned.Provide an interface for assigning MBM events by writing to the file:
/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MONgroup>/<MON group>/<domain_id><opcode><flags>"[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -1050,6 +1050,244 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of,[...]
Quoted 24 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +24
-0+static ssize_t resctrl_mbm_assign_control_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdt_resource *r = of->kn->parent->priv; +char *token, *cmon_grp, *mon_grp; +enum rdt_group_type rtype; +int ret; + +/* 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 (!resctrl_arch_mbm_cntr_assign_enabled (r)) { +rdt_last_cmd_puts ("mbm_cntr_assign mode is not enabled\n" ); +mutex_unlock (&rdtgroup_mutex); +cpus_read_unlock (); +return -EINVAL ;arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, · line 1267
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ } + +while ((token =strsep (&buf,"\n" )) !=NULL ) { +/* +* The write command follows the following format: +* “<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>” +* Extract the CTRL_MON group. +*/ + cmon_grp =strsep (&token,"/" ); +As when reading this file, I think that the data can grow larger than a page and get split into multiple
write()calls.I don't currently think the file needs to be redesigned, but there are some concerns about how userspace will work with it that need to be sorted out.
Every monitoring group can contribute a line to this file:
CTRL_GROUP / MON_GROUP / DOMAIN = [t][l] [ ; DOMAIN = [t][l] ]* LFso, 2 * (
NAME_MAX+ 1) +NUM_DOMAINS* 5 - 1 + 1
NAME_MAXon Linux is 255, so with, say, up to 16 domains, that's about 600 bytes per monitoring group in the worst case.We don't need to have many control and monitoring groups for this to grow potentially over 4K.
We could simply place a limit on how much userspace is allowed to write to this file in one go, although this restriction feels difficult for userspace to follow -- but maybe this is workable in the short term, on current systems (?)
Otherwise, since we expect this interface to be written using scripting languages, I think we need to be prepared to accept fully-buffered I/O. That means that the data may be cut at random places, not necessarily at newlines. (For smaller files such as schemata this is not such an issue, since the whole file is likely to be small enough to fit into the default stdio buffers -- this is how sysfs gets away with it IIUC.)
Quoted 8 lines
For fully-buffered I/O, we may have to cache an incomplete line in between
write()calls. If there is a dangling incomplete line when the file is closed then it is hard to tell userspace, because people often don't bother to check the return value ofclose(),fclose()etc. However, since it's an ABI violation for userspace to end this file with a partial line, I think it's sufficient to report that vialast_cmd_status. (Makingclose()return-EIOstill seems a good idea though, just in case userspace is listening.)
Seems like we can add a check in resctrl_mbm_assign_control_write() to compare nbytes > PAGE_SIZE.
But do we really need this? I have no way of testing this. Help me understand.
All these file operations go thru generic call kernfs_fop_write_iter(). Doesn't it take care of buffer check and overflow?
Quoted 8 lines
I hacked up something a bit like this so that schemata could be written interactively from the shell, so I can try to port that onto this series as an illustration, if it helps.
Cheers
---Dave
Thanks
Babu
Dave Martin
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi,
Quoted 20 lines · Babu
Hi Dave,
Quoted 17 lines · Dave Martin
Hi,
On Wed, Jan 22, 2025 at 02:20:31PM -0600, Babu Moger wrote:
[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -1050,6 +1050,244 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of,[...]
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0+static ssize_t resctrl_mbm_assign_control_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{
[...]
Quoted 51 lines
Quoted 42 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, · line 1267
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-0+while ((token =strsep (&buf,"\n" )) !=NULL ) { +/* +* The write command follows the following format: +* “<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>” +* Extract the CTRL_MON group. +*/ + cmon_grp =strsep (&token,"/" ); +As when reading this file, I think that the data can grow larger than a page and get split into multiple
write()calls.I don't currently think the file needs to be redesigned, but there are some concerns about how userspace will work with it that need to be sorted out.
Every monitoring group can contribute a line to this file:
CTRL_GROUP / MON_GROUP / DOMAIN = [t][l] [ ; DOMAIN = [t][l] ]* LFso, 2 * (
NAME_MAX+ 1) +NUM_DOMAINS* 5 - 1 + 1
NAME_MAXon Linux is 255, so with, say, up to 16 domains, that's about 600 bytes per monitoring group in the worst case.We don't need to have many control and monitoring groups for this to grow potentially over 4K.
We could simply place a limit on how much userspace is allowed to write to this file in one go, although this restriction feels difficult for userspace to follow -- but maybe this is workable in the short term, on current systems (?)
Otherwise, since we expect this interface to be written using scripting languages, I think we need to be prepared to accept fully-buffered I/O. That means that the data may be cut at random places, not necessarily at newlines. (For smaller files such as schemata this is not such an issue, since the whole file is likely to be small enough to fit into the default stdio buffers -- this is how sysfs gets away with it IIUC.)
Quoted 8 lines
For fully-buffered I/O, we may have to cache an incomplete line in between
write()calls. If there is a dangling incomplete line when the file is closed then it is hard to tell userspace, because people often don't bother to check the return value ofclose(),fclose()etc. However, since it's an ABI violation for userspace to end this file with a partial line, I think it's sufficient to report that vialast_cmd_status. (Makingclose()return-EIOstill seems a good idea though, just in case userspace is listening.)
Quoted 2 lines
Seems like we can add a check in
resctrl_mbm_assign_control_write()to compare nbytes >PAGE_SIZE.
This might be a reasonable stopgap approach, if we are confident that the number of RMIDs and monitoring domains is small enough on known platforms that the problem is unlikely to be hit. I can't really judge on this.
Quoted 2 lines
But do we really need this? I have no way of testing this. Help me understand.
It's easy to demonatrate this using the schemata file (which works in a similar way). Open f in /sys/fs/resctrl/schemata, then:
int n = 0;
for (n = 0; n < 1000; n++)
if (fputs("MB:0=100;1=100\n", f) == EOF)
fprintf(stderr, "Failed on interation %d\n", n);This will succeed a certain number of times (272, for me) and then fail when the stdio buffer for f overflows, triggering a write().
Putting an explicit fflush() after every fputs() call (or doing a setlinebuf(f) before the loop) makes it work. But this is awkward and unexpected for the user, and doing the right thing from a scripting language may be tricky.
In this example I am doing something a bit artificial -- we don't officially say what happens when a pre-opened schemata file handle is reused in this way, AFAICT. But for mbm_assign_control it is legitimate to write many lines, and we can hit this kind of problem.
I'll leave it to others to judge whether we _need_ to fix this, but it feels like a problem waiting to happen.
Quoted 2 lines
All these file operations go thru generic call
kernfs_fop_write_iter(). Doesn't it take care of buffer check and overflow?
No, this is called for each iovec segment (where userspace used one of the iovec based I/O syscalls). But there is no buffering or concatenation of the data read in: each segment gets passed down to the individual kernfs_file_operations write method for the file:
len = ops->write(of, buf, len, iocb->ki_pos)
calls down to
resctrl_mbm_assign_control_write(of, buf, len, iocb->ki_pos).
I'll try to port my buffering hack on top of the series -- that should help to illustrate what I mean.
Cheers
---Dave
Moger, Babu
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi Dave,
Quoted 105 lines · Dave Martin
Hi,
Quoted 20 lines · Babu
Hi Dave,
Quoted 17 lines · Dave Martin
Hi,
On Wed, Jan 22, 2025 at 02:20:31PM -0600, Babu Moger wrote:
[...]
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -1050,6 +1050,244 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of,[...]
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0+static ssize_t resctrl_mbm_assign_control_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{[...]
Quoted 51 lines
Quoted 42 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-0+while ((token =strsep (&buf,"\n" )) !=NULL ) { +/* +* The write command follows the following format: +* “<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>” +* Extract the CTRL_MON group. +*/ + cmon_grp =strsep (&token,"/" ); +As when reading this file, I think that the data can grow larger than a page and get split into multiple
write()calls.I don't currently think the file needs to be redesigned, but there are some concerns about how userspace will work with it that need to be sorted out.
Every monitoring group can contribute a line to this file:
CTRL_GROUP / MON_GROUP / DOMAIN = [t][l] [ ; DOMAIN = [t][l] ]* LFso, 2 * (
NAME_MAX+ 1) +NUM_DOMAINS* 5 - 1 + 1
NAME_MAXon Linux is 255, so with, say, up to 16 domains, that's about 600 bytes per monitoring group in the worst case.We don't need to have many control and monitoring groups for this to grow potentially over 4K.
We could simply place a limit on how much userspace is allowed to write to this file in one go, although this restriction feels difficult for userspace to follow -- but maybe this is workable in the short term, on current systems (?)
Otherwise, since we expect this interface to be written using scripting languages, I think we need to be prepared to accept fully-buffered I/O. That means that the data may be cut at random places, not necessarily at newlines. (For smaller files such as schemata this is not such an issue, since the whole file is likely to be small enough to fit into the default stdio buffers -- this is how sysfs gets away with it IIUC.)
Quoted 8 lines
For fully-buffered I/O, we may have to cache an incomplete line in between
write()calls. If there is a dangling incomplete line when the file is closed then it is hard to tell userspace, because people often don't bother to check the return value ofclose(),fclose()etc. However, since it's an ABI violation for userspace to end this file with a partial line, I think it's sufficient to report that vialast_cmd_status. (Makingclose()return-EIOstill seems a good idea though, just in case userspace is listening.)Quoted 2 lines
Seems like we can add a check in
resctrl_mbm_assign_control_write()to compare nbytes >PAGE_SIZE.This might be a reasonable stopgap approach, if we are confident that the number of RMIDs and monitoring domains is small enough on known platforms that the problem is unlikely to be hit. I can't really judge on this.
Quoted 2 lines
But do we really need this? I have no way of testing this. Help me understand.
It's easy to demonatrate this using the schemata file (which works in a similar way). Open f in
/sys/fs/resctrl/schemata, then:int n = 0; for (n = 0; n < 1000; n++) if (fputs("MB:0=100;1=100\n", f) == EOF) fprintf(stderr, "Failed on interation %d\n", n);This will succeed a certain number of times (272, for me) and then fail when the stdio buffer for f overflows, triggering a
write().Putting an explicit
fflush()after everyfputs()call (or doing a setlinebuf(f) before the loop) makes it work. But this is awkward and unexpected for the user, and doing the right thing from a scripting language may be tricky.
Quoted 8 lines
In this example I am doing something a bit artificial -- we don't officially say what happens when a pre-opened schemata file handle is reused in this way, AFAICT. But for
mbm_assign_controlit is legitimate to write many lines, and we can hit this kind of problem.I'll leave it to others to judge whether we _need_ to fix this, but it feels like a problem waiting to happen.
Created the problem using this code using a "test" group.
include <stdio.h>
#include <errno.h>
#include <string.h>
int main()
{
FILE *file;
int n;
file = fopen("/sys/fs/resctrl/info/L3_MON/mbm_assign_control", "w");
if (file == NULL) {
printf("Error opening file!\n");
return 1;
}
printf("File opened successfully.\n");
for (n = 0; n < 100; n++)
if(fputs("test//0=tl;1=tl;2=tl;3=tl;4=tl;5=tl;9=tl;10=tl;11=tl\n", file) == EOF)
fprintf(stderr, "Failed on interation %d error
%s\n ", n, strerror(errno));
if (fclose(file) == 0) {
printf("File closed successfully.\n");
} else {
printf("Error closing file!\n");
}
}When the buffer overflow happens the newline will not be there. I have added this error via rdt_last_cmd_puts. At least user knows there is an error.
(quoted diff) +0 -0
b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 484d6009869f..70a96976e3ab 100644
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
@@ -1250,8 +1252,10 @@ static ssize_t
resctrl_mbm_assign_control_write(struct kernfs_open_file *of,
int ret;
/* Valid input requires a trailing newline */
- if (nbytes == 0 || buf[nbytes - 1] != '\n')
+ if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+ rdt_last_cmd_puts("mbm_cntr_assign: buffer invalid\n");
return -EINVAL;+ }
buf[nbytes - 1] = '\0';
I am open to other ideas to handle this case.
Quoted 23 lines
Quoted 4 lines
All these file operations go thru generic call
kernfs_fop_write_iter(). Doesn't it take care of buffer check and overflow?No, this is called for each iovec segment (where userspace used one of the iovec based I/O syscalls). But there is no buffering or concatenation of the data read in: each segment gets passed down to the individual
kernfs_file_operationswrite method for the file:len = ops->write(of, buf, len, iocb->ki_pos)calls down to
resctrl_mbm_assign_control_write(of, buf, len, iocb->ki_pos).I'll try to port my buffering hack on top of the series -- that should help to illustrate what I mean.
Cheers
---Dave
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi,
Quoted 1 line · Babu
Hi Dave,
[...]
Quoted 26 lines
Created the problem using this code using a "test" group.
include <
stdio.h>
#include <errno.h>
#include <string.h>int
main(){ FILE *file; int n; file = fopen("/sys/fs/resctrl/info/L3_MON/mbm_assign_control", "w"); if (file == NULL) { printf("Error opening file!\n"); return 1; } printf("File opened successfully.\n"); for (n = 0; n < 100; n++) if(
fputs("test//0=tl;1=tl;2=tl;3=tl;4=tl;5=tl;9=tl;10=tl;11=tl\n", file)== EOF)
fprintf(stderr, "Failed on interation %d error
%s\n ", n, strerror(errno));
Quoted 6 lines
if (fclose(file) == 0) {
printf("File closed successfully.\n");
} else {
printf("Error closing file!\n");
}
}Right.
Quoted 23 lines
When the buffer overflow happens the newline will not be there. I have added this error via
rdt_last_cmd_puts. At least user knows there is an error.arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-1@@ -1250,8 +1252,10 @@ static ssize_t resctrl_mbm_assign_control_write(struct kernfs_open_file *of, int ret;/* Valid input requires a trailing newline */ -if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) +if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) { +rdt_last_cmd_puts ("mbm_cntr_assign: buffer invalid\n" );return -EINVAL ; + } buf[nbytes -1 ] ='\0' ;
Quoted 1 line
I am open to other ideas to handle this case.
Reinette, what do you think about this as a stopgap approach?
The worst that happens is that userspace gets an unexpected failure in scenarios that seem unlikely in the near future (i.e., where there are a lot of RMIDs available, and at the same time groups have been given stupidly long names).
Since this is an implementation issue rather than an interface issue, we could fix it later on.
Longer term, we may want to define some stuff along the lines of
struct rdtgroup_file {
/* persistent data for an rdtgroup open file instance */
};
static int rdtgroup_file_open(struct kernfs_open_file *of)
{
struct rdtgroup_file *rf;
rf = kzalloc(sizeof(*rf), GFP_KERNEL);
if (!rf)
return -ENOMEM;
of->priv;
}
static void rdtgroup_file_release(struct kernfs_open_file *of)
{
/*
* Deal with dangling data and do cleanup appropriate
* for whatever kind of file this is, then:
*/
kfree(of->priv);
}Then we'd have somewhere to stash data that needs to be carried over from one read/write call to the next.
I tried to port my schemata buffering hack over, but the requirements are not exactly the same as for mbm_assign_control, so it wasn't trivial. It feels do-able, but it might be better to stabilise this series before going down that road.
(I'm happy to spend some time trying to wire this up if it would be useful, though.)
Cheers
---Dave
Reinette Chatre
maintainerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi Dave,
Quoted 61 lines · Dave Martin
Hi,
Quoted 1 line · Babu
Hi Dave,
[...]
Quoted 26 lines
Created the problem using this code using a "test" group.
include <
stdio.h>
#include <errno.h>
#include <string.h>int
main(){ FILE *file; int n; file = fopen("/sys/fs/resctrl/info/L3_MON/mbm_assign_control", "w"); if (file == NULL) { printf("Error opening file!\n"); return 1; } printf("File opened successfully.\n"); for (n = 0; n < 100; n++) if(
fputs("test//0=tl;1=tl;2=tl;3=tl;4=tl;5=tl;9=tl;10=tl;11=tl\n", file)== EOF)
fprintf(stderr, "Failed on interation %d error
%s\n ", n, strerror(errno));Quoted 6 lines
if (fclose(file) == 0) { printf("File closed successfully.\n"); } else { printf("Error closing file!\n"); } }Right.
Quoted 19 lines
When the buffer overflow happens the newline will not be there. I have added this error via
rdt_last_cmd_puts. At least user knows there is an error.arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-1@@ -1250,8 +1252,10 @@ static ssize_t resctrl_mbm_assign_control_write(struct kernfs_open_file *of, int ret;/* Valid input requires a trailing newline */ -if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) +if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) { +rdt_last_cmd_puts ("mbm_cntr_assign: buffer invalid\n" );return -EINVAL ; + }
Quoted 7 lines
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0buf[nbytes -1 ] ='\0' ;I am open to other ideas to handle this case.
Reinette, what do you think about this as a stopgap approach?
This seems fair. I expect that we need to document somewhere that writes "may" (to leave wiggle room for improvements) require page sized writes.
Quoted 37 lines
The worst that happens is that userspace gets an unexpected failure in scenarios that seem unlikely in the near future (i.e., where there are a lot of RMIDs available, and at the same time groups have been given stupidly long names).
Since this is an implementation issue rather than an interface issue, we could fix it later on.
Longer term, we may want to define some stuff along the lines of
struct rdtgroup_file { /* persistent data for an rdtgroup open file instance */ }; static int rdtgroup_file_open(struct kernfs_open_file *of) { struct rdtgroup_file *rf; rf = kzalloc(sizeof(*rf), GFP_KERNEL); if (!rf) return -ENOMEM; of->priv; } static void rdtgroup_file_release(struct kernfs_open_file *of) { /* * Deal with dangling data and do cleanup appropriate * for whatever kind of file this is, then: */ kfree(of->priv); }
Quoted 2 lines
Then we'd have somewhere to stash data that needs to be carried over from one read/write call to the next.
Something like this seems needed for reading from this file.
Quoted 8 lines
I tried to port my schemata buffering hack over, but the requirements are not exactly the same as for
mbm_assign_control, so it wasn't trivial. It feels do-able, but it might be better to stabilise this series before going down that road.(I'm happy to spend some time trying to wire this up if it would be useful, though.)
I was hoping that we would not need to re-invent something here. This does not seem like a new problem.
Reinette
James Morse
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
In reply to Babu MogerHi Babu,
Quoted 155 lines · Babu Moger
When
mbm_cntr_assignmode is enabled, users can designate which of the MBM events in theCTRL_MONor MON groups should have counters assigned.Provide an interface for assigning MBM events by writing to the file:
/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MONgroup>/<MON group>/<domain_id><opcode><flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:"//<domain_id><opcode><flags>"* Non-default
CTRL_MONgroup:"<CTRL_MON group>//<domain_id><opcode><flags>"* Child MON group of default
CTRL_MONgroup:"/<MON group>/<domain_id><opcode><flags>"* Child MON group of non-default
CTRL_MONgroup:"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Domain_id'*' will apply the flags on all the domains.Opcode can be one of the following:
= Update the assignment to match the flags
+ Assign a new MBM event without impacting existing assignments.
- Unassign a MBM event from currently assigned events.Assignment flags can be one of the following:
t MBM total event
l MBM local event
tl Both total and local MBM events
_ None of the MBM events. Valid only with '=' opcode. This flag cannot
be combined with other flags.arch/x86/kernel/cpu/resctrl/rdtgroup.c +107
-0@@ -1050,6 +1050,244 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, +static int resctrl_process_flags (struct rdt_resource *r, +enum rdt_group_type rtype, +char *p_grp,char *c_grp,char *tok) +{ +unsigned int op, mon_state, assign_state, unassign_state; +char *dom_str, *id_str, *op_str; +struct rdt_mon_domain *d; +unsigned long dom_id =0 ; +struct rdtgroup *rdtgrp; +char domain[10 ]; +bool found; +int ret; + + rdtgrp =rdtgroup_find_grp_by_name (rtype, p_grp, c_grp); + +if (!rdtgrp) { +rdt_last_cmd_puts ("Not a valid resctrl group\n" ); +return -EINVAL ; + } + +next: +if (!tok || tok[0 ] =='\0' ) +return 0 ; + +/* Start processing the strings for each domain */ + dom_str =strim (strsep (&tok,";" )); + + op_str =strpbrk (dom_str,"=+-" ); + +if (op_str) { + op = *op_str; + }else { +rdt_last_cmd_puts ("Missing operation =, +, - character\n" ); +return -EINVAL ; + } + + id_str =strsep (&dom_str,"=+-" ); + +/* Check for domain id '*' which means all domains */ +if (id_str && *id_str =='*' ) { + d =NULL ; + goto check_state; + }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 */ + found = false; +list_for_each_entry (d, &r->mon_domains, hdr.list) { +if (d->hdr.id == dom_id) { + found = true; +break ; + } + } + +if (!found) { +rdt_last_cmd_printf ("Invalid domain id %ld\n" , dom_id); +return -EINVAL ; + } + +check_state: + mon_state =resctrl_str_to_mon_state (dom_str); + +if (mon_state ==ASSIGN_INVALID ) { +rdt_last_cmd_puts ("Invalid assign flag\n" ); + goto out_fail; + } + + assign_state =0 ; + unassign_state =0 ; + +switch (op) { +case '+' : +if (mon_state ==ASSIGN_NONE ) { +rdt_last_cmd_puts ("Invalid assign opcode\n" ); + goto out_fail; + } + assign_state = mon_state; +break ; +case '-' : +if (mon_state ==ASSIGN_NONE ) { +rdt_last_cmd_puts ("Invalid assign opcode\n" ); + goto out_fail; + } + unassign_state = mon_state; +break ; +case '=' : + assign_state = mon_state; + unassign_state = (ASSIGN_TOTAL |ASSIGN_LOCAL ) & ~assign_state; +break ; +default : +break ; + } +if (unassign_state &ASSIGN_TOTAL ) { + ret =resctrl_unassign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); +if (ret) + goto out_fail; + } + +if (unassign_state &ASSIGN_LOCAL ) { + ret =resctrl_unassign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +if (ret) + goto out_fail; + } + +if (assign_state &ASSIGN_TOTAL ) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, · line 1169
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ ret =resctrl_assign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); +if (ret) + goto out_fail; + } + +if (assign_state &ASSIGN_LOCAL ) { + ret =resctrl_assign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +if (ret) + goto out_fail; + }
This sequence of if's allows the helpers to be called on platforms that doesn't support both local and total. Could we reject such misconfiguration here in the parsing code? You have these checks in rdtgroup_assign_cntrs() added in patch 17.
What do you think to trying to group these four by event type, and passing the event type in as an argument? ... it ends up with a helper that takes a large number of arguments, (both assign_state and unassign_state), but there is less repetition...
Thanks,
James
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11
-0+ goto next; + +out_fail: +sprintf (domain, d ?"%ld" :"*" , dom_id); + +rdt_last_cmd_printf ("Assign operation '%s%c%s' failed on the group %s/%s/\n" , + domain, op, dom_str, p_grp, c_grp); + +return -EINVAL ; +} +
Moger, Babu
reviewerRe: [PATCH v11 23/23] x86/resctrl: Introduce interface to modify assignment states of the groups
Hi James,
Quoted 164 lines · James Morse
Hi Babu,
Quoted 161 lines · Babu Moger
When
mbm_cntr_assignmode is enabled, users can designate which of the MBM events in theCTRL_MONor MON groups should have counters assigned.Provide an interface for assigning MBM events by writing to the file:
/sys/fs/resctrl/info/L3_MON/mbm_assign_control. Using this interface, events can be assigned or unassigned as needed.Format is similar to the list format with addition of opcode for the assignment operation.
"<CTRL_MONgroup>/<MON group>/<domain_id><opcode><flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:"//<domain_id><opcode><flags>"* Non-default
CTRL_MONgroup:"<CTRL_MON group>//<domain_id><opcode><flags>"* Child MON group of default
CTRL_MONgroup:"/<MON group>/<domain_id><opcode><flags>"* Child MON group of non-default
CTRL_MONgroup:"<CTRL_MON group>/<MON group>/<domain_id><opcode><flags>"
Domain_id'*' will apply the flags on all the domains.Opcode can be one of the following:
= Update the assignment to match the flags
+ Assign a new MBM event without impacting existing assignments.
- Unassign a MBM event from currently assigned events.Assignment flags can be one of the following:
t MBM total event
l MBM local event
tl Both total and local MBM events
_ None of the MBM events. Valid only with '=' opcode. This flag cannot
be combined with other flags.arch/x86/kernel/cpu/resctrl/rdtgroup.c +113
-0@@ -1050,6 +1050,244 @@ static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, +static int resctrl_process_flags (struct rdt_resource *r, +enum rdt_group_type rtype, +char *p_grp,char *c_grp,char *tok) +{ +unsigned int op, mon_state, assign_state, unassign_state; +char *dom_str, *id_str, *op_str; +struct rdt_mon_domain *d; +unsigned long dom_id =0 ; +struct rdtgroup *rdtgrp; +char domain[10 ]; +bool found; +int ret; + + rdtgrp =rdtgroup_find_grp_by_name (rtype, p_grp, c_grp); + +if (!rdtgrp) { +rdt_last_cmd_puts ("Not a valid resctrl group\n" ); +return -EINVAL ; + } + +next: +if (!tok || tok[0 ] =='\0' ) +return 0 ; + +/* Start processing the strings for each domain */ + dom_str =strim (strsep (&tok,";" )); + + op_str =strpbrk (dom_str,"=+-" ); + +if (op_str) { + op = *op_str; + }else { +rdt_last_cmd_puts ("Missing operation =, +, - character\n" ); +return -EINVAL ; + } + + id_str =strsep (&dom_str,"=+-" ); + +/* Check for domain id '*' which means all domains */ +if (id_str && *id_str =='*' ) { + d =NULL ; + goto check_state; + }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 */ + found = false; +list_for_each_entry (d, &r->mon_domains, hdr.list) { +if (d->hdr.id == dom_id) { + found = true; +break ; + } + } + +if (!found) { +rdt_last_cmd_printf ("Invalid domain id %ld\n" , dom_id); +return -EINVAL ; + } + +check_state: + mon_state =resctrl_str_to_mon_state (dom_str); + +if (mon_state ==ASSIGN_INVALID ) { +rdt_last_cmd_puts ("Invalid assign flag\n" ); + goto out_fail; + } + + assign_state =0 ; + unassign_state =0 ; + +switch (op) { +case '+' : +if (mon_state ==ASSIGN_NONE ) { +rdt_last_cmd_puts ("Invalid assign opcode\n" ); + goto out_fail; + } + assign_state = mon_state; +break ; +case '-' : +if (mon_state ==ASSIGN_NONE ) { +rdt_last_cmd_puts ("Invalid assign opcode\n" ); + goto out_fail; + } + unassign_state = mon_state; +break ; +case '=' : + assign_state = mon_state; + unassign_state = (ASSIGN_TOTAL |ASSIGN_LOCAL ) & ~assign_state; +break ; +default : +break ; + } +if (unassign_state &ASSIGN_TOTAL ) { + ret =resctrl_unassign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); +if (ret) + goto out_fail; + } + +if (unassign_state &ASSIGN_LOCAL ) { + ret =resctrl_unassign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +if (ret) + goto out_fail; + } + +if (assign_state &ASSIGN_TOTAL ) { + ret =resctrl_assign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_TOTAL_EVENT_ID ); +if (ret) + goto out_fail; + } + +if (assign_state &ASSIGN_LOCAL ) {
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int resctrl_mbm_assign_control_show(struct kernfs_open_file *of, · line 1221
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0+ ret =resctrl_assign_cntr_event (r, d, rdtgrp,QOS_L3_MBM_LOCAL_EVENT_ID ); +if (ret) + goto out_fail; + }This sequence of if's allows the helpers to be called on platforms that doesn't support both local and total. Could we reject such misconfiguration here in the parsing code? You have these checks in
rdtgroup_assign_cntrs()added in patch 17.
Yes. Added the check is_mbm_total_enabled() and is_mbm_local_enabled().
Quoted 4 lines
What do you think to trying to group these four by event type, and passing the event type in as an argument? ... it ends up with a helper that takes a large number of arguments, (both
assign_stateandunassign_state), but there is less repetition...
Added a new helper function resctrl_process_cntr_event(). I could not avoid the repetitions.
Quoted 18 lines
Thanks,
James
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11
-0+ goto next; + +out_fail: +sprintf (domain, d ?"%ld" :"*" , dom_id); + +rdt_last_cmd_printf ("Assign operation '%s%c%s' failed on the group %s/%s/\n" , + domain, op, dom_str, p_grp, c_grp); + +return -EINVAL ; +} +
Signature · 2 lines
Thanks Babu Moger
Hi Babu,
Quoted 41 lines · Babu Moger
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 atThe patches are based on top of commit
d361b84d51bfe(tip/master) Merge branch into tip/master: 'x86/tdx'# Introduction
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 for certain point of time. Users do not have the option to monitor a group or set of groups for certain period of time without worrying about counter being reset in between.
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually. There is no need to worry about counters being reset during this period. Additionally, the user can specify a bitmask identifying the specific bandwidth types from the given source to track with the counter.
Without ABMC enabled, monitoring will work in current 'default' mode without assignment option.
Quoted 6 lines
# Linux Implementation
Create a generic interface aimed 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.
As a reminder of the work related to this, please take a look at the thread where Reinette proposed a "shared counters" mode in mbm_assign_control[1]. I am currently working to demonstrate that this combined with the mbm_*_bytes_per_second events discussed earlier in the same thread will address my users' concerns about the overhead of reading a large number of MBM counters, resulting from a maximal number of monitoring groups whose jobs are not isolated to any L3 monitoring domain.
ABMC will add to the number of registers which need to be programmed in each domain, so I will need to demonstrate that ABMC combined with these additional features addresses their performance concerns and that the resulting interface is user-friendly enough that they will not need a detailed understanding of the implementation to avoid an unacceptable performance degradation (i.e., needing to understand what conditions will increase the number of IPIs required).
If all goes well, soft-ABMC will try to extend this usage model to the existing, pre-ABMC, AMD platforms I support.
Thanks,
-Peter
Moger, Babu
reviewerHi Peter,
Quoted 68 lines · Peter Newman
Hi Babu,
Quoted 41 lines · Babu Moger
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 atThe patches are based on top of commit
d361b84d51bfe(tip/master) Merge branch into tip/master: 'x86/tdx'# Introduction
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 for certain point of time. Users do not have the option to monitor a group or set of groups for certain period of time without worrying about counter being reset in between.
The ABMC feature provides an option to the user to assign a hardware counter to an RMID, event pair and monitor the bandwidth as long as it is assigned. The assigned RMID will be tracked by the hardware until the user unassigns it manually. There is no need to worry about counters being reset during this period. Additionally, the user can specify a bitmask identifying the specific bandwidth types from the given source to track with the counter.
Without ABMC enabled, monitoring will work in current 'default' mode without assignment option.
Quoted 6 lines
# Linux Implementation
Create a generic interface aimed 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.
As a reminder of the work related to this, please take a look at the thread where Reinette proposed a "shared counters" mode in mbm_assign_control[1]. I am currently working to demonstrate that this combined with the mbm_*_bytes_per_second events discussed earlier in the same thread will address my users' concerns about the overhead of reading a large number of MBM counters, resulting from a maximal number of monitoring groups whose jobs are not isolated to any L3 monitoring domain.
ABMC will add to the number of registers which need to be programmed in each domain, so I will need to demonstrate that ABMC combined with these additional features addresses their performance concerns and that the resulting interface is user-friendly enough that they will not need a detailed understanding of the implementation to avoid an unacceptable performance degradation (i.e., needing to understand what conditions will increase the number of IPIs required).
Quoted 8 lines
If all goes well, soft-ABMC will try to extend this usage model to the existing, pre-ABMC, AMD platforms I support.
Thanks,
-Peter
Thanks for the heads-up. I understand what's going on and have an idea of the plan. Please keep us updated on the progress. Also, if any changes are needed in this series to meet your requirements, feel free to share your feedback.
Signature · 2 lines
Thanks Babu Moger
Dave Martin
reviewerQuoted 3 lines · Babu
Hi Peter,
On 2/3/25 08:54, Peter Newman wrote:
[...]
Quoted 30 lines
Quoted 30 lines
Quoted 6 lines
# Linux Implementation
Create a generic interface aimed 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.
As a reminder of the work related to this, please take a look at the thread where Reinette proposed a "shared counters" mode in mbm_assign_control[1]. I am currently working to demonstrate that this combined with the mbm_*_bytes_per_second events discussed earlier in the same thread will address my users' concerns about the overhead of reading a large number of MBM counters, resulting from a maximal number of monitoring groups whose jobs are not isolated to any L3 monitoring domain.
ABMC will add to the number of registers which need to be programmed in each domain, so I will need to demonstrate that ABMC combined with these additional features addresses their performance concerns and that the resulting interface is user-friendly enough that they will not need a detailed understanding of the implementation to avoid an unacceptable performance degradation (i.e., needing to understand what conditions will increase the number of IPIs required).
If all goes well, soft-ABMC will try to extend this usage model to the existing, pre-ABMC, AMD platforms I support.
Thanks,
-Peter
Quoted 7 lines
Quoted 2 lines
Thanks for the heads-up. I understand what's going on and have an idea of the plan. Please keep us updated on the progress. Also, if any changes are needed in this series to meet your requirements, feel free to share your feedback.
Playing devil's advocate, I wonder whether there is a point beyond which it would be better to have an interface to hand over some of the counters to perf?
The logic for round-robin scheduling of events onto counters, dealing with overflows etc. has already been invented over there, and it's fiddly to get right. Ideally resctrl wouldn't have its own special implementation of that kind of stuff.
(Said my someone who has never tried to hack up an uncore event source in perf.)
Cheers
---Dave
Luck, Tony
maintainerQuoted 11 lines
Playing devil's advocate, I wonder whether there is a point beyond which it would be better to have an interface to hand over some of the counters to perf?
The logic for round-robin scheduling of events onto counters, dealing with overflows etc. has already been invented over there, and it's fiddly to get right. Ideally resctrl wouldn't have its own special implementation of that kind of stuff.
(Said my someone who has never tried to hack up an uncore event source in perf.)
Initial implementation on Intel RDT tried to use perf ... it all went badly and was reverted.
There are some very un-perf-like properties that we couldn't find a workaround for at the time.
E.g.
1) Cache occupancy counters. These change even when your workload isn't running (downward due to evictions).
2) Counters based on RMIDs show the aggregated values from multiple CPUs as tasks are scheduled on cores.
But maybe you meant "don't let resctrl use all those counters" ... hand some of them to perf to use in some other way?
-Tony
Dave Martin
reviewerHi there,
Quoted 17 lines · Babu Moger
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 atThe patches are based on top of commit
d361b84d51bfe(tip/master) Merge branch into tip/master: 'x86/tdx'# Introduction
[...]
Quoted 8 lines
# Examples
a. Check if ABMC support is available
#mount -t resctrl resctrl/sys/fs/resctrl/# cat
/sys/fs/resctrl/info/L3_MON/mbm_assign_mode[mbm_cntr_assign]
default
(Nit: can this be called "mbm_counter_assign"? The name is already long, so I wonder whether anything is gained by using a cryptic abbreviation for "counter". Same with all the "cntrs" elsewhere. This is purely cosmetic, though -- the interface works either way.)
Quoted 6 lines
ABMC feature is detected and it is enabled.
b. Check how many ABMC counters are available.
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32
Is this file needed?
With MPAM, it is more difficult to promise that the same number of counters will be available everywhere.
Rather than lie, or report a "safe" value here that may waste some counters, can we just allow the number of counters to be be discovered per domain via available_mbm_cntrs?
num_closids and num_rmids are already problematic for MPAM, so it would be good to avoid any more parameters of this sort from being reported to userspace unless there is a clear understanding of why they are needed.
Reporting number of counters per monitoring domain is a more natural fit for MPAM, as below:
Quoted 4 lines
c. Check how many ABMC counters are available in each domain.
# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=30;1=30
For MPAM, this seems supportable. Each monitoring domain will have some counters, and a well-defined number of them will be available for allocation at any one time.
Quoted 20 lines
d. Create few resctrl groups.
# mkdir /sys/fs/resctrl/mon_groups/child_default_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp/mon_groups/child_non_default_mon_grpe. This series adds a new interface file
/sys/fs/resctrl/info/L3_MON/mbm_assign_control
to list and modify any group's monitoring states. File provides single place to list monitoring states of all the resctrl groups. It makes it easier for user space to learn about the used counters without needing to traverse all the groups thus reducing the number of file system calls.The list follows the following format:
"<
CTRL_MONgroup>/<MON group>/<domain_id>=<flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:
"//<domain_id>=<flags>"
[...]
Quoted 8 lines
Flags can be one of the following:
t MBM total event is enabled.
l MBM local event is enabled.
tl Both total and local MBM events are enabled. _ None of the MBM events are enabledExamples:
[...]
I think that this basically works for MPAM.
The local/total distinction doesn't map in a consistent way onto MPAM, but this problem is not specific to ABMC. It feels sensible for ABMC to be built around the same concepts that resctrl already has elsewhere in the interface. MPAM will do its best to fit (as already).
Regarding Peter's use case of assiging multiple counters to a monitoring group [1], I feel that it's probably good enough to make sure that the ABMC interface can be extended in future in a backwards compatible way so as to support this, without trying to support it immediately.
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
For example, if we added new generic "letters" -- say, "0" to "9", combined with new counter files in resctrlfs, that feels like a possible approach. ABMC (as in this series) should just reject such such assignments, and the new counter files wouldn't exist.
Availability of this feature could also be reported as a distinct mode in mbm_assign_mode, say "mbm_cntr_generic", or whatever.
A _sketch_ of this follows. This is NOT a proposal -- the key question is whether we are confident that we can extend the interface in this way in the future without breaking anything.
If "yes", then the ABMC interface (as proposed by this series) works as a foundation to build on.
--8<--
[artists's impression]
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode mbm_cntr_generic [mbm_cntr_assign] default
# echo mbm_cntr_generic >/sys/fs/resctrl/info/L3_MON/mbm_assign_mode # echo '//0=01;1=23' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter0_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter1_bytes_type # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter2_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter3_bytes_type
...
# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_counter1_bytes
etc.
-->8--
Any thoughts on this, Peter?
[...]
Cheers
---Dave
Reinette Chatre
maintainerHi Dave,
Quoted 44 lines · Dave Martin
Hi there,
Quoted 17 lines · Babu Moger
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 atThe patches are based on top of commit
d361b84d51bfe(tip/master) Merge branch into tip/master: 'x86/tdx'# Introduction
[...]
Quoted 8 lines
# Examples
a. Check if ABMC support is available
#mount -t resctrl resctrl/sys/fs/resctrl/# cat
/sys/fs/resctrl/info/L3_MON/mbm_assign_mode[mbm_cntr_assign]
default(Nit: can this be called "
mbm_counter_assign"? The name is already long, so I wonder whether anything is gained by using a cryptic abbreviation for "counter". Same with all the "cntrs" elsewhere. This is purely cosmetic, though -- the interface works either way.)Quoted 6 lines
ABMC feature is detected and it is enabled.
b. Check how many ABMC counters are available.
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32
Quoted 8 lines
Is this file needed?
With MPAM, it is more difficult to promise that the same number of counters will be available everywhere.
Rather than lie, or report a "safe" value here that may waste some counters, can we just allow the number of counters to be be discovered per domain via
available_mbm_cntrs?
This sounds reasonable to me. I think us having trouble with the user documentation of this file so late in development should also have been a sign to rethink its value.
For a user to discover the number of counters supported via available_mbm_cntrs would require the file's contents to be captured right after mount. Since we've had scenarios where new userspace needs to discover an up-and-running system's configuration this may not be possible. I thus wonder instead of removing num_mbm_cntrs, it could be modified to return the per-domain supported counters instead of a single value?
Quoted 4 lines
num_closidsandnum_rmidsare already problematic for MPAM, so it would be good to avoid any more parameters of this sort from being reported to userspace unless there is a clear understanding of why they are needed.
Yes. Appreciate your help in identifying what could be problematic for MPAM.
Quoted 54 lines
Reporting number of counters per monitoring domain is a more natural fit for MPAM, as below:
Quoted 4 lines
c. Check how many ABMC counters are available in each domain.
# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=30;1=30For MPAM, this seems supportable. Each monitoring domain will have some counters, and a well-defined number of them will be available for allocation at any one time.
Quoted 20 lines
d. Create few resctrl groups.
# mkdir /sys/fs/resctrl/mon_groups/child_default_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp/mon_groups/child_non_default_mon_grpe. This series adds a new interface file
/sys/fs/resctrl/info/L3_MON/mbm_assign_control
to list and modify any group's monitoring states. File provides single place to list monitoring states of all the resctrl groups. It makes it easier for user space to learn about the used counters without needing to traverse all the groups thus reducing the number of file system calls.The list follows the following format:
"<
CTRL_MONgroup>/<MON group>/<domain_id>=<flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:
"//<domain_id>=<flags>"[...]
Quoted 8 lines
Flags can be one of the following:
t MBM total event is enabled.
l MBM local event is enabled.
tl Both total and local MBM events are enabled. _ None of the MBM events are enabledExamples:
[...]
I think that this basically works for MPAM.
The local/total distinction doesn't map in a consistent way onto MPAM, but this problem is not specific to ABMC. It feels sensible for ABMC to be built around the same concepts that resctrl already has elsewhere in the interface. MPAM will do its best to fit (as already).
Quoted 8 lines
Regarding Peter's use case of assiging multiple counters to a monitoring group [1], I feel that it's probably good enough to make sure that the ABMC interface can be extended in future in a backwards compatible way so as to support this, without trying to support it immediately.
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
I do not think that resctrl's current support of the mbm_total_bytes and mbm_local_bytes should be considered as the "only" two available "slots" into which all possible events should be forced into. "mon_features" exists to guide user space to which events are supported and as I see it new events can be listed here to inform user space of their availability, with their associated event files available in the resource groups.
Quoted 33 lines
For example, if we added new generic "letters" -- say, "0" to "9", combined with new counter files in resctrlfs, that feels like a possible approach. ABMC (as in this series) should just reject such such assignments, and the new counter files wouldn't exist.
Availability of this feature could also be reported as a distinct mode in
mbm_assign_mode, say "mbm_cntr_generic", or whatever.A _sketch_ of this follows. This is NOT a proposal -- the key question is whether we are confident that we can extend the interface in this way in the future without breaking anything.
If "yes", then the ABMC interface (as proposed by this series) works as a foundation to build on.
--8<--
[artists's impression]
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode(quoted diff) +0
-0mbm_cntr_generic [mbm_cntr_assign] default# echo mbm_cntr_generic >/sys/fs/resctrl/info/L3_MON/mbm_assign_mode # echo '//0=01;1=23' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter0_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter1_bytes_type # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter2_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter3_bytes_type
Quoted 6 lines
...
# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_counter1_bytesetc.
It is not clear to me what additional features such an interface enables. It also looks like user space will need to track and manage counter IDs?
It sounds to me as though the issue starts with your statement "The local/total distinction doesn't map in a consistent way onto MPAM". To address this I expect that an MPAM system will not support nor list mbm_total_bytes and/or mbm_local_bytes in its mon_features file (*)? Instead, it would list the events that are appropriate to the system? Trying to match with what Peter said [1] in the message you refer to, this may be possible:
# cat /sys/fs/resctrl/info/L3_MON/mon_features mbm_local_read_bytes mbm_local_write_bytes mbm_local_bytes
(*) I am including mbm_local_bytes since it could be an event that can be software defined as a sum of mbm_local_read_bytes and mbm_local_write_bytes when they are both counted.
I see the support for MPAM events distinct from the support of assignable counters. Once the MPAM events are sorted, I think that they can be assigned with existing interface. Please help me understand if you see it differently.
Doing so would need to come up with alphabetical letters for these events, which seems to be needed for your proposal also? If we use possible flags of:
mbm_local_read_bytes ambm_local_write_bytes b
Then mbm_assign_control can be used as:
# echo '//0=ab;1=b' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_read_bytes <value> # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes <sum of mbm_local_read_bytes and mbm_local_write_bytes>
One issue would be when resctrl needs to support more than 26 events (no more flags available), assuming that upper case would be used for "shared" counters (unless this interface is defined differently and only few uppercase letters used for it). Would this be too low of a limit?
Reinette
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
Reinette Chatre
maintainer-Fenghua (his email address does not work anymore)
Quoted 227 lines · Reinette Chatre
Hi Dave,
Quoted 44 lines · Dave Martin
Hi there,
Quoted 17 lines · Babu Moger
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 atThe patches are based on top of commit
d361b84d51bfe(tip/master) Merge branch into tip/master: 'x86/tdx'# Introduction
[...]
Quoted 8 lines
# Examples
a. Check if ABMC support is available
#mount -t resctrl resctrl/sys/fs/resctrl/# cat
/sys/fs/resctrl/info/L3_MON/mbm_assign_mode[mbm_cntr_assign]
default(Nit: can this be called "
mbm_counter_assign"? The name is already long, so I wonder whether anything is gained by using a cryptic abbreviation for "counter". Same with all the "cntrs" elsewhere. This is purely cosmetic, though -- the interface works either way.)Quoted 6 lines
ABMC feature is detected and it is enabled.
b. Check how many ABMC counters are available.
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32Quoted 8 lines
Is this file needed?
With MPAM, it is more difficult to promise that the same number of counters will be available everywhere.
Rather than lie, or report a "safe" value here that may waste some counters, can we just allow the number of counters to be be discovered per domain via
available_mbm_cntrs?This sounds reasonable to me. I think us having trouble with the user documentation of this file so late in development should also have been a sign to rethink its value.
For a user to discover the number of counters supported via
available_mbm_cntrswould require the file's contents to be captured right after mount. Since we've had scenarios where new userspace needs to discover an up-and-running system's configuration this may not be possible. I thus wonder instead of removingnum_mbm_cntrs, it could be modified to return the per-domain supported counters instead of a single value?Quoted 4 lines
num_closidsandnum_rmidsare already problematic for MPAM, so it would be good to avoid any more parameters of this sort from being reported to userspace unless there is a clear understanding of why they are needed.Yes. Appreciate your help in identifying what could be problematic for MPAM.
Quoted 54 lines
Reporting number of counters per monitoring domain is a more natural fit for MPAM, as below:
Quoted 4 lines
c. Check how many ABMC counters are available in each domain.
# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=30;1=30For MPAM, this seems supportable. Each monitoring domain will have some counters, and a well-defined number of them will be available for allocation at any one time.
Quoted 20 lines
d. Create few resctrl groups.
# mkdir /sys/fs/resctrl/mon_groups/child_default_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp # mkdir /sys/fs/resctrl/non_default_ctrl_mon_grp/mon_groups/child_non_default_mon_grpe. This series adds a new interface file
/sys/fs/resctrl/info/L3_MON/mbm_assign_control
to list and modify any group's monitoring states. File provides single place to list monitoring states of all the resctrl groups. It makes it easier for user space to learn about the used counters without needing to traverse all the groups thus reducing the number of file system calls.The list follows the following format:
"<
CTRL_MONgroup>/<MON group>/<domain_id>=<flags>"Format for specific type of groups:
* Default
CTRL_MONgroup:
"//<domain_id>=<flags>"[...]
Quoted 8 lines
Flags can be one of the following:
t MBM total event is enabled.
l MBM local event is enabled.
tl Both total and local MBM events are enabled. _ None of the MBM events are enabledExamples:
[...]
I think that this basically works for MPAM.
The local/total distinction doesn't map in a consistent way onto MPAM, but this problem is not specific to ABMC. It feels sensible for ABMC to be built around the same concepts that resctrl already has elsewhere in the interface. MPAM will do its best to fit (as already).
Quoted 8 lines
Regarding Peter's use case of assiging multiple counters to a monitoring group [1], I feel that it's probably good enough to make sure that the ABMC interface can be extended in future in a backwards compatible way so as to support this, without trying to support it immediately.
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
I do not think that resctrl's current support of the
mbm_total_bytesandmbm_local_bytesshould be considered as the "only" two available "slots" into which all possible events should be forced into. "mon_features" exists to guide user space to which events are supported and as I see it new events can be listed here to inform user space of their availability, with their associated event files available in the resource groups.Quoted 33 lines
For example, if we added new generic "letters" -- say, "0" to "9", combined with new counter files in resctrlfs, that feels like a possible approach. ABMC (as in this series) should just reject such such assignments, and the new counter files wouldn't exist.
Availability of this feature could also be reported as a distinct mode in
mbm_assign_mode, say "mbm_cntr_generic", or whatever.A _sketch_ of this follows. This is NOT a proposal -- the key question is whether we are confident that we can extend the interface in this way in the future without breaking anything.
If "yes", then the ABMC interface (as proposed by this series) works as a foundation to build on.
--8<--
[artists's impression]
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode(quoted diff) +0
-0mbm_cntr_generic [mbm_cntr_assign] default# echo mbm_cntr_generic >/sys/fs/resctrl/info/L3_MON/mbm_assign_mode # echo '//0=01;1=23' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter0_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter1_bytes_type # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter2_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter3_bytes_typeQuoted 6 lines
...
# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_counter1_bytesetc.
It is not clear to me what additional features such an interface enables. It also looks like user space will need to track and manage counter IDs?
It sounds to me as though the issue starts with your statement "The local/total distinction doesn't map in a consistent way onto MPAM". To address this I expect that an MPAM system will not support nor list
mbm_total_bytesand/ormbm_local_bytesin itsmon_featuresfile (*)? Instead, it would list the events that are appropriate to the system? Trying to match with what Peter said [1] in the message you refer to, this may be possible:# cat /sys/fs/resctrl/info/L3_MON/mon_features mbm_local_read_bytes mbm_local_write_bytes mbm_local_bytes(*) I am including
mbm_local_bytessince it could be an event that can be software defined as a sum ofmbm_local_read_bytesandmbm_local_write_byteswhen they are both counted.I see the support for MPAM events distinct from the support of assignable counters. Once the MPAM events are sorted, I think that they can be assigned with existing interface. Please help me understand if you see it differently.
Doing so would need to come up with alphabetical letters for these events, which seems to be needed for your proposal also? If we use possible flags of:
mbm_local_read_bytesambm_local_write_bytesbThen
mbm_assign_controlcan be used as:# echo '//0=ab;1=b' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_read_bytes <value> # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes <sum of mbm_local_read_bytes and mbm_local_write_bytes>One issue would be when resctrl needs to support more than 26 events (no more flags available), assuming that upper case would be used for "shared" counters (unless this interface is defined differently and only few uppercase letters used for it). Would this be too low of a limit?
Reinette
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
Luck, Tony
maintainerQuoted 6 lines
I do not think that resctrl's current support of the
mbm_total_bytesandmbm_local_bytesshould be considered as the "only" two available "slots" into which all possible events should be forced into. "mon_features" exists to guide user space to which events are supported and as I see it new events can be listed here to inform user space of their availability, with their associated event files available in the resource groups.
100% I have a number of "events" in the pipeline that do not fit these names. I'm planning on new files with descriptive[1] names for the events they report.
-Tony
[1] When these are ready to post we can discuss the names I chose and change them if there are better names that work across architectures.
Dave Martin
reviewerHi Tony,
Quoted 7 lines · Tony
Quoted 6 lines
I do not think that resctrl's current support of the
mbm_total_bytesandmbm_local_bytesshould be considered as the "only" two available "slots" into which all possible events should be forced into. "mon_features" exists to guide user space to which events are supported and as I see it new events can be listed here to inform user space of their availability, with their associated event files available in the resource groups.
Quoted 8 lines
100% I have a number of "events" in the pipeline that do not fit these names. I'm planning on new files with descriptive[1] names for the events they report.
-Tony
[1] When these are ready to post we can discuss the names I chose and change them if there are better names that work across architectures.
Do any of the approaches discussed in [2] look viable for this?
(Ideally, reply over there.)
Cheers
---Dave
Dave Martin
reviewerHi Reinette,
Quoted 21 lines · Reinette Chatre
Hi Dave,
Quoted 18 lines · Dave Martin
Hi there,
Quoted 15 lines · Babu Moger
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 atThe patches are based on top of commit
d361b84d51bfe(tip/master) Merge branch into tip/master: 'x86/tdx'
[...]
Quoted 18 lines
Quoted 5 lines
Quoted 4 lines
b. Check how many ABMC counters are available.
# cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 32Quoted 8 lines
Is this file needed?
With MPAM, it is more difficult to promise that the same number of counters will be available everywhere.
Rather than lie, or report a "safe" value here that may waste some counters, can we just allow the number of counters to be be discovered per domain via
available_mbm_cntrs?This sounds reasonable to me. I think us having trouble with the user documentation of this file so late in development should also have been a sign to rethink its value.
Quoted 6 lines
For a user to discover the number of counters supported via
available_mbm_cntrswould require the file's contents to be captured right after mount. Since we've had scenarios where new userspace needs to discover an up-and-running system's configuration this may not be possible. I thus wonder instead of removingnum_mbm_cntrs, it could be modified to return the per-domain supported counters instead of a single value?
Is it actually useful to be able to discover the number of counters that exist? A counter that exists but is not available cannot be used, so perhaps it is not useful to know about it in the first place.
But if we keep this file but make it report the number of counters for each domain (similarly to mbm_available_cntrs), then I think the MPAM driver should be able to work with that.
Quoted 6 lines
Quoted 4 lines
num_closidsandnum_rmidsare already problematic for MPAM, so it would be good to avoid any more parameters of this sort from being reported to userspace unless there is a clear understanding of why they are needed.Yes. Appreciate your help in identifying what could be problematic for MPAM.
For clarity: this is a background issue, mostly orthogonal to this series.
If this series is merged as-is, with a global per-resource num_mbm_cntrs property, then this not really worse than the current situation -- it's just a bit annoying from the MPAM perspective.
In a nutshell, the num_closids / num_rmids parameters seem to expose RDT-specific hardware semantics to userspace, implying a specific allocation model for control group and monitoring group identifiers.
The guarantees that userspace is entitled to asssume when resctrl reports particular values do not seem to be well described and are hard to map onto the nearest-equivalent MPAM implementation. A combination of control and monitoring groups that can be created on x86 may not be creatable on MPAM, even when the number of supportable control and monitoring partitions is the same.
Even with the ABMC series, we may still be constrained on what we can report for num_rmids: we can't know in advance whether or not the user is going to use mbm_cntr_assign mode -- if not, we can't promise to create more monitoring groups than the number of counters in the hardware.
It seems natural for the counts reported by "available_mbm_cntrs" to change dynamically when the ABMC assignment mode is changed, but I think userspace are likely to expect the global "num_rmids" parameters to be fixed for the lifetime of the resctrl mount (and possibly fixed for all time on a given hardware platform -- at least, modulo CDP).
I think it might be possible to tighten up the docmentation of num_closids in particular in a way that doesn't conflict with x86 and may make it easier for MPAM to fit in with, but that feels like a separate conversation.
None of this should be considered a blocker for this series, either way.
Quoted 12 lines
Quoted 12 lines
Reporting number of counters per monitoring domain is a more natural fit for MPAM, as below:
Quoted 4 lines
c. Check how many ABMC counters are available in each domain.
# cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=30;1=30For MPAM, this seems supportable. Each monitoring domain will have some counters, and a well-defined number of them will be available for allocation at any one time.
[...]
Quoted 1 line
Quoted 1 line
Quoted 1 line
e. This series adds a new interface file
/sys/fs/resctrl/info/L3_MON/mbm_assign_control
[...]
Quoted 27 lines
Quoted 18 lines
Quoted 8 lines
Flags can be one of the following:
t MBM total event is enabled.
l MBM local event is enabled.
tl Both total and local MBM events are enabled. _ None of the MBM events are enabledExamples:
[...]
I think that this basically works for MPAM.
The local/total distinction doesn't map in a consistent way onto MPAM, but this problem is not specific to ABMC. It feels sensible for ABMC to be built around the same concepts that resctrl already has elsewhere in the interface. MPAM will do its best to fit (as already).
Quoted 8 lines
Regarding Peter's use case of assiging multiple counters to a monitoring group [1], I feel that it's probably good enough to make sure that the ABMC interface can be extended in future in a backwards compatible way so as to support this, without trying to support it immediately.
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
Quoted 6 lines
I do not think that resctrl's current support of the
mbm_total_bytesandmbm_local_bytesshould be considered as the "only" two available "slots" into which all possible events should be forced into. "mon_features" exists to guide user space to which events are supported and as I see it new events can be listed here to inform user space of their availability, with their associated event files available in the resource groups.
That's fair. I wasn't currently sure how (or if) the set of countable events was expected to grow / evolve via this route.
Either way, I think this confirms that there is at least one viable way to enable more counters for a single control group, on top of this series.
(If there is more than one way, that seems fine?)
Quoted 35 lines
Quoted 35 lines
For example, if we added new generic "letters" -- say, "0" to "9", combined with new counter files in resctrlfs, that feels like a possible approach. ABMC (as in this series) should just reject such such assignments, and the new counter files wouldn't exist.
Availability of this feature could also be reported as a distinct mode in
mbm_assign_mode, say "mbm_cntr_generic", or whatever.A _sketch_ of this follows. This is NOT a proposal -- the key question is whether we are confident that we can extend the interface in this way in the future without breaking anything.
If "yes", then the ABMC interface (as proposed by this series) works as a foundation to build on.
--8<--
[artists's impression]
# cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode(quoted diff) +0
-0mbm_cntr_generic [mbm_cntr_assign] default# echo mbm_cntr_generic >/sys/fs/resctrl/info/L3_MON/mbm_assign_mode # echo '//0=01;1=23' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter0_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter1_bytes_type # echo t >/sys/fs/resctrl/info/L3_MON/mbm_counter2_bytes_type # echo l >/sys/fs/resctrl/info/L3_MON/mbm_counter3_bytes_type...
Quoted 7 lines
Quoted 4 lines
# cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_counter1_bytesetc.
It is not clear to me what additional features such an interface enables. It also looks like user space will need to track and manage counter IDs?
My idea was that for these generic counters, new files could be exposed to configure what they actually count (the ..._type files shown above; or possibly via the ..._config files that already exist).
The "IDs" were inteded as abstract; the number only relates the assignments in mbm_assign_control to the files created elsewhere. This wouldn't be related to IDs assigned by the hardware.
If there are multiple resctrl users then using numeric IDs might be problematic; though if we go eventually in the direction of making resctrlfs multi-mountable then each mount could have its own namespace.
Allowing counters to be named and configured with a mkdir()-style interface might be possible too; that might make it easier for users to coexist within a single resctrl mount (if we think that's important enough).
Quoted 33 lines
It sounds to me as though the issue starts with your statement "The local/total distinction doesn't map in a consistent way onto MPAM". To address this I expect that an MPAM system will not support nor list
mbm_total_bytesand/ormbm_local_bytesin itsmon_featuresfile (*)? Instead, it would list the events that are appropriate to the system? Trying to match with what Peter said [1] in the message you refer to, this may be possible:# cat /sys/fs/resctrl/info/L3_MON/mon_features mbm_local_read_bytes mbm_local_write_bytes mbm_local_bytes(*) I am including
mbm_local_bytessince it could be an event that can be software defined as a sum ofmbm_local_read_bytesandmbm_local_write_byteswhen they are both counted.I see the support for MPAM events distinct from the support of assignable counters. Once the MPAM events are sorted, I think that they can be assigned with existing interface. Please help me understand if you see it differently.
Doing so would need to come up with alphabetical letters for these events, which seems to be needed for your proposal also? If we use possible flags of:
mbm_local_read_bytesambm_local_write_bytesbThen
mbm_assign_controlcan be used as:# echo '//0=ab;1=b' >/sys/fs/resctrl/info/L3_MON/mbm_assign_control # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_read_bytes <value> # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes <sum of mbm_local_read_bytes and mbm_local_write_bytes>
Quoted 7 lines
One issue would be when resctrl needs to support more than 26 events (no more flags available), assuming that upper case would be used for "shared" counters (unless this interface is defined differently and only few uppercase letters used for it). Would this be too low of a limit?
Reinette
[1] https://lore.kernel.org/lkml/CALPaoCjY-3f2tWvBjuaQPfoPhxveWxxCxHqQMn4BEaeBXBa0bA@mail.gmail.com/
That approach would also work, where an MPAM system has events are not a reasonable approximation of the generic "total" or "local".
For now we would probably stick with "total" and "local" anyway though, because the MPAM architecture doesn't natively allow the mapping onto the memory system topology to be discovered, and the information in ACPI / device tree is insufficient to tell us everything we'd need to know. But I guess what counts as "local" in particular will be quite hardware and topology dependent even on x86, so perhaps we shouldn't worry about having the behaviour match exactly (?)
Regarding the code letters, my idea was that the event type might be configured by a separate file, instead of in mbm_assign_control directly, in which case running out of letters wouldn't be a problem.
Alternatively, if we want to be able to expand beyond single letters, could we reserve one or more characters for extension purposes?
If braces are forbidden by the syntax today, could we add support for something like the following later on, without breaking anything?
# echo '//0={foo}{bar};1={bar}' >/sys/fs/resctrl/info/L3_MON/mbm_assign_controlFor now, my main concern would be whether this series prevents that sort of thing being added in a backwards compatible way later.
I don't really see anything that is a blocker.
What do you think?
Cheers
---Dave