From 6b2652f6a6bc9af7543380dc981ca09a4a2926d2 Mon Sep 17 00:00:00 2001 From: yangchenguang Date: Mon, 14 Aug 2023 19:25:36 +0800 Subject: [PATCH] Add loongarch64 and sw_64 support Signed-off-by: yangchenguang (cherry picked from commit 6119b0e0db6b0edb77bbfc4fa2050e6e314d1a1e) --- add-loongarch-support.patch | 90 +++++++++++++++++++++++++++++ papi-5.7.0-sw.patch | 109 ++++++++++++++++++++++++++++++++++++ papi.spec | 12 +++- 3 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 add-loongarch-support.patch create mode 100644 papi-5.7.0-sw.patch diff --git a/add-loongarch-support.patch b/add-loongarch-support.patch new file mode 100644 index 0000000..c4ee40f --- /dev/null +++ b/add-loongarch-support.patch @@ -0,0 +1,90 @@ +diff -Nur a/src/linux-context.h b/src/linux-context.h +--- a/src/linux-context.h 2023-02-13 17:13:46.695350258 +0800 ++++ b/src/linux-context.h 2023-02-13 17:12:54.094497176 +0800 +@@ -33,6 +33,8 @@ + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.arm_pc + #elif defined(__aarch64__) + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.pc ++#elif defined(__loongarch__) ++#define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.__pc + #elif defined(__mips__) + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.pc + #elif defined(__hppa__) +diff -Nur a/src/linux-lock.h b/src/linux-lock.h +--- a/src/linux-lock.h 2019-03-05 03:56:23.000000000 +0800 ++++ b/src/linux-lock.h 2023-02-13 17:12:54.094497176 +0800 +@@ -223,6 +223,37 @@ + } + #define _papi_hwd_lock(lck) __raw_spin_lock(&_papi_hwd_lock_data[lck]); + #define _papi_hwd_unlock(lck) __raw_spin_unlock(&_papi_hwd_lock_data[lck]) ++#elif defined(__loongarch__) ++static inline void __raw_spin_lock(volatile unsigned int *lock) ++{ ++ unsigned int tmp; ++ __asm__ __volatile__( ++ "1: ll.w %1, %2 \n" ++ " bnez %1, 1b \n" ++ " li.w %1, 1 \n" ++ " sc.w %1, %0 \n" ++ " beqz %1, 1b \n" ++ " nop \n" ++ : "=m" (*lock), "=&r" (tmp) ++ : "m" (*lock) ++ : "memory"); ++} ++ ++static inline void __raw_spin_unlock(volatile unsigned int *lock) ++{ ++ unsigned int tmp; ++ __asm__ __volatile__( ++ " nop \n" ++ " li.w %1, 0 \n" ++ " st.w %1, %0 \n" ++ : "=m" (*lock), "=&r" (tmp) ++ : "m" (*lock) ++ : "memory"); ++} ++#define _papi_hwd_lock(lck) { rmb(); __raw_spin_lock(&_papi_hwd_lock_data[lck]); rmb(); } ++#define _papi_hwd_unlock(lck) { rmb(); __raw_spin_unlock(&_papi_hwd_lock_data[lck]); rmb(); } ++ ++ + #else + + #error "_papi_hwd_lock/unlock undefined!" +diff -Nur a/src/linux-timer.c b/src/linux-timer.c +--- a/src/linux-timer.c 2023-02-13 17:13:46.695350258 +0800 ++++ b/src/linux-timer.c 2023-02-13 17:12:54.094497176 +0800 +@@ -245,6 +245,20 @@ + return ret; + } + ++/****************************/ ++/* loongarch64 get_cycles() */ ++/****************************/ ++#elif defined(__loongarch__) ++static inline long long ++get_cycles(void) ++{ ++ register unsigned long ret = 0; ++ int rID = 0; ++ __asm__ __volatile__ ("ibar 0" ::: "memory"); ++ __asm__ __volatile__ ("rdtime.d %0, %1" :"=r"(ret),"=r"(rID)); ++ return ret; ++} ++ + /************************/ + /* POWER get_cycles() */ + /************************/ +diff -Nur a/src/mb.h b/src/mb.h +--- a/src/mb.h 2023-02-13 17:13:46.695350258 +0800 ++++ b/src/mb.h 2023-02-13 17:12:54.098497240 +0800 +@@ -39,6 +39,9 @@ + #elif defined(__aarch64__) + #define rmb() asm volatile("dmb ld" ::: "memory") + ++#elif defined(__loongarch__) ++#define rmb() asm volatile("dbar 0" ::: "memory") ++ + #elif defined(__riscv) + #define rmb() asm volatile("fence ir, ir" ::: "memory") + diff --git a/papi-5.7.0-sw.patch b/papi-5.7.0-sw.patch new file mode 100644 index 0000000..d479644 --- /dev/null +++ b/papi-5.7.0-sw.patch @@ -0,0 +1,109 @@ +From 5152ebe60d70f212df8619313463ae08185cfc55 Mon Sep 17 00:00:00 2001 +From: panchenbo +Date: Tue, 16 May 2023 20:03:44 +0800 +Subject: [PATCH] add sw_64 support + +--- + src/components/appio/tests/iozone/iozone.c | 2 +- + src/configure | 2 +- + src/configure.in | 2 +- + src/linux-context.h | 2 ++ + src/linux-timer.c | 15 +++++++++++++++ + src/mb.h | 3 +++ + 6 files changed, 23 insertions(+), 3 deletions(-) + +diff --git a/src/components/appio/tests/iozone/iozone.c b/src/components/appio/tests/iozone/iozone.c +index 7708cd7..0fb29e3 100644 +--- a/src/components/appio/tests/iozone/iozone.c ++++ b/src/components/appio/tests/iozone/iozone.c +@@ -81,7 +81,7 @@ extern int h_errno; /* imported for errors */ + + #include + #include +-#if defined (__LP64__) || defined(OSF_64) || defined(__alpha__) || defined(__arch64__) || defined(_LP64) || defined(__s390x__) || defined(__AMD64__) ++#if defined (__LP64__) || defined(OSF_64) || defined(__alpha__) || defined(__sw_64__) || defined(__arch64__) || defined(_LP64) || defined(__s390x__) || defined(__AMD64__) + #define MODE "\tCompiled for 64 bit mode." + #define _64BIT_ARCH_ + #else +diff --git a/src/configure b/src/configure +index 02db3ac..2f83166 100755 +--- a/src/configure ++++ b/src/configure +@@ -4628,7 +4628,7 @@ _ACEOF + + # First set pthread-mutexes based on arch + case $arch in +- aarch64|arm*|parisc*|riscv*) ++ aarch64|arm*|parisc*|riscv*|sw_64) + 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 2c219ad..964f0e6 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*|parisc*|riscv*) ++ aarch64|arm*|parisc*|riscv*|sw_64) + pthread_mutexes=yes + CFLAGS="$CFLAGS -DUSE_PTHREAD_MUTEXES" + echo "forcing use of pthread mutexes... " >&6 +diff --git a/src/linux-context.h b/src/linux-context.h +index fc07338..a55127c 100644 +--- a/src/linux-context.h ++++ b/src/linux-context.h +@@ -33,6 +33,8 @@ typedef ucontext_t hwd_ucontext_t; + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.arm_pc + #elif defined(__aarch64__) + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.pc ++#elif defined(__sw_64__) ++#define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.sc_pc + #elif defined(__loongarch__) + #define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.__pc + #elif defined(__mips__) +diff --git a/src/linux-timer.c b/src/linux-timer.c +index 1d6b7a8..43de746 100644 +--- a/src/linux-timer.c ++++ b/src/linux-timer.c +@@ -230,6 +230,21 @@ get_cycles( void ) + return ret; + } + ++/************************/ ++/* sw_64 get_cycles() */ ++/************************/ ++ ++#elif defined(__sw_64__) ++static inline long long ++get_cycles( void ) ++{ ++ register unsigned long ret; ++ ++ __asm__ __volatile__ ("rtc %0" : "=r" (ret)); ++ ++ return ret; ++} ++ + /************************/ + /* aarch64 get_cycles() */ + /************************/ +diff --git a/src/mb.h b/src/mb.h +index e98b574..b14bf5e 100644 +--- a/src/mb.h ++++ b/src/mb.h +@@ -26,6 +26,9 @@ + #elif defined (__alpha__) + #define rmb() asm volatile("mb" ::: "memory") + ++#elif defined (__sw_64__) ++#define rmb() asm volatile("memb" ::: "memory") ++ + #elif defined(__ia64__) + #define rmb() asm volatile ("mf" ::: "memory") + +-- +2.27.0 + diff --git a/papi.spec b/papi.spec index 06cf427..405b26e 100644 --- a/papi.spec +++ b/papi.spec @@ -1,6 +1,6 @@ Name: papi Version: 5.7.0 -Release: 1 +Release: 2 Summary: Performance Application Programming Interface License: BSD URL: http://icl.cs.utk.edu/papi/ @@ -13,6 +13,9 @@ Obsoletes: papi-libs < %{version}-%{release} Patch0001: papi-add-support-riscv64.patch +Patch3000: add-loongarch-support.patch +Patch3001: papi-5.7.0-sw.patch + %description PAPI provides a programmer interface to monitor the performance of running programs,and contains the run-time libraries for any application that wishes @@ -42,7 +45,11 @@ cd src autoconf %configure --with-perf-events --with-pfm-incdir=%{_includedir} --with-pfm-libdir=%{_libdir} \ --with-static-lib=yes --with-shared-lib=yes --with-shlib --with-shlib-tools \ +%ifarch sw_64 +--with-components="coretemp example infiniband lmsensors lustre micpower mx net rapl stealtime" +%else --with-components="appio coretemp example infiniband lmsensors lustre micpower mx net rapl stealtime" +%endif cd components cd infiniband_umad; %configure @@ -87,6 +94,9 @@ chrpath --delete $RPM_BUILD_ROOT%{_libdir}/*.so* %{_mandir}/man3/* %changelog +* Mon Aug 14 2023 yangchenguang - 5.7.0-2 +- Add loongarch64 and sw_64 support + * Mon Feb 13 2023 liyanan - 5.7.0-1 - Update to 5.7.0 -- Gitee