1 //===-- X86Counter.h --------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Perf counter that reads the LBRs for measuring the benchmarked block's
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
18 #include "../PerfHelper.h"
19 #include "llvm/Support/Error.h"
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)
29 class X86LbrPerfEvent
: public pfm::PerfEvent
{
31 X86LbrPerfEvent(unsigned SamplingPeriod
);
34 class X86LbrCounter
: public pfm::Counter
{
36 static llvm::Error
checkLbrSupport();
38 explicit X86LbrCounter(pfm::PerfEvent
&&Event
);
40 virtual ~X86LbrCounter();
42 void start() override
;
44 llvm::Expected
<llvm::SmallVector
<int64_t, 4>>
45 readOrError(StringRef FunctionBytes
) const override
;
48 llvm::Expected
<llvm::SmallVector
<int64_t, 4>>
49 doReadCounter(const void *From
, const void *To
) const;
51 void *MMappedBuffer
= nullptr;
54 } // namespace exegesis
57 #endif // defined(__linux__) && defined(HAVE_LIBPFM) &&
58 // defined(LIBPFM_HAS_FIELD_CYCLES)
60 #endif // LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H