From: Jonathan Perry <yonch@yonch.com>
To: Tony Luck <tony.luck@intel.com>,
Reinette Chatre <reinette.chatre@intel.com>,
linux-kernel@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
Jonathan Corbet <corbet@lwn.net>,
James Morse <james.morse@arm.com>,
Roman Storozhenko <romeusmeister@gmail.com>,
Jonathan Perry <yonch@yonch.com>
Subject: [PATCH 2/8] resctrl/mon: Split RMID read init from execution
Date: Thu, 16 Oct 2025 09:46:50 -0500 [thread overview]
Message-ID: <20251016144656.74928-3-yonch@yonch.com> (raw)
In-Reply-To: <20251016144656.74928-1-yonch@yonch.com>
Introduce rmid_read_init() to fill struct rmid_read (resource, domain,
rdtgroup, event id, flags, ci). Change mon_event_read() to accept a
prepared rmid_read and a CPU mask.
Update callers to use rmid_read_init() + mon_event_read().
This prepares reuse from contexts that pre-select the CPU (e.g. the
perf PMU) without duplicating initialization logic.
No functional change intended.
Signed-off-by: Jonathan Perry <yonch@yonch.com>
---
fs/resctrl/ctrlmondata.c | 40 ++++++++++++++++++++++------------------
fs/resctrl/internal.h | 5 +++--
fs/resctrl/rdtgroup.c | 6 ++++--
3 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index 0d0ef54fc4de..82f8ad2b3053 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -546,28 +546,31 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
return NULL;
}
-void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
+void rmid_read_init(struct rmid_read *rr, struct rdt_resource *r,
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
- cpumask_t *cpumask, int evtid, int first)
+ int evtid, int first, struct cacheinfo *ci)
{
- int cpu;
-
- /* When picking a CPU from cpu_mask, ensure it can't race with cpuhp */
- lockdep_assert_cpus_held();
-
- /*
- * Setup the parameters to pass to mon_event_count() to read the data.
- */
+ memset(rr, 0, sizeof(*rr));
rr->rgrp = rdtgrp;
rr->evtid = evtid;
rr->r = r;
rr->d = d;
rr->first = first;
+ rr->ci = ci;
if (resctrl_arch_mbm_cntr_assign_enabled(r) &&
- resctrl_is_mbm_event(evtid)) {
+ resctrl_is_mbm_event(evtid))
rr->is_mbm_cntr = true;
- } else {
- rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, evtid);
+}
+
+void mon_event_read(struct rmid_read *rr, cpumask_t *cpumask)
+{
+ int cpu;
+
+ /* When picking a CPU from cpu_mask, ensure it can't race with cpuhp */
+ lockdep_assert_cpus_held();
+
+ if (!rr->is_mbm_cntr) {
+ rr->arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr->r, rr->evtid);
if (IS_ERR(rr->arch_mon_ctx)) {
rr->err = -EINVAL;
return;
@@ -588,7 +591,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
smp_call_on_cpu(cpu, smp_mon_event_count, rr, false);
if (rr->arch_mon_ctx)
- resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
+ resctrl_arch_mon_ctx_free(rr->r, rr->evtid, rr->arch_mon_ctx);
}
int rdtgroup_mondata_show(struct seq_file *m, void *arg)
@@ -635,9 +638,9 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
ci = get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE);
if (!ci)
continue;
- rr.ci = ci;
- mon_event_read(&rr, r, NULL, rdtgrp,
- &ci->shared_cpu_map, evtid, false);
+ rmid_read_init(&rr, r, NULL, rdtgrp,
+ evtid, false, ci);
+ mon_event_read(&rr, &ci->shared_cpu_map);
goto checkresult;
}
}
@@ -654,7 +657,8 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
goto out;
}
d = container_of(hdr, struct rdt_mon_domain, hdr);
- mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false);
+ rmid_read_init(&rr, r, d, rdtgrp, evtid, false, NULL);
+ mon_event_read(&rr, &d->hdr.cpu_mask);
}
checkresult:
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index 63fb4d6c21a7..dcc0b7bea3ac 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -363,9 +363,10 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg);
int rdtgroup_mondata_open(struct kernfs_open_file *of);
void rdtgroup_mondata_release(struct kernfs_open_file *of);
-void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
+void rmid_read_init(struct rmid_read *rr, struct rdt_resource *r,
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
- cpumask_t *cpumask, int evtid, int first);
+ int evtid, int first, struct cacheinfo *ci);
+void mon_event_read(struct rmid_read *rr, cpumask_t *cpumask);
int resctrl_mon_resource_init(void);
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 17b61dcfad07..34337abe5345 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -3235,8 +3235,10 @@ static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain *d,
if (ret)
return ret;
- if (!do_sum && resctrl_is_mbm_event(mevt->evtid))
- mon_event_read(&rr, r, d, prgrp, &d->hdr.cpu_mask, mevt->evtid, true);
+ if (!do_sum && resctrl_is_mbm_event(mevt->evtid)) {
+ rmid_read_init(&rr, r, d, prgrp, mevt->evtid, true, NULL);
+ mon_event_read(&rr, &d->hdr.cpu_mask);
+ }
}
return 0;
next prev parent reply other threads:[~2025-10-16 14:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 14:46 [PATCH 0/8] resctrl: Add perf PMU for resctrl monitoring Jonathan Perry
2025-10-16 14:46 ` [PATCH 1/8] resctrl: Pin rdtgroup for mon_data file lifetime Jonathan Perry
2025-10-16 14:46 ` Jonathan Perry [this message]
2025-10-16 14:46 ` [PATCH 3/8] resctrl/mon: Select cpumask before invoking mon_event_read() Jonathan Perry
2025-10-16 14:46 ` [PATCH 4/8] resctrl/mon: Create mon_event_setup_read() helper Jonathan Perry
2025-10-16 14:46 ` [PATCH 5/8] resctrl: Propagate CPU mask validation error via rr->err Jonathan Perry
2025-10-16 14:46 ` [PATCH 6/8] resctrl/pmu: Introduce skeleton PMU and selftests Jonathan Perry
2025-10-16 14:46 ` [PATCH 7/8] resctrl/pmu: Use mon_event_setup_read() and validate CPU Jonathan Perry
2025-10-16 14:46 ` [PATCH 8/8] resctrl/pmu: Implement .read via direct RMID read; add LLC selftest Jonathan Perry
2025-10-16 21:25 ` [PATCH 0/8] resctrl: Add perf PMU for resctrl monitoring Luck, Tony
2025-10-16 21:51 ` Luck, Tony
2025-10-17 18:17 ` Jonathan Perry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251016144656.74928-3-yonch@yonch.com \
--to=yonch@yonch.com \
--cc=corbet@lwn.net \
--cc=james.morse@arm.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=romeusmeister@gmail.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.