lkml.org 
[lkml]   [2014]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] tracing: fix uptime overflow problem
On Sat, 28 Jun 2014 19:10:00 +0800
Xie XiuQi <xiexiuqi@huawei.com> wrote:


> /*
> - * trace_jiffy_clock(): Simply use jiffies as a clock counter.
> + * trace_clock_uptime(): Use lockless version __current_kernel_time,
> + * so it's safe in NMI context.
> */
> -u64 notrace trace_clock_jiffies(void)
> +u64 notrace trace_clock_uptime(void)
> {
> - u64 jiffy = jiffies - INITIAL_JIFFIES;
> + struct timespec uptime, now, boottime;
> +
> + /* Does not take xtime_lock, so it's safe in NMI context. */
> + now = __current_kernel_time();

The problem with this patch is that you have a race:

ts.tv_sec = tk->xtime_sec;
ts.tv_nsec = (long)(tk->xtime_nsec >> tk->shift);

There's a chance that gets done between the update of xtime_sec an
xtime_nsec, and make time go backwards.

This call is lockless but is not reliable.

-- Steve


> + getboottime(&boottime);
> + uptime = timespec_sub(now, boottime);
>
> /* Return nsecs */
> - return (u64)jiffies_to_usecs(jiffy) * 1000ULL;
> + return timespec_to_ns(&uptime);
> }
>
> /*



\
 
 \ /
  Last update: 2014-06-30 23:41    [W:0.055 / U:1.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site