Add RISC-V 64 support
authorMichal Biesek <michalbiesek@gmail.com>
Tue, 22 Aug 2023 23:03:02 +0000 (01:03 +0200)
committerMichal Biesek <michalbiesek@gmail.com>
Wed, 23 Aug 2023 00:02:45 +0000 (02:02 +0200)
Signed-off-by: Michal Biesek <michalbiesek@gmail.com>
arch/arch-riscv64.h [new file with mode: 0644]
arch/arch.h
configure
libfio.c
os/os-linux-syscall.h

diff --git a/arch/arch-riscv64.h b/arch/arch-riscv64.h
new file mode 100644 (file)
index 0000000..a74b7d4
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef ARCH_RISCV64_H
+#define ARCH_RISCV64_H
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define FIO_ARCH       (arch_riscv64)
+
+#define nop            __asm__ __volatile__ ("nop")
+#define read_barrier()         __asm__ __volatile__("fence r, r": : :"memory")
+#define write_barrier()                __asm__ __volatile__("fence w, w": : :"memory")
+
+static inline unsigned long long get_cpu_clock(void)
+{
+       unsigned long val;
+
+       asm volatile("rdcycle %0" : "=r"(val));
+       return val;
+}
+#define ARCH_HAVE_CPU_CLOCK
+
+#define ARCH_HAVE_INIT
+extern bool tsc_reliable;
+static inline int arch_init(char *envp[])
+{
+       tsc_reliable = true;
+       return 0;
+}
+
+#endif
index 6e476701b5a4258b6fb99ad3ae08209eb643d675..3ee9b0538dbc62a4e047771413b5b73db5a6d03b 100644 (file)
@@ -24,6 +24,7 @@ enum {
        arch_mips,
        arch_aarch64,
        arch_loongarch64,
+       arch_riscv64,
 
        arch_generic,
 
@@ -100,6 +101,8 @@ extern unsigned long arch_flags;
 #include "arch-aarch64.h"
 #elif defined(__loongarch64)
 #include "arch-loongarch64.h"
+#elif defined(__riscv) && __riscv_xlen == 64
+#include "arch-riscv64.h"
 #else
 #warning "Unknown architecture, attempting to use generic model."
 #include "arch-generic.h"
index 6c9382517378894df2ee1d02733813f68eb51c8f..36184a58ad6652ba2f14611218f5a48cf8248de3 100755 (executable)
--- a/configure
+++ b/configure
@@ -133,6 +133,20 @@ EOF
   compile_object
 }
 
+check_val() {
+    cat > $TMPC <<EOF
+#if $1 == $2
+int main(void)
+{
+  return 0;
+}
+#else
+#error $1 is not equal $2
+#endif
+EOF
+  compile_object
+}
+
 output_sym() {
   echo "$1=y" >> $config_host_mak
   echo "#define $1" >> $config_host_h
@@ -501,13 +515,21 @@ elif check_define __hppa__ ; then
   cpu="hppa"
 elif check_define __loongarch64 ; then
   cpu="loongarch64"
+elif check_define __riscv ; then
+  if check_val __riscv_xlen 32 ; then
+    cpu="riscv32"
+  elif check_val __riscv_xlen 64 ; then
+    cpu="riscv64"
+  elif check_val __riscv_xlen 128 ; then
+    cpu="riscv128"
+  fi
 else
   cpu=`uname -m`
 fi
 
 # Normalise host CPU name and set ARCH.
 case "$cpu" in
-  ia64|ppc|ppc64|s390|s390x|sparc64|loongarch64)
+  ia64|ppc|ppc64|s390|s390x|sparc64|loongarch64|riscv64)
     cpu="$cpu"
   ;;
   i386|i486|i586|i686|i86pc|BePC)
index 5e3fd30b718ecc57c3b9e6d5e45202d635a26e0f..237ce34cb3bb9dc42599309683ca807850a1af5d 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -75,6 +75,7 @@ static const char *fio_arch_strings[arch_nr] = {
        "mips",
        "aarch64",
        "loongarch64",
+       "riscv64",
        "generic"
 };
 
index 67ee4d9109fe0ac3f989087d593cc6c742b9b96f..626330adde01ff25dec386dd23d765cf3e3e30cd 100644 (file)
 #define __NR_sys_tee           77
 #define __NR_sys_vmsplice       75
 #endif
+
+/* Linux syscalls for riscv64 */
+#elif defined(ARCH_RISCV64_H)
+#ifndef __NR_ioprio_set
+#define __NR_ioprio_set                30
+#define __NR_ioprio_get                31
+#endif
 #else
 #warning "Unknown architecture"
 #endif