Skip to content

Commit

Permalink
Revert "[llvm-exegesis] Add benchmark latency option on X86 that uses…
Browse files Browse the repository at this point in the history
… LBR for more precise measurements."

From @erichkeane:
```
This patch doesn't seem to build for me:
/iusers/ekeane1/workspaces/llvm-project/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp: In function ‘llvm::Error llvm::exegesis::parseDataBuffer(const char*, size_t, const void*, const void*, llvm::SmallVector<long int, 4>*)’:
/iusers/ekeane1/workspaces/llvm-project/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp:99:37: error: ‘struct perf_branch_entry’ has no member named ‘cycles’

CycleArray->push_back(Entry.cycles);
I'm on RHEL7, so I have kernel 3.10, so it doesn't have 'cycles'.

According ot this: https://elixir.bootlin.com/linux/v4.3/source/include/uapi/linux/perf_event.h#L963 kernel 4.3 is the first time that 'cycles' appeared in this structure.
```
  • Loading branch information
legrosbuffle committed Jul 17, 2020
1 parent 7ebc6be commit 6bddd09
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 416 deletions.
20 changes: 3 additions & 17 deletions llvm/docs/CommandGuide/llvm-exegesis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,10 @@ OPTIONS

.. option:: -mode=[latency|uops|inverse_throughput|analysis]

Specify the run mode. Note that some modes have additional requirements and options.
Specify the run mode. Note that if you pick `analysis` mode, you also need
to specify at least one of the `-analysis-clusters-output-file=` and
`-analysis-inconsistencies-output-file=`.

`latency` mode can be make use of either RDTSC or LBR.
`latency[LBR]` is only available on X86 (at least `Skylake`).
To run in this mode, a positive value must be specified for `x86-lbr-sample-period` and `--repetition-mode=loop`

In `analysis` mode, you also need to specify at least one of the
`-analysis-clusters-output-file=` and `-analysis-inconsistencies-output-file=`.

.. option:: -x86-lbr-sample-period=<nBranches/sample>

Specify the LBR sampling period - how many branches before we take a sample.
When a positive value is specified for this option and when the mode is `latency`,
we will use LBRs for measuring.
On choosing the "right" sampling period, a small value is preferred, but throttling
could occur if the sampling is too frequent. A prime number should be used to
avoid consistently skipping certain blocks.

.. option:: -repetition-mode=[duplicate|loop|min]

Specify the repetition mode. `duplicate` will create a large, straight line
Expand Down
4 changes: 0 additions & 4 deletions llvm/test/tools/llvm-exegesis/X86/lbr/Inputs/mov_add.att

This file was deleted.

31 changes: 0 additions & 31 deletions llvm/test/tools/llvm-exegesis/X86/lbr/lit.local.cfg

This file was deleted.

18 changes: 0 additions & 18 deletions llvm/test/tools/llvm-exegesis/X86/lbr/mov-add.s

This file was deleted.

5 changes: 3 additions & 2 deletions llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class FunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
static void
accumulateCounterValues(const llvm::SmallVector<int64_t, 4> &NewValues,
llvm::SmallVector<int64_t, 4> *Result) {

const size_t NumValues = std::max(NewValues.size(), Result->size());
if (NumValues > Result->size())
Result->resize(NumValues, 0);
Expand Down Expand Up @@ -105,10 +106,10 @@ class FunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
if (Crashed)
return make_error<SnippetCrash>("snippet crashed while running");
}

auto ValueOrError = Counter->readOrError(Function.getFunctionBytes());
auto ValueOrError = Counter->readOrError();
if (!ValueOrError)
return ValueOrError.takeError();

accumulateCounterValues(ValueOrError.get(), &CounterValues);
}
return CounterValues;
Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ int64_t Counter::read() const {
return -1;
}

