public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Luba <l.luba@partner.samsung.com>
To: linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org
Cc: mark.rutland@arm.com, len.brown@intel.com, tony.luck@intel.com,
	keescook@chromium.org, cw00.choi@samsung.com,
	b.zolnierkie@samsung.com, gregkh@linuxfoundation.org,
	anton@enomsg.org, rjw@rjwysocki.net, robh+dt@kernel.org,
	Lukasz Luba <l.luba@partner.samsung.com>,
	tjakobi@math.uni-bielefeld.de, kyungmin.park@samsung.com,
	myungjoo.ham@samsung.com, kgene@kernel.org, pavel@ucw.cz,
	ccross@android.com, krzk@kernel.org, m.szyprowski@samsung.com
Subject: [PATCH 3/6] devfreq: add support for suspend/resume of a devfreq device
Date: Wed, 21 Nov 2018 19:01:38 +0100	[thread overview]
Message-ID: <1542823301-23563-4-git-send-email-l.luba@partner.samsung.com> (raw)
In-Reply-To: <1542823301-23563-1-git-send-email-l.luba@partner.samsung.com>

The patch adds support for handling suspend/resume process.
It uses atomic variables to make sure no race condition
affects the process.

The patch draws on Tobias Jakobi's work posted ~2 years ago, who tried to
solve issue with devfreq device's frequency during suspend/resume.
During the discussion on LKML some corner cases and comments appeared
related to the design. This patch address them keeping in mind suggestions
from Chanwoo Choi.

Suggested-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Suggested-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Lukasz Luba <l.luba@partner.samsung.com>
---
 drivers/devfreq/devfreq.c | 45 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index cf9c643..7e09de8 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -872,14 +872,33 @@ EXPORT_SYMBOL(devm_devfreq_remove_device);
  */
 int devfreq_suspend_device(struct devfreq *devfreq)
 {
-	if (!devfreq)
-		return -EINVAL;
+        int ret;
+        unsigned long prev_freq;
+        u32 flags = 0;
+
+        if (!devfreq)
+                return -EINVAL;
+
+        if (devfreq->governor) {
+		ret = devfreq->governor->event_handler(devfreq,
+					DEVFREQ_GOV_SUSPEND, NULL);
+		if (ret)
+			return ret;
+	}
 
-	if (!devfreq->governor)
-		return 0;
+	if (devfreq->suspend_freq) {
+		if (atomic_inc_return(&devfreq->suspend_count) > 1)
+			return 0;
 
-	return devfreq->governor->event_handler(devfreq,
-				DEVFREQ_GOV_SUSPEND, NULL);
+		ret = devfreq_set_target(devfreq, devfreq->suspend_freq,
+					 &prev_freq, flags);
+		if (ret)
+			return ret;
+
+		devfreq->resume_freq = prev_freq;
+	}
+
+        return 0;
 }
 EXPORT_SYMBOL(devfreq_suspend_device);
 
@@ -893,9 +912,23 @@ EXPORT_SYMBOL(devfreq_suspend_device);
  */
 int devfreq_resume_device(struct devfreq *devfreq)
 {
+        int ret;
+        unsigned long prev_freq;
+        u32 flags = 0;
+
 	if (!devfreq)
 		return -EINVAL;
 
+	if (devfreq->suspend_freq) {
+		if (atomic_dec_return(&devfreq->suspend_count) >= 1)
+			return 0;
+
+		ret = devfreq_set_target(devfreq, devfreq->resume_freq,
+					 &prev_freq, flags);
+		if (ret)
+			return ret;
+	}
+
 	if (!devfreq->governor)
 		return 0;
 
-- 
2.7.4

  parent reply	other threads:[~2018-11-21 18:01 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20181121180156eucas1p225af7f4341a039264ff26f2a9ad9bb12@eucas1p2.samsung.com>
2018-11-21 18:01 ` [PATCH 0/6] devfreq: handle suspend/resume Lukasz Luba
2018-11-21 18:01   ` [PATCH 1/6] devfreq: add basic fileds supporting suspend functionality Lukasz Luba
2018-11-22  2:37     ` Chanwoo Choi
2018-11-26  8:14     ` MyungJoo Ham
2018-12-03 14:03       ` Lukasz Luba
2018-11-21 18:01   ` [PATCH 2/6] devfreq: refactor set_target frequency function Lukasz Luba
2018-11-22  2:52     ` Chanwoo Choi
2018-11-22  2:54       ` Chanwoo Choi
2018-11-22 10:40       ` Lukasz Luba
2018-11-22 23:45         ` Chanwoo Choi
2018-11-23  9:58           ` Lukasz Luba
2018-11-21 18:01   ` Lukasz Luba [this message]
2018-11-22  2:58     ` [PATCH 3/6] devfreq: add support for suspend/resume of a devfreq device Chanwoo Choi
2018-11-22 11:00       ` Lukasz Luba
2018-11-22 23:54         ` Chanwoo Choi
2018-11-23 10:01           ` Lukasz Luba
2018-11-26  0:19             ` Chanwoo Choi
2018-12-03 14:05               ` Lukasz Luba
2018-11-21 18:01   ` [PATCH 4/6] devfreq: add devfreq_suspend/resume() functions Lukasz Luba
2018-11-22  3:07     ` Chanwoo Choi
2018-11-22 11:02       ` Lukasz Luba
2018-11-21 18:01   ` [PATCH 5/6] drivers: power: suspend: call devfreq suspend/resume Lukasz Luba
2018-11-22  3:08     ` Chanwoo Choi
2018-11-21 18:01   ` [PATCH 6/6] arm: dts: exynos4: set opp-suspend for DMC and leftbus Lukasz Luba
2018-11-22  3:09     ` Chanwoo Choi
2018-11-22 11:04       ` Lukasz Luba
2018-11-22 17:24   ` [PATCH 0/6] devfreq: handle suspend/resume Tobias Jakobi
2018-11-22 17:44     ` Lukasz Luba

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=1542823301-23563-4-git-send-email-l.luba@partner.samsung.com \
    --to=l.luba@partner.samsung.com \
    --cc=anton@enomsg.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=ccross@android.com \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=kgene@kernel.org \
    --cc=krzk@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=len.brown@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mark.rutland@arm.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=tjakobi@math.uni-bielefeld.de \
    --cc=tony.luck@intel.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