Skip to content

Commit aebd535

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Add helper for setting CPU default properties
rdtgroup_rmdir_ctrl() and rdtgroup_rmdir_mon() set the per-CPU pqr_state for CPUs that were part of the rmdir()'d group. Another architecture might not have a 'pqr_state', its hardware may need the values in a different format. MPAM's equivalent of RMID values are not unique, and always need the CLOSID to be provided too. There is only one caller that modifies a single value, (rdtgroup_rmdir_mon()). MPAM always needs both CLOSID and RMID for the hardware value as these are written to the same system register. As rdtgroup_rmdir_mon() has the CLOSID on hand, only provide a helper to set both values. These values are read by __resctrl_sched_in(), but may be written by a different CPU without any locking, add READ/WRTE_ONCE() to avoid torn values. Co-developed-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64 Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64 Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lore.kernel.org/r/20250311183715.16445-10-james.morse@arm.com
1 parent dbc58f7 commit aebd535

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

arch/x86/include/asm/resctrl.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
#ifdef CONFIG_X86_CPU_RESCTRL
66

7-
#include <linux/sched.h>
87
#include <linux/jump_label.h>
8+
#include <linux/percpu.h>
9+
#include <linux/sched.h>
910

1011
/*
1112
* This value can never be a valid CLOSID, and is used when mapping a
@@ -96,8 +97,8 @@ static inline void resctrl_arch_disable_mon(void)
9697
static inline void __resctrl_sched_in(struct task_struct *tsk)
9798
{
9899
struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
99-
u32 closid = state->default_closid;
100-
u32 rmid = state->default_rmid;
100+
u32 closid = READ_ONCE(state->default_closid);
101+
u32 rmid = READ_ONCE(state->default_rmid);
101102
u32 tmp;
102103

103104
/*
@@ -132,6 +133,13 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
132133
return val * scale;
133134
}
134135

136+
static inline void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid,
137+
u32 rmid)
138+
{
139+
WRITE_ONCE(per_cpu(pqr_state.default_closid, cpu), closid);
140+
WRITE_ONCE(per_cpu(pqr_state.default_rmid, cpu), rmid);
141+
}
142+
135143
static inline void resctrl_arch_set_closid_rmid(struct task_struct *tsk,
136144
u32 closid, u32 rmid)
137145
{

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,14 +3731,21 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
37313731
static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
37323732
{
37333733
struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
3734+
u32 closid, rmid;
37343735
int cpu;
37353736

37363737
/* Give any tasks back to the parent group */
37373738
rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
37383739

3739-
/* Update per cpu rmid of the moved CPUs first */
3740+
/*
3741+
* Update per cpu closid/rmid of the moved CPUs first.
3742+
* Note: the closid will not change, but the arch code still needs it.
3743+
*/
3744+
closid = prdtgrp->closid;
3745+
rmid = prdtgrp->mon.rmid;
37403746
for_each_cpu(cpu, &rdtgrp->cpu_mask)
3741-
per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
3747+
resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
3748+
37423749
/*
37433750
* Update the MSR on moved CPUs and CPUs which have moved
37443751
* task running on them.
@@ -3771,6 +3778,7 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)
37713778

37723779
static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
37733780
{
3781+
u32 closid, rmid;
37743782
int cpu;
37753783

37763784
/* Give any tasks back to the default group */
@@ -3781,10 +3789,10 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
37813789
&rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
37823790

37833791
/* Update per cpu closid and rmid of the moved CPUs first */
3784-
for_each_cpu(cpu, &rdtgrp->cpu_mask) {
3785-
per_cpu(pqr_state.default_closid, cpu) = rdtgroup_default.closid;
3786-
per_cpu(pqr_state.default_rmid, cpu) = rdtgroup_default.mon.rmid;
3787-
}
3792+
closid = rdtgroup_default.closid;
3793+
rmid = rdtgroup_default.mon.rmid;
3794+
for_each_cpu(cpu, &rdtgrp->cpu_mask)
3795+
resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
37883796

37893797
/*
37903798
* Update the MSR on moved CPUs and CPUs which have moved

0 commit comments

Comments
 (0)