public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clocksource: Add debugfs support
@ 2020-03-31 21:40 Thierry Reding
  2020-03-31 21:50 ` John Stultz
  2020-03-31 22:06 ` Thomas Gleixner
  0 siblings, 2 replies; 10+ messages in thread
From: Thierry Reding @ 2020-03-31 21:40 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: Stephen Boyd, linux-kernel

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-03-31 23:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-31 21:40 [PATCH] clocksource: Add debugfs support Thierry Reding
2020-03-31 21:50 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox