Skip to content

Commit f3cbeac

Browse files
Vikas ShivappaKAGA-KOKO
authored andcommitted
x86/intel_rdt/cqm: Add rmdir support
Resource groups (ctrl_mon and monitor groups) are represented by directories in resctrl fs. Add support to remove the directories. When a ctrl_mon directory is removed all the cpus and tasks are assigned back to the root rdtgroup. When a monitor group is removed the cpus and tasks are returned to the parent control group. Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: ravi.v.shankar@intel.com Cc: tony.luck@intel.com Cc: fenghua.yu@intel.com Cc: peterz@infradead.org Cc: eranian@google.com Cc: vikas.shivappa@intel.com Cc: ak@linux.intel.com Cc: davidcc@google.com Cc: reinette.chatre@intel.com Link: http://lkml.kernel.org/r/1501017287-28083-22-git-send-email-vikas.shivappa@linux.intel.com
1 parent f904954 commit f3cbeac

1 file changed

Lines changed: 86 additions & 4 deletions

File tree

‎arch/x86/kernel/cpu/intel_rdt_rdtgroup.c‎

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,18 @@ static int reset_all_ctrls(struct rdt_resource *r)
11301130
return 0;
11311131
}
11321132

1133+
static bool is_closid_match(struct task_struct *t, struct rdtgroup *r)
1134+
{
1135+
return (rdt_alloc_capable &&
1136+
(r->type == RDTCTRL_GROUP) && (t->closid == r->closid));
1137+
}
1138+
1139+
static bool is_rmid_match(struct task_struct *t, struct rdtgroup *r)
1140+
{
1141+
return (rdt_mon_capable &&
1142+
(r->type == RDTMON_GROUP) && (t->rmid == r->mon.rmid));
1143+
}
1144+
11331145
/*
11341146
* Move tasks from one to the other group. If @from is NULL, then all tasks
11351147
* in the systems are moved unconditionally (used for teardown).
@@ -1145,8 +1157,11 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to,
11451157

11461158
read_lock(&tasklist_lock);
11471159
for_each_process_thread(p, t) {
1148-
if (!from || t->closid == from->closid) {
1160+
if (!from || is_closid_match(t, from) ||
1161+
is_rmid_match(t, from)) {
11491162
t->closid = to->closid;
1163+
t->rmid = to->mon.rmid;
1164+
11501165
#ifdef CONFIG_SMP
11511166
/*
11521167
* This is safe on x86 w/o barriers as the ordering
@@ -1165,6 +1180,19 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to,
11651180
read_unlock(&tasklist_lock);
11661181
}
11671182

1183+
static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp)
1184+
{
1185+
struct rdtgroup *sentry, *stmp;
1186+
struct list_head *head;
1187+
1188+
head = &rdtgrp->mon.crdtgrp_list;
1189+
list_for_each_entry_safe(sentry, stmp, head, mon.crdtgrp_list) {
1190+
free_rmid(sentry->mon.rmid);
1191+
list_del(&sentry->mon.crdtgrp_list);
1192+
kfree(sentry);
1193+
}
1194+
}
1195+
11681196
/*
11691197
* Forcibly remove all of subdirectories under root.
11701198
*/
@@ -1565,6 +1593,44 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
15651593
return -EPERM;
15661594
}
15671595

1596+
static int rdtgroup_rmdir_mon(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
1597+
cpumask_var_t tmpmask)
1598+
{
1599+
struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
1600+
int cpu;
1601+
1602+
/* Give any tasks back to the parent group */
1603+
rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
1604+
1605+
/* Update per cpu rmid of the moved CPUs first */
1606+
for_each_cpu(cpu, &rdtgrp->cpu_mask)
1607+
per_cpu(rdt_cpu_default.rmid, cpu) = prdtgrp->mon.rmid;
1608+
/*
1609+
* Update the MSR on moved CPUs and CPUs which have moved
1610+
* task running on them.
1611+
*/
1612+
cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
1613+
update_closid_rmid(tmpmask, NULL);
1614+
1615+
rdtgrp->flags = RDT_DELETED;
1616+
free_rmid(rdtgrp->mon.rmid);
1617+
1618+
/*
1619+
* Remove the rdtgrp from the parent ctrl_mon group's list
1620+
*/
1621+
WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
1622+
list_del(&rdtgrp->mon.crdtgrp_list);
1623+
1624+
/*
1625+
* one extra hold on this, will drop when we kfree(rdtgrp)
1626+
* in rdtgroup_kn_unlock()
1627+
*/
1628+
kernfs_get(kn);
1629+
kernfs_remove(rdtgrp->kn);
1630+
1631+
return 0;
1632+
}
1633+
15681634
static int rdtgroup_rmdir_ctrl(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
15691635
cpumask_var_t tmpmask)
15701636
{
@@ -1577,9 +1643,12 @@ static int rdtgroup_rmdir_ctrl(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
15771643
cpumask_or(&rdtgroup_default.cpu_mask,
15781644
&rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
15791645

1580-
/* Update per cpu closid of the moved CPUs first */
1581-
for_each_cpu(cpu, &rdtgrp->cpu_mask)
1646+
/* Update per cpu closid and rmid of the moved CPUs first */
1647+
for_each_cpu(cpu, &rdtgrp->cpu_mask) {
15821648
per_cpu(rdt_cpu_default.closid, cpu) = rdtgroup_default.closid;
1649+
per_cpu(rdt_cpu_default.rmid, cpu) = rdtgroup_default.mon.rmid;
1650+
}
1651+
15831652
/*
15841653
* Update the MSR on moved CPUs and CPUs which have moved
15851654
* task running on them.
@@ -1589,6 +1658,13 @@ static int rdtgroup_rmdir_ctrl(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
15891658

15901659
rdtgrp->flags = RDT_DELETED;
15911660
closid_free(rdtgrp->closid);
1661+
free_rmid(rdtgrp->mon.rmid);
1662+
1663+
/*
1664+
* Free all the child monitor group rmids.
1665+
*/
1666+
free_all_child_rdtgrp(rdtgrp);
1667+
15921668
list_del(&rdtgrp->rdtgroup_list);
15931669

15941670
/*
@@ -1619,10 +1695,16 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
16191695

16201696
/*
16211697
* If the rdtgroup is a ctrl_mon group and parent directory
1622-
* is the root directory, remove the ctrl group.
1698+
* is the root directory, remove the ctrl_mon group.
1699+
*
1700+
* If the rdtgroup is a mon group and parent directory
1701+
* is a valid "mon_groups" directory, remove the mon group.
16231702
*/
16241703
if (rdtgrp->type == RDTCTRL_GROUP && parent_kn == rdtgroup_default.kn)
16251704
ret = rdtgroup_rmdir_ctrl(kn, rdtgrp, tmpmask);
1705+
else if (rdtgrp->type == RDTMON_GROUP &&
1706+
is_mon_groups(parent_kn, kn->name))
1707+
ret = rdtgroup_rmdir_mon(kn, rdtgrp, tmpmask);
16261708
else
16271709
ret = -EPERM;
16281710

0 commit comments

Comments
 (0)