Skip to content

Commit 8e93110

Browse files
aeglbp3tk0v
authored andcommitted
x86/resctrl: Add write option to "mba_MBps_event" file
The "mba_MBps" mount option provides an alternate method to control memory bandwidth. Instead of specifying allowable bandwidth as a percentage of maximum possible, the user provides a MiB/s limit value. There is a file in each CTRL_MON group directory that shows the event currently in use. Allow writing that file to choose a different event. A user can choose any of the memory bandwidth monitoring events listed in /sys/fs/resctrl/info/L3_mon/mon_features independently for each CTRL_MON group by writing to each of the "mba_MBps_event" files. Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Tested-by: Babu Moger <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f5cd0e3 commit 8e93110

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

arch/x86/kernel/cpu/resctrl/ctrlmondata.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,46 @@ static int smp_mon_event_count(void *arg)
518518
return 0;
519519
}
520520

521+
ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
522+
char *buf, size_t nbytes, loff_t off)
523+
{
524+
struct rdtgroup *rdtgrp;
525+
int ret = 0;
526+
527+
/* Valid input requires a trailing newline */
528+
if (nbytes == 0 || buf[nbytes - 1] != '\n')
529+
return -EINVAL;
530+
buf[nbytes - 1] = '\0';
531+
532+
rdtgrp = rdtgroup_kn_lock_live(of->kn);
533+
if (!rdtgrp) {
534+
rdtgroup_kn_unlock(of->kn);
535+
return -ENOENT;
536+
}
537+
rdt_last_cmd_clear();
538+
539+
if (!strcmp(buf, "mbm_local_bytes")) {
540+
if (is_mbm_local_enabled())
541+
rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
542+
else
543+
ret = -EINVAL;
544+
} else if (!strcmp(buf, "mbm_total_bytes")) {
545+
if (is_mbm_total_enabled())
546+
rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
547+
else
548+
ret = -EINVAL;
549+
} else {
550+
ret = -EINVAL;
551+
}
552+
553+
if (ret)
554+
rdt_last_cmd_printf("Unsupported event id '%s'\n", buf);
555+
556+
rdtgroup_kn_unlock(of->kn);
557+
558+
return ret ?: nbytes;
559+
}
560+
521561
int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
522562
struct seq_file *s, void *v)
523563
{

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
610610
char *buf, size_t nbytes, loff_t off);
611611
int rdtgroup_schemata_show(struct kernfs_open_file *of,
612612
struct seq_file *s, void *v);
613+
ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
614+
char *buf, size_t nbytes, loff_t off);
613615
int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
614616
struct seq_file *s, void *v);
615617
bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domain *d,

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,8 +1952,9 @@ static struct rftype res_common_files[] = {
19521952
},
19531953
{
19541954
.name = "mba_MBps_event",
1955-
.mode = 0444,
1955+
.mode = 0644,
19561956
.kf_ops = &rdtgroup_kf_single_ops,
1957+
.write = rdtgroup_mba_mbps_event_write,
19571958
.seq_show = rdtgroup_mba_mbps_event_show,
19581959
},
19591960
{

0 commit comments

Comments
 (0)