68 lines
2.0 KiB
Diff
68 lines
2.0 KiB
Diff
|
|
From 5caa74b57f4f0bbcdef3a0d764b544f5c6061222 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Wenlong Zhang <zhangwenlong@loongson.cn>
|
||
|
|
Date: Tue, 16 Apr 2024 02:24:07 +0000
|
||
|
|
Subject: [PATCH] add loongarch64 support for papi
|
||
|
|
|
||
|
|
---
|
||
|
|
src/linux-context.h | 2 ++
|
||
|
|
src/linux-timer.c | 15 +++++++++++++++
|
||
|
|
src/mb.h | 3 +++
|
||
|
|
3 files changed, 20 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/src/linux-context.h b/src/linux-context.h
|
||
|
|
index 394a480..00ebf73 100644
|
||
|
|
--- a/src/linux-context.h
|
||
|
|
+++ b/src/linux-context.h
|
||
|
|
@@ -41,6 +41,8 @@ typedef ucontext_t hwd_ucontext_t;
|
||
|
|
#define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.sc_iaoq[0]
|
||
|
|
#elif defined(__riscv)
|
||
|
|
#define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.__gregs[REG_PC]
|
||
|
|
+#elif defined(__loongarch__)
|
||
|
|
+#define OVERFLOW_ADDRESS(ctx) ctx.ucontext->uc_mcontext.__pc
|
||
|
|
#else
|
||
|
|
#error "OVERFLOW_ADDRESS() undefined!"
|
||
|
|
#endif
|
||
|
|
diff --git a/src/linux-timer.c b/src/linux-timer.c
|
||
|
|
index 46bfe75..666801f 100644
|
||
|
|
--- a/src/linux-timer.c
|
||
|
|
+++ b/src/linux-timer.c
|
||
|
|
@@ -322,6 +322,21 @@ get_cycles( void )
|
||
|
|
* Timers and Counters
|
||
|
|
*/
|
||
|
|
|
||
|
|
+/****************************/
|
||
|
|
+/* 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;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+
|
||
|
|
#elif !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_CLOCK_GETTIME)
|
||
|
|
#error "No get_cycles support for this architecture. "
|
||
|
|
#endif
|
||
|
|
diff --git a/src/mb.h b/src/mb.h
|
||
|
|
index 347436b..03e910b 100644
|
||
|
|
--- a/src/mb.h
|
||
|
|
+++ b/src/mb.h
|
||
|
|
@@ -42,6 +42,9 @@
|
||
|
|
#elif defined(__riscv)
|
||
|
|
#define rmb() asm volatile("fence ir, ir" ::: "memory")
|
||
|
|
|
||
|
|
+#elif defined(__loongarch__)
|
||
|
|
+#define rmb() asm volatile("dbar 0" ::: "memory")
|
||
|
|
+
|
||
|
|
#elif defined(__mips__)
|
||
|
|
#define rmb() asm volatile( \
|
||
|
|
".set mips2\n\t" \
|
||
|
|
--
|
||
|
|
2.43.0
|
||
|
|
|