Skip to content

Commit 1d81d15

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read()
resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a counter. Currently the function returns the MBM values in chunks directly from hardware. When reading a bandwidth counter, mbm_overflow_count() must be used to correct for any possible overflow. mbm_overflow_count() is architecture specific, its behaviour should be part of resctrl_arch_rmid_read(). Move the mbm_overflow_count() calls into resctrl_arch_rmid_read(). This allows the resctrl filesystems's prev_msr to be removed in favour of the architecture private version. Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Jamie Iles <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Tested-by: Xin Hao <[email protected]> Tested-by: Shaopeng Tan <[email protected]> Tested-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8286618 commit 1d81d15

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,13 @@ struct rftype {
281281
/**
282282
* struct mbm_state - status for each MBM counter in each domain
283283
* @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes)
284-
* @prev_msr: Value of IA32_QM_CTR for this RMID last time we read it
285284
* @prev_bw_chunks: Previous chunks value read for bandwidth calculation
286285
* @prev_bw: The most recent bandwidth in MBps
287286
* @delta_bw: Difference between the current and previous bandwidth
288287
* @delta_comp: Indicates whether to compute the delta_bw
289288
*/
290289
struct mbm_state {
291290
u64 chunks;
292-
u64 prev_msr;
293291
u64 prev_bw_chunks;
294292
u32 prev_bw;
295293
u32 delta_bw;

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,20 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
167167
memset(am, 0, sizeof(*am));
168168
}
169169

170+
static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
171+
{
172+
u64 shift = 64 - width, chunks;
173+
174+
chunks = (cur_msr << shift) - (prev_msr << shift);
175+
return chunks >> shift;
176+
}
177+
170178
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
171179
u32 rmid, enum resctrl_event_id eventid, u64 *val)
172180
{
181+
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
182+
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
183+
struct arch_mbm_state *am;
173184
u64 msr_val;
174185

175186
if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
@@ -191,7 +202,13 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
191202
if (msr_val & RMID_VAL_UNAVAIL)
192203
return -EINVAL;
193204

194-
*val = msr_val;
205+
am = get_arch_mbm_state(hw_dom, rmid, eventid);
206+
if (am) {
207+
*val = mbm_overflow_count(am->prev_msr, msr_val, hw_res->mbm_width);
208+
am->prev_msr = msr_val;
209+
} else {
210+
*val = msr_val;
211+
}
195212

196213
return 0;
197214
}
@@ -322,19 +339,10 @@ void free_rmid(u32 rmid)
322339
list_add_tail(&entry->list, &rmid_free_lru);
323340
}
324341

325-
static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
326-
{
327-
u64 shift = 64 - width, chunks;
328-
329-
chunks = (cur_msr << shift) - (prev_msr << shift);
330-
return chunks >> shift;
331-
}
332-
333342
static int __mon_event_count(u32 rmid, struct rmid_read *rr)
334343
{
335-
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
336344
struct mbm_state *m;
337-
u64 chunks, tval = 0;
345+
u64 tval = 0;
338346

339347
if (rr->first)
340348
resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
@@ -363,13 +371,10 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr)
363371

364372
if (rr->first) {
365373
memset(m, 0, sizeof(struct mbm_state));
366-
m->prev_msr = tval;
367374
return 0;
368375
}
369376

370-
chunks = mbm_overflow_count(m->prev_msr, tval, hw_res->mbm_width);
371-
m->chunks += chunks;
372-
m->prev_msr = tval;
377+
m->chunks += tval;
373378

374379
rr->val += get_corrected_mbm_count(rmid, m->chunks);
375380

0 commit comments

Comments
 (0)