Skip to contentSkip to conversation

ftrace: Provide trace clock monotonic raw

PATCH Superseded Drew Richardson 6 participants 18 messages May 4, 2015 – May 12, 2015 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftrace: Provide trace clock monotonic raw

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. Although the monotonic raw clock cannot be used to compare time between different machines, it is not perterbed by ntp.

---
 kernel/trace/trace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/trace.c +1 -0
index 05330494a0df..458031c31a37 100644
@@ -876,6 +876,7 @@ static struct {
 	{ trace_clock_jiffies,		"uptime",	0 },
 	{ trace_clock,			"perf",		1 },
 	{ ktime_get_mono_fast_ns,	"mono",		1 },
+	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
 	ARCH_TRACE_CLOCKS
 };
 
Signature · 1 line
2.1.4
#1 lore raw

----- Original Message -----

Quoted 5 lines

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. Although the monotonic raw clock cannot be used to compare time between different machines, it is not perterbed by ntp.

perterbed -> perturbed

Quoted 3 lines

What is the use-case that justify exposing the "raw fast" clock that cannot be handled by the "monotonic fast" clock ?

Thanks,

Mathieu

Quoted 20 lines
---
 kernel/trace/trace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/trace.c +1 -1
index 05330494a0df..458031c31a37 100644
@@ -876,6 +876,7 @@ static struct {
 	{ trace_clock_jiffies,		"uptime",	0 },
 	{ trace_clock,			"perf",		1 },
 	{ ktime_get_mono_fast_ns,	"mono",		1 },
+	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
 	ARCH_TRACE_CLOCKS
 };
 
--

2.1.4

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#2 lore raw
Quoted 8 lines · Mathieu Desnoyers

----- Original Message -----

Quoted 5 lines

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. Although the monotonic raw clock cannot be used to compare time between different machines, it is not perterbed by ntp.

perterbed -> perturbed

Oops, I'll correct that in the next version.

Quoted 10 lines
Quoted 3 lines

What is the use-case that justify exposing the "raw fast" clock that cannot be handled by the "monotonic fast" clock ?

Thanks,

Mathieu

I'm collecting and merging data from perf, with Android Atrace data (writes to /sys/kernel/debug/tracing/trace_marker) which ends up in the ftrace stream and other measurements collected from userspace. Currently the only clock readable from userspace, supported by perf and by ftrace is CLOCK_MONOTONIC. However this clock is affected by the incremental adjustments performed by adjtime(3) and NTP. But I'd prefer to use a clock that is advancing at a consistent rate, hence CLOCK_MONOTONIC_RAW.

Thanks,

Drew

Quoted 26 lines
Quoted 20 lines
---
 kernel/trace/trace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/trace.c +1 -1
index 05330494a0df..458031c31a37 100644
@@ -876,6 +876,7 @@ static struct {
 	{ trace_clock_jiffies,		"uptime",	0 },
 	{ trace_clock,			"perf",		1 },
 	{ ktime_get_mono_fast_ns,	"mono",		1 },
+	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
 	ARCH_TRACE_CLOCKS
 };
 
--

2.1.4

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#3 lore raw
Quoted 23 lines · Drew Richardson
Quoted 8 lines · Mathieu Desnoyers

----- Original Message -----

Quoted 5 lines

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. Although the monotonic raw clock cannot be used to compare time between different machines, it is not perterbed by ntp.

perterbed -> perturbed

Oops, I'll correct that in the next version.

Quoted 10 lines
Quoted 3 lines

What is the use-case that justify exposing the "raw fast" clock that cannot be handled by the "monotonic fast" clock ?

Thanks,

Mathieu

Quoted 8 lines

I'm collecting and merging data from perf, with Android Atrace data (writes to /sys/kernel/debug/tracing/trace_marker) which ends up in the ftrace stream and other measurements collected from userspace. Currently the only clock readable from userspace, supported by perf and by ftrace is CLOCK_MONOTONIC. However this clock is affected by the incremental adjustments performed by adjtime(3) and NTP. But I'd prefer to use a clock that is advancing at a consistent rate, hence CLOCK_MONOTONIC_RAW.

