Devicetree
 help / color / mirror / Atom feed
From: Pranjal Shrivastava <praan@google.com>
To: amitamishra@google.com
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org,
	krzk+dt@kernel.org,  linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  linux-perf-users@vger.kernel.org,
	mark.rutland@arm.com, robh@kernel.org,  robin.murphy@arm.com,
	will@kernel.org, iommu@lists.linux.dev,  smostafa@google.com
Subject: Re: [PATCH 2/2] perf/smmuv3: Add runtime PM support
Date: Mon, 23 Nov 2026 15:49:45 +0000	[thread overview]
Message-ID: <20261123154945.3083888-1-praan@google.com> (raw)
In-Reply-To: <20261118101913.3135869-3-amitamishra@google.com>

On Wed, Nov 18, 2026 at 10:19:13AM +0000, Amita Mishra wrote:

Hi Amita,

+iommu@lists.linux.dev
Please CC the iommu list as well.

> On SoCs where an SMMUv3 PMCG resides in a switchable power domain,
> probing the PMCG attaches and powers on the domain, but without runtime
> PM support the domain remains permanently powered on even when no perf
> events are active.

I'm interested to know which PMCGs are these? Upstream arm-smmu-v3 
doesn't have runtime PM yet, thus, a PMCG that shares its SMMU's power 
domain gains nothing from this today: the SMMU keeps the domain on anyway

With my arm-smmu-v3 runtime PM series [1], the SMMU lets go of the domain
once it has no active clients, and then a PMCG without runtime PM would be
the one keeping it on, the two series seem to fit together. For TBU PMCGs
in a subsystem's domain this matters either way.

I'm wondering if you have PMCGs in power-domains that are neither tied to
the SMMU power-domain and nor it's clients' power-domain? 
(That'd be a bit odd but possible).

[...]

> +    /* The same condition smmu_pmu_probe() enables runtime PM on. */
> +    if (dev->pm_domain) {
> +        int ret = pm_runtime_resume_and_get(dev);
> +
> +        if (ret < 0)
> +            return ret;
> +        event->destroy = smmu_pmu_event_destroy;
>      }

This keeps the domain powered for as long as the event exists, even
while it is disabled or not scheduled. I'd be surprised if the 
production devices that use runtime PM keep a PMCG event open requiring
this? 

For a PMCG in the SMMU's domain, with [1] that means a perf event keeps
the domain on while the SMMU itself is suspended (SMMUEN=0, GBPA=Abort).
The SMMU only suspends once all its clients are idle, so apart from
cycles there's nothing meaningful to count.

For a TBU PMCG, it keeps the subsystem's domain powered, which changes
what's being measured: the TBU's TLBs and config caches survive what
would otherwise be power-offs, so tlb_miss and config_cache_miss can
under-report compared to the unmonitored system.

Which makes me question whether the PMCG needs runtime PM at all. It's
a profiling tool, and I'd be surprised if production devices that use
runtime PM keep PMCG events open. Without events nothing needs the PMCG
powered, so all this buys is not pinning the domain while the driver is
probed but unused..

Do you probe the PMCGs on production devices? If they're only used for
profiling and not in-field, not loading the driver there (or leaving the
node disabled) avoids the problem without runtime PM in the driver.

If we do need it, a couple of issues with the implementation below:

[...]

> @@ -975,15 +1040,45 @@ static void smmu_pmu_remove(struct platform_device *pdev)
>
>      perf_pmu_unregister(&smmu_pmu->pmu);
>      cpuhp_state_remove_instance_nocalls(cpuhp_state_num, &smmu_pmu->node);
> +    if (pdev->dev.pm_domain)
> +        pm_runtime_disable(&pdev->dev);
>  }

Events hold a module reference and bind/unbind is suppressed, so this
only runs with no events, i.e. normally with the PMCG runtime-suspended.
devres then frees the IRQ: free_irq() -> msi_domain_deactivate() ->
smmu_pmu_write_msi_msg() writes to the unpowered PMCG, since the PM
domain is only detached after devres in device_unbind_cleanup(). Wired
interrupts are fine, and the CPU hotplug path Sashiko mentioned
shouldn't rewrite the message with a GICv3 ITS parent, so in practice
this is MSIs plus module unload.

With the MSI message cached by the core (see below),
smmu_pmu_write_msi_msg() could simply skip the MMIO while the PMCG is
suspended and leave it to resume. Note it would have to check
pm_runtime_status_suspended(), since runtime PM is already disabled by
the time devres runs. Alternatively, keep the PMCG resumed across the
devres teardown.

[...]

> +static int smmu_pmu_runtime_resume(struct device *dev)
> +{
> +    struct smmu_pmu *smmu_pmu = dev_get_drvdata(dev);
> +
> +    smmu_pmu_reset(smmu_pmu);
> +    return 0;
> +}

Sashiko flagged this too: after a power-off the IRQ configuration is
gone, and smmu_pmu_reset() doesn't put it back. With MSIs, overflow
interrupts stop arriving and counters wrap unnoticed. With a wired
interrupt on an MSI-capable PMCG, IRQ_CFG0 comes back UNKNOWN, so an
overflow can send an MSI write to a garbage address, which is exactly
why probe clears it.

This is the same problem I had to solve for the SMMU in [1]: patches
7-8 make the genirq/msi core cache the message in
irq_chip_write_msi_msg() and add msi_device_domain_restore_msi_msgs(),
and arm_smmu_resume_msis() in patch 9 clears the IRQ_CFG0 registers and
then calls it (a no-op for wired IRQs). The PMCG resume needs the same:

    writeq_relaxed(0, smmu_pmu->reg_base + SMMU_PMCG_IRQ_CFG0);
    msi_device_domain_restore_msi_msgs(dev, MSI_DEFAULT_DOMAIN);

Minor: an autosuspend delay would avoid powering the domain on and off
for every event open/close.

Thanks,
Praan

[1] https://lore.kernel.org/all/20260929034510.2023173-1-praan@google.com/

      parent reply	other threads:[~2026-11-23 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 10:19 [PATCH 0/2] perf/smmuv3: Add runtime PM support Amita Mishra
2026-11-18 10:19 ` [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains Amita Mishra
2026-11-18 13:07   ` Robin Murphy
2026-11-18 10:19 ` [PATCH 2/2] perf/smmuv3: Add runtime PM support Amita Mishra
2026-11-18 10:44   ` sashiko-bot
2026-11-23 15:49   ` Pranjal Shrivastava [this message]

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=20261123154945.3083888-1-praan@google.com \
    --to=praan@google.com \
    --cc=amitamishra@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=smostafa@google.com \
    --cc=will@kernel.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