Skip to content

Commit 12e3db9

Browse files
babumogergregkh
authored andcommitted
x86/resctrl: Refactor resctrl_arch_rmid_read()
[ Upstream commit 7c9ac60 ] 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: 15292f1 ("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 78a2d39 commit 12e3db9

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

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

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

315-
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
316-
u32 unused, u32 rmid, enum resctrl_event_id eventid,
317-
u64 *val, void *ignored)
315+
static u64 get_corrected_val(struct rdt_resource *r, struct rdt_mon_domain *d,
316+
u32 rmid, enum resctrl_event_id eventid, u64 msr_val)
318317
{
319318
struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
320319
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
321-
int cpu = cpumask_any(&d->hdr.cpu_mask);
322320
struct arch_mbm_state *am;
323-
u64 msr_val, chunks;
324-
u32 prmid;
325-
int ret;
326-
327-
resctrl_arch_rmid_read_context_check();
328-
329-
prmid = logical_rmid_to_physical_rmid(cpu, rmid);
330-
ret = __rmid_read_phys(prmid, eventid, &msr_val);
331-
if (ret)
332-
return ret;
321+
u64 chunks;
333322

334323
am = get_arch_mbm_state(hw_dom, rmid, eventid);
335324
if (am) {
@@ -341,7 +330,26 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
341330
chunks = msr_val;
342331
}
343332

344-
*val = chunks * hw_res->mon_scale;
333+
return chunks * hw_res->mon_scale;
334+
}
335+
336+
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
337+
u32 unused, u32 rmid, enum resctrl_event_id eventid,
338+
u64 *val, void *ignored)
339+
{
340+
int cpu = cpumask_any(&d->hdr.cpu_mask);
341+
u64 msr_val;
342+
u32 prmid;
343+
int ret;
344+
345+
resctrl_arch_rmid_read_context_check();
346+
347+
prmid = logical_rmid_to_physical_rmid(cpu, rmid);
348+
ret = __rmid_read_phys(prmid, eventid, &msr_val);
349+
if (ret)
350+
return ret;
351+
352+
*val = get_corrected_val(r, d, rmid, eventid, msr_val);
345353

346354
return 0;
347355
}

0 commit comments

Comments
 (0)