Skip to content

Commit a9fcf86

Browse files
Vikas ShivappaKAGA-KOKO
authored andcommitted
x86/intel_rdt/cqm: Add cpus file support
The cpus file is extended to support resource monitoring. This is used to over-ride the RMID of the default group when running on specific CPUs. It works similar to the resource control. The "cpus" and "cpus_list" file is present in default group, ctrl_mon groups and monitor groups. Each "cpus" file or cpu_list file reads a cpumask or list showing which CPUs belong to the resource group. By default all online cpus belong to the default root group. A CPU can be present in one "ctrl_mon" and one "monitor" group simultaneously. They can be added to a resource group by writing the CPU to the file. When a CPU is added to a ctrl_mon group it is automatically removed from the previous ctrl_mon group. A CPU can be added to a monitor group only if it is present in the parent ctrl_mon group and when a CPU is added to a monitor group, it is automatically removed from the previous monitor group. When CPUs go offline, they are automatically removed from the ctrl_mon and monitor groups. 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-18-git-send-email-vikas.shivappa@linux.intel.com
1 parent b09d981 commit a9fcf86

1 file changed

Lines changed: 93 additions & 17 deletions

File tree

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

Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,17 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
181181
/*
182182
* This is safe against intel_rdt_sched_in() called from __switch_to()
183183
* because __switch_to() is executed with interrupts disabled. A local call
184-
* from update_closid() is proteced against __switch_to() because
184+
* from update_closid_rmid() is proteced against __switch_to() because
185185
* preemption is disabled.
186186
*/
187-
static void update_cpu_closid(void *info)
187+
static void update_cpu_closid_rmid(void *info)
188188
{
189189
struct rdtgroup *r = info;
190190

191-
if (r)
191+
if (r) {
192192
this_cpu_write(rdt_cpu_default.closid, r->closid);
193+
this_cpu_write(rdt_cpu_default.rmid, r->mon.rmid);
194+
}
193195

194196
/*
195197
* We cannot unconditionally write the MSR because the current
@@ -205,20 +207,72 @@ static void update_cpu_closid(void *info)
205207
* Per task closids/rmids must have been set up before calling this function.
206208
*/
207209
static void
208-
update_closid(const struct cpumask *cpu_mask, struct rdtgroup *r)
210+
update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
209211
{
210212
int cpu = get_cpu();
211213

212214
if (cpumask_test_cpu(cpu, cpu_mask))
213-
update_cpu_closid(r);
214-
smp_call_function_many(cpu_mask, update_cpu_closid, r, 1);
215+
update_cpu_closid_rmid(r);
216+
smp_call_function_many(cpu_mask, update_cpu_closid_rmid, r, 1);
215217
put_cpu();
216218
}
217219

220+
static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
221+
cpumask_var_t tmpmask)
222+
{
223+
struct rdtgroup *prgrp = rdtgrp->mon.parent, *crgrp;
224+
struct list_head *head;
225+
226+
/* Check whether cpus belong to parent ctrl group */
227+
cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);
228+
if (cpumask_weight(tmpmask))
229+
return -EINVAL;
230+
231+
/* Check whether cpus are dropped from this group */
232+
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
233+
if (cpumask_weight(tmpmask)) {
234+
/* Give any dropped cpus to parent rdtgroup */
235+
cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);
236+
update_closid_rmid(tmpmask, prgrp);
237+
}
238+
239+
/*
240+
* If we added cpus, remove them from previous group that owned them
241+
* and update per-cpu rmid
242+
*/
243+
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
244+
if (cpumask_weight(tmpmask)) {
245+
head = &prgrp->mon.crdtgrp_list;
246+
list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
247+
if (crgrp == rdtgrp)
248+
continue;
249+
cpumask_andnot(&crgrp->cpu_mask, &crgrp->cpu_mask,
250+
tmpmask);
251+
}
252+
update_closid_rmid(tmpmask, rdtgrp);
253+
}
254+
255+
/* Done pushing/pulling - update this group with new mask */
256+
cpumask_copy(&rdtgrp->cpu_mask, newmask);
257+
258+
return 0;
259+
}
260+
261+
static void cpumask_rdtgrp_clear(struct rdtgroup *r, struct cpumask *m)
262+
{
263+
struct rdtgroup *crgrp;
264+
265+
cpumask_andnot(&r->cpu_mask, &r->cpu_mask, m);
266+
/* update the child mon group masks as well*/
267+
list_for_each_entry(crgrp, &r->mon.crdtgrp_list, mon.crdtgrp_list)
268+
cpumask_and(&crgrp->cpu_mask, &r->cpu_mask, &crgrp->cpu_mask);
269+
}
270+
218271
static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
219-
cpumask_var_t tmpmask)
272+
cpumask_var_t tmpmask, cpumask_var_t tmpmask1)
220273
{
221-
struct rdtgroup *r;
274+
struct rdtgroup *r, *crgrp;
275+
struct list_head *head;
222276

223277
/* Check whether cpus are dropped from this group */
224278
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
@@ -230,33 +284,47 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
230284
/* Give any dropped cpus to rdtgroup_default */
231285
cpumask_or(&rdtgroup_default.cpu_mask,
232286
&rdtgroup_default.cpu_mask, tmpmask);
233-
update_closid(tmpmask, &rdtgroup_default);
287+
update_closid_rmid(tmpmask, &rdtgroup_default);
234288
}
235289

