[XRay] Update TSC math to handle wraparound
authorDean Michael Berris <dberris@google.com>
Mon, 5 Nov 2018 05:43:22 +0000 (05:43 +0000)
committerDean Michael Berris <dberris@google.com>
Mon, 5 Nov 2018 05:43:22 +0000 (05:43 +0000)
commit1e255e7a7b3752ef7f786506e695f0f7b58e2339
tree4207c46d48c69f0b282489ca2253d0d9c77e9075
parent30b627e5c9a4bec17cd1ee53533fa685913971ce
[XRay] Update TSC math to handle wraparound

Summary:
Prior to this change, we can run into situations where the TSC we're
getting when exiting a function is less than the TSC we got when
entering it. This would sometimes cause the counter for cumulative call
times overflow, which was erroneously also being stored as a signed
64-bit integer.

This change addresses both these issues while adding provisions for
tracking CPU migrations. We do this because moving from one CPU to
another doesn't guarantee that the timestamp counter for some
architectures aren't guaranteed to be synchronised. For the moment, we
leave the provisions there until we can update the data format to
include the counting of CPU migrations we can catch.

We update the necessary tests as well, ensuring that our expectations
for the cycle accounting to be met in case of counter wraparound.

Reviewers: mboerger

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D54088

llvm-svn: 346116
compiler-rt/lib/xray/tests/unit/function_call_trie_test.cc
compiler-rt/lib/xray/tests/unit/profile_collector_test.cc
compiler-rt/lib/xray/xray_function_call_trie.h
compiler-rt/lib/xray/xray_profiling.cc