From: Peter Newman <peternewman@google.com>
To: reinette.chatre@intel.com, fenghua.yu@intel.com
Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com,
eranian@google.com, gupasani@google.com, hpa@zytor.com,
james.morse@arm.com, linux-kernel@vger.kernel.org,
mingo@redhat.com, skodak@google.com, tony.luck@intel.com,
tglx@linutronix.de, x86@kernel.org,
Peter Newman <peternewman@google.com>
Subject: [PATCH v3 3/3] x86/resctrl: Implement rename op for mon groups
Date: Wed, 25 Jan 2023 11:13:34 +0100 [thread overview]
Message-ID: <20230125101334.1069060-4-peternewman@google.com> (raw)
In-Reply-To: <20230125101334.1069060-1-peternewman@google.com>
To change the class of service for a large group of tasks, such as an
application container, a container manager must write all of the tasks'
IDs into the tasks file interface of the new control group.
If a container manager is tracking containers' bandwidth usage by
placing tasks from each into their own monitoring group, it must first
move the tasks to the default monitoring group of the new control group
before it can move the tasks into their new monitoring groups. This is
undesirable because it makes bandwidth usage during the move
unattributable to the correct tasks and resets monitoring event counters
and cache usage information for the group.
To address this, implement the rename operation for resctrlfs mon groups
to effect a change in CLOSID for a MON group while otherwise leaving the
monitoring group intact.
Signed-off-by: Peter Newman <peternewman@google.com>
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 75 ++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index b2081bc1bbfd..595f83a517c6 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -3238,6 +3238,80 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
return ret;
}
+static void mongrp_move(struct rdtgroup *rdtgrp, struct rdtgroup *new_prdtgrp,
+ cpumask_var_t cpus)
+{
+ struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+ struct task_struct *p, *t;
+
+ WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
+ list_del(&rdtgrp->mon.crdtgrp_list);
+
+ list_add_tail(&rdtgrp->mon.crdtgrp_list,
+ &new_prdtgrp->mon.crdtgrp_list);
+ rdtgrp->mon.parent = new_prdtgrp;
+
+ read_lock(&tasklist_lock);
+ for_each_process_thread(p, t) {
+ if (is_closid_match(t, prdtgrp) && is_rmid_match(t, rdtgrp))
+ rdt_move_one_task(t, new_prdtgrp->closid, t->rmid,
+ cpus);
+ }
+ read_unlock(&tasklist_lock);
+
+ update_closid_rmid(cpus, NULL);
+}
+
+static int rdtgroup_rename(struct kernfs_node *kn,
+ struct kernfs_node *new_parent, const char *new_name)
+{
+ struct rdtgroup *new_prdtgrp;
+ struct rdtgroup *rdtgrp;
+ cpumask_var_t tmpmask;
+ int ret;
+
+ if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
+ return -ENOMEM;
+
+ rdtgrp = kernfs_to_rdtgroup(kn);
+ new_prdtgrp = kernfs_to_rdtgroup(new_parent);
+ if (!rdtgrp || !new_prdtgrp) {
+ free_cpumask_var(tmpmask);
+ return -EPERM;
+ }
+
+ /* Release both kernfs active_refs before obtaining rdtgroup mutex. */
+ rdtgroup_kn_get(rdtgrp, kn);
+ rdtgroup_kn_get(new_prdtgrp, new_parent);
+
+ mutex_lock(&rdtgroup_mutex);
+
+ if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) {
+ ret = -ESRCH;
+ goto out;
+ }
+
+ /* Only a mon group can be moved to a new mon_groups directory. */
+ if (rdtgrp->type != RDTMON_GROUP ||
+ !is_mon_groups(new_parent, kn->name)) {
+ ret = -EPERM;
+ goto out;
+ }
+
+ ret = kernfs_rename(kn, new_parent, new_name);
+ if (ret)
+ goto out;
+
+ mongrp_move(rdtgrp, new_prdtgrp, tmpmask);
+
+out:
+ mutex_unlock(&rdtgroup_mutex);
+ rdtgroup_kn_put(rdtgrp, kn);
+ rdtgroup_kn_put(new_prdtgrp, new_parent);
+ free_cpumask_var(tmpmask);
+ return ret;
+}
+
static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
{
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
@@ -3255,6 +3329,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = {
.mkdir = rdtgroup_mkdir,
.rmdir = rdtgroup_rmdir,
+ .rename = rdtgroup_rename,
.show_options = rdtgroup_show_options,
};
--
2.39.1.405.gd4c25cc71f-goog
next prev parent reply other threads:[~2023-01-25 10:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-25 10:13 [PATCH v3 0/3] x86/resctrl: Implement rename to help move containers' tasks Peter Newman
2023-01-25 10:13 ` [PATCH v3 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops Peter Newman
2023-02-10 23:21 ` Reinette Chatre
2023-01-25 10:13 ` [PATCH v3 2/3] x86/resctrl: Factor work to update task CLOSID/RMID Peter Newman
2023-01-25 10:13 ` Peter Newman [this message]
2023-02-10 23:21 ` [PATCH v3 3/3] x86/resctrl: Implement rename op for mon groups Reinette Chatre
2023-03-02 14:26 ` Peter Newman
2023-03-02 22:26 ` Reinette Chatre
2023-03-03 15:10 ` Peter Newman
2023-03-03 19:05 ` Reinette Chatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230125101334.1069060-4-peternewman@google.com \
--to=peternewman@google.com \
--cc=Babu.Moger@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=eranian@google.com \
--cc=fenghua.yu@intel.com \
--cc=gupasani@google.com \
--cc=hpa@zytor.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=reinette.chatre@intel.com \
--cc=skodak@google.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome