From: Dave Martin <Dave.Martin@arm.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: James Morse <james.morse@arm.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Reinette Chatre <reinette.chatre@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
H Peter Anvin <hpa@zytor.com>, Babu Moger <Babu.Moger@amd.com>,
shameerali.kolothum.thodi@huawei.com,
D Scott Phillips OS <scott@os.amperecomputing.com>,
carl@os.amperecomputing.com, lcherian@marvell.com,
bobo.shaobowang@huawei.com,
"Shaopeng Tan (Fujitsu)" <tan.shaopeng@fujitsu.com>,
baolin.wang@linux.alibaba.com,
Jamie Iles <quic_jiles@quicinc.com>,
Xin Hao <xhao@linux.alibaba.com>,
Peter Newman <peternewman@google.com>,
dfustini@baylibre.com, amitsinght@marvell.com,
David Hildenbrand <david@redhat.com>,
Rex Nie <rex.nie@jaguarmicro.com>
Subject: [PATCH v2 02/35] x86/resctrl: Add a helper to avoid reaching into the arch code resource list
Date: Fri, 26 Apr 2024 16:08:31 +0100 [thread overview]
Message-ID: <20240426150904.8854-2-Dave.Martin@arm.com> (raw)
In-Reply-To: <20240426150904.8854-1-Dave.Martin@arm.com>
From: James Morse <james.morse@arm.com>
Resctrl occasionally wants to know something about a specific resource,
in these cases it reaches into the arch code's rdt_resources_all[]
array.
Once the filesystem parts of resctrl are moved to /fs/, this means it
will need visibility of the architecture specific struct
rdt_hw_resource definition, and the array of all resources. All
architectures would also need a r_resctrl member in this struct.
Instead, abstract this via a helper to allow architectures to do
different things here. Move the level enum to the resctrl header and
add a helper to retrieve the struct rdt_resource by 'rid'.
resctrl_arch_get_resource() should not return NULL for any value in
the enum, it may instead return a dummy resource that is
!alloc_enabled && !mon_enabled.
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
FYI: David Hildenbrand <david@redhat.com>
* Dropped your Reviewed-by due to changes in the patch.
Are you happy for it to be reapplied?
Changes in v2:
* Backed out non-functional renaming of "r" to "l3" in rdt_get_tree(),
and unhoisted the assignment of r (as now is) back into the if ()
where it started out. There seem to be no uses of this variable
outside this if().
* [Commit message only] Typo fix:
s/resctrl_hw_resource/rdt_hw_resource/g
---
arch/x86/kernel/cpu/resctrl/core.c | 10 +++++++++-
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +-
arch/x86/kernel/cpu/resctrl/internal.h | 10 ----------
arch/x86/kernel/cpu/resctrl/monitor.c | 8 ++++----
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 ++++++------
include/linux/resctrl.h | 17 +++++++++++++++++
6 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 83e40341583e..b773b3bdebe3 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -122,6 +122,14 @@ struct rdt_hw_resource rdt_resources_all[] = {
},
};
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
+{
+ if (l >= RDT_NUM_RESOURCES)
+ return NULL;
+
+ return &rdt_resources_all[l].r_resctrl;
+}
+
/*
* cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs
* as they do not have CPUID enumeration support for Cache allocation.
@@ -169,7 +177,7 @@ static inline void cache_alloc_hsw_probe(void)
bool is_mba_sc(struct rdt_resource *r)
{
if (!r)
- return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.mba_sc;
+ r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
/*
* The software controller support is only applicable to MBA resource.
diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 7997b47743a2..788ac0395645 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -599,7 +599,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
domid = md.u.domid;
evtid = md.u.evtid;
- r = &rdt_resources_all[resid].r_resctrl;
+ r = resctrl_arch_get_resource(resid);
d = rdt_find_domain(r, domid, NULL);
if (IS_ERR_OR_NULL(d)) {
ret = -ENOENT;
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index c99f26ebe7a6..65990def6c79 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -466,16 +466,6 @@ extern struct rdt_hw_resource rdt_resources_all[];
extern struct rdtgroup rdtgroup_default;
extern struct dentry *debugfs_resctrl;
-enum resctrl_res_level {
- RDT_RESOURCE_L3,
- RDT_RESOURCE_L2,
- RDT_RESOURCE_MBA,
- RDT_RESOURCE_SMBA,
-
- /* Must be the last */
- RDT_NUM_RESOURCES,
-};
-
static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
{
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(res);
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index c34a35ec0f03..06565153ceb2 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -321,7 +321,7 @@ static void limbo_release_entry(struct rmid_entry *entry)
*/
void __check_limbo(struct rdt_domain *d, bool force_free)
{
- struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
struct rmid_entry *entry;
u32 idx, cur_idx = 1;
@@ -467,7 +467,7 @@ int alloc_rmid(u32 closid)
static void add_rmid_to_limbo(struct rmid_entry *entry)
{
- struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdt_domain *d;
u32 idx;
@@ -669,7 +669,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
if (!is_mbm_local_enabled())
return;
- r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+ r_mba = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
closid = rgrp->closid;
rmid = rgrp->mon.rmid;
@@ -839,7 +839,7 @@ void mbm_handle_overflow(struct work_struct *work)
if (!resctrl_mounted || !resctrl_arch_mon_capable())
goto out_unlock;
- r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+ r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
d = container_of(work, struct rdt_domain, mbm_over.work);
list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 1767c1affa60..47234562a1dd 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2253,7 +2253,7 @@ static void l2_qos_cfg_update(void *arg)
static inline bool is_mba_linear(void)
{
- return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.delay_linear;
+ return resctrl_arch_get_resource(RDT_RESOURCE_MBA)->membw.delay_linear;
}
static int set_cache_qos_cfg(int level, bool enable)
@@ -2341,7 +2341,7 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
*/
static bool supports_mba_mbps(void)
{
- struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
return (is_mbm_local_enabled() &&
r->alloc_capable && is_mba_linear());
@@ -2353,7 +2353,7 @@ static bool supports_mba_mbps(void)
*/
static int set_mba_sc(bool mba_sc)
{
- struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
u32 num_closid = resctrl_arch_get_num_closid(r);
struct rdt_domain *d;
int i;
@@ -2701,7 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc)
resctrl_mounted = true;
if (is_mbm_enabled()) {
- r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+ r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
list_for_each_entry(dom, &r->domains, list)
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
RESCTRL_PICK_ANY_CPU);
@@ -3878,7 +3878,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
seq_puts(seq, ",cdpl2");
- if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
+ if (is_mba_sc(resctrl_arch_get_resource(RDT_RESOURCE_MBA)))
seq_puts(seq, ",mba_MBps");
if (resctrl_debug)
@@ -4068,7 +4068,7 @@ static void clear_childcpus(struct rdtgroup *r, unsigned int cpu)
void resctrl_offline_cpu(unsigned int cpu)
{
- struct rdt_resource *l3 = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+ struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdtgroup *rdtgrp;
struct rdt_domain *d;
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index a365f67131ec..168cc9510069 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -36,6 +36,16 @@ enum resctrl_conf_type {
CDP_DATA,
};
+enum resctrl_res_level {
+ RDT_RESOURCE_L3,
+ RDT_RESOURCE_L2,
+ RDT_RESOURCE_MBA,
+ RDT_RESOURCE_SMBA,
+
+ /* Must be the last */
+ RDT_NUM_RESOURCES,
+};
+
#define CDP_NUM_TYPES (CDP_DATA + 1)
/*
@@ -190,6 +200,13 @@ struct rdt_resource {
bool cdp_capable;
};
+/*
+ * Get the resource that exists at this level. If the level is not supported
+ * a dummy/not-capable resource can be returned. Levels >= RDT_NUM_RESOURCES
+ * will return NULL.
+ */
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
+
/**
* struct resctrl_schema - configuration abilities of a resource presented to
* user-space
--
2.34.1
next prev parent reply other threads:[~2024-04-26 15:09 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 15:05 [PATCH v2 00/35] x86/resctrl: Move the resctrl filesystem code to /fs/resctrl Dave Martin
2024-04-26 15:08 ` [PATCH v2 01/35] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors Dave Martin
2024-04-26 15:08 ` Dave Martin [this message]
2024-04-26 15:08 ` [PATCH v2 03/35] x86/resctrl: Move ctrlval string parsing policy away from the arch code Dave Martin
2024-04-26 15:08 ` [PATCH v2 04/35] x86/resctrl: Add helper for setting CPU default properties Dave Martin
2024-04-26 15:08 ` [PATCH v2 05/35] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid() Dave Martin
2024-04-26 15:08 ` [PATCH v2 06/35] x86/resctrl: Export resctrl fs's init function Dave Martin
2024-05-23 0:48 ` Shaopeng Tan (Fujitsu)
2024-04-26 15:08 ` [PATCH v2 07/35] x86/resctrl: Wrap resctrl_arch_find_domain() around rdt_find_domain() Dave Martin
2024-04-26 15:08 ` [PATCH v2 08/35] x86/resctrl: Move resctrl types to a separate header Dave Martin
2024-04-26 15:08 ` [PATCH v2 09/35] x86/resctrl: Add a resctrl helper to reset all the resources Dave Martin
2024-04-26 15:08 ` [PATCH v2 10/35] x86/resctrl: Move monitor init work to a resctrl init call Dave Martin
2024-04-26 15:08 ` [PATCH v2 11/35] x86/resctrl: Move monitor exit work to a resctrl exit call Dave Martin
2024-04-26 15:08 ` [PATCH v2 12/35] x86/resctrl: Move max_{name,data}_width into resctrl code Dave Martin
2024-04-26 15:08 ` [PATCH v2 13/35] x86/resctrl: Stop using the for_each_*_rdt_resource() walkers Dave Martin
2024-04-26 15:08 ` [PATCH v2 14/35] x86/resctrl: Export the is_mbm_*_enabled() helpers to asm/resctrl.h Dave Martin
2024-04-26 15:08 ` [PATCH v2 15/35] x86/resctrl: Add resctrl_arch_is_evt_configurable() to abstract BMEC Dave Martin
2024-04-26 15:08 ` [PATCH v2 16/35] x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers Dave Martin
2024-04-26 15:08 ` [PATCH v2 17/35] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource Dave Martin
2024-06-14 13:57 ` James Morse
2024-04-26 15:08 ` [PATCH v2 18/35] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error Dave Martin
2024-04-26 15:08 ` [PATCH v2 19/35] x86/resctrl: Add resctrl_arch_ prefix to pseudo lock functions Dave Martin
2024-04-26 15:08 ` [PATCH v2 20/35] x86/resctrl: Allow an architecture to disable pseudo lock Dave Martin
2024-04-26 15:08 ` [PATCH v2 21/35] x86/resctrl: Make prefetch_disable_bits belong to the arch code Dave Martin
2024-04-26 15:08 ` [PATCH v2 22/35] x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr Dave Martin
2024-06-14 13:58 ` James Morse
2024-04-26 15:08 ` [PATCH v2 23/35] x86/resctrl: Move thread_throttle_mode_init() to be managed by resctrl Dave Martin
2024-04-26 15:08 ` [PATCH v2 24/35] x86/resctrl: Move get_config_index() to a header Dave Martin
2024-04-26 15:08 ` [PATCH v2 25/35] x86/resctrl: Claim get_domain_from_cpu() for resctrl Dave Martin
2024-04-26 15:08 ` [PATCH v2 26/35] x86/resctrl: Describe resctrl's bitmap size assumptions Dave Martin
2024-04-26 15:08 ` [PATCH v2 27/35] x86/resctrl: Rename resctrl_sched_in() to begin with "resctrl_arch_" Dave Martin
2024-04-26 15:08 ` [PATCH v2 28/35] x86/resctrl: Drop __init/__exit on assorted symbols Dave Martin
2024-04-26 15:08 ` [PATCH v2 29/35] fs/resctrl: Add boiler plate for external resctrl code Dave Martin
2024-06-14 13:59 ` James Morse
2024-04-26 15:08 ` [PATCH v2 30/35] x86/resctrl: Squelch whitespace anomalies in resctrl core code Dave Martin
2024-04-26 15:09 ` [PATCH v2 31/35] x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context() Dave Martin
2024-04-26 15:09 ` [PATCH v2 32/35] x86/resctrl: Relax some asm #includes Dave Martin
2024-04-26 15:09 ` [PATCH v2 33/35] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl Dave Martin
2024-04-26 15:09 ` [PATCH v2 34/35] x86/resctrl: Move the resctrl filesystem code to /fs/resctrl Dave Martin
2024-04-26 15:09 ` [PATCH v2 35/35] [SQUASHME] " Dave Martin
2024-04-29 23:34 ` [PATCH v2 00/35] " Peter Newman
2024-04-30 16:29 ` Dave Martin
2024-05-08 15:41 ` Reinette Chatre
2024-05-14 15:17 ` Dave Martin
2024-05-14 15:56 ` Reinette Chatre
2024-05-23 15:01 ` Dave Martin
2024-05-23 15:07 ` David Hildenbrand
2024-05-23 15:18 ` Dave Martin
2024-05-23 0:39 ` Shaopeng Tan (Fujitsu)
2024-06-14 13:59 ` James Morse
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=20240426150904.8854-2-Dave.Martin@arm.com \
--to=dave.martin@arm.com \
--cc=Babu.Moger@amd.com \
--cc=amitsinght@marvell.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=bobo.shaobowang@huawei.com \
--cc=bp@alien8.de \
--cc=carl@os.amperecomputing.com \
--cc=david@redhat.com \
--cc=dfustini@baylibre.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=james.morse@arm.com \
--cc=lcherian@marvell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peternewman@google.com \
--cc=quic_jiles@quicinc.com \
--cc=reinette.chatre@intel.com \
--cc=rex.nie@jaguarmicro.com \
--cc=scott@os.amperecomputing.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=tan.shaopeng@fujitsu.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xhao@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox