Skip to content

Commit 159f36c

Browse files
babumogerbp3tk0v
authored andcommitted
fs/resctrl: Support counter read/reset with mbm_event assignment mode
When "mbm_event" counter assignment mode is enabled, the architecture requires a counter ID to read the event data. Introduce an is_mbm_cntr field in struct rmid_read to indicate whether counter assignment mode is in use. Update the logic to call resctrl_arch_cntr_read() and resctrl_arch_reset_cntr() when the assignment mode is active. Report 'Unassigned' in case the user attempts to read an event without assigning a hardware counter. Suggested-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Babu Moger <babu.moger@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com
1 parent 2a65b72 commit 159f36c

4 files changed

Lines changed: 62 additions & 16 deletions

File tree

Documentation/filesystems/resctrl.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ When monitoring is enabled all MON groups will also contain:
434434
for the L3 cache they occupy). These are named "mon_sub_L3_YY"
435435
where "YY" is the node number.
436436

437+
When the 'mbm_event' counter assignment mode is enabled, reading
438+
an MBM event of a MON group returns 'Unassigned' if no hardware
439+
counter is assigned to it. For CTRL_MON groups, 'Unassigned' is
440+
returned if the MBM event does not have an assigned counter in the
441+
CTRL_MON group nor in any of its associated MON groups.
442+
437443
"mon_hw_id":
438444
Available only with debug option. The identifier used by hardware
439445
for the monitor group. On x86 this is the RMID.

fs/resctrl/ctrlmondata.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,15 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
563563
rr->r = r;
564564
rr->d = d;
565565
rr->first = first;
566-
rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
567-
if (IS_ERR(rr->arch_mon_ctx)) {
568-
rr->err = -EINVAL;
569-
return;
566+
if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
567+
resctrl_is_mbm_event(evtid)) {
568+
rr->is_mbm_cntr = true;
569+
} else {
570+
rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
571+
if (IS_ERR(rr->arch_mon_ctx)) {
572+
rr->err = -EINVAL;
573+
return;
574+
}
570575
}
571576

572577
cpu = cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU);
@@ -582,7 +587,8 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
582587
else
583588
smp_call_on_cpu(cpu, smp_mon_event_count, rr, false);
584589

585-
resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
590+
if (rr->arch_mon_ctx)
591+
resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
586592
}
587593

588594
int rdtgroup_mondata_show(struct seq_file *m, void *arg)
@@ -653,10 +659,16 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
653659

654660
checkresult:
655661

662+
/*
663+
* -ENOENT is a special case, set only when "mbm_event" counter assignment
664+
* mode is enabled and no counter has been assigned.
665+
*/
656666
if (rr.err == -EIO)
657667
seq_puts(m, "Error\n");
658668
else if (rr.err == -EINVAL)
659669
seq_puts(m, "Unavailable\n");
670+
else if (rr.err == -ENOENT)
671+
seq_puts(m, "Unassigned\n");
660672
else
661673
seq_printf(m, "%llu\n", rr.val);
662674

fs/resctrl/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ struct mon_data {
111111
* @evtid: Which monitor event to read.
112112
* @first: Initialize MBM counter when true.
113113
* @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing domains.
114+
* @is_mbm_cntr: true if "mbm_event" counter assignment mode is enabled and it
115+
* is an MBM event.
114116
* @err: Error encountered when reading counter.
115117
* @val: Returned value of event counter. If @rgrp is a parent resource group,
116118
* @val includes the sum of event counts from its child resource groups.
@@ -125,6 +127,7 @@ struct rmid_read {
125127
enum resctrl_event_id evtid;
126128
bool first;
127129
struct cacheinfo *ci;
130+
bool is_mbm_cntr;
128131
int err;
129132
u64 val;
130133
void *arch_mon_ctx;

fs/resctrl/monitor.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,24 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
419419
u32 closid = rdtgrp->closid;
420420
u32 rmid = rdtgrp->mon.rmid;
421421
struct rdt_mon_domain *d;
422+
int cntr_id = -ENOENT;
422423
struct mbm_state *m;
423424
int err, ret;
424425
u64 tval = 0;
425426

427+
if (rr->is_mbm_cntr) {
428+
cntr_id = mbm_cntr_get(rr->r, rr->d, rdtgrp, rr->evtid);
429+
if (cntr_id < 0) {
430+
rr->err = -ENOENT;
431+
return -EINVAL;
432+
}
433+
}
434+
426435
if (rr->first) {
427-
resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
436+
if (rr->is_mbm_cntr)
437+
resctrl_arch_reset_cntr(rr->r, rr->d, closid, rmid, cntr_id, rr->evtid);
438+
else
439+
resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid);
428440
m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
429441
if (m)
430442
memset(m, 0, sizeof(struct mbm_state));
@@ -435,8 +447,12 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
435447
/* Reading a single domain, must be on a CPU in that domain. */
436448
if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask))
437449
return -EINVAL;
438-
rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid,
439-
rr->evtid, &tval, rr->arch_mon_ctx);
450+
if (rr->is_mbm_cntr)
451+
rr->err = resctrl_arch_cntr_read(rr->r, rr->d, closid, rmid, cntr_id,
452+
rr->evtid, &tval);
453+
else
454+
rr->err = resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid,
455+
rr->evtid, &tval, rr->arch_mon_ctx);
440456
if (rr->err)
441457
return rr->err;
442458

@@ -460,8 +476,12 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
460476
list_for_each_entry(d, &rr->r->mon_domains, hdr.list) {
461477
if (d->ci_id != rr->ci->id)
462478
continue;
463-
err = resctrl_arch_rmid_read(rr->r, d, closid, rmid,
464-
rr->evtid, &tval, rr->arch_mon_ctx);
479+
if (rr->is_mbm_cntr)
480+
err = resctrl_arch_cntr_read(rr->r, d, closid, rmid, cntr_id,
481+
rr->evtid, &tval);
482+
else
483+
err = resctrl_arch_rmid_read(rr->r, d, closid, rmid,
484+
rr->evtid, &tval, rr->arch_mon_ctx);
465485
if (!err) {
466486
rr->val += tval;
467487
ret = 0;
@@ -668,11 +688,15 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
668688
rr.r = r;
669689
rr.d = d;
670690
rr.evtid = evtid;
671-
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
672-
if (IS_ERR(rr.arch_mon_ctx)) {
673-
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
674-
PTR_ERR(rr.arch_mon_ctx));
675-
return;
691+
if (resctrl_arch_mbm_cntr_assign_enabled(r)) {
692+
rr.is_mbm_cntr = true;
693+
} else {
694+
rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
695+
if (IS_ERR(rr.arch_mon_ctx)) {
696+
pr_warn_ratelimited("Failed to allocate monitor context: %ld",
697+
PTR_ERR(rr.arch_mon_ctx));
698+
return;
699+
}
676700
}
677701

678702
__mon_event_count(rdtgrp, &rr);
@@ -684,7 +708,8 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *
684708
if (is_mba_sc(NULL))
685709
mbm_bw_count(rdtgrp, &rr);
686710

687-
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
711+
if (rr.arch_mon_ctx)
712+
resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
688713
}
689714

690715
static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,

0 commit comments

Comments
 (0)