From b33c1413c4aa8a89b023e0e95f9dfdd441cee3a2 Mon Sep 17 00:00:00 2001 From: Wenlong Zhang Date: Wed, 11 Oct 2023 15:32:22 +0800 Subject: [PATCH] add loongarch64 support for papi --- 0001-add-loongarch64-support-for-papi.patch | 109 ++++++++++++++++++++ papi.spec | 15 ++- 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 0001-add-loongarch64-support-for-papi.patch diff --git a/0001-add-loongarch64-support-for-papi.patch b/0001-add-loongarch64-support-for-papi.patch new file mode 100644 index 0000000..5001e7b --- /dev/null +++ b/0001-add-loongarch64-support-for-papi.patch @@ -0,0 +1,109 @@ +From 2a10a6419a75e46881922e7d8379ca39ee503fe0 Mon Sep 17 00:00:00 2001 +From: Wenlong Zhang +Date: Wed, 11 Oct 2023 15:24:00 +0800 +Subject: [PATCH] add loongarch64 support for papi + +--- + src/linux-context.h | 2 ++ + src/linux-lock.h | 31 +++++++++++++++++++++++++++++++ + src/linux-timer.c | 14 ++++++++++++++ + src/mb.h | 3 +++ + 4 files changed, 50 insertions(+) + +diff --git a/src/linux-context.h b/src/linux-context.h +index f46e557..f2b118d 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.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 --git a/src/linux-lock.h b/src/linux-lock.h +index fd05f83..508949a 100644 +--- a/src/linux-lock.h ++++ b/src/linux-lock.h +@@ -256,6 +256,37 @@ static inline void __raw_spin_unlock(volatile unsigned int *lock) + } + #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 --git a/src/linux-timer.c b/src/linux-timer.c +index 0eaa79c..864e6cb 100644 +--- a/src/linux-timer.c ++++ b/src/linux-timer.c +@@ -245,6 +245,20 @@ get_cycles( void ) + 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 --git a/src/mb.h b/src/mb.h +index 81797c5..359458f 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(__loongarch__) ++#define rmb() asm volatile("dbar 0" ::: "memory") ++ + #elif defined(__mips__) + #define rmb() asm volatile( \ + ".set mips2\n\t" \ +-- +2.40.1 + diff --git a/papi.spec b/papi.spec index 28d3670..7735667 100644 --- a/papi.spec +++ b/papi.spec @@ -1,10 +1,11 @@ -%define anolis_release 1 +%define anolis_release 2 # Default to no static libraries %{!?with_static: %global with_static 0} %bcond_with bundled_libpfm %{!?with_rdma: %global with_rdma 1} %{!?with_pcp: %global with_pcp 0} +%bcond_with abi Summary: Performance Application Programming Interface Name: papi @@ -16,6 +17,7 @@ Source0: http://icl.cs.utk.edu/projects/papi/downloads/%{name}-%{version}.tar.g Patch1: papi-python3.patch Patch2: papi-nostatic.patch +Patch3: 0001-add-loongarch64-support-for-papi.patch Requires: papi-libs = %{version}-%{release} BuildRequires: make @@ -93,6 +95,7 @@ The %{name}-doc package contains documentation files for %{name}. %setup -q %patch1 -p1 -b .python3 %patch2 -p1 +%patch3 -p1 %build @@ -150,7 +153,9 @@ make DESTDIR=$RPM_BUILD_ROOT LDCONFIG=/bin/true install-all # Scrub the rpath/runpath from all the binaries. find %{buildroot} -type f -executable ! -iname "*.py" ! -iname "*.sh" | xargs chrpath --delete +%if %{with abi} %generate_compatibility_deps +%endif %files %{_bindir}/* @@ -158,6 +163,7 @@ find %{buildroot} -type f -executable ! -iname "*.py" ! -iname "*.sh" | xargs ch /usr/share/papi/papi_events.csv %doc LICENSE.txt %doc %{_mandir}/man1/* +%if %{with abi} %{abidir}/papi_avail-option.list %{abidir}/papi_clockres-option.list %{abidir}/papi_command_line-option.list @@ -169,13 +175,16 @@ find %{buildroot} -type f -executable ! -iname "*.py" ! -iname "*.sh" | xargs ch %{abidir}/papi_multiplex_cost-option.list %{abidir}/papi_version-option.list %{abidir}/papi_xml_event_info-option.list +%endif %files libs %{_libdir}/*.so.* +%if %{with abi} %doc INSTALL.txt README.md LICENSE.txt RELEASENOTES.txt %dir %{abidir} %{abidir}/libpapi.dump %{abidir}/libsde.dump +%endif %files devel %{_includedir}/*.h @@ -204,5 +213,9 @@ find %{buildroot} -type f -executable ! -iname "*.py" ! -iname "*.sh" | xargs ch %doc INSTALL.txt README.md RELEASENOTES.txt %changelog +* Tue Oct 10 2023 Wenlong Zhang - 7.0.1-2 +- add loongarch64 support for papi +- disable generate_compatibility_deps to fix build timeout + * Mon Mar 27 2023 Yuanhong Peng - 7.0.1-1 - Init from upstream -- Gitee