Skip to content

Commit 48dbe31

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Add per-rmid arch private storage for overflow and chunks
A renamed __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. For bandwidth counters the resctrl filesystem uses this to calculate the number of bytes ever seen. MPAM's scaling of counters can be changed at runtime, reducing the resolution but increasing the range. When this is changed the prev_msr values need to be converted by the architecture code. Add an array for per-rmid private storage. The prev_msr and chunks values will move here to allow resctrl_arch_rmid_read() to always return the number of bytes read by this counter without assistance from the filesystem. The values are moved in later patches when the overflow and correction calls are moved into __rmid_read(). 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 3044257 commit 48dbe31

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
413413

414414
static void domain_free(struct rdt_hw_domain *hw_dom)
415415
{
416+
kfree(hw_dom->arch_mbm_total);
417+
kfree(hw_dom->arch_mbm_local);
416418
kfree(hw_dom->ctrl_val);
417419
kfree(hw_dom);
418420
}
@@ -438,6 +440,34 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
438440
return 0;
439441
}
440442

443+
/**
444+
* arch_domain_mbm_alloc() - Allocate arch private storage for the MBM counters
445+
* @num_rmid: The size of the MBM counter array
446+
* @hw_dom: The domain that owns the allocated arrays
447+
*/
448+
static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)
449+
{
450+
size_t tsize;
451+
452+
if (is_mbm_total_enabled()) {
453+
tsize = sizeof(*hw_dom->arch_mbm_total);
454+
hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
455+
if (!hw_dom->arch_mbm_total)
456+
return -ENOMEM;
457+
}
458+
if (is_mbm_local_enabled()) {
459+
tsize = sizeof(*hw_dom->arch_mbm_local);
460+
hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
461+
if (!hw_dom->arch_mbm_local) {
462+
kfree(hw_dom->arch_mbm_total);
463+
hw_dom->arch_mbm_total = NULL;
464+
return -ENOMEM;
465+
}
466+
}
467+
468+
return 0;
469+
}
470+
441471
/*
442472
* domain_add_cpu - Add a cpu to a resource's domain list.
443473
*
@@ -487,6 +517,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
487517
return;
488518
}
489519

520+
if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) {
521+
domain_free(hw_dom);
522+
return;
523+
}
524+
490525
list_add_tail(&d->list, add_pos);
491526

492527
err = resctrl_online_domain(r, d);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,31 @@ struct mbm_state {
303303
bool delta_comp;
304304
};
305305

306+
/**
307+
* struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s
308+
* return value.
309+
* @prev_msr: Value of IA32_QM_CTR last time it was read for the RMID used to
310+
* find this struct.
311+
*/
312+
struct arch_mbm_state {
313+
u64 prev_msr;
314+
};
315+
306316
/**
307317
* struct rdt_hw_domain - Arch private attributes of a set of CPUs that share
308318
* a resource
309319
* @d_resctrl: Properties exposed to the resctrl file system
310320
* @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID)
321+
* @arch_mbm_total: arch private state for MBM total bandwidth
322+
* @arch_mbm_local: arch private state for MBM local bandwidth
311323
*
312324
* Members of this structure are accessed via helpers that provide abstraction.
313325
*/
314326
struct rdt_hw_domain {
315327
struct rdt_domain d_resctrl;
316328
u32 *ctrl_val;
329+
struct arch_mbm_state *arch_mbm_total;
330+
struct arch_mbm_state *arch_mbm_local;
317331
};
318332

319333
static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r)

0 commit comments

Comments
 (0)