Skip to content

Commit ba0f26d

Browse files
Vikas ShivappaKAGA-KOKO
authored andcommitted
x86/intel_rdt/mba_sc: Prepare for feedback loop
This is a preparatory patch for the mba feedback loop. Add support to measure the "bandwidth in MBps" and the "delta bandwidth". Measure it by reading the MBM IA32_QM_CTR MSRs and calculating the amount of "bytes" moved. There is no user space interface for this and will only be used by the feedback loop patch. Signed-off-by: Vikas Shivappa <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 8205a07 commit ba0f26d

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

arch/x86/kernel/cpu/intel_rdt.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,20 @@ struct rftype {
180180
* struct mbm_state - status for each MBM counter in each domain
181181
* @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes)
182182
* @prev_msr Value of IA32_QM_CTR for this RMID last time we read it
183+
* @chunks_bw Total local data moved. Used for bandwidth calculation
184+
* @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting
185+
* @prev_bw The most recent bandwidth in MBps
186+
* @delta_bw Difference between the current and previous bandwidth
187+
* @delta_comp Indicates whether to compute the delta_bw
183188
*/
184189
struct mbm_state {
185190
u64 chunks;
186191
u64 prev_msr;
192+
u64 chunks_bw;
193+
u64 prev_bw_msr;
194+
u32 prev_bw;
195+
u32 delta_bw;
196+
bool delta_comp;
187197
};
188198

189199
/**

arch/x86/kernel/cpu/intel_rdt_monitor.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,18 @@ void free_rmid(u32 rmid)
225225
list_add_tail(&entry->list, &rmid_free_lru);
226226
}
227227

228+
static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr)
229+
{
230+
u64 shift = 64 - MBM_CNTR_WIDTH, chunks;
231+
232+
chunks = (cur_msr << shift) - (prev_msr << shift);
233+
return chunks >>= shift;
234+
}
235+
228236
static int __mon_event_count(u32 rmid, struct rmid_read *rr)
229237
{
230-
u64 chunks, shift, tval;
231238
struct mbm_state *m;
239+
u64 chunks, tval;
232240

233241
tval = __rmid_read(rmid, rr->evtid);
234242
if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
@@ -254,21 +262,45 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr)
254262
}
255263

256264
if (rr->first) {
257-
m->prev_msr = tval;
258-
m->chunks = 0;
265+
memset(m, 0, sizeof(struct mbm_state));
266+
m->prev_bw_msr = m->prev_msr = tval;
259267
return 0;
260268
}
261269

262-
shift = 64 - MBM_CNTR_WIDTH;
263-
chunks = (tval << shift) - (m->prev_msr << shift);
264-
chunks >>= shift;
270+
chunks = mbm_overflow_count(m->prev_msr, tval);
265271
m->chunks += chunks;
266272
m->prev_msr = tval;
267273

268274
rr->val += m->chunks;
269275
return 0;
270276
}
271277

278+
/*
279+
* Supporting function to calculate the memory bandwidth
280+
* and delta bandwidth in MBps.
281+
*/
282+
static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
283+
{
284+
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3];
285+
struct mbm_state *m = &rr->d->mbm_local[rmid];
286+
u64 tval, cur_bw, chunks;
287+
288+
tval = __rmid_read(rmid, rr->evtid);
289+
if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL))
290+
return;
291+
292+
chunks = mbm_overflow_count(m->prev_bw_msr, tval);
293+
m->chunks_bw += chunks;
294+
m->chunks = m->chunks_bw;
295+
cur_bw = (chunks * r->mon_scale) >> 20;
296+
297+
if (m->delta_comp)
298+
m->delta_bw = abs(cur_bw - m->prev_bw);
299+
m->delta_comp = false;
300+
m->prev_bw = cur_bw;
301+
m->prev_bw_msr = tval;
302+
}
303+
272304
/*
273305
* This is called via IPI to read the CQM/MBM counters
274306
* on a domain.

0 commit comments

Comments
 (0)