From bbeb4d255c100d0db823a8d2084358c17edc66a4 Mon Sep 17 00:00:00 2001 From: wangguofeng Date: Thu, 12 Aug 2021 10:00:08 +0800 Subject: [PATCH 1/3] arch: add loongarch support. This patch adds support for loongarch for fio. This is tested by building FIO on an loongarch Debian 10 system. Signed-off-by: wangguofeng --- arch/arch-loongarch.h | 37 +++++++++++++++++++++++++++++++++++++ arch/arch.h | 3 +++ os/os-linux-syscall.h | 4 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 arch/arch-loongarch.h diff --git a/arch/arch-loongarch.h b/arch/arch-loongarch.h new file mode 100644 index 0000000000..1f1b8a0034 --- /dev/null +++ b/arch/arch-loongarch.h @@ -0,0 +1,37 @@ +#ifndef ARCH_LOONGARCH_H +#define ARCH_LOONGARCH_H + +#define FIO_ARCH (arch_loongarch) + +#define read_barrier() __asm__ __volatile__("dbar 0": : :"memory") +#define write_barrier() __asm__ __volatile__("dbar 0": : :"memory") +#define nop __asm__ __volatile__("nop") + +#if __loongarch_xlen == 64 +#define CTZ "ctz.d" +#define CTO "cto.d" +#else +#define CTZ "ctz.w" +#define CTO "cto.w" +#endif +static inline int arch_ffz(unsigned long bitmask) +{ + unsigned long count; + if (~bitmask == 0) /* ffz() in lib/ffz.h does this. */ + return 63; + + __asm__ __volatile__ (CTZ " %0, %1\n\t" + "bnez %0, 0f\n\t" + CTO " %0, %1\n\t" + "b 1f\n\t" + "0: move %0, $zero\n\t" + "1:\n\t" + :"=&r"(count) + :"r"(bitmask)); + + return count; +} + +#define ARCH_HAVE_FFZ + +#endif diff --git a/arch/arch.h b/arch/arch.h index a25779d4fd..19bce09a7e 100644 --- a/arch/arch.h +++ b/arch/arch.h @@ -19,6 +19,7 @@ enum { arch_hppa, arch_mips, arch_aarch64, + arch_loongarch, arch_generic, @@ -77,6 +78,8 @@ extern unsigned long arch_flags; #include "arch-hppa.h" #elif defined(__aarch64__) #include "arch-aarch64.h" +#elif defined(__loongarch__) +#include "arch-loongarch.h" #else #warning "Unknown architecture, attempting to use generic model." #include "arch-generic.h" diff --git a/os/os-linux-syscall.h b/os/os-linux-syscall.h index c399b2fa99..a43e394e65 100644 --- a/os/os-linux-syscall.h +++ b/os/os-linux-syscall.h @@ -263,8 +263,8 @@ #define __NR_sys_vmsplice 294 #endif -/* Linux syscalls for aarch64 */ -#elif defined(ARCH_AARCH64_H) +/* Linux syscalls for aarch64 and loongarch */ +#elif defined(ARCH_AARCH64_H) || defined(ARCH_LOONGARCH_H) #ifndef __NR_ioprio_set #define __NR_ioprio_set 30 #define __NR_ioprio_get 31 From 5accd4b7b44204a696e047d7e9c194cb01682e06 Mon Sep 17 00:00:00 2001 From: wangguofeng Date: Mon, 16 Aug 2021 14:20:07 +0800 Subject: [PATCH 2/3] arch: remove loongarch 32bit ffz --- arch/arch-loongarch.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arch-loongarch.h b/arch/arch-loongarch.h index 1f1b8a0034..474f70deb8 100644 --- a/arch/arch-loongarch.h +++ b/arch/arch-loongarch.h @@ -10,10 +10,6 @@ #if __loongarch_xlen == 64 #define CTZ "ctz.d" #define CTO "cto.d" -#else -#define CTZ "ctz.w" -#define CTO "cto.w" -#endif static inline int arch_ffz(unsigned long bitmask) { unsigned long count; @@ -35,3 +31,5 @@ static inline int arch_ffz(unsigned long bitmask) #define ARCH_HAVE_FFZ #endif + +#endif From 32560c7cf51cb179d1a892263849d60cbe29d3f6 Mon Sep 17 00:00:00 2001 From: wangguofeng Date: Mon, 16 Aug 2021 17:55:19 +0800 Subject: [PATCH 3/3] arch: add loongarch 32bit ffz --- arch/arch-loongarch.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arch-loongarch.h b/arch/arch-loongarch.h index 474f70deb8..e1248fae2f 100644 --- a/arch/arch-loongarch.h +++ b/arch/arch-loongarch.h @@ -7,14 +7,19 @@ #define write_barrier() __asm__ __volatile__("dbar 0": : :"memory") #define nop __asm__ __volatile__("nop") -#if __loongarch_xlen == 64 -#define CTZ "ctz.d" -#define CTO "cto.d" static inline int arch_ffz(unsigned long bitmask) { unsigned long count; if (~bitmask == 0) /* ffz() in lib/ffz.h does this. */ +#if __loongarch_xlen == 64 return 63; +#define CTZ "ctz.d" +#define CTO "cto.d" +#else + return 31; +#define CTZ "ctz.w" +#define CTO "cto.w" +#endif __asm__ __volatile__ (CTZ " %0, %1\n\t" "bnez %0, 0f\n\t" @@ -31,5 +36,3 @@ static inline int arch_ffz(unsigned long bitmask) #define ARCH_HAVE_FFZ #endif - -#endif