61 lines · c
1//===-- X86Counter.h --------------------------------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// Perf counter that reads the LBRs for measuring the benchmarked block's11/// throughput.12///13/// More info at: https://lwn.net/Articles/68098514//===----------------------------------------------------------------------===//15#ifndef LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H16#define LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H17 18#include "../PerfHelper.h"19#include "llvm/Support/Error.h"20 21// FIXME: Use appropriate wrappers for poll.h and mman.h22// to support Windows and remove this linux-only guard.23#if defined(__linux__) && defined(HAVE_LIBPFM) && \24 defined(LIBPFM_HAS_FIELD_CYCLES)25 26namespace llvm {27namespace exegesis {28 29class X86LbrPerfEvent : public pfm::PerfEvent {30public:31 X86LbrPerfEvent(unsigned SamplingPeriod);32};33 34class X86LbrCounter : public pfm::CounterGroup {35public:36 static Error checkLbrSupport();37 38 explicit X86LbrCounter(pfm::PerfEvent &&Event);39 40 virtual ~X86LbrCounter();41 42 void start() override;43 44 Expected<SmallVector<int64_t, 4>>45 readOrError(StringRef FunctionBytes) const override;46 47private:48 Expected<SmallVector<int64_t, 4>> doReadCounter(const void *From,49 const void *To) const;50 51 void *MMappedBuffer = nullptr;52};53 54} // namespace exegesis55} // namespace llvm56 57#endif // defined(__linux__) && defined(HAVE_LIBPFM) &&58 // defined(LIBPFM_HAS_FIELD_CYCLES)59 60#endif // LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H61