From: Krzysztof Kozlowski <krzk@kernel.org>
To: "Peter Griffin" <peter.griffin@linaro.org>,
"André Draszik" <andre.draszik@linaro.org>,
"Tudor Ambarus" <tudor.ambarus@linaro.org>,
"Alim Akhtar" <alim.akhtar@samsung.com>
Cc: William Mcvicker <willmcvicker@google.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@android.com, sudeep.holla@arm.com
Subject: Re: [PATCH v6] soc: samsung: exynos-pmu: Enable CPU Idle for gs101
Date: Sat, 12 Jul 2025 19:42:46 +0200 [thread overview]
Message-ID: <5597644b-267d-40d0-aa33-a8a665cebd70@kernel.org> (raw)
In-Reply-To: <20250711-gs101-cpuidle-v6-1-503ec55fc2f9@linaro.org>
On 11/07/2025 15:50, Peter Griffin wrote:
>
> #include <linux/soc/samsung/exynos-regs-pmu.h>
> @@ -35,6 +37,14 @@ struct exynos_pmu_context {
> const struct exynos_pmu_data *pmu_data;
> struct regmap *pmureg;
> struct regmap *pmuintrgen;
> + /*
> + * Serialization lock for CPU hot plug and cpuidle ACPM hint
> + * programming. Also protects the in_hotplug flag.
> + */
> + raw_spinlock_t cpupm_lock;
> + bool *in_hotplug;
This should be bitmap - more obvious code.
> + atomic_t sys_suspended;
> + atomic_t sys_rebooting;
> };
>
> void __iomem *pmu_base_addr;
> @@ -221,6 +231,15 @@ static const struct regmap_config regmap_smccfg = {
> .reg_read = tensor_sec_reg_read,
> .reg_write = tensor_sec_reg_write,
> .reg_update_bits = tensor_sec_update_bits,
> + .use_raw_spinlock = true,
> +};
> +
> +static const struct regmap_config regmap_pmu_intr = {
> + .name = "pmu_intr_gen",
> + .reg_bits = 32,
> + .reg_stride = 4,
> + .val_bits = 32,
> + .use_raw_spinlock = true,
> };
>
> static const struct exynos_pmu_data gs101_pmu_data = {
> @@ -330,13 +349,19 @@ struct regmap *exynos_get_pmu_regmap_by_phandle(struct device_node *np,
> EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap_by_phandle);
>
...
> +/* Called from CPU PM notifier (CPUIdle code path) with IRQs disabled */
> +static int gs101_cpu_pmu_offline(void)
> +{
> + int cpu;
> +
> + raw_spin_lock(&pmu_context->cpupm_lock);
> + cpu = smp_processor_id();
> +
> + if (pmu_context->in_hotplug[cpu]) {
> + raw_spin_unlock(&pmu_context->cpupm_lock);
> + return NOTIFY_BAD;
> + }
> +
> + __gs101_cpu_pmu_offline(cpu);
> + raw_spin_unlock(&pmu_context->cpupm_lock);
> +
> + return NOTIFY_OK;
> +}
> +
> +/* Called from CPU hot plug callback with IRQs enabled */
> +static int gs101_cpuhp_pmu_offline(unsigned int cpu)
> +{
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&pmu_context->cpupm_lock, flags);
> + /*
> + * Mark this CPU as entering hotplug. So as not to confuse
> + * ACPM the CPU entering hotplug should not enter C2 idle state.
> + */
> + pmu_context->in_hotplug[cpu] = true;
> + __gs101_cpu_pmu_offline(cpu);
> +
> + raw_spin_unlock_irqrestore(&pmu_context->cpupm_lock, flags);
> +
> + return 0;
> +}
> +
> +static int gs101_cpu_pm_notify_callback(struct notifier_block *self,
> + unsigned long action, void *v)
> +{
> + switch (action) {
> + case CPU_PM_ENTER:
> + /*
> + * Ignore CPU_PM_ENTER event in reboot or
> + * suspend sequence.
> + */
> +
> + if (atomic_read(&pmu_context->sys_suspended) ||
> + atomic_read(&pmu_context->sys_rebooting))
I don't get exactly why you need here atomics. You don't have here
barriers, so ordering is not kept (non-RMW atomics are unordered), so
maybe ordering was not the problem to be solved here. But then you don't
use these at all as RMW and this is even explicitly described in atomic doc!
"Therefore, if you find yourself only using the Non-RMW operations of
atomic_t, you do not in fact need atomic_t at all and are doing it wrong."
And it is right. READ/WRITE_ONCE gives you the same.
The question is whether you need ordering or barriers in general
(atomics don't give you these) - you have here control dependency
if-else, however it is immediately followed with gs101_cpu_pmu_offline()
which will use spin-lock (so memory barrier).
Basically you should have here comment explaining why there is no
barrier - you rely on barrier from spin lock in next calls.
And if my reasoning is correct, then you should use just READ/WRITE_ONCE.
> + return NOTIFY_OK;
> +
> + return gs101_cpu_pmu_offline();
> +
> + case CPU_PM_EXIT:
> +
> + if (atomic_read(&pmu_context->sys_rebooting))
> + return NOTIFY_OK;
> +
> + return gs101_cpu_pmu_online();
> + }
> +
> + return NOTIFY_OK;
> +}
The rest looked fine.
Best regards,
Krzysztof
next prev parent reply other threads:[~2025-07-12 17:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 13:50 [PATCH v6] soc: samsung: exynos-pmu: Enable CPU Idle for gs101 Peter Griffin
2025-07-11 14:53 ` Sudeep Holla
2025-07-11 14:56 ` Sudeep Holla
2025-07-11 15:49 ` Peter Griffin
2025-07-12 17:42 ` Krzysztof Kozlowski [this message]
2025-07-17 16:33 ` Peter Griffin
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=5597644b-267d-40d0-aa33-a8a665cebd70@kernel.org \
--to=krzk@kernel.org \
--cc=alim.akhtar@samsung.com \
--cc=andre.draszik@linaro.org \
--cc=kernel-team@android.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=sudeep.holla@arm.com \
--cc=tudor.ambarus@linaro.org \
--cc=willmcvicker@google.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.