[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6a2cdedc0b2bf7e3da82d453b0104b46a2e85529.1747349530.git.babu.moger@amd.com>
Date: Thu, 15 May 2025 17:52:09 -0500
From: Babu Moger <babu.moger@....com>
To: <corbet@....net>, <tony.luck@...el.com>, <reinette.chatre@...el.com>,
<tglx@...utronix.de>, <mingo@...hat.com>, <bp@...en8.de>,
<dave.hansen@...ux.intel.com>
CC: <james.morse@....com>, <dave.martin@....com>, <fenghuay@...dia.com>,
<x86@...nel.org>, <hpa@...or.com>, <paulmck@...nel.org>,
<akpm@...ux-foundation.org>, <thuth@...hat.com>, <rostedt@...dmis.org>,
<ardb@...nel.org>, <gregkh@...uxfoundation.org>,
<daniel.sneddon@...ux.intel.com>, <jpoimboe@...nel.org>,
<alexandre.chartre@...cle.com>, <pawan.kumar.gupta@...ux.intel.com>,
<thomas.lendacky@....com>, <perry.yuan@....com>, <seanjc@...gle.com>,
<kai.huang@...el.com>, <xiaoyao.li@...el.com>, <babu.moger@....com>,
<kan.liang@...ux.intel.com>, <xin3.li@...el.com>, <ebiggers@...gle.com>,
<xin@...or.com>, <sohil.mehta@...el.com>, <andrew.cooper3@...rix.com>,
<mario.limonciello@....com>, <linux-doc@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <peternewman@...gle.com>,
<maciej.wieczor-retman@...el.com>, <eranian@...gle.com>,
<Xiaojian.Du@....com>, <gautham.shenoy@....com>
Subject: [PATCH v13 24/27] x86/resctrl: Introduce the interface to modify assignments in a group
Introduce an interface to modify assignments within a group.
Modifications follow this format:
<Event configuration>:<Domain id>=<Assignment type>
The assignment type can be one of the following:
_ : No event configuration assigned
e : Event configuration assigned in exclusive mode
Domain id can be any valid domain ID number or '*' to update all the
domains.
Example:
$cd /sys/fs/resctrl
$cat mbm_L3_assignments
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e
To unassign the configuration of mbm_total_bytes on domain 0:
$echo "mbm_total_bytes:0=_" > mbm_L3_assignments
$cat mbm_L3_assignments
mbm_total_bytes:0=_;1=e
mbm_local_bytes:0=e;1=e
To unassign the mbm_total_bytes configuration on all domains:
$echo "mbm_total_bytes:*=_" > mbm_L3_assignments
$cat mbm_L3_assignments
mbm_total_bytes:0=_;1=_
mbm_local_bytes:0=e;1=e
Signed-off-by: Babu Moger <babu.moger@....com>
---
v13: Few changes in mbm_L3_assignments_write() after moving the event config to evt_list.
Resolved conflicts caused by the recent FS/ARCH code restructure.
v12: New patch:
Assignment interface moved inside the group based the discussion
https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=kVLBzhfNo0SFqt4kQGwGSGVUqvr2Dg@mail.gmail.com/#t
---
Documentation/filesystems/resctrl.rst | 29 ++++-
fs/resctrl/internal.h | 9 ++
fs/resctrl/rdtgroup.c | 165 +++++++++++++++++++++++++-
3 files changed, 201 insertions(+), 2 deletions(-)
diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
index 2350c1f21f4e..d779554a2f91 100644
--- a/Documentation/filesystems/resctrl.rst
+++ b/Documentation/filesystems/resctrl.rst
@@ -515,7 +515,7 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
Event configuration: A valid event configuration listed in the
/sys/fs/resctrl/info/L3_MON/counter_configs directory.
- Domain ID: A valid domain ID number.
+ Domain ID: A valid domain ID number or '*' to update all the domains.
Assignment types:
@@ -532,6 +532,33 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
mbm_total_bytes:0=e;1=e
mbm_local_bytes:0=e;1=e
+ Modify the assignment states by writing to the interface file.
+
+ Example:
+ To unassign the configuration of mbm_total_bytes on domain 0:
+ ::
+
+ # echo "mbm_total_bytes:0=_" > mbm_L3_assignments
+ # cat mbm_L3_assignments
+ mbm_total_bytes:0=_;1=e
+ mbm_local_bytes:0=e;1=e
+
+ To unassign the mbm_total_bytes configuration on all domains:
+ ::
+
+ # echo "mbm_total_bytes:*=_" > mbm_L3_assignments
+ # cat mbm_L3_assignments
+ mbm_total_bytes:0=_;1=_
+ mbm_local_bytes:0=e;1=e
+
+ To assign the mbm_total_bytes configuration on all domains in exclusive mode:
+ ::
+
+ # echo "mbm_total_bytes:*=e" > mbm_L3_assignments
+ # cat mbm_L3_assignments
+ mbm_total_bytes:0=e;1=e
+ mbm_local_bytes:0=e;1=e
+
Resource allocation rules
-------------------------
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index 446cc9cc61df..a6069a5dfd49 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -51,6 +51,15 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
return container_of(kfc, struct rdt_fs_context, kfc);
}
+/*
+ * Assignment types for mbm_cntr_assign mode
+ */
+enum {
+ ASSIGN_NONE = 0,
+ ASSIGN_EXCLUSIVE,
+ ASSIGN_INVALID,
+};
+
/**
* struct mon_evt - Entry in the event list of a resource
* @evtid: event id
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 8d970b99bbbd..ea1782723f81 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2126,6 +2126,168 @@ static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file
return ret;
}
+/*
+ * mbm_get_mon_event_by_name() - Return the mon_evt entry for the matching
+ * event name.
+ */
+static struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r,
+ char *name)
+{
+ struct mon_evt *mevt;
+
+ list_for_each_entry(mevt, &r->mon.evt_list, list) {
+ if (!strcmp(mevt->name, name))
+ return mevt;
+ }
+
+ return NULL;
+}
+
+static unsigned int resctrl_get_assing_type(char *assign)
+{
+ unsigned int mon_state = ASSIGN_NONE;
+ int len = strlen(assign);
+
+ if (!len || len > 1)
+ return ASSIGN_INVALID;
+
+ switch (*assign) {
+ case 'e':
+ mon_state = ASSIGN_EXCLUSIVE;
+ break;
+ case '_':
+ mon_state = ASSIGN_NONE;
+ break;
+ default:
+ mon_state = ASSIGN_INVALID;
+ break;
+ }
+
+ return mon_state;
+}
+
+static int resctrl_process_assign(struct rdt_resource *r, struct rdtgroup *rdtgrp,
+ char *config, char *tok)
+{
+ struct rdt_mon_domain *d;
+ char *dom_str, *id_str;
+ unsigned long dom_id = 0;
+ struct mon_evt *mevt;
+ int assign_type;
+ char domain[10];
+ bool found;
+ int ret;
+
+ mevt = mbm_get_mon_event_by_name(r, config);
+ if (!mevt) {
+ rdt_last_cmd_printf("Invalid assign configuration %s\n", config);
+ return -ENOENT;
+ }
+
+next:
+ if (!tok || tok[0] == '\0')
+ return 0;
+
+ /* Start processing the strings for each domain */
+ dom_str = strim(strsep(&tok, ";"));
+
+ id_str = strsep(&dom_str, "=");
+
+ /* Check for domain id '*' which means all domains */
+ if (id_str && *id_str == '*') {
+ d = NULL;
+ goto check_state;
+ } else if (!id_str || kstrtoul(id_str, 10, &dom_id)) {
+ rdt_last_cmd_puts("Missing domain id\n");
+ return -EINVAL;
+ }
+
+ /* Verify if the dom_id is valid */
+ found = false;
+ list_for_each_entry(d, &r->mon_domains, hdr.list) {
+ if (d->hdr.id == dom_id) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ rdt_last_cmd_printf("Invalid domain id %ld\n", dom_id);
+ return -EINVAL;
+ }
+
+check_state:
+ assign_type = resctrl_get_assing_type(dom_str);
+
+ switch (assign_type) {
+ case ASSIGN_NONE:
+ ret = resctrl_unassign_cntr_event(r, d, rdtgrp, mevt->evtid);
+ break;
+ case ASSIGN_EXCLUSIVE:
+ ret = resctrl_assign_cntr_event(r, d, rdtgrp, mevt->evtid);
+ break;
+ case ASSIGN_INVALID:
+ ret = -EINVAL;
+ }
+
+ if (ret)
+ goto out_fail;
+
+ goto next;
+
+out_fail:
+ sprintf(domain, d ? "%ld" : "*", dom_id);
+
+ rdt_last_cmd_printf("Assign operation '%s:%s=%s' failed\n", config, domain, dom_str);
+
+ return ret;
+}
+
+static ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,
+ size_t nbytes, loff_t off)
+{
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+ struct rdtgroup *rdtgrp;
+ char *token, *config;
+ int ret = 0;
+
+ /* Valid input requires a trailing newline */
+ if (nbytes == 0 || buf[nbytes - 1] != '\n')
+ return -EINVAL;
+
+ buf[nbytes - 1] = '\0';
+
+ rdtgrp = rdtgroup_kn_lock_live(of->kn);
+ if (!rdtgrp) {
+ rdtgroup_kn_unlock(of->kn);
+ return -ENOENT;
+ }
+ rdt_last_cmd_clear();
+
+ if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+ rdt_last_cmd_puts("mbm_cntr_assign mode is not enabled\n");
+ rdtgroup_kn_unlock(of->kn);
+ return -EINVAL;
+ }
+
+ while ((token = strsep(&buf, "\n")) != NULL) {
+ /*
+ * The write command follows the following format:
+ * “<Assign config>:<domain_id>=<assign mode>”
+ * Extract Assign config first.
+ */
+ config = strsep(&token, ":");
+
+ ret = resctrl_process_assign(r, rdtgrp, config, token);
+ if (ret)
+ break;
+ }
+
+ rdtgroup_kn_unlock(of->kn);
+
+ return ret ?: nbytes;
+}
+
/* rdtgroup information files for one cache resource. */
static struct rftype res_common_files[] = {
{
@@ -2266,9 +2428,10 @@ static struct rftype res_common_files[] = {
},
{
.name = "mbm_L3_assignments",
- .mode = 0444,
+ .mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.seq_show = mbm_L3_assignments_show,
+ .write = mbm_L3_assignments_write,
},
{
.name = "mbm_assign_mode",
--
2.34.1
Powered by blists - more mailing lists