From 27d2cc2b4c20b0c657f5150535481e980f79d4e1 Mon Sep 17 00:00:00 2001 From: Wang Junqiang Date: Thu, 22 Sep 2022 11:47:44 +0800 Subject: [PATCH] add riscv64 support Porting basic arch specific code to RISC-V(64bit). Tested vma services and `make tests`, tests/gtest. Signed-off-by: Wang Junqiang --- add-riscv64-support.patch | 139 ++++++++++++++++++++++++++++++++++++++ libvma.spec | 6 +- 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 add-riscv64-support.patch diff --git a/add-riscv64-support.patch b/add-riscv64-support.patch new file mode 100644 index 0000000..5eb3ee2 --- /dev/null +++ b/add-riscv64-support.patch @@ -0,0 +1,139 @@ +From f664d44c4e0f5b795b0acaf8ad2e7d129b05ca46 Mon Sep 17 00:00:00 2001 +From: Wang Junqiang +Date: Thu, 22 Sep 2022 11:46:15 +0800 +Subject: [PATCH] add riscv64 support + +Implement riscv64 asm file + +Signed-off-by: Wang Junqiang +--- + src/utils/asm-riscv64.h | 103 ++++++++++++++++++++++++++++++++++++++++ + src/utils/asm.h | 2 + + 2 files changed, 105 insertions(+) + create mode 100644 src/utils/asm-riscv64.h + +diff --git a/src/utils/asm-riscv64.h b/src/utils/asm-riscv64.h +new file mode 100644 +index 0000000..053b7d3 +--- /dev/null ++++ b/src/utils/asm-riscv64.h +@@ -0,0 +1,103 @@ ++/* ++ * Copyright (c) 2001-2019 Mellanox Technologies, Ltd. All rights reserved. ++ * ++ * This software is available to you under a choice of one of two ++ * licenses. You may choose to be licensed under the terms of the GNU ++ * General Public License (GPL) Version 2, available from the file ++ * COPYING in the main directory of this source tree, or the ++ * BSD license below: ++ * ++ * Redistribution and use in source and binary forms, with or ++ * without modification, are permitted provided that the following ++ * conditions are met: ++ * ++ * - Redistributions of source code must retain the above ++ * copyright notice, this list of conditions and the following ++ * disclaimer. ++ * ++ * - Redistributions in binary form must reproduce the above ++ * copyright notice, this list of conditions and the following ++ * disclaimer in the documentation and/or other materials ++ * provided with the distribution. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ++ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ++ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ++ * SOFTWARE. ++ */ ++ ++ ++#ifndef ASMRISCV64_H_ ++#define ASMRISCV64_H_ ++ ++#include ++#include ++#include ++ ++#define COPY_64B_NT(dst, src) \ ++ *dst++ = *src++; \ ++ *dst++ = *src++; \ ++ *dst++ = *src++; \ ++ *dst++ = *src++; \ ++ *dst++ = *src++; \ ++ *dst++ = *src++; \ ++ *dst++ = *src++; \ ++ *dst++ = *src++ ++ ++#define RISCV_FENCE(p, s) \ ++ __asm__ __volatile__ ("fence " #p "," #s : : : "memory") ++ ++#define mb() RISCV_FENCE(iorw,iorw) ++#define rmb() RISCV_FENCE(ir,ir) ++#define wmb() RISCV_FENCE(ow,ow) ++#define wc_wmb() wmb() ++ ++/** ++ * Add to the atomic variable. ++ * @param i integer value to add. ++ * @param v pointer of type atomic_t. ++ * @return Value before add. ++ */ ++static inline int atomic_fetch_and_add(int i, volatile int *ptr) ++{ ++ return __atomic_fetch_add(ptr, i, __ATOMIC_ACQUIRE); ++} ++ ++/** ++ * Read RDTSC register ++ */ ++static inline void gettimeoftsc(unsigned long long *p_tscval) ++{ ++ // Read Time Stamp Counter ++ asm volatile ("rdcycle %0" : "=r" (*p_tscval)); ++} ++ ++/** ++ * Cache Line Prefetch - Arch specific! ++ */ ++#ifndef L1_CACHE_BYTES ++#define L1_CACHE_BYTES 64 ++#endif ++ ++static inline void prefetch(void *x) ++{ ++ // Use simple memcpy to get data into cache ++ char temp_prefetch_block[L1_CACHE_BYTES]; ++ memcpy(temp_prefetch_block, x, L1_CACHE_BYTES); ++} ++ ++static inline void prefetch_range(void *addr, size_t len) ++{ ++ char *cp = (char*)addr; ++ char *end = (char*)addr + len; ++ for (; cp < end; cp += L1_CACHE_BYTES) ++ prefetch(cp); ++} ++ ++ ++ ++#endif +diff --git a/src/utils/asm.h b/src/utils/asm.h +index 78530cc..04ec821 100644 +--- a/src/utils/asm.h ++++ b/src/utils/asm.h +@@ -40,6 +40,8 @@ + #include "asm-ppc64.h" + #elif defined(__x86_64__) + #include "asm-x86.h" ++#elif defined(__riscv) ++#include "asm-riscv64.h" + #else + #error No architecture specific memory barrier definitions found! + #endif +-- +2.17.1 + diff --git a/libvma.spec b/libvma.spec index d740443..c1f3ecc 100644 --- a/libvma.spec +++ b/libvma.spec @@ -1,11 +1,12 @@ Name: libvma Version: 9.8.1 -Release: 1 +Release: 2 Summary: A library that boosts performance for message-based and streaming applications License: GPLv2 or BSD URL: https://github.com/Mellanox/libvma Source: https://github.com/Mellanox/libvma/archive/%{version}.tar.gz Patch0000: add-loongarch64-support-for-libvma.patch +Patch0001: add-riscv64-support.patch ExcludeArch: %{arm} Requires: pam @@ -81,6 +82,9 @@ rm -f $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/vma %changelog +* Wed Aug 09 2023 Wang Junqiang - 9.8.1-2 +- add riscv64 support + * Sat Jul 15 2023 wulei - 9.8.1-1 - Update to 9.8.1 -- Gitee