From 35706d045e862f8ed9289d1bb92950920cee5869 Mon Sep 17 00:00:00 2001 From: kuroro99 Date: Thu, 27 Jan 2022 17:11:18 +0800 Subject: [PATCH] support-get_cycles-for-riscv --- perftest.spec | 6 ++++- support-get_cycles-for-riscv.patch | 41 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 support-get_cycles-for-riscv.patch diff --git a/perftest.spec b/perftest.spec index e9a13d1..8ca1bc6 100644 --- a/perftest.spec +++ b/perftest.spec @@ -1,6 +1,6 @@ Name: perftest Version: 4.2 -Release: 7 +Release: 8 License: GPLv2 or BSD Summary: RDMA Performance Testing Tools Url: https://github.com/linux-rdma/perftest @@ -11,6 +11,7 @@ BuildRequires: gcc libibverbs-devel >= 1.2.0 librdmacm-devel >= 1.0.21 libibuma Obsoletes: openib-perftest < 1.3 Patch0001: bugfix-of-gcc-10.patch +Patch0002: support-get_cycles-for-riscv.patch %description Perftest is a collection of simple tools for testing bandwidth and latency over RDMA connections. @@ -32,6 +33,9 @@ done %_bindir/* %changelog +* Thu 27 Jan 2022 Jiatai He - 4.2-8 +- support-get_cycles-for-riscv.patch + * Tue 3 Aug 2021 Shenmei Tu - 4.2-7 - bugfix-of-gcc-10.patch diff --git a/support-get_cycles-for-riscv.patch b/support-get_cycles-for-riscv.patch new file mode 100644 index 0000000..4a3108b --- /dev/null +++ b/support-get_cycles-for-riscv.patch @@ -0,0 +1,41 @@ +--- perftest-4.2/src/get_clock.org.h 2018-05-06 19:58:57.000000000 +0800 ++++ perftest-4.2/src/get_clock.h 2022-01-27 17:02:20.551375012 +0800 +@@ -105,6 +105,38 @@ + 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 -- Gitee