From: "Yicong Yang" <yang.yicong@picoheart.com>
To: <xueshuai@linux.alibaba.com>, <renyu.zj@linux.alibaba.com>,
<will@kernel.org>, <mark.rutland@arm.com>, <jic23@kernel.org>,
<bhelgaas@google.com>, <linux-pci@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: <jingoohan1@gmail.com>, <mani@kernel.org>,
<juwenlong@picoheart.com>, <geshijian@picoheart.com>,
<yang.yicong@picoheart.com>, <douyufan@picoheart.com>
Subject: [PATCH v3 4/4] drivers/perf: Fix the condition where the root port is runtime suspended
Date: Wed, 8 Jul 2026 16:45:06 +0800 [thread overview]
Message-ID: <20260708084507.98242-5-yang.yicong@picoheart.com> (raw)
In-Reply-To: <20260708084507.98242-1-yang.yicong@picoheart.com>
The PMU is based on the corresponding root port's VSEC capability,
which could be inaccessible if the target root port is runtime
suspended to D3Cold. Fix this by getting/putting the root port's
runtime pm when the event of this PMU is init/destroy. It cannot
be done in the add()/del() callbacks where the events is actually
scheduled, since there's not way to runtime resume the device
synchronously in the atomic context (add()/del()).
With this patch, the root port will keep D0 while counting and suspend
after counting finished (for prove the correctness since my board does
not support D3Cold):
root@localhost:~# cat /sys/bus/pci/devices/0008\:00\:00.0/power_state
D3hot
root@localhost:~# perf stat -e dwc_rootport_8000/one_cycle/ &
[1] 14580
root@localhost:~# cat /sys/bus/pci/devices/0008\:00\:00.0/power_state
D0
root@localhost:~# kill %1
[1]+ Terminated perf stat -e dwc_rootport_8000/one_cycle/
root@localhost:~# cat /sys/bus/pci/devices/0008\:00\:00.0/power_state
D3hot
The root port also needs to be runtime resumed during PCIe PMU
device registration and probe, so get/put the runtime pm there
as well.
Fixes: af9597adc2f1 ("drivers/perf: add DesignWare PCIe PMU driver")
Closes: https://lore.kernel.org/linux-pci/20260629094234.F25E71F000E9@smtp.kernel.org/
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Yicong Yang <yang.yicong@picoheart.com>
---
drivers/perf/dwc_pcie_pmu.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c
index 7b4ee71b966b..aea387d0d0fe 100644
--- a/drivers/perf/dwc_pcie_pmu.c
+++ b/drivers/perf/dwc_pcie_pmu.c
@@ -17,6 +17,7 @@
#include <linux/list.h>
#include <linux/pcie-dwc.h>
#include <linux/perf_event.h>
+#include <linux/pm_runtime.h>
#include <linux/pci.h>
#include <linux/smp.h>
#include <linux/sysfs.h>
@@ -474,12 +475,20 @@ static enum hrtimer_restart dwc_pcie_pmu_hrtimer_callback(struct hrtimer *hrtime
return HRTIMER_RESTART;
}
+static void dwc_pcie_pmu_event_destroy(struct perf_event *event)
+{
+ struct dwc_pcie_pmu *pcie_pmu = to_dwc_pcie_pmu(event->pmu);
+
+ pm_runtime_put_autosuspend(&pcie_pmu->pdev->dev);
+}
+
static int dwc_pcie_pmu_event_init(struct perf_event *event)
{
struct dwc_pcie_pmu *pcie_pmu = to_dwc_pcie_pmu(event->pmu);
enum dwc_pcie_event_type type = DWC_PCIE_EVENT_TYPE(event);
struct perf_event *sibling;
u32 lane;
+ int ret;
if (event->attr.type != event->pmu->type)
return -ENOENT;
@@ -509,7 +518,16 @@ static int dwc_pcie_pmu_event_init(struct perf_event *event)
if (dwc_pcie_pmu_validate_group(event))
return -ENOSPC;
+ /*
+ * Resume the root port for VSEC access. Use RPM_TRANSPARENT as the
+ * VSEC is accessible if root port's runtime pm is disabled.
+ */
+ ret = pm_runtime_get_active(&pcie_pmu->pdev->dev, RPM_TRANSPARENT);
+ if (ret < 0)
+ return ret;
+
event->cpu = pcie_pmu->on_cpu;
+ event->destroy = dwc_pcie_pmu_event_destroy;
return 0;
}
@@ -776,6 +794,7 @@ static int dwc_pcie_pmu_probe(struct faux_device *fdev)
if (!name)
return -ENOMEM;
+ guard(pm_runtime_active_auto)(&pdev->dev);
vsec = dwc_pcie_des_cap(pdev);
if (!vsec)
return -ENODEV;
@@ -909,6 +928,8 @@ static int __init dwc_pcie_pmu_init(void)
dwc_pcie_pmu_hp_state = ret;
for_each_pci_dev(pdev) {
+ guard(pm_runtime_active_auto)(&pdev->dev);
+
if (!dwc_pcie_des_cap(pdev))
continue;
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-07-08 8:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 8:45 [PATCH v3 0/4] New vendor support and optimizations for DWC PCIe PMU Yicong Yang
2026-07-08 8:45 ` [PATCH v3 1/4] perf/dwc_pcie: Add support for Picoheart vendor devices Yicong Yang
2026-07-08 8:45 ` [PATCH v3 2/4] perf/dwc_pcie: Support narrowed time-based counter for long time monitoring Yicong Yang
2026-07-08 8:45 ` [PATCH v3 3/4] perf/dwc_pcie: Convert to faux device interface Yicong Yang
2026-07-08 8:45 ` Yicong Yang [this message]
2026-08-01 11:28 ` [PATCH v3 0/4] New vendor support and optimizations for DWC PCIe PMU Will Deacon
2026-08-03 8:35 ` Yicong Yang
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=20260708084507.98242-5-yang.yicong@picoheart.com \
--to=yang.yicong@picoheart.com \
--cc=bhelgaas@google.com \
--cc=douyufan@picoheart.com \
--cc=geshijian@picoheart.com \
--cc=jic23@kernel.org \
--cc=jingoohan1@gmail.com \
--cc=juwenlong@picoheart.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=mark.rutland@arm.com \
--cc=renyu.zj@linux.alibaba.com \
--cc=will@kernel.org \
--cc=xueshuai@linux.alibaba.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®