Skip to content

Commit

Permalink
[llvm-exegesis] Delegate the decision of cycle counter name to the ta…
Browse files Browse the repository at this point in the history
…rget

Currently the cycle counter is taken from the subtarget schedule model, which
isn't any use if the subtarget doesn't have one. Delegate the decision to the
target benchmark runner, as it may know better what to do in that case, with
the default being the current behaviour.

Differential Revision: https://reviews.llvm.org/D48779

llvm-svn: 336099
  • Loading branch information
john-brawn-arm committed Jul 2, 2018
1 parent 4ebba90 commit 8fc5ec7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
19 changes: 14 additions & 5 deletions llvm/tools/llvm-exegesis/lib/Latency.cpp
Expand Up @@ -94,19 +94,28 @@ LatencyBenchmarkRunner::generatePrototype(unsigned Opcode) const {
return generateTwoInstructionPrototype(Instr);
}

const char *LatencyBenchmarkRunner::getCounterName() const {
if (!State.getSubtargetInfo().getSchedModel().hasExtraProcessorInfo())
llvm::report_fatal_error("sched model is missing extra processor info!");
const char *CounterName = State.getSubtargetInfo()
.getSchedModel()
.getExtraProcessorInfo()
.PfmCounters.CycleCounter;
if (!CounterName)
llvm::report_fatal_error("sched model does not define a cycle counter");
return CounterName;
}

std::vector<BenchmarkMeasure>
LatencyBenchmarkRunner::runMeasurements(const ExecutableFunction &Function,
const unsigned NumRepetitions) const {
// Cycle measurements include some overhead from the kernel. Repeat the
// measure several times and take the minimum value.
constexpr const int NumMeasurements = 30;
int64_t MinLatency = std::numeric_limits<int64_t>::max();
const char *CounterName = State.getSubtargetInfo()
.getSchedModel()
.getExtraProcessorInfo()
.PfmCounters.CycleCounter;
const char *CounterName = getCounterName();
if (!CounterName)
llvm::report_fatal_error("sched model does not define a cycle counter");
llvm::report_fatal_error("could not determine cycle counter name");
const pfm::PerfEvent CyclesPerfEvent(CounterName);
if (!CyclesPerfEvent.valid())
llvm::report_fatal_error("invalid perf event");
Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/llvm-exegesis/lib/Latency.h
Expand Up @@ -38,6 +38,8 @@ class LatencyBenchmarkRunner : public BenchmarkRunner {
std::vector<BenchmarkMeasure>
runMeasurements(const ExecutableFunction &EF,
const unsigned NumRepetitions) const override;

virtual const char *getCounterName() const;
};

} // namespace exegesis
Expand Down
4 changes: 0 additions & 4 deletions llvm/tools/llvm-exegesis/llvm-exegesis.cpp
Expand Up @@ -140,10 +140,6 @@ void benchmarkMain() {
return;
}

// FIXME: Do not require SchedModel for latency.
if (!State.getSubtargetInfo().getSchedModel().hasExtraProcessorInfo())
llvm::report_fatal_error("sched model is missing extra processor info!");

const std::unique_ptr<BenchmarkRunner> Runner =
State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
if (!Runner) {
Expand Down

0 comments on commit 8fc5ec7

Please sign in to comment.