public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff LaBundy <jeff@labundy.com>
To: rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz
Cc: linux-pm@vger.kernel.org, Jeff LaBundy <jeff@labundy.com>
Subject: [PATCH] PM / sysfs: Add the ability to call PM operations manually
Date: Sun, 11 Oct 2020 19:09:24 -0500	[thread overview]
Message-ID: <1602461364-17300-1-git-send-email-jeff@labundy.com> (raw)

During driver development, it's useful to be able to call a device's
suspend and resume operations for test purposes without having to
involve the rest of the PM subsystem. Such an ability would be handy
for measuring power consumption, checking interrupt function, etc.

The PM subsystem does have debug hooks for limiting the scope of
suspend or excluding devices that shouldn't suspend, but there can be
overhead in configuring these hooks that is often inconvenient during
early bring-up.

This patch introduces the pm_op_test attribute, to be used as follows
(random I2C client used as an example):

1. echo 'suspend' > /sys/bus/i2c/devices/1-0044/power/pm_op_test
2. Measure power consumption at one's leisure, check wake-up interrupt
   behavior, etc.
3. echo 'resume' > /sys/bus/i2c/devices/1-0044/power/pm_op_test

Nothing is done to check or report the device's state; as such this
new function is conservatively guarded by CONFIG_PM_ADVANCED_DEBUG.
Only suspend and resume PM operations are included for now.

Signed-off-by: Jeff LaBundy <jeff@labundy.com>
---
 drivers/base/power/sysfs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index c7b2481..78ee6f1 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -77,6 +77,8 @@
  *	attribute is set to "enabled" by bus type code or device drivers and in
  *	that cases it should be safe to leave the default value.
  *
+ *	pm_op_test - Call one of the device's PM operations for test purposes
+ *
  *	autosuspend_delay_ms - Report/change a device's autosuspend_delay value
  *
  *	Some drivers don't want to carry out a runtime suspend as soon as a
@@ -571,6 +573,27 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR_RW(async);
 
+static const char pm_op_test_suspend[] = "suspend";
+static const char pm_op_test_resume[] = "resume";
+
+static ssize_t pm_op_test_store(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t n)
+{
+	int ret;
+
+	if (sysfs_streq(buf, pm_op_test_suspend))
+		ret = pm_generic_suspend(dev);
+	else if (sysfs_streq(buf, pm_op_test_resume))
+		ret = pm_generic_resume(dev);
+	else
+		ret = -EINVAL;
+
+	return ret < 0 ? ret : n;
+}
+
+static DEVICE_ATTR_WO(pm_op_test);
+
 #endif /* CONFIG_PM_SLEEP */
 #endif /* CONFIG_PM_ADVANCED_DEBUG */
 
@@ -578,6 +601,7 @@ static struct attribute *power_attrs[] = {
 #ifdef CONFIG_PM_ADVANCED_DEBUG
 #ifdef CONFIG_PM_SLEEP
 	&dev_attr_async.attr,
+	&dev_attr_pm_op_test.attr,
 #endif
 	&dev_attr_runtime_status.attr,
 	&dev_attr_runtime_usage.attr,
-- 
2.7.4


             reply	other threads:[~2020-10-12  0:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12  0:09 Jeff LaBundy [this message]
2020-10-12 10:31 ` [PATCH] PM / sysfs: Add the ability to call PM operations manually Rafael J. Wysocki
2020-10-12 17:04   ` Jeff LaBundy

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=1602461364-17300-1-git-send-email-jeff@labundy.com \
    --to=jeff@labundy.com \
    --cc=len.brown@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    /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