1//===-- xray_powerpc64.inc --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of XRay, a dynamic runtime instrumentation system.
10//
11//===----------------------------------------------------------------------===//
12
13#include <cstdint>
14#include <mutex>
15#ifdef __linux__
16#include <sys/platform/ppc.h>
17#elif defined(__FreeBSD__)
18#include <sys/types.h>
19#include <sys/sysctl.h>
20
21#define __ppc_get_timebase __builtin_ppc_get_timebase
22
23uint64_t __ppc_get_timebase_freq (void)
24{
25  uint64_t tb_freq = 0;
26  size_t length = sizeof(tb_freq);
27  sysctlbyname("kern.timecounter.tc.timebase.frequency", &tb_freq, &length, nullptr, 0);
28  return tb_freq;
29}
30#endif
31
32#include "xray_defs.h"
33
34namespace __xray {
35
36ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
37  CPU = 0;
38  return __ppc_get_timebase();
39}
40
41inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
42  static std::mutex M;
43  std::lock_guard<std::mutex> Guard(M);
44  return __ppc_get_timebase_freq();
45}
46
47inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT {
48  return true;
49}
50
51} // namespace __xray
52