Well, I'd caution against assuming CLOCK_MONOTONIC_RAW is really a consistent rate, since w/ thermal changes the oscillator likely will drift around. But especially during early initialization, ntp can manipulate the CLOCK_MONOTONIC freq more drastically to align time.

Another more concrete benefit is that since CLOCK_MONOTONIC is frequency adjusted, its possible for slight inconsistencies to appear when using the lock-free ktime_get_mono_fast_ns() accessor that perf uses. With CLOCK_MONOTONIC_RAW, since there are no frequency adjustments made, inconsistencies shouldn't occur with the lock-free accessor.

thanks
-john

#4 lore raw
In reply to Drew Richardson
Quoted 7 lines · Drew Richardson

I'm collecting and merging data from perf, with Android Atrace data (writes to /sys/kernel/debug/tracing/trace_marker) which ends up in the ftrace stream and other measurements collected from userspace. Currently the only clock readable from userspace, supported by perf and by ftrace is CLOCK_MONOTONIC. However this clock is affected by the incremental adjustments performed by adjtime(3) and NTP.

Which should not matter at all, right? If both sources are using the same clock (they are) then its trivial to merge them and everything works as expected.

Quoted 2 lines

But I'd prefer to use a clock that is advancing at a consistent rate, hence CLOCK_MONOTONIC_RAW.

Right, Mathieu is asking _why_ you prefer that?

#5 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · Drew Richardson

I'm collecting and merging data from perf, with Android Atrace data (writes to /sys/kernel/debug/tracing/trace_marker) which ends up in the ftrace stream and other measurements collected from userspace. Currently the only clock readable from userspace, supported by perf and by ftrace is CLOCK_MONOTONIC. However this clock is affected by the incremental adjustments performed by adjtime(3) and NTP.

Quoted 9 lines

Which should not matter at all, right? If both sources are using the same clock (they are) then its trivial to merge them and everything works as expected.

Quoted 2 lines

But I'd prefer to use a clock that is advancing at a consistent rate, hence CLOCK_MONOTONIC_RAW.

Right, Mathieu is asking _why_ you prefer that?

I think John described it well.

Quoted 10 lines · John Stultz

... [D]uring early initialization, ntp can
manipulate the CLOCK_MONOTONIC freq more drastically to align time.

Another more concrete benefit is that since CLOCK_MONOTONIC is frequency adjusted, its possible for slight inconsistencies to appear when using the lock-free ktime_get_mono_fast_ns() accessor that perf uses. With CLOCK_MONOTONIC_RAW, since there are no frequency adjustments made, inconsistencies shouldn't occur with the lock-free accessor.

CLOCK_MONOTONIC_RAW will advance more constantly than CLOCK_MONOTONIC.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that ntp is running and potentially making larger adjustments to CLOCK_MONOTONIC. If ntp is adjusting CLOCK_MONOTONIC to advance more rapidly, the program will appear to use fewer instructions per second but run longer than it would if CLOCK_MONOTONIC_RAW had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Conversely if ntp is adjusting CLOCK_MONOTONIC to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but I'd like to remove ntp from the list.

Thanks,

Drew

maintainer
#6 lore raw
Quoted 12 lines · On Tue, 5 May 2015 07:54:46 -0700 Drew Richardson <[email protected]>…

CLOCK_MONOTONIC_RAW will advance more constantly than CLOCK_MONOTONIC.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that ntp is running and potentially making larger adjustments to CLOCK_MONOTONIC. If ntp is adjusting CLOCK_MONOTONIC to advance more rapidly, the program will appear to use fewer instructions per second but run longer than it would if CLOCK_MONOTONIC_RAW had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Quoted 5 lines

Conversely if ntp is adjusting CLOCK_MONOTONIC to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but I'd like to remove ntp from the list.

What's the consensus on this patch? Everyone OK with it? If so, can you please post a new patch with the proper change log. And can everyone else give acks. I can take it in my tree.

Thanks,

-- Steve

reviewer Acked-by
#7 lore raw

----- Original Message -----

Quoted 21 lines
Quoted 12 lines · On Tue, 5 May 2015 07:54:46 -0700 Drew Richardson <[email protected]>…

