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/resctrl_types.h>
10+ #include <linux/sched.h>
911
1012/*
1113 * This value can never be a valid CLOSID, and is used when mapping a
@@ -40,6 +42,7 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);
4042
4143extern bool rdt_alloc_capable ;
4244extern bool rdt_mon_capable ;
45+ extern unsigned int rdt_mon_features ;
4346
4447DECLARE_STATIC_KEY_FALSE (rdt_enable_key );
4548DECLARE_STATIC_KEY_FALSE (rdt_alloc_enable_key );
@@ -79,6 +82,21 @@ static inline void resctrl_arch_disable_mon(void)
7982 static_branch_dec_cpuslocked (& rdt_enable_key );
8083}
8184
85+ static inline bool resctrl_arch_is_llc_occupancy_enabled (void )
86+ {
87+ return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID ));
88+ }
89+
90+ static inline bool resctrl_arch_is_mbm_total_enabled (void )
91+ {
92+ return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID ));
93+ }
94+
95+ static inline bool resctrl_arch_is_mbm_local_enabled (void )
96+ {
97+ return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID ));
98+ }
99+
82100/*
83101 * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR
84102 *
@@ -96,8 +114,8 @@ static inline void resctrl_arch_disable_mon(void)
96114static inline void __resctrl_sched_in (struct task_struct * tsk )
97115{
98116 struct resctrl_pqr_state * state = this_cpu_ptr (& pqr_state );
99- u32 closid = state -> default_closid ;
100- u32 rmid = state -> default_rmid ;
117+ u32 closid = READ_ONCE ( state -> default_closid ) ;
118+ u32 rmid = READ_ONCE ( state -> default_rmid ) ;
101119 u32 tmp ;
102120
103121 /*
@@ -132,6 +150,13 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
132150 return val * scale ;
133151}
134152
153+ static inline void resctrl_arch_set_cpu_default_closid_rmid (int cpu , u32 closid ,
154+ u32 rmid )
155+ {
156+ WRITE_ONCE (per_cpu (pqr_state .default_closid , cpu ), closid );
157+ WRITE_ONCE (per_cpu (pqr_state .default_rmid , cpu ), rmid );
158+ }
159+
135160static inline void resctrl_arch_set_closid_rmid (struct task_struct * tsk ,
136161 u32 closid , u32 rmid )
137162{
@@ -150,7 +175,7 @@ static inline bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 ignored,
150175 return READ_ONCE (tsk -> rmid ) == rmid ;
151176}
152177
153- static inline void resctrl_sched_in (struct task_struct * tsk )
178+ static inline void resctrl_arch_sched_in (struct task_struct * tsk )
154179{
155180 if (static_branch_likely (& rdt_enable_key ))
156181 __resctrl_sched_in (tsk );
@@ -169,20 +194,22 @@ static inline u32 resctrl_arch_rmid_idx_encode(u32 ignored, u32 rmid)
169194
170195/* x86 can always read an rmid, nothing needs allocating */
171196struct rdt_resource ;
172- static inline void * resctrl_arch_mon_ctx_alloc (struct rdt_resource * r , int evtid )
197+ static inline void * resctrl_arch_mon_ctx_alloc (struct rdt_resource * r ,
198+ enum resctrl_event_id evtid )
173199{
174200 might_sleep ();
175201 return NULL ;
176- };
202+ }
177203
178- static inline void resctrl_arch_mon_ctx_free (struct rdt_resource * r , int evtid ,
179- void * ctx ) { };
204+ static inline void resctrl_arch_mon_ctx_free (struct rdt_resource * r ,
205+ enum resctrl_event_id evtid ,
206+ void * ctx ) { }
180207
181208void resctrl_cpu_detect (struct cpuinfo_x86 * c );
182209
183210#else
184211
185- static inline void resctrl_sched_in (struct task_struct * tsk ) {}
212+ static inline void resctrl_arch_sched_in (struct task_struct * tsk ) {}
186213static inline void resctrl_cpu_detect (struct cpuinfo_x86 * c ) {}
187214
188215#endif /* CONFIG_X86_CPU_RESCTRL */
0 commit comments