Skip to content

Commit 15189d4

Browse files
Set PERF_IOC_FLAG_GROUP on ioctl calls
Without this call, the ioctl calls only work by chance and fail in certain cases, like when the users sets the RDX register in subprocess mode.
1 parent d17e9c4 commit 15189d4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

llvm/tools/llvm-exegesis/lib/PerfHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ Counter::~Counter() {
154154

155155
void Counter::start() {
156156
if (!IsDummyEvent)
157-
ioctl(FileDescriptor, PERF_EVENT_IOC_RESET, 0);
157+
ioctl(FileDescriptor, PERF_EVENT_IOC_RESET, PERF_IOC_FLAG_GROUP);
158158
}
159159

160160
void Counter::stop() {
161161
if (!IsDummyEvent)
162-
ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0);
162+
ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, PERF_IOC_FLAG_GROUP);
163163
}
164164

165165
llvm::Expected<llvm::SmallVector<int64_t, 4>>

llvm/tools/llvm-exegesis/lib/X86/Target.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#include <sys/mman.h>
4646
#include <sys/syscall.h>
4747
#include <unistd.h>
48+
#ifdef HAVE_LIBPFM
49+
#include <perfmon/perf_event.h>
50+
#endif // HAVE_LIBPFM
4851
#endif
4952

5053
#define GET_AVAILABLE_OPCODE_CHECKER
@@ -1252,7 +1255,7 @@ std::vector<MCInst>
12521255
ExegesisX86Target::configurePerfCounter(long Request, bool SaveRegisters) const {
12531256
std::vector<MCInst> ConfigurePerfCounterCode;
12541257
if (SaveRegisters)
1255-
saveSyscallRegisters(ConfigurePerfCounterCode, 2);
1258+
saveSyscallRegisters(ConfigurePerfCounterCode, 3);
12561259
ConfigurePerfCounterCode.push_back(
12571260
loadImmediate(X86::RDI, 64, APInt(64, getAuxiliaryMemoryStartAddress())));
12581261
ConfigurePerfCounterCode.push_back(MCInstBuilder(X86::MOV32rm)
@@ -1264,9 +1267,13 @@ ExegesisX86Target::configurePerfCounter(long Request, bool SaveRegisters) const
12641267
.addReg(0));
12651268
ConfigurePerfCounterCode.push_back(
12661269
loadImmediate(X86::RSI, 64, APInt(64, Request)));
1270+
#ifdef HAVE_LIBPFM
1271+
ConfigurePerfCounterCode.push_back(
1272+
loadImmediate(X86::RDX, 64, APInt(64, PERF_IOC_FLAG_GROUP)));
1273+
#endif // HAVE_LIBPFM
12671274
generateSyscall(SYS_ioctl, ConfigurePerfCounterCode);
12681275
if (SaveRegisters)
1269-
restoreSyscallRegisters(ConfigurePerfCounterCode, 2);
1276+
restoreSyscallRegisters(ConfigurePerfCounterCode, 3);
12701277
return ConfigurePerfCounterCode;
12711278
}
12721279

0 commit comments

Comments
 (0)