From: Ping Li <leeonion.muyu@gmail.com>
To: james.morse@arm.com, ben.horgan@arm.com
Cc: linux-kernel@vger.kernel.org, reinette.chatre@intel.com,
fenghuay@nvidia.com, Ping Li <leeonion.muyu@gmail.com>
Subject: [PATCH v3] arm_mpam: Use an atomic counter to schedule mpam_enable_once()
Date: Tue, 15 Sep 2026 11:18:09 +0800 [thread overview]
Message-ID: <20260915031809.4073512-1-leeonion.muyu@gmail.com> (raw)
In-Reply-To: <20260908024846.2063161-1-ping.li@horizon.auto>
mpam_discovery_cpu_online() scheduled mpam_enable() after each MSC
probe, and mpam_enable() walked the whole MSC list taking each probe
lock in turn to check if all the MSCs had been probed.
Count the MSCs that have had their hardware probed with
mpam_num_msc_probed, and schedule mpam_enable_once() directly when the
count reaches mpam_num_msc, the number of MSCs the driver discovered.
MSCs that were already probed no longer cause work to be scheduled.
Suggested-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
Changes in v3:
- Rework per review feedback: instead of scheduling mpam_enable() after
each probe and walking the MSC list to check whether all MSCs have
been probed, count the probed MSCs and schedule mpam_enable_once()
directly when the last one is probed.
drivers/resctrl/mpam_devices.c | 47 +++++++++------------------------
drivers/resctrl/mpam_internal.h | 1 -
2 files changed, 12 insertions(+), 36 deletions(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 2f09f4b78bd3..c6000bc2157a 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -55,6 +55,11 @@ struct srcu_struct mpam_srcu;
*/
static atomic_t mpam_num_msc;
+/* Number of MSCs that have had their hardware probed */
+static atomic_t mpam_num_msc_probed;
+
+static void mpam_enable_once(struct work_struct *work);
+
static int mpam_cpuhp_state;
static DEFINE_MUTEX(mpam_cpuhp_state_lock);
@@ -72,7 +77,7 @@ static DEFINE_SPINLOCK(partid_max_lock);
* scheduled via this work_struct. If access to an MSC depends on a CPU that
* was not brought online at boot, this can happen surprisingly late.
*/
-static DECLARE_WORK(mpam_enable_work, &mpam_enable);
+static DECLARE_WORK(mpam_enable_work, &mpam_enable_once);
/*
* All mpam error interrupts indicate a software bug. On receipt, disable the
@@ -1854,7 +1859,6 @@ static int mpam_discovery_cpu_online(unsigned int cpu)
{
int err = 0;
struct mpam_msc *msc;
- bool new_device_probed = false;
if (mpam_is_enabled())
return 0;
@@ -1866,17 +1870,18 @@ static int mpam_discovery_cpu_online(unsigned int cpu)
continue;
mutex_lock(&msc->probe_lock);
- if (!msc->probed)
+ if (!msc->probed) {
err = mpam_msc_hw_probe(msc);
+ if (!err && atomic_add_return(1, &mpam_num_msc_probed) ==
+ atomic_read(&mpam_num_msc))
+ schedule_work(&mpam_enable_work);
+ }
mutex_unlock(&msc->probe_lock);
if (err)
break;
- new_device_probed = true;
}
- if (new_device_probed && !err)
- schedule_work(&mpam_enable_work);
if (err) {
mpam_disable_reason = "error during probing";
schedule_work(&mpam_broken_work);
@@ -2713,7 +2718,7 @@ static int mpam_allocate_config(void)
return 0;
}
-static void mpam_enable_once(void)
+static void mpam_enable_once(struct work_struct *work)
{
int err;
@@ -2867,34 +2872,6 @@ void mpam_disable(struct work_struct *ignored)
pr_err_once("MPAM disabled due to %s\n", mpam_disable_reason);
}
-/*
- * Enable mpam once all devices have been probed.
- * Scheduled by mpam_discovery_cpu_online() once all devices have been created.
- * Also scheduled when new devices are probed when new CPUs come online.
- */
-void mpam_enable(struct work_struct *work)
-{
- static atomic_t once;
- struct mpam_msc *msc;
- bool all_devices_probed = true;
-
- /* Have we probed all the hw devices? */
- guard(srcu)(&mpam_srcu);
- list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list,
- srcu_read_lock_held(&mpam_srcu)) {
- mutex_lock(&msc->probe_lock);
- if (!msc->probed)
- all_devices_probed = false;
- mutex_unlock(&msc->probe_lock);
-
- if (!all_devices_probed)
- break;
- }
-
- if (all_devices_probed && !atomic_fetch_inc(&once))
- mpam_enable_once();
-}
-
#define maybe_update_config(cfg, feature, newcfg, member, changes) do { \
if (mpam_has_feature(feature, newcfg) && \
(newcfg)->member != (cfg)->member) { \
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index 04d1a59f02af..72bf296c846e 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -453,7 +453,6 @@ extern u16 mpam_partid_max;
extern u8 mpam_pmg_max;
/* Scheduled work callback to enable mpam once all MSC have been probed */
-void mpam_enable(struct work_struct *work);
void mpam_disable(struct work_struct *work);
/* Reset all the RIS in a class under cpus_read_lock() */
--
2.34.1
next prev parent reply other threads:[~2026-09-15 3:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 13:06 [PATCH] arm_mpam: Only schedule mpam_enable work after first successful MSC probe ping.li
2026-09-08 2:48 ` [PATCH v2] " ping.li
2026-09-10 9:25 ` Ben Horgan
2026-09-17 9:19 ` Yin Li
2026-09-15 3:18 ` Ping Li [this message]
2026-09-15 9:48 ` [PATCH v3] arm_mpam: Use an atomic counter to schedule mpam_enable_once() Ben Horgan
2026-09-15 11:56 ` [PATCH v4] " Ping Li
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=20260915031809.4073512-1-leeonion.muyu@gmail.com \
--to=leeonion.muyu@gmail.com \
--cc=ben.horgan@arm.com \
--cc=fenghuay@nvidia.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=reinette.chatre@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®