Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions llvm/include/llvm/Target/TargetPfmCounters.td
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ class PfmIssueCounter<string resource_name, string counter>
string ResourceName = resource_name;
}

class ValidationEvent <int event_number> {
int EventNumber = event_number;
}

def L1DCacheLoadMiss : ValidationEvent<0>;
def InstructionRetired : ValidationEvent<1>;
def DataTLBLoadMiss : ValidationEvent<2>;
def DataTLBStoreMiss : ValidationEvent<3>;

// Validation counters can be tied to a specific event
class PfmValidationCounter<ValidationEvent event_type, string counter>
: PfmCounter<counter> {
// The name of the event that the validation counter detects.
ValidationEvent EventType = event_type;
}

def NoPfmCounter : PfmCounter <""> {}

// Set of PfmCounters for measuring sched model characteristics.
Expand All @@ -38,6 +54,9 @@ class ProcPfmCounters {
PfmCounter UopsCounter = NoPfmCounter;
// Processors can define how to measure issued uops by defining IssueCounters.
list<PfmIssueCounter> IssueCounters = [];
// Processor can list mappings between validation events and real counters
// to measure the specified events.
list<PfmValidationCounter> ValidationCounters = [];
}

// A binding of a set of counters to a CPU.
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/X86/X86PfmCounters.td
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ def ZnVer2PfmCounters : ProcPfmCounters {
PfmIssueCounter<"Zn2AGU", "ls_dispatch:ld_st_dispatch + ls_dispatch:ld_dispatch + ls_dispatch:store_dispatch">,
PfmIssueCounter<"Zn2Divider", "div_op_count">
];
let ValidationCounters = [
PfmValidationCounter<InstructionRetired, "RETIRED_INSTRUCTIONS">
];
}
def : PfmCountersBinding<"znver2", ZnVer2PfmCounters>;

Expand All @@ -288,6 +291,9 @@ def ZnVer3PfmCounters : ProcPfmCounters {
PfmIssueCounter<"Zn3Store", "ls_dispatch:store_dispatch">,
PfmIssueCounter<"Zn3Divider", "div_op_count">
];
let ValidationCounters = [
PfmValidationCounter<InstructionRetired, "RETIRED_INSTRUCTIONS">
];
}
def : PfmCountersBinding<"znver3", ZnVer3PfmCounters>;

Expand Down
6 changes: 5 additions & 1 deletion llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@ class SubProcessFunctionExecutorImpl
if (ChildExitCode == 0) {
// The child exited succesfully, read counter values and return
// success
CounterValues[0] = Counter->read();
auto CounterValueOrErr = Counter->readOrError();
if (!CounterValueOrErr)
return CounterValueOrErr.takeError();
CounterValues.swap(*CounterValueOrErr);

return Error::success();
}
// The child exited, but not successfully
Expand Down
13 changes: 0 additions & 13 deletions llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,6 @@ void Counter::stop() {
ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
}

int64_t Counter::read() const {
auto ValueOrError = readOrError();
if (ValueOrError) {
if (!ValueOrError.get().empty())
return ValueOrError.get()[0];
errs() << "Counter has no reading\n";
} else
errs() << ValueOrError.takeError() << "\n";
return -1;
}

