public inbox for linux-kernel@vger.kernel.org
 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] clocksource: Add debugfs support
Date: Tue, 31 Mar 2020 23:40:45 +0200	[thread overview]
Message-ID: <20200331214045.2957710-1-thierry.reding@gmail.com> (raw)

From: Thierry Reding <treding@nvidia.com>

Add a top-level "clocksource" directory to debugfs. For each clocksource
registered with the system, a subdirectory will be added with attributes
that can be queried to obtain information about the clocksource.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 include/linux/clocksource.h |  3 ++
 kernel/time/clocksource.c   | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 86d143db6523..89424da76244 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -118,6 +118,9 @@ struct clocksource {
 	u64			wd_last;
 #endif
 	struct module		*owner;
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs;
+#endif
 };
 
 /*
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 7cb09c4cf21c..51266f53df83 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -911,6 +911,63 @@ void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq
 }
 EXPORT_SYMBOL_GPL(__clocksource_update_freq_scale);
 
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+
+static struct dentry *debugfs_root;
+
+static int clocksource_debugfs_counter_show(struct seq_file *s, void *data)
+{
+	struct clocksource *cs = s->private;
+
+	seq_printf(s, "%llu\n", cs->read(cs));
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(clocksource_debugfs_counter);
+
+static void clocksource_debugfs_add(struct clocksource *cs)
+{
+	if (!debugfs_root)
+		return;
+
+	cs->debugfs = debugfs_create_dir(cs->name, debugfs_root);
+
+	debugfs_create_file("counter", 0444, cs->debugfs, cs,
+			    &clocksource_debugfs_counter_fops);
+}
+
+static void clocksource_debugfs_remove(struct clocksource *cs)
+{
+	debugfs_remove_recursive(cs->debugfs);
+}
+
+static int __init init_clocksource_debugfs(void)
+{
+	struct clocksource *cs;
+
+	debugfs_root = debugfs_create_dir("clocksource", NULL);
+
+	mutex_lock(&clocksource_mutex);
+
+	list_for_each_entry(cs, &clocksource_list, list)
+		clocksource_debugfs_add(cs);
+
+	mutex_unlock(&clocksource_mutex);
+
+	return 0;
+}
+late_initcall(init_clocksource_debugfs);
+#else
+static inline void clocksource_debugfs_add(struct clocksource *cs)
+{
+}
+
+static inline void clocksource_debugfs_remove(struct clocksource *cs)
+{
+}
+#endif
+
 /**
  * __clocksource_register_scale - Used to install new clocksources
  * @cs:		clocksource to be registered
@@ -951,6 +1008,7 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
 	clocksource_select();
 	clocksource_select_watchdog(false);
 	__clocksource_suspend_select(cs);
+	clocksource_debugfs_add(cs);
 	mutex_unlock(&clocksource_mutex);
 	return 0;
 }
@@ -991,6 +1049,8 @@ static int clocksource_unbind(struct clocksource *cs)
 {
 	unsigned long flags;
 
+	clocksource_debugfs_remove(cs);
+
 	if (clocksource_is_watchdog(cs)) {
 		/* Select and try to install a replacement watchdog. */
 		clocksource_select_watchdog(true);
-- 
2.24.1


             reply	other threads:[~2020-03-31 21:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 21:40 Thierry Reding [this message]
2020-03-31 21:50 ` [PATCH] clocksource: Add debugfs support John Stultz
2020-03-31 22:25   ` Thierry Reding
2020-03-31 22:44     ` John Stultz
2020-03-31 23:02       ` Thierry Reding
2020-03-31 22:06 ` Thomas Gleixner
2020-03-31 22:29   ` Thierry Reding
2020-03-31 22:49     ` Thierry Reding
2020-03-31 23:01     ` Thomas Gleixner
2020-03-31 23:06       ` Thierry Reding

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=20200331214045.2957710-1-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