236290
/*
237-
* If we added cpus, remove them from previous group that owned them
238-
* and update per-cpu closid
291+
* If we added cpus, remove them from previous group and
292+
* the prev group's child groups that owned them
293+
* and update per-cpu closid/rmid.
239294
*/
240295
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
241296
if (cpumask_weight(tmpmask)) {
242297
list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
243298
if (r == rdtgrp)
244299
continue;
245-
cpumask_andnot(&r->cpu_mask, &r->cpu_mask, tmpmask);
300+
cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);
301+
if (cpumask_weight(tmpmask1))
302+
cpumask_rdtgrp_clear(r, tmpmask1);
246303
}
247-
update_closid(tmpmask, rdtgrp);
304+
update_closid_rmid(tmpmask, rdtgrp);
248305
}
249306

250307
/* Done pushing/pulling - update this group with new mask */
251308
cpumask_copy(&rdtgrp->cpu_mask, newmask);
252309

310+
/*
311+
* Clear child mon group masks since there is a new parent mask
312+
* now and update the rmid for the cpus the child lost.
313+
*/
314+
head = &rdtgrp->mon.crdtgrp_list;
315+
list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
316+
cpumask_and(tmpmask, &rdtgrp->cpu_mask, &crgrp->cpu_mask);
317+
update_closid_rmid(tmpmask, rdtgrp);
318+
cpumask_clear(&crgrp->cpu_mask);
319+
}
320+
253321
return 0;
254322
}
255323

256324
static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
257325
char *buf, size_t nbytes, loff_t off)
258326
{
259-
cpumask_var_t tmpmask, newmask;
327+
cpumask_var_t tmpmask, newmask, tmpmask1;
260328
struct rdtgroup *rdtgrp;
261329
int ret;
262330

@@ -269,6 +337,11 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
269337
free_cpumask_var(tmpmask);
270338
return -ENOMEM;
271339
}
340+
if (!zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) {
341+
free_cpumask_var(tmpmask);
342+
free_cpumask_var(newmask);
343+
return -ENOMEM;
344+
}
272345

273346
rdtgrp = rdtgroup_kn_lock_live(of->kn);
274347
if (!rdtgrp) {
@@ -292,14 +365,17 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
292365
}
293366

294367
if (rdtgrp->type == RDTCTRL_GROUP)
295-
ret = cpus_ctrl_write(rdtgrp, newmask, tmpmask);
368+
ret = cpus_ctrl_write(rdtgrp, newmask, tmpmask, tmpmask1);
369+
else if (rdtgrp->type == RDTMON_GROUP)
370+
ret = cpus_mon_write(rdtgrp, newmask, tmpmask);
296371
else
297372
ret = -EINVAL;
298373

299374
unlock:
300375
rdtgroup_kn_unlock(of->kn);
301376
free_cpumask_var(tmpmask);
302377
free_cpumask_var(newmask);
378+
free_cpumask_var(tmpmask1);
303379

304380
return ret ?: nbytes;
305381
}
@@ -1113,7 +1189,7 @@ static void rmdir_all_sub(void)
11131189
}
11141190
/* Notify online CPUs to update per cpu storage and PQR_ASSOC MSR */
11151191
get_online_cpus();
1116-
update_closid(cpu_online_mask, &rdtgroup_default);
1192+
update_closid_rmid(cpu_online_mask, &rdtgroup_default);
11171193
put_online_cpus();
11181194

11191195
kernfs_remove(kn_info);
@@ -1374,7 +1450,7 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
13741450
* task running on them.
13751451
*/
13761452
cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
1377-
update_closid(tmpmask, NULL);
1453+
update_closid_rmid(tmpmask, NULL);
13781454

13791455
rdtgrp->flags = RDT_DELETED;
13801456
closid_free(rdtgrp->closid);

0 commit comments

Comments
 (0)