llvm::Expected<llvm::SmallVector<int64_t, 4>>
Counter::readOrError(StringRef /*unused*/) const {
int64_t Count = 0;
Expand Down Expand Up @@ -187,8 +176,6 @@ void Counter::start() {}

void Counter::stop() {}

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

llvm::Expected<llvm::SmallVector<int64_t, 4>>
Counter::readOrError(StringRef /*unused*/) const {
if (IsDummyEvent) {
Expand Down
3 changes: 0 additions & 3 deletions llvm/tools/llvm-exegesis/lib/PerfHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class Counter {
/// Stops the measurement of the event.
void stop();

/// Returns the current value of the counter or -1 if it cannot be read.
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
Expand Down
13 changes: 7 additions & 6 deletions llvm/tools/llvm-exegesis/lib/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ std::unique_ptr<BenchmarkRunner> ExegesisTarget::createUopsBenchmarkRunner(
ExecutionMode);
}

static_assert(std::is_trivial_v<PfmCountersInfo>,
"We shouldn't have dynamic initialization here");
const PfmCountersInfo PfmCountersInfo::Default = {nullptr, nullptr, nullptr,
0u};
const PfmCountersInfo PfmCountersInfo::Default = {
nullptr, nullptr, nullptr, 0u, {}};
const PfmCountersInfo PfmCountersInfo::Dummy = {
pfm::PerfEvent::DummyEventString, pfm::PerfEvent::DummyEventString, nullptr,
0u};
pfm::PerfEvent::DummyEventString,
pfm::PerfEvent::DummyEventString,
nullptr,
0u,
{}};

const PfmCountersInfo &ExegesisTarget::getPfmCounters(StringRef CpuName) const {
assert(llvm::is_sorted(
Expand Down
11 changes: 11 additions & 0 deletions llvm/tools/llvm-exegesis/lib/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/TargetParser/Triple.h"

#include <unordered_map>

namespace llvm {
namespace exegesis {

extern cl::OptionCategory Options;
extern cl::OptionCategory BenchmarkOptions;
extern cl::OptionCategory AnalysisOptions;

enum ValidationEvent {
L1DCacheLoadMiss,
InstructionRetired,
DataTLBLoadMiss,
DataTLBStoreMiss
};

struct PfmCountersInfo {
// An optional name of a performance counter that can be used to measure
// cycles.
Expand All @@ -59,6 +68,8 @@ struct PfmCountersInfo {
const IssueCounter *IssueCounters;
unsigned NumIssueCounters;

std::unordered_map<ValidationEvent, const char *> ValidationCounters;

static const PfmCountersInfo Default;
static const PfmCountersInfo Dummy;
};
Expand Down
28 changes: 26 additions & 2 deletions llvm/utils/TableGen/ExegesisEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <string>
#include <vector>

#include <iostream>

using namespace llvm;

#define DEBUG_TYPE "exegesis-emitter"
Expand Down Expand Up @@ -81,6 +83,11 @@ collectPfmCounters(const RecordKeeper &Records) {
"duplicate ResourceName " + ResourceName);
AddPfmCounterName(IssueCounter);
}

for (const Record *ValidationCounter :
Def->getValueAsListOfDefs("ValidationCounters"))
AddPfmCounterName(ValidationCounter);

AddPfmCounterName(Def->getValueAsDef("CycleCounter"));
AddPfmCounterName(Def->getValueAsDef("UopsCounter"));
}
Expand Down Expand Up @@ -109,6 +116,8 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,
Def.getValueAsDef("UopsCounter")->getValueAsString("Counter");
const size_t NumIssueCounters =
Def.getValueAsListOfDefs("IssueCounters").size();
const size_t NumValidationCounters =
Def.getValueAsListOfDefs("ValidationCounters").size();

OS << "\nstatic const PfmCountersInfo " << Target << Def.getName()
<< " = {\n";
Expand All @@ -129,10 +138,25 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,

// Issue Counters
if (NumIssueCounters == 0)
OS << " nullptr, // No issue counters.\n 0\n";
OS << " nullptr, 0, // No issue counters\n";
else
OS << " " << Target << "PfmIssueCounters + " << IssueCountersTableOffset
<< ", " << NumIssueCounters << " // Issue counters.\n";
<< ", " << NumIssueCounters << ", // Issue counters.\n";

// Validation Counters
if (NumValidationCounters == 0)
OS << " {} // No validation counters.\n";
else {
OS << " {\n";
for (const Record *ValidationCounter :
Def.getValueAsListOfDefs("ValidationCounters")) {
OS << " { " << ValidationCounter->getValueAsDef("EventType")->getName()
<< ", " << Target << "PfmCounterNames["
<< getPfmCounterId(ValidationCounter->getValueAsString("Counter"))
<< "]},\n";
}
OS << " } // Validation counters.\n";
}

OS << "};\n";
IssueCountersTableOffset += NumIssueCounters;
Expand Down