Skip to content

Commit 2c272fa

Browse files
aeglbp3tk0v
authored andcommitted
x86/resctrl: Compute memory bandwidth for all supported events
Switching between local and total memory bandwidth events as the input to the mba_sc feedback loop would be cumbersome and take effect slowly in the current implementation as the bandwidth is only known after two consecutive readings of the same event. Compute the bandwidth for all supported events. This doesn't add significant overhead and will make changing which event is used simple. Suggested-by: Reinette Chatre <[email protected]> Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Tested-by: Babu Moger <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 481d363 commit 2c272fa

File tree

1 file changed

+33
-39
lines changed

1 file changed

+33
-39
lines changed

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

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,12 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
663663
*/
664664
static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)
665665
{
666-
u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid);
667-
struct mbm_state *m = &rr->d->mbm_local[idx];
668666
u64 cur_bw, bytes, cur_bytes;
667+
struct mbm_state *m;
668+
669+
m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
670+
if (WARN_ON_ONCE(!m))
671+
return;
669672

670673
cur_bytes = rr->val;
671674
bytes = cur_bytes - m->prev_bw_bytes;
@@ -815,54 +818,45 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
815818
resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val);
816819
}
817820

818-
static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
819-
u32 closid, u32 rmid)
821+
static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *d,
822+
u32 closid, u32 rmid, enum resctrl_event_id evtid)
820823
{
821824
struct rmid_read rr = {0};
822825

823826
rr.r = r;
824827
rr.d = d;
828+
rr.evtid = evtid;
829+
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
830+
if (IS_ERR(rr.arch_mon_ctx)) {
831+
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
832+
PTR_ERR(rr.arch_mon_ctx));
833+
return;
834+
}
835+
836+
__mon_event_count(closid, rmid, &rr);
825837

826838
/*
827-
* This is protected from concurrent reads from user
828-
* as both the user and we hold the global mutex.
839+
* If the software controller is enabled, compute the
840+
* bandwidth for this event id.
829841
*/
830-
if (is_mbm_total_enabled()) {
831-
rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID;
832-
rr.val = 0;
833-
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
834-
if (IS_ERR(rr.arch_mon_ctx)) {
835-
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
836-
PTR_ERR(rr.arch_mon_ctx));
837-
return;
838-
}
842+
if (is_mba_sc(NULL))
843+
mbm_bw_count(closid, rmid, &rr);
839844

840-
__mon_event_count(closid, rmid, &rr);
841-
842-
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
843-
}
844-
if (is_mbm_local_enabled()) {
845-
rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID;
846-
rr.val = 0;
847-
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
848-
if (IS_ERR(rr.arch_mon_ctx)) {
849-
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
850-
PTR_ERR(rr.arch_mon_ctx));
851-
return;
852-
}
853-
854-
__mon_event_count(closid, rmid, &rr);
845+
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
846+
}
855847

856-
/*
857-
* Call the MBA software controller only for the
858-
* control groups and when user has enabled
859-
* the software controller explicitly.
860-
*/
861-
if (is_mba_sc(NULL))
862-
mbm_bw_count(closid, rmid, &rr);
848+
static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
849+
u32 closid, u32 rmid)
850+
{
851+
/*
852+
* This is protected from concurrent reads from user as both
853+
* the user and overflow handler hold the global mutex.
854+
*/
855+
if (is_mbm_total_enabled())
856+
mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID);
863857

864-
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
865-
}
858+
if (is_mbm_local_enabled())
859+
mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID);
866860
}
867861

868862
/*

0 commit comments

Comments
 (0)