This is an archive of the discontinued LLVM Phabricator instance.

Bug fix for PR#43703
AbandonedPublic

Authored by rprichard on Oct 22 2019, 11:06 AM.

Details

Summary

https://PR43703 - std::steady_clock::now() frequently overflows on Windows

I'm putting this up for review because I'm not seeing an easy way to test this - and because I don't have a windows box handy.

Diff Detail

Event Timeline

mclow.lists created this revision.Oct 22 2019, 11:06 AM

I tested this patch, and it appears to fix the overflow problem.

(FWIW, I tested using https://gist.github.com/rprichard/bcff3b3fb0451207dc9f31ccbab938df on Wine and on Windows 10. For both targets, the performance counter frequency was 10MHz, so counter.QuadPart * nano::den had previously wrapped around about every 1845 seconds.)

I tested this patch, and it appears to fix the overflow problem.

(FWIW, I tested using https://gist.github.com/rprichard/bcff3b3fb0451207dc9f31ccbab938df on Wine and on Windows 10. For both targets, the performance counter frequency was 10MHz, so counter.QuadPart * nano::den had previously wrapped around about every 1845 seconds.)

@rprichard Thanks for testing this on Windows. Do you think it's possible to make that test program run for a shorter amount of time so that it can be added to our test suite (i.e. do you think the test would still be relevant if we made it run for a shorter amount of time)?

ldionne requested changes to this revision.Mar 25 2020, 8:52 AM

(requesting changes so it shows up in the review queue properly)

This revision now requires changes to proceed.Mar 25 2020, 8:52 AM

@rprichard Thanks for testing this on Windows. Do you think it's possible to make that test program run for a shorter amount of time so that it can be added to our test suite (i.e. do you think the test would still be relevant if we made it run for a shorter amount of time)?

I suppose a test would only need to sleep for a second or two total to exercise the new part1-vs-part2 logic. I'm not sure how much of the existing test would still be relevant.

Can the computation be split out from the Query calls, though? If we had an internal (Freq, Counter) -> time_point function, we could test that quickly.

I think this function assumes that the performance counter frequency is less than about 2**63 / 10**9, about 9.22GHz. It was 10MHz on the two targets I saw, but comments on the Internet suggest that it's sometimes 3MHz. I think this assumption is OK.

rprichard commandeered this revision.Sep 29 2022, 2:56 PM
rprichard added a reviewer: mclow.lists.
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2022, 2:56 PM
rprichard abandoned this revision.Sep 29 2022, 2:57 PM

A version of this fix was already merged in D93456.