From nobody Thu Nov 28 04:51:54 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73D39216A21 for ; Fri, 4 Oct 2024 18:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728065163; cv=none; b=fnhaZXHmUMX68NQ7HHxnuE5Ob8FZk/jP9/neFFnnK3py/H2jJ5FVRqGP67nsU/Z52j/o5f1RKFuaD6SBNQF3VfGDYXgXRLe2DP/wWL1k27myKDU1j0KCjn0TL/M52oJNm7XIoONfbO8szANiyjIUa8bur65VbxkQPIu4uufw4w0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728065163; c=relaxed/simple; bh=XvO7WeFNDTxZEJUYvl3F/ZtdGsVRyuTO//2pOzWfr2w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SWkltIoda9ijReWk/w9vSF/QN3jECvE0xTqnz+IyCGx75ED7WuEYPJymRMeJ/WI/jEP+v6v3KKAfd6R4v1rP3AIblVCVJ3yACFwMmpyhUUozkk6tmVE5uiTC8gDMzin5J2svUcnU17ldhuUtYy8rhuonJYWWEQI3nXjvOqQ4M/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8FC8D1063; Fri, 4 Oct 2024 11:06:30 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ED2FC3F58B; Fri, 4 Oct 2024 11:05:57 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin , Shaopeng Tan Subject: [PATCH v5 18/40] x86/resctrl: Export the is_mbm_*_enabled() helpers to asm/resctrl.h Date: Fri, 4 Oct 2024 18:03:25 +0000 Message-Id: <20241004180347.19985-19-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241004180347.19985-1-james.morse@arm.com> References: <20241004180347.19985-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The architecture specific parts of resctrl have helpers to hide accesses to the rdt_mon_features bitmap. Once the filesystem parts of resctrl are moved, these can no longer live in internal.h. Once these are exposed to the wider kernel, they should have a 'resctrl_arch_' prefix, to fit the rest of the arch<->fs interface. Move and rename the helpers that touch rdt_mon_features directly. is_mbm_event() and is_mbm_enabled() are only called from rdtgroup.c, so can be moved into that file. Signed-off-by: James Morse Tested-by: Carl Worth # arm64 Tested-by: Shaopeng Tan Reviewed-by: Shaopeng Tan --- arch/x86/include/asm/resctrl.h | 16 +++++++++++ arch/x86/kernel/cpu/resctrl/core.c | 4 +-- arch/x86/kernel/cpu/resctrl/internal.h | 27 ----------------- arch/x86/kernel/cpu/resctrl/monitor.c | 18 ++++++------ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++--------- 5 files changed, 53 insertions(+), 52 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 5622943f6354..a28a1d8a4ca8 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -44,6 +44,7 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); =20 extern bool rdt_alloc_capable; extern bool rdt_mon_capable; +extern unsigned int rdt_mon_features; =20 DECLARE_STATIC_KEY_FALSE(rdt_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); @@ -83,6 +84,21 @@ static inline void resctrl_arch_disable_mon(void) static_branch_dec_cpuslocked(&rdt_enable_key); } =20 +static inline bool resctrl_arch_is_llc_occupancy_enabled(void) +{ + return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID)); +} + +static inline bool resctrl_arch_is_mbm_total_enabled(void) +{ + return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID)); +} + +static inline bool resctrl_arch_is_mbm_local_enabled(void) +{ + return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID)); +} + /* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR * diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 830607986c06..8db946ebc4ff 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -489,13 +489,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct= rdt_hw_mon_domain *hw_dom) { size_t tsize; =20 - if (is_mbm_total_enabled()) { + if (resctrl_arch_is_mbm_total_enabled()) { tsize =3D sizeof(*hw_dom->arch_mbm_total); hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_total) return -ENOMEM; } - if (is_mbm_local_enabled()) { + if (resctrl_arch_is_mbm_local_enabled()) { tsize =3D sizeof(*hw_dom->arch_mbm_local); hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_local) { diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index a434daa6dba4..6b076216911c 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -156,7 +156,6 @@ struct rmid_read { void *arch_mon_ctx; }; =20 -extern unsigned int rdt_mon_features; extern struct list_head resctrl_schema_all; extern bool resctrl_mounted; =20 @@ -404,32 +403,6 @@ struct msr_param { u32 high; }; =20 -static inline bool is_llc_occupancy_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID)); -} - -static inline bool is_mbm_total_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID)); -} - -static inline bool is_mbm_local_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID)); -} - -static inline bool is_mbm_enabled(void) -{ - return (is_mbm_total_enabled() || is_mbm_local_enabled()); -} - -static inline bool is_mbm_event(int e) -{ - return (e >=3D QOS_L3_MBM_TOTAL_EVENT_ID && - e <=3D QOS_L3_MBM_LOCAL_EVENT_ID); -} - /** * struct rdt_hw_resource - arch private attributes of a resctrl resource * @r_resctrl: Attributes of the resource used directly by resctrl. diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index cecc96213c49..68e05bd0eb94 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -295,11 +295,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource = *r, struct rdt_mon_domain * { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); =20 - if (is_mbm_total_enabled()) + if (resctrl_arch_is_mbm_total_enabled()) memset(hw_dom->arch_mbm_total, 0, sizeof(*hw_dom->arch_mbm_total) * r->num_rmid); =20 - if (is_mbm_local_enabled()) + if (resctrl_arch_is_mbm_local_enabled()) memset(hw_dom->arch_mbm_local, 0, sizeof(*hw_dom->arch_mbm_local) * r->num_rmid); } @@ -569,7 +569,7 @@ void free_rmid(u32 closid, u32 rmid) =20 entry =3D __rmid_entry(idx); =20 - if (is_llc_occupancy_enabled()) + if (resctrl_arch_is_llc_occupancy_enabled()) add_rmid_to_limbo(entry); else list_add_tail(&entry->list, &rmid_free_lru); @@ -757,7 +757,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_mon_domain *dom_mbm) struct list_head *head; struct rdtgroup *entry; =20 - if (!is_mbm_local_enabled()) + if (!resctrl_arch_is_mbm_local_enabled()) return; =20 r_mba =3D resctrl_arch_get_resource(RDT_RESOURCE_MBA); @@ -825,7 +825,7 @@ static void mbm_update(struct rdt_resource *r, struct r= dt_mon_domain *d, * This is protected from concurrent reads from user * as both the user and we hold the global mutex. */ - if (is_mbm_total_enabled()) { + if (resctrl_arch_is_mbm_total_enabled()) { rr.evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID; rr.val =3D 0; rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); @@ -839,7 +839,7 @@ static void mbm_update(struct rdt_resource *r, struct r= dt_mon_domain *d, =20 resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); } - if (is_mbm_local_enabled()) { + if (resctrl_arch_is_mbm_local_enabled()) { rr.evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID; rr.val =3D 0; rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); @@ -1089,11 +1089,11 @@ static void l3_mon_evt_init(struct rdt_resource *r) { INIT_LIST_HEAD(&r->evt_list); =20 - if (is_llc_occupancy_enabled()) + if (resctrl_arch_is_llc_occupancy_enabled()) list_add_tail(&llc_occupancy_event.list, &r->evt_list); - if (is_mbm_total_enabled()) + if (resctrl_arch_is_mbm_total_enabled()) list_add_tail(&mbm_total_event.list, &r->evt_list); - if (is_mbm_local_enabled()) + if (resctrl_arch_is_mbm_local_enabled()) list_add_tail(&mbm_local_event.list, &r->evt_list); } =20 diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 7be1ff466559..7ed295225da7 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -108,6 +108,18 @@ void rdt_staged_configs_clear(void) } } =20 +static bool resctrl_is_mbm_enabled(void) +{ + return (resctrl_arch_is_mbm_total_enabled() || + resctrl_arch_is_mbm_local_enabled()); +} + +static bool resctrl_is_mbm_event(int e) +{ + return (e >=3D QOS_L3_MBM_TOTAL_EVENT_ID && + e <=3D QOS_L3_MBM_LOCAL_EVENT_ID); +} + /* * Trivial allocator for CLOSIDs. Since h/w only supports a small number, * we can keep a bitmap of free CLOSIDs in a single integer. @@ -155,7 +167,7 @@ static int closid_alloc(void) lockdep_assert_held(&rdtgroup_mutex); =20 if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) && - is_llc_occupancy_enabled()) { + resctrl_arch_is_llc_occupancy_enabled()) { cleanest_closid =3D resctrl_find_cleanest_closid(); if (cleanest_closid < 0) return cleanest_closid; @@ -2373,7 +2385,7 @@ static bool supports_mba_mbps(void) struct rdt_resource *rmbm =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_MBA); =20 - return (is_mbm_local_enabled() && + return (resctrl_arch_is_mbm_local_enabled() && r->alloc_capable && is_mba_linear() && r->ctrl_scope =3D=3D rmbm->mon_scope); } @@ -2740,7 +2752,7 @@ static int rdt_get_tree(struct fs_context *fc) if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable()) resctrl_mounted =3D true; =20 - if (is_mbm_enabled()) { + if (resctrl_is_mbm_enabled()) { r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); list_for_each_entry(dom, &r->mon_domains, hdr.list) mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL, @@ -3114,7 +3126,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_mon_domain *d, if (ret) return ret; =20 - if (!do_sum && is_mbm_event(mevt->evtid)) + if (!do_sum && resctrl_is_mbm_event(mevt->evtid)) mon_event_read(&rr, r, d, prgrp, &d->hdr.cpu_mask, mevt->evtid, true); } =20 @@ -4069,9 +4081,9 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d if (resctrl_mounted && resctrl_arch_mon_capable()) rmdir_mondata_subdir_allrdtgrp(r, d); =20 - if (is_mbm_enabled()) + if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); - if (is_llc_occupancy_enabled() && has_busy_rmid(d)) { + if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) { /* * When a package is going down, forcefully * decrement rmid->ebusy. There is no way to know @@ -4107,12 +4119,12 @@ static int domain_setup_mon_state(struct rdt_resour= ce *r, struct rdt_mon_domain u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize; =20 - if (is_llc_occupancy_enabled()) { + if (resctrl_arch_is_llc_occupancy_enabled()) { d->rmid_busy_llc =3D bitmap_zalloc(idx_limit, GFP_KERNEL); if (!d->rmid_busy_llc) return -ENOMEM; } - if (is_mbm_total_enabled()) { + if (resctrl_arch_is_mbm_total_enabled()) { tsize =3D sizeof(*d->mbm_total); d->mbm_total =3D kcalloc(idx_limit, tsize, GFP_KERNEL); if (!d->mbm_total) { @@ -4120,7 +4132,7 @@ static int domain_setup_mon_state(struct rdt_resource= *r, struct rdt_mon_domain return -ENOMEM; } } - if (is_mbm_local_enabled()) { + if (resctrl_arch_is_mbm_local_enabled()) { tsize =3D sizeof(*d->mbm_local); d->mbm_local =3D kcalloc(idx_limit, tsize, GFP_KERNEL); if (!d->mbm_local) { @@ -4159,13 +4171,13 @@ int resctrl_online_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d) if (err) goto out_unlock; =20 - if (is_mbm_enabled()) { + if (resctrl_is_mbm_enabled()) { INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow); mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL, RESCTRL_PICK_ANY_CPU); } =20 - if (is_llc_occupancy_enabled()) + if (resctrl_arch_is_llc_occupancy_enabled()) INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); =20 /* @@ -4220,12 +4232,12 @@ void resctrl_offline_cpu(unsigned int cpu) =20 d =3D get_mon_domain_from_cpu(cpu, l3); if (d) { - if (is_mbm_enabled() && cpu =3D=3D d->mbm_work_cpu) { + if (resctrl_is_mbm_enabled() && cpu =3D=3D d->mbm_work_cpu) { cancel_delayed_work(&d->mbm_over); mbm_setup_overflow_handler(d, 0, cpu); } - if (is_llc_occupancy_enabled() && cpu =3D=3D d->cqm_work_cpu && - has_busy_rmid(d)) { + if (resctrl_arch_is_llc_occupancy_enabled() && + cpu =3D=3D d->cqm_work_cpu && has_busy_rmid(d)) { cancel_delayed_work(&d->cqm_limbo); cqm_setup_limbo_handler(d, 0, cpu); } --=20 2.39.2