Skip to content

Commit 28fa2cc

Browse files
babumogerbp3tk0v
authored andcommitted
fs/resctrl: Introduce interface to modify io_alloc capacity bitmasks
The io_alloc feature in resctrl enables system software to configure the portion of the cache allocated for I/O traffic. When supported, the io_alloc_cbm file in resctrl provides access to capacity bitmasks (CBMs) allocated for I/O devices. Enable users to modify io_alloc CBMs by writing to the io_alloc_cbm resctrl file when the io_alloc feature is enabled. Mirror the CBMs between CDP_CODE and CDP_DATA when CDP is enabled to present consistent I/O allocation information to user space. Signed-off-by: Babu Moger <babu.moger@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://patch.msgid.link/67609641b03ccfba18a8ee0bf9dbd1f3dcbecda3.1762995456.git.babu.moger@amd.com
1 parent af1242e commit 28fa2cc

4 files changed

Lines changed: 109 additions & 1 deletion

File tree

Documentation/filesystems/resctrl.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ related to allocation:
196196
# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
197197
0=ffff;1=ffff
198198

199+
CBMs can be configured by writing to the interface.
200+
201+
Example::
202+
203+
# echo 1=ff > /sys/fs/resctrl/info/L3/io_alloc_cbm
204+
# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
205+
0=ffff;1=00ff
206+
207+
# echo "0=ff;1=f" > /sys/fs/resctrl/info/L3/io_alloc_cbm
208+
# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
209+
0=00ff;1=000f
210+
199211
When CDP is enabled "io_alloc_cbm" associated with the CDP_DATA and CDP_CODE
200212
resources may reflect the same values. For example, values read from and
201213
written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected by

fs/resctrl/ctrlmondata.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,96 @@ int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq,
864864
cpus_read_unlock();
865865
return ret;
866866
}
867+
868+
static int resctrl_io_alloc_parse_line(char *line, struct rdt_resource *r,
869+
struct resctrl_schema *s, u32 closid)
870+
{
871+
enum resctrl_conf_type peer_type;
872+
struct rdt_parse_data data;
873+
struct rdt_ctrl_domain *d;
874+
char *dom = NULL, *id;
875+
unsigned long dom_id;
876+
877+
next:
878+
if (!line || line[0] == '\0')
879+
return 0;
880+
881+
dom = strsep(&line, ";");
882+
id = strsep(&dom, "=");
883+
if (!dom || kstrtoul(id, 10, &dom_id)) {
884+
rdt_last_cmd_puts("Missing '=' or non-numeric domain\n");
885+
return -EINVAL;
886+
}
887+
888+
dom = strim(dom);
889+
list_for_each_entry(d, &r->ctrl_domains, hdr.list) {
890+
if (d->hdr.id == dom_id) {
891+
data.buf = dom;
892+
data.mode = RDT_MODE_SHAREABLE;
893+
data.closid = closid;
894+
if (parse_cbm(&data, s, d))
895+
return -EINVAL;
896+
/*
897+
* Keep io_alloc CLOSID's CBM of CDP_CODE and CDP_DATA
898+
* in sync.
899+
*/
900+
if (resctrl_arch_get_cdp_enabled(r->rid)) {
901+
peer_type = resctrl_peer_type(s->conf_type);
902+
memcpy(&d->staged_config[peer_type],
903+
&d->staged_config[s->conf_type],
904+
sizeof(d->staged_config[0]));
905+
}
906+
goto next;
907+
}
908+
}
909+
910+
return -EINVAL;
911+
}
912+
913+
ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
914+
size_t nbytes, loff_t off)
915+
{
916+
struct resctrl_schema *s = rdt_kn_parent_priv(of->kn);
917+
struct rdt_resource *r = s->res;
918+
u32 io_alloc_closid;
919+
int ret = 0;
920+
921+
/* Valid input requires a trailing newline */
922+
if (nbytes == 0 || buf[nbytes - 1] != '\n')
923+
return -EINVAL;
924+
925+
buf[nbytes - 1] = '\0';
926+
927+
cpus_read_lock();
928+
mutex_lock(&rdtgroup_mutex);
929+
rdt_last_cmd_clear();
930+
931+
if (!r->cache.io_alloc_capable) {
932+
rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
933+
ret = -ENODEV;
934+
goto out_unlock;
935+
}
936+
937+
if (!resctrl_arch_get_io_alloc_enabled(r)) {
938+
rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
939+
ret = -EINVAL;
940+
goto out_unlock;
941+
}
942+
943+
io_alloc_closid = resctrl_io_alloc_closid(r);
944+
945+
rdt_staged_configs_clear();
946+
ret = resctrl_io_alloc_parse_line(buf, r, s, io_alloc_closid);
947+
if (ret)
948+
goto out_clear_configs;
949+
950+
ret = resctrl_arch_update_domains(r, io_alloc_closid);
951+
952+
out_clear_configs:
953+
rdt_staged_configs_clear();
954+
out_unlock:
955+
mutex_unlock(&rdtgroup_mutex);
956+
cpus_read_unlock();
957+
958+
return ret ?: nbytes;
959+
}

fs/resctrl/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
440440
const char *rdtgroup_name_by_closid(u32 closid);
441441
int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq,
442442
void *v);
443+
ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
444+
size_t nbytes, loff_t off);
443445

444446
#ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
445447
int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);

fs/resctrl/rdtgroup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,9 +1973,10 @@ static struct rftype res_common_files[] = {
19731973
},
19741974
{
19751975
.name = "io_alloc_cbm",
1976-
.mode = 0444,
1976+
.mode = 0644,
19771977
.kf_ops = &rdtgroup_kf_single_ops,
19781978
.seq_show = resctrl_io_alloc_cbm_show,
1979+
.write = resctrl_io_alloc_cbm_write,
19791980
},
19801981
{
19811982
.name = "max_threshold_occupancy",

0 commit comments

Comments
 (0)