This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add POSIX implementation for SYSTEM_CLOCK
ClosedPublic

Authored by rovka on Jul 14 2021, 3:40 AM.

Details

Summary

This is very similar to CPU_TIME, except that we return nanoseconds
rather than seconds. This means we're potentially dealing with rather
large numbers, so we'll have to wrap around to avoid overflows.

Diff Detail

Event Timeline

rovka created this revision.Jul 14 2021, 3:40 AM
rovka requested review of this revision.Jul 14 2021, 3:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2021, 3:40 AM
klausler added inline comments.Jul 16 2021, 11:39 AM
flang/runtime/time-intrinsic.cpp
110

Please use modern braced initializers in the runtime; they're safer.

135

Can be constexpr.

Since count_t is a 64-bit signed integer, max_secs is going to be ca. 8e9, or roughly 300 years. That might make it hard to test your overflow cases.

rovka added inline comments.Jul 26 2021, 10:04 AM
flang/runtime/time-intrinsic.cpp
135

Well, the POSIX epoch ought to be set to 1970, and most code survives longer than people expect it to, so I'm sure it will be relevant :P
Anyway, on a serious note, are you saying we should skip the wrapping altogether and just return tv_nsec + tv_sec * NSECS_PER_SEC?

klausler added inline comments.Jul 26 2021, 10:11 AM
flang/runtime/time-intrinsic.cpp
135

No, I was pointing out that the overflow path isn't tested. Not a big deal.

rovka updated this revision to Diff 361960.Jul 27 2021, 2:58 AM

Address review comments.

jeanPerier accepted this revision.Aug 4 2021, 9:51 AM

LGTM and thanks !

This revision is now accepted and ready to land.Aug 4 2021, 9:51 AM
This revision was landed with ongoing or failed builds.Aug 19 2021, 1:11 AM
This revision was automatically updated to reflect the committed changes.