Skip to content

Commit 9d2e1a9

Browse files
author
James Morse
committed
arm_mpam: resctrl: Add plumbing against arm64 task and cpu hooks
arm64 provides helpers for changing a task's and a cpu's mpam partid/pmg values. These are used to back a number of resctrl_arch_ functions. Connect them up. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Jesse Chick <jessechick@os.amperecomputing.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Co-developed-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 9cd2b52 commit 9d2e1a9

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

drivers/resctrl/mpam_resctrl.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/cpu.h>
99
#include <linux/cpumask.h>
1010
#include <linux/errno.h>
11+
#include <linux/limits.h>
1112
#include <linux/list.h>
1213
#include <linux/printk.h>
1314
#include <linux/rculist.h>
@@ -34,6 +35,8 @@ static struct mpam_resctrl_res mpam_resctrl_controls[RDT_NUM_RESOURCES];
3435
/* The lock for modifying resctrl's domain lists from cpuhp callbacks. */
3536
static DEFINE_MUTEX(domain_list_lock);
3637

38+
static bool cdp_enabled;
39+
3740
bool resctrl_arch_alloc_capable(void)
3841
{
3942
struct mpam_resctrl_res *res;
@@ -57,6 +60,61 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored)
5760
return mpam_partid_max + 1;
5861
}
5962

63+
void resctrl_arch_sched_in(struct task_struct *tsk)
64+
{
65+
lockdep_assert_preemption_disabled();
66+
67+
mpam_thread_switch(tsk);
68+
}
69+
70+
void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid)
71+
{
72+
WARN_ON_ONCE(closid > U16_MAX);
73+
WARN_ON_ONCE(rmid > U8_MAX);
74+
75+
if (!cdp_enabled) {
76+
mpam_set_cpu_defaults(cpu, closid, closid, rmid, rmid);
77+
} else {
78+
/*
79+
* When CDP is enabled, resctrl halves the closid range and we
80+
* use odd/even partid for one closid.
81+
*/
82+
u32 partid_d = resctrl_get_config_index(closid, CDP_DATA);
83+
u32 partid_i = resctrl_get_config_index(closid, CDP_CODE);
84+
85+
mpam_set_cpu_defaults(cpu, partid_d, partid_i, rmid, rmid);
86+
}
87+
}
88+
89+
void resctrl_arch_sync_cpu_closid_rmid(void *info)
90+
{
91+
struct resctrl_cpu_defaults *r = info;
92+
93+
lockdep_assert_preemption_disabled();
94+
95+
if (r) {
96+
resctrl_arch_set_cpu_default_closid_rmid(smp_processor_id(),
97+
r->closid, r->rmid);
98+
}
99+
100+
resctrl_arch_sched_in(current);
101+
}
102+
103+
void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid)
104+
{
105+
WARN_ON_ONCE(closid > U16_MAX);
106+
WARN_ON_ONCE(rmid > U8_MAX);
107+
108+
if (!cdp_enabled) {
109+
mpam_set_task_partid_pmg(tsk, closid, closid, rmid, rmid);
110+
} else {
111+
u32 partid_d = resctrl_get_config_index(closid, CDP_DATA);
112+
u32 partid_i = resctrl_get_config_index(closid, CDP_CODE);
113+
114+
mpam_set_task_partid_pmg(tsk, partid_d, partid_i, rmid, rmid);
115+
}
116+
}
117+
60118
struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
61119
{
62120
if (l >= RDT_NUM_RESOURCES)

include/linux/arm_mpam.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
5252
bool resctrl_arch_alloc_capable(void);
5353
bool resctrl_arch_mon_capable(void);
5454

55+
void resctrl_arch_set_cpu_default_closid(int cpu, u32 closid);
56+
void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
57+
void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid);
58+
void resctrl_arch_sched_in(struct task_struct *tsk);
59+
5560
/**
5661
* mpam_register_requestor() - Register a requestor with the MPAM driver
5762
* @partid_max: The maximum PARTID value the requestor can generate.

0 commit comments

Comments
 (0)