[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-25 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |MOVED

--- Comment #8 from Jonathan Wakely  ---
OK, let's close this as MOVED then, thanks!

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-25 Thread anthony.ajw at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #7 from Anthony Williams  ---
Reported as ubuntu bug:
https://bugs.launchpad.net/ubuntu/+source/linux-signed-oem/+bug/1853807

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #6 from Jonathan Wakely  ---
https://bugzilla.kernel.org/ but I think they prefer bugs to be reported to
distros unless you're actually using the upstream kernel. So report it to
Ubuntu (but mention it's also seen in Fedora).

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-21 Thread anthony.ajw at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #5 from Anthony Williams  ---
Where can I file a bug in the vDSO?

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #4 from Jonathan Wakely  ---
gettimeofday agrees with clock_gettime(CLOCK_REALTIME):

void dumpNow() {
  struct timespec ts;
  clock_gettime(CLOCK_REALTIME, );
  auto const now = time(nullptr);
  struct timeval tv;
  gettimeofday(, NULL);
  tm nowTm;
  localtime_r(_sec, );
  std::cout << "Now (clock_gettime) time is " << ts.tv_sec << std::setw(9) <<
std::setfill('0') << ts.tv_nsec
<< "\n=>" << ts.tv_sec << "(time_t)\n=>" << nowTm.tm_hour
<< ":" << nowTm.tm_min << ":" << nowTm.tm_sec << std::endl;

  localtime_r(, );
  std::cout << "Now (time(nullptr)) time is " << now << "(time_t)\n=>"
<< nowTm.tm_hour << ":" << nowTm.tm_min << ":" << nowTm.tm_sec
<< std::endl;

  localtime_r(_sec, );
  std::cout << "Now (gettimeofday) time is " << tv.tv_sec << std::setw(6) <<
std::setfill('0') << tv.tv_usec << "\n=>" << tv.tv_sec << "(time_t)\n=>"
<< nowTm.tm_hour << ":" << nowTm.tm_min << ":" << nowTm.tm_sec
<< std::endl;
}

Now (clock_gettime) time is 1574344361836948044
=>1574344361(time_t)
=>13:52:41
Now (time(nullptr)) time is 1574344361(time_t)
=>13:52:41
Now (gettimeofday) time is 1574344361836949
=>1574344361(time_t)
=>13:52:41
Now (clock_gettime) time is 1574344363000108423
=>1574344363(time_t)
=>13:52:43
Now (time(nullptr)) time is 1574344362(time_t)
=>13:52:42
Now (gettimeofday) time is 1574344363000108
=>1574344363(time_t)
=>13:52:43

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #3 from Jonathan Wakely  ---
(In reply to Jonathan Wakely from comment #1)
> I can reproduce it, but I think this has to be a glibc problem. Libstdc++
> simply calls clock_gettime(3), and both that and time(3) come from glibc.

Correction, they come from the linux kernel's vDSO, not glibc. Apparently there
are different paths for computing the seconds for time(3) and the
CLOCK_REALTIME result.

Either way, there's nothing we can do about it in libstdc++.

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #2 from Jonathan Wakely  ---
I see the same result when using clock_gettime directly instead of
system_clock::now()

#include 
#include 
#include 
#include 

void dumpNow() {
  struct timespec ts;
  clock_gettime(CLOCK_REALTIME, );
  auto const nowSc = ts.tv_sec;
  auto const now = time(nullptr);
  tm nowTm;
  localtime_r(, );
  std::cout << "Now (sc) time is " << ts.tv_sec << std::setw(9) <<
std::setfill('0') << ts.tv_nsec
<< " (system clock)\n=>" << nowSc << "(time_t)\n=>" <<
nowTm.tm_hour
<< ":" << nowTm.tm_min << ":" << nowTm.tm_sec << std::endl;

  localtime_r(, );
  std::cout << "Now (time(nullptr)) time is " << now << "(time_t)\n=>"
<< nowTm.tm_hour << ":" << nowTm.tm_min << ":" << nowTm.tm_sec
<< std::endl;
}
int main() {
  dumpNow();
  std::this_thread::sleep_until(
  std::chrono::system_clock::from_time_t(time(nullptr) + 2));
  dumpNow();
}

Now (sc) time is 1574343394343888130 (system clock)
=>1574343394(time_t)
=>13:36:34
Now (time(nullptr)) time is 1574343394(time_t)
=>13:36:34
Now (sc) time is 157434339683583 (system clock)
=>1574343396(time_t)
=>13:36:36
Now (time(nullptr)) time is 1574343395(time_t)
=>13:36:35

[Bug libstdc++/92616] Inconsistency in time between system_clock::now() and time(nullptr)

2019-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92616

--- Comment #1 from Jonathan Wakely  ---
I can reproduce it, but I think this has to be a glibc problem. Libstdc++
simply calls clock_gettime(3), and both that and time(3) come from glibc.