Skip to content

Commit b09d981

Browse files
Vikas ShivappaKAGA-KOKO
authored andcommitted
x86/intel_rdt: Prepare to add RDT monitor cpus file support
Separate the ctrl cpus file handling from the generic cpus file handling and convert the per cpu closid from u32 to a struct which will be used later to add rmid to the same struct. Also cleanup some name space. 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-17-git-send-email-vikas.shivappa@linux.intel.com
1 parent d6aaba6 commit b09d981

4 files changed

Lines changed: 62 additions & 53 deletions

File tree

‎arch/x86/include/asm/intel_rdt_sched.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct intel_pqr_state {
2626
};
2727

2828
DECLARE_PER_CPU(struct intel_pqr_state, pqr_state);
29-
DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
29+
DECLARE_PER_CPU_READ_MOSTLY(struct intel_pqr_state, rdt_cpu_default);
3030
DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
3131

3232
/*
@@ -54,7 +54,7 @@ static inline void intel_rdt_sched_in(void)
5454
*/
5555
closid = current->closid;
5656
if (closid == 0)
57-
closid = this_cpu_read(cpu_closid);
57+
closid = this_cpu_read(rdt_cpu_default.closid);
5858

5959
if (closid != state->closid) {
6060
state->closid = closid;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
/* Mutex to protect rdtgroup access. */
4040
DEFINE_MUTEX(rdtgroup_mutex);
4141

42-
DEFINE_PER_CPU_READ_MOSTLY(int, cpu_closid);
43-
4442
/*
4543
* The cached intel_pqr_state is strictly per CPU and can never be
4644
* updated from a remote CPU. Functions which modify the state
@@ -49,6 +47,8 @@ DEFINE_PER_CPU_READ_MOSTLY(int, cpu_closid);
4947
*/
5048
DEFINE_PER_CPU(struct intel_pqr_state, pqr_state);
5149

50+
DEFINE_PER_CPU_READ_MOSTLY(struct intel_pqr_state, rdt_cpu_default);
51+
5252
/*
5353
* Used to store the max resource name width and max resource data width
5454
* to display the schemata in a tabular format
@@ -500,7 +500,7 @@ static void clear_closid(int cpu)
500500
{
501501
struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
502502

503-
per_cpu(cpu_closid, cpu) = 0;
503+
per_cpu(rdt_cpu_default.closid, cpu) = 0;
504504
state->closid = 0;
505505
wrmsr(IA32_PQR_ASSOC, state->rmid, 0);
506506
}

‎arch/x86/kernel/cpu/intel_rdt.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,6 @@ union cpuid_0x10_x_edx {
320320
unsigned int full;
321321
};
322322

323-
DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
324-
325323
void rdt_ctrl_update(void *arg);
326324
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
327325
void rdtgroup_kn_unlock(struct kernfs_node *kn);

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

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ 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 rdt_update_closid() is proteced against __switch_to() because
184+
* from update_closid() is proteced against __switch_to() because
185185
* preemption is disabled.
186186
*/
187-
static void rdt_update_cpu_closid(void *closid)
187+
static void update_cpu_closid(void *info)
188188
{
189-
if (closid)
190-
this_cpu_write(cpu_closid, *(int *)closid);
189+
struct rdtgroup *r = info;
190+
191+
if (r)
192+
this_cpu_write(rdt_cpu_default.closid, r->closid);
193+
191194
/*
192195
* We cannot unconditionally write the MSR because the current
193196
* executing task might have its own closid selected. Just reuse
@@ -199,28 +202,62 @@ static void rdt_update_cpu_closid(void *closid)
199202
/*
200203
* Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
201204
*
202-
* Per task closids must have been set up before calling this function.
203-
*
204-
* The per cpu closids are updated with the smp function call, when @closid
205-
* is not NULL. If @closid is NULL then all affected percpu closids must
206-
* have been set up before calling this function.
205+
* Per task closids/rmids must have been set up before calling this function.
207206
*/
208207
static void
209-
rdt_update_closid(const struct cpumask *cpu_mask, int *closid)
208+
update_closid(const struct cpumask *cpu_mask, struct rdtgroup *r)
210209
{
211210
int cpu = get_cpu();
212211

213212
if (cpumask_test_cpu(cpu, cpu_mask))
214-
rdt_update_cpu_closid(closid);
215-
smp_call_function_many(cpu_mask, rdt_update_cpu_closid, closid, 1);
213+
update_cpu_closid(r);
214+
smp_call_function_many(cpu_mask, update_cpu_closid, r, 1);
216215
put_cpu();
217216
}
218217

218+
static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
219+
cpumask_var_t tmpmask)
220+
{
221+
struct rdtgroup *r;
222+
223+
/* Check whether cpus are dropped from this group */
224+
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
225+
if (cpumask_weight(tmpmask)) {
226+
/* Can't drop from default group */
227+
if (rdtgrp == &rdtgroup_default)
228+
return -EINVAL;
229+
230+
/* Give any dropped cpus to rdtgroup_default */
231+
cpumask_or(&rdtgroup_default.cpu_mask,
232+
&rdtgroup_default.cpu_mask, tmpmask);
233+
update_closid(tmpmask, &rdtgroup_default);
234+
}
235+
236+
/*
237+
* If we added cpus, remove them from previous group that owned them
238+
* and update per-cpu closid
239+
*/
240+
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
241+
if (cpumask_weight(tmpmask)) {
242+
list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
243+
if (r == rdtgrp)
244+
continue;
245+
cpumask_andnot(&r->cpu_mask, &r->cpu_mask, tmpmask);
246+
}
247+
update_closid(tmpmask, rdtgrp);
248+
}
249+
250+
/* Done pushing/pulling - update this group with new mask */
251+
cpumask_copy(&rdtgrp->cpu_mask, newmask);
252+
253+
return 0;
254+
}
255+
219256
static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
220257
char *buf, size_t nbytes, loff_t off)
221258
{
222259
cpumask_var_t tmpmask, newmask;
223-
struct rdtgroup *rdtgrp, *r;
260+
struct rdtgroup *rdtgrp;
224261
int ret;
225262

226263
if (!buf)
@@ -254,36 +291,10 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
254291
goto unlock;
255292
}
256293

