Skip to content

Commit 3044257

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks
mbm_bw_count() is only called by the mbm_handle_overflow() worker once a second. It reads the hardware register, calculates the bandwidth and updates m->prev_bw_msr which is used to hold the previous hardware register value. Operating directly on hardware register values makes it difficult to make this code architecture independent, so that it can be moved to /fs/, making the mba_sc feature something resctrl supports with no additional support from the architecture. Prior to calling mbm_bw_count(), mbm_update() reads from the same hardware register using __mon_event_count(). Change mbm_bw_count() to use the current chunks value most recently saved by __mon_event_count(). This removes an extra call to __rmid_read(). Instead of using m->prev_msr to calculate the number of chunks seen, use the rr->val that was updated by __mon_event_count(). This removes an extra call to mbm_overflow_count() and get_corrected_mbm_count(). Calculating bandwidth like this means mbm_bw_count() no longer operates on hardware register values directly. 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 ff6357b commit 3044257

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ struct rftype {
289289
* struct mbm_state - status for each MBM counter in each domain
290290
* @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes)
291291
* @prev_msr: Value of IA32_QM_CTR for this RMID last time we read it
292-
* @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting
292+
* @prev_bw_chunks: Previous chunks value read for bandwidth calculation
293293
* @prev_bw: The most recent bandwidth in MBps
294294
* @delta_bw: Difference between the current and previous bandwidth
295295
* @delta_comp: Indicates whether to compute the delta_bw
296296
*/
297297
struct mbm_state {
298298
u64 chunks;
299299
u64 prev_msr;
300-
u64 prev_bw_msr;
300+
u64 prev_bw_chunks;
301301
u32 prev_bw;
302302
u32 delta_bw;
303303
bool delta_comp;

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
315315

316316
if (rr->first) {
317317
memset(m, 0, sizeof(struct mbm_state));
318-
m->prev_bw_msr = m->prev_msr = tval;
318+
m->prev_msr = tval;
319319
return 0;
320320
}
321321

@@ -329,27 +329,32 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
329329
}
330330

331331
/*
332+
* mbm_bw_count() - Update bw count from values previously read by
333+
* __mon_event_count().
334+
* @rmid: The rmid used to identify the cached mbm_state.
335+
* @rr: The struct rmid_read populated by __mon_event_count().
336+
*
332337
* Supporting function to calculate the memory bandwidth
333-
* and delta bandwidth in MBps.
338+
* and delta bandwidth in MBps. The chunks value previously read by
339+
* __mon_event_count() is compared with the chunks value from the previous
340+
* invocation. This must be called once per second to maintain values in MBps.
334341
*/
335342
static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
336343
{
337344
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
338345
struct mbm_state *m = &rr->d->mbm_local[rmid];
339-
u64 tval, cur_bw, chunks;
346+
u64 cur_bw, chunks, cur_chunks;
340347

341-
tval = __rmid_read(rmid, rr->evtid);
342-
if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL))
343-
return;
348+
cur_chunks = rr->val;
349+
chunks = cur_chunks - m->prev_bw_chunks;
350+
m->prev_bw_chunks = cur_chunks;
344351

345-
chunks = mbm_overflow_count(m->prev_bw_msr, tval, hw_res->mbm_width);
346-
cur_bw = (get_corrected_mbm_count(rmid, chunks) * hw_res->mon_scale) >> 20;
352+
cur_bw = (chunks * hw_res->mon_scale) >> 20;
347353

348354
if (m->delta_comp)
349355
m->delta_bw = abs(cur_bw - m->prev_bw);
350356
m->delta_comp = false;
351357
m->prev_bw = cur_bw;
352-
m->prev_bw_msr = tval;
353358
}
354359

355360
/*
@@ -516,10 +521,12 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid)
516521
*/
517522
if (is_mbm_total_enabled()) {
518523
rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID;
524+
rr.val = 0;
519525
__mon_event_count(rmid, &rr);
520526
}
521527
if (is_mbm_local_enabled()) {
522528
rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID;
529+
rr.val = 0;
523530
__mon_event_count(rmid, &rr);
524531

525532
/*

0 commit comments

Comments
 (0)