1 //===-- xray_emulate_tsc.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of XRay, a dynamic runtime instrumentation system.
12 //===----------------------------------------------------------------------===//
13 #ifndef XRAY_EMULATE_TSC_H
14 #define XRAY_EMULATE_TSC_H
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_internal_defs.h"
18 #include "xray_defs.h"
25 static constexpr uint64_t NanosecondsPerSecond = 1000ULL * 1000 * 1000;
27 ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
29 int result = clock_gettime(CLOCK_REALTIME, &TS);
31 Report("clock_gettime(2) returned %d, errno=%d.", result, int(errno));
36 return TS.tv_sec * NanosecondsPerSecond + TS.tv_nsec;
40 #endif // XRAY_EMULATE_TSC_H