Skip to content

Commit 265268c

Browse files
babumogergregkh
authored andcommitted
x86/resctrl: Refactor resctrl_arch_rmid_read()
[ Upstream commit 7c9ac605e202c4668e441fc8146a993577131ca1 ] 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 <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Link: https://lore.kernel.org/[email protected] Stable-dep-of: 15292f1b4c55 ("x86/resctrl: Fix miscount of bandwidth event when reactivating previously unavailable RMID") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 785ec51 commit 265268c

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,13 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
224224
return chunks >> shift;
225225
}
226226

227-
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
228-
u32 unused, u32 rmid, enum resctrl_event_id eventid,
229-
u64 *val, void *ignored)
227+
static u64 get_corrected_val(struct rdt_resource *r, struct rdt_mon_domain *d,
228+
u32 rmid, enum resctrl_event_id eventid, u64 msr_val)
230229
{
231230
struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
232231
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
233-
int cpu = cpumask_any(&d->hdr.cpu_mask);
234232
struct arch_mbm_state *am;
235-
u64 msr_val, chunks;
236-
u32 prmid;
237-
int ret;
238-
239-
resctrl_arch_rmid_read_context_check();
240-
241-
prmid = logical_rmid_to_physical_rmid(cpu, rmid);
242-
ret = __rmid_read_phys(prmid, eventid, &msr_val);
243-
if (ret)
244-
return ret;
233+
u64 chunks;
245234

246235
am = get_arch_mbm_state(hw_dom, rmid, eventid);
247236
if (am) {
@@ -253,7 +242,26 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
253242
chunks = msr_val;
254243
}
255244

256-
*val = chunks * hw_res->mon_scale;
245+
return chunks * hw_res->mon_scale;
246+
}
247+
248+
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
249+
u32 unused, u32 rmid, enum resctrl_event_id eventid,
250+
u64 *val, void *ignored)
251+
{
252+
int cpu = cpumask_any(&d->hdr.cpu_mask);
253+
u64 msr_val;
254+
u32 prmid;
255+
int ret;
256+
257+
resctrl_arch_rmid_read_context_check();
258+
259+
prmid = logical_rmid_to_physical_rmid(cpu, rmid);
260+
ret = __rmid_read_phys(prmid, eventid, &msr_val);
261+
if (ret)
262+
return ret;
263+
264+
*val = get_corrected_val(r, d, rmid, eventid, msr_val);
257265

258266
return 0;
259267
}

0 commit comments

Comments
 (0)