CLOCK_MONOTONIC_RAW will advance more constantly than CLOCK_MONOTONIC.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that ntp is running and potentially making larger adjustments to CLOCK_MONOTONIC. If ntp is adjusting CLOCK_MONOTONIC to advance more rapidly, the program will appear to use fewer instructions per second but run longer than it would if CLOCK_MONOTONIC_RAW had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Quoted 5 lines

Conversely if ntp is adjusting CLOCK_MONOTONIC to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but I'd like to remove ntp from the list.

Quoted 3 lines

What's the consensus on this patch? Everyone OK with it? If so, can you please post a new patch with the proper change log. And can everyone else give acks. I can take it in my tree.

I can see it being useful for tracing early boot, e.g. when debugging issues with NTP. So adding it to ftrace makes sense to me.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
maintainer
#8 lore raw
In reply to Drew Richardson
Quoted 12 lines · On Tue, 5 May 2015 07:54:46 -0700 Drew Richardson <[email protected]>…

CLOCK_MONOTONIC_RAW will advance more constantly than CLOCK_MONOTONIC.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that ntp is running and potentially making larger adjustments to CLOCK_MONOTONIC. If ntp is adjusting CLOCK_MONOTONIC to advance more rapidly, the program will appear to use fewer instructions per second but run longer than it would if CLOCK_MONOTONIC_RAW had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Quoted 5 lines

Conversely if ntp is adjusting CLOCK_MONOTONIC to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but I'd like to remove ntp from the list.

This is a nice description, and was expecting to see it in the change log of the latest patch. Can you resend with a more detailed description (like the above).

Thanks!

-- Steve

#9 lore raw
Quoted 21 lines · Steven Rostedt
Quoted 12 lines · On Tue, 5 May 2015 07:54:46 -0700 Drew Richardson <[email protected]>…

CLOCK_MONOTONIC_RAW will advance more constantly than CLOCK_MONOTONIC.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that ntp is running and potentially making larger adjustments to CLOCK_MONOTONIC. If ntp is adjusting CLOCK_MONOTONIC to advance more rapidly, the program will appear to use fewer instructions per second but run longer than it would if CLOCK_MONOTONIC_RAW had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Quoted 5 lines

Conversely if ntp is adjusting CLOCK_MONOTONIC to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but I'd like to remove ntp from the list.

Quoted 8 lines

This is a nice description, and was expecting to see it in the change log of the latest patch. Can you resend with a more detailed description (like the above).

Thanks!

-- Steve

Sorry about that, thanks for your patience.

#10 lore raw

PATCH v3 1/1 ftrace: Provide trace clock monotonic raw

In reply to Steven Rostedt

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. The advantage of the monotonic raw clock is that it will advance more constantly than the monotonic clock.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that NTP is running and potentially making larger adjustments to the monotonic clock. If NTP is adjusting the monotonic clock to advance more rapidly, the program will appear to use fewer instructions per second but run longer than if the monotonic raw clock had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Conversely if NTP is adjusting the monotonic clock to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but let's remove NTP from the list.

The monotonic raw clock can also be useful for tracing early boot, e.g. when debugging issues with NTP.

---
 kernel/trace/trace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/trace.c +1 -0
index 05330494a0df..458031c31a37 100644
@@ -876,6 +876,7 @@ static struct {
 	{ trace_clock_jiffies,		"uptime",	0 },
 	{ trace_clock,			"perf",		1 },
 	{ ktime_get_mono_fast_ns,	"mono",		1 },
+	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
 	ARCH_TRACE_CLOCKS
 };
 
Signature · 1 line
2.1.4
maintainer
#11 lore raw
Quoted 16 lines · On Fri, 8 May 2015 07:30:39 -0700 Drew Richardson <[email protected]>…

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. The advantage of the monotonic raw clock is that it will advance more constantly than the monotonic clock.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that NTP is running and potentially making larger adjustments to the monotonic clock. If NTP is adjusting the monotonic clock to advance more rapidly, the program will appear to use fewer instructions per second but run longer than if the monotonic raw clock had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Quoted 9 lines

Conversely if NTP is adjusting the monotonic clock to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but let's remove NTP from the list.

