[llvm] e366e04 - [llvm-exegesis] Refactor Counter to CounterGroup (#77887)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 01:24:25 PST 2024
Author: Aiden Grossman
Date: 2024-01-16T01:24:22-08:00
New Revision: e366e04d5a3ae8d469ce8e3c88360a9b5ea51054
URL: https://github.com/llvm/llvm-project/commit/e366e04d5a3ae8d469ce8e3c88360a9b5ea51054
DIFF: https://github.com/llvm/llvm-project/commit/e366e04d5a3ae8d469ce8e3c88360a9b5ea51054.diff
LOG: [llvm-exegesis] Refactor Counter to CounterGroup (#77887)
This refactoring gets things ready for validation counters where the
plan is to reuse the existing Counter infrastructure to contain event
groups that consist of a single event that is being measured along with
validation counters.
Added:
Modified:
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
llvm/tools/llvm-exegesis/lib/PerfHelper.h
llvm/tools/llvm-exegesis/lib/Target.cpp
llvm/tools/llvm-exegesis/lib/Target.h
llvm/tools/llvm-exegesis/lib/X86/Target.cpp
llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index dee7af5fd520a4..28d578ce5bea01 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -128,7 +128,7 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
if (!CounterOrError)
return CounterOrError.takeError();
- pfm::Counter *Counter = CounterOrError.get().get();
+ pfm::CounterGroup *Counter = CounterOrError.get().get();
Scratch->clear();
{
auto PS = ET.withSavedState();
@@ -311,7 +311,7 @@ class SubProcessFunctionExecutorImpl
if (!CounterOrError)
return CounterOrError.takeError();
- pfm::Counter *Counter = CounterOrError.get().get();
+ pfm::CounterGroup *Counter = CounterOrError.get().get();
close(PipeFiles[0]);
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
index 314de1ec32366f..f6e091bdff9aec 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp
@@ -107,7 +107,8 @@ StringRef PerfEvent::getPfmEventString() const {
return FullQualifiedEventString;
}
-Counter::Counter(PerfEvent &&E, pid_t ProcessID) : Event(std::move(E)) {
+CounterGroup::CounterGroup(PerfEvent &&E, pid_t ProcessID)
+ : Event(std::move(E)) {
assert(Event.valid());
IsDummyEvent = Event.name() == PerfEvent::DummyEventString;
if (!IsDummyEvent)
@@ -115,7 +116,7 @@ Counter::Counter(PerfEvent &&E, pid_t ProcessID) : Event(std::move(E)) {
}
#ifdef HAVE_LIBPFM
-void Counter::initRealEvent(const PerfEvent &E, pid_t ProcessID) {
+void CounterGroup::initRealEvent(const PerfEvent &E, pid_t ProcessID) {
const int Cpu = -1; // measure any processor.
const int GroupFd = -1; // no grouping of counters.
const uint32_t Flags = 0;
@@ -133,23 +134,23 @@ void Counter::initRealEvent(const PerfEvent &E, pid_t ProcessID) {
assert(FileDescriptor != -1 && "Unable to open event");
}
-Counter::~Counter() {
+CounterGroup::~CounterGroup() {
if (!IsDummyEvent)
close(FileDescriptor);
}
-void Counter::start() {
+void CounterGroup::start() {
if (!IsDummyEvent)
ioctl(FileDescriptor, PERF_EVENT_IOC_RESET, 0);
}
-void Counter::stop() {
+void CounterGroup::stop() {
if (!IsDummyEvent)
ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
}
llvm::Expected<llvm::SmallVector<int64_t, 4>>
-Counter::readOrError(StringRef /*unused*/) const {
+CounterGroup::readOrError(StringRef /*unused*/) const {
int64_t Count = 0;
if (!IsDummyEvent) {
ssize_t ReadSize = ::read(FileDescriptor, &Count, sizeof(Count));
@@ -165,19 +166,19 @@ Counter::readOrError(StringRef /*unused*/) const {
return Result;
}
-int Counter::numValues() const { return 1; }
+int CounterGroup::numValues() const { return 1; }
#else
-void Counter::initRealEvent(const PerfEvent &, pid_t ProcessID) {}
+void CounterGroup::initRealEvent(const PerfEvent &, pid_t ProcessID) {}
-Counter::~Counter() = default;
+CounterGroup::~CounterGroup() = default;
-void Counter::start() {}
+void CounterGroup::start() {}
-void Counter::stop() {}
+void CounterGroup::stop() {}
llvm::Expected<llvm::SmallVector<int64_t, 4>>
-Counter::readOrError(StringRef /*unused*/) const {
+CounterGroup::readOrError(StringRef /*unused*/) const {
if (IsDummyEvent) {
llvm::SmallVector<int64_t, 4> Result;
Result.push_back(42);
@@ -187,7 +188,7 @@ Counter::readOrError(StringRef /*unused*/) const {
llvm::errc::io_error);
}
-int Counter::numValues() const { return 1; }
+int CounterGroup::numValues() const { return 1; }
#endif
diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.h b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
index 894aac1f197ed1..daf2fbd0e3abc8 100644
--- a/llvm/tools/llvm-exegesis/lib/PerfHelper.h
+++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.h
@@ -77,17 +77,19 @@ class PerfEvent {
void initRealEvent(StringRef PfmEventString);
};
-// Uses a valid PerfEvent to configure the Kernel so we can measure the
-// underlying event.
-class Counter {
+// Consists of a counter measuring a specific event and associated validation
+// counters measuring execution conditions. All counters in a group are part
+// of a single event group and are thus scheduled on and off the CPU as a single
+// unit.
+class CounterGroup {
public:
// event: the PerfEvent to measure.
- explicit Counter(PerfEvent &&event, pid_t ProcessID = 0);
+ explicit CounterGroup(PerfEvent &&event, pid_t ProcessID = 0);
- Counter(const Counter &) = delete;
- Counter(Counter &&other) = default;
+ CounterGroup(const CounterGroup &) = delete;
+ CounterGroup(CounterGroup &&other) = default;
- virtual ~Counter();
+ virtual ~CounterGroup();
/// Starts the measurement of the event.
virtual void start();
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp
index fe1eded63dc51a..8f1c5a157eea39 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -35,7 +35,7 @@ const ExegesisTarget *ExegesisTarget::lookup(Triple TT) {
return nullptr;
}
-Expected<std::unique_ptr<pfm::Counter>>
+Expected<std::unique_ptr<pfm::CounterGroup>>
ExegesisTarget::createCounter(StringRef CounterName, const LLVMState &,
const pid_t ProcessID) const {
pfm::PerfEvent Event(CounterName);
@@ -45,7 +45,7 @@ ExegesisTarget::createCounter(StringRef CounterName, const LLVMState &,
.concat(CounterName)
.concat("'"));
- return std::make_unique<pfm::Counter>(std::move(Event), ProcessID);
+ return std::make_unique<pfm::CounterGroup>(std::move(Event), ProcessID);
}
void ExegesisTarget::registerTarget(ExegesisTarget *Target) {
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h
index a9e21c782b4dfe..da6d44611eca7c 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -84,7 +84,7 @@ class ExegesisTarget {
: CpuPfmCounters(CpuPfmCounters), IsOpcodeAvailable(IsOpcodeAvailable) {}
// Targets can use this to create target-specific perf counters.
- virtual Expected<std::unique_ptr<pfm::Counter>>
+ virtual Expected<std::unique_ptr<pfm::CounterGroup>>
createCounter(StringRef CounterName, const LLVMState &State,
const pid_t ProcessID = 0) const;
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index 0ab74b8e00da11..25df89fb0cf31d 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -679,7 +679,7 @@ class ExegesisX86Target : public ExegesisTarget {
ExegesisX86Target()
: ExegesisTarget(X86CpuPfmCounters, X86_MC::isOpcodeAvailable) {}
- Expected<std::unique_ptr<pfm::Counter>>
+ Expected<std::unique_ptr<pfm::CounterGroup>>
createCounter(StringRef CounterName, const LLVMState &State,
const pid_t ProcessID) const override {
// If LbrSamplingPeriod was provided, then ignore the
diff --git a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
index 423c45e22bf8c0..55ca2d7146ceb7 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
@@ -141,7 +141,7 @@ X86LbrPerfEvent::X86LbrPerfEvent(unsigned SamplingPeriod) {
}
X86LbrCounter::X86LbrCounter(pfm::PerfEvent &&NewEvent)
- : Counter(std::move(NewEvent)) {
+ : CounterGroup(std::move(NewEvent)) {
MMappedBuffer = mmap(nullptr, kMappedBufferSize, PROT_READ | PROT_WRITE,
MAP_SHARED, FileDescriptor, 0);
if (MMappedBuffer == MAP_FAILED)
diff --git a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
index 73e4dc5b990a0f..bc2fced9acfbf4 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
+++ b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
@@ -31,7 +31,7 @@ class X86LbrPerfEvent : public pfm::PerfEvent {
X86LbrPerfEvent(unsigned SamplingPeriod);
};
-class X86LbrCounter : public pfm::Counter {
+class X86LbrCounter : public pfm::CounterGroup {
public:
static llvm::Error checkLbrSupport();
More information about the llvm-commits
mailing list