[llvm] [Exegesis][RISCV] Add RISCV support for llvm-exegesis (PR #89047)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 06:43:53 PDT 2024


================
@@ -0,0 +1,95 @@
+//===-- RISCVCounters.cpp ---------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines RISC-V perf counters.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RISCVCounters.h"
+#include <linux/sysctl.h>
+#include <sys/types.h>
+
+namespace llvm {
+namespace exegesis {
+
+// This implementation of RISCV target for Exegesis doesn't use libpfm
+// and provides manual implementation of performance counters.
+
+inline uint64_t getRISCVCpuCyclesCount() {
+#if defined(__riscv) && defined(__linux__)
+  uint32_t Cycle;
+  size_t Length = sizeof(Cycle);
+  if (!sysctlbyname("kernel.perf_user_access", &Cycle, &Length, NULL, 0) ||
+      Cycle != 1)
+    report_fatal_error(
+        "Please write 'sudo echo 1 > /proc/sys/kernel/perf_user_access'");
----------------
dtcxzyw wrote:

Can we move these code into `RISCVCpuCyclesCounter::RISCVCpuCyclesCounter`?

`getRISCVCpuCyclesCount` seems to be called multiple times.


https://github.com/llvm/llvm-project/pull/89047


More information about the llvm-commits mailing list