The monotonic raw clock can also be useful for tracing early boot, e.g. when debugging issues with NTP.

Peter, Thomas, John, you OK with this?

-- Steve

Quoted 18 lines
---
 kernel/trace/trace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/trace.c +1 -0
index 05330494a0df..458031c31a37 100644
@@ -876,6 +876,7 @@ static struct {
 	{ trace_clock_jiffies,		"uptime",	0 },
 	{ trace_clock,			"perf",		1 },
 	{ ktime_get_mono_fast_ns,	"mono",		1 },
+	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
 	ARCH_TRACE_CLOCKS
 };
 
#12 lore raw
Quoted 25 lines · Steven Rostedt
Quoted 22 lines · On Fri, 8 May 2015 07:30:39 -0700 Drew Richardson <[email protected]>…

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. The advantage of the monotonic raw clock is that it will advance more constantly than the monotonic clock.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that NTP is running and potentially making larger adjustments to the monotonic clock. If NTP is adjusting the monotonic clock to advance more rapidly, the program will appear to use fewer instructions per second but run longer than if the monotonic raw clock had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Conversely if NTP is adjusting the monotonic clock to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but let's remove NTP from the list.

Quoted 5 lines
Quoted 3 lines

The monotonic raw clock can also be useful for tracing early boot, e.g. when debugging issues with NTP.

Peter, Thomas, John, you OK with this?

Yea. No objections from me wrt the functionality of the patch.

I'd just again maybe caution folks to not go too far in assuming CLOCK_MONOTONIC_RAW doesn't have frequency changes, as the underlying hardware will drift due to varying thermal conditions.

thanks
-john

maintainer
#13 lore raw
Quoted 1 line · On Fri, 8 May 2015 09:05:24 -0700 John Stultz <[email protected]> wrote:

Yea. No objections from me wrt the functionality of the patch.

Can I take that as an Acked-by?

Quoted 4 lines

I'd just again maybe caution folks to not go too far in assuming CLOCK_MONOTONIC_RAW doesn't have frequency changes, as the underlying hardware will drift due to varying thermal conditions.

I totally understand this, but that's a hardware limitation (outside the control of software). But CLOCK_MONOTONIC can drift due to software updates, which to me, is a significant difference.

-- Steve

#15 lore raw
In reply to Steven Rostedt
Quoted 25 lines · Steven Rostedt
Quoted 22 lines · On Fri, 8 May 2015 07:30:39 -0700 Drew Richardson <[email protected]>…

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. The advantage of the monotonic raw clock is that it will advance more constantly than the monotonic clock.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that NTP is running and potentially making larger adjustments to the monotonic clock. If NTP is adjusting the monotonic clock to advance more rapidly, the program will appear to use fewer instructions per second but run longer than if the monotonic raw clock had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Conversely if NTP is adjusting the monotonic clock to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but let's remove NTP from the list.

Quoted 5 lines
Quoted 3 lines

The monotonic raw clock can also be useful for tracing early boot, e.g. when debugging issues with NTP.

Peter, Thomas, John, you OK with this?

Sure.

#16 lore raw
In reply to Steven Rostedt
Quoted 25 lines · Steven Rostedt
Quoted 22 lines · On Fri, 8 May 2015 07:30:39 -0700 Drew Richardson <[email protected]>…

Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. The advantage of the monotonic raw clock is that it will advance more constantly than the monotonic clock.

Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that NTP is running and potentially making larger adjustments to the monotonic clock. If NTP is adjusting the monotonic clock to advance more rapidly, the program will appear to use fewer instructions per second but run longer than if the monotonic raw clock had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected.

Conversely if NTP is adjusting the monotonic clock to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but let's remove NTP from the list.

Quoted 5 lines
Quoted 3 lines

The monotonic raw clock can also be useful for tracing early boot, e.g. when debugging issues with NTP.

Peter, Thomas, John, you OK with this?

Yup.

maintainer
#17 lore raw
Quoted 3 lines · On Tue, 12 May 2015 16:26:27 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 1 line

Peter, Thomas, John, you OK with this?

Yup.

I'll take that as an Ack.

OK, I'm applying it.

-- Steve