From 064da87f28a1faf4c74ee973b80982b13b8a2952 Mon Sep 17 00:00:00 2001 From: David Abdurachmanov Date: Fri, 1 Jun 2018 11:03:43 +0200 Subject: [PATCH] Add initial support for RISC-V (riscv64) Signed-off-by: David Abdurachmanov --- papi-5.6.0-riscv64.patch | 99 ++++++++++++++++++++++++++++++++++++++++ papi.spec | 7 ++- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 papi-5.6.0-riscv64.patch diff --git a/papi-5.6.0-riscv64.patch b/papi-5.6.0-riscv64.patch new file mode 100644 index 0000000..e4ed7a1 --- /dev/null +++ b/papi-5.6.0-riscv64.patch @@ -0,0 +1,99 @@ +diff --git a/src/configure b/src/configure +index 3d05182..357b874 100755 +--- a/src/configure ++++ b/src/configure +@@ -4628,7 +4628,7 @@ _ACEOF + + # First set pthread-mutexes based on arch + case $arch in +- aarch64|arm*) ++ aarch64|arm*|riscv*) + pthread_mutexes=yes + CFLAGS="$CFLAGS -DUSE_PTHREAD_MUTEXES" + echo "forcing use of pthread mutexes... " >&6 +diff --git a/src/configure.in b/src/configure.in +index cff36bc..697c317 100644 +--- a/src/configure.in ++++ b/src/configure.in +@@ -378,7 +378,7 @@ AC_DEFINE_UNQUOTED(CPU,$CPU,[cpu type]) + + # First set pthread-mutexes based on arch + case $arch in +- aarch64|arm*) ++ aarch64|arm*|riscv*) + pthread_mutexes=yes + CFLAGS="$CFLAGS -DUSE_PTHREAD_MUTEXES" + echo "forcing use of pthread mutexes... " >&6 +diff --git a/src/libpfm4/config.mk b/src/libpfm4/config.mk +index 51d4f25..18f5838 100644 +--- a/src/libpfm4/config.mk ++++ b/src/libpfm4/config.mk +@@ -177,6 +177,9 @@ ifeq ($(ARCH),cell) + CONFIG_PFMLIB_CELL=y + endif + ++ifeq ($(ARCH),riscv64) ++CONFIG_PFMLIB_ARCH_RISCV64=y ++endif + + # + # you shouldn't have to touch anything beyond this point +diff --git a/src/linux-context.h b/src/linux-context.h +index 524490b..7d51495 100644 +--- a/src/linux-context.h ++++ b/src/linux-context.h +@@ -35,6 +35,8 @@ typedef ucontext_t hwd_ucontext_t; + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.pc + #elif defined(__mips__) + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.pc ++#elif defined(__riscv) ++#define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.__gregs[REG_PC] + #else + #error "OVERFLOW_ADDRESS() undefined!" + #endif +diff --git a/src/linux-timer.c b/src/linux-timer.c +index 853e676..8222acb 100644 +--- a/src/linux-timer.c ++++ b/src/linux-timer.c +@@ -288,6 +288,27 @@ get_cycles( void ) + return 0; + } + ++/************************/ ++/* riscv64 get_cycles() */ ++/************************/ ++ ++#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 ++static inline long long ++get_cycles( void ) ++{ ++ register unsigned long ret; ++ ++ __asm__ __volatile__ ("rdcycle %0" : "=r" (ret)); ++ ++ return ret; ++} ++ ++/* ++ * TODO: riscv32 implementation can be done following example in: ++ * Volume I: RISC-V User-Level ISA V2.2 ++ * 2.8 Control and Status Register Instructions ++ * Timers and Counters ++ */ + + #elif !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_CLOCK_GETTIME) + #error "No get_cycles support for this architecture. " +diff --git a/src/mb.h b/src/mb.h +index 1019691..0b82a9d 100644 +--- a/src/mb.h ++++ b/src/mb.h +@@ -39,6 +39,9 @@ + #elif defined(__aarch64__) + #define rmb() asm volatile("dmb ld" ::: "memory") + ++#elif defined(__riscv) ++#define rmb() asm volatile("fence ir, ir" ::: "memory") ++ + #elif defined(__mips__) + #define rmb() asm volatile( \ + ".set mips2\n\t" \ diff --git a/papi.spec b/papi.spec index 41745c6..c43e853 100644 --- a/papi.spec +++ b/papi.spec @@ -8,13 +8,14 @@ Summary: Performance Application Programming Interface Name: papi Version: 5.6.0 -Release: 6%{?dist} +Release: 6.0.riscv64%{?dist} License: BSD Group: Development/System Requires: papi-libs = %{version}-%{release} URL: http://icl.cs.utk.edu/papi/ Source0: http://icl.cs.utk.edu/projects/papi/downloads/%{name}-%{version}.tar.gz Patch1: papi-ldflags.patch +Patch2: papi-5.6.0-riscv64.patch BuildRequires: autoconf BuildRequires: doxygen BuildRequires: ncurses-devel @@ -77,6 +78,7 @@ the PAPI user-space libraries and interfaces. %prep %setup -q %patch1 -p1 -b .ldflags +%patch2 -p1 -b .riscv64 %build %if %{without bundled_libpfm} @@ -159,6 +161,9 @@ chrpath --delete $RPM_BUILD_ROOT%{_libdir}/*.so* %{_libdir}/*.a %changelog +* Fri Jun 01 2018 David Abdurachmanov - 5.6.0-6.0.riscv64 +- Add initial base support for RISC-V (riscv64) + * Thu May 17 2018 William Cohen - 5.6.0-6 - Dynamically link utilities and tests to papi libraries.