[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241114135037.918470-7-zengheng4@huawei.com>
Date: Thu, 14 Nov 2024 21:50:37 +0800
From: Zeng Heng <zengheng4@...wei.com>
To: <james.morse@....com>, <Dave.Martin@....com>
CC: <bobo.shaobowang@...wei.com>, <linux-kernel@...r.kernel.org>,
<jonathan.cameron@...wei.com>, <linux-arm-kernel@...ts.infradead.org>
Subject: [RFC PATCH mpam mpam/snapshot/v6.11-rc1 6/6] fs/resctrl: Add the helper to check if the task exists in the target group
After introducing the extension for monitoring feature, to check if a
closid exists within the target control group, it is not only check if the
closid of the control group is the same, but also to recursively check if
there is a closid of sub-monitor groups is the same. Therefore, a new
helper task_belongs_to_ctrl_group() is added.
On the x86 side, the closid of the child monitor group is the same as its
parent control group's (only the rmid is different), hence
resctrl_arch_match_rmid() can directly use the closid of the child monitor
group. Meanwhile, task_belongs_to_ctrl_group() can replace
resctrl_arch_match_closid() to be compatible with the x86 arch.
Signed-off-by: Zeng Heng <zengheng4@...wei.com>
---
fs/resctrl/rdtgroup.c | 52 +++++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 19 deletions(-)
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 2e8ec20f0415..03c5c9eb9298 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -589,19 +589,38 @@ static void update_task_closid_rmid(struct task_struct *t)
static bool task_in_rdtgroup(struct task_struct *tsk, struct rdtgroup *rdtgrp)
{
- u32 closid, rmid = rdtgrp->mon.rmid;
+ u32 closid, rmid;
- if (rdtgrp->type == RDTCTRL_GROUP)
- closid = rdtgrp->closid;
- else if (rdtgrp->type == RDTMON_GROUP)
- closid = rdtgrp->mon.parent->closid;
- else
- return false;
+ closid = rdtgrp->closid;
+ rmid = rdtgrp->mon.rmid;
return resctrl_arch_match_closid(tsk, closid) &&
resctrl_arch_match_rmid(tsk, closid, rmid);
}
+/**
+ * task_belongs_to_ctrl_group - the helper to check if the task exists in
+ * the target control group.
+ * @tsk: task to be checked
+ * @rdtgrp: target control group
+ */
+static bool task_belongs_to_ctrl_group(struct task_struct *tsk, struct rdtgroup *rdtgrp)
+{
+ struct rdtgroup *crdtgrp;
+
+ /* Check whether exists in contrl group self */
+ if (resctrl_arch_match_closid(tsk, rdtgrp->closid))
+ return true;
+
+ /* Check if exists in one of children monitor groups */
+ list_for_each_entry(crdtgrp, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) {
+ if (resctrl_arch_match_closid(tsk, crdtgrp->closid))
+ return true;
+ }
+
+ return false;
+}
+
static int __rdtgroup_move_task(struct task_struct *tsk,
struct rdtgroup *rdtgrp)
{
@@ -618,17 +637,13 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
* their parent CTRL group.
*/
if (rdtgrp->type == RDTMON_GROUP &&
- !resctrl_arch_match_closid(tsk, rdtgrp->mon.parent->closid)) {
+ !task_belongs_to_ctrl_group(tsk, rdtgrp->mon.parent)) {
rdt_last_cmd_puts("Can't move task to different control group\n");
return -EINVAL;
}
- if (rdtgrp->type == RDTMON_GROUP)
- resctrl_arch_set_closid_rmid(tsk, rdtgrp->mon.parent->closid,
- rdtgrp->mon.rmid);
- else
- resctrl_arch_set_closid_rmid(tsk, rdtgrp->closid,
- rdtgrp->mon.rmid);
+ resctrl_arch_set_closid_rmid(tsk, rdtgrp->closid,
+ rdtgrp->mon.rmid);
/*
* Ensure the task's closid and rmid are written before determining if
@@ -652,14 +667,13 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
static bool is_closid_match(struct task_struct *t, struct rdtgroup *r)
{
return (resctrl_arch_alloc_capable() && (r->type == RDTCTRL_GROUP) &&
- resctrl_arch_match_closid(t, r->closid));
+ task_belongs_to_ctrl_group(t, r));
}
static bool is_rmid_match(struct task_struct *t, struct rdtgroup *r)
{
return (resctrl_arch_mon_capable() && (r->type == RDTMON_GROUP) &&
- resctrl_arch_match_rmid(t, r->mon.parent->closid,
- r->mon.rmid));
+ resctrl_arch_match_rmid(t, r->closid, r->mon.rmid));
}
/**
@@ -909,7 +923,7 @@ int proc_resctrl_show(struct seq_file *s, struct pid_namespace *ns,
rdtg->mode != RDT_MODE_EXCLUSIVE)
continue;
- if (!resctrl_arch_match_closid(tsk, rdtg->closid))
+ if (!task_belongs_to_ctrl_group(tsk, rdtg))
continue;
seq_printf(s, "res:%s%s\n", (rdtg == &rdtgroup_default) ? "/" : "",
@@ -917,7 +931,7 @@ int proc_resctrl_show(struct seq_file *s, struct pid_namespace *ns,
seq_puts(s, "mon:");
list_for_each_entry(crg, &rdtg->mon.crdtgrp_list,
mon.crdtgrp_list) {
- if (!resctrl_arch_match_rmid(tsk, crg->mon.parent->closid,
+ if (!resctrl_arch_match_rmid(tsk, crg->closid,
crg->mon.rmid))
continue;
seq_printf(s, "%s", crg->kn->name);
--
2.25.1
Powered by blists - more mailing lists