mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: John Stultz <john.stultz@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] clocksource: Add suspend clocksource sysfs attribute
Date: Fri, 14 Jun 2019 12:45:10 +0200	[thread overview]
Message-ID: <20190614104510.19360-2-thierry.reding@gmail.com> (raw)
In-Reply-To: <20190614104510.19360-1-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

Allow the currently selected suspend clocksource to be inspected via
sysfs. The suspend clocksource can also be set using this attribute,
which can be useful for debugging.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 kernel/time/clocksource.c | 53 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 467b36d2f9f8..d963bcecbc96 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -489,7 +489,8 @@ static void __clocksource_suspend_select(struct clocksource *cs)
 	}
 
 	/* Pick the best rating. */
-	if (!suspend_clocksource || cs->rating > suspend_clocksource->rating)
+	if (!suspend_clocksource || cs->rating > suspend_clocksource->rating ||
+	    (suspend_clocksource->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) == 0)
 		suspend_clocksource = cs;
 }
 
@@ -1172,10 +1173,60 @@ static ssize_t available_clocksource_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(available_clocksource);
 
+static ssize_t suspend_clocksource_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct clocksource *clksrc = suspend_clocksource;
+	ssize_t count = 0;
+
+	if (clksrc)
+		count += snprintf(buf, PAGE_SIZE, "%s\n", clksrc->name);
+
+	return count;
+}
+
+static ssize_t suspend_clocksource_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t count)
+{
+	struct clocksource *cs;
+	char name[CS_NAME_LEN];
+	ssize_t ret;
+
+	ret = sysfs_get_uname(buf, name, count);
+	if (ret < 0)
+		return ret;
+
+	mutex_lock(&clocksource_mutex);
+
+	if (strlen(name) > 0) {
+		cs = clocksource_lookup(name);
+		if (cs) {
+			if (!(cs->flags & CLOCK_SOURCE_SUSPEND_NONSTOP))
+				pr_warn("using non-persistent clocksource %s for suspend\n",
+					cs->name);
+
+			suspend_clocksource = cs;
+		} else {
+			ret = -ENODEV;
+		}
+	} else {
+		clocksource_suspend_select(false);
+	}
+
+	mutex_unlock(&clocksource_mutex);
+
+	return ret ? ret : count;
+}
+
+static DEVICE_ATTR_RW(suspend_clocksource);
+
 static struct attribute *clocksource_attrs[] = {
 	&dev_attr_current_clocksource.attr,
 	&dev_attr_unbind_clocksource.attr,
 	&dev_attr_available_clocksource.attr,
+	&dev_attr_suspend_clocksource.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(clocksource);
-- 
2.21.0


      reply	other threads:[~2019-06-14 10:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 10:45 [PATCH 1/2] clocksource: Extract clocksource lookup code Thierry Reding
2019-06-14 10:45 ` Thierry Reding [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=20190614104510.19360-2-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome