10b57cec5SDimitry Andric//===-- xray_powerpc64.inc --------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric// 90b57cec5SDimitry Andric// This file is a part of XRay, a dynamic runtime instrumentation system. 100b57cec5SDimitry Andric// 110b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric#include <cstdint> 140b57cec5SDimitry Andric#include <mutex> 15*f5024381SPiotr Kubaj#ifdef __linux__ 160b57cec5SDimitry Andric#include <sys/platform/ppc.h> 17*f5024381SPiotr Kubaj#elif defined(__FreeBSD__) 18*f5024381SPiotr Kubaj#include <sys/types.h> 19*f5024381SPiotr Kubaj#include <sys/sysctl.h> 20*f5024381SPiotr Kubaj 21*f5024381SPiotr Kubaj#define __ppc_get_timebase __builtin_ppc_get_timebase 22*f5024381SPiotr Kubaj 23*f5024381SPiotr Kubajuint64_t __ppc_get_timebase_freq (void) 24*f5024381SPiotr Kubaj{ 25*f5024381SPiotr Kubaj uint64_t tb_freq = 0; 26*f5024381SPiotr Kubaj size_t length = sizeof(tb_freq); 27*f5024381SPiotr Kubaj sysctlbyname("kern.timecounter.tc.timebase.frequency", &tb_freq, &length, nullptr, 0); 28*f5024381SPiotr Kubaj return tb_freq; 29*f5024381SPiotr Kubaj} 30*f5024381SPiotr Kubaj#endif 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric#include "xray_defs.h" 330b57cec5SDimitry Andric 340b57cec5SDimitry Andricnamespace __xray { 350b57cec5SDimitry Andric 360b57cec5SDimitry AndricALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT { 370b57cec5SDimitry Andric CPU = 0; 380b57cec5SDimitry Andric return __ppc_get_timebase(); 390b57cec5SDimitry Andric} 400b57cec5SDimitry Andric 410b57cec5SDimitry Andricinline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT { 420b57cec5SDimitry Andric static std::mutex M; 430b57cec5SDimitry Andric std::lock_guard<std::mutex> Guard(M); 440b57cec5SDimitry Andric return __ppc_get_timebase_freq(); 450b57cec5SDimitry Andric} 460b57cec5SDimitry Andric 470b57cec5SDimitry Andricinline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT { 480b57cec5SDimitry Andric return true; 490b57cec5SDimitry Andric} 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric} // namespace __xray 52