257-
/* Check whether cpus are dropped from this group */
258-
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
259-
if (cpumask_weight(tmpmask)) {
260-
/* Can't drop from default group */
261-
if (rdtgrp == &rdtgroup_default) {
262-
ret = -EINVAL;
263-
goto unlock;
264-
}
265-
/* Give any dropped cpus to rdtgroup_default */
266-
cpumask_or(&rdtgroup_default.cpu_mask,
267-
&rdtgroup_default.cpu_mask, tmpmask);
268-
rdt_update_closid(tmpmask, &rdtgroup_default.closid);
269-
}
270-
271-
/*
272-
* If we added cpus, remove them from previous group that owned them
273-
* and update per-cpu closid
274-
*/
275-
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
276-
if (cpumask_weight(tmpmask)) {
277-
list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
278-
if (r == rdtgrp)
279-
continue;
280-
cpumask_andnot(&r->cpu_mask, &r->cpu_mask, tmpmask);
281-
}
282-
rdt_update_closid(tmpmask, &rdtgrp->closid);
283-
}
284-
285-
/* Done pushing/pulling - update this group with new mask */
286-
cpumask_copy(&rdtgrp->cpu_mask, newmask);
294+
if (rdtgrp->type == RDTCTRL_GROUP)
295+
ret = cpus_ctrl_write(rdtgrp, newmask, tmpmask);
296+
else
297+
ret = -EINVAL;
287298

288299
unlock:
289300
rdtgroup_kn_unlock(of->kn);
@@ -1102,7 +1113,7 @@ static void rmdir_all_sub(void)
11021113
}
11031114
/* Notify online CPUs to update per cpu storage and PQR_ASSOC MSR */
11041115
get_online_cpus();
1105-
rdt_update_closid(cpu_online_mask, &rdtgroup_default.closid);
1116+
update_closid(cpu_online_mask, &rdtgroup_default);
11061117
put_online_cpus();
11071118

11081119
kernfs_remove(kn_info);
@@ -1357,13 +1368,13 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
13571368

13581369
/* Update per cpu closid of the moved CPUs first */
13591370
for_each_cpu(cpu, &rdtgrp->cpu_mask)
1360-
per_cpu(cpu_closid, cpu) = closid;
1371+
per_cpu(rdt_cpu_default.closid, cpu) = closid;
13611372
/*
13621373
* Update the MSR on moved CPUs and CPUs which have moved
13631374
* task running on them.
13641375
*/
13651376
cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask);
1366-
rdt_update_closid(tmpmask, NULL);
1377+
update_closid(tmpmask, NULL);
13671378

13681379
rdtgrp->flags = RDT_DELETED;
13691380
closid_free(rdtgrp->closid);

0 commit comments

Comments
 (0)