From: Rob Clark <robdclark@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org,
Rob Clark <robdclark@chromium.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-pm@vger.kernel.org (open list:POWER MANAGEMENT CORE),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v3 4/9] PM / QoS: Decouple request alloc from dev_pm_qos_mtx
Date: Thu, 3 Aug 2023 15:01:52 -0700 [thread overview]
Message-ID: <20230803220202.78036-5-robdclark@gmail.com> (raw)
In-Reply-To: <20230803220202.78036-1-robdclark@gmail.com>
From: Rob Clark <robdclark@chromium.org>
Similar to the previous patch, move the allocation out from under
dev_pm_qos_mtx, by speculatively doing the allocation and handle
any race after acquiring dev_pm_qos_mtx by freeing the redundant
allocation.
Signed-off-by: Rob Clark <robdclark@chromium.org>
---
drivers/base/power/qos.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
index f3e0c6b65635..4537d93ddb45 100644
--- a/drivers/base/power/qos.c
+++ b/drivers/base/power/qos.c
@@ -922,17 +922,19 @@ s32 dev_pm_qos_get_user_latency_tolerance(struct device *dev)
*/
int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
{
+ struct dev_pm_qos_request *req = NULL;
int ret;
ret = dev_pm_qos_constraints_ensure_allocated(dev);
if (ret)
return ret;
+ if (!dev->power.qos->latency_tolerance_req)
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
+
mutex_lock(&dev_pm_qos_mtx);
if (!dev->power.qos->latency_tolerance_req) {
- struct dev_pm_qos_request *req;
-
if (val < 0) {
if (val == PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT)
ret = 0;
@@ -940,7 +942,6 @@ int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
ret = -EINVAL;
goto out;
}
- req = kzalloc(sizeof(*req), GFP_KERNEL);
if (!req) {
ret = -ENOMEM;
goto out;
@@ -952,6 +953,13 @@ int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val)
}
dev->power.qos->latency_tolerance_req = req;
} else {
+ /*
+ * If we raced with another thread to allocate the request,
+ * simply free the redundant allocation and move on.
+ */
+ if (req)
+ kfree(req);
+
if (val < 0) {
__dev_pm_qos_drop_user_request(dev, DEV_PM_QOS_LATENCY_TOLERANCE);
ret = 0;
--
2.41.0
next prev parent reply other threads:[~2023-08-03 22:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 22:01 [PATCH v3 0/9] drm/msm+PM+icc: Make job_run() reclaim-safe Rob Clark
2023-08-03 22:01 ` [PATCH v3 1/9] PM / devfreq: Drop unneed locking to appease lockdep Rob Clark
2023-08-03 22:01 ` [PATCH v3 2/9] PM / devfreq: Teach lockdep about locking order Rob Clark
2023-08-03 22:01 ` [PATCH v3 3/9] PM / QoS: Fix constraints alloc vs reclaim locking Rob Clark
2023-08-04 17:07 ` Rafael J. Wysocki
2023-08-04 18:38 ` Rob Clark
2023-08-04 19:11 ` Rafael J. Wysocki
2023-08-04 20:37 ` Rob Clark
2023-08-04 20:45 ` Rafael J. Wysocki
2023-08-03 22:01 ` Rob Clark [this message]
2023-08-04 9:29 ` [PATCH v3 4/9] PM / QoS: Decouple request alloc from dev_pm_qos_mtx Dan Carpenter
2023-08-03 22:01 ` [PATCH v3 5/9] PM / QoS: Teach lockdep about dev_pm_qos_mtx locking order Rob Clark
2023-08-03 22:01 ` [PATCH v3 6/9] interconnect: Fix locking for runpm vs reclaim Rob Clark
2023-08-03 22:01 ` [PATCH v3 7/9] interconnect: Teach lockdep about icc_bw_lock order Rob Clark
2023-08-03 22:01 ` [PATCH v3 8/9] drm/sched: Add (optional) fence signaling annotation Rob Clark
2023-08-03 22:01 ` [PATCH v3 9/9] drm/msm: Enable fence signalling annotations Rob Clark
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=20230803220202.78036-5-robdclark@gmail.com \
--to=robdclark@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=len.brown@intel.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
--cc=robdclark@chromium.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