Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

x86/resctrl: Refactor resctrl_arch_rmid_read()

resctrl_arch_rmid_read() adjusts the value obtained from MSR_IA32_QM_CTR to
account for the overflow for MBM events and apply counter scaling for all the
events. This logic is common to both reading an RMID and reading a hardware
counter directly.

Refactor the hardware value adjustment logic into get_corrected_val() to
prepare for support of reading a hardware counter.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com

authored by

Babu Moger and committed by
Borislav Petkov (AMD)
7c9ac605 862314fd

+23 -15
+23 -15
arch/x86/kernel/cpu/resctrl/monitor.c
··· 217 217 return chunks >> shift; 218 218 } 219 219 220 - int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, 221 - u32 unused, u32 rmid, enum resctrl_event_id eventid, 222 - u64 *val, void *ignored) 220 + static u64 get_corrected_val(struct rdt_resource *r, struct rdt_mon_domain *d, 221 + u32 rmid, enum resctrl_event_id eventid, u64 msr_val) 223 222 { 224 223 struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d); 225 224 struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); 226 - int cpu = cpumask_any(&d->hdr.cpu_mask); 227 225 struct arch_mbm_state *am; 228 - u64 msr_val, chunks; 229 - u32 prmid; 230 - int ret; 231 - 232 - resctrl_arch_rmid_read_context_check(); 233 - 234 - prmid = logical_rmid_to_physical_rmid(cpu, rmid); 235 - ret = __rmid_read_phys(prmid, eventid, &msr_val); 236 - if (ret) 237 - return ret; 226 + u64 chunks; 238 227 239 228 am = get_arch_mbm_state(hw_dom, rmid, eventid); 240 229 if (am) { ··· 235 246 chunks = msr_val; 236 247 } 237 248 238 - *val = chunks * hw_res->mon_scale; 249 + return chunks * hw_res->mon_scale; 250 + } 251 + 252 + int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, 253 + u32 unused, u32 rmid, enum resctrl_event_id eventid, 254 + u64 *val, void *ignored) 255 + { 256 + int cpu = cpumask_any(&d->hdr.cpu_mask); 257 + u64 msr_val; 258 + u32 prmid; 259 + int ret; 260 + 261 + resctrl_arch_rmid_read_context_check(); 262 + 263 + prmid = logical_rmid_to_physical_rmid(cpu, rmid); 264 + ret = __rmid_read_phys(prmid, eventid, &msr_val); 265 + if (ret) 266 + return ret; 267 + 268 + *val = get_corrected_val(r, d, rmid, eventid, msr_val); 239 269 240 270 return 0; 241 271 }