Re: [PATCH] timekeeping: Fix overflow in rawtime tv_nsec on 32 bitarchs

From: Jason Wessel
Date: Fri Aug 06 2010 - 11:10:01 EST

On 08/05/2010 05:17 PM, john stultz wrote:
> On Thu, 2010-08-05 at 07:28 -0500, Jason Wessel wrote:
>> The tv_nsec is a long and when added to the shift value it can wrap
>> and become negative which later causes looping problems in the
>> getrawmonotonic(). The edge case occurs when the system has slept for
>> a short period of time of ~2 seconds.
> Ah, good catch!
> I reworked some of the variable names to make a little more sense and
> simplified the accumulation. Do you mind giving this a test in your
> environment that triggered the issue to make sure nothing else slipped
> in?

No problem.

This looks good to me. I even increased the delay and I can see it recovers properly.

The instrumentation shows raw_nsecs would have otherwise been negative going from 90.* to 97.* in the log.

<...>-4801 [000] 90.105084: update_wall_time: raw_nsecs: 37283ea1
<...>-4801 [000] 90.109078: update_wall_time: raw_nsecs: 376547b4
<...>-4801 [000] 97.694264: update_wall_time: raw_nsecs: b1776db4
<...>-4801 [000] 97.694270: update_wall_time: raw_nsecs: b453ffb4
<...>-4801 [000] 97.694272: update_wall_time: raw_nsecs: 7b95c7b4

Note that I had instrumented it just after:

raw_nsecs += raw_time.tv_nsec;

We should send this over to -stable when it is considered baked because this was found in the 2.6.35 and may be a problem elsewhere as well.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at