Skip to contentSkip to conversation

clocksource: Add debugfs support

PATCH In review Thierry Reding 3 participants 10 messages Mar 31, 2020 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: Add debugfs support

From: Thierry Reding <[email protected]>

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.

---
 include/linux/clocksource.h |  3 ++
 kernel/time/clocksource.c   | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
include/linux/clocksource.h +3 -0
index 86d143db6523..89424da76244 100644
@@ -118,6 +118,9 @@ struct clocksource {
 	u64			wd_last;
 #endif
 	struct module		*owner;
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs;
+#endif
 };
 
 /*
kernel/time/clocksource.c +60 -0

78 lines not on this page · raw message

Signature · 1 line
2.24.1
#1 lore raw
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

Curious, what's the need/planned use for this? I know in the past folks have tried to get timekeeping internals exported to userland so they could create their own parallel userland timekeeping system, which I worry is a poor idea.

thanks
-john

#2 lore raw
Quoted 9 lines · John Stultz
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

Quoted 4 lines

Curious, what's the need/planned use for this? I know in the past folks have tried to get timekeeping internals exported to userland so they could create their own parallel userland timekeeping system, which I worry is a poor idea.

This was meant to be purely for debugging purposes. That is as an easy way to check that the code was working and that the counter is properly updated.

I certainly wasn't planning on implementing any userland on top of this. Well, I guess it could be useful to use these values in test scripts perhaps, since one of the clock sources exposed by one of the drivers I have been working on is used across Tegra SoCs for hardware timestamping. For that it might be interesting to be able to compare those timestamp snapshots to something that I can read from userspace during testing.

But that's about as far as I was planning on taking this. I agree that basing some userland timekeeping system on a debugfs interface sounds like a very bad idea.

Thierry

#3 lore raw
Quoted 19 lines · Thierry Reding
Quoted 9 lines · John Stultz
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

Quoted 4 lines

Curious, what's the need/planned use for this? I know in the past folks have tried to get timekeeping internals exported to userland so they could create their own parallel userland timekeeping system, which I worry is a poor idea.

This was meant to be purely for debugging purposes. That is as an easy way to check that the code was working and that the counter is properly updated.

Quoted 7 lines

I certainly wasn't planning on implementing any userland on top of this. Well, I guess it could be useful to use these values in test scripts perhaps, since one of the clock sources exposed by one of the drivers I have been working on is used across Tegra SoCs for hardware timestamping. For that it might be interesting to be able to compare those timestamp snapshots to something that I can read from userspace during testing.

So, other platforms do similar, but utilizing the ktime_get_snapshot() interface internally so drivers can share that SoC hardware timestamping logic and export that via driver interfaces in a cleanly abstracted way to userland, rather than exposing the timekeping internals.

thanks
-john

#4 lore raw
Quoted 28 lines · John Stultz
Quoted 19 lines · Thierry Reding
Quoted 9 lines · John Stultz
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

Quoted 4 lines

Curious, what's the need/planned use for this? I know in the past folks have tried to get timekeeping internals exported to userland so they could create their own parallel userland timekeeping system, which I worry is a poor idea.

This was meant to be purely for debugging purposes. That is as an easy way to check that the code was working and that the counter is properly updated.

Quoted 7 lines

I certainly wasn't planning on implementing any userland on top of this. Well, I guess it could be useful to use these values in test scripts perhaps, since one of the clock sources exposed by one of the drivers I have been working on is used across Tegra SoCs for hardware timestamping. For that it might be interesting to be able to compare those timestamp snapshots to something that I can read from userspace during testing.

Quoted 5 lines

So, other platforms do similar, but utilizing the ktime_get_snapshot() interface internally so drivers can share that SoC hardware timestamping logic and export that via driver interfaces in a cleanly abstracted way to userland, rather than exposing the timekeping internals.

The hardware timestamping functionality is going to be exposed by a different driver. I was merely speculating that the debugfs interface could be used to also read out the counter value for the TSC as a means of correlating it to the values from the timestamping hardware. On second thought that may not be very useful given the non-deterministic delay between the hardware timestamp and the debugfs read.

Like I said, the original intent here was really only to make it easy to inspect the clocksources. I can add more fields if that's deemed useful. I can imagine that different engineers keep writing different test code to verify clock sources and thought that this might be a good addition to make this easier.

But if you have concerns that this might get abused for something unintended I understand that, so if you think exposing this is a bad idea, I'll just drop this patch.

Thierry

#5 lore raw
In reply to Thierry Reding

Thierry,

Quoted 3 lines · Thierry Reding

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.

first of all this does tell what this patch does but omits the more important information about the WHY.

What's even worse is that the changelog is blantantly wrong.

Quoted 10 lines
kernel/time/clocksource.c +10 -0
+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);
+

kernel/time/clocksource.c void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq · line 938

Quoted 10 lines
kernel/time/clocksource.c +10 -0
+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);
+}

It does not provide any information about the clocksource, it provides an interface to read the counter - nothing else.

Try again.

Thanks,

tglx

#6 lore raw
Quoted 27 lines · Thomas Gleixner

Thierry,

Quoted 3 lines · Thierry Reding

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.

first of all this does tell what this patch does but omits the more important information about the WHY.

What's even worse is that the changelog is blantantly wrong.

Quoted 15 lines
kernel/time/clocksource.c +15 -0
+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;
+
Quoted 8 lines

kernel/time/clocksource.c void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq · line 938

Quoted 5 lines
kernel/time/clocksource.c +5 -0
+	cs->debugfs = debugfs_create_dir(cs->name, debugfs_root);
+
+	debugfs_create_file("counter", 0444, cs->debugfs, cs,
+			    &clocksource_debugfs_counter_fops);
+}

It does not provide any information about the clocksource, it provides an interface to read the counter - nothing else.

The counter is part of the information about a clocksource, isn't it? But yes, frankly I had anticipated that I'd be adding more files here and when I ended up not doing that I forgot to update the patch description.

I can also add some information about what I intend to use this for, though it'll be a bit boring because I really only want this as a way of testing that I'm reading from the right registers and that these counters are running. A debugfs interface seemed like a better and more widely useful way to achieve that than implementing some one-off hack to poll those registers.

Thierry

#7 lore raw
Quoted 37 lines · Thierry Reding
Quoted 27 lines · Thomas Gleixner

Thierry,

Quoted 3 lines · Thierry Reding

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.

first of all this does tell what this patch does but omits the more important information about the WHY.

What's even worse is that the changelog is blantantly wrong.

Quoted 15 lines
kernel/time/clocksource.c +15 -0
+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;
+
Quoted 8 lines

kernel/time/clocksource.c void __clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq · line 938

Quoted 5 lines
kernel/time/clocksource.c +5 -0
+	cs->debugfs = debugfs_create_dir(cs->name, debugfs_root);
+
+	debugfs_create_file("counter", 0444, cs->debugfs, cs,
+			    &clocksource_debugfs_counter_fops);
+}

It does not provide any information about the clocksource, it provides an interface to read the counter - nothing else.

Quoted 4 lines

The counter is part of the information about a clocksource, isn't it? But yes, frankly I had anticipated that I'd be adding more files here and when I ended up not doing that I forgot to update the patch description.

Looking again, I suppose I could add a couple of the fields from struct clocksource to this as well. The rating seems like it would be useful, as well as perhaps the mult (and maxadj) and shift fields, which would give users an easy way of converting the counter value to nanoseconds. max_idle_ns, max_cycles and mask seem too low-level and are really only useful for the kernel to deal with the clocksource.

"flags" might also be interesting.

Any other suggestions?

Thierry

#8 lore raw
In reply to Thierry Reding
Quoted 5 lines · Thierry Reding
Quoted 2 lines · Thomas Gleixner

It does not provide any information about the clocksource, it provides an interface to read the counter - nothing else.

The counter is part of the information about a clocksource, isn't it?

Sorry to be pedantic, but no. Information about a clocksource is the name, the type, the frequency, bitwidth etc.

The counter file is not providing information about the clocksource. It's exposing an accessor to the clocksource itself.

Quoted 6 lines

I can also add some information about what I intend to use this for, though it'll be a bit boring because I really only want this as a way of testing that I'm reading from the right registers and that these counters are running. A debugfs interface seemed like a better and more widely useful way to achieve that than implementing some one-off hack to poll those registers.

But how much value has this interface beyond the 'hack a driver for a new clocksource' experience?

To me none, but that might be my personal skewed view.

Thanks,

tglx

#9 lore raw
Quoted 5 lines · Thomas Gleixner
Quoted 4 lines · Thierry Reding
Quoted 2 lines · Thomas Gleixner

It does not provide any information about the clocksource, it provides an interface to read the counter - nothing else.

Quoted 7 lines
Quoted 1 line

The counter is part of the information about a clocksource, isn't it?

Sorry to be pedantic, but no. Information about a clocksource is the name, the type, the frequency, bitwidth etc.

The counter file is not providing information about the clocksource. It's exposing an accessor to the clocksource itself.

Okay, fair enough.

Quoted 11 lines
Quoted 6 lines

I can also add some information about what I intend to use this for, though it'll be a bit boring because I really only want this as a way of testing that I'm reading from the right registers and that these counters are running. A debugfs interface seemed like a better and more widely useful way to achieve that than implementing some one-off hack to poll those registers.

But how much value has this interface beyond the 'hack a driver for a new clocksource' experience?

To me none, but that might be my personal skewed view.

No, that's the only intended purpose. I just thought that would be nicer than everyone having to write their own debug messages to do the same thing.

If nobody else thinks this is useful I'll just stash it somewhere in case I ever need it again.

Thierry