Skip to content

Commit 58d4e21

Browse files
aeglrostedt
authored andcommitted
tracing: Fix wraparound problems in "uptime" trace clock
The "uptime" trace clock added in: commit 8aacf01 tracing: Add "uptime" trace clock that uses jiffies has wraparound problems when the system has been up more than 1 hour 11 minutes and 34 seconds. It converts jiffies to nanoseconds using: (u64)jiffies_to_usecs(jiffy) * 1000ULL but since jiffies_to_usecs() only returns a 32-bit value, it truncates at 2^32 microseconds. An additional problem on 32-bit systems is that the argument is "unsigned long", so fixing the return value only helps until 2^32 jiffies (49.7 days on a HZ=1000 system). Avoid these problems by using jiffies_64 as our basis, and not converting to nanoseconds (we do convert to clock_t because user facing API must not be dependent on internal kernel HZ values). Link: http://lkml.kernel.org/p/99d63c5bfe9b320a3b428d773825a37095bf6a51.1405708254.git.tony.luck@intel.com Cc: [email protected] # 3.10+ Fixes: 8aacf01 "tracing: Add "uptime" trace clock that uses jiffies" Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 9a3c414 commit 58d4e21

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static struct {
823823
{ trace_clock_local, "local", 1 },
824824
{ trace_clock_global, "global", 1 },
825825
{ trace_clock_counter, "counter", 0 },
826-
{ trace_clock_jiffies, "uptime", 1 },
826+
{ trace_clock_jiffies, "uptime", 0 },
827827
{ trace_clock, "perf", 1 },
828828
ARCH_TRACE_CLOCKS
829829
};

kernel/trace/trace_clock.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ u64 notrace trace_clock(void)
5959

6060
/*
6161
* trace_jiffy_clock(): Simply use jiffies as a clock counter.
62+
* Note that this use of jiffies_64 is not completely safe on
63+
* 32-bit systems. But the window is tiny, and the effect if
64+
* we are affected is that we will have an obviously bogus
65+
* timestamp on a trace event - i.e. not life threatening.
6266
*/
6367
u64 notrace trace_clock_jiffies(void)
6468
{
65-
u64 jiffy = jiffies - INITIAL_JIFFIES;
66-
67-
/* Return nsecs */
68-
return (u64)jiffies_to_usecs(jiffy) * 1000ULL;
69+
return jiffies_64_to_clock_t(jiffies_64 - INITIAL_JIFFIES);
6970
}
7071

7172
/*

0 commit comments

Comments
 (0)