From: Nikunj Kela <quic_nkela@quicinc.com>
To: Ulf Hansson <ulf.hansson@linaro.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>, <linux-pm@vger.kernel.org>
Cc: Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com>,
Nikunj Kela <nkela@quicinc.com>,
Prasad Sodagudi <psodagud@quicinc.com>,
Maulik Shah <quic_mkshah@quicinc.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
<linux-rt-users@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/7] pmdomain: core: Enable s2idle for CPU PM domains on PREEMPT_RT
Date: Tue, 28 May 2024 12:55:58 -0700 [thread overview]
Message-ID: <52dce8d3-acfa-4f2c-92d0-c25aa59d6526@quicinc.com> (raw)
In-Reply-To: <20240527142557.321610-2-ulf.hansson@linaro.org>
On 5/27/2024 7:25 AM, Ulf Hansson wrote:
> To allow a genpd provider for a CPU PM domain to enter a domain-idle-state
> during s2idle on a PREEMPT_RT based configuration, we can't use the regular
> spinlock, as they are turned into sleepable locks on PREEMPT_RT.
>
> To address this problem, let's convert into using the raw spinlock, but
> only for genpd providers that have the GENPD_FLAG_CPU_DOMAIN bit set. In
> this way, the lock can still be acquired/released in atomic context, which
> is needed in the idle-path for PREEMPT_RT.
>
> Do note that the genpd power-on/off notifiers may also be fired during
> s2idle, but these are already prepared for PREEMPT_RT as they are based on
> the raw notifiers. However, consumers of them may need to adopt accordingly
> to work properly on PREEMPT_RT.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>
> Changes in v2:
> - None.
>
> ---
> drivers/pmdomain/core.c | 47 ++++++++++++++++++++++++++++++++++++++-
> include/linux/pm_domain.h | 5 ++++-
> 2 files changed, 50 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> index 623d15b68707..072e6bdb6ee6 100644
> --- a/drivers/pmdomain/core.c
> +++ b/drivers/pmdomain/core.c
> @@ -117,6 +117,48 @@ static const struct genpd_lock_ops genpd_spin_ops = {
> .unlock = genpd_unlock_spin,
> };
>
> +static void genpd_lock_raw_spin(struct generic_pm_domain *genpd)
> + __acquires(&genpd->raw_slock)
> +{
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&genpd->raw_slock, flags);
> + genpd->raw_lock_flags = flags;
> +}
> +
> +static void genpd_lock_nested_raw_spin(struct generic_pm_domain *genpd,
> + int depth)
> + __acquires(&genpd->raw_slock)
> +{
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave_nested(&genpd->raw_slock, flags, depth);
> + genpd->raw_lock_flags = flags;
> +}
> +
> +static int genpd_lock_interruptible_raw_spin(struct generic_pm_domain *genpd)
> + __acquires(&genpd->raw_slock)
> +{
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&genpd->raw_slock, flags);
> + genpd->raw_lock_flags = flags;
> + return 0;
> +}
> +
> +static void genpd_unlock_raw_spin(struct generic_pm_domain *genpd)
> + __releases(&genpd->raw_slock)
> +{
> + raw_spin_unlock_irqrestore(&genpd->raw_slock, genpd->raw_lock_flags);
> +}
> +
> +static const struct genpd_lock_ops genpd_raw_spin_ops = {
> + .lock = genpd_lock_raw_spin,
> + .lock_nested = genpd_lock_nested_raw_spin,
> + .lock_interruptible = genpd_lock_interruptible_raw_spin,
> + .unlock = genpd_unlock_raw_spin,
> +};
> +
> #define genpd_lock(p) p->lock_ops->lock(p)
> #define genpd_lock_nested(p, d) p->lock_ops->lock_nested(p, d)
> #define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p)
> @@ -2079,7 +2121,10 @@ static void genpd_free_data(struct generic_pm_domain *genpd)
>
> static void genpd_lock_init(struct generic_pm_domain *genpd)
> {
> - if (genpd->flags & GENPD_FLAG_IRQ_SAFE) {
> + if (genpd->flags & GENPD_FLAG_CPU_DOMAIN) {
> + raw_spin_lock_init(&genpd->raw_slock);
> + genpd->lock_ops = &genpd_raw_spin_ops;
> + } else if (genpd->flags & GENPD_FLAG_IRQ_SAFE) {
Hi Ulf, though you are targeting only CPU domains for now, I wonder if
FLAG_IRQ_SAFE will be a better choice? The description of the flag says
it is safe for atomic context which won't be the case for PREEMPT_RT?
> spin_lock_init(&genpd->slock);
> genpd->lock_ops = &genpd_spin_ops;
> } else {
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index f24546a3d3db..0d7fc47de3bc 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -194,8 +194,11 @@ struct generic_pm_domain {
> spinlock_t slock;
> unsigned long lock_flags;
> };
> + struct {
> + raw_spinlock_t raw_slock;
> + unsigned long raw_lock_flags;
> + };
> };
> -
> };
>
> static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
next prev parent reply other threads:[~2024-05-28 19:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 14:25 [PATCH v2 0/7] pmdomain/cpuidle-psci: Support s2idle/s2ram " Ulf Hansson
2024-05-27 14:25 ` [PATCH v2 1/7] pmdomain: core: Enable s2idle for CPU PM domains " Ulf Hansson
2024-05-28 19:55 ` Nikunj Kela [this message]
2024-05-30 8:15 ` Ulf Hansson
2024-05-30 14:23 ` Nikunj Kela
2024-06-03 13:58 ` Ulf Hansson
2024-06-04 17:22 ` Nikunj Kela
2024-05-27 14:25 ` [PATCH v2 2/7] pmdomain: core: Don't hold the genpd-lock when calling dev_pm_domain_set() Ulf Hansson
2024-05-27 14:25 ` [PATCH v2 3/7] pmdomain: core: Use dev_name() instead of kobject_get_path() in debugfs Ulf Hansson
2024-08-20 8:55 ` Geert Uytterhoeven
2024-08-20 8:57 ` Ulf Hansson
2024-08-30 15:50 ` Geert Uytterhoeven
2024-09-02 14:42 ` Geert Uytterhoeven
2024-09-03 10:13 ` Ulf Hansson
2024-05-27 14:25 ` [PATCH v2 4/7] cpuidle: psci-domain: Enable system-wide suspend on PREEMPT_RT Ulf Hansson
2024-05-27 14:25 ` [PATCH v2 5/7] cpuidle: psci: Drop redundant assignment of CPUIDLE_FLAG_RCU_IDLE Ulf Hansson
2024-05-27 14:25 ` [PATCH v2 6/7] cpuidle: psci: Enable the hierarchical topology for s2ram on PREEMPT_RT Ulf Hansson
2024-05-27 14:25 ` [PATCH v2 7/7] cpuidle: psci: Enable the hierarchical topology for s2idle " Ulf Hansson
2024-07-08 13:53 ` [PATCH v2 0/7] pmdomain/cpuidle-psci: Support s2idle/s2ram " Sebastian Andrzej Siewior
2024-07-09 15:31 ` Ulf Hansson
2024-07-31 8:15 ` Sebastian Andrzej Siewior
2024-07-25 10:32 ` Raghavendra Kakarla
2024-08-05 11:35 ` Ulf Hansson
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=52dce8d3-acfa-4f2c-92d0-c25aa59d6526@quicinc.com \
--to=quic_nkela@quicinc.com \
--cc=Lorenzo.Pieralisi@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=nkela@quicinc.com \
--cc=psodagud@quicinc.com \
--cc=quic_mkshah@quicinc.com \
--cc=rafael@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=ulf.hansson@linaro.org \
/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®