Skip to content

Commit b748089

Browse files
Addressing review comments
1 parent c688d40 commit b748089

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

llvm/tools/llvm-exegesis/lib/RISCV/RISCVCounters.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "RISCVCounters.h"
14-
#include <linux/sysctl.h>
15-
#include <sys/types.h>
1614

1715
namespace llvm {
1816
namespace exegesis {
@@ -63,12 +61,16 @@ class RISCVCpuCyclesCounter : public pfm::CounterGroup {
6361
RISCVCpuCyclesCounter::RISCVCpuCyclesCounter(pfm::PerfEvent &&Event)
6462
: CounterGroup(std::move(Event), {}) {
6563
#if defined(__riscv) && defined(__linux__)
66-
uint32_t Cycle;
67-
size_t Length = sizeof(Cycle);
68-
if (!sysctlbyname("kernel.perf_user_access", &Cycle, &Length, NULL, 0) ||
69-
Cycle != 1)
64+
char Value[2] = "0";
65+
int File = 0;
66+
std::error_code FileError = sys::fs::openFileForRead("/proc/sys/kernel/watchdog", File);
67+
sys::fs::file_t FileNative = sys::fs::convertFDToNativeFile(File);
68+
Expected<size_t> ReadBytes = sys::fs::readNativeFile(FileNative, Value);
69+
70+
if (FileError || !ReadBytes || strcmp(Value, "1") != 0) {
7071
report_fatal_error(
7172
"Please write 'sudo echo 1 > /proc/sys/kernel/perf_user_access'");
73+
}
7274
#endif
7375
StartValue = getRISCVCpuCyclesCount();
7476
EndValue = getRISCVCpuCyclesCount();

0 commit comments

Comments
 (0)