llvm::Expected<llvm::SmallVector<int64_t, 4>>
Counter::readOrError(StringRef /*unused*/) const {
llvm::Expected<llvm::SmallVector<int64_t, 4>> Counter::readOrError() const {
int64_t Count = 0;
ssize_t ReadSize = ::read(FileDescriptor, &Count, sizeof(Count));
if (ReadSize != sizeof(Count))
Expand All @@ -153,8 +152,7 @@ void Counter::stop() {}

int64_t Counter::read() const { return 42; }

llvm::Expected<llvm::SmallVector<int64_t, 4>>
Counter::readOrError(StringRef /*unused*/) const {
llvm::Expected<llvm::SmallVector<int64_t, 4>> Counter::readOrError() const {
return llvm::make_error<llvm::StringError>("Not implemented",
llvm::errc::io_error);
}
Expand Down
15 changes: 4 additions & 11 deletions llvm/tools/llvm-exegesis/lib/PerfHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class PerfEvent {
// e.g. "snb_ep::INSTRUCTION_RETIRED:e=0:i=0:c=0:t=0:u=1:k=0:mg=0:mh=1"
StringRef getPfmEventString() const;

protected:
PerfEvent() = default;
std::string EventString;
private:
const std::string EventString;
std::string FullQualifiedEventString;
perf_event_attr *Attr;
};
Expand All @@ -88,17 +87,11 @@ class Counter {
int64_t read() const;

/// Returns the current value of the counter or error if it cannot be read.
/// FunctionBytes: The benchmark function being executed.
/// This is used to filter out the measurements to ensure they are only
/// within the benchmarked code.
/// If empty (or not specified), then no filtering will be done.
/// Not all counters choose to use this.
virtual llvm::Expected<llvm::SmallVector<int64_t, 4>>
readOrError(StringRef FunctionBytes = StringRef()) const;
virtual llvm::Expected<llvm::SmallVector<int64_t, 4>> readOrError() const;

virtual int numValues() const;

protected:
private:
PerfEvent Event;
#ifdef HAVE_LIBPFM
int FileDescriptor = -1;
Expand Down
1 change: 0 additions & 1 deletion llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ include_directories(
add_library(LLVMExegesisX86
STATIC
Target.cpp
X86Counter.cpp
)

llvm_update_compile_flags(LLVMExegesisX86)
Expand Down
44 changes: 0 additions & 44 deletions llvm/tools/llvm-exegesis/lib/X86/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,15 @@
#include "MCTargetDesc/X86BaseInfo.h"
#include "MCTargetDesc/X86MCTargetDesc.h"
#include "X86.h"
#include "X86Counter.h"
#include "X86RegisterInfo.h"
#include "X86Subtarget.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/MC/MCInstBuilder.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"

#include <memory>
#include <string>
#include <vector>

namespace llvm {
namespace exegesis {

static cl::OptionCategory
BenchmarkOptions("llvm-exegesis benchmark x86-options");

// If a positive value is specified, we are going to use the LBR in
// latency-mode.
//
// Note:
// - A small value is preferred, but too low a value could result in
// throttling.
// - A prime number is preferred to avoid always skipping certain blocks.
//
static cl::opt<unsigned> LbrSamplingPeriod(
"x86-lbr-sample-period",
cl::desc("The sample period (nbranches/sample), used for LBR sampling"),
cl::cat(BenchmarkOptions), cl::init(0));

// FIXME: Validates that repetition-mode is loop if LBR is requested.

// Returns a non-null reason if we cannot handle the memory references in this
// instruction.
static const char *isInvalidMemoryInstr(const Instruction &Instr) {
Expand Down Expand Up @@ -593,29 +568,10 @@ void ConstantInliner::initStack(unsigned Bytes) {
#include "X86GenExegesis.inc"

namespace {

class ExegesisX86Target : public ExegesisTarget {
public:
ExegesisX86Target() : ExegesisTarget(X86CpuPfmCounters) {}

Expected<std::unique_ptr<pfm::Counter>>
createCounter(StringRef CounterName, const LLVMState &State) const override {
// If LbrSamplingPeriod was provided, then ignore the
// CounterName because we only have one for LBR.
if (LbrSamplingPeriod > 0) {
// Can't use LBR without HAVE_LIBPFM, or __linux__ (for now)
#if defined(HAVE_LIBPFM) && defined(__linux__)
return std::make_unique<X86LbrCounter>(
X86LbrPerfEvent(LbrSamplingPeriod));
#else
return llvm::make_error<llvm::StringError>(
"LBR counter requested without HAVE_LIBPFM or running on Linux.",
llvm::errc::invalid_argument);
#endif
}
return ExegesisTarget::createCounter(CounterName, State);
}

private:
void addTargetSpecificPasses(PassManagerBase &PM) const override;

Expand Down
Loading

0 comments on commit 6bddd09

Please sign in to comment.