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