0001
0002 #ifndef _ASM_X86_RESCTRL_H
0003 #define _ASM_X86_RESCTRL_H
0004
0005 #ifdef CONFIG_X86_CPU_RESCTRL
0006
0007 #include <linux/sched.h>
0008 #include <linux/jump_label.h>
0009
0010 #define IA32_PQR_ASSOC 0x0c8f
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 struct resctrl_pqr_state {
0028 u32 cur_rmid;
0029 u32 cur_closid;
0030 u32 default_rmid;
0031 u32 default_closid;
0032 };
0033
0034 DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);
0035
0036 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
0037 DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
0038 DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 static void __resctrl_sched_in(void)
0055 {
0056 struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
0057 u32 closid = state->default_closid;
0058 u32 rmid = state->default_rmid;
0059 u32 tmp;
0060
0061
0062
0063
0064
0065 if (static_branch_likely(&rdt_alloc_enable_key)) {
0066 tmp = READ_ONCE(current->closid);
0067 if (tmp)
0068 closid = tmp;
0069 }
0070
0071 if (static_branch_likely(&rdt_mon_enable_key)) {
0072 tmp = READ_ONCE(current->rmid);
0073 if (tmp)
0074 rmid = tmp;
0075 }
0076
0077 if (closid != state->cur_closid || rmid != state->cur_rmid) {
0078 state->cur_closid = closid;
0079 state->cur_rmid = rmid;
0080 wrmsr(IA32_PQR_ASSOC, rmid, closid);
0081 }
0082 }
0083
0084 static inline void resctrl_sched_in(void)
0085 {
0086 if (static_branch_likely(&rdt_enable_key))
0087 __resctrl_sched_in();
0088 }
0089
0090 void resctrl_cpu_detect(struct cpuinfo_x86 *c);
0091
0092 #else
0093
0094 static inline void resctrl_sched_in(void) {}
0095 static inline void resctrl_cpu_detect(struct cpuinfo_x86 *c) {}
0096
0097 #endif
0098
0099 #endif