x86,fs/resctrl: Add kernel-mode (e.g., PLZA) support to the resctrl subsystem
Subsystems (5)
Babu Moger
reviewerv6 cover x86,fs/resctrl: Add kernel-mode (e.g., PLZA) support to the resctrl subsystem
Hi All,
This series adds support for AMD's Privilege-Level Zero Association (PLZA) so kernel work can use a separate resource allocation and/or monitoring association from the user task, and wires it up through a small generic "kernel mode" (kmode) layer in fs/resctrl so future architectures can plug in without touching (hopefully) core resctrl.
The features are documented in:
AMD64 Zen6 Platform Quality of Service (PQOS) Extensions, Publication # 69193 Revision 1.00, Issue Date March 2026
available at https://bugzilla.kernel.org/show_bug.cgi?id=206537
The patches are based on top of commit (tip/master):
8cf07e484290 Merge branch into tip/master: 'x86/tdx'
Any feedback is appreciated.
Background
==========
When memory bandwidth associated with a CLOSID is aggressively throttled, and a task with that CLOSID moves into kernel mode, the kernel operations are also aggressively throttled. This can stall forward progress and eventually degrade overall system performance.
Privilege-Level Zero Association (PLZA) allows the user to specify a CLOSID and/or RMID for execution at Privilege Level Zero. When PLZA is enabled on a CPU, kernel work at PL0 uses the CLOSID and/or RMID from MSR PQR_PLZA_ASSOC; otherwise, the CPU uses the CLOSID and RMID from PQR_ASSOC.
Design
======
A new sysfs file, info/kernel_mode, selects the kernel mode for resource allocation and monitoring of kernel work and, when the mode needs one, the resource group that backs it. Reads list the supported modes and the currently active association; writes select the mode or the group. Look at the thread below for design discussion.
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
Two kernel modes are exposed:
- inherit_user: kernel work uses the allocation and monitoring associations of the user-space task on whose behalf it runs.
- global_enable_per_cpu: kernel work uses the allocation and/or monitoring association of a backing CTRL_MON or MON group. ctrl= and mon= select assign or inherit for each, and group= names the group with <CTRL_MON>/<MON>/ path syntax. An omitted parameter keeps the value the file currently shows. A monitor group requires mon=assign. A failed write leaves the current association in place.
Per-rdtgroup files kmode_cpus and kmode_cpus_list scope the association to a subset of online CPUs. They are visible only on the group that backs the active association. A write enables the association on CPUs added to the mask and disables it on CPUs removed from the mask. A new global_enable_per_cpu association sets the mask to every online CPU. A CPU that comes online later joins the association. A CPU that goes offline leaves it only when that CPU is in the mask.
A group that backs the association, or a control group whose monitor group does, cannot change mode, including entering pseudo-lock setup. The backing group cannot be renamed until the association is cleared.
The arch hook, resctrl_arch_configure_kmode_global(), keeps the fs/resctrl layer arch-neutral.
resctrl_set_kmode_support() lets architecture code register each extra mode during resctrl initialization. inherit_user is already registered when the platform can allocate or monitor. On AMD, PLZA registers global_enable_per_cpu when the feature is available.
Only AMD PLZA is wired up here; Intel and ARM can add their own support later by implementing the hooks.
Examples
========
(See Documentation/filesystems/resctrl.rst, "kernel_mode", "kmode_cpus", and "Examples on working with kernel_mode", for the full UAPI.)
# Mount resctrl
# mount -t resctrl resctrl /sys/fs/resctrl # cd /sys/fs/resctrl
# Read the supported modes. The active mode is bracketed for display # only; do not include brackets when writing.
# cat info/kernel_mode [inherit_user] global_enable_per_cpu:ctrl=assign;mon=assign;group=//
# Create a CTRL_MON group and back kernel-mode allocation with it.
# mkdir ctrl1
# echo "global_enable_per_cpu:ctrl=assign;mon=inherit;group=ctrl1//" \
> info/kernel_mode
# cat info/kernel_mode
inherit_user
[global_enable_per_cpu:ctrl=assign;mon=inherit;group=ctrl1//]# kmode_cpus and kmode_cpus_list are visible only on the backing group. # ls ctrl1/kmode_cpus* ctrl1/kmode_cpus ctrl1/kmode_cpus_list
# Restrict the association to a CPU subset. The association is enabled
# on CPUs added to the mask and disabled on CPUs removed from it. # echo 0-3 > ctrl1/kmode_cpus_list # cat ctrl1/kmode_cpus f # cat ctrl1/kmode_cpus_list 0-3
# Return to inherit_user.
# echo "inherit_user" > info/kernel_mode # cat info/kernel_mode [inherit_user] global_enable_per_cpu:ctrl=assign;mon=assign;group=//
Tested on AMD with PLZA; builds on x86 without PLZA and does not expose global_enable_per_cpu unless the feature is available.
Layout
======
01-03 x86: PLZA CPU feature, command-line option, and MSR definitions. 04-07 fs/resctrl: kernel mode enum, arch hook, kmode state, and
resctrl_set_kmode_support().
08 x86/resctrl: register global_enable_per_cpu when PLZA is
available.
09 fs/resctrl: info/kernel_mode read interface.
10 fs/resctrl: hidden rdtgroup files.
11 fs/resctrl: per-rdtgroup kmode_cpus/kmode_cpus_list.
12 fs/resctrl: CPU hotplug for the active association.
13 fs/resctrl: deactivate the association when a group is removed.
14 fs/resctrl: show or hide kmode_cpus on the backing group.
15 fs/resctrl: reject mode changes while a group backs the
association.
16 fs/resctrl: info/kernel_mode write interface.
17 fs/resctrl: kmode_cpus/kmode_cpus_list writes.
18 fs/resctrl: documentation and examples.Changelog
=========
v6:
- Addressed all the comments as discussed in v5. Anything missing is not intentional. Please feel to comment on any mistake.
- Rename assign_global_enable_per_cpu to global_enable_per_cpu and describe the interface as a kernel mode rather than a policy.
- Flatten kernel mode state into resctrl_kmode. The arch hook is resctrl_arch_configure_kmode_global().
- An omitted ctrl=, mon=, or group= keeps the value shown by reading info/kernel_mode. inherit_user takes no parameters. ctrl=inherit;mon=inherit remains global_enable_per_cpu.
- Selecting a new global_enable_per_cpu association sets that group's kmode_cpus to every online CPU. A CPU that comes online later joins the association even if user space had removed it from the mask.
- kmode_cpus files are created hidden and shown only while the group backs the active association.
- A monitor group requires mon=assign. Removing a control group detaches a child that backs the association before the parent's CLOSID is freed.
- Reject a mode change when the group or one of its monitor groups backs the association.
- Split kmode_cpus visibility and the mode-change rejection into their own patches.
- Use the parsing similar to ctrlmondata.c:parse_line(), ctrlmondata.c:resctrl_io_alloc_parse_line(), monitor.c:resctrl_parse_mbm_assignment().
- Re-wrote the changelog as a feature and not as a bug-fix.
- Remove implementation details in function headers.
v5:
- Collapse the two v4 global-assign modes into a single assign_global_enable_per_cpu policy with ctrl= and mon= options.
- Use "association" terminology consistently in code, errors, and documentation.
- Register assign_global_enable_per_cpu once during x86 resource discovery when PLZA is available.
- Reject mon=inherit when group= selects a monitor group.
- Split hidden-file support, deactivation-on-teardown, and PLZA mode registration into separate patches for easier review.
- Fix msr_pqr_plza_assoc truncation on 32-bit systems by using u64.
- Refresh documentation and add a readable end-to-end example walkthrough.
- Block pseudo-lock setup on kernel-mode-associated groups.
- Reject mode changes and rename while a group backs the active association.
v4:
- Reorder and split the series into 15 patches: separate read-only info/kernel_mode display from the write path; add hotplug support when a CPU comes online; add an end-to-end documentation/examples patch.
- Introduced resctrl_set_kmode_support() so architecture code can register supported kernel-mode policies during resctrl initialization.
- info/kernel_mode write: validate group type; run fail paths before tearing down the active association so errors retain the old state.
- kmode_cpus / kmode_cpus_list: writable with incremental enable/disable deltas; empty masks allowed; offline CPUs rejected.
- Hotplug: newly online CPUs are added to the associated group's kmode_cpu_mask and programmed when assign_global_enable_per_cpu is active.
v3:
- Generalise the layer beyond AMD: rename "PLZA mode" to "kernel mode" (kmode) in code, sysfs, and Documentation.
- Reset the association when the associated rdtgroup is removed, instead of leaving stale state.
v2:
- Similar to RFC with a new proposal; interface names were not final.
- Separated Global Bandwidth Enforcement (GLBE) from PLZA; this series only adds PLZA support.
- Used "kmode" instead of "PLZA" in the generic layer.
Previous versions:
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 (18):
x86/cpufeatures: Support Privilege Level Zero Association (PLZA) x86/resctrl: Add PLZA support to command-line options x86/resctrl: Add PLZA configuration definitions and data structures fs/resctrl: Introduce kernel mode enum x86,arm,fs/resctrl: Introduce architecture hook to program global
kernel mode
fs/resctrl: Introduce kernel mode states for resctrl fs/resctrl: Introduce resctrl_set_kmode_support() to register
supported modes
x86/resctrl: Register RESCTRL_GLOBAL_ENABLE_PER_CPU when PLZA is
available
fs/resctrl: Add interface to display kernel mode status fs/resctrl: Add support for hidden resource group files fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup fs/resctrl: Add CPU hotplug support for kernel mode associations fs/resctrl: Deactivate kernel mode associations when a group is
removed
fs/resctrl: Control visibility of global per-CPU kernel mode group
files
fs/resctrl: Reject mode changes for groups backing kernel mode fs/resctrl: Add interface to modify kernel mode via info/kernel_mode fs/resctrl: Allow user space to write kmode_cpus/kmode_cpus_list fs/resctrl: Add kernel mode documentation and examples
.../admin-guide/kernel-parameters.txt | 2 +- Documentation/filesystems/resctrl.rst | 209 +++++ arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 6 + arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 38 + arch/x86/kernel/cpu/resctrl/internal.h | 49 ++ arch/x86/kernel/cpu/scattered.c | 1 + drivers/resctrl/mpam_resctrl.c | 7 + fs/resctrl/internal.h | 35 + fs/resctrl/rdtgroup.c | 713 ++++++++++++++++++ include/linux/resctrl.h | 81 ++ 12 files changed, 1142 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
Babu Moger
reviewerPATCH v6 1/18 x86/cpufeatures: Support Privilege Level Zero Association (PLZA)
When memory bandwidth associated with a CLOSID is aggressively throttled, and a task with that CLOSID moves into kernel mode, the kernel operations are also aggressively throttled. This can stall forward progress and eventually degrade overall system performance.
AMD hardware supports a feature Privilege Level Zero Association (PLZA), which allows the CPU's CLOSID and/or RMID association to be changed during the transition from user mode to kernel mode. This allows the kernel to run using a different CLOSID and/or RMID than user space, which can improve system performance and/or allow kernel work to be monitored separately.
Note that PLZA feature associates CLOSID and/or RMID to kernel work, and therefore influences resource allocation and/or monitoring for all resources, not only memory bandwidth.
The feature is detected via CPUID_Fn80000020_EBX_x00 [Bit 9]: Privilege Level Zero Association (PLZA).
The PLZA feature details are documented in [1] available from [2].
[1] AMD64 Zen6 Platform Quality of Service (PQOS) Extensions:
Publication # 69193 Revision: 1.00, Issue Date: March 2026
---
v6: Highlight that CLOSID/RMID association affects all resources,
not just memory bandwidth.
v5: Added Acked-by from Boris.
Updated the changelog to include cache allocation and monitoring. Moved the Link tag last.
Updated subject line for cpufeatures.
v4: Split the patch into 2. This patch only handles x86 changes.
Re-wrote the changelog along the ABMC changes.
v3: Code did not change. Patch order changed.
Added documentation link.
v2: Rebased on top of the latest tip.
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -532,6 +532,7 @@* and purposes if CLEAR_CPU_BUF_VM is set). */ #define X86_FEATURE_X2AVIC_EXT (21*32+20)/* AMD SVM x2AVIC support for 4k vCPUs */ +#define X86_FEATURE_PLZA (21*32+21)/* Privilege Level Zero Association */ /* * BUG word(s)
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -61,6 +61,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 }, { X86_FEATURE_ABMC, CPUID_EBX, 5, 0x80000020, 0 }, { X86_FEATURE_SDCIAE, CPUID_EBX, 6, 0x80000020, 0 }, + { X86_FEATURE_PLZA, CPUID_EBX, 9, 0x80000020, 0 }, { X86_FEATURE_AMD_WORKLOAD_CLASS, CPUID_EAX, 22, 0x80000021, 0 }, { X86_FEATURE_TSA_SQ_NO, CPUID_ECX, 1, 0x80000021, 0 }, { X86_FEATURE_TSA_L1_NO, CPUID_ECX, 2, 0x80000021, 0 },
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v6 01/18] x86/cpufeatures: Support Privilege Level Zero Association (PLZA)
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] x86/cpufeatures: missing tools header synchronization for X86_FEATURE_PLZA --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] x86/cpufeatures: missing tools header synchronization for X86_FEATURE_PLZA --
commit 4774876a98b5fdbef10f6f59346ad4e8b9b8b7ac
Author: Babu Moger <[email protected]>
x86/cpufeatures: Support Privilege Level Zero Association (PLZA)
This commit adds support for the Privilege Level Zero Association (PLZA) feature on AMD processors. It updates the cpufeatures header and the scattered CPUID bits to detect and expose PLZA.
arch/x86/include/asm/cpufeatures.h line 532
Quoted 9 lines
arch/x86/include/asm/cpufeatures.h +1
-0@@ -529,6 +529,7 @@* and purposes if CLEAR_CPU_BUF_VM is set). */ #define X86_FEATURE_X2AVIC_EXT (21*32+20)/* AMD SVM x2AVIC support for 4k vCPUs */ +#define X86_FEATURE_PLZA (21*32+21)/* Privilege Level Zero Association */
[Severity: Low]
Does this change also need to be synchronized to the tools directory?
The tools/perf build process runs check-headers.sh, which strictly checks for synchronization between arch/x86/include/asm/cpufeatures.h and its copy in tools/arch/x86/include/asm/cpufeatures.h.
Failing to synchronize the tools copy will result in a "Kernel ABI header differs" build warning when compiling perf from this commit or anywhere later in the series.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v6 01/18] x86/cpufeatures: Support Privilege Level Zero Association (PLZA)
In reply to Babu MogerHi Babu,
Quoted 20 lines · Babu Moger
When memory bandwidth associated with a CLOSID is aggressively throttled, and a task with that CLOSID moves into kernel mode, the kernel operations are also aggressively throttled. This can stall forward progress and eventually degrade overall system performance.
AMD hardware supports a feature Privilege Level Zero Association (PLZA), which allows the CPU's CLOSID and/or RMID association to be changed during the transition from user mode to kernel mode. This allows the kernel to run using a different CLOSID and/or RMID than user space, which can improve system performance and/or allow kernel work to be monitored separately.
Note that PLZA feature associates CLOSID and/or RMID to kernel work, and therefore influences resource allocation and/or monitoring for all resources, not only memory bandwidth.
The feature is detected via
CPUID_Fn80000020_EBX_x00[Bit 9]: Privilege Level Zero Association (PLZA).The PLZA feature details are documented in [1] available from [2].
Quoted 7 lines
[1] AMD64 Zen6 Platform Quality of Service (PQOS) Extensions:
Publication # 69193 Revision: 1.00, Issue Date: March 2026Signed-off-by Babu Moger <[email protected]>---
Reinette
Babu Moger
reviewerRe: [PATCH v6 01/18] x86/cpufeatures: Support Privilege Level Zero Association (PLZA)
Hi Reinette,
Thanks for the review and quick turn-around.
Quoted 26 lines · Reinette Chatre
Hi Babu,
Quoted 23 lines · Babu Moger
When memory bandwidth associated with a CLOSID is aggressively throttled, and a task with that CLOSID moves into kernel mode, the kernel operations are also aggressively throttled. This can stall forward progress and eventually degrade overall system performance.
AMD hardware supports a feature Privilege Level Zero Association (PLZA), which allows the CPU's CLOSID and/or RMID association to be changed during the transition from user mode to kernel mode. This allows the kernel to run using a different CLOSID and/or RMID than user space, which can improve system performance and/or allow kernel work to be monitored separately.
Note that PLZA feature associates CLOSID and/or RMID to kernel work, and therefore influences resource allocation and/or monitoring for all resources, not only memory bandwidth.
The feature is detected via
CPUID_Fn80000020_EBX_x00[Bit 9]: Privilege Level Zero Association (PLZA).The PLZA feature details are documented in [1] available from [2].
[1] AMD64 Zen6 Platform Quality of Service (PQOS) Extensions:
Publication # 69193 Revision: 1.00, Issue Date: March 2026
Quoted 7 lines
Quoted 4 lines
Signed-off-by Babu Moger <[email protected]>---
Reviewed-by Reinette Chatre <[email protected]>
Thanks
Babu
Babu Moger
reviewerPATCH v6 2/18 x86/resctrl: Add PLZA support to command-line options
In reply to Babu MogerAdd a kernel command-line parameter to enable or disable the exposure of the PLZA (Privilege Level Zero Association) feature to resctrl.
This allows administrators to control PLZA visibility at boot time via the rdt= option (e.g. rdt=plza or rdt=!plza).
Add "plza" to the rdt= command-line parameter so PLZA exposure to resctrl can be enabled or disabled at boot. PLZA is exposed by default when supported; rdt=!plza suppresses it.
---
v6: Updated the changelog.
v5: Updated the changelog to mention about rdt= options.
v4: Split the patch 1 from v3 into 2 patches.
This patch contains changes for resctrl subsystem.
--- Documentation/admin-guide/kernel-parameters.txt | 2 +- Documentation/filesystems/resctrl.rst | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
@@ -6449,7 +6449,7 @@ Kernel parameters rdt= [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec, abmc, sdciae, energy[:guid], + mba, smba, bmec, abmc, sdciae, plza, energy[:guid], perf[:guid]. E.g. to turn on cmt and turn off mba use: rdt=cmt,!mba
Documentation/filesystems/resctrl.rst +1 -0
@@ -28,6 +28,7 @@ SMBA (Slow Memory Bandwidth Allocation) "" BMEC (Bandwidth Monitoring Event Configuration) "" ABMC (Assignable Bandwidth Monitoring Counters) "" SDCIAE (Smart Data Cache Injection Allocation Enforcement) "" +PLZA (Privilege Level Zero Association) "" =============================================================== ================================ Historically, new features were made visible by default in /proc/cpuinfo. This
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -803,6 +803,7 @@ enum {RDT_FLAG_BMEC ,RDT_FLAG_ABMC ,RDT_FLAG_SDCIAE , + RDT_FLAG_PLZA, };#define RDT_OPT (idx, n, f) \
@@ -830,6 +831,7 @@ static struct rdt_options rdt_options[] __ro_after_init = {RDT_OPT (RDT_FLAG_BMEC ,"bmec" ,X86_FEATURE_BMEC ),RDT_OPT (RDT_FLAG_ABMC ,"abmc" ,X86_FEATURE_ABMC ),RDT_OPT (RDT_FLAG_SDCIAE ,"sdciae" ,X86_FEATURE_SDCIAE ), + RDT_OPT(RDT_FLAG_PLZA, "plza", X86_FEATURE_PLZA), };#define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options)
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 02/18] x86/resctrl: Add PLZA support to command-line options
Hi Babu,
Quoted 6 lines · Babu Moger
Add a kernel command-line parameter to enable or disable the exposure of the PLZA (Privilege Level Zero Association) feature to resctrl.
This allows administrators to control PLZA visibility at boot time via the rdt= option (e.g. rdt=plza or rdt=!plza).
Apologies for not being clear in previous review. This changelog has a lot of repetition. Above two paragraphs are redundant, paragraph below is sufficient by itself. One possible change would be to spell out PLZA in the paragraph below. Spelling PLZA out may not be necessary since it is spelled out in the patch self, so up to you.
Quoted 6 lines
Add "plza" to the rdt= command-line parameter so PLZA exposure to resctrl can be enabled or disabled at boot. PLZA is exposed by default when supported; rdt=!plza suppresses it.
Signed-off-by Babu Moger <[email protected]>---
With first two paragraphs of changelog removed:
| Reviewed-by: Reinette Chatre <[email protected]>
Reinette
Babu Moger
reviewerRe: [PATCH v6 02/18] x86/resctrl: Add PLZA support to command-line options
Hi Reinette,
Quoted 10 lines · Reinette Chatre
Hi Babu,
Quoted 6 lines · Babu Moger
Add a kernel command-line parameter to enable or disable the exposure of the PLZA (Privilege Level Zero Association) feature to resctrl.
This allows administrators to control PLZA visibility at boot time via the rdt= option (e.g. rdt=plza or rdt=!plza).
Quoted 5 lines
Apologies for not being clear in previous review. This changelog has a lot of repetition. Above two paragraphs are redundant, paragraph below is sufficient by itself. One possible change would be to spell out PLZA in the paragraph below. Spelling PLZA out may not be necessary since it is spelled out in the patch self, so up to you.
No worries. It will be:
Add "plza" to the rdt= command-line parameter so PLZA (Privilege Level Zero Association) exposure to resctrl can be enabled or disabled at boot. PLZA is exposed by default when supported; rdt=!plza suppresses it.
Quoted 11 lines
Quoted 7 lines
Add "plza" to the rdt= command-line parameter so PLZA exposure to resctrl can be enabled or disabled at boot. PLZA is exposed by default when supported; rdt=!plza suppresses it.
Signed-off-by Babu Moger <[email protected]>---
With first two paragraphs of changelog removed:
| Reviewed-by: Reinette Chatre <[email protected]>
Thanks
Babu
Babu Moger
reviewerPATCH v6 3/18 x86/resctrl: Add PLZA configuration definitions and data structures
In reply to Babu MogerPrivilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
PLZA associations are programmed on a per-CPU basis through MSR_IA32_PQR_PLZA_ASSOC (0xc00003fc), which contains the kernel RMID and CLOSID values along with their corresponding enable bits.
Make the register and its field layout available so kernel mode allocation and monitoring associations can be configured independently.
---
v6: Updated the code comments to match general format (members first and
details after).
changelog update.
v5: Sashiko reported:
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=3
Fix the union truncate issue on 32 bit systems by using u64. Updated the changelog and code comments.
v4: Re-wrote the changelog and code comment.
v3: No code changes. Patch order changed. Improved changelog.
v2: No changes. Just rebasing on top of the latest tip branch.
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 49 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1304,6 +1304,7 @@/* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200#define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_PQR_PLZA_ASSOC 0xc00003fc#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 +49 -0
55 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] x86/resctrl: silent truncation of closid in msr_pqr_plza_assoc --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] x86/resctrl: silent truncation of closid in msr_pqr_plza_assoc
--
commit 850d244de0af8ce075ea53a011e816d9227fff52
Author: Babu Moger <[email protected]>
x86/resctrl: Add PLZA configuration definitions and data structures
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0
[ ... ]
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/internal.h +3
-0@@ -222,6 +222,55 @@ union l3_qos_abmc_cfg {unsigned long full; }; +/* +* Privilege Level Zero Association (PLZA) is configured via +* MSR_IA32_PQR_PLZA_ASSOC.
[ ... ]
arch/x86/kernel/cpu/resctrl/internal.h union l3_qos_abmc_cfg { · line 266
Quoted 12 lines
+ * This allows PLZA to override only RMID, only CLOSID, or both. If both
+ *rmid_enandclosid_enare clear, the effective behavior is the same as
+ * when PLZA is disabled, with RMID and CLOSID used fromMSR_IA32_PQR_ASSOC
+ * irrespective of privilege level.
+ */arch/x86/kernel/cpu/resctrl/internal.h +7
-0+union msr_pqr_plza_assoc { +struct { +u64 rmid :12 , + reserved1 :19 , + rmid_en :1 , + closid :4 , + reserved2 :11,
[Severity: High]
Does this correctly size the closid field?
The closid is defined as a 4-bit field, which could cause a regression through silent data truncation when assigned a value >= 16.
resctrl dynamically discovers the maximum number of CLOSIDs supported by the hardware via CPUID. If the hardware reports support for more than 16 CLOSIDs, resctrl will allocate closid values >= 16.
When a resource group with closid >= 16 is assigned to PLZA via resctrl_arch_configure_kmode_global(), the u32 closid is assigned to the 4-bit split.closid bitfield, silently truncating the upper bits. This programs an incorrect CLOSID into the MSR, breaking the requested cache/bandwidth isolation for kernel mode operations without any warning or error.
If the AMD specification allows a 15-bit CLOSID (like standard MSR_IA32_PQR_ASSOC), does the struct bitfield incorrectly split 15 bits into 4 bits for closid and 11 bits for reserved2?
If the hardware is strictly limited to 4 bits, should there be a bounds check (if (closid > 15)) or a cap on num_closids when PLZA is enabled?
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/internal.h +7
-0+ closid_en : 1, + reserved3 :15, + plza_en : 1; + } split; +u64 full; +}; +void rdt_ctrl_update (void *arg);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Reinette Chatre
maintainerRe: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
In reply to Babu MogerHi Babu,
nit: subject claims multiple "definitions" while only adding one #define.
Quoted 4 lines · Babu Moger
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
That CLOSID and RMID are independent on x86 is clear to me. That they can be configured separately is not clear to me in this context. What does this "separate configuration" refer to? Looking at the later patches kernel mode allocation and monitoring associations are always configured together and written to same MSR at the same time?
Quoted 7 lines
PLZA associations are programmed on a per-CPU basis through
MSR_IA32_PQR_PLZA_ASSOC(0xc00003fc), which contains the kernel RMID and CLOSID values along with their corresponding enable bits.Make the register and its field layout available so kernel mode allocation and monitoring associations can be configured independently.
Could you please also elaborate what "configured independently" refers to? At this point it specifically refers to kernel mode and from what I understand kernel mode of allocation and monitoring are configured together.
Quoted 3 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 47 lines
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 49 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1304,6 +1304,7 @@/* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200#define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_PQR_PLZA_ASSOC 0xc00003fc#define MSR_IA32_L3_QOS_ABMC_CFG 0xc00003fd#define MSR_IA32_L3_QOS_EXT_CFG 0xc00003ff#define MSR_IA32_EVT_CFG_BASE 0xc0000400arch/x86/kernel/cpu/resctrl/internal.h +22
-0@@ -222,6 +222,55 @@ union l3_qos_abmc_cfg {unsigned long full; }; +/* +* Privilege Level Zero Association (PLZA) is configured via +* MSR_IA32_PQR_PLZA_ASSOC. +* +* @rmid : RMID programmed for PLZA. +* @reserved1 : Reserved. +* @rmid_en : Enable RMID for PLZA. +* @closid : CLOSID programmed for PLZA. +* @reserved2 : Reserved. +* @closid_en : Enable CLOSID for PLZA. +* @reserved3 : Reserved. +* @plza_en : Enable PLZA. When enabled, PLZA applies to the +* given CPU. +* +* The MSR_IA32_PQR_PLZA_ASSOC must be programmed on every CPU in a QoS +* domain. Each domain supports a single PLZA CLOSID and/or RMID +* association, and all fields except @plza_en must be programmed +* identically across the domain to ensure consistent behavior. +* +* CLOSID and RMID selections are controlled independently. When PLZA is +* enabled (@plza_en = 1), CPL0 uses CLOSID and RMID values from +* MSR_IA32_PQR_PLZA_ASSOC depending on the corresponding enable bits. When
arch/x86/kernel/cpu/resctrl/internal.h union l3_qos_abmc_cfg { · line 256
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/internal.h +10
-0+* PLZA is disabled (@plza_en = 0), the CLOSID and RMID are always taken +* from MSR_IA32_PQR_ASSOC regardless of privilege level. +* +* - @rmid_en = 1: use the RMID from MSR_IA32_PQR_PLZA_ASSOC if @plza_en = 1. +* - @rmid_en = 0: use the RMID from MSR_IA32_PQR_ASSOC. +* - @closid_en = 1: use the CLOSID from MSR_IA32_PQR_PLZA_ASSOC if @plza_en = 1. +* - @closid_en = 0: use the CLOSID from MSR_IA32_PQR_ASSOC. +* +* This allows PLZA to override only RMID, only CLOSID, or both. If both +* rmid_en and closid_en are clear, the effective behavior is the same as
nit: rmid_en -> @rmid_en, closid_en -> @closid_en
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/internal.h +10
-0+* when PLZA is disabled, with RMID and CLOSID used from MSR_IA32_PQR_ASSOC +* irrespective of privilege level. +*/ +union msr_pqr_plza_assoc { +struct { +u64 rmid :12 , + reserved1 :19 , + rmid_en :1 , + closid :4 , + reserved2 :11,
arch/x86/kernel/cpu/resctrl/internal.h union l3_qos_abmc_cfg { · line 276
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/internal.h +7
-0+ closid_en : 1, + reserved3 :15, + plza_en : 1; + } split; +u64 full; +}; +void rdt_ctrl_update (void *arg);int rdt_get_l3_mon_config (struct rdt_resource *r);
Reinette
Babu Moger
reviewerRe: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
nit: subject claims multiple "definitions" while only adding one #define.
Will change it to:
x86/resctrl: Add PLZA configuration register and data structures
Quoted 7 lines · Babu Moger
Quoted 4 lines
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
Quoted 5 lines
That CLOSID and RMID are independent on x86 is clear to me. That they can be configured separately is not clear to me in this context. What does this "separate configuration" refer to? Looking at the later patches kernel mode allocation and monitoring associations are always configured together and written to same MSR at the same time?
Good point. Its confusing. What I meant is that allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and can be enabled independently in hardware. For example, a platform may enable kernel mode CLOSID association without enabling kernel mode RMID association, or vice versa.
Yes. The kernel interface configures both together because they are carried in the same IA32_PQR_ASSOC MSR update.
How about?
Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID in kernel mode than in user mode. Allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and may be enabled independently by hardware.
Quoted 6 lines
Quoted 6 lines
PLZA associations are programmed on a per-CPU basis through
MSR_IA32_PQR_PLZA_ASSOC(0xc00003fc), which contains the kernel RMID and CLOSID values along with their corresponding enable bits.
Quoted 6 lines
Quoted 2 lines
Make the register and its field layout available so kernel mode allocation and monitoring associations can be configured independently.
Could you please also elaborate what "configured independently" refers to? At this point it specifically refers to kernel mode and from what I understand kernel mode of allocation and monitoring are configured together.
Yea. it is not clear. Let me change. Remove the text "independently"(Its already in the earlier text).
Make the register and its field layout available so kernel mode allocation and monitoring associations can be configured.
Quoted 58 lines
Quoted 4 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 51 lines
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 49 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1304,6 +1304,7 @@/* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200#define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_PQR_PLZA_ASSOC 0xc00003fc#define MSR_IA32_L3_QOS_ABMC_CFG 0xc00003fd#define MSR_IA32_L3_QOS_EXT_CFG 0xc00003ff#define MSR_IA32_EVT_CFG_BASE 0xc0000400arch/x86/kernel/cpu/resctrl/internal.h +26
-0@@ -222,6 +222,55 @@ union l3_qos_abmc_cfg {unsigned long full; }; +/* +* Privilege Level Zero Association (PLZA) is configured via +* MSR_IA32_PQR_PLZA_ASSOC. +* +* @rmid : RMID programmed for PLZA. +* @reserved1 : Reserved. +* @rmid_en : Enable RMID for PLZA. +* @closid : CLOSID programmed for PLZA. +* @reserved2 : Reserved. +* @closid_en : Enable CLOSID for PLZA. +* @reserved3 : Reserved. +* @plza_en : Enable PLZA. When enabled, PLZA applies to the +* given CPU. +* +* The MSR_IA32_PQR_PLZA_ASSOC must be programmed on every CPU in a QoS +* domain. Each domain supports a single PLZA CLOSID and/or RMID +* association, and all fields except @plza_en must be programmed +* identically across the domain to ensure consistent behavior. +* +* CLOSID and RMID selections are controlled independently. When PLZA is +* enabled (@plza_en = 1), CPL0 uses CLOSID and RMID values from +* MSR_IA32_PQR_PLZA_ASSOC depending on the corresponding enable bits. When +* PLZA is disabled (@plza_en = 0), the CLOSID and RMID are always taken +* from MSR_IA32_PQR_ASSOC regardless of privilege level. +* +* - @rmid_en = 1: use the RMID from MSR_IA32_PQR_PLZA_ASSOC if @plza_en = 1.
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/internal.h union l3_qos_abmc_cfg { · line 256
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/internal.h +6
-0+* - @rmid_en = 0: use the RMID from MSR_IA32_PQR_ASSOC. +* - @closid_en = 1: use the CLOSID from MSR_IA32_PQR_PLZA_ASSOC if @plza_en = 1. +* - @closid_en = 0: use the CLOSID from MSR_IA32_PQR_ASSOC. +* +* This allows PLZA to override only RMID, only CLOSID, or both. If both +* rmid_en and closid_en are clear, the effective behavior is the same as nit:
rmid_en-> @rmid_en,closid_en-> @closid_en
Sure.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
Hi Babu,
Quoted 22 lines · Babu Moger
Quoted 11 lines · Reinette Chatre
Quoted 4 lines · Babu Moger
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
That CLOSID and RMID are independent on x86 is clear to me. That they can be configured separately is not clear to me in this context. What does this "separate configuration" refer to? Looking at the later patches kernel mode allocation and monitoring associations are always configured together and written to same MSR at the same time?
Good point. Its confusing. What I meant is that allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and can be enabled independently in hardware. For example, a platform may enable kernel mode CLOSID association without enabling kernel mode RMID association, or vice versa.
Yes. The kernel interface configures both together because they are carried in the same
IA32_PQR_ASSOCMSR update.
Quoted 7 lines
How about?
Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID in kernel mode than in user mode. Allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and may be enabled independently by hardware.
Which CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid) is used in kernel mode is different from whether the CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid_en) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid_en) is used in kernel mode.
This series uses the high level "allocation and monitoring association" term interchangeably for both of these meanings and doing so causes confusion.
Please pick specific terms to refer to the CLOSID/RMID assigned to kernel mode vs whether the CLOSID/RMID assignment is enabled and use it throughout the series.
Reinette
Babu Moger
reviewerRe: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
Hi Reinette,
Quoted 37 lines · Reinette Chatre
Hi Babu,
Quoted 22 lines · Babu Moger
Quoted 11 lines · Reinette Chatre
Quoted 4 lines · Babu Moger
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
That CLOSID and RMID are independent on x86 is clear to me. That they can be configured separately is not clear to me in this context. What does this "separate configuration" refer to? Looking at the later patches kernel mode allocation and monitoring associations are always configured together and written to same MSR at the same time?
Good point. Its confusing. What I meant is that allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and can be enabled independently in hardware. For example, a platform may enable kernel mode CLOSID association without enabling kernel mode RMID association, or vice versa.
Yes. The kernel interface configures both together because they are carried in the same
IA32_PQR_ASSOCMSR update.Quoted 7 lines
How about?
Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID in kernel mode than in user mode. Allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and may be enabled independently by hardware.
Which CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid) is used in kernel mode is different from whether the CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid_en) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid_en) is used in kernel mode.
Quoted 6 lines
This series uses the high level "allocation and monitoring association" term interchangeably for both of these meanings and doing so causes confusion.
Please pick specific terms to refer to the CLOSID/RMID assigned to kernel mode vs whether the CLOSID/RMID assignment is enabled and use it throughout the series.
Another attempt to capture all the details:
"Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID than those used in user mode when executing in kernel mode. CLOSID and RMID selection can be configured independently.
The kernel mode CLOSID and RMID are specified by MSR_IA32_PQR_PLZA_ASSOC.closid and MSR_IA32_PQR_PLZA_ASSOC.rmid, respectively. plza_en activates the PLZA operation, while closid_en and rmid_en independently control whether the corresponding kernel mode CLOSID or RMID is used.
Make the register and its field layout available so kernel mode allocation (CLOSID) and monitoring (RMID) selection can be configured independently."
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
Hi Babu,
Quoted 43 lines · Babu Moger
Quoted 35 lines · Reinette Chatre
Quoted 22 lines · Babu Moger
Quoted 11 lines · Reinette Chatre
Quoted 4 lines · Babu Moger
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
That CLOSID and RMID are independent on x86 is clear to me. That they can be configured separately is not clear to me in this context. What does this "separate configuration" refer to? Looking at the later patches kernel mode allocation and monitoring associations are always configured together and written to same MSR at the same time?
Good point. Its confusing. What I meant is that allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and can be enabled independently in hardware. For example, a platform may enable kernel mode CLOSID association without enabling kernel mode RMID association, or vice versa.
Yes. The kernel interface configures both together because they are carried in the same
IA32_PQR_ASSOCMSR update.Quoted 7 lines
How about?
Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID in kernel mode than in user mode. Allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and may be enabled independently by hardware.
Which CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid) is used in kernel mode is different from whether the CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid_en) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid_en) is used in kernel mode.
Quoted 6 lines
This series uses the high level "allocation and monitoring association" term interchangeably for both of these meanings and doing so causes confusion.
Please pick specific terms to refer to the CLOSID/RMID assigned to kernel mode vs whether the CLOSID/RMID assignment is enabled and use it throughout the series.
Quoted 6 lines
Another attempt to capture all the details:
"Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID than those used in user mode when executing in kernel mode. CLOSID and RMID selection can be configured independently.
First sentence already contains "and/or" so I think the last sentence can just be dropped.
Quoted 6 lines
The kernel mode CLOSID and RMID are specified by MSR_IA32_PQR_PLZA_ASSOC.closid and MSR_IA32_PQR_PLZA_ASSOC.rmid, respectively.
plza_enactivates the PLZA operation, whileclosid_enandrmid_enindependently control whether the corresponding kernel mode CLOSID or RMID is used.
Please aim to provide higher level description than what can be seen from the patch.
Quoted 4 lines
Make the register and its field layout available so kernel mode allocation (CLOSID) and monitoring (RMID) selection can be configured independently."
Apologies but I really do not understand why the "independently" distinction is needed since these values are always programmed together.
Here is an attempt, but it is written without knowing which terms you have picked to stick with:
x86/resctrl: Add PLZA MSR definition and field layout
Privilege Level Zero Association (PLZA) enables a CPU to use a different CLOSID and/or RMID when executing in kernel mode than those used in user mode.
PLZA is programmed per CPU through MSR_IA32_PQR_PLZA_ASSOC, which contains the kernel mode CLOSID and RMID, an enable bit for each, and a bit that enables PLZA on the CPU. All fields except the PLZA enable bit must be programmed identically on every CPU in a domain.
Make the register and its field layout available in preparation for resctrl support of kernel mode allocation and monitoring.
Reinette
Re: [PATCH v6 03/18] x86/resctrl: Add PLZA configuration definitions and data structures
Hi Reinette,
Quoted 48 lines · Reinette Chatre
Hi Babu,
Quoted 45 lines · Babu Moger
Quoted 35 lines · Reinette Chatre
Quoted 22 lines · Babu Moger
Quoted 11 lines · Reinette Chatre
Quoted 4 lines · Babu Moger
Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID than those used in user mode when entering kernel mode. CLOSID and RMID selection are independent and can be configured separately.
That CLOSID and RMID are independent on x86 is clear to me. That they can be configured separately is not clear to me in this context. What does this "separate configuration" refer to? Looking at the later patches kernel mode allocation and monitoring associations are always configured together and written to same MSR at the same time?
Good point. Its confusing. What I meant is that allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and can be enabled independently in hardware. For example, a platform may enable kernel mode CLOSID association without enabling kernel mode RMID association, or vice versa.
Yes. The kernel interface configures both together because they are carried in the same
IA32_PQR_ASSOCMSR update.Quoted 7 lines
How about?
Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID in kernel mode than in user mode. Allocation (CLOSID) and monitoring (RMID) associations are independent PLZA features and may be enabled independently by hardware.
Which CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid) is used in kernel mode is different from whether the CLOSID (MSR_IA32_PQR_PLZA_ASSOC.closid_en) and/or RMID (MSR_IA32_PQR_PLZA_ASSOC.rmid_en) is used in kernel mode.
Quoted 6 lines
This series uses the high level "allocation and monitoring association" term interchangeably for both of these meanings and doing so causes confusion.
Please pick specific terms to refer to the CLOSID/RMID assigned to kernel mode vs whether the CLOSID/RMID assignment is enabled and use it throughout the series.
Another attempt to capture all the details:
Quoted 8 lines
Quoted 4 lines
"Privilege Level Zero Association (PLZA) enables the kernel to use a different CLOSID and/or RMID than those used in user mode when executing in kernel mode. CLOSID and RMID selection can be configured independently.
First sentence already contains "and/or" so I think the last sentence can just be dropped.
ok.
Quoted 10 lines
Quoted 6 lines
The kernel mode CLOSID and RMID are specified by MSR_IA32_PQR_PLZA_ASSOC.closid and MSR_IA32_PQR_PLZA_ASSOC.rmid, respectively.
plza_enactivates the PLZA operation, whileclosid_enandrmid_enindependently control whether the corresponding kernel mode CLOSID or RMID is used.Please aim to provide higher level description than what can be seen from the patch.
Ack.
Quoted 7 lines
Quoted 4 lines
Make the register and its field layout available so kernel mode allocation (CLOSID) and monitoring (RMID) selection can be configured independently."
Apologies but I really do not understand why the "independently" distinction is needed since these values are always programmed together.
No problem. This looks good.
Quoted 10 lines
Here is an attempt, but it is written without knowing which terms you have picked to stick with:
x86/resctrl: Add PLZA MSR definition and field layout
Privilege Level Zero Association (PLZA) enables a CPU to use a different CLOSID and/or RMID when executing in kernel mode than those used in user mode.
Quoted 8 lines
PLZA is programmed per CPU through
MSR_IA32_PQR_PLZA_ASSOC, which contains the kernel mode CLOSID and RMID, an enable bit for each, and a bit that enables PLZA on the CPU. All fields except the PLZA enable bit must be programmed identically on every CPU in a domain.Make the register and its field layout available in preparation for resctrl support of kernel mode allocation and monitoring.
thanks
Babu
Babu Moger
reviewerPATCH v6 4/18 fs/resctrl: Introduce kernel mode enum
In reply to Babu MogerKernel mode work can use different allocation and monitoring associations than the originating user task. On x86, Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID when entering kernel mode.
Architectures need a common way to name kernel modes before resctrl can report what is active or what the platform supports.
Introduce enum resctrl_kernel_mode:
- RESCTRL_INHERIT_USER: Kernel mode work inherits allocation and monitoring from the user task.
- RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work uses allocation and/or monitoring associations that differ from the user task.
---
v6: changelog update and code comment update.
Renamed RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU to RESCTRL_GLOBAL_ENABLE_PER_CPU.
v5: Collapse the two global-assign modes into a single
RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU value. Update the changelog to match the enum names and descriptions in the code.
v4: Updated the changelog to be generic as possible.
Moved the enum resctrl_kernel_mode to include/linux/resctrl.h. Updated the code comments to be generic.
Removed resctrl_kmode_cfg from the code. This definition can be fs specific only and architectures dont need to know. Changed enum name to resctrl_kernel_mode from resctrl_kernel_modes.
v3: Removed resctrl_kmode definition.
Changed the kernel mode definitions to enum resctrl_kernel_modes. Used BIT() to set/test the features.
Added details to changelog.
v2: New patch to handle PLZA interfaces with /sys/fs/resctrl/info/ directory.
https://lore.kernel.org/lkml/[email protected]/ --- include/linux/resctrl.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/linux/resctrl.h +29 -0
@@ -723,6 +723,35 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable);*/ bool resctrl_arch_get_io_alloc_enabled (struct rdt_resource *r); +/** +* enum resctrl_kernel_mode - Kernel mode control and monitoring association. +* +* @RESCTRL_INHERIT_USER: +* Kernel mode inherits both allocation and monitoring associations +* from the user-space task. On x86, the kernel uses the same CLOSID and +* RMID as the user-space task. +* +* @RESCTRL_GLOBAL_ENABLE_PER_CPU: +* All kernel mode work uses the same allocation and/or monitoring +* association via an assigned CTRL_MON or MON group. The mode can +* be enabled/disabled per-CPU. When the mode is disabled on a CPU +* then the kernel work on that CPU inherits the allocation and +* monitoring association from the user-space task, effectively the +* kernel mode becomes RESCTRL_INHERIT_USER on that CPU. +* +* All online CPUs are included by default. A subset may be selected +* through the resctrl group interface, and a CTRL_MON or MON group +* may be assigned to this mode. On x86, CLOSID and RMID are configured +* independently; either or both may differ from the user-space task. +*/ +enum resctrl_kernel_mode { +RESCTRL_INHERIT_USER , +RESCTRL_GLOBAL_ENABLE_PER_CPU , +RESCTRL_KMODE_LAST =RESCTRL_GLOBAL_ENABLE_PER_CPU +}; + +#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 04/18] fs/resctrl: Introduce kernel mode enum
Hi Babu,
Quoted 1 line · Babu Moger
Kernel mode work can use different allocation and monitoring associations
Here I think "different allocation and monitoring associations" means different CLOSID/RMID, while other places "different allocation and monitoring associations" means different MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en?
Quoted 4 lines
than the originating user task. On x86, Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID when entering kernel mode.
Quoted 8 lines
Architectures need a common way to name kernel modes before resctrl can report what is active or what the platform supports.
Introduce enum
resctrl_kernel_mode:
-RESCTRL_INHERIT_USER: Kernel mode work inherits allocation and monitoring from the user task.
-RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work uses allocation and/or monitoring associations that differ from the user task.
As written this is not accurate because there is nothing that prevents the "kernel mode group" from being the same as a task's own group?
Could the description of RESCTRL_GLOBAL_ENABLE_PER_CPU be made more specific to include that (a) it is a single (global) association that applies to *all* user space tasks, and (b) it can be enabled/disabled on each CPU? With these two additional details reader will more easily understand why the name of this mode is "RESCTRL_GLOBAL_ENABLE_PER_CPU".
Quoted 3 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 21 lines
--- include/linux/resctrl.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)include/linux/resctrl.h +9
-0@@ -723,6 +723,35 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable);*/ bool resctrl_arch_get_io_alloc_enabled (struct rdt_resource *r); +/** +* enum resctrl_kernel_mode - Kernel mode control and monitoring association. +* +* @RESCTRL_INHERIT_USER: +* Kernel mode inherits both allocation and monitoring associations +* from the user-space task. On x86, the kernel uses the same CLOSID and +* RMID as the user-space task. +* +* @RESCTRL_GLOBAL_ENABLE_PER_CPU:
include/linux/resctrl.h int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable); · line 744
Quoted 10 lines
include/linux/resctrl.h +10
-0+* All kernel mode work uses the same allocation and/or monitoring +* association via an assigned CTRL_MON or MON group. The mode can +* be enabled/disabled per-CPU. When the mode is disabled on a CPU +* then the kernel work on that CPU inherits the allocation and +* monitoring association from the user-space task, effectively the +* kernel mode becomes RESCTRL_INHERIT_USER on that CPU. +* +* All online CPUs are included by default. A subset may be selected +* through the resctrl group interface, and a CTRL_MON or MON group +* may be assigned to this mode. On x86, CLOSID and RMID are configured
The sentence starting with "A subset ..." repeats what is described in the first paragraph so it could just be dropped? This leaves the first sentence of second paragraph out of place, how about merging it into first paragraph like:
The mode can be enabled/disabled per-CPU, all online CPUs are enabled by default.
include/linux/resctrl.h int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable); · line 757
Quoted 13 lines
include/linux/resctrl.h +10
-0+* independently; either or both may differ from the user-space task. +*/ +enum resctrl_kernel_mode { +RESCTRL_INHERIT_USER , +RESCTRL_GLOBAL_ENABLE_PER_CPU , +RESCTRL_KMODE_LAST =RESCTRL_GLOBAL_ENABLE_PER_CPU +}; + +#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
Reinette
Babu Moger
reviewerRe: [PATCH v6 04/18] fs/resctrl: Introduce kernel mode enum
Hi Reinette,
Quoted 9 lines · Reinette Chatre
Hi Babu,
Quoted 1 line · Babu Moger
Kernel mode work can use different allocation and monitoring associations
Here I think "different allocation and monitoring associations" means different CLOSID/RMID, while other places "different allocation and monitoring associations" means different MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en?
That is correct. Hope text here is fine.
Quoted 8 lines
Quoted 8 lines
than the originating user task. On x86, Privilege Level Zero Association (PLZA) enables the kernel to switch to a different CLOSID and/or RMID when entering kernel mode.
Architectures need a common way to name kernel modes before resctrl can report what is active or what the platform supports.
Quoted 8 lines
Quoted 5 lines
Introduce enum
resctrl_kernel_mode:
-RESCTRL_INHERIT_USER: Kernel mode work inherits allocation and monitoring from the user task.
-RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work uses allocation and/or monitoring associations that differ from the user task.As written this is not accurate because there is nothing that prevents the "kernel mode group" from being the same as a task's own group?
Yes. That can happen.
- RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work may use allocation
and/or monitoring associations that differ from the user task.
Quoted 6 lines
Could the description of
RESCTRL_GLOBAL_ENABLE_PER_CPUbe made more specific to include that (a) it is a single (global) association that applies to *all* user space tasks, and (b) it can be enabled/disabled on each CPU? With these two additional details reader will more easily understand why the name of this mode is "RESCTRL_GLOBAL_ENABLE_PER_CPU".
Sure.
Quoted 44 lines
Quoted 4 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 21 lines
--- include/linux/resctrl.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)include/linux/resctrl.h +9
-0@@ -723,6 +723,35 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable);*/ bool resctrl_arch_get_io_alloc_enabled (struct rdt_resource *r); +/** +* enum resctrl_kernel_mode - Kernel mode control and monitoring association. +* +* @RESCTRL_INHERIT_USER: +* Kernel mode inherits both allocation and monitoring associations +* from the user-space task. On x86, the kernel uses the same CLOSID and +* RMID as the user-space task. +* +* @RESCTRL_GLOBAL_ENABLE_PER_CPU: include/linux/resctrl.h int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable); · line 744
Quoted 10 lines
include/linux/resctrl.h +10
-0+* All kernel mode work uses the same allocation and/or monitoring +* association via an assigned CTRL_MON or MON group. The mode can +* be enabled/disabled per-CPU. When the mode is disabled on a CPU +* then the kernel work on that CPU inherits the allocation and +* monitoring association from the user-space task, effectively the +* kernel mode becomes RESCTRL_INHERIT_USER on that CPU. +* +* All online CPUs are included by default. A subset may be selected +* through the resctrl group interface, and a CTRL_MON or MON group +* may be assigned to this mode. On x86, CLOSID and RMID are configured The sentence starting with "A subset ..." repeats what is described in the first paragraph so it could just be dropped? This leaves the first sentence of second paragraph out of place, how about merging it into first paragraph like:
Quoted 2 lines
The mode can be enabled/disabled per-CPU, all online CPUs are enabled by default.
Sure.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 04/18] fs/resctrl: Introduce kernel mode enum
Hi Babu,
Quoted 11 lines · Babu Moger
Quoted 7 lines · Reinette Chatre
Quoted 1 line · Babu Moger
Kernel mode work can use different allocation and monitoring associations
Here I think "different allocation and monitoring associations" means different CLOSID/RMID, while other places "different allocation and monitoring associations" means different MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en?
That is correct. Hope text here is fine.
I had to guess. This is the same topic as being discussed in patch #3. Could you please add clear definitions to eliminate the need for guessing?
Reinette
Babu Moger
reviewerRe: [PATCH v6 04/18] fs/resctrl: Introduce kernel mode enum
Hi Reinette,
Quoted 12 lines · Reinette Chatre
Hi Babu,
Quoted 9 lines · Babu Moger
Quoted 7 lines · Reinette Chatre
Quoted 1 line · Babu Moger
Kernel mode work can use different allocation and monitoring associations
Here I think "different allocation and monitoring associations" means different CLOSID/RMID, while other places "different allocation and monitoring associations" means different MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en?
Quoted 6 lines
Quoted 2 lines
That is correct. Hope text here is fine.
I had to guess. This is the same topic as being discussed in patch #3. Could you please add clear definitions to eliminate the need for guessing?
Ack, rephrased the changelog to use CLOSID and RMID terminology to avoid the ambiguity around "allocation and monitoring associations". If you agree, we can use CLOSID and RMID consistently throughout the series.
"fs/resctrl: Introduce kernel mode enum
Kernel mode operation enables a CPU to use a different CLOSID and/or RMID when executing in kernel mode than those used in user mode.
Architectures need a common set of kernel mode definitions so resctrl can report supported modes and indicate which mode is active.
Introduce enum resctrl_kernel_mode:
- RESCTRL_INHERIT_USER: Kernel mode work inherits the CLOSID and/or RMID of the user task.
- RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work uses a single global CLOSID and/or RMID association shared by all userspace tasks. The mode can be enabled or disabled on a per-CPU basis.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 04/18] fs/resctrl: Introduce kernel mode enum
Hi Babu,
Quoted 13 lines · Babu Moger
Quoted 12 lines · Reinette Chatre
Quoted 11 lines · Babu Moger
Quoted 7 lines · Reinette Chatre
Quoted 1 line · Babu Moger
Kernel mode work can use different allocation and monitoring associations
Here I think "different allocation and monitoring associations" means different CLOSID/RMID, while other places "different allocation and monitoring associations" means different MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en?
That is correct. Hope text here is fine.
Quoted 8 lines
Quoted 4 lines
I had to guess. This is the same topic as being discussed in patch #3. Could you please add clear definitions to eliminate the need for guessing?
Ack, rephrased the changelog to use CLOSID and RMID terminology to avoid the ambiguity around "allocation and monitoring associations". If you agree, we can use CLOSID and RMID consistently throughout the series.
I agree, with emphasis on consistently.
Quoted 6 lines
"fs/resctrl: Introduce kernel mode enum
Kernel mode operation enables a CPU to use a different CLOSID and/or RMID when executing in kernel mode than those used in user mode.
Please take care to distinguish between the "kernel mode" that defines the policy here and "kernel work" that is what the policy governs. At this time this series even conflates the two in some places ("kernel mode work").
Quoted 2 lines
Architectures need a common set of kernel mode definitions so resctrl
It is resctrl filesystem that needs the common vocabulary.
Quoted 6 lines
can report supported modes and indicate which mode is active.
Introduce enum
resctrl_kernel_mode:-
RESCTRL_INHERIT_USER: Kernel mode work inherits the CLOSID and/or RMID of the user task.
This does not look right, it inherits CLOSID *and* RMID, unconditionally, no?
Quoted 4 lines
-
RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work uses a single global CLOSID and/or RMID association shared by all userspace tasks. The mode can be enabled or disabled on a per-CPU basis.
"shared by all user space tasks" is not right? The CLOSID/RMID come from the backing CTRL_MON or MON group, so they are shared only with the tasks assigned to that group (possibly even none).
Below is a suggestion that aims to address the comments. Please do not just copy&paste without verifying it for accuracy and that it matches the terms you decided to stick with.
Kernel work need not use the CLOSID and RMID of the user task on whose behalf it runs. On x86, Privilege Level Zero Association (PLZA) enables a CPU to use a different CLOSID and/or RMID while executing at privilege level zero.
resctrl needs common definitions of how kernel work is managed so that architectures can advertise the kernel modes they support and user space can query them and select the one to use.
Introduce enum resctrl_kernel_mode:
- RESCTRL_INHERIT_USER: Kernel work uses the CLOSID and RMID of the user task.
- RESCTRL_GLOBAL_ENABLE_PER_CPU: All kernel work uses the CLOSID and/or RMID of a single resource group, which may also have user tasks assigned to it. The mode can be enabled or disabled per CPU; on a CPU where it is disabled, kernel work inherits the user task's CLOSID and RMID.
Reinette
Babu Moger
reviewerRe: [PATCH v6 04/18] fs/resctrl: Introduce kernel mode enum
Hi Reinette,
Quoted 20 lines · Reinette Chatre
Hi Babu,
Quoted 17 lines · Babu Moger
Quoted 16 lines · Reinette Chatre
Quoted 11 lines · Babu Moger
Quoted 7 lines · Reinette Chatre
Quoted 1 line · Babu Moger
Kernel mode work can use different allocation and monitoring associations
Here I think "different allocation and monitoring associations" means different CLOSID/RMID, while other places "different allocation and monitoring associations" means different MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en?
That is correct. Hope text here is fine.
I had to guess. This is the same topic as being discussed in patch #3. Could you please add clear definitions to eliminate the need for guessing?
Quoted 7 lines
Quoted 4 lines
Ack, rephrased the changelog to use CLOSID and RMID terminology to avoid the ambiguity around "allocation and monitoring associations". If you agree, we can use CLOSID and RMID consistently throughout the series.
I agree, with emphasis on consistently.
Ack.
Quoted 7 lines
Quoted 6 lines
"fs/resctrl: Introduce kernel mode enum
Kernel mode operation enables a CPU to use a different CLOSID and/or RMID when executing in kernel mode than those used in user mode.
Quoted 8 lines
Please take care to distinguish between the "kernel mode" that defines the policy here and "kernel work" that is what the policy governs. At this time this series even conflates the two in some places ("kernel mode work").
Quoted 2 lines
Architectures need a common set of kernel mode definitions so resctrl
It is resctrl filesystem that needs the common vocabulary.
Ack.
Quoted 9 lines
Quoted 7 lines
can report supported modes and indicate which mode is active.
Introduce enum
resctrl_kernel_mode:-
RESCTRL_INHERIT_USER: Kernel mode work inherits the CLOSID and/or RMID of the user task.This does not look right, it inherits CLOSID *and* RMID, unconditionally, no?
Yes.
Quoted 26 lines
Quoted 5 lines
-
RESCTRL_GLOBAL_ENABLE_PER_CPU: Kernel mode work uses a single global CLOSID and/or RMID association shared by all userspace tasks. The mode can be enabled or disabled on a per-CPU basis."shared by all user space tasks" is not right? The CLOSID/RMID come from the backing
CTRL_MONor MON group, so they are shared only with the tasks assigned to that group (possibly even none).Below is a suggestion that aims to address the comments. Please do not just copy&paste without verifying it for accuracy and that it matches the terms you decided to stick with.
Kernel work need not use the CLOSID and RMID of the user task on whose behalf it runs. On x86, Privilege Level Zero Association (PLZA) enables a CPU to use a different CLOSID and/or RMID while executing at privilege level zero.
resctrl needs common definitions of how kernel work is managed so that architectures can advertise the kernel modes they support and user space can query them and select the one to use.
Introduce enum
resctrl_kernel_mode:
Quoted 8 lines
-
RESCTRL_INHERIT_USER: Kernel work uses the CLOSID and RMID of the user task.-
RESCTRL_GLOBAL_ENABLE_PER_CPU: All kernel work uses the CLOSID and/or RMID of a single resource group, which may also have user tasks assigned to it. The mode can be enabled or disabled per CPU; on a CPU where it is disabled, kernel work inherits the user task's CLOSID and RMID.
Looks good.
Thanks
Babu
Babu Moger
reviewerPATCH v6 5/18 x86,arm,fs/resctrl: Introduce architecture hook to program global kernel mode
In reply to Babu MogerRESCTRL_GLOBAL_ENABLE_PER_CPU mode enables kernel work to use different allocation and monitoring associations than the originating user task.
The mode is enabled independently on each CPU, so the filesystem must program hardware when the mode is activated, when CPUs are added or removed, and when it is deactivated. Allocation and monitoring associations can be done independently, so the architecture callback takes separate control and monitoring options.
Add resctrl_arch_configure_kmode_global() with an x86 PLZA implementation and an empty MPAM stub for ARM systems that do not support this mode.
---
v6: Rename to resctrl_arch_configure_kmode_global(). Rewrite changelog
for RESCTRL_GLOBAL_ENABLE_PER_CPU only (not a bugfix, not a code restatement). Add arm to the subject. Document parameters first; closid/rmid are always programmed. Split fs/arch contract from call scenarios and name the mode explicitly.
v5: Fix kernel-doc for resctrl_arch_configure_kmode(), wire assign_ctrl
through to PLZA closid_en, and update the changelog.
Add calling context in API doc.
v4: Added assign_mon parameter in resctrl_arch_configure_kmode() to program the RMID
as discussed in below.
https://lore.kernel.org/lkml/[email protected]/
Reintroduce independent monitoring assignment via assign_mon after removing the task-based PLZA approach in v3.
Changed cpumask type to "const struct cpumask *cpu_mask".
Added MPAM stub to avoid any linking issues when resctrl_arch_configure_kmode() is called from FS layer. Thanks to Qinyun.
Re-wrote the changelog to be generic.
Updated code comments.
v3: Removed task based PLZA implementation so related changes are removed.
Per-task RMID handling is replaced by group type selection in the fs layer. Updated the change log with details.
Removed resctrl_arch_set_kmode() as arch only provides the modes supported. It is FS which decided which mode to apply.
v2: Updated the commit message to include the sequence of steps to enable PLZA.
Added mode code comments for clarity.
Added kmode to function names to be generic.
--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 38 +++++++++++++++++++++++ drivers/resctrl/mpam_resctrl.c | 7 +++++ include/linux/resctrl.h | 37 ++++++++++++++++++++++ 3 files changed, 82 insertions(+)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +38 -0
@@ -137,3 +137,41 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)return 0 ; } + +static void resctrl_kmode_set_one_amd (void *arg) +{ +union msr_pqr_plza_assoc *plza = arg; + +wrmsrq (MSR_IA32_PQR_PLZA_ASSOC , plza->full); +} + +/* +* resctrl_arch_configure_kmode_global - Program Privilege Level Zero +* Association (PLZA). +* @cpu_mask: CPUs whose PLZA MSR should be updated. +* @closid: CLOSID programmed into MSR_IA32_PQR_PLZA_ASSOC. Always +* written; required even when @assign_ctrl is false. +* @assign_ctrl: Whether PLZA should program the kernel-mode CLOSID. +* @rmid: RMID programmed into MSR_IA32_PQR_PLZA_ASSOC. Always +* written; required even when @assign_mon is false. +* @assign_mon: Whether PLZA should program the kernel-mode RMID. +* @enable: Whether PLZA should program the kernel-mode association. +* +* Program PLZA on @cpu_mask for %RESCTRL_GLOBAL_ENABLE_PER_CPU. See +* union msr_pqr_plza_assoc for the hardware field meanings. +*/ +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable) +{ +union msr_pqr_plza_assoc plza = {0 }; + + plza.split.rmid = rmid; + plza.split.rmid_en = assign_mon; + plza.split.closid = closid; + plza.split.closid_en = assign_ctrl; + plza.split.plza_en = enable; + +on_each_cpu_mask (cpu_mask, resctrl_kmode_set_one_amd, &plza,1 ); +}
drivers/resctrl/mpam_resctrl.c +7 -0
@@ -139,6 +139,13 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r)return false; } +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable) +{ +} +void resctrl_arch_pre_mount (void ) { }
include/linux/resctrl.h +37 -0
@@ -752,6 +752,43 @@ enum resctrl_kernel_mode {#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +/** +* resctrl_arch_configure_kmode_global() - Program RESCTRL_GLOBAL_ENABLE_PER_CPU +* +* @cpu_mask: CPUs whose kernel-mode association should be updated. +* @closid: CLOSID that matches the RMID to program kernel mode. Depending +* on the architecture, the counter may match traffic of both +* @closid and @rmid, or @rmid only. Always provided; a valid +* CLOSID is required even when @assign_ctrl is false. +* @assign_ctrl: true to assign @closid for kernel mode; false to inherit +* association from the user-space task. +* @rmid: RMID to program the kernel mode. Some architectures may use +* CLOSID/RMID separately, others will consider them together. +* Always provided; a valid RMID is required even when +* @assign_mon is false. +* @assign_mon: true to assign @rmid for kernel mode; false to inherit +* monitoring association from the user-space task. +* @enable: true to enable kernel mode association on CPUs in @cpu_mask; +* false to disable kernel mode. +* +* This callback programs %RESCTRL_GLOBAL_ENABLE_PER_CPU. It is called in +* the following scenarios: +* - If the mode is active when user space changes the configuration, it is +* first called to deactivate the mode on all CPUs where it is active. +* - When user space activates the mode, it is called with cpu_online_mask. +* - When user space adds a CPU to the active mode. +* - When user space removes a CPU from the active mode. +* +* Contract between fs and arch: resctrl fs always provides the same +* closid, assign_ctrl, rmid, and assign_mon when activating +* %RESCTRL_GLOBAL_ENABLE_PER_CPU, during CPU add/remove while the mode is +* active, and when deactivating the mode. +*/ +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable); +extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v6 05/18] x86,arm,fs/resctrl: Introduce architecture hook to program global kernel mode
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] resctrl: silent truncation of closid in PLZA kmode configuration --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] resctrl: silent truncation of closid in PLZA kmode configuration --
commit afe4da7391bfbc3b6cf3aee15c764cd25113c4e6
Author: Babu Moger <[email protected]>
x86,arm,fs/resctrl: Introduce architecture hook to program global kernel mode
RESCTRL_GLOBAL_ENABLE_PER_CPU mode enables kernel work to use different allocation and monitoring associations than the originating user task.
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0 -0
[ ... ]
Review
Quoted 10 lines
(quoted diff) +10
-0+void resctrl_arch_configure_kmode_global(const struct cpumask *cpu_mask, + u32 closid, bool assign_ctrl, + u32 rmid, bool assign_mon, + bool enable) +{ + union msr_pqr_plza_assoc plza = { 0 }; + + plza.split.rmid = rmid; + plza.split.rmid_en = assign_mon; + plza.split.closid = closid;
[Severity: Medium]
Will this silently truncate the u32 closid to 4 bits on systems with more than 16 CLOSIDs?
Looking at union msr_pqr_plza_assoc in arch/x86/kernel/cpu/resctrl/internal.h, the bitfield restricts closid to 4 bits:
struct {
u64 rmid :12,
reserved1 :19,
rmid_en : 1,
closid : 4,
reserved2 :11,
closid_en : 1,
reserved3 :15,
plza_en : 1;
} split;If an administrator assigns a resource group with an index 16 or greater to kernel mode, the ID will truncate. This causes a QoS resource limit bypass where kernel execution uses the wrong cache or bandwidth limits.
Given the 11 reserved bits right next to it, is closid: 4 a typo for a 15-bit field?
Quoted 5 lines
(quoted diff) +5
-0+ plza.split.closid_en = assign_ctrl; + plza.split.plza_en = enable; + + on_each_cpu_mask(cpu_mask, resctrl_kmode_set_one_amd, &plza, 1); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Reinette Chatre
maintainerRe: [PATCH v6 05/18] x86,arm,fs/resctrl: Introduce architecture hook to program global kernel mode
In reply to Babu MogerHi Babu,
There is no reference in upstream resctrl but during discussions around the "multiple controls" support we settled on a new subject prefix of "arm,x86,fs/resctrl" for patches that touch all these parts.
Quoted 8 lines · Babu Moger
RESCTRL_GLOBAL_ENABLE_PER_CPUmode enables kernel work to use different allocation and monitoring associations than the originating user task.The mode is enabled independently on each CPU, so the filesystem must program hardware when the mode is activated, when CPUs are added or removed, and when it is deactivated. Allocation and monitoring associations can be done independently, so the architecture callback takes separate control and monitoring options.
Going back and forth through this series a couple of times all these usages of "allocation and monitoring associations" in different contexts become a blur and at this point I do not know what it means at all.
Quoted 6 lines
Add
resctrl_arch_configure_kmode_global()with an x86 PLZA implementation and an empty MPAM stub for ARM systems that do not support this mode.Signed-off-by Babu Moger <[email protected]>---
...
Quoted 19 lines
--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 38 +++++++++++++++++++++++ drivers/resctrl/mpam_resctrl.c | 7 +++++ include/linux/resctrl.h | 37 ++++++++++++++++++++++ 3 files changed, 82 insertions(+)arch/x86/kernel/cpu/resctrl/ctrlmondata.c +5
-0@@ -137,3 +137,41 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)return 0 ; } + +static void resctrl_kmode_set_one_amd (void *arg) +{ +union msr_pqr_plza_assoc *plza = arg; +
arch/x86/kernel/cpu/resctrl/ctrlmondata.c int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable) · line 154
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +10
-0+wrmsrq (MSR_IA32_PQR_PLZA_ASSOC , plza->full); +} + +/* +* resctrl_arch_configure_kmode_global - Program Privilege Level Zero +* Association (PLZA). +* @cpu_mask: CPUs whose PLZA MSR should be updated. +* @closid: CLOSID programmed into MSR_IA32_PQR_PLZA_ASSOC. Always +* written; required even when @assign_ctrl is false. +* @assign_ctrl: Whether PLZA should program the kernel-mode CLOSID.
At this point the series seems to switch terms from the "kernel mode" in previous patches to "kernel-mode" here. Could this all be consistently "kernel mode"?
On a similar note, the series switches between "global kernel mode" (like in this subject) and "global per-CPU kernel mode" (like in patch #14 subject).
Quoted 46 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +23
-0+* @rmid: RMID programmed into MSR_IA32_PQR_PLZA_ASSOC. Always +* written; required even when @assign_mon is false. +* @assign_mon: Whether PLZA should program the kernel-mode RMID. +* @enable: Whether PLZA should program the kernel-mode association. +* +* Program PLZA on @cpu_mask for %RESCTRL_GLOBAL_ENABLE_PER_CPU. See +* union msr_pqr_plza_assoc for the hardware field meanings. +*/ +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable) +{ +union msr_pqr_plza_assoc plza = {0 }; + + plza.split.rmid = rmid; + plza.split.rmid_en = assign_mon; + plza.split.closid = closid; + plza.split.closid_en = assign_ctrl; + plza.split.plza_en = enable; + +on_each_cpu_mask (cpu_mask, resctrl_kmode_set_one_amd, &plza,1 ); +}drivers/resctrl/mpam_resctrl.c +7
-0@@ -139,6 +139,13 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r)return false; } +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable) +{ +} +void resctrl_arch_pre_mount (void ) { }include/linux/resctrl.h +0
-0
include/linux/resctrl.h enum resctrl_kernel_mode { · line 758
Quoted 7 lines
include/linux/resctrl.h +4
-0@@ -752,6 +752,43 @@ enum resctrl_kernel_mode {#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +/** +* resctrl_arch_configure_kmode_global() - Program RESCTRL_GLOBAL_ENABLE_PER_CPU +* +* @cpu_mask: CPUs whose kernel-mode association should be updated.
This could be made more specific about being online CPUs. For example,
@cpu_mask: Online CPUs on which to update the association.
include/linux/resctrl.h enum resctrl_kernel_mode { · line 762
Quoted 4 lines
include/linux/resctrl.h +4
-0+* @closid: CLOSID that matches the RMID to program kernel mode. Depending +* on the architecture, the counter may match traffic of both +* @closid and @rmid, or @rmid only. Always provided; a valid +* CLOSID is required even when @assign_ctrl is false.
Above description seems to be a concatenation of different texts. The "counter" text seems to be copied from resctrl_arch_rmid_read() and does not seem relevant here. The "CLOSID is required" is copied from the x86 arch helper where it is indeed required - but this does not apply to resctrl fs?
How about something like:
@closid: CLOSID of the resource group backing %RESCTRL_GLOBAL_ENABLE_PER_CPU mode.
Always provided, even when @assign_ctrl is false.
include/linux/resctrl.h enum resctrl_kernel_mode { · line 768
Quoted 6 lines
include/linux/resctrl.h +6
-0+* @assign_ctrl: true to assign @closid for kernel mode; false to inherit +* association from the user-space task. +* @rmid: RMID to program the kernel mode. Some architectures may use +* CLOSID/RMID separately, others will consider them together. +* Always provided; a valid RMID is required even when +* @assign_mon is false.
(similar comment as for @closid)
include/linux/resctrl.h enum resctrl_kernel_mode { · line 772
Quoted 4 lines
include/linux/resctrl.h +4
-0+* @assign_mon: true to assign @rmid for kernel mode; false to inherit +* monitoring association from the user-space task. +* @enable: true to enable kernel mode association on CPUs in @cpu_mask; +* false to disable kernel mode.
"false to disable kernel mode" does not seem to capture all that is required from architecture. When considering resctrl_kmode_switch(), @enable being false is only thing resctrl fs does to put CPUs into RESCTRL_INHERIT_USER mode? So when @enable is false the architecture should disable %RESCTRL_GLOBAL_ENABLE_PER_CPU *and* enable %RESCTRL_INHERIT_USER?
include/linux/resctrl.h enum resctrl_kernel_mode { · line 780
Quoted 8 lines
include/linux/resctrl.h +8
-0+* +* This callback programs %RESCTRL_GLOBAL_ENABLE_PER_CPU. It is called in +* the following scenarios: +* - If the mode is active when user space changes the configuration, it is +* first called to deactivate the mode on all CPUs where it is active. +* - When user space activates the mode, it is called with cpu_online_mask. +* - When user space adds a CPU to the active mode. +* - When user space removes a CPU from the active mode.
This attempt at listing all callsites is proving problematic since it is already out of date by the end of the series. I would thus suggest to drop listing the individual call sites and instead focus on writing a clear contract. Consider, for example, something like (but please verify, especially for accuracy and correct terms, do not just copy&paste):
An association starts when %RESCTRL_GLOBAL_ENABLE_PER_CPU is activated and ends when the mode is deactivated or user space changes the backing resource group, @assign_ctrl or @assign_mon. Every call for one association provides the same @closid, @assign_ctrl, @rmid and @assign_mon; only @cpu_mask and @enable differ between calls. Before an association ends, it is disabled on every CPU where it is enabled.
Quoted 4 lines
include/linux/resctrl.h +4
-0+* +* Contract between fs and arch: resctrl fs always provides the same +* closid, assign_ctrl, rmid, and assign_mon when activating +* %RESCTRL_GLOBAL_ENABLE_PER_CPU, during CPU add/remove while the mode is
include/linux/resctrl.h enum resctrl_kernel_mode { · line 794
Quoted 10 lines
include/linux/resctrl.h +7
-0+* active, and when deactivating the mode. +*/ +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable); +extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
Reinette
Re: [PATCH v6 05/18] x86,arm,fs/resctrl: Introduce architecture hook to program global kernel mode
Hi Reinette,
Quoted 5 lines · Reinette Chatre
Hi Babu,
There is no reference in upstream resctrl but during discussions around the "multiple controls" support we settled on a new subject prefix of "arm,x86,fs/resctrl" for patches that touch all these parts.
Sure.
Quoted 11 lines · Babu Moger
Quoted 8 lines
RESCTRL_GLOBAL_ENABLE_PER_CPUmode enables kernel work to use different allocation and monitoring associations than the originating user task.The mode is enabled independently on each CPU, so the filesystem must program hardware when the mode is activated, when CPUs are added or removed, and when it is deactivated. Allocation and monitoring associations can be done independently, so the architecture callback takes separate control and monitoring options.
Quoted 3 lines
Going back and forth through this series a couple of times all these usages of "allocation and monitoring associations" in different contexts become a blur and at this point I do not know what it means at all.
May be removing the text in some places might help. In this patch, the last line may not required.
Quoted 35 lines
Quoted 7 lines
Add
resctrl_arch_configure_kmode_global()with an x86 PLZA implementation and an empty MPAM stub for ARM systems that do not support this mode.Signed-off-by Babu Moger <[email protected]>---
...
Quoted 25 lines
--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 38 +++++++++++++++++++++++ drivers/resctrl/mpam_resctrl.c | 7 +++++ include/linux/resctrl.h | 37 ++++++++++++++++++++++ 3 files changed, 82 insertions(+)arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11
-0@@ -137,3 +137,41 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)return 0 ; } + +static void resctrl_kmode_set_one_amd (void *arg) +{ +union msr_pqr_plza_assoc *plza = arg; + +wrmsrq (MSR_IA32_PQR_PLZA_ASSOC , plza->full); +} + +/* +* resctrl_arch_configure_kmode_global - Program Privilege Level Zero +* Association (PLZA).
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable) · line 154
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +4
-0+* @cpu_mask: CPUs whose PLZA MSR should be updated. +* @closid: CLOSID programmed into MSR_IA32_PQR_PLZA_ASSOC. Always +* written; required even when @assign_ctrl is false. +* @assign_ctrl: Whether PLZA should program the kernel-mode CLOSID. At this point the series seems to switch terms from the "kernel mode" in previous patches to "kernel-mode" here. Could this all be consistently "kernel mode"?
Sure.
Quoted 4 lines
On a similar note, the series switches between "global kernel mode" (like in this subject) and "global per-CPU kernel mode" (like in patch #14 subject).
Lets say "global per-CPU kernel mode" consistently when referring to RESCTRL_GLOBAL_ENABLE_PER_CPU.
Quoted 50 lines
Quoted 50 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +23
-0+* @rmid: RMID programmed into MSR_IA32_PQR_PLZA_ASSOC. Always +* written; required even when @assign_mon is false. +* @assign_mon: Whether PLZA should program the kernel-mode RMID. +* @enable: Whether PLZA should program the kernel-mode association. +* +* Program PLZA on @cpu_mask for %RESCTRL_GLOBAL_ENABLE_PER_CPU. See +* union msr_pqr_plza_assoc for the hardware field meanings. +*/ +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable) +{ +union msr_pqr_plza_assoc plza = {0 }; + + plza.split.rmid = rmid; + plza.split.rmid_en = assign_mon; + plza.split.closid = closid; + plza.split.closid_en = assign_ctrl; + plza.split.plza_en = enable; + +on_each_cpu_mask (cpu_mask, resctrl_kmode_set_one_amd, &plza,1 ); +}drivers/resctrl/mpam_resctrl.c +7
-0@@ -139,6 +139,13 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r)return false; } +void resctrl_arch_configure_kmode_global (const struct cpumask *cpu_mask, +u32 closid,bool assign_ctrl, +u32 rmid,bool assign_mon, +bool enable) +{ +} +void resctrl_arch_pre_mount (void ) { }include/linux/resctrl.h +0
-0@@ -752,6 +752,43 @@ enum resctrl_kernel_mode {#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1)
Quoted 7 lines
include/linux/resctrl.h enum resctrl_kernel_mode { · line 758
Quoted 4 lines
include/linux/resctrl.h +4
-0+/** +* resctrl_arch_configure_kmode_global() - Program RESCTRL_GLOBAL_ENABLE_PER_CPU +* +* @cpu_mask: CPUs whose kernel-mode association should be updated. This could be made more specific about being online CPUs. For example,
@cpu_mask: Online CPUs on which to update the association.
Sure.
Quoted 10 lines
include/linux/resctrl.h enum resctrl_kernel_mode { · line 762
Quoted 5 lines
include/linux/resctrl.h +4
-0+* @closid: CLOSID that matches the RMID to program kernel mode. Depending +* on the architecture, the counter may match traffic of both +* @closid and @rmid, or @rmid only. Always provided; a valid +* CLOSID is required even when @assign_ctrl is false. Above description seems to be a concatenation of different texts. The "counter" text seems to be copied from
resctrl_arch_rmid_read()and does not seem relevant here. The "CLOSID is required" is copied from the x86 arch helper where it is indeed required - but this does not apply to resctrl fs?
Ack.
Quoted 5 lines
How about something like:
@closid: CLOSID of the resource group backing %RESCTRL_GLOBAL_ENABLE_PER_CPU mode.
Always provided, even when @assign_ctrl is false.
Sure.
Quoted 9 lines
include/linux/resctrl.h enum resctrl_kernel_mode { · line 768
Quoted 7 lines
include/linux/resctrl.h +6
-0+* @assign_ctrl: true to assign @closid for kernel mode; false to inherit +* association from the user-space task. +* @rmid: RMID to program the kernel mode. Some architectures may use +* CLOSID/RMID separately, others will consider them together. +* Always provided; a valid RMID is required even when +* @assign_mon is false. (similar comment as for @closid)
Sure.
Quoted 11 lines
include/linux/resctrl.h enum resctrl_kernel_mode { · line 772
Quoted 5 lines
include/linux/resctrl.h +4
-0+* @assign_mon: true to assign @rmid for kernel mode; false to inherit +* monitoring association from the user-space task. +* @enable: true to enable kernel mode association on CPUs in @cpu_mask; +* false to disable kernel mode. "false to disable kernel mode" does not seem to capture all that is required from architecture. When considering
resctrl_kmode_switch(), @enable being false is only thing resctrl fs does to put CPUs intoRESCTRL_INHERIT_USERmode? So when @enable is false the architecture should disable %RESCTRL_GLOBAL_ENABLE_PER_CPU *and* enable %RESCTRL_INHERIT_USER?
Yes. Will update.
Quoted 10 lines
include/linux/resctrl.h enum resctrl_kernel_mode { · line 780
Quoted 9 lines
include/linux/resctrl.h +8
-0+* +* This callback programs %RESCTRL_GLOBAL_ENABLE_PER_CPU. It is called in +* the following scenarios: +* - If the mode is active when user space changes the configuration, it is +* first called to deactivate the mode on all CPUs where it is active. +* - When user space activates the mode, it is called with cpu_online_mask. +* - When user space adds a CPU to the active mode. +* - When user space removes a CPU from the active mode.
Quoted 5 lines
This attempt at listing all callsites is proving problematic since it is already out of date by the end of the series. I would thus suggest to drop listing the individual call sites and instead focus on writing a clear contract. Consider, for example, something like (but please verify, especially for accuracy and correct terms, do not just copy&paste):
):
Quoted 8 lines
An association starts when %RESCTRL_GLOBAL_ENABLE_PER_CPU is activated and ends when the mode is deactivated or user space changes the backing resource group, @assign_ctrl or @assign_mon. Every call for one association provides the same @closid, @assign_ctrl, @rmid and @assign_mon; only @cpu_mask and @enable differ between calls. Before an association ends, it is disabled on every CPU where it is enabled.
Looks good with minor change.
The callback programs %RESCTRL_GLOBAL_ENABLE_PER_CPU. An association starts when %RESCTRL_GLOBAL_ENABLE_PER_CPU is activated and ends when the mode is deactivated or userspace changes the backing resource group, @assign_ctrl, or @assign_mon. Each call for a given association uses the same @closid, @assign_ctrl, @rmid, and @assign_mon; only @cpu_mask and @enable differ. Before an association ends, it is disabled on every CPU where it is enabled.
Thanks
Babu
Babu Moger
reviewerPATCH v6 6/18 fs/resctrl: Introduce kernel mode states for resctrl
In reply to Babu MogerThe filesystem tracks supported kernel modes, the active mode, and the control and monitoring association for the assigned group.
Introduce struct resctrl_kmode_cfg and initialize the default configuration from the platform's capabilities.
---
v6: Drop ctrl_en/mon_en and use resctrl_arch_alloc_capable() /
resctrl_arch_mon_capable() directly. Flatten caps/active into resctrl_kmode_cfg. Rename resctrl_kcfg to resctrl_kmode, ctrl_mode to ctrl, mon_mode to mon, and k_rdtgrp to rdtgrp. Comments describe the objects, not a member list. Rewrite changelog.
v5: Replace per-mode registration helpers with a single resctrl_kmode_cfg
structure. Derive ctrl_en and mon_en from resctrl_arch_alloc_capable() and resctrl_arch_mon_capable() during filesystem init. Update code comments and changelog.
v4: New patch to initialize supported kernel modes.
https://lore.kernel.org/lkml/[email protected]/
Changed the kmode_cur to enum resctrl_kernel_mode in resctrl_kmode_cfg. Moved the resctrl_kmode_cfg to filesystem code.
--- fs/resctrl/internal.h | 29 +++++++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
fs/resctrl/internal.h +29 -0
@@ -314,6 +314,35 @@ struct mbm_state {u32 prev_bw; }; +/** +* enum kmode_state - Control or monitoring association +* @KMODE_INHERIT: Inherit from the user-space task. +* @KMODE_ASSIGN: Use the backing group's CLOSID or RMID. +*/ +enum kmode_state { +KMODE_INHERIT , +KMODE_ASSIGN +}; + +/** +* struct resctrl_kmode_cfg - Kernel mode configuration +* @kmode_sup: Bitmap of supported kernel modes. +* @kmode_cur: Currently selected kernel mode. +* @ctrl: Control association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* Kept while %RESCTRL_INHERIT_USER is selected. +* @mon: Monitoring association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* Kept while %RESCTRL_INHERIT_USER is selected. +* @rdtgrp: Resource group backing %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* %NULL while that mode is not selected. +*/ +struct resctrl_kmode_cfg { + DECLARE_BITMAP(kmode_sup, RESCTRL_NUM_KERNEL_MODES); +enum resctrl_kernel_mode kmode_cur; +enum kmode_state ctrl; +enum kmode_state mon; +struct rdtgroup *rdtgrp; +}; +extern struct mutex rdtgroup_mutex;static inline const char *rdt_kn_name (const struct kernfs_node *kn)
fs/resctrl/rdtgroup.c +25 -0
@@ -76,6 +76,9 @@ static void rdtgroup_destroy_root(void);struct dentry *debugfs_resctrl; +/* Kernel mode for this system. */ +static struct resctrl_kmode_cfg resctrl_kmode; +/* * Memory bandwidth monitoring event to use for the default CTRL_MON group * and each new CTRL_MON group created by the user. Only relevant when
@@ -2297,6 +2300,26 @@ static void io_alloc_init(void) } } +/* +* Set RESCTRL_INHERIT_USER as the default when the platform supports +* allocation or monitoring. Otherwise leave kernel mode unsupported. +*/ +static void resctrl_kmode_init (void ) +{ +if (!resctrl_arch_alloc_capable () && !resctrl_arch_mon_capable ()) +return ; + + resctrl_kmode.kmode_cur =RESCTRL_INHERIT_USER ; +__set_bit (RESCTRL_INHERIT_USER , resctrl_kmode.kmode_sup); + +/* +* Defaults used when RESCTRL_GLOBAL_ENABLE_PER_CPU mode is +* activated without new values. +*/ + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ; +} +void resctrl_file_fflags_init (const char *config,unsigned long fflags) {struct rftype *rft;
@@ -4814,6 +4837,8 @@ int resctrl_init(void)if (ret)return ret; +resctrl_kmode_init (); + ret =sysfs_create_mount_point (fs_kobj,"resctrl" );if (ret) {resctrl_l3_mon_resource_exit ();
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 06/18] fs/resctrl: Introduce kernel mode states for resctrl
Hi Babu,
nit: "for resctrl" in subject is redundant.
Quoted 2 lines · Babu Moger
The filesystem tracks supported kernel modes, the active mode, and the control and monitoring association for the assigned group.
Please let the context describe the context at the time of the patch, not how things will work after entire series is applied.
Please use consistent terminology, this series switches between "assigned group" and "backing group" to refer to the same group.
Please use the changelog to guide the reader to understand the architecture and how things fit together. Many changelogs are very cryptic without explanation of what the patch does and why.
Quoted 3 lines
Introduce struct
resctrl_kmode_cfgand initialize the default configuration from the platform's capabilities.
Please check all changelogs to ensure they all are able to provide an answer to "why". More specifically, please consider:
https://lore.kernel.org/lkml/20250911165433.GBaML-yTUZHkywuJIe@fat_crate.local/
Quoted 3 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 10 lines
--- fs/resctrl/internal.h | 29 +++++++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+)fs/resctrl/internal.h +0
-0
fs/resctrl/internal.h struct mbm_state { · line 318
Quoted 5 lines
fs/resctrl/internal.h +2
-0@@ -314,6 +314,35 @@ struct mbm_state {u32 prev_bw; }; +/** +* enum kmode_state - Control or monitoring association
What does "control or monitoring association" mean? This is becoming an overloaded term used to mean different things and becoming confusing. For comparison, earlier patch introduced *another*
"control and monitoring association" enum:
enum resctrl_kernel_mode - Kernel mode control and monitoring association
fs/resctrl/internal.h struct mbm_state { · line 330
Quoted 12 lines
fs/resctrl/internal.h +12
-0+* @KMODE_INHERIT: Inherit from the user-space task. +* @KMODE_ASSIGN: Use the backing group's CLOSID or RMID. +*/ +enum kmode_state { +KMODE_INHERIT , +KMODE_ASSIGN +}; + +/** +* struct resctrl_kmode_cfg - Kernel mode configuration +* @kmode_sup: Bitmap of supported kernel modes. +* @kmode_cur: Currently selected kernel mode.
Adding this comment during a second pass ... please consider later motivations about naming of these fields. This field is introduced as "kmode_cur" but when considering the language used in rest of series "active" seems more appropriate.
@kmode_sup could also just be @supported (the "kmode" is redundant).
fs/resctrl/internal.h struct mbm_state { · line 332
Quoted 2 lines
fs/resctrl/internal.h +2
-0+* @ctrl: Control association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* Kept while %RESCTRL_INHERIT_USER is selected.
The "Kept while ..." does not seem to match implementation. Looks like resctrl_kmode_switch() always resets it to KMODE_ASSIGN?
At this point the reader is left to decipher the architecture via cryptic changelogs and inaccurate comments. It is very difficult to parse.
fs/resctrl/internal.h struct mbm_state { · line 334
Quoted 2 lines
fs/resctrl/internal.h +2
-0+* @mon: Monitoring association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* Kept while %RESCTRL_INHERIT_USER is selected.
Similar comment about "Kept ..."
Quoted 29 lines
fs/resctrl/internal.h +11
-0+* @rdtgrp: Resource group backing %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* %NULL while that mode is not selected. +*/ +struct resctrl_kmode_cfg { + DECLARE_BITMAP(kmode_sup, RESCTRL_NUM_KERNEL_MODES); +enum resctrl_kernel_mode kmode_cur; +enum kmode_state ctrl; +enum kmode_state mon; +struct rdtgroup *rdtgrp; +}; +extern struct mutex rdtgroup_mutex;static inline const char *rdt_kn_name (const struct kernfs_node *kn)fs/resctrl/rdtgroup.c +3
-0@@ -76,6 +76,9 @@ static void rdtgroup_destroy_root(void);struct dentry *debugfs_resctrl; +/* Kernel mode for this system. */ +static struct resctrl_kmode_cfg resctrl_kmode; +/* * Memory bandwidth monitoring event to use for the default CTRL_MON group * and each new CTRL_MON group created by the user. Only relevant when
fs/resctrl/rdtgroup.c static void io_alloc_init(void) · line 2305
Quoted 6 lines
fs/resctrl/rdtgroup.c +3
-0@@ -2297,6 +2300,26 @@ static void io_alloc_init(void) } } +/* +* Set RESCTRL_INHERIT_USER as the default when the platform supports +* allocation or monitoring. Otherwise leave kernel mode unsupported.
This (and why) would be useful to describe in changelog.
fs/resctrl/rdtgroup.c static void io_alloc_init(void) · line 2311
Quoted 6 lines
fs/resctrl/rdtgroup.c +6
-0+*/ +static void resctrl_kmode_init (void ) +{ +if (!resctrl_arch_alloc_capable () && !resctrl_arch_mon_capable ()) +return ; +
This check seems unnecessary? resctrl_kmode_init() will only be called on a system that is capable of allocation or monitoring.
The planned AET changes will change this behavior see
https://lore.kernel.org/lkml/[email protected]/
but in that case it still seems as though initializing the kernel mode as below always needs to be done.
That begs the question why is resctrl_kmode_init() needed at all? Why not use a static initializer?
I find resctrl_kmode_init() to be potentially confusing since it does *not* actually initialize resctrl_kmode. This is only possible to see two patches later where get_rdt_resources() is changed so that x86 sets its supported modes and this runs *before* resctrl_kmode_init().
If anyone decides one day "this initialization code is missing a bitmap_zero()" then it will break PLZA.
Quoted 15 lines
fs/resctrl/rdtgroup.c +11
-0+ resctrl_kmode.kmode_cur =RESCTRL_INHERIT_USER ; +__set_bit (RESCTRL_INHERIT_USER , resctrl_kmode.kmode_sup); + +/* +* Defaults used when RESCTRL_GLOBAL_ENABLE_PER_CPU mode is +* activated without new values. +*/ + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ; +} +void resctrl_file_fflags_init (const char *config,unsigned long fflags) {struct rftype *rft;
fs/resctrl/rdtgroup.c int resctrl_init(void) · line 4844
Quoted 8 lines
fs/resctrl/rdtgroup.c +2
-0@@ -4814,6 +4837,8 @@ int resctrl_init(void)if (ret)return ret; +resctrl_kmode_init (); + ret =sysfs_create_mount_point (fs_kobj,"resctrl" );if (ret) {resctrl_l3_mon_resource_exit ();
Reinette
Re: [PATCH v6 06/18] fs/resctrl: Introduce kernel mode states for resctrl
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
nit: "for resctrl" in subject is redundant.
ok.
Quoted 10 lines · Babu Moger
Quoted 2 lines
The filesystem tracks supported kernel modes, the active mode, and the control and monitoring association for the assigned group.
Please let the context describe the context at the time of the patch, not how things will work after entire series is applied.
Please use consistent terminology, this series switches between "assigned group" and "backing group" to refer to the same group.
Will use the "backing group". That seems more clearer.
Quoted 5 lines
Please use the changelog to guide the reader to understand the architecture and how things fit together. Many changelogs are very cryptic without explanation of what the patch does and why.
Ack.
Quoted 8 lines
Quoted 3 lines
Introduce struct
resctrl_kmode_cfgand initialize the default configuration from the platform's capabilities.Please check all changelogs to ensure they all are able to provide an answer to "why". More specifically, please consider:
https://lore.kernel.org/lkml/20250911165433.GBaML-yTUZHkywuJIe@fat_crate.local/
Ack
Quoted 26 lines
Quoted 3 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 10 lines
--- fs/resctrl/internal.h | 29 +++++++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+)fs/resctrl/internal.h +0
-0fs/resctrl/internal.h struct mbm_state { · line 318
Quoted 5 lines
fs/resctrl/internal.h +2
-0@@ -314,6 +314,35 @@ struct mbm_state {u32 prev_bw; }; +/** +* enum kmode_state - Control or monitoring association What does "control or monitoring association" mean? This is becoming an overloaded term used to mean different things and becoming confusing. For comparison, earlier patch introduced *another*
"control and monitoring association" enum:
Quoted 1 line
enum
resctrl_kernel_mode- Kernel mode control and monitoring association
Sure.
Quoted 18 lines
fs/resctrl/internal.h struct mbm_state { · line 330
Quoted 13 lines
fs/resctrl/internal.h +12
-0+* @KMODE_INHERIT: Inherit from the user-space task. +* @KMODE_ASSIGN: Use the backing group's CLOSID or RMID. +*/ +enum kmode_state { +KMODE_INHERIT , +KMODE_ASSIGN +}; + +/** +* struct resctrl_kmode_cfg - Kernel mode configuration +* @kmode_sup: Bitmap of supported kernel modes. +* @kmode_cur: Currently selected kernel mode. Adding this comment during a second pass ... please consider later motivations about naming of these fields. This field is introduced as "
kmode_cur" but when considering the language used in rest of series "active" seems more appropriate.
Quoted 1 line
@kmode_sup could also just be @supported (the "kmode" is redundant).
Sure. Will change kmode_cur to "current".
Quoted 6 lines
fs/resctrl/internal.h struct mbm_state { · line 332
Quoted 3 lines
fs/resctrl/internal.h +2
-0+* @ctrl: Control association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* Kept while %RESCTRL_INHERIT_USER is selected. The "Kept while ..." does not seem to match implementation. Looks like
resctrl_kmode_switch()always resets it toKMODE_ASSIGN?
Yes. Will remove the line.
Quoted 8 lines
At this point the reader is left to decipher the architecture via cryptic changelogs and inaccurate comments. It is very difficult to parse.
fs/resctrl/internal.h struct mbm_state { · line 334
Quoted 2 lines
fs/resctrl/internal.h +2
-0+* @mon: Monitoring association for %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* Kept while %RESCTRL_INHERIT_USER is selected. Similar comment about "Kept ..."
Yes. Will remove the text.
Quoted 33 lines
Quoted 33 lines
fs/resctrl/internal.h +11
-0+* @rdtgrp: Resource group backing %RESCTRL_GLOBAL_ENABLE_PER_CPU. +* %NULL while that mode is not selected. +*/ +struct resctrl_kmode_cfg { + DECLARE_BITMAP(kmode_sup, RESCTRL_NUM_KERNEL_MODES); +enum resctrl_kernel_mode kmode_cur; +enum kmode_state ctrl; +enum kmode_state mon; +struct rdtgroup *rdtgrp; +}; +extern struct mutex rdtgroup_mutex;static inline const char *rdt_kn_name (const struct kernfs_node *kn)fs/resctrl/rdtgroup.c +3
-0@@ -76,6 +76,9 @@ static void rdtgroup_destroy_root(void);struct dentry *debugfs_resctrl; +/* Kernel mode for this system. */ +static struct resctrl_kmode_cfg resctrl_kmode; +/* * Memory bandwidth monitoring event to use for the default CTRL_MON group * and each new CTRL_MON group created by the user. Only relevant when @@ -2297,6 +2300,26 @@ static void io_alloc_init(void) } }
Quoted 5 lines
fs/resctrl/rdtgroup.c static void io_alloc_init(void) · line 2305
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+/* +* Set RESCTRL_INHERIT_USER as the default when the platform supports +* allocation or monitoring. Otherwise leave kernel mode unsupported. This (and why) would be useful to describe in changelog.
Ack.
Quoted 15 lines
fs/resctrl/rdtgroup.c static void io_alloc_init(void) · line 2311
Quoted 7 lines
fs/resctrl/rdtgroup.c +6
-0+*/ +static void resctrl_kmode_init (void ) +{ +if (!resctrl_arch_alloc_capable () && !resctrl_arch_mon_capable ()) +return ; +This check seems unnecessary?
resctrl_kmode_init()will only be called on a system that is capable of allocation or monitoring.
The planned AET changes will change this behavior see
https://lore.kernel.org/lkml/[email protected]/
but in that case it still seems as though initializing the kernel mode as below always needs to be done.
Quoted 2 lines
That begs the question why is
resctrl_kmode_init()needed at all? Why not use a static initializer?
Sure. Will do.
Quoted 8 lines
I find
resctrl_kmode_init()to be potentially confusing since it does *not* actually initializeresctrl_kmode. This is only possible to see two patches later whereget_rdt_resources()is changed so that x86 sets its supported modes and this runs *before*resctrl_kmode_init().If anyone decides one day "this initialization code is missing a
bitmap_zero()" then it will break PLZA.
Sounds good. Will remove resctrl_kmode_init() and statically initialize resctrl_kmode.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 06/18] fs/resctrl: Introduce kernel mode states for resctrl
Hi Babu,
Quoted 8 lines · Babu
Quoted 7 lines · Reinette Chatre
Quoted 4 lines · Babu Moger
+/**
+ * structresctrl_kmode_cfg- Kernel mode configuration
+ * @kmode_sup: Bitmap of supported kernel modes.
+ * @kmode_cur: Currently selected kernel mode.
Quoted 7 lines
Quoted 5 lines
Adding this comment during a second pass ... please consider later motivations about naming of these fields. This field is introduced as "
kmode_cur" but when considering the language used in rest of series "active" seems more appropriate.@kmode_sup could also just be @supported (the "kmode" is redundant).
Sure. Will change
kmode_curto "current".
Please do not use "current" as it is generally used to represent the current running task.
Why do you find "active" not appropriate? The text usually refers to it as the "active". Consider the resctrl.rst text that reads "When the mode is not active ...", changelogs refer to it as the "active" mode, user messages refer to it as the "active" mode, the functions are named rdtgroup_kmode_global_activate()/rdtgroup_kmode_global_deactivate().
Reinette
Babu Moger
reviewerRe: [PATCH v6 06/18] fs/resctrl: Introduce kernel mode states for resctrl
Hi Reinette,
Quoted 19 lines · Reinette Chatre
Hi Babu,
Quoted 8 lines · Babu
Quoted 7 lines · Reinette Chatre
Quoted 4 lines · Babu Moger
+/**
+ * structresctrl_kmode_cfg- Kernel mode configuration
+ * @kmode_sup: Bitmap of supported kernel modes.
+ * @kmode_cur: Currently selected kernel mode.Quoted 7 lines
Quoted 5 lines
Adding this comment during a second pass ... please consider later motivations about naming of these fields. This field is introduced as "
kmode_cur" but when considering the language used in rest of series "active" seems more appropriate.@kmode_sup could also just be @supported (the "kmode" is redundant).
Sure. Will change
kmode_curto "current".
Quoted 9 lines
Please do not use "current" as it is generally used to represent the current running task.
Why do you find "active" not appropriate? The text usually refers to it as the "active". Consider the
resctrl.rsttext that reads "When the mode is not active ...", changelogs refer to it as the "active" mode, user messages refer to it as the "active" mode, the functions are named rdtgroup_kmode_global_activate()/rdtgroup_kmode_global_deactivate().
Yea. My bad. Sorry for the confusion.
@supported and @active looks good.
Thanks
Babu
Babu Moger
reviewerPATCH v6 7/18 fs/resctrl: Introduce resctrl_set_kmode_support() to register supported modes
In reply to Babu MogerThe resctrl subsystem tracks kernel mode configuration. Architectures need to register the supported kernel modes.
Add resctrl_set_kmode_support() so an architecture can register supported kernel modes.
---
v6: Use resctrl_kmode.kmode_sup after the struct flatten. Drop duplicate
kernel-doc from the .c definition and place the function next to resctrl_kmode_init(). Rewrite changelog (not a bugfix).
v5: New patch split from resctrl_kmode_cfg initialization. Register modes
in resctrl_kmode_cfg.caps.kmode_sup using RESCTRL_INHERIT_USER and RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU. Ignore out-of-range mode values.
v4: New patch to initialize supported kernel modes.
https://lore.kernel.org/lkml/[email protected]/ --- fs/resctrl/rdtgroup.c | 6 ++++++ include/linux/resctrl.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+)
fs/resctrl/rdtgroup.c +6 -0
@@ -2320,6 +2320,12 @@ static void resctrl_kmode_init(void) resctrl_kmode.mon =KMODE_ASSIGN ; } +void resctrl_set_kmode_support (enum resctrl_kernel_mode kmode) +{ +if (kmode <RESCTRL_NUM_KERNEL_MODES ) +__set_bit (kmode, resctrl_kmode.kmode_sup); +} +void resctrl_file_fflags_init (const char *config,unsigned long fflags) {struct rftype *rft;
include/linux/resctrl.h +15 -0
@@ -752,6 +752,21 @@ enum resctrl_kernel_mode {#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +/** +* resctrl_set_kmode_support() - Register a supported kernel mode +* @kmode: Kernel mode supported by the architecture. +* +* RESCTRL_INHERIT_USER is registered by resctrl_kmode_init() and does +* not need to be registered again. +* +* Architectures use this interface during resctrl initialization to +* advertise supported kernel modes. Registration of a mode indicates +* architectural support only. The final decision to expose and enable +* a mode is made by resctrl based on system capabilities and +* configuration. +*/ +void resctrl_set_kmode_support (enum resctrl_kernel_mode kmode); +/** * resctrl_arch_configure_kmode_global() - Program RESCTRL_GLOBAL_ENABLE_PER_CPU *
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 07/18] fs/resctrl: Introduce resctrl_set_kmode_support() to register supported modes
Hi Babu,
Quoted 1 line · Babu Moger
The resctrl subsystem tracks kernel mode configuration. Architectures need
resctrl tracks nothing at this point. This is preparatory work to enable resctrl to do so.
Quoted 7 lines
to register the supported kernel modes.
Add
resctrl_set_kmode_support()so an architecture can register supported kernel modes.Signed-off-by Babu Moger <[email protected]>---
...
Quoted 32 lines
--- fs/resctrl/rdtgroup.c | 6 ++++++ include/linux/resctrl.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+)fs/resctrl/rdtgroup.c +6
-0@@ -2320,6 +2320,12 @@ static void resctrl_kmode_init(void) resctrl_kmode.mon =KMODE_ASSIGN ; } +void resctrl_set_kmode_support (enum resctrl_kernel_mode kmode) +{ +if (kmode <RESCTRL_NUM_KERNEL_MODES ) +__set_bit (kmode, resctrl_kmode.kmode_sup); +} +void resctrl_file_fflags_init (const char *config,unsigned long fflags) {struct rftype *rft;include/linux/resctrl.h +2
-0@@ -752,6 +752,21 @@ enum resctrl_kernel_mode {#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +/** +* resctrl_set_kmode_support() - Register a supported kernel mode
include/linux/resctrl.h enum resctrl_kernel_mode { · line 766
Quoted 10 lines
include/linux/resctrl.h +10
-0+* @kmode: Kernel mode supported by the architecture. +* +* RESCTRL_INHERIT_USER is registered by resctrl_kmode_init() and does +* not need to be registered again. +* +* Architectures use this interface during resctrl initialization to +* advertise supported kernel modes. Registration of a mode indicates +* architectural support only. The final decision to expose and enable +* a mode is made by resctrl based on system capabilities and +* configuration.
The last sentence is not clear to me. There is no filtering of any modes before it is exposed to user space. It is the architecture that sets the modes based on the "system capabilities", this is not something the filesystem decides?
include/linux/resctrl.h enum resctrl_kernel_mode { · line 772
Quoted 6 lines
include/linux/resctrl.h +3
-0+*/ +void resctrl_set_kmode_support (enum resctrl_kernel_mode kmode); +/** * resctrl_arch_configure_kmode_global() - Program RESCTRL_GLOBAL_ENABLE_PER_CPU *
Reinette
Re: [PATCH v6 07/18] fs/resctrl: Introduce resctrl_set_kmode_support() to register supported modes
Hi Reinette,
Quoted 7 lines · Reinette Chatre
Hi Babu,
Quoted 1 line · Babu Moger
The resctrl subsystem tracks kernel mode configuration. Architectures need
resctrl tracks nothing at this point. This is preparatory work to enable resctrl to do so.
Yes. That is correct. Hope this looks ok.
Architectures may support different kernel modes that need to be exposed to resctrl.
Add resctrl_set_kmode_support() to allow an architecture to register its supported kernel modes. This is preparatory infrastructure for future kernel mode support in resctrl.
Quoted 50 lines
Quoted 8 lines
to register the supported kernel modes.
Add
resctrl_set_kmode_support()so an architecture can register supported kernel modes.Signed-off-by Babu Moger <[email protected]>---
...
Quoted 39 lines
--- fs/resctrl/rdtgroup.c | 6 ++++++ include/linux/resctrl.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+)fs/resctrl/rdtgroup.c +6
-0@@ -2320,6 +2320,12 @@ static void resctrl_kmode_init(void) resctrl_kmode.mon =KMODE_ASSIGN ; } +void resctrl_set_kmode_support (enum resctrl_kernel_mode kmode) +{ +if (kmode <RESCTRL_NUM_KERNEL_MODES ) +__set_bit (kmode, resctrl_kmode.kmode_sup); +} +void resctrl_file_fflags_init (const char *config,unsigned long fflags) {struct rftype *rft;include/linux/resctrl.h +9
-0@@ -752,6 +752,21 @@ enum resctrl_kernel_mode {#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) +/** +* resctrl_set_kmode_support() - Register a supported kernel mode +* @kmode: Kernel mode supported by the architecture. +* +* RESCTRL_INHERIT_USER is registered by resctrl_kmode_init() and does +* not need to be registered again. +* +* Architectures use this interface during resctrl initialization to +* advertise supported kernel modes. Registration of a mode indicates
Quoted 8 lines
include/linux/resctrl.h enum resctrl_kernel_mode { · line 766
Quoted 3 lines
include/linux/resctrl.h +3
-0+* architectural support only. The final decision to expose and enable +* a mode is made by resctrl based on system capabilities and +* configuration. The last sentence is not clear to me. There is no filtering of any modes before it is exposed to user space. It is the architecture that sets the modes based on the "system capabilities", this is not something the filesystem decides?
Yes. Will remove last two lines.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 07/18] fs/resctrl: Introduce resctrl_set_kmode_support() to register supported modes
Hi Babu,
Quoted 8 lines · Babu
Hi Reinette,
Quoted 5 lines · Reinette Chatre
Hi Babu,
Quoted 1 line · Babu Moger
The resctrl subsystem tracks kernel mode configuration. Architectures need
Quoted 7 lines
Quoted 2 lines
resctrl tracks nothing at this point. This is preparatory work to enable resctrl to do so.
Yes. That is correct. Hope this looks ok.
Architectures may support different kernel modes that need to be exposed to resctrl.
nit: "need to be exposed to user space via resctrl filesystem."?
Quoted 5 lines
Add
resctrl_set_kmode_support()to allow an architecture to register its supported kernel modes. This is preparatory infrastructure for future kernel mode support in resctrl.
Looks good, thank you.
Reinette
Babu Moger
reviewerRe: [PATCH v6 07/18] fs/resctrl: Introduce resctrl_set_kmode_support() to register supported modes
Hi Reinette,
Quoted 14 lines · Reinette Chatre
Hi Babu,
Quoted 11 lines · Babu
Hi Reinette,
Quoted 7 lines · Reinette Chatre
Hi Babu,
Quoted 1 line · Babu Moger
The resctrl subsystem tracks kernel mode configuration. Architectures need
resctrl tracks nothing at this point. This is preparatory work to enable resctrl to do so.
Quoted 6 lines
Quoted 4 lines
Yes. That is correct. Hope this looks ok.
Architectures may support different kernel modes that need to be exposed to resctrl.
nit: "need to be exposed to user space via resctrl filesystem."?
Sure.>
Quoted 8 lines
Quoted 5 lines
Add
resctrl_set_kmode_support()to allow an architecture to register its supported kernel modes. This is preparatory infrastructure for future kernel mode support in resctrl.Looks good, thank you.
Thanks,
Babu
Babu Moger
reviewerPATCH v6 8/18 x86/resctrl: Register RESCTRL_GLOBAL_ENABLE_PER_CPU when PLZA is available
In reply to Babu MogerPLZA (Privilege Level Zero Association) provides the global per-CPU kernel mode, RESCTRL_GLOBAL_ENABLE_PER_CPU, allowing kernel work to use allocation and monitoring associations that differ from user tasks.
Add x86 support for this kernel mode and make it available through the resctrl kernel-mode infrastructure.
---
v6: Use RESCTRL_GLOBAL_ENABLE_PER_CPU.
Rewrite changelog (not a bugfix).
v5: Update the patch to adapt new data structure and resctrl_set_kmode_support()
changes.
v4: New patch to set the supported features during arch init.
--- arch/x86/kernel/cpu/resctrl/core.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/resctrl/core.c +4 -0
@@ -1021,6 +1021,10 @@ static __init bool get_rdt_resources(void) rdt_alloc_capable =get_rdt_alloc_resources (); rdt_mon_capable =get_rdt_mon_resources (); +if (rdt_cpu_has (X86_FEATURE_PLZA ) && + (rdt_alloc_capable || rdt_mon_capable)) +resctrl_set_kmode_support (RESCTRL_GLOBAL_ENABLE_PER_CPU ); +return (rdt_mon_capable || rdt_alloc_capable); }
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 08/18] x86/resctrl: Register RESCTRL_GLOBAL_ENABLE_PER_CPU when PLZA is available
Hi Babu,
Quoted 5 lines · Babu Moger
PLZA (Privilege Level Zero Association) provides the global per-CPU kernel mode,
RESCTRL_GLOBAL_ENABLE_PER_CPU, allowing kernel work to use allocation and monitoring associations that differ from user tasks.Add x86 support for this kernel mode and make it available through the
nit: This patch does not add any support, it just registers the mode with resctrl fs (as the subject already indicates). Didn't patch #5 already claim to add support?
Quoted 4 lines
resctrl kernel-mode infrastructure.
Signed-off-by Babu Moger <[email protected]>---
Reinette
Re: [PATCH v6 08/18] x86/resctrl: Register RESCTRL_GLOBAL_ENABLE_PER_CPU when PLZA is available
Hi Reinette,
Quoted 7 lines · Reinette Chatre
Hi Babu,
Quoted 4 lines · Babu Moger
PLZA (Privilege Level Zero Association) provides the global per-CPU kernel mode,
RESCTRL_GLOBAL_ENABLE_PER_CPU, allowing kernel work to use allocation and monitoring associations that differ from user tasks.
Quoted 5 lines
Quoted 1 line
Add x86 support for this kernel mode and make it available through the
nit: This patch does not add any support, it just registers the mode with resctrl fs (as the subject already indicates). Didn't patch #5 already claim to add support?
Yes. Will change it to:
PLZA (Privilege Level Zero Association) provides the global per-CPU kernel mode, RESCTRL_GLOBAL_ENABLE_PER_CPU, allowing kernel work to use allocation and monitoring associations that differ from user tasks.
Register the PLZA kernel mode with the resctrl kernel mode infrastructure so it can be exposed through the resctrl filesystem.
Thanks
Babu
Babu Moger
reviewerPATCH v6 9/18 fs/resctrl: Add interface to display kernel mode status
In reply to Babu MogerResctrl kernel modes control how allocation and monitoring associations are applied in kernel mode relative to user mode.
Add info/kernel_mode to expose the supported and active kernel modes via the resctrl filesystem. Supported modes are listed one per line, with the active mode enclosed in square brackets.
Document the interface in Documentation/filesystems/resctrl.rst.
---
v6: Rewrote the changelog to make it as feature and not as a bug fix.
Update the code to use the new name "global_enable_per_cpu". Display ctrl or mon only when allocation or monitoring is supportd.
v5: Use resctrl_kcfg.caps and resctrl_kcfg.active after the struct split
from patch 0006. Rename resctrl_kmode_bind_str() to resctrl_kmode_state_str() and ctrl_bind/mon_bind to ctrl_state/mon_state. Used info_kn_lock()/info_kn_unlock().
Add documentation update in resctrl.rst.
v4: Fixed the display of inherit_ctrl_and_mon policy. It is not
associated with any group.
Added "uninitialized" for the non-active group. Rewrote the changelog.
v3: New patch to handle the changed interface file info/kernel_mode.
Changed the group name to "none" if kmode binding is not done. Reinette suggested "uninitialized". "none" seemed more relevent.
--- Documentation/filesystems/resctrl.rst | 48 +++++++++++++ fs/resctrl/rdtgroup.c | 100 ++++++++++++++++++++++++++ 2 files changed, 148 insertions(+)
Documentation/filesystems/resctrl.rst +48 -0
@@ -527,6 +527,54 @@ conveyed in the error returns from file operations. E.g. # cat info/last_cmd_status mask f7 has non-consecutive 1-bits +"kernel_mode": + In the top level of the "info" directory, "kernel_mode" lists the + kernel modes supported by the system, one per line, with the active + mode enclosed in square brackets. A kernel mode determines the + allocation and monitoring associations when a task switches from + user mode to kernel mode. + + Possible kernel modes are: + + "inherit_user": + Kernel mode work uses the allocation and monitoring associations + of the user-space task on whose behalf it runs. + + "global_enable_per_cpu": + Kernel mode work uses the allocation and/or monitoring + association of a backing CTRL_MON or MON group. The mode can + be activated or deactivated per CPU. The line contains group= + and whichever of ctrl= and mon= the platform supports:: + + global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;group=<CTRL_MON>/<MON>/ + + "ctrl": + "assign" if kernel mode work uses the allocation + association of the resource group named by "group", + "inherit" if it uses the allocation association of + the user-space task. Present only on systems that + support allocation. + "mon": + "assign" if kernel mode work uses the monitoring + association of the resource group named by "group", + "inherit" if it uses the monitoring association of + the user-space task. Present only on systems that + support monitoring. + "group": + Path of the resource group, relative to the resctrl + mount point. A CTRL_MON group is shown as <CTRL_MON>//, + a MON group as <CTRL_MON>/<MON>/. + + When the mode is not active, the parameters are the defaults + used if it is activated without new values. + + Example of a system that supports allocation and monitoring, with + default mode inherit_user:: + + # cat info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Resource alloc and monitor groups =================================
fs/resctrl/rdtgroup.c +100 -0
112 lines not on this page · raw message
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 09/18] fs/resctrl: Add interface to display kernel mode status
Hi Babu,
Quoted 1 line · Babu Moger
Resctrl kernel modes control how allocation and monitoring associations
"allocation and monitoring associations" - unclear what this refers to at this point.
Quoted 4 lines
are applied in kernel mode relative to user mode.
Add info/kernel_mode to expose the supported and active kernel modes via the resctrl filesystem. Supported modes are listed one per line, with the
(needs imperative)
Quoted 3 lines
active mode enclosed in square brackets.
Document the interface in
Documentation/filesystems/resctrl.rst.
Above sentence is not necessary, it is obvious from the patch.
Quoted 3 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 10 lines
--- Documentation/filesystems/resctrl.rst | 48 +++++++++++++ fs/resctrl/rdtgroup.c | 100 ++++++++++++++++++++++++++ 2 files changed, 148 insertions(+)Documentation/filesystems/resctrl.rst +0
-0
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 531
Quoted 5 lines
Documentation/filesystems/resctrl.rst +2
-0@@ -527,6 +527,54 @@ conveyed in the error returns from file operations. E.g. # cat info/last_cmd_status mask f7 has non-consecutive 1-bits +"kernel_mode": + In the top level of the "info" directory, "kernel_mode" lists the
Note that just above this addition the documentation reads: "Finally, in the top level of the "info" directory there is a file named "last_cmd_status"." This addition thus creates a contradiction by adding another file after the "Finally". Could you please rework that portion of the documentation to have an introduction for the files in the top level info directory and make it clear how there are two files in this directory, similar to how the other directories are documented?
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 534
Quoted 3 lines
Documentation/filesystems/resctrl.rst +3
-0+ kernel modes supported by the system, one per line, with the active + mode enclosed in square brackets. A kernel mode determines the + allocation and monitoring associations when a task switches from
Would user space know what "allocation and monitoring associations" means?
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 546
Quoted 12 lines
Documentation/filesystems/resctrl.rst +12
-0+ user mode to kernel mode. + + Possible kernel modes are: + + "inherit_user": + Kernel mode work uses the allocation and monitoring associations + of the user-space task on whose behalf it runs. + + "global_enable_per_cpu": + Kernel mode work uses the allocation and/or monitoring + association of a backing CTRL_MON or MON group. The mode can + be activated or deactivated per CPU. The line contains group=
Having a global "activate"/"deactivate" as well as a per CPU "activate"/"deactivate" is confusing. The series switches between language here but I find other places that refer to the global "activate"/"deactivate" and then per CPU "enable"/"disable" to be easier to follow. Doing so will match the text of the "kmode_cpus" file that reads "The association is enabled on CPUs added to the mask and disabled on CPUs removed".
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 556
Quoted 10 lines
Documentation/filesystems/resctrl.rst +10
-0+ and whichever of ctrl= and mon= the platform supports:: + + global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;group=<CTRL_MON>/<MON>/ + + "ctrl": + "assign" if kernel mode work uses the allocation + association of the resource group named by "group", + "inherit" if it uses the allocation association of + the user-space task. Present only on systems that + support allocation.
ok - this is already late in the series but this seems to make it clear that "allocation association" means the portions of resources allocated to this group. Thus the earlier " enum kmode_state - Control or monitoring association" is wrong?
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 565
Quoted 9 lines
Documentation/filesystems/resctrl.rst +9
-0+ "mon": + "assign" if kernel mode work uses the monitoring + association of the resource group named by "group", + "inherit" if it uses the monitoring association of + the user-space task. Present only on systems that + support monitoring. + "group": + Path of the resource group, relative to the resctrl + mount point. A CTRL_MON group is shown as <CTRL_MON>//,
Shouldn't it just be <CTRL_MON>/ ?
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 569
Quoted 4 lines
Documentation/filesystems/resctrl.rst +4
-0+ a MON group as <CTRL_MON>/<MON>/. + + When the mode is not active, the parameters are the defaults + used if it is activated without new values.
"parameters are the defaults" seems to conflate two things: (a) the supported parameters, and (2) the default values of those supported parameters.
Quoted 92 lines
Documentation/filesystems/resctrl.rst +8
-0+ + Example of a system that supports allocation and monitoring, with + default mode inherit_user:: + + # cat info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Resource alloc and monitor groups =================================fs/resctrl/rdtgroup.c +73
-0@@ -993,6 +993,99 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,return 0 ; } +/* Names used in info/kernel_mode; indexed by enum resctrl_kernel_mode */ +static const char *const resctrl_kmode_str[] = { + [RESCTRL_INHERIT_USER ] ="inherit_user" , + [RESCTRL_GLOBAL_ENABLE_PER_CPU ] ="global_enable_per_cpu" +}; + +static_assert (ARRAY_SIZE (resctrl_kmode_str) ==RESCTRL_NUM_KERNEL_MODES ); + +static const char *resctrl_kmode_state_str (enum kmode_state state) +{ +return state ==KMODE_ASSIGN ?"assign" :"inherit" ; +} + +static void resctrl_kmode_group_path (struct rdtgroup *rdtgrp, +const char **ctrl,const char **mon) +{ + *ctrl ="" ; + *mon ="" ; + +if (rdtgrp->type ==RDTMON_GROUP ) { + *ctrl =rdt_kn_name (rdtgrp->mon.parent->kn); + *mon =rdt_kn_name (rdtgrp->kn); + }else { + *ctrl =rdt_kn_name (rdtgrp->kn); + } +} + +/** +* resctrl_kernel_mode_show() - Display supported and active kernel modes +* @of: kernfs open file +* @seq: output seq_file +* @v: unused +* +* Lists one line per mode and brackets the active mode. inherit_user +* has no parameters. global_enable_per_cpu prints ctrl= only when +* allocation is supported and mon= only when monitoring is supported, +* then group=. +* +* Return: 0 on success, or -ENOENT on error. +*/ +static int resctrl_kernel_mode_show (struct kernfs_open_file *of, +struct seq_file *seq,void *v) +{ +const char *ctrl_grp, *mon_grp; +enum resctrl_kernel_mode mode; +bool active; +char sep; + +if (!info_kn_lock (of->kn)) +return -ENOENT ; + +for (mode =0 ; mode <RESCTRL_NUM_KERNEL_MODES ; mode++) { +if (!test_bit (mode, resctrl_kmode.kmode_sup)) +continue ; + + active = resctrl_kmode.kmode_cur == mode; + +seq_printf (seq, active ?"[%s" :"%s" , resctrl_kmode_str[mode]); + +if (mode ==RESCTRL_GLOBAL_ENABLE_PER_CPU ) { + ctrl_grp ="" ; + mon_grp ="" ; +if (active) { +if (resctrl_kmode.rdtgrp) +resctrl_kmode_group_path (resctrl_kmode.rdtgrp, + &ctrl_grp, &mon_grp); +else +pr_warn ("%s active without a resource group\n" , + resctrl_kmode_str[mode]); + } + + sep =':' ; +if (resctrl_arch_alloc_capable ()) {
fs/resctrl/rdtgroup.c static int rdt_last_cmd_status_show(struct kernfs_open_file *of, · line 1078
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+seq_printf (seq,"%cctrl=%s" , sep, +resctrl_kmode_state_str (resctrl_kmode.ctrl)); + sep =';' ; + } +if (resctrl_arch_mon_capable ()) { +seq_printf (seq,"%cmon=%s" , sep, +resctrl_kmode_state_str (resctrl_kmode.mon)); + sep =';' ; + } +seq_printf (seq,"%cgroup=%s/%s/" , sep, ctrl_grp, mon_grp);
Looks like this will print a monitoring group on a system that does not support monitoring? I understand that the monitoring group will be the empty string in this scenario but in resctrl that has meaning of "default monitoring group" so printing this when monitoring is not supported is unexpected.
I also do not expect the monitoring group to be displayed if "mon=inherit" since that presents a contradiction with stating that "monitoring group is inherited" while printing a monitoring group.
Quoted 17 lines
fs/resctrl/rdtgroup.c +10
-0+ } + +seq_puts (seq, active ?"]\n" :"\n" ); + } + +info_kn_unlock (of->kn); + +return 0 ; +} +void *rdt_kn_parent_priv (struct kernfs_node *kn) {/* @@ -1978,6 +2071,13 @@ static struct rftype res_common_files[] = { .seq_show = rdt_last_cmd_status_show, .fflags = RFTYPE_TOP_INFO, },
fs/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 2083
Quoted 10 lines
fs/resctrl/rdtgroup.c +7
-0+ { + .name = "kernel_mode", + .mode = 0444, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = resctrl_kernel_mode_show, + .fflags = RFTYPE_TOP_INFO, + }, { .name = "mbm_assign_on_mkdir", .mode = 0644,
Reinette
Re: [PATCH v6 09/18] fs/resctrl: Add interface to display kernel mode status
Hi Reinette,
Quoted 7 lines · Reinette Chatre
Hi Babu,
Quoted 1 line · Babu Moger
Resctrl kernel modes control how allocation and monitoring associations
"allocation and monitoring associations" - unclear what this refers to at this point.
Hmm.. Not sure what other alternative.
Quoted 7 lines
Quoted 4 lines
are applied in kernel mode relative to user mode.
Add info/kernel_mode to expose the supported and active kernel modes via the resctrl filesystem. Supported modes are listed one per line, with the
(needs imperative)
Sure.
Quoted 5 lines
Quoted 3 lines
active mode enclosed in square brackets.
Document the interface in
Documentation/filesystems/resctrl.rst.Above sentence is not necessary, it is obvious from the patch.
Sure.
A resctrl kernel mode enables kernel work to use different allocation and monitoring associations than the originating user task.
Add info/kernel_mode to expose the supported and active kernel modes through the resctrl filesystem. List supported modes one per line, with the active mode enclosed in square brackets.
Quoted 20 lines
Quoted 4 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 13 lines
--- Documentation/filesystems/resctrl.rst | 48 +++++++++++++ fs/resctrl/rdtgroup.c | 100 ++++++++++++++++++++++++++ 2 files changed, 148 insertions(+)Documentation/filesystems/resctrl.rst +0
-0@@ -527,6 +527,54 @@ conveyed in the error returns from file operations. E.g. # cat info/last_cmd_status mask f7 has non-consecutive 1-bits
Quoted 10 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 531
Quoted 2 lines
Documentation/filesystems/resctrl.rst +2
-0+"kernel_mode": + In the top level of the "info" directory, "kernel_mode" lists theNote that just above this addition the documentation reads: "Finally, in the top level of the "info" directory there is a file named "
last_cmd_status"." This addition thus creates a contradiction by adding another file after the "Finally". Could you please rework that portion of the documentation to have an introduction for the files in the top level info directory and make it clear how there are two files in this directory, similar to how the other directories are documented?
Sure. Will do. Probably separate patch to change "last_cmd_status".
Quoted 7 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 534
Quoted 4 lines
Documentation/filesystems/resctrl.rst +3
-0+ kernel modes supported by the system, one per line, with the active + mode enclosed in square brackets. A kernel mode determines the + allocation and monitoring associations when a task switches fromWould user space know what "allocation and monitoring associations" means?
Will add a line about association means.
Quoted 11 lines
Quoted 11 lines
Documentation/filesystems/resctrl.rst +11
-0+ user mode to kernel mode. + + Possible kernel modes are: + + "inherit_user": + Kernel mode work uses the allocation and monitoring associations + of the user-space task on whose behalf it runs. + + "global_enable_per_cpu": + Kernel mode work uses the allocation and/or monitoring + association of a backing CTRL_MON or MON group. The mode can
Quoted 8 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 546
Quoted 1 line
Documentation/filesystems/resctrl.rst +1
-0+ be activated or deactivated per CPU. The line contains group=Having a global "activate"/"deactivate" as well as a per CPU "activate"/"deactivate" is confusing. The series switches between language here but I find other places that refer to the global "activate"/"deactivate" and then per CPU "enable"/"disable" to be easier to follow. Doing so will match the text of the "
kmode_cpus" file that reads "The association is enabled on CPUs added to the mask and disabled on CPUs removed".
Sure.
Quoted 15 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 556
Quoted 11 lines
Documentation/filesystems/resctrl.rst +10
-0+ and whichever of ctrl= and mon= the platform supports:: + + global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;group=<CTRL_MON>/<MON>/ + + "ctrl": + "assign" if kernel mode work uses the allocation + association of the resource group named by "group", + "inherit" if it uses the allocation association of + the user-space task. Present only on systems that + support allocation.ok - this is already late in the series but this seems to make it clear that "allocation association" means the portions of resources allocated to this group. Thus the earlier " enum
kmode_state- Control or monitoring association" is wrong?
I think, it should be " enum kmode_state - Allocation or monitoring association"
Quoted 12 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 565
Quoted 10 lines
Documentation/filesystems/resctrl.rst +9
-0+ "mon": + "assign" if kernel mode work uses the monitoring + association of the resource group named by "group", + "inherit" if it uses the monitoring association of + the user-space task. Present only on systems that + support monitoring. + "group": + Path of the resource group, relative to the resctrl + mount point. A CTRL_MON group is shown as <CTRL_MON>//,Shouldn't it just be <CTRL_MON>/ ?
Or We can say "<CTRL_MON>/<MON>/" to be generic for both cases.
"The group is shown as "<CTRL_MON>/<MON>/".
Quoted 10 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 569
Quoted 5 lines
Documentation/filesystems/resctrl.rst +4
-0+ a MON group as <CTRL_MON>/<MON>/. + + When the mode is not active, the parameters are the defaults + used if it is activated without new values."parameters are the defaults" seems to conflate two things: (a) the supported parameters, and (2) the default values of those supported parameters.
When the mode is not active, the output shows the supported parameters and their default values, which are used if the mode is activated without new values.
Quoted 99 lines
Quoted 99 lines
Documentation/filesystems/resctrl.rst +8
-0+ + Example of a system that supports allocation and monitoring, with + default mode inherit_user:: + + # cat info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Resource alloc and monitor groups =================================fs/resctrl/rdtgroup.c +80
-0@@ -993,6 +993,99 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,return 0 ; } +/* Names used in info/kernel_mode; indexed by enum resctrl_kernel_mode */ +static const char *const resctrl_kmode_str[] = { + [RESCTRL_INHERIT_USER ] ="inherit_user" , + [RESCTRL_GLOBAL_ENABLE_PER_CPU ] ="global_enable_per_cpu" +}; + +static_assert (ARRAY_SIZE (resctrl_kmode_str) ==RESCTRL_NUM_KERNEL_MODES ); + +static const char *resctrl_kmode_state_str (enum kmode_state state) +{ +return state ==KMODE_ASSIGN ?"assign" :"inherit" ; +} + +static void resctrl_kmode_group_path (struct rdtgroup *rdtgrp, +const char **ctrl,const char **mon) +{ + *ctrl ="" ; + *mon ="" ; + +if (rdtgrp->type ==RDTMON_GROUP ) { + *ctrl =rdt_kn_name (rdtgrp->mon.parent->kn); + *mon =rdt_kn_name (rdtgrp->kn); + }else { + *ctrl =rdt_kn_name (rdtgrp->kn); + } +} + +/** +* resctrl_kernel_mode_show() - Display supported and active kernel modes +* @of: kernfs open file +* @seq: output seq_file +* @v: unused +* +* Lists one line per mode and brackets the active mode. inherit_user +* has no parameters. global_enable_per_cpu prints ctrl= only when +* allocation is supported and mon= only when monitoring is supported, +* then group=. +* +* Return: 0 on success, or -ENOENT on error. +*/ +static int resctrl_kernel_mode_show (struct kernfs_open_file *of, +struct seq_file *seq,void *v) +{ +const char *ctrl_grp, *mon_grp; +enum resctrl_kernel_mode mode; +bool active; +char sep; + +if (!info_kn_lock (of->kn)) +return -ENOENT ; + +for (mode =0 ; mode <RESCTRL_NUM_KERNEL_MODES ; mode++) { +if (!test_bit (mode, resctrl_kmode.kmode_sup)) +continue ; + + active = resctrl_kmode.kmode_cur == mode; + +seq_printf (seq, active ?"[%s" :"%s" , resctrl_kmode_str[mode]); + +if (mode ==RESCTRL_GLOBAL_ENABLE_PER_CPU ) { + ctrl_grp ="" ; + mon_grp ="" ; +if (active) { +if (resctrl_kmode.rdtgrp) +resctrl_kmode_group_path (resctrl_kmode.rdtgrp, + &ctrl_grp, &mon_grp); +else +pr_warn ("%s active without a resource group\n" , + resctrl_kmode_str[mode]); + } + + sep =':' ; +if (resctrl_arch_alloc_capable ()) { +seq_printf (seq,"%cctrl=%s" , sep, +resctrl_kmode_state_str (resctrl_kmode.ctrl)); + sep =';' ; + } +if (resctrl_arch_mon_capable ()) { +seq_printf (seq,"%cmon=%s" , sep, +resctrl_kmode_state_str (resctrl_kmode.mon));
Quoted 9 lines
fs/resctrl/rdtgroup.c static int rdt_last_cmd_status_show(struct kernfs_open_file *of, · line 1078
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+ sep =';' ; + } +seq_printf (seq,"%cgroup=%s/%s/" , sep, ctrl_grp, mon_grp);Looks like this will print a monitoring group on a system that does not support monitoring? I understand that the monitoring group will be the empty string in this scenario but in resctrl that has meaning of "default monitoring group" so printing this when monitoring is not supported is unexpected.
Ok. If monitoring not supported it will be "CTRL_MON/" (Example group=ctrl1/") and then default group is "/".
Is that what you are suggesting?
Quoted 3 lines
I also do not expect the monitoring group to be displayed if "mon=inherit" since that presents a contradiction with stating that "monitoring group is inherited" while printing a monitoring group.
Yes. We should not display "mon=inherit" when monitoring in not supported. Will check on this.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 09/18] fs/resctrl: Add interface to display kernel mode status
Hi Babu,
Quoted 19 lines · Babu
Quoted 17 lines · Reinette Chatre
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 556
Quoted 10 lines · Babu Moger
+ and whichever of ctrl= and mon= the platform supports::
Documentation/filesystems/resctrl.rst +9
-0+ + global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;group=<CTRL_MON>/<MON>/ + + "ctrl": + "assign" if kernel mode work uses the allocation + association of the resource group named by "group", + "inherit" if it uses the allocation association of + the user-space task. Present only on systems that + support allocation.ok - this is already late in the series but this seems to make it clear that "allocation association" means the portions of resources allocated to this group. Thus the earlier " enum
kmode_state- Control or monitoring association" is wrong?
Quoted 1 line
I think, it should be " enum
kmode_state- Allocation or monitoring association"
Please don't. This is exactly the problem that I keep coming back to. If you change the name as you suggest then you solidify that you use the same term to mean two different things. Specifically, what above change implies is that the reader is left to decipher when:
"allocation and monitoring association" means
MSR_IA32_PQR_PLZA_ASSOC.closid and MSR_IA32_PQR_PLZA_ASSOC.rmid
vs when
"allocation and monitoring association" means
MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
+ "mon":
+ "assign" if kernel mode work uses the monitoring + association of the resource group named by "group", + "inherit" if it uses the monitoring association of + the user-space task. Present only on systems that + support monitoring.
+ "group":
+ Path of the resource group, relative to the resctrl + mount point. ACTRL_MONgroup is shown as <CTRL_MON>//,
Quoted 5 lines
Quoted 1 line
Shouldn't it just be <CTRL_MON>/ ?
Or We can say "<CTRL_MON>/<MON>/" to be generic for both cases.
"The group is shown as "<CTRL_MON>/<MON>/".
No, this depends on whether monitoring is enabled or not, or (if monitoring is supported) whether mon=inherit.
...
Quoted 20 lines
Quoted 14 lines
Quoted 5 lines
+
+ sep = ':';
+ if (resctrl_arch_alloc_capable()) {
+ seq_printf(seq, "%cctrl=%s", sep,
+resctrl_kmode_state_str(resctrl_kmode.ctrl));Quoted 8 lines
+ sep = ';';
+ }
+ if (resctrl_arch_mon_capable()) {
+ seq_printf(seq, "%cmon=%s", sep,
+resctrl_kmode_state_str(resctrl_kmode.mon)); + sep = ';';
+ }
+seq_printf(seq, "%cgroup=%s/%s/", sep, ctrl_grp, mon_grp);Quoted 5 lines
Looks like this will print a monitoring group on a system that does not support monitoring? I understand that the monitoring group will be the empty string in this scenario but in resctrl that has meaning of "default monitoring group" so printing this when monitoring is not supported is unexpected.
Quoted 3 lines
Ok. If monitoring not supported it will be "CTRL_MON/" (Example group=ctrl1/") and then default group is "/".
Is that what you are suggesting?
Yes. This matches the proc output.
Quoted 8 lines
Quoted 5 lines
I also do not expect the monitoring group to be displayed if "mon=inherit" since that presents a contradiction with stating that "monitoring group is inherited" while printing a monitoring group.
Yes. We should not display "mon=inherit" when monitoring in not supported. Will check on this.
This is needed yes, but what I was actually referring to was that if "mon=inherit" then the group parameter should not include a monitoring group. For example, "group=ctrl/". Including the name of a monitoring group when "mon=inherit" is confusing.
Reinette
Babu Moger
reviewerRe: [PATCH v6 09/18] fs/resctrl: Add interface to display kernel mode status
Hi Reinette,
Quoted 29 lines · Reinette Chatre
Hi Babu,
Quoted 19 lines · Babu
Quoted 17 lines · Reinette Chatre
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 556
Quoted 10 lines · Babu Moger
+ and whichever of ctrl= and mon= the platform supports::
Documentation/filesystems/resctrl.rst +9
-0+ + global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;group=<CTRL_MON>/<MON>/ + + "ctrl": + "assign" if kernel mode work uses the allocation + association of the resource group named by "group", + "inherit" if it uses the allocation association of + the user-space task. Present only on systems that + support allocation.ok - this is already late in the series but this seems to make it clear that "allocation association" means the portions of resources allocated to this group. Thus the earlier " enum
kmode_state- Control or monitoring association" is wrong?Quoted 1 line
I think, it should be " enum
kmode_state- Allocation or monitoring association"Please don't. This is exactly the problem that I keep coming back to. If you change the name as you suggest then you solidify that you use the same term to mean two different things. Specifically, what above change implies is that the reader is left to decipher when:
Quoted 9 lines
"allocation and monitoring association" means
MSR_IA32_PQR_PLZA_ASSOC.closid and MSR_IA32_PQR_PLZA_ASSOC.rmidvs when
"allocation and monitoring association" means
MSR_IA32_PQR_PLZA_ASSOC.closid_en and MSR_IA32_PQR_PLZA_ASSOC.rmid_en
That is correct. It is confusing. Let me try to revise these terms in next revision and go from there.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
+ "mon":
+ "assign" if kernel mode work uses the monitoring + association of the resource group named by "group", + "inherit" if it uses the monitoring association of + the user-space task. Present only on systems that + support monitoring.
+ "group":
+ Path of the resource group, relative to the resctrl + mount point. ACTRL_MONgroup is shown as <CTRL_MON>//,
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Shouldn't it just be <CTRL_MON>/ ?
Or We can say "<CTRL_MON>/<MON>/" to be generic for both cases.
"The group is shown as "<CTRL_MON>/<MON>/".
No, this depends on whether monitoring is enabled or not, or (if monitoring is supported) whether mon=inherit.
ok. Will try to handle it.
Quoted 36 lines
...
Quoted 20 lines
Quoted 14 lines
Quoted 5 lines
+
+ sep = ':';
+ if (resctrl_arch_alloc_capable()) {
+ seq_printf(seq, "%cctrl=%s", sep,
+resctrl_kmode_state_str(resctrl_kmode.ctrl));Quoted 8 lines
+ sep = ';';
+ }
+ if (resctrl_arch_mon_capable()) {
+ seq_printf(seq, "%cmon=%s", sep,
+resctrl_kmode_state_str(resctrl_kmode.mon)); + sep = ';';
+ }
+seq_printf(seq, "%cgroup=%s/%s/", sep, ctrl_grp, mon_grp);Quoted 5 lines
Looks like this will print a monitoring group on a system that does not support monitoring? I understand that the monitoring group will be the empty string in this scenario but in resctrl that has meaning of "default monitoring group" so printing this when monitoring is not supported is unexpected.
Quoted 3 lines
Ok. If monitoring not supported it will be "CTRL_MON/" (Example group=ctrl1/") and then default group is "/".
Is that what you are suggesting?
Yes. This matches the proc output.
Quoted 6 lines
Quoted 5 lines
I also do not expect the monitoring group to be displayed if "mon=inherit" since that presents a contradiction with stating that "monitoring group is inherited" while printing a monitoring group.
Quoted 6 lines
Quoted 2 lines
Yes. We should not display "mon=inherit" when monitoring in not supported. Will check on this.
This is needed yes, but what I was actually referring to was that if "mon=inherit" then the group parameter should not include a monitoring group. For example, "group=ctrl/". Including the name of a monitoring group when "mon=inherit" is confusing.
Good point. This is something new that I need to handle here, so I'll work on fixing it.
Thanks,
Babu
Babu
Babu Moger
reviewerPATCH v6 10/18 fs/resctrl: Add support for hidden resource group files
In reply to Babu MogerSome per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Creating them only at activation would complicate group setup and teardown, while exposing them on every group would show empty files with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
---
v6: Removed resctrl_hidden_files_set_visible() from the patch.
It will be separate patch.
Re-wrote the changelog.
v5: New patch to add support for creating hidden files.
--- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 3 +++ 2 files changed, 5 insertions(+)
fs/resctrl/internal.h +2 -0
@@ -283,6 +283,7 @@ extern int max_name_width;* @kf_ops: File operations * @flags: File specific RFTYPE_FLAGS_* flags * @fflags: File specific RFTYPE_* flags +* @hidden: Hide file at creation; visibility may be restored later * @seq_show: Show content of the file * @write: Write to the file */
@@ -292,6 +293,7 @@ struct rftype {const struct kernfs_ops *kf_ops;unsigned long flags;unsigned long fflags; +bool hidden;int (*seq_show)(struct kernfs_open_file *of,struct seq_file *sf,void *v);
fs/resctrl/rdtgroup.c +3 -0
@@ -308,6 +308,9 @@ static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft)return ret; } +if (rft->hidden) +kernfs_show (kn, false); +return 0 ; }
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 10/18] fs/resctrl: Add support for hidden resource group files
Hi Babu,
Quoted 2 lines · Babu Moger
Some per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Could this elaborate more about how the files depend on the kernel mode and why they may not always be meaningful?
Quoted 2 lines
Creating them only at activation would complicate group setup and
Why would it complicate group setup and teardown? I think it would rather complicate mode activation and de-activation but since there is no detail about how this will complicate group setup it is difficult to compare. It is difficult to reason about a patch when the motivation is vague.
Quoted 1 line
teardown, while exposing them on every group would show empty files
"show empty files" - technically these files, as they are implemented, will not be empty but return errors
Quoted 3 lines
with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
Missing a "why".
This can append to describe how this adds the foundational support in preparation for features to restore visibility when the feature's files need to be exposed to user space.
Quoted 4 lines
Suggested-by Reinette Chatre <[email protected]>Signed-off-by Babu Moger <[email protected]>---
Reinette
Re: [PATCH v6 10/18] fs/resctrl: Add support for hidden resource group files
Hi Reinette,
Quoted 23 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu Moger
Some per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Could this elaborate more about how the files depend on the kernel mode and why they may not always be meaningful?
Quoted 2 lines
Creating them only at activation would complicate group setup and
Why would it complicate group setup and teardown? I think it would rather complicate mode activation and de-activation but since there is no detail about how this will complicate group setup it is difficult to compare. It is difficult to reason about a patch when the motivation is vague.
Quoted 1 line
teardown, while exposing them on every group would show empty files
"show empty files" - technically these files, as they are implemented, will not be empty but return errors
Quoted 9 lines
Quoted 3 lines
with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
Missing a "why".
This can append to describe how this adds the foundational support in preparation for features to restore visibility when the feature's files need to be exposed to user space.
Will rephrase the whole changelog:
"Some per-group resctrl files are only applicable to resource groups with an active kernel mode association. Accessing these files before a kernel mode association is established would result in errors and does not provide useful information.
Creating and removing these files when a kernel mode is activated or deactivated would add complexity to the mode management path. Add a hidden property to struct rftype so files can be created with the resource group and exposed only when they become applicable.
This provides the infrastructure needed to control file visibility for future kernel-mode-specific resctrl interfaces."
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 10/18] fs/resctrl: Add support for hidden resource group files
Hi Babu,
Quoted 32 lines · Babu
Quoted 21 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
Some per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Could this elaborate more about how the files depend on the kernel mode and why they may not always be meaningful?
Quoted 2 lines
Creating them only at activation would complicate group setup and
Why would it complicate group setup and teardown? I think it would rather complicate mode activation and de-activation but since there is no detail about how this will complicate group setup it is difficult to compare. It is difficult to reason about a patch when the motivation is vague.
Quoted 1 line
teardown, while exposing them on every group would show empty files
"show empty files" - technically these files, as they are implemented, will not be empty but return errors
Quoted 9 lines
Quoted 3 lines
with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
Missing a "why".
This can append to describe how this adds the foundational support in preparation for features to restore visibility when the feature's files need to be exposed to user space.
Quoted 6 lines
Will rephrase the whole changelog:
"Some per-group resctrl files are only applicable to resource groups with an active kernel mode association. Accessing these files before a kernel mode association is established would result in errors and does not provide useful information.
What does "and does not provide useful information" refer to? Does this mean that the errors are not useful?
Quoted 5 lines
Creating and removing these files when a kernel mode is activated or deactivated would add complexity to the mode management path. Add a hidden property to struct rftype so files can be created with the resource group and exposed only when they become applicable.
Please separate the problem and solution descriptions.
Quoted 3 lines
This provides the infrastructure needed to control file visibility for future kernel-mode-specific resctrl interfaces."
Reinette
Babu Moger
reviewerRe: [PATCH v6 10/18] fs/resctrl: Add support for hidden resource group files
Hi Reinette,
Quoted 37 lines · Reinette Chatre
Hi Babu,
Quoted 34 lines · Babu
Quoted 21 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
Some per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Could this elaborate more about how the files depend on the kernel mode and why they may not always be meaningful?
Quoted 2 lines
Creating them only at activation would complicate group setup and
Why would it complicate group setup and teardown? I think it would rather complicate mode activation and de-activation but since there is no detail about how this will complicate group setup it is difficult to compare. It is difficult to reason about a patch when the motivation is vague.
Quoted 1 line
teardown, while exposing them on every group would show empty files
"show empty files" - technically these files, as they are implemented, will not be empty but return errors
Quoted 9 lines
Quoted 3 lines
with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
Missing a "why".
This can append to describe how this adds the foundational support in preparation for features to restore visibility when the feature's files need to be exposed to user space.Will rephrase the whole changelog:
Quoted 7 lines
Quoted 4 lines
"Some per-group resctrl files are only applicable to resource groups with an active kernel mode association. Accessing these files before a kernel mode association is established would result in errors and does not provide useful information.
What does "and does not provide useful information" refer to? Does this mean that the errors are not useful?
Hmm.. One more attempt:
"Some per-group resctrl files are only applicable when a resource group has an active kernel mode association. Exposing these files before the mode is activated is not useful because they have no meaningful information to provide, while reporting errors on access offers little value. Dynamically creating and removing the files as associations are activated and deactivated would add complexity to the mode management path.
Add a hidden property to struct rftype so the files can be created with the resource group and exposed only when applicable.
This provides the infrastructure needed to control file visibility for future kernel-mode-specific resctrl interfaces."
Quoted 9 lines
Quoted 6 lines
Creating and removing these files when a kernel mode is activated or deactivated would add complexity to the mode management path. Add a hidden property to struct rftype so files can be created with the resource group and exposed only when they become applicable.
Please separate the problem and solution descriptions.
Ack.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 10/18] fs/resctrl: Add support for hidden resource group files
Hi Babu,
Quoted 44 lines · Babu Moger
Quoted 35 lines · Reinette Chatre
Quoted 34 lines · Babu
Quoted 21 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
Some per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Could this elaborate more about how the files depend on the kernel mode and why they may not always be meaningful?
Quoted 2 lines
Creating them only at activation would complicate group setup and
Why would it complicate group setup and teardown? I think it would rather complicate mode activation and de-activation but since there is no detail about how this will complicate group setup it is difficult to compare. It is difficult to reason about a patch when the motivation is vague.
Quoted 1 line
teardown, while exposing them on every group would show empty files
"show empty files" - technically these files, as they are implemented, will not be empty but return errors
Quoted 9 lines
Quoted 3 lines
with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
Missing a "why".
This can append to describe how this adds the foundational support in preparation for features to restore visibility when the feature's files need to be exposed to user space.Will rephrase the whole changelog:
Quoted 7 lines
Quoted 4 lines
"Some per-group resctrl files are only applicable to resource groups with an active kernel mode association. Accessing these files before a kernel mode association is established would result in errors and does not provide useful information.
What does "and does not provide useful information" refer to? Does this mean that the errors are not useful?
Quoted 8 lines
Hmm.. One more attempt:
"Some per-group resctrl files are only applicable when a resource group has an active kernel mode association. Exposing these files before the mode is activated is not useful because they have no meaningful information to provide, while reporting errors on access offers little value. Dynamically creating and removing the files as associations are activated and deactivated would add complexity to the mode management path.
Add a hidden property to struct rftype so the files can be created with the resource group and exposed only when applicable.
This provides the infrastructure needed to control file visibility for future kernel-mode-specific resctrl interfaces."
I still find this motivation vague as it seems to aim to be generic when it requires to be specific since it is needed by the global per-CPU kernel mode support. Consider, for example, in comparison a changelog below that is specific to the problem that needs to be solved and why. Again this is an example that does not take into account the consistent terms that you aim to use in next version:
fs/resctrl: Add support for hidden resource group files
A resctrl file is visible to user space as soon as its resource group directory is activated. A file can only be hidden after it has been created, as is done for the info directory's BMEC event configuration files.
In the global_enable_per_cpu kernel mode, kernel work running on CPUs where the mode is active is allocated resources and/or monitored as part of a single backing resource group. The files needed to display and modify the CPUs on which this kernel mode is active are only meaningful in that group. Visible in every resource group, the files would return errors when accessed in any group other than the one backing the active kernel mode. Creating the files when the kernel mode is activated, and removing them when it is deactivated, would add failure paths to kernel mode activation that showing and hiding existing files does not have.
Allow a resource group file to be marked as hidden so that it is hidden when created, before its directory is activated, and is never visible to user space until resctrl restores its visibility. This provides the foundation in preparation for kernel mode support that shows the kmode_cpus and kmode_cpus_list files only in the resource group backing the active kernel mode.
Reinette
Babu Moger
reviewerRe: [PATCH v6 10/18] fs/resctrl: Add support for hidden resource group files
Hi Reinette,
Quoted 77 lines · Reinette Chatre
Hi Babu,
Quoted 44 lines · Babu Moger
Quoted 35 lines · Reinette Chatre
Quoted 34 lines · Babu
Quoted 21 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
Some per-group resctrl files are only meaningful once a resource group has an active kernel mode association.
Could this elaborate more about how the files depend on the kernel mode and why they may not always be meaningful?
Quoted 2 lines
Creating them only at activation would complicate group setup and
Why would it complicate group setup and teardown? I think it would rather complicate mode activation and de-activation but since there is no detail about how this will complicate group setup it is difficult to compare. It is difficult to reason about a patch when the motivation is vague.
Quoted 1 line
teardown, while exposing them on every group would show empty files
"show empty files" - technically these files, as they are implemented, will not be empty but return errors
Quoted 9 lines
Quoted 3 lines
with no clear purpose.
Add a hidden property to struct rftype to hide files at creation.
Missing a "why".
This can append to describe how this adds the foundational support in preparation for features to restore visibility when the feature's files need to be exposed to user space.Will rephrase the whole changelog:
Quoted 7 lines
Quoted 4 lines
"Some per-group resctrl files are only applicable to resource groups with an active kernel mode association. Accessing these files before a kernel mode association is established would result in errors and does not provide useful information.
What does "and does not provide useful information" refer to? Does this mean that the errors are not useful?
Quoted 8 lines
Hmm.. One more attempt:
"Some per-group resctrl files are only applicable when a resource group has an active kernel mode association. Exposing these files before the mode is activated is not useful because they have no meaningful information to provide, while reporting errors on access offers little value. Dynamically creating and removing the files as associations are activated and deactivated would add complexity to the mode management path.
Add a hidden property to struct rftype so the files can be created with the resource group and exposed only when applicable.
This provides the infrastructure needed to control file visibility for future kernel-mode-specific resctrl interfaces."
I still find this motivation vague as it seems to aim to be generic when it requires to be specific since it is needed by the global per-CPU kernel mode support. Consider, for example, in comparison a changelog below that is specific to the problem that needs to be solved and why. Again this is an example that does not take into account the consistent terms that you aim to use in next version:
fs/resctrl: Add support for hidden resource group files
A resctrl file is visible to user space as soon as its resource group directory is activated. A file can only be hidden after it has been created, as is done for the info directory's BMEC event configuration files.
In the
global_enable_per_cpukernel mode, kernel work running on CPUs where the mode is active is allocated resources and/or monitored as part of a single backing resource group. The files needed to display and modify the CPUs on which this kernel mode is active are only meaningful in that group. Visible in every resource group, the files would return errors when accessed in any group other than the one backing the active kernel mode. Creating the files when the kernel mode is activated, and removing them when it is deactivated, would add failure paths to kernel mode activation that showing and hiding existing files does not have.
Quoted 7 lines
Allow a resource group file to be marked as hidden so that it is hidden when created, before its directory is activated, and is never visible to user space until resctrl restores its visibility. This provides the foundation in preparation for kernel mode support that shows the
kmode_cpusandkmode_cpus_listfiles only in the resource group backing the active kernel mode.
Looks good.
Thanks,
Babu
Babu Moger
reviewerPATCH v6 11/18 fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup
In reply to Babu MogerThe RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode allows tasks to use different allocation and monitoring associations when transitioning from user mode to kernel mode. The mode is enabled/disabled on a per-CPU basis.
Add kmode_cpus and kmode_cpus_list to display the CPUs associated with a kernel mode. These files are exposed only when the global_enable_per_cpu mode is active.
---
v6: Drop rdtgrp::kmode. Rewrite changelog (not a bugfix; association).
https://lore.kernel.org/lkml/[email protected]/
v5: Updated the changelog.
Removed the RDT_MODE_PSEUDO_LOCKED check and added rdtgroup->kmode check. Files are created hidden.
v4: Rewrote the change to be generic.
v3: New patch to add "kmode_cpus" and "kmode_cpus_list" to support
kernel_modes.
--- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
fs/resctrl/internal.h +2 -0
@@ -216,6 +216,7 @@ struct mongroup {* @mon: mongroup related data * @mode: mode of resource group * @mba_mbps_event: input monitoring event id when mba_sc is enabled +* @kmode_cpu_mask: CPUs in this group's kernel-mode association * @plr: pseudo-locked region */ struct rdtgroup {
@@ -229,6 +230,7 @@ struct rdtgroup {struct mongroup mon;enum rdtgrp_mode mode;enum resctrl_event_id mba_mbps_event; +struct cpumask kmode_cpu_mask;struct pseudo_lock_region *plr; };
fs/resctrl/rdtgroup.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 11/18] fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup
Hi Babu,
Quoted 2 lines · Babu Moger
The
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode allows tasks to use different allocation and monitoring associations when transitioning from user mode to
Could "different allocation and monitoring associations" just be "different CLOSID and RMID" (in places where this is what it refers to)? Being specific and consistent with terms would make this so much easier to understand.
Quoted 4 lines
kernel mode. The mode is enabled/disabled on a per-CPU basis.
Add
kmode_cpusandkmode_cpus_listto display the CPUs associated with a kernel mode. These files are exposed only when theglobal_enable_per_cpu
"a kernel mode" -> this is specific to RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode node?
This switches from "RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode" to "global_enable_per_cpu mode" mid changelog.
Quoted 4 lines
mode is active.
Signed-off-by Babu Moger <[email protected]>---
...> ---
fs/resctrl/internal.h struct mongroup { · line 219
Quoted 13 lines
fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)fs/resctrl/internal.h +1
-0@@ -216,6 +216,7 @@ struct mongroup {* @mon: mongroup related data * @mode: mode of resource group * @mba_mbps_event: input monitoring event id when mba_sc is enabled +* @kmode_cpu_mask: CPUs in this group's kernel-mode association
Could there be a caveat that the value is only valid when the resource group is backing the RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode?
Quoted 16 lines
fs/resctrl/internal.h +1
-0* @plr: pseudo-locked region */ struct rdtgroup {@@ -229,6 +230,7 @@ struct rdtgroup {struct mongroup mon;enum rdtgrp_mode mode;enum resctrl_event_id mba_mbps_event; +struct cpumask kmode_cpu_mask;struct pseudo_lock_region *plr; };fs/resctrl/rdtgroup.c +0
-0
fs/resctrl/rdtgroup.c static int rdtgroup_cpus_show(struct kernfs_open_file *of, · line 389
Quoted 5 lines
fs/resctrl/rdtgroup.c +2
-0@@ -385,6 +385,31 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,return ret; } +/* +* Display CPU masks for the kernel-mode associated resource group.
nit: "masks for" -> "mask of"?
Quoted 4 lines
fs/resctrl/rdtgroup.c +4
-0+* Supports both "kmode_cpus" (bitmap format) and "kmode_cpus_list" +* (range list format); the output format is selected accordingly. +* +* Returns -ENOENT on error.
fs/resctrl/rdtgroup.c static int rdtgroup_cpus_show(struct kernfs_open_file *of, · line 403
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+*/ +static int rdtgroup_kmode_cpus_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{ +struct rdtgroup *rdtgrp; +int ret =0 ; + + rdtgrp =rdtgroup_kn_lock_live (of->kn); + +if (!rdtgrp || rdtgrp != resctrl_kmode.rdtgrp)
Could the changelog please help reader understand the patches better? For example, the additional "rdtgrp != resctrl_kmode.rdtgrp" check is subtle but very important to maintain synchronization, but it is never mentioned why this is used.
Quoted 26 lines
fs/resctrl/rdtgroup.c +19
-0+ ret = -ENOENT ; + else + seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n", + cpumask_pr_args(&rdtgrp->kmode_cpu_mask)); +rdtgroup_kn_unlock (of->kn); + +return ret; +} +/* * Update the PGR_ASSOC MSR on all cpus in @cpu_mask, * @@ -2256,6 +2281,23 @@ static struct rftype res_common_files[] = { .flags = RFTYPE_FLAGS_CPUS_LIST, .fflags = RFTYPE_BASE, }, + { + .name = "kmode_cpus", + .mode = 0444, + .hidden = true, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = rdtgroup_kmode_cpus_show, + .fflags = RFTYPE_BASE, + }, + { + .name = "kmode_cpus_list",
fs/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 2303
Quoted 10 lines
fs/resctrl/rdtgroup.c +7
-0+ .mode = 0444, + .hidden = true, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = rdtgroup_kmode_cpus_show, + .flags = RFTYPE_FLAGS_CPUS_LIST, + .fflags = RFTYPE_BASE, + }, { .name = "tasks", .mode = 0644,
Reinette
Re: [PATCH v6 11/18] fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup
Hi Reinette,
Quoted 9 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu Moger
The
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode allows tasks to use different allocation and monitoring associations when transitioning from user mode toCould "different allocation and monitoring associations" just be "different CLOSID and RMID" (in places where this is what it refers to)? Being specific and consistent with terms would make this so much easier to understand.
I avoided using CLOSID and RMID terms in filesystem specific code. If you are ok with that then I will use these terms.
Quoted 9 lines
Quoted 5 lines
kernel mode. The mode is enabled/disabled on a per-CPU basis.
Add
kmode_cpusandkmode_cpus_listto display the CPUs associated with a kernel mode. These files are exposed only when theglobal_enable_per_cpu"a kernel mode" -> this is specific to
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode node?
Sure.
Quoted 3 lines
This switches from "
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode" to "global_enable_per_cpumode" mid changelog.
Will change it.
Quoted 11 lines
Quoted 5 lines
mode is active.
Signed-off-by Babu Moger <[email protected]>---
...> ---
Quoted 4 lines
fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
Quoted 12 lines
fs/resctrl/internal.h struct mongroup { · line 219
Quoted 9 lines
fs/resctrl/internal.h +1
-0@@ -216,6 +216,7 @@ struct mongroup {* @mon: mongroup related data * @mode: mode of resource group * @mba_mbps_event: input monitoring event id when mba_sc is enabled +* @kmode_cpu_mask: CPUs in this group's kernel-mode association Could there be a caveat that the value is only valid when the resource group is backing the
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode?
Sure.
Quoted 20 lines
Quoted 20 lines
fs/resctrl/internal.h +1
-0* @plr: pseudo-locked region */ struct rdtgroup {@@ -229,6 +230,7 @@ struct rdtgroup {struct mongroup mon;enum rdtgrp_mode mode;enum resctrl_event_id mba_mbps_event; +struct cpumask kmode_cpu_mask;struct pseudo_lock_region *plr; };fs/resctrl/rdtgroup.c +0
-0@@ -385,6 +385,31 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,return ret; }
Quoted 4 lines
fs/resctrl/rdtgroup.c static int rdtgroup_cpus_show(struct kernfs_open_file *of, · line 389
Quoted 2 lines
fs/resctrl/rdtgroup.c +2
-0+/* +* Display CPU masks for the kernel-mode associated resource group. nit: "masks for" -> "mask of"?
Sure.
Quoted 12 lines
Quoted 12 lines
fs/resctrl/rdtgroup.c +11
-0+* Supports both "kmode_cpus" (bitmap format) and "kmode_cpus_list" +* (range list format); the output format is selected accordingly. +* +* Returns -ENOENT on error. +*/ +static int rdtgroup_kmode_cpus_show (struct kernfs_open_file *of, +struct seq_file *s,void *v) +{ +struct rdtgroup *rdtgrp; +int ret =0 ; +
Quoted 8 lines
fs/resctrl/rdtgroup.c static int rdtgroup_cpus_show(struct kernfs_open_file *of, · line 403
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+ rdtgrp =rdtgroup_kn_lock_live (of->kn); + +if (!rdtgrp || rdtgrp != resctrl_kmode.rdtgrp)Could the changelog please help reader understand the patches better? For example, the additional "rdtgrp != resctrl_kmode.rdtgrp" check is subtle but very important to maintain synchronization, but it is never mentioned why this is used.
Will add a line in changelog about this check.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 11/18] fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup
Hi Babu,
Quoted 7 lines · Babu
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
On 10/1/26 8:10 AM, Babu Moger wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
The
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode allows tasks to use different allocation and monitoring associations when transitioning from user mode toCould "different allocation and monitoring associations" just be "different CLOSID and RMID" (in places where this is what it refers to)? Being specific and consistent with terms would make this so much easier to understand.
I avoided using CLOSID and RMID terms in filesystem specific code. If you are ok with that then I will use these terms.
Why?
Internally resctrl filesystem has a CLOSID assigned to a control group, RMID assigned to a monitor group. When a user assigns a resource group to the global kernel mode the kernel mode is implicitly assigned a CLOSID and/or RMID. These are all part of the resctrl filesystem design. What is the benefit to avoid these specific terms when explaining the implementation details?
An important distinction is that in this feature the CLOSID and RMID values originate from a CTRL_MON or MON group assigned by user space. Any architecture where there is a dependency between CLOSID and RMID will already have accounted for that during the creation of the resource group. This is something that should be clear from the context when referring to CLOSID and RMID.
The resctrl fs code even uses CLOSID and RMID in the API used to interact with the architecture:
void resctrl_arch_configure_kmode_global(const struct cpumask *cpu_mask,
u32 closid, bool assign_ctrl, u32 rmid, bool assign_mon, bool enable);
The only place where we should avoid using CLOSID and RMID is in anything exposed to user space since CLOSID and RMID has different meanings on different architectures.
Reinette
Babu Moger
reviewerRe: [PATCH v6 11/18] fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup
Hi Reinette,
Quoted 27 lines · Reinette Chatre
Hi Babu,
Quoted 7 lines · Babu
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
On 10/1/26 8:10 AM, Babu Moger wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
The
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode allows tasks to use different allocation and monitoring associations when transitioning from user mode toCould "different allocation and monitoring associations" just be "different CLOSID and RMID" (in places where this is what it refers to)? Being specific and consistent with terms would make this so much easier to understand.
I avoided using CLOSID and RMID terms in filesystem specific code. If you are ok with that then I will use these terms.
Why?
Internally resctrl filesystem has a CLOSID assigned to a control group, RMID assigned to a monitor group. When a user assigns a resource group to the global kernel mode the kernel mode is implicitly assigned a CLOSID and/or RMID. These are all part of the resctrl filesystem design. What is the benefit to avoid these specific terms when explaining the implementation details?
Quoted 5 lines
An important distinction is that in this feature the CLOSID and RMID values originate from a
CTRL_MONor MON group assigned by user space. Any architecture where there is a dependency between CLOSID and RMID will already have accounted for that during the creation of the resource group. This is something that should be clear from the context when referring to CLOSID and RMID.
That helps. Thanks for the explanation.
Quoted 11 lines
The resctrl fs code even uses CLOSID and RMID in the API used to interact with the architecture:
void resctrl_arch_configure_kmode_global(const struct cpumask*cpu_mask,
u32 closid, boolassign_ctrl, u32 rmid, boolassign_mon, bool enable);The only place where we should avoid using CLOSID and RMID is in anything exposed to user space since CLOSID and RMID has different meanings on different architectures.
Yeah, I need to come up with some generic terminology for this interface in resctrl.rst. I'll try to address it in the next revision.
Thanks,
Babu
Babu Moger
reviewerPATCH v6 12/18 fs/resctrl: Add CPU hotplug support for kernel mode associations
In reply to Babu MogerKernel mode allocation and monitoring associations are maintained on a per-CPU basis. Extend the kernel mode infrastructure to integrate with CPU hotplug handling, allowing kernel mode state to be managed as CPUs enter or leave the online set.
Introduce resctrl_kmode_global_online_cpu() and resctrl_kmode_global_offline_cpu(), and hook them into the existing resctrl_online_cpu() and resctrl_offline_cpu() paths.
---
v6: Update the changelog in non-bugfix form.
Update the code to remove rdtgroup->kmode.
Introduce new wrapper resctrl_configure_kmode_global() to consolidate architecture calls.
v5: Added resctrl_kmode_offline_cpu() to disable the kernel mode
association and update kmode_cpu_mask when an associated CPU goes
offline.
This addresses sashiko comments:
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=11
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=10
Also moved the patch earlier than patch 10.
[RESEND PATCH v4 10/15] fs/resctrl: Reset the kernel mode binding when an rdtgroup is removed That seemed much more clear.
v4: New patch in the series. Patch taken from:
https://lore.kernel.org/lkml/[email protected]/
Updated the code to enable kernel mode by default whenever a CPU comes online when one of global-assign mode is enabled.
--- fs/resctrl/rdtgroup.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
fs/resctrl/rdtgroup.c +57 -0
@@ -410,6 +410,17 @@ static int rdtgroup_kmode_cpus_show(struct kernfs_open_file *of,return ret; } +static void resctrl_configure_kmode_global (const struct cpumask *mask, +struct rdtgroup *rdtgrp, +bool enable) +{ +resctrl_arch_configure_kmode_global (mask, rdtgrp->closid, + resctrl_kmode.ctrl ==KMODE_ASSIGN , + rdtgrp->mon.rmid, + resctrl_kmode.mon ==KMODE_ASSIGN , + enable); +} +/* * Update the PGR_ASSOC MSR on all cpus in @cpu_mask, *
@@ -1114,6 +1125,48 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,return 0 ; } +/* +* resctrl_kmode_global_online_cpu() - Program kernel mode association for @cpu +* @cpu: CPU that has just been brought online +* +* When global_enable_per_cpu is active, @cpu joins that association and is +* programmed on. +*/ +static void resctrl_kmode_global_online_cpu (unsigned int cpu) +{ +struct rdtgroup *rdtgrp = resctrl_kmode.rdtgrp; + +if (resctrl_kmode.kmode_cur !=RESCTRL_GLOBAL_ENABLE_PER_CPU || !rdtgrp) +return ; + +cpumask_set_cpu (cpu, &rdtgrp->kmode_cpu_mask); + +resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, true); +} + +/* +* resctrl_kmode_global_offline_cpu() - Clear kernel mode association for @cpu +* @cpu: CPU being taken offline. +* +* When global_enable_per_cpu is active and @cpu is in kmode_cpu_mask, the +* association is disabled on @cpu and @cpu is removed from that mask. A CPU +* outside the mask is left unchanged. +*/ +static void resctrl_kmode_global_offline_cpu (unsigned int cpu) +{ +struct rdtgroup *rdtgrp = resctrl_kmode.rdtgrp; + +if (resctrl_kmode.kmode_cur !=RESCTRL_GLOBAL_ENABLE_PER_CPU || !rdtgrp) +return ; + +if (!cpumask_test_cpu (cpu, &rdtgrp->kmode_cpu_mask)) +return ; + +cpumask_clear_cpu (cpu, &rdtgrp->kmode_cpu_mask); + +resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, false); +} +void *rdt_kn_parent_priv (struct kernfs_node *kn) {/*
@@ -4896,6 +4949,7 @@ void resctrl_online_cpu(unsigned int cpu)mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +resctrl_kmode_global_online_cpu (cpu);mutex_unlock (&rdtgroup_mutex); }
@@ -4939,6 +4993,9 @@ void resctrl_offline_cpu(unsigned int cpu) } } +/* Clear any active kernel mode association on this CPU. */ +resctrl_kmode_global_offline_cpu (cpu); +if (!l3->mon_capable) goto out_unlock;
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 12/18] fs/resctrl: Add CPU hotplug support for kernel mode associations
Hi Babu,
Quoted 1 line · Babu Moger
Kernel mode allocation and monitoring associations are maintained on a
wrt "Kernel mode", this is specific to only the "global per-CPU kernel mode", no?
Quoted 7 lines
per-CPU basis. Extend the kernel mode infrastructure to integrate with CPU hotplug handling, allowing kernel mode state to be managed as CPUs enter or leave the online set.
Introduce
resctrl_kmode_global_online_cpu()andresctrl_kmode_global_offline_cpu(), and hook them into the existingresctrl_online_cpu()andresctrl_offline_cpu()paths.
Above just narrates the diff. Please check all changelogs to match tip changelog expectations. So far they are light on context/problem/solution and many miss an answer to "why".
It deserves a mention in the changelog that the active kernel mode is automatically enabled on a new online CPU followed by why this is done. This is a big design decision that will be user visible but I missed where this is highlighted and motivated.
Changelog should help reader to understand the patch. In this series the changelogs provide little help.
Quoted 2 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 27 lines
--- fs/resctrl/rdtgroup.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)fs/resctrl/rdtgroup.c +11
-0@@ -410,6 +410,17 @@ static int rdtgroup_kmode_cpus_show(struct kernfs_open_file *of,return ret; } +static void resctrl_configure_kmode_global (const struct cpumask *mask, +struct rdtgroup *rdtgrp, +bool enable) +{ +resctrl_arch_configure_kmode_global (mask, rdtgrp->closid, + resctrl_kmode.ctrl ==KMODE_ASSIGN , + rdtgrp->mon.rmid, + resctrl_kmode.mon ==KMODE_ASSIGN , + enable); +} +/* * Update the PGR_ASSOC MSR on all cpus in @cpu_mask, *
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1132
Quoted 8 lines
fs/resctrl/rdtgroup.c +5
-0@@ -1114,6 +1125,48 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,return 0 ; } +/* +* resctrl_kmode_global_online_cpu() - Program kernel mode association for @cpu +* @cpu: CPU that has just been brought online +* +* When global_enable_per_cpu is active, @cpu joins that association and is
Please consistently use the enum name in comments and code to help grep find how/where it is used in the code.
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1133
Quoted 1 line
fs/resctrl/rdtgroup.c +1
-0+* programmed on.
What does "is programmed on" mean? CPU is already online.
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1144
Quoted 11 lines
fs/resctrl/rdtgroup.c +11
-0+*/ +static void resctrl_kmode_global_online_cpu (unsigned int cpu) +{ +struct rdtgroup *rdtgrp = resctrl_kmode.rdtgrp; + +if (resctrl_kmode.kmode_cur !=RESCTRL_GLOBAL_ENABLE_PER_CPU || !rdtgrp) +return ; + +cpumask_set_cpu (cpu, &rdtgrp->kmode_cpu_mask); + +resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, true);
Shouldn't CPU be added to mask *after* it has been configured? I understand that configuration cannot fail but having the order set makes it easier to make changes later.
Quoted 37 lines
fs/resctrl/rdtgroup.c +26
-0+} + +/* +* resctrl_kmode_global_offline_cpu() - Clear kernel mode association for @cpu +* @cpu: CPU being taken offline. +* +* When global_enable_per_cpu is active and @cpu is in kmode_cpu_mask, the +* association is disabled on @cpu and @cpu is removed from that mask. A CPU +* outside the mask is left unchanged. +*/ +static void resctrl_kmode_global_offline_cpu (unsigned int cpu) +{ +struct rdtgroup *rdtgrp = resctrl_kmode.rdtgrp; + +if (resctrl_kmode.kmode_cur !=RESCTRL_GLOBAL_ENABLE_PER_CPU || !rdtgrp) +return ; + +if (!cpumask_test_cpu (cpu, &rdtgrp->kmode_cpu_mask)) +return ; + +cpumask_clear_cpu (cpu, &rdtgrp->kmode_cpu_mask); + +resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, false); +} +void *rdt_kn_parent_priv (struct kernfs_node *kn) {/* @@ -4896,6 +4949,7 @@ void resctrl_online_cpu(unsigned int cpu)mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +resctrl_kmode_global_online_cpu (cpu);mutex_unlock (&rdtgroup_mutex); }
fs/resctrl/rdtgroup.c void resctrl_offline_cpu(unsigned int cpu) · line 4996
Quoted 4 lines
fs/resctrl/rdtgroup.c +1
-0@@ -4939,6 +4993,9 @@ void resctrl_offline_cpu(unsigned int cpu) } } +/* Clear any active kernel mode association on this CPU. */
Above comment can be dropped, it just duplicates the function comment.
fs/resctrl/rdtgroup.c void resctrl_offline_cpu(unsigned int cpu) · line 5001
Quoted 5 lines
fs/resctrl/rdtgroup.c +2
-0+resctrl_kmode_global_offline_cpu (cpu); +if (!l3->mon_capable) goto out_unlock;
Reinette
Re: [PATCH v6 12/18] fs/resctrl: Add CPU hotplug support for kernel mode associations
Hi Reinette,
Quoted 6 lines · Reinette Chatre
Hi Babu,
Quoted 1 line · Babu Moger
Kernel mode allocation and monitoring associations are maintained on a
wrt "Kernel mode", this is specific to only the "global per-CPU kernel mode", no?
Yes.
Quoted 13 lines
Quoted 8 lines
per-CPU basis. Extend the kernel mode infrastructure to integrate with CPU hotplug handling, allowing kernel mode state to be managed as CPUs enter or leave the online set.
Introduce
resctrl_kmode_global_online_cpu()andresctrl_kmode_global_offline_cpu(), and hook them into the existingresctrl_online_cpu()andresctrl_offline_cpu()paths.Above just narrates the diff. Please check all changelogs to match tip changelog expectations. So far they are light on context/problem/solution and many miss an answer to "why".
Quoted 6 lines
It deserves a mention in the changelog that the active kernel mode is automatically enabled on a new online CPU followed by why this is done. This is a big design decision that will be user visible but I missed where this is highlighted and motivated.
Changelog should help reader to understand the patch. In this series the changelogs provide little help.
Will rephrase:
"The global per-CPU kernel mode enables kernel work to use different allocation and monitoring associations than the originating user task. The mode is enabled and disabled on a per-CPU basis.
A newly online CPU inherits the active kernel mode configuration to ensure consistent kernel mode behavior across the system. Likewise, kernel mode state is cleaned up when a CPU goes offline.
Integrate kernel mode handling with CPU hotplug to apply the active kernel mode configuration to newly online CPUs and remove it from CPUs that leave the online set."
Quoted 35 lines
Quoted 3 lines
Signed-off-by Babu Moger <[email protected]>---
...
Quoted 30 lines
--- fs/resctrl/rdtgroup.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)fs/resctrl/rdtgroup.c +11
-0@@ -410,6 +410,17 @@ static int rdtgroup_kmode_cpus_show(struct kernfs_open_file *of,return ret; } +static void resctrl_configure_kmode_global (const struct cpumask *mask, +struct rdtgroup *rdtgrp, +bool enable) +{ +resctrl_arch_configure_kmode_global (mask, rdtgrp->closid, + resctrl_kmode.ctrl ==KMODE_ASSIGN , + rdtgrp->mon.rmid, + resctrl_kmode.mon ==KMODE_ASSIGN , + enable); +} +/* * Update the PGR_ASSOC MSR on all cpus in @cpu_mask, * @@ -1114,6 +1125,48 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,return 0 ; }
Quoted 8 lines
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1132
Quoted 5 lines
fs/resctrl/rdtgroup.c +5
-0+/* +* resctrl_kmode_global_online_cpu() - Program kernel mode association for @cpu +* @cpu: CPU that has just been brought online +* +* When global_enable_per_cpu is active, @cpu joins that association and is Please consistently use the enum name in comments and code to help grep find how/where it is used in the code.
Sure.
Quoted 5 lines
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1133
Quoted 2 lines
fs/resctrl/rdtgroup.c +1
-0+* programmed on. What does "is programmed on" mean? CPU is already online.
* When %RESCTRL_GLOBAL_ENABLE_PER_CPU is active, @cpu joins the active
* association and is programmed with its kernel mode configuration.
Quoted 7 lines
Quoted 7 lines
fs/resctrl/rdtgroup.c +7
-0+*/ +static void resctrl_kmode_global_online_cpu (unsigned int cpu) +{ +struct rdtgroup *rdtgrp = resctrl_kmode.rdtgrp; + +if (resctrl_kmode.kmode_cur !=RESCTRL_GLOBAL_ENABLE_PER_CPU || !rdtgrp) +return ;
Quoted 8 lines
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1144
Quoted 4 lines
fs/resctrl/rdtgroup.c +4
-0+ +cpumask_set_cpu (cpu, &rdtgrp->kmode_cpu_mask); + +resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, true);Shouldn't CPU be added to mask *after* it has been configured? I understand that configuration cannot fail but having the order set makes it easier to make changes later.
Will change the order.
Quoted 37 lines
Quoted 37 lines
fs/resctrl/rdtgroup.c +26
-0+} + +/* +* resctrl_kmode_global_offline_cpu() - Clear kernel mode association for @cpu +* @cpu: CPU being taken offline. +* +* When global_enable_per_cpu is active and @cpu is in kmode_cpu_mask, the +* association is disabled on @cpu and @cpu is removed from that mask. A CPU +* outside the mask is left unchanged. +*/ +static void resctrl_kmode_global_offline_cpu (unsigned int cpu) +{ +struct rdtgroup *rdtgrp = resctrl_kmode.rdtgrp; + +if (resctrl_kmode.kmode_cur !=RESCTRL_GLOBAL_ENABLE_PER_CPU || !rdtgrp) +return ; + +if (!cpumask_test_cpu (cpu, &rdtgrp->kmode_cpu_mask)) +return ; + +cpumask_clear_cpu (cpu, &rdtgrp->kmode_cpu_mask); + +resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, false); +} +void *rdt_kn_parent_priv (struct kernfs_node *kn) {/* @@ -4896,6 +4949,7 @@ void resctrl_online_cpu(unsigned int cpu)mutex_lock (&rdtgroup_mutex);/* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask); +resctrl_kmode_global_online_cpu (cpu);mutex_unlock (&rdtgroup_mutex); }
Quoted 7 lines
fs/resctrl/rdtgroup.c void resctrl_offline_cpu(unsigned int cpu) · line 4996
Quoted 5 lines
fs/resctrl/rdtgroup.c +1
-0@@ -4939,6 +4993,9 @@ void resctrl_offline_cpu(unsigned int cpu) } } +/* Clear any active kernel mode association on this CPU. */ Above comment can be dropped, it just duplicates the function comment.
Sure.
Thanks
Babu
Babu Moger
reviewerPATCH v6 13/18 fs/resctrl: Deactivate kernel mode associations when a group is removed
In reply to Babu MogerThe active kernel mode association is backed by either a CTRL_MON or MON group.
When the backing group is removed, or when resctrl is unmounted, clear the programmed association and restore the default settings.
---
v6: Rewrite changelog (not a bugfix).
Shorten the code comments.
v5: Took care of couple of Sashiko comments on previous patch.
https://sashiko.dev/#/patchset/[email protected]?part=10
Re-wrote the changelog.
Renamed rdtgroup_config_kmode_reset() to rdtgroup_kmode_deactivate().
v4: Re-wrote the changelog.
Added the call free_all_child_rdtgrp() and rmdir_all_sub() Simplified the code comments.
v3: New patch to handle the kernel_mode clean up.
--- fs/resctrl/rdtgroup.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
fs/resctrl/rdtgroup.c +44 -0
@@ -1167,6 +1167,36 @@ static void resctrl_kmode_global_offline_cpu(unsigned int cpu)resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, false); } +/* +* Disable the association on @rdtgrp's kmode_cpu_mask, clear the mask, and +* hide the group's kmode_cpus files. +*/ +static void rdtgroup_kmode_global_deactivate (struct rdtgroup *rdtgrp) +{ +resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, false); +cpumask_clear (&rdtgrp->kmode_cpu_mask); +} + +/* +* rdtgroup_kmode_global_detach() - Detach @rdtgrp from the global per-CPU mode +* @rdtgrp: Resctrl group being removed or torn down. +* +* If @rdtgrp backs the active association, disable it, clear kernel mode +* state, and restore RESCTRL_INHERIT_USER. +*/ +static void rdtgroup_kmode_global_detach (struct rdtgroup *rdtgrp) +{ +if (resctrl_kmode.rdtgrp != rdtgrp) +return ; + +rdtgroup_kmode_global_deactivate (rdtgrp); + + resctrl_kmode.rdtgrp =NULL ; + resctrl_kmode.kmode_cur =RESCTRL_INHERIT_USER ; + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ; +} +void *rdt_kn_parent_priv (struct kernfs_node *kn) {/*
@@ -3228,6 +3258,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_kmode_global_detach (sentry);rdtgroup_unassign_cntrs (sentry);free_rmid (sentry->closid, sentry->mon.rmid);list_del (&sentry->mon.crdtgrp_list);
@@ -3265,6 +3296,7 @@ static void rmdir_all_sub(void)cpumask_or (&rdtgroup_default.cpu_mask, &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); +rdtgroup_kmode_global_detach (rdtgrp);rdtgroup_unassign_cntrs (rdtgrp); if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||
@@ -3360,6 +3392,7 @@ static void resctrl_fs_teardown(void)return ;rmdir_all_sub (); +rdtgroup_kmode_global_detach (&rdtgroup_default);rdtgroup_unassign_cntrs (&rdtgroup_default);mon_put_kn_priv ();rdt_pseudo_lock_release ();
@@ -4395,6 +4428,8 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)u32 closid, rmid;int cpu; +rdtgroup_kmode_global_detach (rdtgrp); +/* Give any tasks back to the parent group */ rdt_move_group_tasks (rdtgrp, prdtgrp, tmpmask);
@@ -4442,9 +4477,18 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)static int rdtgroup_rmdir_ctrl (struct rdtgroup *rdtgrp,cpumask_var_t tmpmask) { +struct rdtgroup *sentry;u32 closid, rmid;int cpu; +/* +* A monitor group uses its parent's CLOSID. Detach a child that +* backs the association before that CLOSID is freed. +*/ +list_for_each_entry (sentry, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) +rdtgroup_kmode_global_detach (sentry); +rdtgroup_kmode_global_detach (rdtgrp); +/* Give any tasks back to the default group */ rdt_move_group_tasks (rdtgrp, &rdtgroup_default, tmpmask);
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 13/18] fs/resctrl: Deactivate kernel mode associations when a group is removed
Hi Babu,
Quoted 2 lines · Babu Moger
The active kernel mode association is backed by either a
CTRL_MONor MON group.
This context does not reflect the code at this point in series but what behavior will be after entire series is applied. It is also written as general but specific to the global per-CPU kernel mode.
Quoted 2 lines
When the backing group is removed, or when resctrl is unmounted, clear the programmed association and restore the default settings.
Please provide more context to user and help reader to understand what the patch does without needing to decipher the patch.
For example, "restore the default settings" is a very vague way to describe that removing the group backing the global per-CPU kernel mode automatically switches the kernel mode to "inherit user". Please explain at high level what the code does and why. As a hypothetical, why not keep the kernel mode as "global per-CPU kernel mode" but switch the assigned group to the default group? This would match most other similar resctrl behaviors, no?
This is also user visible behavior that should be documented in resctrl.rst.
Quoted 9 lines
--- fs/resctrl/rdtgroup.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)fs/resctrl/rdtgroup.c +0
-0
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1172
Quoted 6 lines
fs/resctrl/rdtgroup.c +3
-0@@ -1167,6 +1167,36 @@ static void resctrl_kmode_global_offline_cpu(unsigned int cpu)resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, false); } +/* +* Disable the association on @rdtgrp's kmode_cpu_mask, clear the mask, and +* hide the group's kmode_cpus files.
"hide the group's kmode_cpus files"? Does not match the code below. Even so, the comments just narrate the function.
Quoted 7 lines
fs/resctrl/rdtgroup.c +7
-0+*/ +static void rdtgroup_kmode_global_deactivate (struct rdtgroup *rdtgrp) +{ +resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, false); +cpumask_clear (&rdtgrp->kmode_cpu_mask); +} +
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1189
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+/* +* rdtgroup_kmode_global_detach() - Detach @rdtgrp from the global per-CPU mode +* @rdtgrp: Resctrl group being removed or torn down. +* +* If @rdtgrp backs the active association, disable it, clear kernel mode +* state, and restore RESCTRL_INHERIT_USER. +*/ +static void rdtgroup_kmode_global_detach (struct rdtgroup *rdtgrp) +{ +if (resctrl_kmode.rdtgrp != rdtgrp)
Please do not use tests on resctrl_kmode.rdtgrp as synonym for resctrl_kmode.active == RESCTRL_GLOBAL_ENABLE_PER_CPU.
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1198
Quoted 9 lines
fs/resctrl/rdtgroup.c +9
-0+return ; + +rdtgroup_kmode_global_deactivate (rdtgrp); + + resctrl_kmode.rdtgrp =NULL ; + resctrl_kmode.kmode_cur =RESCTRL_INHERIT_USER ; + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ; +}
There seems to be some duplication between rdtgroup_kmode_global_detach() and resctrl_kmode_switch(). Since the contract is already established that disabling RESCTRL_GLOBAL_ENABLE_PER_CPU enables RESCTRL_INHERIT_USER, could this reset to RESCTRL_INHERIT_USER not just be done in rdtgroup_kmode_global_deactivate() without duplicating it in rdtgroup_kmode_global_detach() and resctrl_kmode_switch()?
With that done, it looks like rdtgroup_kmode_global_detach() could just be dropped if rdtgroup_kmode_global_deactivate() gets the check to ensure the group needs removing?
Quoted 38 lines
fs/resctrl/rdtgroup.c +6
-0+void *rdt_kn_parent_priv (struct kernfs_node *kn) {/* @@ -3228,6 +3258,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_kmode_global_detach (sentry);rdtgroup_unassign_cntrs (sentry);free_rmid (sentry->closid, sentry->mon.rmid);list_del (&sentry->mon.crdtgrp_list);@@ -3265,6 +3296,7 @@ static void rmdir_all_sub(void)cpumask_or (&rdtgroup_default.cpu_mask, &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); +rdtgroup_kmode_global_detach (rdtgrp);rdtgroup_unassign_cntrs (rdtgrp); if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||@@ -3360,6 +3392,7 @@ static void resctrl_fs_teardown(void)return ;rmdir_all_sub (); +rdtgroup_kmode_global_detach (&rdtgroup_default);rdtgroup_unassign_cntrs (&rdtgroup_default);mon_put_kn_priv ();rdt_pseudo_lock_release ();@@ -4395,6 +4428,8 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)u32 closid, rmid;int cpu; +rdtgroup_kmode_global_detach (rdtgrp); +/* Give any tasks back to the parent group */ rdt_move_group_tasks (rdtgrp, prdtgrp, tmpmask);
fs/resctrl/rdtgroup.c static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp) · line 4486
Quoted 10 lines
fs/resctrl/rdtgroup.c +4
-0@@ -4442,9 +4477,18 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)static int rdtgroup_rmdir_ctrl (struct rdtgroup *rdtgrp,cpumask_var_t tmpmask) { +struct rdtgroup *sentry;u32 closid, rmid;int cpu; +/* +* A monitor group uses its parent's CLOSID. Detach a child that +* backs the association before that CLOSID is freed.
Why does this have to be done before the CLOSID is freed? The monitor groups are cleared later from free_all_child_rdtgrp() that will call rdtgroup_kmode_global_detach() for every monitor again.
fs/resctrl/rdtgroup.c static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp) · line 4494
Quoted 8 lines
fs/resctrl/rdtgroup.c +5
-0+*/ +list_for_each_entry (sentry, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) +rdtgroup_kmode_global_detach (sentry); +rdtgroup_kmode_global_detach (rdtgrp); +/* Give any tasks back to the default group */ rdt_move_group_tasks (rdtgrp, &rdtgroup_default, tmpmask);
Reinette
Babu Moger
reviewerRe: [PATCH v6 13/18] fs/resctrl: Deactivate kernel mode associations when a group is removed
Hi Reinette,
Quoted 10 lines · Reinette Chatre
Hi Babu,
Quoted 2 lines · Babu Moger
The active kernel mode association is backed by either a
CTRL_MONor MON group.This context does not reflect the code at this point in series but what behavior will be after entire series is applied. It is also written as general but specific to the global per-CPU kernel mode.
Quoted 5 lines
Quoted 2 lines
When the backing group is removed, or when resctrl is unmounted, clear the programmed association and restore the default settings.
Please provide more context to user and help reader to understand what the patch does without needing to decipher the patch.
"The global per-CPU kernel mode, RESCTRL_GLOBAL_ENABLE_PER_CPU, allows kernel work to use allocation and monitoring associations that differ from those of the originating user task. When the mode is active, "info/kernel_mode" displays the backing mode. If the backing group is removed, or resctrl is unmounted, the association becomes invalid.
Clear the programmed association and revert the kernel mode to the default "inherit user" behavior. This ensures that kernel work continues to use the allocation and monitoring associations of the originating user task until a new kernel mode association is configured.
Document this user-visible behavior in resctrl.rst."
Quoted 8 lines
For example, "restore the default settings" is a very vague way to describe that removing the group backing the global per-CPU kernel mode automatically switches the kernel mode to "inherit user". Please explain at high level what the code does and why. As a hypothetical, why not keep the kernel mode as "global per-CPU kernel mode" but switch the assigned group to the default group? This would match most other similar resctrl behaviors, no?
My assuption, you are not asking me to change it to "global per-CPU kernel mode" when the group is removed.
Quoted 2 lines
This is also user visible behavior that should be documented in
resctrl.rst.
Will add a line under "inherit_user" documentation.
Quoted 13 lines
Quoted 13 lines
--- fs/resctrl/rdtgroup.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)fs/resctrl/rdtgroup.c +0
-0@@ -1167,6 +1167,36 @@ static void resctrl_kmode_global_offline_cpu(unsigned int cpu)resctrl_configure_kmode_global (cpumask_of (cpu), rdtgrp, false); }
Quoted 6 lines
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1172
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+/* +* Disable the association on @rdtgrp's kmode_cpu_mask, clear the mask, and +* hide the group's kmode_cpus files. "hide the group's
kmode_cpusfiles"? Does not match the code below. Even so, the comments just narrate the function.
Yea. Will remove "hide the group's kmode_cpus files" detail.
Quoted 13 lines
Quoted 13 lines
fs/resctrl/rdtgroup.c +12
-0+*/ +static void rdtgroup_kmode_global_deactivate (struct rdtgroup *rdtgrp) +{ +resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, false); +cpumask_clear (&rdtgrp->kmode_cpu_mask); +} + +/* +* rdtgroup_kmode_global_detach() - Detach @rdtgrp from the global per-CPU mode +* @rdtgrp: Resctrl group being removed or torn down. +* +* If @rdtgrp backs the active association, disable it, clear kernel mode
Quoted 8 lines
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1189
Quoted 5 lines
fs/resctrl/rdtgroup.c +5
-0+* state, and restore RESCTRL_INHERIT_USER. +*/ +static void rdtgroup_kmode_global_detach (struct rdtgroup *rdtgrp) +{ +if (resctrl_kmode.rdtgrp != rdtgrp)Please do not use tests on resctrl_kmode.rdtgrp as synonym for resctrl_kmode.active ==
RESCTRL_GLOBAL_ENABLE_PER_CPU.
Not really. This was a check to make sure kernel mode is pointing to correct group that is being removed.
Quoted 17 lines
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1198
Quoted 10 lines
fs/resctrl/rdtgroup.c +9
-0+return ; + +rdtgroup_kmode_global_deactivate (rdtgrp); + + resctrl_kmode.rdtgrp =NULL ; + resctrl_kmode.kmode_cur =RESCTRL_INHERIT_USER ; + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ; +}There seems to be some duplication between
rdtgroup_kmode_global_detach()andresctrl_kmode_switch(). Since the contract is already established that disablingRESCTRL_GLOBAL_ENABLE_PER_CPUenablesRESCTRL_INHERIT_USER, could this reset toRESCTRL_INHERIT_USERnot just be done inrdtgroup_kmode_global_deactivate()without duplicating it inrdtgroup_kmode_global_detach()andresctrl_kmode_switch()?
Quoted 4 lines
With that done, it looks like
rdtgroup_kmode_global_detach()could just be dropped ifrdtgroup_kmode_global_deactivate()gets the check to ensure the group needs removing?
Yea. I may have to re-organize few things. I can do everything with rdtgroup_kmode_global_deactivate() and rdtgroup_kmode_global_activate(). And remove both rdtgroup_kmode_global_detach() and resctrl_kmode_switch().
Quoted 46 lines
Quoted 46 lines
fs/resctrl/rdtgroup.c +7
-0+void *rdt_kn_parent_priv (struct kernfs_node *kn) {/* @@ -3228,6 +3258,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_kmode_global_detach (sentry);rdtgroup_unassign_cntrs (sentry);free_rmid (sentry->closid, sentry->mon.rmid);list_del (&sentry->mon.crdtgrp_list);@@ -3265,6 +3296,7 @@ static void rmdir_all_sub(void)cpumask_or (&rdtgroup_default.cpu_mask, &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); +rdtgroup_kmode_global_detach (rdtgrp);rdtgroup_unassign_cntrs (rdtgrp); if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP ||@@ -3360,6 +3392,7 @@ static void resctrl_fs_teardown(void)return ;rmdir_all_sub (); +rdtgroup_kmode_global_detach (&rdtgroup_default);rdtgroup_unassign_cntrs (&rdtgroup_default);mon_put_kn_priv ();rdt_pseudo_lock_release ();@@ -4395,6 +4428,8 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)u32 closid, rmid;int cpu; +rdtgroup_kmode_global_detach (rdtgrp); +/* Give any tasks back to the parent group */ rdt_move_group_tasks (rdtgrp, prdtgrp, tmpmask);@@ -4442,9 +4477,18 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)static int rdtgroup_rmdir_ctrl (struct rdtgroup *rdtgrp,cpumask_var_t tmpmask) { +struct rdtgroup *sentry;u32 closid, rmid;int cpu;
Quoted 7 lines
fs/resctrl/rdtgroup.c static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp) · line 4486
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+/* +* A monitor group uses its parent's CLOSID. Detach a child that +* backs the association before that CLOSID is freed. Why does this have to be done before the CLOSID is freed? The monitor groups are cleared later from
free_all_child_rdtgrp()that will callrdtgroup_kmode_global_detach()for every monitor again.
Yea. May not be required. Will remove.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 13/18] fs/resctrl: Deactivate kernel mode associations when a group is removed
Hi Babu,
Quoted 30 lines · Babu Moger
Quoted 8 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
The active kernel mode association is backed by either a
CTRL_MONor MON group.This context does not reflect the code at this point in series but what behavior will be after entire series is applied. It is also written as general but specific to the global per-CPU kernel mode.
Quoted 5 lines
Quoted 2 lines
When the backing group is removed, or when resctrl is unmounted, clear the programmed association and restore the default settings.
Please provide more context to user and help reader to understand what the patch does without needing to decipher the patch.
"The global per-CPU kernel mode,
RESCTRL_GLOBAL_ENABLE_PER_CPU, allows kernel work to use allocation and monitoring associations that differ from those of the originating user task. When the mode is active, "info/kernel_mode" displays the backing mode. If the backing group is removed, or resctrl is unmounted, the association becomes invalid.Clear the programmed association and revert the kernel mode to the default "inherit user" behavior. This ensures that kernel work continues to use the allocation and monitoring associations of the originating user task until a new kernel mode association is configured.
Document this user-visible behavior in
resctrl.rst."Quoted 8 lines
For example, "restore the default settings" is a very vague way to describe that removing the group backing the global per-CPU kernel mode automatically switches the kernel mode to "inherit user". Please explain at high level what the code does and why. As a hypothetical, why not keep the kernel mode as "global per-CPU kernel mode" but switch the assigned group to the default group? This would match most other similar resctrl behaviors, no?
Quoted 1 line
My assuption, you are not asking me to change it to "global per-CPU kernel mode" when the group is removed.
Not specifically, but since the behavior is different from the typical resctrl behavior that, for example moves a removed group's tasks etc. to the default group, it would be valuable to know *why* this behavior was chosen.
...
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
+ */
fs/resctrl/rdtgroup.c +11
-0+static void rdtgroup_kmode_global_deactivate (struct rdtgroup *rdtgrp) +{ + resctrl_configure_kmode_global(&rdtgrp->kmode_cpu_mask, rdtgrp, false); + cpumask_clear(&rdtgrp->kmode_cpu_mask); +} + +/* +* rdtgroup_kmode_global_detach() - Detach @rdtgrp from the global per-CPU mode +* @rdtgrp: Resctrl group being removed or torn down. +* +* If @rdtgrp backs the active association, disable it, clear kernel mode Quoted 8 lines
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1189
Quoted 5 lines
+ * state, and restore
RESCTRL_INHERIT_USER.
+ */fs/resctrl/rdtgroup.c +3
-0+static void rdtgroup_kmode_global_detach (struct rdtgroup *rdtgrp) +{ + if (resctrl_kmode.rdtgrp != rdtgrp)Please do not use tests on resctrl_kmode.rdtgrp as synonym for resctrl_kmode.active ==
RESCTRL_GLOBAL_ENABLE_PER_CPU.
Quoted 1 line
Not really. This was a check to make sure kernel mode is pointing to correct group that is being removed.
The problem is this "global per-CPU kernel mode" specific function is called without ever checking if "global per-CPU kernel mode" is active. Instead it uses one of the parameter values as synonym for whether the "global per-CPU kernel mode" is active. What is a future developer to understand from this? This implies there are two *interchangeable* ways to determine whether "global per-CPU kernel mode" is active ... sometimes
resctrl_kmode.active == RESCTRL_GLOBAL_ENABLE_PER_CPU is/should be used and sometimes the value of resctrl_kmode.rdtgrp is/should be used. How should somebody interpret this? Are these two interchangeable tests (and thus making one redundant) or is the test dependent on the scenario (which is not explained anywhere).
Reinette
Babu Moger
reviewerRe: [PATCH v6 13/18] fs/resctrl: Deactivate kernel mode associations when a group is removed
Hi Reinette,
Quoted 33 lines · Reinette Chatre
Hi Babu,
Quoted 30 lines · Babu Moger
Quoted 8 lines · Reinette Chatre
Quoted 2 lines · Babu Moger
The active kernel mode association is backed by either a
CTRL_MONor MON group.This context does not reflect the code at this point in series but what behavior will be after entire series is applied. It is also written as general but specific to the global per-CPU kernel mode.
Quoted 5 lines
Quoted 2 lines
When the backing group is removed, or when resctrl is unmounted, clear the programmed association and restore the default settings.
Please provide more context to user and help reader to understand what the patch does without needing to decipher the patch.
"The global per-CPU kernel mode,
RESCTRL_GLOBAL_ENABLE_PER_CPU, allows kernel work to use allocation and monitoring associations that differ from those of the originating user task. When the mode is active, "info/kernel_mode" displays the backing mode. If the backing group is removed, or resctrl is unmounted, the association becomes invalid.Clear the programmed association and revert the kernel mode to the default "inherit user" behavior. This ensures that kernel work continues to use the allocation and monitoring associations of the originating user task until a new kernel mode association is configured.
Document this user-visible behavior in
resctrl.rst."Quoted 8 lines
For example, "restore the default settings" is a very vague way to describe that removing the group backing the global per-CPU kernel mode automatically switches the kernel mode to "inherit user". Please explain at high level what the code does and why. As a hypothetical, why not keep the kernel mode as "global per-CPU kernel mode" but switch the assigned group to the default group? This would match most other similar resctrl behaviors, no?
Quoted 5 lines
Quoted 1 line
My assuption, you are not asking me to change it to "global per-CPU kernel mode" when the group is removed.
Not specifically, but since the behavior is different from the typical resctrl behavior that, for example moves a removed group's tasks etc. to the default group, it would be valuable to know *why* this behavior was chosen.
Sure. Will add explanation for that.
Quoted 26 lines
...
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
+ */
fs/resctrl/rdtgroup.c +11
-0+static void rdtgroup_kmode_global_deactivate (struct rdtgroup *rdtgrp) +{ + resctrl_configure_kmode_global(&rdtgrp->kmode_cpu_mask, rdtgrp, false); + cpumask_clear(&rdtgrp->kmode_cpu_mask); +} + +/* +* rdtgroup_kmode_global_detach() - Detach @rdtgrp from the global per-CPU mode +* @rdtgrp: Resctrl group being removed or torn down. +* +* If @rdtgrp backs the active association, disable it, clear kernel mode Quoted 8 lines
fs/resctrl/rdtgroup.c static void resctrl_kmode_global_offline_cpu(unsigned int cpu) · line 1189
Quoted 5 lines
+ * state, and restore
RESCTRL_INHERIT_USER.
+ */fs/resctrl/rdtgroup.c +3
-0+static void rdtgroup_kmode_global_detach (struct rdtgroup *rdtgrp) +{ + if (resctrl_kmode.rdtgrp != rdtgrp)Please do not use tests on resctrl_kmode.rdtgrp as synonym for resctrl_kmode.active ==
RESCTRL_GLOBAL_ENABLE_PER_CPU.Quoted 1 line
Not really. This was a check to make sure kernel mode is pointing to correct group that is being removed.
Quoted 9 lines
The problem is this "global per-CPU kernel mode" specific function is called without ever checking if "global per-CPU kernel mode" is active. Instead it uses one of the parameter values as synonym for whether the "global per-CPU kernel mode" is active. What is a future developer to understand from this? This implies there are two *interchangeable* ways to determine whether "global per-CPU kernel mode" is active ... sometimes
resctrl_kmode.active ==RESCTRL_GLOBAL_ENABLE_PER_CPUis/should be used and sometimes the value of resctrl_kmode.rdtgrp is/should be used. How should somebody interpret this? Are these two interchangeable tests (and thus making one redundant) or is the test dependent on the scenario (which is not explained anywhere).
Understood. I will try to fix in the next revision.
Thanks
Babu
Babu Moger
reviewerPATCH v6 14/18 fs/resctrl: Control visibility of global per-CPU kernel mode group files
In reply to Babu MogerThe kmode_cpus and kmode_cpus_list files are specific to the RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode. These files are created in a hidden state when an rdtgroup is created.
Introduce resctrl_kmode_global_files_show() to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled.
---
v6: Helper named for the global per-CPU files instead of unhiding every
hidden file on the group.
https://lore.kernel.org/lkml/[email protected]/
--- fs/resctrl/rdtgroup.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
fs/resctrl/rdtgroup.c +19 -0
@@ -1125,6 +1125,24 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,return 0 ; } +/* Show or hide kmode_cpus and kmode_cpus_list on @kn. */ +static void resctrl_kmode_global_files_show (struct kernfs_node *kn,bool show) +{ +struct kernfs_node *kn_file; + + kn_file =kernfs_find_and_get (kn,"kmode_cpus" ); +if (kn_file) { +kernfs_show (kn_file, show); +kernfs_put (kn_file); + } + + kn_file =kernfs_find_and_get (kn,"kmode_cpus_list" ); +if (kn_file) { +kernfs_show (kn_file, show); +kernfs_put (kn_file); + } +} +/* * resctrl_kmode_global_online_cpu() - Program kernel mode association for @cpu * @cpu: CPU that has just been brought online
@@ -1175,6 +1193,7 @@ static void rdtgroup_kmode_global_deactivate(struct rdtgroup *rdtgrp) {resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, false);cpumask_clear (&rdtgrp->kmode_cpu_mask); +resctrl_kmode_global_files_show (rdtgrp->kn, false); }/*
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 14/18] fs/resctrl: Control visibility of global per-CPU kernel mode group files
Hi Babu,
Quoted 7 lines · Babu Moger
The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Introduce
resctrl_kmode_global_files_show()to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled.
This does not sound right and does not match the patch. The visibility of files is per group, not globally whether the mode is enabled or not, right?
It is ok to have cryptic changelogs when changes are small and simple but these changes are not small and simple.
Sidenote (on topic of consistent terminology): Please stick to "activate"/"deactivate" for the mode itself and use "enable"/"disable" when mode is enabled/disabled per-CPU.
Quoted 16 lines
Suggested-by Reinette Chatre <[email protected]>Signed-off-by Babu Moger <[email protected]>---
v6: Helper named for the global per-CPU files instead of unhiding every
hidden file on the group.
https://lore.kernel.org/lkml/[email protected]/--- fs/resctrl/rdtgroup.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)fs/resctrl/rdtgroup.c +0
-0
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1129
Quoted 5 lines
fs/resctrl/rdtgroup.c +2
-0@@ -1125,6 +1125,24 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,return 0 ; } +/* Show or hide kmode_cpus and kmode_cpus_list on @kn. */ +static void resctrl_kmode_global_files_show (struct kernfs_node *kn,bool show)
I think this can be simplified by changing the signature to:
rdtgroup_kmode_global_files_show(struct rdtgroup *rdtgrp, bool show)
Quoted 20 lines
fs/resctrl/rdtgroup.c +16
-0+{ +struct kernfs_node *kn_file; + + kn_file =kernfs_find_and_get (kn,"kmode_cpus" ); +if (kn_file) { +kernfs_show (kn_file, show); +kernfs_put (kn_file); + } + + kn_file =kernfs_find_and_get (kn,"kmode_cpus_list" ); +if (kn_file) { +kernfs_show (kn_file, show); +kernfs_put (kn_file); + } +} +/* * resctrl_kmode_global_online_cpu() - Program kernel mode association for @cpu * @cpu: CPU that has just been brought online
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_deactivate(struct rdtgroup *rdtgrp) · line 1199
Quoted 7 lines
fs/resctrl/rdtgroup.c +1
-0@@ -1175,6 +1193,7 @@ static void rdtgroup_kmode_global_deactivate(struct rdtgroup *rdtgrp) {resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, false);cpumask_clear (&rdtgrp->kmode_cpu_mask); +resctrl_kmode_global_files_show (rdtgrp->kn, false); }/*
Reinette
Babu Moger
reviewerRe: [PATCH v6 14/18] fs/resctrl: Control visibility of global per-CPU kernel mode group files
Hi Reinette,
Quoted 11 lines · Reinette Chatre
Hi Babu,
Quoted 7 lines · Babu Moger
The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Introduce
resctrl_kmode_global_files_show()to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled.
Quoted 5 lines
This does not sound right and does not match the patch. The visibility of files is per group, not globally whether the mode is enabled or not, right?
It is ok to have cryptic changelogs when changes are small and simple but these changes are not small and simple.
"The kmode_cpus and kmode_cpus_list files are specific to the RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode. These files are created in a hidden state when an rdtgroup is created.
Introduce resctrl_kmode_global_files_show() to manage the visibility of these files based on whether a resource group backs the global per-CPU kernel mode. Hide the files when the group is no longer associated with the mode.
This avoids exposing kernel mode configuration files in resource groups where they do not apply."
Quoted 4 lines
Sidenote (on topic of consistent terminology): Please stick to "activate"/"deactivate" for the mode itself and use "enable"/"disable" when mode is enabled/disabled per-CPU.
Sure.
Quoted 20 lines
Quoted 20 lines
Suggested-by Reinette Chatre <[email protected]>Signed-off-by Babu Moger <[email protected]>---
v6: Helper named for the global per-CPU files instead of unhiding every
hidden file on the group.
https://lore.kernel.org/lkml/[email protected]/--- fs/resctrl/rdtgroup.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)fs/resctrl/rdtgroup.c +0
-0@@ -1125,6 +1125,24 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,return 0 ; }
Quoted 5 lines
fs/resctrl/rdtgroup.c static int resctrl_kernel_mode_show(struct kernfs_open_file *of, · line 1129
Quoted 2 lines
fs/resctrl/rdtgroup.c +2
-0+/* Show or hide kmode_cpus and kmode_cpus_list on @kn. */ +static void resctrl_kmode_global_files_show (struct kernfs_node *kn,bool show)I think this can be simplified by changing the signature to:
rdtgroup_kmode_global_files_show(struct rdtgroup *rdtgrp, bool show)
Sure. Will do.
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 14/18] fs/resctrl: Control visibility of global per-CPU kernel mode group files
Hi Babu,
Quoted 14 lines · Babu Moger
Hi Reinette,
Quoted 11 lines · Reinette Chatre
Hi Babu,
Quoted 7 lines · Babu Moger
The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Introduce
resctrl_kmode_global_files_show()to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled.
Quoted 7 lines
Quoted 5 lines
This does not sound right and does not match the patch. The visibility of files is per group, not globally whether the mode is enabled or not, right?
It is ok to have cryptic changelogs when changes are small and simple but these changes are not small and simple.
"The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.
Could the context please help the reader a bit more? Some items that could help:
- *why* are these files specific to global per-CPU kernel mode? (mention that it is used by user space to do the per-CPU enable/disable of the mode)
- *why* is it created in a hidden state? (mention that a resource group can only be assigned to the global per-CPU kernel mode after it has been created via a separate resctrl file)
Quoted 2 lines
Quoted 1 line
Introduce
resctrl_kmode_global_files_show()to manage the visibilityof these files based on whether a resource group backs the global
hmmm ... resctrl_kmode_global_files_show() does not actually do any checks to ensure the resource group backs the global per-CPU kernel mode.
Quoted 2 lines
per-CPU kernel mode. Hide the files when the group is no longer associated with the mode.
Could the patches be organized so that this becomes a symmetrical change that highlights when files become visible and when they become invisible to support the description within this changelog?
Quoted 3 lines
This avoids exposing kernel mode configuration files in resource groups where they do not apply."
Reinette
Babu Moger
reviewerRe: [PATCH v6 14/18] fs/resctrl: Control visibility of global per-CPU kernel mode group files
Hi Reinette,
Quoted 23 lines · Reinette Chatre
Hi Babu,
Quoted 20 lines · Babu Moger
Hi Reinette,
Quoted 16 lines · Reinette Chatre
Hi Babu,
Quoted 7 lines · Babu Moger
The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Introduce
resctrl_kmode_global_files_show()to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled.This does not sound right and does not match the patch. The visibility of files is per group, not globally whether the mode is enabled or not, right?
It is ok to have cryptic changelogs when changes are small and simple but these changes are not small and simple.
Quoted 8 lines
Quoted 1 line
"The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Could the context please help the reader a bit more? Some items that could help:
- *why* are these files specific to global per-CPU kernel mode? (mention that it is used by user space to do the per-CPU enable/disable of the mode)
- *why* is it created in a hidden state? (mention that a resource group can only be assigned to the global per-CPU kernel mode after it has been created via a separate resctrl file)
Sure. Will add that.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Introduce
resctrl_kmode_global_files_show()to manage the visibilityof these files based on whether a resource group backs the global
hmmm ...
resctrl_kmode_global_files_show()does not actually do any checks to ensure the resource group backs the global per-CPU kernel mode.
Yes. Will fix this.
Quoted 6 lines
Quoted 3 lines
per-CPU kernel mode. Hide the files when the group is no longer associated with the mode.
Could the patches be organized so that this becomes a symmetrical change that highlights when files become visible and when they become invisible to support the description within this changelog?
I didn't quite understand this comment. Could you please elaborate?
Thanks,
Babu
Reinette Chatre
maintainerRe: [PATCH v6 14/18] fs/resctrl: Control visibility of global per-CPU kernel mode group files
Hi Babu,
Quoted 11 lines · Babu Moger
Quoted 10 lines · Reinette Chatre
Quoted 9 lines · Babu Moger
Quoted 8 lines · Reinette Chatre
Quoted 7 lines · Babu Moger
The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Introduce
resctrl_kmode_global_files_show()to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled.
...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
per-CPU kernel mode. Hide the files when the group is no longer associated with the mode.
Could the patches be organized so that this becomes a symmetrical change that highlights when files become visible and when they become invisible to support the description within this changelog?
I didn't quite understand this comment. Could you please elaborate?
The subject claims that this patch "Control visibility of global per-CPU kernel mode group files". The changelog builds on this by stating that the visibility depends on "whether the global per-CPU kernel mode is enabled[sic] or disabled[sic]."
The patch delivers only one half of what the subject and changelog describes since it only contains the change that hides the files when the mode is deactivated, the patch does not contain the symmetrical change that shows the files when the mode is activated. Having the "show" and "hide" paths in the same patch would make the change symmetrical and easier to follow.
Reinette
Babu Moger
reviewerRe: [PATCH v6 14/18] fs/resctrl: Control visibility of global per-CPU kernel mode group files
Hi Reinetee,
Quoted 29 lines · Reinette Chatre
Hi Babu,
Quoted 11 lines · Babu Moger
Quoted 10 lines · Reinette Chatre
Quoted 9 lines · Babu Moger
Quoted 8 lines · Reinette Chatre
Quoted 7 lines · Babu Moger
The
kmode_cpusandkmode_cpus_listfiles are specific to theRESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode. These files are created in a hidden state when an rdtgroup is created.Introduce
resctrl_kmode_global_files_show()to manage the visibility of these files based on whether the global per-CPU kernel mode is enabled or disabled....
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
per-CPU kernel mode. Hide the files when the group is no longer associated with the mode.
Could the patches be organized so that this becomes a symmetrical change that highlights when files become visible and when they become invisible to support the description within this changelog?
I didn't quite understand this comment. Could you please elaborate?
The subject claims that this patch "Control visibility of global per-CPU kernel mode group files". The changelog builds on this by stating that the visibility depends on "whether the global per-CPU kernel mode is enabled[sic] or disabled[sic]."
Quoted 6 lines
The patch delivers only one half of what the subject and changelog describes since it only contains the change that hides the files when the mode is deactivated, the patch does not contain the symmetrical change that shows the files when the mode is activated. Having the "show" and "hide" paths in the same patch would make the change symmetrical and easier to follow.
Yes, Got it. I may have re-arrange the patch to do that.
thanks
Babu
Babu Moger
reviewerPATCH v6 15/18 fs/resctrl: Reject mode changes for groups backing kernel mode
In reply to Babu MogerThe RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode can be backed by only one resource group at a time. The active kernel-mode association depends on the group's mode and, for a monitor group, its parent control group.
Prevent mode changes for a resource group that backs the active kernel mode. Also prevent mode changes to the parent control group of a backing monitor group, and prevent a backing monitor group from being moved to a different parent. These restrictions ensure that the active kernel-mode association remains valid and consistent.
---
v6: New patch to fix sashiko feedback.
https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com --- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
fs/resctrl/internal.h +2 -0
@@ -462,6 +462,8 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,void resctrl_bmec_files_show (struct rdt_resource *r,struct kernfs_node *l3_mon_kn,bool show); +bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp); +int resctrl_num_mbm_cntrs_show (struct kernfs_open_file *of,struct seq_file *s,void *v); int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s,
fs/resctrl/rdtgroup.c +35 -0
@@ -1738,6 +1738,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)return true; } +/* True when @rdtgrp or one of its monitor groups backs the kernel mode. */ +bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp) +{ +struct rdtgroup *child; + +if (!resctrl_kmode.rdtgrp) +return false; + +if (resctrl_kmode.rdtgrp == rdtgrp) +return true; + +if (rdtgrp->type !=RDTCTRL_GROUP ) +return false; + +list_for_each_entry (child, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) +if (child == resctrl_kmode.rdtgrp) +return true; + +return false; +} +/* * rdtgroup_mode_write - Modify the resource group's mode */
@@ -1778,6 +1799,12 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, goto out; } +if (rdtgroup_has_kmode_global (rdtgrp)) { +rdt_last_cmd_puts ("Cannot change mode for kernel-mode assigned group\n" ); + ret = -EINVAL ; + goto out; + } +if (!strcmp (buf,"shareable" )) {if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { ret =rdtgroup_locksetup_exit (rdtgrp);
@@ -4697,6 +4724,14 @@ static int rdtgroup_rename(struct kernfs_node *kn, goto out; } +/* Reject moving to different parent if group backs kernel-mode */ +if (rdtgrp == resctrl_kmode.rdtgrp && + rdtgrp->mon.parent != new_prdtgrp) { +rdt_last_cmd_puts ("Cannot move a group that backs kernel mode\n" ); + ret = -EPERM ; + goto out; + } +/* * Allocate the cpumask for use in mongrp_reparent() to avoid the * possibility of failing to allocate it after kernfs_rename() has
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 15/18] fs/resctrl: Reject mode changes for groups backing kernel mode
Hi Babu,
Quoted 3 lines · Babu Moger
The
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode can be backed by only one resource group at a time. The active kernel-mode association depends on the group's mode and, for a monitor group, its parent control group.
I am not able to parse above. The second sentence is difficult to decipher. Apart from this it also assumes reader is familiar with how a group can back the global kernel mode but this is behavior that does not exist here.
Quoted 5 lines
Prevent mode changes for a resource group that backs the active kernel mode. Also prevent mode changes to the parent control group of a backing monitor group, and prevent a backing monitor group from being moved to a different parent. These restrictions ensure that the active kernel-mode association remains valid and consistent.
"These restrictions ensure that the active kernel-mode association remains valid and consistent." could this be more specific?
This patch does two things:
- prevent user from switching the mode of the resource group backing the global per-CPU kernel mode. Why? The reason for this is never given and there is only a hint in the *code* of the *next* patch that requires the resource group to be shareable. The next changelog does not mention this requirement either.
This is important to highlight since a resource group backing the global kernel mode would have all its resource allocations shared by kernel work done on behalf of *all* tasks. This makes it a clear requirement for this group to be shareable and for its mode to never change.
This highlights that there is an ordering issue with the patches since this series establishes the requirement after it enforces the requirement.
- prevent a monitor group backing global kernel mode from being moved to another control group. Why should this be prevented? Could the global kernel mode not just be reconfigured, just like when user space provides it a new group? This is a design decision that is never motivated.
Quoted 14 lines
Signed-off-by Babu Moger <[email protected]>---
v6: New patch to fix sashiko feedback.https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com --- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)fs/resctrl/internal.h +0
-0
fs/resctrl/internal.h ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf, · line 465
Quoted 4 lines
fs/resctrl/internal.h +1
-0@@ -462,6 +462,8 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,void resctrl_bmec_files_show (struct rdt_resource *r,struct kernfs_node *l3_mon_kn,bool show); +bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp);
Does not look like this is needed, can this function just be static within fs/resctrl/rdtgroup.c?
Quoted 37 lines
fs/resctrl/internal.h +1
-0+int resctrl_num_mbm_cntrs_show (struct kernfs_open_file *of,struct seq_file *s,void *v); int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s,fs/resctrl/rdtgroup.c +21
-0@@ -1738,6 +1738,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)return true; } +/* True when @rdtgrp or one of its monitor groups backs the kernel mode. */ +bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp) +{ +struct rdtgroup *child; + +if (!resctrl_kmode.rdtgrp) +return false; + +if (resctrl_kmode.rdtgrp == rdtgrp) +return true; + +if (rdtgrp->type !=RDTCTRL_GROUP ) +return false; + +list_for_each_entry (child, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) +if (child == resctrl_kmode.rdtgrp) +return true; + +return false; +} +/* * rdtgroup_mode_write - Modify the resource group's mode */
fs/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1803
Quoted 5 lines
fs/resctrl/rdtgroup.c +2
-0@@ -1778,6 +1799,12 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, goto out; } +if (rdtgroup_has_kmode_global (rdtgrp)) { +rdt_last_cmd_puts ("Cannot change mode for kernel-mode assigned group\n" );
The messages to user space also switch back and forth between kernel mode and kernel-mode.
fs/resctrl/rdtgroup.c static int rdtgroup_rename(struct kernfs_node *kn, · line 4727
Quoted 12 lines
fs/resctrl/rdtgroup.c +5
-0+ ret = -EINVAL ; + goto out; + } +if (!strcmp (buf,"shareable" )) {if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { ret =rdtgroup_locksetup_exit (rdtgrp);@@ -4697,6 +4724,14 @@ static int rdtgroup_rename(struct kernfs_node *kn, goto out; } +/* Reject moving to different parent if group backs kernel-mode */
Comment states the obvious. Could it instead state *why* this is rejected?
fs/resctrl/rdtgroup.c static int rdtgroup_rename(struct kernfs_node *kn, · line 4737
Quoted 10 lines
fs/resctrl/rdtgroup.c +7
-0+if (rdtgrp == resctrl_kmode.rdtgrp && + rdtgrp->mon.parent != new_prdtgrp) { +rdt_last_cmd_puts ("Cannot move a group that backs kernel mode\n" ); + ret = -EPERM ; + goto out; + } +/* * Allocate the cpumask for use in mongrp_reparent() to avoid the * possibility of failing to allocate it after kernfs_rename() has
Reinette
Babu Moger
reviewerRe: [PATCH v6 15/18] fs/resctrl: Reject mode changes for groups backing kernel mode
Hi Reinette,
Quoted 10 lines · Reinette Chatre
Hi Babu,
Quoted 3 lines · Babu Moger
The
RESCTRL_GLOBAL_ENABLE_PER_CPUkernel mode can be backed by only one resource group at a time. The active kernel-mode association depends on the group's mode and, for a monitor group, its parent control group.I am not able to parse above. The second sentence is difficult to decipher. Apart from this it also assumes reader is familiar with how a group can back the global kernel mode but this is behavior that does not exist here.
Ack. Will re-write the changelog.
Quoted 9 lines
Quoted 5 lines
Prevent mode changes for a resource group that backs the active kernel mode. Also prevent mode changes to the parent control group of a backing monitor group, and prevent a backing monitor group from being moved to a different parent. These restrictions ensure that the active kernel-mode association remains valid and consistent.
"These restrictions ensure that the active kernel-mode association remains valid and consistent." could this be more specific?
Quoted 12 lines
This patch does two things:
- prevent user from switching the mode of the resource group backing the global per-CPU kernel mode. Why? The reason for this is never given and there is only a hint in the *code* of the *next* patch that requires the resource group to be shareable. The next changelog does not mention this requirement either.
This is important to highlight since a resource group backing the global kernel mode would have all its resource allocations shared by kernel work done on behalf of *all* tasks. This makes it a clear requirement for this group to be shareable and for its mode to never change.
This highlights that there is an ordering issue with the patches since this series establishes the requirement after it enforces the requirement.
This check is only exercised when userspace attempts to activate the kernel mode, which is introduced in the next patch. I can merge this change in the next patch.
Quoted 4 lines
- prevent a monitor group backing global kernel mode from being moved to another control group. Why should this be prevented? Could the global kernel mode not just be reconfigured, just like when user space provides it a new group? This is a design decision that is never motivated.
[1] There is no specific reason for preventing it. I just did not consider it a use case. Also, changing the parent of a backing monitor group affects both groups because the kernel resource allocation is moved from one group to another.
If there is a valid use case for supporting this, we could allow it and update the kernel mode association accordingly. What do you think?
Quoted 19 lines
Quoted 19 lines
Signed-off-by Babu Moger <[email protected]>---
v6: New patch to fix sashiko feedback.https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com --- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)fs/resctrl/internal.h +0
-0@@ -462,6 +462,8 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,void resctrl_bmec_files_show (struct rdt_resource *r,struct kernfs_node *l3_mon_kn,bool show);
Quoted 3 lines
fs/resctrl/internal.h ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf, · line 465
Quoted 1 line
fs/resctrl/internal.h +1
-0+bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp);Does not look like this is needed, can this function just be static within
fs/resctrl/rdtgroup.c?
Yes. The only issue is the build dependency. Since the function is declared static, it needs a caller in the same patch. One option is to merge this change with the next patch, which is where the function is first used.
Quoted 41 lines
Quoted 41 lines
fs/resctrl/internal.h +1
-0+int resctrl_num_mbm_cntrs_show (struct kernfs_open_file *of,struct seq_file *s,void *v); int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s,fs/resctrl/rdtgroup.c +21
-0@@ -1738,6 +1738,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)return true; } +/* True when @rdtgrp or one of its monitor groups backs the kernel mode. */ +bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp) +{ +struct rdtgroup *child; + +if (!resctrl_kmode.rdtgrp) +return false; + +if (resctrl_kmode.rdtgrp == rdtgrp) +return true; + +if (rdtgrp->type !=RDTCTRL_GROUP ) +return false; + +list_for_each_entry (child, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) +if (child == resctrl_kmode.rdtgrp) +return true; + +return false; +} +/* * rdtgroup_mode_write - Modify the resource group's mode */ @@ -1778,6 +1799,12 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, goto out; }
Quoted 4 lines
fs/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1803
Quoted 2 lines
fs/resctrl/rdtgroup.c +2
-0+if (rdtgroup_has_kmode_global (rdtgrp)) { +rdt_last_cmd_puts ("Cannot change mode for kernel-mode assigned group\n" );The messages to user space also switch back and forth between kernel mode and kernel-mode.
Will change to "kernel mode".
Quoted 12 lines
Quoted 12 lines
fs/resctrl/rdtgroup.c +4
-0+ ret = -EINVAL ; + goto out; + } +if (!strcmp (buf,"shareable" )) {if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { ret =rdtgroup_locksetup_exit (rdtgrp);@@ -4697,6 +4724,14 @@ static int rdtgroup_rename(struct kernfs_node *kn, goto out; }
Quoted 3 lines
fs/resctrl/rdtgroup.c static int rdtgroup_rename(struct kernfs_node *kn, · line 4727
Quoted 1 line
fs/resctrl/rdtgroup.c +1
-0+/* Reject moving to different parent if group backs kernel-mode */ Comment states the obvious. Could it instead state *why* this is rejected?
Same reason as in [1].
Thanks
Babu
Reinette Chatre
maintainerRe: [PATCH v6 15/18] fs/resctrl: Reject mode changes for groups backing kernel mode
Hi Babu,
Quoted 24 lines · Babu Moger
Quoted 10 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
Prevent mode changes for a resource group that backs the active kernel mode. Also prevent mode changes to the parent control group of a backing monitor group, and prevent a backing monitor group from being moved to a different parent. These restrictions ensure that the active kernel-mode association remains valid and consistent.
"These restrictions ensure that the active kernel-mode association remains valid and consistent." could this be more specific?
Quoted 12 lines
This patch does two things:
- prevent user from switching the mode of the resource group backing the global per-CPU kernel mode. Why? The reason for this is never given and there is only a hint in the *code* of the *next* patch that requires the resource group to be shareable. The next changelog does not mention this requirement either.
This is important to highlight since a resource group backing the global kernel mode would have all its resource allocations shared by kernel work done on behalf of *all* tasks. This makes it a clear requirement for this group to be shareable and for its mode to never change.
This highlights that there is an ordering issue with the patches since this series establishes the requirement after it enforces the requirement.
Quoted 1 line
This check is only exercised when userspace attempts to activate the kernel mode, which is introduced in the next patch. I can merge this change in the next patch.
The next patch is already quite large. I would instead suggest that the changelog of next patch includes why a resource group backing the global kernel mode is required to be shareable. This patch can then follow after that to ensure that the mode of a resource group backing kernel mode cannot change.
Quoted 6 lines
Quoted 5 lines
- prevent a monitor group backing global kernel mode from being moved to another control group. Why should this be prevented? Could the global kernel mode not just be reconfigured, just like when user space provides it a new group? This is a design decision that is never motivated.
Quoted 8 lines
[1] There is no specific reason for preventing it. I just did not consider it a use case. Also, changing the parent of a backing monitor group affects both groups because the kernel resource allocation is moved from one group to another.
If there is a valid use case for supporting this, we could allow it and update the kernel mode association accordingly. What do you think?
Up to you, but please make these design decisions explicit. Do not hide them behind hand waving like "These restrictions ensure that the active kernel-mode association remains valid and consistent.". If you choose to delay this support until your customers ask for it then please change the message to something that highlights this. For example, "Cannot move a group that backs kernel mode" can be something like "Moving the MON group that backs global_enable_per_cpu kernel mode is not supported."
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines
Signed-off-by Babu Moger <[email protected]>---
v6: New patch to fix sashiko feedback.
https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com
---
fs/resctrl/internal.h| 2 ++
fs/resctrl/rdtgroup.c| 35 +++++++++++++++++++++++++++++++++++2 files changed, 37 insertions(+)Quoted 10 lines
fs/resctrl/internal.h ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf, · line 464
Quoted 8 lines
fs/resctrl/internal.h +0
-0@@ -462,6 +462,8 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf, void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *l3_mon_kn, bool show); +bool rdtgroup_has_kmode_global(struct rdtgroup *rdtgrp);Does not look like this is needed, can this function just be static within
fs/resctrl/rdtgroup.c?
Quoted 4 lines
Yes. The only issue is the build dependency. Since the function is declared static, it needs a caller in the same patch. One option is to merge this change with the next patch, which is where the function is first used.
There is a caller in this patch, no?
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
fs/resctrl/internal.h +1
-0+ int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s, void *v); int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s,fs/resctrl/rdtgroup.c +0
-0@@ -1738,6 +1738,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp) return true; }+/* True when @rdtgrp or one of its monitor groups backs the kernel mode. */
fs/resctrl/rdtgroup.c +19
-0+bool rdtgroup_has_kmode_global (struct rdtgroup *rdtgrp) +{ + struct rdtgroup *child; + + if (!resctrl_kmode.rdtgrp) + return false; + + if (resctrl_kmode.rdtgrp == rdtgrp) + return true; + + if (rdtgrp->type != RDTCTRL_GROUP) + return false; + + list_for_each_entry(child, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) + if (child == resctrl_kmode.rdtgrp) + return true; + + return false; +}
Quoted 8 lines
Quoted 8 lines
fs/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1801
Quoted 8 lines
+
/*
*rdtgroup_mode_write- Modify the resource group's mode */fs/resctrl/rdtgroup.c +0
-0@@ -1778,6 +1799,12 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, goto out; } + if (rdtgroup_has_kmode_global(rdtgrp)) {
Above calls rdtgroup_has_kmode_global().
Quoted 21 lines
Quoted 3 lines
fs/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1803
Quoted 1 line
fs/resctrl/rdtgroup.c +1
-0+ rdt_last_cmd_puts("Cannot change mode for kernel-mode assigned group\n");The messages to user space also switch back and forth between kernel mode and kernel-mode.
Will change to "kernel mode".
Quoted 14 lines
Quoted 11 lines
fs/resctrl/rdtgroup.c +4
-0+ ret = -EINVAL; + goto out; + } + if (!strcmp(buf, "shareable")) { if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { ret = rdtgroup_locksetup_exit(rdtgrp);@@ -4697,6 +4724,14 @@ static int rdtgroup_rename(struct kernfs_node *kn, goto out; }Quoted 1 line
+ /* Reject moving to different parent if group backs kernel-mode */
Comment states the obvious. Could it instead state *why* this is rejected?
Quoted 1 line
Same reason as in [1].
ok ... but could the comment be changed to reflect this design choice instead of stating what is obvious just by looking at the code?
Reinette
Babu Moger
reviewerRe: [PATCH v6 15/18] fs/resctrl: Reject mode changes for groups backing kernel mode
Hi Reinette,
Quoted 27 lines · Reinette Chatre
Hi Babu,
Quoted 24 lines · Babu Moger
Quoted 22 lines · Reinette Chatre
Quoted 5 lines · Babu Moger
Prevent mode changes for a resource group that backs the active kernel mode. Also prevent mode changes to the parent control group of a backing monitor group, and prevent a backing monitor group from being moved to a different parent. These restrictions ensure that the active kernel-mode association remains valid and consistent.
"These restrictions ensure that the active kernel-mode association remains valid and consistent." could this be more specific?
This patch does two things:
- prevent user from switching the mode of the resource group backing the global per-CPU kernel mode. Why? The reason for this is never given and there is only a hint in the *code* of the *next* patch that requires the resource group to be shareable. The next changelog does not mention this requirement either.
This is important to highlight since a resource group backing the global kernel mode would have all its resource allocations shared by kernel work done on behalf of *all* tasks. This makes it a clear requirement for this group to be shareable and for its mode to never change.
This highlights that there is an ordering issue with the patches since this series establishes the requirement after it enforces the requirement.
Quoted 7 lines
Quoted 1 line
This check is only exercised when userspace attempts to activate the kernel mode, which is introduced in the next patch. I can merge this change in the next patch.
The next patch is already quite large. I would instead suggest that the changelog of next patch includes why a resource group backing the global kernel mode is required to be shareable. This patch can then follow after that to ensure that the mode of a resource group backing kernel mode cannot change.
Sure. Will move after patch 16.
Quoted 16 lines
Quoted 7 lines
Quoted 6 lines
- prevent a monitor group backing global kernel mode from being moved to another control group. Why should this be prevented? Could the global kernel mode not just be reconfigured, just like when user space provides it a new group? This is a design decision that is never motivated.
Quoted 8 lines
[1] There is no specific reason for preventing it. I just did not consider it a use case. Also, changing the parent of a backing monitor group affects both groups because the kernel resource allocation is moved from one group to another.
If there is a valid use case for supporting this, we could allow it and update the kernel mode association accordingly. What do you think?
Quoted 8 lines
Up to you, but please make these design decisions explicit. Do not hide them behind hand waving like "These restrictions ensure that the active kernel-mode association remains valid and consistent.". If you choose to delay this support until your customers ask for it then please change the message to something that highlights this. For example, "Cannot move a group that backs kernel mode" can be something like "Moving the MON group that backs
global_enable_per_cpukernel mode is not supported."
Ok. Sure.
Quoted 21 lines
Quoted 21 lines
Quoted 19 lines
Quoted 14 lines
Signed-off-by Babu Moger <[email protected]>---
v6: New patch to fix sashiko feedback.
https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com--- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)fs/resctrl/internal.h +0
-0fs/resctrl/internal.h ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf, · line 464
Quoted 3 lines
fs/resctrl/internal.h +0
-0@@ -462,6 +462,8 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf, void resctrl_bmec_files_show(struct rdt_resource *r, struct kernfs_node *l3_mon_kn, bool show); +bool rdtgroup_has_kmode_global(struct rdtgroup *rdtgrp);Does not look like this is needed, can this function just be static within
fs/resctrl/rdtgroup.c?
Quoted 6 lines
Quoted 4 lines
Yes. The only issue is the build dependency. Since the function is declared static, it needs a caller in the same patch. One option is to merge this change with the next patch, which is where the function is first used.
There is a caller in this patch, no?
My bad.
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
fs/resctrl/internal.h +1
-0+ int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s, void *v); int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s,fs/resctrl/rdtgroup.c +20
-0@@ -1738,6 +1738,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp) return true; } +/* True when @rdtgrp or one of its monitor groups backs the kernel mode. */ +bool rdtgroup_has_kmode_global(struct rdtgroup *rdtgrp) +{ + struct rdtgroup *child; + + if (!resctrl_kmode.rdtgrp) + return false; + + if (resctrl_kmode.rdtgrp == rdtgrp) + return true; + + if (rdtgrp->type != RDTCTRL_GROUP) + return false; + + list_for_each_entry(child, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) + if (child == resctrl_kmode.rdtgrp) + return true; + + return false; +} + /*
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
fs/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1801
Quoted 6 lines
fs/resctrl/rdtgroup.c +0
-0* rdtgroup_mode_write - Modify the resource group's mode */ @@ -1778,6 +1799,12 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, goto out; } + if (rdtgroup_has_kmode_global(rdtgrp)) {Above calls
rdtgroup_has_kmode_global().
You are right. This can be static.
Quoted 22 lines
Quoted 22 lines
Quoted 4 lines
fs/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1803
Quoted 2 lines
fs/resctrl/rdtgroup.c +1
-0+ rdt_last_cmd_puts("Cannot change mode for kernel-mode assigned group\n");The messages to user space also switch back and forth between kernel mode and kernel-mode.
Will change to "kernel mode".
Quoted 14 lines
fs/resctrl/rdtgroup.c static int rdtgroup_rename(struct kernfs_node *kn, · line 4726
Quoted 12 lines
fs/resctrl/rdtgroup.c +4
-0+ ret = -EINVAL; + goto out; + } + if (!strcmp(buf, "shareable")) { if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { ret = rdtgroup_locksetup_exit(rdtgrp);@@ -4697,6 +4724,14 @@ static int rdtgroup_rename(struct kernfs_node *kn, goto out; } + /* Reject moving to different parent if group backs kernel-mode */Comment states the obvious. Could it instead state *why* this is rejected?
Quoted 4 lines
Quoted 1 line
Same reason as in [1].
ok ... but could the comment be changed to reflect this design choice instead of stating what is obvious just by looking at the code?
Sure. Will do.
Thanks
Babu
Babu Moger
reviewerPATCH v6 16/18 fs/resctrl: Add interface to modify kernel mode via info/kernel_mode
In reply to Babu MogerKernel modes determine how resctrl allocation and monitoring associations are applied when execution transitions between user mode and kernel mode.
Add write support to info/kernel_mode to allow user space to configure the active kernel mode and any required resource group associations.
Document the interface in Documentation/filesystems/resctrl.rst.
---
v6: Use flattened resctrl_kmode and global_enable_per_cpu. Omitted
parameters keep the values shown by reading the file. Drop the ctrl=inherit;mon=inherit no-op. Parse options with strsep(), as the other resctrl writers do, and split validation out of the write path.
https://lore.kernel.org/lkml/[email protected]/
v5: Adapt to the resctrl_kcfg caps and active split. Accept
assign_global_enable_per_cpu:ctrl=;mon=;group=<ctrl>/<mon>/ writes. Treat both ctrl=inherit and mon=inherit as a no-op. Use group=// for the default control group. Show associated kmode files through resctrl_hidden_files_set_visible().
Added kmode check in rdtgroup_locksetup_enter(), rdtgroup_mode_write() and rdtgroup_rename().
Simplify kernel-doc for write and activate helpers.
v4: Validate input before tearing down the active association so failures
retain the previous association. Allow assign_mon on CTRL_MON and MON groups; require a control group when control assignment is inherit.
v3: New patch to make info/kernel_mode writable.
--- Documentation/filesystems/resctrl.rst | 28 +++ fs/resctrl/rdtgroup.c | 274 +++++++++++++++++++++++++- 2 files changed, 301 insertions(+), 1 deletion(-)
Documentation/filesystems/resctrl.rst +28 -0
@@ -575,6 +575,34 @@ conveyed in the error returns from file operations. E.g. [inherit_user] global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Writes use the same line format as read, without square brackets and + with a trailing newline. + + inherit_user is written without any parameters. + + For global_enable_per_cpu, the parameters are optional. An omitted + ctrl=, mon=, or group= keeps the value currently shown. Parameters + may appear in any order. Empty values are rejected. + + Selecting a new mode, parameter, or group replaces the active + association. A new global_enable_per_cpu association sets that + group's kmode_cpus to every online CPU. Errors are reported in + "info/last_cmd_status". + Example:: + + # mkdir ctrl1 + # echo "global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//" \ + > info/kernel_mode + + # cat info/kernel_mode + inherit_user + [global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//] + + # echo "inherit_user" > info/kernel_mode + # cat info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Resource alloc and monitor groups =================================
fs/resctrl/rdtgroup.c +273 -1
288 lines not on this page · raw message
Signature · 1 line
2.43.0
Reinette Chatre
maintainerRe: [PATCH v6 16/18] fs/resctrl: Add interface to modify kernel mode via info/kernel_mode
Hi Babu,
nit: subject states this adds new interfaces but that is not true?
Quoted 10 lines · Babu Moger
--- Documentation/filesystems/resctrl.rst | 28 +++ fs/resctrl/rdtgroup.c | 274 +++++++++++++++++++++++++- 2 files changed, 301 insertions(+), 1 deletion(-)Documentation/filesystems/resctrl.rst +0
-0
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 584
Quoted 10 lines
Documentation/filesystems/resctrl.rst +7
-0@@ -575,6 +575,34 @@ conveyed in the error returns from file operations. E.g. [inherit_user] global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Writes use the same line format as read, without square brackets and + with a trailing newline. + + inherit_user is written without any parameters. + + For global_enable_per_cpu, the parameters are optional. An omitted + ctrl=, mon=, or group= keeps the value currently shown. Parameters
"keeps the value currently shown" -> "keeps the default values" Text as suggested, or similar, will connect this text with the earlier "When the mode is not active, the parameters are the defaults ..." Although, please check earlier comment about the "parameters are the defaults" text.
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 585
Quoted 1 line
Documentation/filesystems/resctrl.rst +1
-0+ may appear in any order. Empty values are rejected.
More on this later but I do not think it is possible for parameters to appear in any order ...
Quoted 31 lines
Documentation/filesystems/resctrl.rst +20
-0+ + Selecting a new mode, parameter, or group replaces the active + association. A new global_enable_per_cpu association sets that + group's kmode_cpus to every online CPU. Errors are reported in + "info/last_cmd_status". + Example:: + + # mkdir ctrl1 + # echo "global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//" \ + > info/kernel_mode + + # cat info/kernel_mode + inherit_user + [global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//] + + # echo "inherit_user" > info/kernel_mode + # cat info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Resource alloc and monitor groups =================================fs/resctrl/rdtgroup.c +0
-0@@ -1216,6 +1216,277 @@ static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) resctrl_kmode.mon =KMODE_ASSIGN ; }
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1228
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+/* Program @rdtgrp on every online CPU and show its kmode_cpus files. */ +static void rdtgroup_kmode_global_activate (struct rdtgroup *rdtgrp) +{ +cpumask_copy (&rdtgrp->kmode_cpu_mask, cpu_online_mask); +resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, true); +resctrl_kmode_global_files_show (rdtgrp->kn, true); +} + +/** +* rdtgroup_by_kmode_path() - Resolve a "<ctrl>/<mon>/" path to an rdtgroup
It is a contradiction to have description read "Resolve a "<ctrl>/<mon>/" path" and then the control and monitor group names are provided as separate parameters
The function name also includes "path" but there is nothing about a path in the implementation, the caller parses the path, no?
Quoted 11 lines
fs/resctrl/rdtgroup.c +11
-0+* @ctrl_name: CTRL_MON group name, or "" for the default control group. +* @mon_name: MON group name, or "" to select the control group itself. +* +* Matches the path syntax displayed by resctrl_kernel_mode_show(): +* "//" - the default CTRL_MON group +* "<ctrl>//" - CTRL_MON group @ctrl_name +* "/<mon>/" - MON group @mon_name under the default control group +* "<ctrl>/<mon>/" - MON group @mon_name under control group @ctrl_name +* +* Return: Pointer to the matching rdtgroup, or NULL if no such group exists. +*/
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1249
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+static struct rdtgroup *rdtgroup_by_kmode_path (const char *ctrl_name, +const char *mon_name) +{ +struct rdtgroup *rdtg, *parent = &rdtgroup_default; + +if (*ctrl_name) { + parent =NULL ; +list_for_each_entry (rdtg, &rdt_all_groups, rdtgroup_list) { +if (rdtg->type !=RDTCTRL_GROUP ) +continue ;
All entries of rdt_all_groups are of type RDTCTRL_GROUP, no?
Quoted 34 lines
fs/resctrl/rdtgroup.c +34
-0+if (!strcmp (rdt_kn_name (rdtg->kn), ctrl_name)) { + parent = rdtg; +break ; + } + } + } +if (!parent) +return NULL ; + +if (!*mon_name) +return parent; + +list_for_each_entry (rdtg, &parent->mon.crdtgrp_list, mon.crdtgrp_list) +if (!strcmp (rdt_kn_name (rdtg->kn), mon_name)) +return rdtg; +return NULL ; +} + +static int resctrl_kmode_parse_state (char *val,enum kmode_state *state) +{ +if (!strcmp (val,"assign" )) { + *state =KMODE_ASSIGN ; +return 0 ; + } +if (!strcmp (val,"inherit" )) { + *state =KMODE_INHERIT ; +return 0 ; + } +return -EINVAL ; +} + +static int resctrl_kmode_parse_group (char *group,struct rdtgroup **rdtgrp) +{ +struct rdtgroup *grp;
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1293
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+char *mon, *slash; + + slash =strchr (group,'/' ); +if (!slash) { +rdt_last_cmd_puts ("Group must be <CTRL_MON>/<MON>/\n" ); +return -EINVAL ; + } + *slash ='\0' ; + mon =strim (slash +1 ); +
The reason why we picked the <CTRL_MON>/<MON>/ syntax is because "/" is the one character that is not allowed by kernfs to be in a directory name, additionally resctrl rejects \n in group names.
This parsing should thus take care with stripping spaces and just parsing in general to support all the different resource group names that users may be able to create (it may even contain ";"). Because of this it seems that it should be required for the resource group to be the last parameter provided by user space since it will be terminated by \n that cannot be in a resource group name?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1300
Quoted 7 lines
fs/resctrl/rdtgroup.c +7
-0+ slash =strchr (mon,'/' ); +if (!slash || slash[1 ] !='\0' ) { +rdt_last_cmd_puts ("Group must be <CTRL_MON>/<MON>/\n" ); +return -EINVAL ; + } + *slash ='\0' ; +
The user should not be required to provide a monitor group when "mon=inherit" or if system does not support monitoring.
Quoted 8 lines
fs/resctrl/rdtgroup.c +8
-0+ grp =rdtgroup_by_kmode_path (group, mon); +if (!grp) { +rdt_last_cmd_puts ("Group not found\n" ); +return -EINVAL ; + } + *rdtgrp = grp; +return 0 ; +}
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1318
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+ +static int resctrl_kmode_parse_parameters (char *params,enum kmode_state *ctrl, +enum kmode_state *mon, +struct rdtgroup **rdtgrp) +{ +char *key, *tok; + +while ((tok =strsep (¶ms,";" ))) { + tok =strim (tok); +if (!*tok)
Please use the same string parsing patterns as the rest of resctrl. Specifically, please use the familiar (to resctrl) comparison against '\0' as in "if (tok[0] == '\0')" instead of pointer dereference like above (and below).
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1323
Quoted 5 lines
fs/resctrl/rdtgroup.c +5
-0+continue ; + + key =strsep (&tok,"=" ); +if (!tok) { +rdt_last_cmd_puts ("Empty kernel mode parameters\n" );
Not sure how accurate messages should be but this is just duplicate error message of when there are no kernel mode parameters when the issue is actually that "=" is missing.
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1333
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+return -EINVAL ; + } + key =strim (key); + tok =strim (tok); +if (!*key || !*tok) { +rdt_last_cmd_puts ("Empty kernel mode parameters\n" ); +return -EINVAL ; + } + +if (!strcmp (key,"ctrl" )) {
Should this not fail on a system that is not capable of allocation?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1338
Quoted 5 lines
fs/resctrl/rdtgroup.c +5
-0+if (resctrl_kmode_parse_state (tok, ctrl)) { +rdt_last_cmd_puts ("Invalid ctrl= parameter\n" ); +return -EINVAL ; + } + }else if (!strcmp (key,"mon" )) {
Similarly this should fail on system that does not support monitoring?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1347
Quoted 9 lines
fs/resctrl/rdtgroup.c +9
-0+if (resctrl_kmode_parse_state (tok, mon)) { +rdt_last_cmd_puts ("Invalid mon= parameter\n" ); +return -EINVAL ; + } + }else if (!strcmp (key,"group" )) { +if (resctrl_kmode_parse_group (tok, rdtgrp)) +return -EINVAL ; + }else { +rdt_last_cmd_puts ("Unknown kernel mode parameter\n" );
nit: "Unknown" -> "Unsupported"
Quoted 8 lines
fs/resctrl/rdtgroup.c +8
-0+return -EINVAL ; + } + } +return 0 ; +} + +static int resctrl_kmode_global_validate(struct rdtgroup *rdtgrp, + enum kmode_state ctrl,
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1365
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+ enum kmode_state mon) +{ +if (ctrl ==KMODE_ASSIGN && !resctrl_arch_alloc_capable ()) { +rdt_last_cmd_puts ("ctrl=assign is not supported\n" ); +return -EINVAL ; + } +if (mon ==KMODE_ASSIGN && !resctrl_arch_mon_capable ()) { +rdt_last_cmd_puts ("mon=assign is not supported\n" ); +return -EINVAL ; + }
Does this mean that user can provide "ctrl=inherit" on system that does not support allocation and "mon=inherit" on system that does not support monitoring? That does not look right.
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1378
Quoted 13 lines
fs/resctrl/rdtgroup.c +13
-0+if (mon ==KMODE_INHERIT && rdtgrp->type ==RDTMON_GROUP ) { +rdt_last_cmd_puts ("A monitor group requires mon=assign to use its RMID\n" ); +return -EINVAL ; + } +if (rdtgrp->mode !=RDT_MODE_SHAREABLE ) { +rdt_last_cmd_puts ("The group is not in shareable mode\n" ); +return -EINVAL ; + } +if (rdtgrp->type ==RDTMON_GROUP && + rdtgrp->mon.parent->mode !=RDT_MODE_SHAREABLE ) { +rdt_last_cmd_puts ("The parent group is not in shareable mode\n" ); +return -EINVAL ; + }
I think it will be useful to organize the "kernel_mode" resctrl.rst portion for writing to "kernel_mode" similar to the portion for reading to clearly associate the above rules with the "global_enable_per_cpu" mode.
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1387
Quoted 9 lines
fs/resctrl/rdtgroup.c +9
-0+ +return 0 ; +} + +static void resctrl_kmode_switch (enum resctrl_kernel_mode mode, +struct rdtgroup *rdtgrp, +enum kmode_state ctrl,enum kmode_state mon) +{ +if (resctrl_kmode.rdtgrp)
Please do not use resctrl_kmode.rdtgrp as synonym for and interchangeably with resctrl_kmode.kmode_cur == RESCTRL_GLOBAL_ENABLE_PER_CPU. Please check other places too, like in resctrl_kernel_mode_write()
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1390
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+rdtgroup_kmode_global_deactivate (resctrl_kmode.rdtgrp); + + resctrl_kmode.kmode_cur = mode;
Now looking at how things come together, what do you think of renaming "kmode_cur" to "active"? "kmode" in "kmode_cur" is redundant and "active" looks to be a good match with existing documentation ("... with the active mode enclosed in square brackets") and code like rdtgroup_kmode_global_activate() and "active" used as local variable in resctrl_kernel_mode_show().
Similar to this, could resctrl_kmode.kmode_sup be renamed to resctrl_kmode.supported?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1391
Quoted 1 line
fs/resctrl/rdtgroup.c +1
-0+if (mode !=RESCTRL_GLOBAL_ENABLE_PER_CPU ) {
If this is needed please make the test explicit to the "inherit" mode.
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1394
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+ resctrl_kmode.rdtgrp =NULL ; + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ;
Something does not look right here ... function parameters provide values that are not used. If any reset is needed, should it not be done as part of rdtgroup_kmode_global_deactivate() especially since it appears that the contract with architecture is for disable of global kernel mode to mean that inherit mode has to be enabled?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1407
Quoted 13 lines
fs/resctrl/rdtgroup.c +13
-0+return ; + } + + resctrl_kmode.ctrl = ctrl; + resctrl_kmode.mon = mon; + resctrl_kmode.rdtgrp = rdtgrp; +rdtgroup_kmode_global_activate (rdtgrp); +} + +/** +* resctrl_kernel_mode_write() - Set the active kernel mode +* @of: kernfs open file +* @buf: write buffer
Could this be more specific about what the buffer represents? For example,
Kernel mode line written by user space
Quoted 20 lines
fs/resctrl/rdtgroup.c +20
-0+* @nbytes: length of @buf +* @off: unused +* +* Return: @nbytes on success, negative errno on error. +*/ +static ssize_t resctrl_kernel_mode_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdtgroup *rdtgrp = &rdtgroup_default; +enum resctrl_kernel_mode mode; +enum kmode_state ctrl, mon; +char *params; +int ret =0 ; + +if (!info_kn_lock (of->kn)) +return -ENOENT ; + +rdt_last_cmd_clear (); + +if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) {
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1437
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+rdt_last_cmd_puts ("kernel_mode: Invalid input\n" ); + ret = -EINVAL ; + goto out_unlock; + } + buf[nbytes -1 ] ='\0' ; + buf =strim (buf); + + params =strchr (buf,':' ); +if (params) + *params++ ='\0' ;
Why not use strsep() to be consistent with other parsing in resctrl?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1440
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+ +for (mode =0 ; mode <RESCTRL_NUM_KERNEL_MODES ; mode++) { +if (!strcmp (buf, resctrl_kmode_str[mode]))
The whitespace trimming is inconsistent. Whitespace is trimmed from buffer, but before looking for the ":". Looks like something like "global_enable_per_cpu :ctrl=assign" fails with "Unknown kernel mode", while spaces around ; and = are accepted.
Quoted 6 lines
fs/resctrl/rdtgroup.c +6
-0+break ; + } +if (mode ==RESCTRL_NUM_KERNEL_MODES ) { +rdt_last_cmd_puts ("Unknown kernel mode\n" ); + ret = -EINVAL ; + goto out_unlock;
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1456
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+ } +if (!test_bit (mode, resctrl_kmode.kmode_sup)) { +rdt_last_cmd_puts ("Kernel mode not available\n" ); + ret = -EINVAL ; + goto out_unlock; + } + +if (mode ==RESCTRL_INHERIT_USER ) { +if (params) { +rdt_last_cmd_puts ("inherit_user has no parameters\n" );
nit: Just in case resctrl needs to add parameters later, could this be "Unsupported parameter" instead?
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1465
Quoted 9 lines
fs/resctrl/rdtgroup.c +9
-0+ ret = -EINVAL ; + goto out_unlock; + } +if (resctrl_kmode.kmode_cur != mode) +resctrl_kmode_switch (mode,NULL ,KMODE_ASSIGN ,KMODE_ASSIGN ); + goto out_unlock; + } + +/* Omitted parameters keep the values shown by reading the file. */
This comment does not seem to match the show() that always prints resctrl_kmode.ctrl. Should rdtgroup_kmode_global_deactivate() reset relevant resctrl_kmode fields?
Quoted 29 lines
fs/resctrl/rdtgroup.c +24
-0+ ctrl =resctrl_arch_alloc_capable () ? resctrl_kmode.ctrl :KMODE_INHERIT ; + mon =resctrl_arch_mon_capable () ? resctrl_kmode.mon :KMODE_INHERIT ; +if (resctrl_kmode.rdtgrp) + rdtgrp = resctrl_kmode.rdtgrp; + +if (params) { + ret =resctrl_kmode_parse_parameters (params, &ctrl, &mon, &rdtgrp); +if (ret) + goto out_unlock; + } + + ret =resctrl_kmode_global_validate (rdtgrp, ctrl, mon); +if (ret) + goto out_unlock; + +if (resctrl_kmode.kmode_cur != mode || resctrl_kmode.rdtgrp != rdtgrp || + resctrl_kmode.ctrl != ctrl || resctrl_kmode.mon != mon) +resctrl_kmode_switch (mode, rdtgrp, ctrl, mon); + +out_unlock: +info_kn_unlock (of->kn); +return ret ?: nbytes; +} +void *rdt_kn_parent_priv (struct kernfs_node *kn) {/* @@ -2230,9 +2501,10 @@ static struct rftype res_common_files[] = { },
fs/resctrl/rdtgroup.c static struct rftype res_common_files[] = { · line 2510
Quoted 10 lines
fs/resctrl/rdtgroup.c +2
-1{ .name = "kernel_mode", - .mode = 0444, + .mode = 0644, .kf_ops = &rdtgroup_kf_single_ops, .seq_show = resctrl_kernel_mode_show, + .write = resctrl_kernel_mode_write, .fflags = RFTYPE_TOP_INFO, }, {
Reinette
Babu Moger
reviewerRe: [PATCH v6 16/18] fs/resctrl: Add interface to modify kernel mode via info/kernel_mode
Hi Reinette,
Quoted 3 lines · Reinette Chatre
Hi Babu,
nit: subject states this adds new interfaces but that is not true?
fs/resctrl: Extend info/kernel_mode to modify kernel mode
Quoted 15 lines · Babu Moger
Quoted 13 lines
--- Documentation/filesystems/resctrl.rst | 28 +++ fs/resctrl/rdtgroup.c | 274 +++++++++++++++++++++++++- 2 files changed, 301 insertions(+), 1 deletion(-)Documentation/filesystems/resctrl.rst +0
-0@@ -575,6 +575,34 @@ conveyed in the error returns from file operations. E.g. [inherit_user] global_enable_per_cpu:ctrl=assign;mon=assign;group=//
Quoted 13 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 584
Quoted 7 lines
Documentation/filesystems/resctrl.rst +7
-0+ Writes use the same line format as read, without square brackets and + with a trailing newline. + + inherit_user is written without any parameters. + + For global_enable_per_cpu, the parameters are optional. An omitted + ctrl=, mon=, or group= keeps the value currently shown. Parameters"keeps the value currently shown" -> "keeps the default values" Text as suggested, or similar, will connect this text with the earlier "When the mode is not active, the parameters are the defaults ..." Although, please check earlier comment about the "parameters are the defaults" text.
Sure.
Quoted 6 lines
Documentation/filesystems/resctrl.rst conveyed in the error returns from file operations. E.g. · line 585
Quoted 2 lines
Documentation/filesystems/resctrl.rst +1
-0+ may appear in any order. Empty values are rejected.More on this later but I do not think it is possible for parameters to appear in any order ...
Ack.
Quoted 31 lines
Quoted 31 lines
Documentation/filesystems/resctrl.rst +20
-0+ + Selecting a new mode, parameter, or group replaces the active + association. A new global_enable_per_cpu association sets that + group's kmode_cpus to every online CPU. Errors are reported in + "info/last_cmd_status". + Example:: + + # mkdir ctrl1 + # echo "global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//" \ + > info/kernel_mode + + # cat info/kernel_mode + inherit_user + [global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//] + + # echo "inherit_user" > info/kernel_mode + # cat info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + Resource alloc and monitor groups =================================fs/resctrl/rdtgroup.c +0
-0@@ -1216,6 +1216,277 @@ static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) resctrl_kmode.mon =KMODE_ASSIGN ; }
Quoted 14 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1228
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+/* Program @rdtgrp on every online CPU and show its kmode_cpus files. */ +static void rdtgroup_kmode_global_activate (struct rdtgroup *rdtgrp) +{ +cpumask_copy (&rdtgrp->kmode_cpu_mask, cpu_online_mask); +resctrl_configure_kmode_global (&rdtgrp->kmode_cpu_mask, rdtgrp, true); +resctrl_kmode_global_files_show (rdtgrp->kn, true); +} + +/** +* rdtgroup_by_kmode_path() - Resolve a "<ctrl>/<mon>/" path to an rdtgroup It is a contradiction to have description read "Resolve a "<ctrl>/<mon>/" path" and then the control and monitor group names are provided as separate parameters
ack.
Quoted 2 lines
The function name also includes "path" but there is nothing about a path in the implementation, the caller parses the path, no?
I can handle all this in resctrl_kmode_parse_group(). Dont need a separate rdtgroup_by_kmode_path().
Quoted 16 lines
Quoted 16 lines
fs/resctrl/rdtgroup.c +15
-0+* @ctrl_name: CTRL_MON group name, or "" for the default control group. +* @mon_name: MON group name, or "" to select the control group itself. +* +* Matches the path syntax displayed by resctrl_kernel_mode_show(): +* "//" - the default CTRL_MON group +* "<ctrl>//" - CTRL_MON group @ctrl_name +* "/<mon>/" - MON group @mon_name under the default control group +* "<ctrl>/<mon>/" - MON group @mon_name under control group @ctrl_name +* +* Return: Pointer to the matching rdtgroup, or NULL if no such group exists. +*/ +static struct rdtgroup *rdtgroup_by_kmode_path (const char *ctrl_name, +const char *mon_name) +{ +struct rdtgroup *rdtg, *parent = &rdtgroup_default;
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1249
Quoted 6 lines
fs/resctrl/rdtgroup.c +6
-0+ +if (*ctrl_name) { + parent =NULL ; +list_for_each_entry (rdtg, &rdt_all_groups, rdtgroup_list) { +if (rdtg->type !=RDTCTRL_GROUP ) +continue ;All entries of
rdt_all_groupsare of typeRDTCTRL_GROUP, no?
Yes. That is correct. Will remove this check.
Quoted 50 lines
Quoted 35 lines
fs/resctrl/rdtgroup.c +34
-0+if (!strcmp (rdt_kn_name (rdtg->kn), ctrl_name)) { + parent = rdtg; +break ; + } + } + } +if (!parent) +return NULL ; + +if (!*mon_name) +return parent; + +list_for_each_entry (rdtg, &parent->mon.crdtgrp_list, mon.crdtgrp_list) +if (!strcmp (rdt_kn_name (rdtg->kn), mon_name)) +return rdtg; +return NULL ; +} + +static int resctrl_kmode_parse_state (char *val,enum kmode_state *state) +{ +if (!strcmp (val,"assign" )) { + *state =KMODE_ASSIGN ; +return 0 ; + } +if (!strcmp (val,"inherit" )) { + *state =KMODE_INHERIT ; +return 0 ; + } +return -EINVAL ; +} + +static int resctrl_kmode_parse_group (char *group,struct rdtgroup **rdtgrp) +{ +struct rdtgroup *grp;fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1293
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+char *mon, *slash; + + slash =strchr (group,'/' ); +if (!slash) { +rdt_last_cmd_puts ("Group must be <CTRL_MON>/<MON>/\n" ); +return -EINVAL ; + } + *slash ='\0' ; + mon =strim (slash +1 ); +The reason why we picked the <CTRL_MON>/<MON>/ syntax is because "/" is the one character that is not allowed by kernfs to be in a directory name, additionally resctrl rejects \n in group names.
Quoted 6 lines
This parsing should thus take care with stripping spaces and just parsing in general to support all the different resource group names that users may be able to create (it may even contain ";"). Because of this it seems that it should be required for the resource group to be the last parameter provided by user space since it will be terminated by \n that cannot be in a resource group name?
I hope I got it. We should generalize the parsing to here to handle special characters. Yes. It makes it easy as the group is the last parameter.
Quoted 11 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1300
Quoted 8 lines
fs/resctrl/rdtgroup.c +7
-0+ slash =strchr (mon,'/' ); +if (!slash || slash[1 ] !='\0' ) { +rdt_last_cmd_puts ("Group must be <CTRL_MON>/<MON>/\n" ); +return -EINVAL ; + } + *slash ='\0' ; +The user should not be required to provide a monitor group when "mon=inherit" or if system does not support monitoring.
Yes. that is correct. This code need to change.
Quoted 15 lines
Quoted 15 lines
fs/resctrl/rdtgroup.c +14
-0+ grp =rdtgroup_by_kmode_path (group, mon); +if (!grp) { +rdt_last_cmd_puts ("Group not found\n" ); +return -EINVAL ; + } + *rdtgrp = grp; +return 0 ; +} + +static int resctrl_kmode_parse_parameters (char *params,enum kmode_state *ctrl, +enum kmode_state *mon, +struct rdtgroup **rdtgrp) +{ +char *key, *tok;
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1318
Quoted 4 lines
fs/resctrl/rdtgroup.c +4
-0+ +while ((tok =strsep (¶ms,";" ))) { + tok =strim (tok); +if (!*tok)Please use the same string parsing patterns as the rest of resctrl. Specifically, please use the familiar (to resctrl) comparison against '\0' as in "if (tok[0] == '\0')" instead of pointer dereference like above (and below).
Sure.
Quoted 10 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1323
Quoted 6 lines
fs/resctrl/rdtgroup.c +5
-0+continue ; + + key =strsep (&tok,"=" ); +if (!tok) { +rdt_last_cmd_puts ("Empty kernel mode parameters\n" );Not sure how accurate messages should be but this is just duplicate error message of when there are no kernel mode parameters when the issue is actually that "=" is missing.
It can be "Unsupported kernel mode parameters"
Quoted 13 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1333
Quoted 11 lines
fs/resctrl/rdtgroup.c +10
-0+return -EINVAL ; + } + key =strim (key); + tok =strim (tok); +if (!*key || !*tok) { +rdt_last_cmd_puts ("Empty kernel mode parameters\n" ); +return -EINVAL ; + } + +if (!strcmp (key,"ctrl" )) {Should this not fail on a system that is not capable of allocation?
Sure. Let me verify this.
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1338
Quoted 6 lines
fs/resctrl/rdtgroup.c +5
-0+if (resctrl_kmode_parse_state (tok, ctrl)) { +rdt_last_cmd_puts ("Invalid ctrl= parameter\n" ); +return -EINVAL ; + } + }else if (!strcmp (key,"mon" )) {Similarly this should fail on system that does not support monitoring?
Yes. Will check this.
Quoted 12 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1347
Quoted 10 lines
fs/resctrl/rdtgroup.c +9
-0+if (resctrl_kmode_parse_state (tok, mon)) { +rdt_last_cmd_puts ("Invalid mon= parameter\n" ); +return -EINVAL ; + } + }else if (!strcmp (key,"group" )) { +if (resctrl_kmode_parse_group (tok, rdtgrp)) +return -EINVAL ; + }else { +rdt_last_cmd_puts ("Unknown kernel mode parameter\n" );nit: "Unknown" -> "Unsupported"
Sure.
Quoted 15 lines
Quoted 15 lines
fs/resctrl/rdtgroup.c +14
-0+return -EINVAL ; + } + } +return 0 ; +} + +static int resctrl_kmode_global_validate (struct rdtgroup *rdtgrp, +enum kmode_state ctrl, +enum kmode_state mon) +{ +if (ctrl ==KMODE_ASSIGN && !resctrl_arch_alloc_capable ()) { +rdt_last_cmd_puts ("ctrl=assign is not supported\n" ); +return -EINVAL ; + }
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1365
Quoted 4 lines
fs/resctrl/rdtgroup.c +4
-0+if (mon ==KMODE_ASSIGN && !resctrl_arch_mon_capable ()) { +rdt_last_cmd_puts ("mon=assign is not supported\n" ); +return -EINVAL ; + }Does this mean that user can provide "ctrl=inherit" on system that does not support allocation and "mon=inherit" on system that does not support monitoring? That does not look right.
Good point. Will fix that.
Quoted 11 lines
Quoted 11 lines
fs/resctrl/rdtgroup.c +9
-0+if (mon ==KMODE_INHERIT && rdtgrp->type ==RDTMON_GROUP ) { +rdt_last_cmd_puts ("A monitor group requires mon=assign to use its RMID\n" ); +return -EINVAL ; + } +if (rdtgrp->mode !=RDT_MODE_SHAREABLE ) { +rdt_last_cmd_puts ("The group is not in shareable mode\n" ); +return -EINVAL ; + } + if (rdtgrp->type == RDTMON_GROUP &&
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1378
Quoted 4 lines
fs/resctrl/rdtgroup.c +4
-0+ rdtgrp->mon.parent->mode != RDT_MODE_SHAREABLE) { +rdt_last_cmd_puts ("The parent group is not in shareable mode\n" ); +return -EINVAL ; + }I think it will be useful to organize the "
kernel_mode"resctrl.rstportion for writing to "kernel_mode" similar to the portion for reading to clearly associate the above rules with the "global_enable_per_cpu" mode.
Ok. Sure. Will add few lines about this in resctrl.rst.
Quoted 14 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1387
Quoted 10 lines
fs/resctrl/rdtgroup.c +9
-0+ +return 0 ; +} + +static void resctrl_kmode_switch (enum resctrl_kernel_mode mode, +struct rdtgroup *rdtgrp, +enum kmode_state ctrl,enum kmode_state mon) +{ +if (resctrl_kmode.rdtgrp)Please do not use resctrl_kmode.rdtgrp as synonym for and interchangeably with resctrl_kmode.kmode_cur ==
RESCTRL_GLOBAL_ENABLE_PER_CPU. Please check other places too, like inresctrl_kernel_mode_write()
Sure. Will do.
Quoted 11 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1390
Quoted 4 lines
fs/resctrl/rdtgroup.c +3
-0+rdtgroup_kmode_global_deactivate (resctrl_kmode.rdtgrp); + + resctrl_kmode.kmode_cur = mode;Now looking at how things come together, what do you think of renaming "
kmode_cur" to "active"? "kmode" in "kmode_cur" is redundant and "active" looks to be a good match with existing documentation ("... with the active mode enclosed in square brackets") and code likerdtgroup_kmode_global_activate()and "active" used as local variable inresctrl_kernel_mode_show().
Sounds good.
Quoted 3 lines
Similar to this, could resctrl_kmode.kmode_sup be renamed to resctrl_kmode.supported?
Yes. Will change it.
Quoted 5 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1391
Quoted 2 lines
fs/resctrl/rdtgroup.c +1
-0+if (mode !=RESCTRL_GLOBAL_ENABLE_PER_CPU ) {If this is needed please make the test explicit to the "inherit" mode.
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1394
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+ resctrl_kmode.rdtgrp =NULL ; + resctrl_kmode.ctrl =KMODE_ASSIGN ; + resctrl_kmode.mon =KMODE_ASSIGN ;Something does not look right here ... function parameters provide values that are not used. If any reset is needed, should it not be done as part of
rdtgroup_kmode_global_deactivate()especially since it appears that the contract with architecture is for disable of global kernel mode to mean that inherit mode has to be enabled?
Yes. Will remove resctrl_kmode_switch(). Will handle this in rdtgroup_kmode_global_deactivate().
Quoted 17 lines
Quoted 4 lines
fs/resctrl/rdtgroup.c +3
-0+return ; + } +fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1407
Quoted 10 lines
fs/resctrl/rdtgroup.c +10
-0+ resctrl_kmode.ctrl = ctrl; + resctrl_kmode.mon = mon; + resctrl_kmode.rdtgrp = rdtgrp; +rdtgroup_kmode_global_activate (rdtgrp); +} + +/** +* resctrl_kernel_mode_write() - Set the active kernel mode +* @of: kernfs open file +* @buf: write buffer Could this be more specific about what the buffer represents? For example,
Kernel mode line written by user space
Sure.
Quoted 25 lines
Quoted 25 lines
fs/resctrl/rdtgroup.c +24
-0+* @nbytes: length of @buf +* @off: unused +* +* Return: @nbytes on success, negative errno on error. +*/ +static ssize_t resctrl_kernel_mode_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdtgroup *rdtgrp = &rdtgroup_default; +enum resctrl_kernel_mode mode; +enum kmode_state ctrl, mon; +char *params; +int ret =0 ; + +if (!info_kn_lock (of->kn)) +return -ENOENT ; + +rdt_last_cmd_clear (); + +if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) { +rdt_last_cmd_puts ("kernel_mode: Invalid input\n" ); + ret = -EINVAL ; + goto out_unlock; + }
Quoted 9 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1437
Quoted 6 lines
fs/resctrl/rdtgroup.c +6
-0+ buf[nbytes -1 ] ='\0' ; + buf =strim (buf); + + params =strchr (buf,':' ); +if (params) + *params++ ='\0' ;Why not use
strsep()to be consistent with other parsing in resctrl?
Sure. Will change it.
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1440
Quoted 3 lines
fs/resctrl/rdtgroup.c +3
-0+ +for (mode =0 ; mode <RESCTRL_NUM_KERNEL_MODES ; mode++) { +if (!strcmp (buf, resctrl_kmode_str[mode]))The whitespace trimming is inconsistent. Whitespace is trimmed from buffer, but before looking for the ":". Looks like something like "
global_enable_per_cpu:ctrl=assign" fails with "Unknown kernel mode", while spaces around ; and = are accepted.
Sure. Fix it.
Quoted 12 lines
Quoted 12 lines
fs/resctrl/rdtgroup.c +11
-0+break ; + } +if (mode ==RESCTRL_NUM_KERNEL_MODES ) { +rdt_last_cmd_puts ("Unknown kernel mode\n" ); + ret = -EINVAL ; + goto out_unlock; + } +if (!test_bit (mode, resctrl_kmode.kmode_sup)) { +rdt_last_cmd_puts ("Kernel mode not available\n" ); + ret = -EINVAL ; + goto out_unlock;
Quoted 8 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1456
Quoted 5 lines
fs/resctrl/rdtgroup.c +5
-0+ } + +if (mode ==RESCTRL_INHERIT_USER ) { +if (params) { +rdt_last_cmd_puts ("inherit_user has no parameters\n" );nit: Just in case resctrl needs to add parameters later, could this be "Unsupported parameter" instead?
Sure.
Quoted 13 lines
fs/resctrl/rdtgroup.c static void rdtgroup_kmode_global_detach(struct rdtgroup *rdtgrp) · line 1465
Quoted 10 lines
fs/resctrl/rdtgroup.c +9
-0+ ret = -EINVAL ; + goto out_unlock; + } +if (resctrl_kmode.kmode_cur != mode) +resctrl_kmode_switch (mode,NULL ,KMODE_ASSIGN ,KMODE_ASSIGN ); + goto out_unlock; + } + +/* Omitted parameters keep the values shown by reading the file. */ This comment does not seem to match the
show()that always prints resctrl_kmode.ctrl. Shouldrdtgroup_kmode_global_deactivate()reset relevantresctrl_kmodefields?
Yes. rdtgroup_kmode_global_deactivate() will reset the fields now.
The resctrl_kmode_switch() and resctrl_kmode_detach() will be removed.
Thanks
Babu
Babu Moger
reviewerPATCH v6 17/18 fs/resctrl: Allow user space to write kmode_cpus/kmode_cpus_list
In reply to Babu MogerThe RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode supports configuring kernel-mode resource allocation and monitoring associations on a per-CPU basis. The CPU scope of the association is exposed through kmode_cpus and kmode_cpus_list.
Add write support for kmode_cpus and kmode_cpus_list to allow user space to configure the CPUs associated with the active kernel-mode group.
Document the interface in Documentation/filesystems/resctrl.rst.
---
v6: Use flattened resctrl_kmode and global_enable_per_cpu.
Fix the sashiko reported issue.
https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com?part=15
Update the changelog.
v5: Adapt to the resctrl_kcfg caps and active split. Use
resctrl_kcfg.active.ctrl_mode and mon_mode in kmode_cpus_write(). Use full ctrl=/mon= syntax in the kmode_cpus example.
v4: Empty masks are now allowed and updated masks are in rdtgroup->kmode_cpu_mask.
Updated the changelog.
v3: New patch to add "kmode_cpus" and "kmode_cpus_list" to support
kernel_modes.
--- Documentation/filesystems/resctrl.rst | 30 +++++++ fs/resctrl/rdtgroup.c | 114 +++++++++++++++++++++++++- 2 files changed, 142 insertions(+), 2 deletions(-)
Documentation/filesystems/resctrl.rst +30 -0
@@ -671,6 +671,36 @@ All groups contain the following files: "cpus_list": Just like "cpus", only using ranges of CPUs instead of bitmasks. +"kmode_cpus": + Accessible only within the resource group currently associated with + the active kernel mode (see "info/kernel_mode"). + + Bitmask of the logical CPUs associated with the group's kernel mode. + When kernel mode is activated through info/kernel_mode, every currently + online CPU is included. CPUs that come online later are automatically + added to the association. + + Writing a mask replaces the association's CPU mask. The association is + enabled on CPUs added to the mask and disabled on CPUs removed from + it. An empty mask disables the association on all currently online + CPUs, but CPUs that come online later are still automatically + associated. The mask must contain only online CPUs; masks naming offline + CPUs are rejected. Errors are reported in "info/last_cmd_status". + Example:: + + # mkdir ctrl1 + # echo "global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1//" \ + > info/kernel_mode + # echo 0-3 > ctrl1/kmode_cpus_list + # cat ctrl1/kmode_cpus + f + # cat ctrl1/kmode_cpus_list + 0-3 + +"kmode_cpus_list": + Just like "kmode_cpus", only using ranges of CPUs instead of bitmasks. + Writable with the same semantics and restrictions as "kmode_cpus". + When control is enabled all CTRL_MON groups will also contain:
fs/resctrl/rdtgroup.c +112 -2
135 lines not on this page · raw message
Signature · 1 line
2.43.0
Babu Moger
reviewerPATCH v6 18/18 fs/resctrl: Add kernel mode documentation and examples
In reply to Babu MogerKernel-mode configuration is exposed through info/kernel_mode, kmode_cpus, and kmode_cpus_list.
Provide examples showing how to query supported modes, configure kernel mode associations, and manage per-CPU kernel-mode associations.
---
v6: Renamed assign_global_enable_per_cpu to global_enable_per_cpu in the
examples. Replaced "policy" with "mode" throughout.
v5: Update the example for the collapsed kernel mode model:
inherit_user and assign_global_enable_per_cpu with ctrl=/mon= association options, and <CTRL_MON group>/<MON group>/ paths.
v4: New patch. Added examples in the documentation.
--- Documentation/filesystems/resctrl.rst | 102 ++++++++++++++++++++++++++ 1 file changed, 102 insertions(+)
Documentation/filesystems/resctrl.rst +102 -0
@@ -1888,6 +1888,108 @@ View the llc occupancy snapshot:: 11234000 +Examples on working with kernel_mode +==================================== +The kernel-mode interface spans three files: + +- ``info/kernel_mode`` - select the global mode and associated group +- ``kmode_cpus`` / ``kmode_cpus_list`` - view or adjust the CPU scope of the + active association (visible only on the associated group) + +The walkthrough below covers a typical workflow on a platform with PLZA +(Privilege Level Zero Association) support: + +1. Discover supported modes. +2. Associate ``global_enable_per_cpu`` with a control group. +3. Narrow the CPU scope through ``kmode_cpus_list``. +4. Move the association to a monitor group. +5. Return to ``inherit_user``. + +a. Discover supported kernel modes +:: + + # mount -t resctrl resctrl /sys/fs/resctrl/ + + # cat /sys/fs/resctrl/info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + +``inherit_user`` is the active mode. Kernel work inherits the resource +allocation and monitoring of the current user-space task. The second line +shows ``global_enable_per_cpu`` is available; square brackets mark +the active entry when read back after later steps. + +b. Associate kernel mode allocation with a control group +:: + + # mkdir /sys/fs/resctrl/ctrl1 + # echo "global_enable_per_cpu:ctrl=assign;mon=inherit;group=ctrl1//" > \ + /sys/fs/resctrl/info/kernel_mode + + # cat /sys/fs/resctrl/info/kernel_mode + inherit_user + [global_enable_per_cpu:ctrl=assign;mon=inherit;group=ctrl1//] + +``ctrl=assign`` uses ctrl1's allocation association. ``mon=inherit`` uses +the monitoring association of the user-space task. The group path uses +``<CTRL_MON group>/<MON group>/`` syntax; a control group alone is written +as ``ctrl1//``. + +When the mode is active: + +- ``ctrl1/kmode_cpus`` and ``ctrl1/kmode_cpus_list`` become visible. +- All currently online CPUs are associated initially. +- CPUs that come online later are added to the association automatically. + +c. Narrow the association to CPUs 0-3 +:: + + # echo 0-3 > /sys/fs/resctrl/ctrl1/kmode_cpus_list + # cat /sys/fs/resctrl/ctrl1/kmode_cpus + f + # cat /sys/fs/resctrl/ctrl1/kmode_cpus_list + 0-3 + +The write replaces the association's CPU mask: + +- The association is enabled on CPUs added to the mask. +- The association is disabled on CPUs removed from the mask. +- Offline CPUs in the mask are rejected. +- An empty mask disables the association on all currently online CPUs, but + later hotplug CPUs are still associated automatically. + +d. Move the association to a monitor group +:: + + # mkdir /sys/fs/resctrl/ctrl1/mon_groups/mon1 + # echo "global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1/mon1/" > \ + /sys/fs/resctrl/info/kernel_mode + + # cat /sys/fs/resctrl/info/kernel_mode + inherit_user + [global_enable_per_cpu:ctrl=assign;mon=assign;group=ctrl1/mon1/] + +Kernel mode work uses ctrl1's allocation association (``ctrl=assign``) and +mon1's monitoring association (``mon=assign``). A monitor group requires +``mon=assign``; ``mon=inherit`` does not use that group's RMID and is +rejected. Changing the associated group through ``info/kernel_mode``: + +- Resets the CPU scope to all currently online CPUs. +- Hides ``kmode_cpus`` and ``kmode_cpus_list`` on the previous group. +- Shows them under ``ctrl1/mon_groups/mon1/``. + +e. Return to inherit_user +:: + + # echo "inherit_user" > /sys/fs/resctrl/info/kernel_mode + # cat /sys/fs/resctrl/info/kernel_mode + [inherit_user] + global_enable_per_cpu:ctrl=assign;mon=assign;group=// + +Writing ``inherit_user`` clears the active kernel-mode association and +hides ``kmode_cpus`` and ``kmode_cpus_list`` because no group is +associated with kernel mode. + Examples on working with mbm_assign_mode ========================================
Signature · 1 line
2.43.0
Quoted 8 lines · Babu Moger
Hi All,
This series adds support for AMD's Privilege-Level Zero Association (PLZA) so kernel work can use a separate resource allocation and/or monitoring association from the user task, and wires it up through a small generic "kernel mode" (kmode) layer in fs/resctrl so future architectures can plug in without touching (hopefully) core resctrl.
Hi Babu,
Yunhui Cui (cc'd) recently proposed a RISC-V extension [1] with similar functionality. It adds a new CSR with a RCID (like CLOSID) and MCID (like RMID) to use when the cpu switches to the privilege level that the kernel runs in (supervisor-mode in RISC-V terminology). The srmcfg_assoc register is defined as:
Bits Field
-------- --------
11:0 RCID
12 RCID_EN
15:13 Reserved
27:16 MCID
28 MCID_EN
30:29 Reserved
31 ASSOC_ENIt is similar enough to PLZA that I believe that this series could work for RISC-V. Hopefully Yunhui Cui can comment further.
Thanks,
Drew
Babu Moger
reviewerHi Drew, Yunhui,
Quoted 28 lines · Drew Fustini
Quoted 8 lines · Babu Moger
Hi All,
This series adds support for AMD's Privilege-Level Zero Association (PLZA) so kernel work can use a separate resource allocation and/or monitoring association from the user task, and wires it up through a small generic "kernel mode" (kmode) layer in fs/resctrl so future architectures can plug in without touching (hopefully) core resctrl.
Hi Babu,
Yunhui Cui (cc'd) recently proposed a RISC-V extension [1] with similar functionality. It adds a new CSR with a RCID (like CLOSID) and MCID (like RMID) to use when the cpu switches to the privilege level that the kernel runs in (supervisor-mode in RISC-V terminology). The
srmcfg_assocregister is defined as:Bits Field -------- -------- 11:0 RCID 12 RCID_EN 15:13 Reserved 27:16 MCID 28 MCID_EN 30:29 Reserved 31 ASSOC_EN
Quoted 3 lines
It is similar enough to PLZA that I believe that this series could work for RISC-V. Hopefully Yunhui Cui can comment further.
That's great to hear. Please feel free to share any feedback or suggestions that would make this easier for RISC-V.
Thanks,
Babu