* Which type to use for timestamps: u64 or s64?
@ 2015-11-05 7:41 Hans Verkuil
2015-11-05 8:36 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Hans Verkuil @ 2015-11-05 7:41 UTC (permalink / raw)
To: Linux Media Mailing List, y2038, Arnd Bergmann; +Cc: Junghak Sung
Hi Arnd,
We're redesigning the timestamp handling in the video4linux subsystem moving away
from struct timeval to a single timestamp in ns (what ktime_get_ns() gives us).
But I was wondering: ktime_get_ns() gives a s64, so should we use s64 as well as
the timestamp type we'll eventually be returning to the user, or should we use u64?
The current patch series we made uses a u64, but I am now beginning to doubt that
decision.
Regards,
Hans
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Which type to use for timestamps: u64 or s64?
2015-11-05 7:41 Which type to use for timestamps: u64 or s64? Hans Verkuil
@ 2015-11-05 8:36 ` Arnd Bergmann
2015-11-05 9:05 ` [Y2038] " Hans Verkuil
0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2015-11-05 8:36 UTC (permalink / raw)
To: Hans Verkuil; +Cc: Linux Media Mailing List, y2038, Junghak Sung
On Thursday 05 November 2015 08:41:11 Hans Verkuil wrote:
> Hi Arnd,
>
> We're redesigning the timestamp handling in the video4linux subsystem moving away
> from struct timeval to a single timestamp in ns (what ktime_get_ns() gives us).
> But I was wondering: ktime_get_ns() gives a s64, so should we use s64 as well as
> the timestamp type we'll eventually be returning to the user, or should we use u64?
>
> The current patch series we made uses a u64, but I am now beginning to doubt that
> decision.
I would lean towards u64, but I don't think it really matters either way,
especially since all the drivers should be using monotonic timestamps now.
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Y2038] Which type to use for timestamps: u64 or s64?
2015-11-05 8:36 ` Arnd Bergmann
@ 2015-11-05 9:05 ` Hans Verkuil
2015-11-05 9:25 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Hans Verkuil @ 2015-11-05 9:05 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: y2038, Junghak Sung, Linux Media Mailing List
On 11/05/15 09:36, Arnd Bergmann wrote:
> On Thursday 05 November 2015 08:41:11 Hans Verkuil wrote:
>> Hi Arnd,
>>
>> We're redesigning the timestamp handling in the video4linux subsystem moving away
>> from struct timeval to a single timestamp in ns (what ktime_get_ns() gives us).
>> But I was wondering: ktime_get_ns() gives a s64, so should we use s64 as well as
>> the timestamp type we'll eventually be returning to the user, or should we use u64?
>>
>> The current patch series we made uses a u64, but I am now beginning to doubt that
>> decision.
>
> I would lean towards u64, but I don't think it really matters either way,
> especially since all the drivers should be using monotonic timestamps now.
One thing that might be easier if it is a s64 is when adding/subtracting offsets
from the timestamp. And the other reason is that a u64 gives a false view of the
underlying type. With a s64 it is clear that a timestamp will wrap around after
292 years instead of double that. Admittedly, not our problem, but if we ever send
a space probe to Alpha Centauri, then it might be nice to know as application
developer that you need to take special measures if the mission takes longer than
292 years :-)
Regards,
Hans
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Y2038] Which type to use for timestamps: u64 or s64?
2015-11-05 9:05 ` [Y2038] " Hans Verkuil
@ 2015-11-05 9:25 ` Arnd Bergmann
0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2015-11-05 9:25 UTC (permalink / raw)
To: Hans Verkuil; +Cc: y2038, Junghak Sung, Linux Media Mailing List
On Thursday 05 November 2015 10:05:44 Hans Verkuil wrote:
> On 11/05/15 09:36, Arnd Bergmann wrote:
> > On Thursday 05 November 2015 08:41:11 Hans Verkuil wrote:
> >> Hi Arnd,
> >>
> >> We're redesigning the timestamp handling in the video4linux subsystem moving away
> >> from struct timeval to a single timestamp in ns (what ktime_get_ns() gives us).
> >> But I was wondering: ktime_get_ns() gives a s64, so should we use s64 as well as
> >> the timestamp type we'll eventually be returning to the user, or should we use u64?
> >>
> >> The current patch series we made uses a u64, but I am now beginning to doubt that
> >> decision.
> >
> > I would lean towards u64, but I don't think it really matters either way,
> > especially since all the drivers should be using monotonic timestamps now.
>
> One thing that might be easier if it is a s64 is when adding/subtracting offsets
> from the timestamp. And the other reason is that a u64 gives a false view of the
> underlying type. With a s64 it is clear that a timestamp will wrap around after
> 292 years instead of double that. Admittedly, not our problem, but if we ever send
> a space probe to Alpha Centauri, then it might be nice to know as application
> developer that you need to take special measures if the mission takes longer than
> 292 years
There is another problem here if you are worried about the overflow: Unsigned
overflow is well-defined in C, i.e. (U64_MAX + 1) is known to be 0. However,
signed overflow is not defined in C for historic reasons, so taking the
result of (S64_MAX + 1) can have arbitrary results [1], including a kernel
oops, or random other things not related to the variable that carries the
result, if gcc decides that 'this cannot happen'.
Arnd
[1] http://stackoverflow.com/questions/3948479/integer-overflow-and-undefined-behavior
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-05 9:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-05 7:41 Which type to use for timestamps: u64 or s64? Hans Verkuil
2015-11-05 8:36 ` Arnd Bergmann
2015-11-05 9:05 ` [Y2038] " Hans Verkuil
2015-11-05 9:25 ` Arnd Bergmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.