X86Counter.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "../PerfHelper.h"
  18. #include "llvm/Support/Error.h"
  19. // FIXME: Use appropriate wrappers for poll.h and mman.h
  20. // to support Windows and remove this linux-only guard.
  21. #if defined(__linux__) && defined(HAVE_LIBPFM) && \
  22. defined(LIBPFM_HAS_FIELD_CYCLES)
  23. namespace llvm {
  24. namespace exegesis {
  25. class X86LbrPerfEvent : public pfm::PerfEvent {
  26. public:
  27. X86LbrPerfEvent(unsigned SamplingPeriod);
  28. };
  29. class X86LbrCounter : public pfm::Counter {
  30. public:
  31. static llvm::Error checkLbrSupport();
  32. explicit X86LbrCounter(pfm::PerfEvent &&Event);
  33. virtual ~X86LbrCounter();
  34. void start() override;
  35. llvm::Expected<llvm::SmallVector<int64_t, 4>>
  36. readOrError(StringRef FunctionBytes) const override;
  37. private:
  38. llvm::Expected<llvm::SmallVector<int64_t, 4>>
  39. doReadCounter(const void *From, const void *To) const;
  40. void *MMappedBuffer = nullptr;
  41. };
  42. } // namespace exegesis
  43. } // namespace llvm
  44. #endif // defined(__linux__) && defined(HAVE_LIBPFM) &&
  45. // defined(LIBPFM_HAS_FIELD_CYCLES)
  46. #endif // LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H