x86/resctrl: Add "*" shorthand to set io_alloc CBM for all domains
Subsystems (2)
v4 cover x86/resctrl: Add "*" shorthand to set io_alloc CBM for all domains
Hi Babu, Tony, Reinette,
This patch introduces a wildcard domain ID selector "*" for the io_alloc_cbm interface. It allows a user to update the Capacity Bitmask (CBM) across all cache domains in a single operation.
Currently, configuring io_alloc_cbm requires an explicit ID for each domain, which is cumbersome on systems with high core counts and numerous cache clusters. Supporting a wildcard selector simplifies automation and management tasks.
For example, a user can now write "*=0" to the io_alloc_cbm file to program every domain to the hardware-defined minimum CBM. Note that the value provided must still adhere to the constraints defined in the resource's min_cbm_bits.
Please let me know your thoughts.
Changes since v3 [1]:
- Updated the wildcard documentation text to be clearer and less prescriptive (Reinette Chatre)
- Reverted the while loop refactoring in resctrl_io_alloc_parse_line() to restore the standard parsing pattern and prevent invalid domain ID regressions (Reinette Chatre)
- Added explicit validation to ensure the wildcard selector is followed by a value assignment (Reinette Chatre)
- Restored memcpy() usage for configuration copying to minimise unrelated diff noise
Changes since v2 [2]:
- Dropped return -EINVAL for a missing seq_show implementation (Reinette Chatre)
- Dropped helpers to check io_alloc support and enabled state (Reinette Chatre)
- Removed additional complexity (Babu Moger)
- Introduced the "*" wildcard for io_alloc_cbm to allow updating all cache domains (Reinette Chatre)
- Replaced goto-based line parsing with a while loop to support multi-domain and wildcard iterations
- Replaced memcpy() with direct structure assignment
Changes since v1 [3]:
- Updated each helper for consistency (Babu Moger)
- Refactored the loop logic in function resctrl_io_alloc_parse_line() to improve readability
- Added inline keyword to each helper
- Added inline keyword to function parse_domain_cbm()
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
Aaron Tomlin (1):
x86/resctrl: Add "*" shorthand to set io_alloc CBM for all domains
Documentation/filesystems/resctrl.rst | 8 ++++++++ fs/resctrl/ctrlmondata.c | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-)
Signature · 1 line
2.51.0
PATCH v4 1/1 x86/resctrl: Add "*" shorthand to set io_alloc CBM for all domains
Introduce a wildcard domain ID selector "*" for the io_alloc_cbm interface. This allows a user to update the Capacity Bitmask (CBM) across all cache domains in a single operation.
Currently, configuring io_alloc_cbm requires an explicit ID for each domain, which is cumbersome on systems with high core counts and numerous cache clusters. Supporting a wildcard selector simplifies automation and management tasks.
For example, a user can now write "*=0" to the io_alloc_cbm file to program every domain to the hardware-defined minimum CBM. Note that the value provided must still adhere to the constraints defined in the resource's min_cbm_bits.
--- Documentation/filesystems/resctrl.rst | 8 ++++++++ fs/resctrl/ctrlmondata.c | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-)
Documentation/filesystems/resctrl.rst +8 -0
@@ -215,6 +215,14 @@ related to allocation: # cat /sys/fs/resctrl/info/L3/io_alloc_cbm 0=00ff;1=000f + Set each CBM to a specified value. + + An ID of "*" configures all domains with the provided CBM. + + Example:: + + # echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm + When CDP is enabled "io_alloc_cbm" associated with the CDP_DATA and CDP_CODE resources may reflect the same values. For example, values read from and written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected by
fs/resctrl/ctrlmondata.c +17 -3
@@ -873,21 +873,31 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r,struct rdt_ctrl_domain *d;char *dom =NULL , *id;unsigned long dom_id; +bool update_all; next:if (!line || line[0 ] =='\0' )return 0 ; + update_all = false; dom =strsep (&line,";" ); id =strsep (&dom,"=" ); -if (!dom ||kstrtoul (id,10 , &dom_id)) { + +if (id && !strcmp (id,"*" )) { + update_all = true; + }else if (!dom ||kstrtoul (id,10 , &dom_id)) {rdt_last_cmd_puts ("Missing '=' or non-numeric domain\n" );return -EINVAL ; } dom =strim (dom); +if (update_all && !dom) { +rdt_last_cmd_puts ("Missing '=' after '*'\n" ); +return -EINVAL ; + } +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { -if (d->hdr.id == dom_id) { +if (update_all || d->hdr.id == dom_id) { data.buf = dom; data.mode =RDT_MODE_SHAREABLE ; data.closid = closid;
@@ -903,10 +913,14 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, &d->staged_config[s->conf_type], sizeof(d->staged_config[0])); } - goto next; +if (!update_all) + goto next; } } +if (update_all) + goto next; +return -EINVAL ; }
Signature · 1 line
2.51.0
Hi Aaron,
Quoted 26 lines · Aaron Tomlin
Introduce a wildcard domain ID selector "*" for the
io_alloc_cbminterface. This allows a user to update the Capacity Bitmask (CBM) across all cache domains in a single operation.Currently, configuring
io_alloc_cbmrequires an explicit ID for each domain, which is cumbersome on systems with high core counts and numerous cache clusters. Supporting a wildcard selector simplifies automation and management tasks.For example, a user can now write "*=0" to the
io_alloc_cbmfile to program every domain to the hardware-defined minimum CBM. Note that the value provided must still adhere to the constraints defined in the resource'smin_cbm_bits.Signed-off-by Aaron Tomlin <[email protected]>--- Documentation/filesystems/resctrl.rst | 8 ++++++++ fs/resctrl/ctrlmondata.c | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-)Documentation/filesystems/resctrl.rst +0
-0@@ -215,6 +215,14 @@ related to allocation: # cat /sys/fs/resctrl/info/L3/io_alloc_cbm
Documentation/filesystems/resctrl.rst related to allocation: · line 225
Quoted 10 lines
Documentation/filesystems/resctrl.rst +8
-00=00ff;1=000f + Set each CBM to a specified value. + + An ID of "*" configures all domains with the provided CBM. + + Example:: + + # echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm +
You missed adding
# cat /sys/fs/resctrl/info/L3/io_alloc_cbm 0=0;1=0
Thanks
Babu
Quoted 57 lines
Documentation/filesystems/resctrl.rst +0
-0When CDP is enabled "io_alloc_cbm" associated with the CDP_DATA and CDP_CODE resources may reflect the same values. For example, values read from and written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected byfs/resctrl/ctrlmondata.c +17
-3@@ -873,21 +873,31 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r,struct rdt_ctrl_domain *d;char *dom =NULL , *id;unsigned long dom_id; +bool update_all; next:if (!line || line[0 ] =='\0' )return 0 ; + update_all = false; dom =strsep (&line,";" ); id =strsep (&dom,"=" ); -if (!dom ||kstrtoul (id,10 , &dom_id)) { + +if (id && !strcmp (id,"*" )) { + update_all = true; + }else if (!dom ||kstrtoul (id,10 , &dom_id)) {rdt_last_cmd_puts ("Missing '=' or non-numeric domain\n" );return -EINVAL ; } dom =strim (dom); +if (update_all && !dom) { +rdt_last_cmd_puts ("Missing '=' after '*'\n" ); +return -EINVAL ; + } +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { -if (d->hdr.id == dom_id) { +if (update_all || d->hdr.id == dom_id) { data.buf = dom; data.mode =RDT_MODE_SHAREABLE ; data.closid = closid;@@ -903,10 +913,14 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, &d->staged_config[s->conf_type], sizeof(d->staged_config[0])); } - goto next; +if (!update_all) + goto next; } } +if (update_all) + goto next; +return -EINVAL ; }
Reinette Chatre
maintainerHi Aaron,
No need to add a cover letter when there is just one patch. From what I can tell the cover letter contains duplicate text so can just be dropped in the next version. Although, there may possibly be two patches in next version (more later).
For the subject, please follow the custom to have the "PATCH" text be the prefix. Specifically "[PATCH vX]". For reference, see "Subject Line" in Documentation/process/submitting-patches.rst.
Quoted 3 lines · Aaron Tomlin
Introduce a wildcard domain ID selector "*" for the
io_alloc_cbminterface. This allows a user to update the Capacity Bitmask (CBM) across all cache domains in a single operation.
The changelog jumps in with what the patch does before providing any context (which can be found in paragraph below). Please follow the "context, problem, solution" structure as detailed in section "Changelog" found in Documentation/process/maintainer-tip.rst
Quoted 8 lines
Currently, configuring
io_alloc_cbmrequires an explicit ID for each domain, which is cumbersome on systems with high core counts and numerous cache clusters. Supporting a wildcard selector simplifies automation and management tasks.For example, a user can now write "*=0" to the
io_alloc_cbmfile to program every domain to the hardware-defined minimum CBM. Note that the
(nit: not all hardware has 0 as minimum CBM).
Quoted 39 lines
value provided must still adhere to the constraints defined in the resource's
min_cbm_bits.Signed-off-by Aaron Tomlin <[email protected]>--- Documentation/filesystems/resctrl.rst | 8 ++++++++ fs/resctrl/ctrlmondata.c | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-)Documentation/filesystems/resctrl.rst +8
-0@@ -215,6 +215,14 @@ related to allocation: # cat /sys/fs/resctrl/info/L3/io_alloc_cbm 0=00ff;1=000f + Set each CBM to a specified value. + + An ID of "*" configures all domains with the provided CBM. + + Example:: + + # echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm + When CDP is enabled "io_alloc_cbm" associated with the CDP_DATA and CDP_CODE resources may reflect the same values. For example, values read from and written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected byfs/resctrl/ctrlmondata.c +1
-0@@ -873,21 +873,31 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r,struct rdt_ctrl_domain *d;char *dom =NULL , *id;unsigned long dom_id; +bool update_all; next:
fs/resctrl/ctrlmondata.c static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, · line 887
Quoted 10 lines
fs/resctrl/ctrlmondata.c +4
-1if (!line || line[0 ] =='\0' )return 0 ; + update_all = false; dom =strsep (&line,";" ); id =strsep (&dom,"=" ); -if (!dom ||kstrtoul (id,10 , &dom_id)) { + +if (id && !strcmp (id,"*" )) { + update_all = true;
Since this cannot be reached if line is NULL, can id ever be NULL here?
fs/resctrl/ctrlmondata.c static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, · line 894
Quoted 7 lines
fs/resctrl/ctrlmondata.c +2
-0+ }else if (!dom ||kstrtoul (id,10 , &dom_id)) {rdt_last_cmd_puts ("Missing '=' or non-numeric domain\n" );return -EINVAL ; } dom =strim (dom); +if (update_all && !dom) {
Have you tried just writing '*' to this file as suggested in v3? Please do include doing so in your tests.
The NULL check should be _before_ any access to dom. I think this can be done earlier though. How about something like below?
if (dom && !strcmp(id, "*")) {
...
} else if (!dom || kstrtoul(id, 10, &dom_id)) {
...
}Quoted 12 lines
fs/resctrl/ctrlmondata.c +5
-1+rdt_last_cmd_puts ("Missing '=' after '*'\n" ); +return -EINVAL ; + } +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { -if (d->hdr.id == dom_id) { +if (update_all || d->hdr.id == dom_id) { data.buf = dom; data.mode =RDT_MODE_SHAREABLE ; data.closid = closid;@@ -903,10 +913,14 @@ static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, &d->staged_config[s->conf_type],
fs/resctrl/ctrlmondata.c static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, · line 922
Quoted 10 lines
fs/resctrl/ctrlmondata.c +4
-1sizeof(d->staged_config[0])); } - goto next; +if (!update_all) + goto next; } } +if (update_all) + goto next;
I see that this aims to support input like "*=f;*=0" but I do not see how something like this can ever succeed since parse_cbm() stages the config and should fail if any domain already has a config. Should this perhaps just return success here? This could be made more robust by only returning success if there is no more text to parse, thus failing on input like "*=f;1=f".
fs/resctrl/ctrlmondata.c static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, · line 924
Quoted 2 lines
fs/resctrl/ctrlmondata.c +1
-0+return -EINVAL ;
I just noticed that this is one spot where the user interface may be confusing. The intent here is to return an error if the user provided an invalid domain ID. While this interface returns an error the last_cmd_status file is not updated. What a user would see is thus that writing to io_alloc_cmd fails but last_cmd_status returns "ok". This is a problem with existing implementation.
Would you like to include a fix for this as part of this work? I think just something like
rdt_last_cmd_printf("Invalid domain %d\n", dom_id);before the "return -EINVAL" should be sufficient. This needs to be a separate patch though with a:
Reinette
Reinette Chatre
maintainerHi Aaron,
Quoted 10 lines · Reinette Chatre
Hi Aaron,
No need to add a cover letter when there is just one patch. From what I can tell the cover letter contains duplicate text so can just be dropped in the next version. Although, there may possibly be two patches in next version (more later).
For the subject, please follow the custom to have the "PATCH" text be the prefix. Specifically "[PATCH vX]". For reference, see "Subject Line" in
Documentation/process/submitting-patches.rst.
One addendum here, please update the subject prefix to "fs/resctrl:" to match the area of code modified.
Reinette
Quoted 3 lines · Reinette Chatre
For the subject, please follow the custom to have the "PATCH" text be the prefix. Specifically "[PATCH vX]". For reference, see "Subject Line" in
Documentation/process/submitting-patches.rst.
Hi Reinette,
Thank you for the detailed review.
I will incorporate all the stylistic feedback (Subject prefix, Changelog structure, and dropping the cover letter) in v5.
Quoted 9 lines
Quoted 7 lines
Currently, configuring
io_alloc_cbmrequires an explicit ID for each domain, which is cumbersome on systems with high core counts and numerous cache clusters. Supporting a wildcard selector simplifies automation and management tasks.For example, a user can now write "*=0" to the
io_alloc_cbmfile to program every domain to the hardware-defined minimum CBM. Note that the(nit: not all hardware has 0 as minimum CBM).
I understand. I shall update the text to ensure the distinction regarding the hardware-defined minimum is precise.
Quoted 20 lines
Since this cannot be reached if line is NULL, can id ever be NULL here?
fs/resctrl/ctrlmondata.c static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, · line 894
Quoted 7 lines
fs/resctrl/ctrlmondata.c +2
-0+ }else if (!dom ||kstrtoul (id,10 , &dom_id)) {rdt_last_cmd_puts ("Missing '=' or non-numeric domain\n" );return -EINVAL ; } dom =strim (dom); +if (update_all && !dom) {Have you tried just writing '*' to this file as suggested in v3? Please do include doing so in your tests.
The NULL check should be _before_ any access to dom. I think this can be done earlier though. How about something like below?
Quoted 4 lines
fs/resctrl/ctrlmondata.c +1
-0+ goto next; } }
Quoted 12 lines
fs/resctrl/ctrlmondata.c static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r, · line 922
Quoted 2 lines
fs/resctrl/ctrlmondata.c +2
-0+if (update_all) + goto next;I see that this aims to support input like "*=f;*=0" but I do not see how something like this can ever succeed since
parse_cbm()stages the config and should fail if any domain already has a config. Should this perhaps just return success here? This could be made more robust by only returning success if there is no more text to parse, thus failing on input like "*=f;1=f".Quoted 2 lines
(quoted diff) +1
-0+ return -EINVAL;
Agreed. I will refactor the parsing logic to prioritise the check for dom before performing the string comparison, as you suggested. This yields a significantly cleaner flow and mitigates potential dereference issues.
I will ensure that edge cases, including the standalone * (which should correctly trigger the "Missing '='" error), are explicitly covered in my testing before submission.
Quoted 11 lines
I just noticed that this is one spot where the user interface may be confusing. The intent here is to return an error if the user provided an invalid domain ID. While this interface returns an error the
last_cmd_statusfile is not updated. What a user would see is thus that writing toio_alloc_cmdfails butlast_cmd_statusreturns "ok". This is a problem with existing implementation. Would you like to include a fix for this as part of this work? I think just something likerdt_last_cmd_printf("Invalid domain %d\n", dom_id); before the "return-EINVAL" should be sufficient. This needs to be a separate patch though with a: Fixes:28fa2cce7a83("fs/resctrl: Introduce interface to modifyio_alloccapacity bitmasks")
This is a valid concern. To address this properly, I intend to split the next submission into a two-patch series:
1. A fix for the existing last_cmd_status behaviour (reporting "ok" despite failure) when an invalid domain is provided.
2. The introduction of the wildcard "*" support.
This approach ensures the fix is cleanly separated from the new feature logic.
Kind regards,
Signature · 1 line
Aaron Tomlin