1 Star 0 Fork 23

lvxiaoqian/perftest

forked from src-openEuler/perftest 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
support_get_cycles_for_riscv.patch 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
吕晓倩 提交于 2022-03-15 01:20 . add patch
From 1780311f7bb12dee2b53dddbc8076d4ca4ea65bc Mon Sep 17 00:00:00 2001
From: HeJiatai <jiatai2021@iscas.ac.cn>
Date: Thu, 20 Jan 2022 21:35:39 +0800
Subject: [PATCH] Perftest:support get_cycles for riscv
This patch support the get_cycles for riscv to get the system time. And then
perftest can be built successfully in riscv architecture, which was tested in
openeuler-riscv64 and debian-riscv64-qemu.
---
src/get_clock.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/src/get_clock.h b/src/get_clock.h
index dacbcd0..dde3c34 100755
--- a/src/get_clock.h
+++ b/src/get_clock.h
@@ -104,7 +104,38 @@ static inline cycles_t get_cycles()
asm volatile("mrs %0, cntvct_el0" : "=r" (cval));
return cval;
}
+#elif defined(__riscv)
+#define ASM_STR(x) #x
+#define csr_read(csr) \
+({ \
+ register unsigned long __v; \
+ __asm__ __volatile__ ("csrr %0, " ASM_STR(csr) \
+ : "=r" (__v) : \
+ : "memory"); \
+ __v; \
+})//read mtime csr
+#define CSR_TIME 0xc01 //read mtime from csrs rather than the mmap
+#if __riscv_xlen == 64
+typedef unsigned long long cycles_t;
+static inline cycles_t get_cycles()
+{
+ return csr_read(CSR_TIME);
+}
+#elif __riscv_xlen == 32
+#define CSR_TIMEH 0xc81
+typedef unsigned long long cycles_t;
+static inline cycles_t get_cycles()
+{ uint32_t hi, lo;
+
+ do {
+ hi = csr_read(CSR_TIMEH);
+ lo = csr_read(CSR_TIME);
+ } while (hi != csr_read(CSR_TIMEH));
+ return ((uint64_t)hi << 32) | lo;
+
+}
+#endif/*__riscv*/
#else
#warning get_cycles not implemented for this architecture: attempt asm/timex.h
#include <asm/timex.h>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lvxiaoqian/perftest.git
git@gitee.com:lvxiaoqian/perftest.git
lvxiaoqian
perftest
perftest
master

搜索帮助