git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] git-compat-util: use gettimeofday for current time

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 20, 2023, 16:33 UTC
Message-ID
<xmqqh6ufo01u.fsf@gitster.g>
In-Reply-To
<20230319193449.M629601@dcvr>
Eric Wong <e@80x24.org> writes:
Show 34 quoted lines
> Paul Eggert <eggert@cs.ucla.edu> wrote:
>> Use gettimeofday instead of time(NULL) to get current time.
>> This avoids clock skew on glibc 2.31+ on Linux, where in the
>> first 1 to 2.5 ms of every second, time(NULL) returns a
>> value that is one less than the tv_sec part of
>> higher-resolution timestamps such as those returned by
>> gettimeofday or timespec_get, or those in the file system.
>> There are similar clock skew problems on AIX and MS-Windows,
>> which have problems in the first 5 ms of every second.
>
> Wow, this is enlightening... and unfortunate :<
>
> I decided to check glibc archives to find more discussion on it.
> So far, I've found:
>
>   https://inbox.sourceware.org/libc-alpha/20230306160321.2942372-1-adhemerval.zanella@linaro.org/T/
>
> and the original bug:
>   https://sourceware.org/bugzilla/show_bug.cgi?id=30200
>
> And this is due to the time64 changes in glibc 2.31+?
> (<= 2.30 isn't affected?)
>
> <snip>
>
>> Yet another possibility would be to fix the Linux kernel so
>> that the time syscall is consistent with the other timestamp
>> syscalls.  I suppose this has not been done due to
>> performance implications.  (Git's use of timestamps is rare
>> enough that performance is not a significant consideration
>> for git.)  However, this wouldn't fix Git's problem on older
>> Linux kernels, or on AIX or MS-Windows.
>
> Agreed on the older kernels and other OSes part.

Yeah, this is interesting. I however wonder if we should follow our usual pattern of implementing git_time() with the identical function signature as what we replace (i.e. system's time()), and #undef/#define the symbol we replace with git_time, though. Wouldn't it make [1/2] a lot smaller and future-proof?

Previous: Eric WongNext: Junio C Hamano
Message 4 of 19 in “use gettimeofday for current time”
  1. 0/2 use gettimeofday for current timePaul Eggert, Mar 19, 2023
  2. 2/2 git-compat-util: use gettimeofday for current timePaul Eggert, Mar 19, 2023
  3. Eric WongMar 19, 2023
  4. Junio C HamanoMar 20, 2023
  5. Junio C HamanoMar 20, 2023
  6. Paul EggertMar 20, 2023
  7. Junio C HamanoMar 20, 2023
  8. Taylor BlauMar 20, 2023
  9. Taylor BlauMar 20, 2023
  10. 1/2 git-compat-util: time_now for current timePaul Eggert, Mar 19, 2023
  11. git-compat-util: use gettimeofday(2) for time(2)Junio C Hamano, Mar 20, 2023
  12. Paul EggertMar 20, 2023
  13. Junio C HamanoMar 21, 2023
  14. Konstantin KhomoutovMar 21, 2023
  15. Junio C HamanoMar 21, 2023
  16. Jeff KingMar 21, 2023
  17. Taylor BlauMar 21, 2023
  18. Junio C HamanoMar 21, 2023
  19. Jeff KingMar 22, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.