Skip to content

Commit efab291

Browse files
committed
Add RISC64 Timer Implemention and RISCV64 ci test with qemu.
Signed-off-by: heyujiao99 <[email protected]>
1 parent d9cccba commit efab291

File tree

8 files changed

+121
-1
lines changed

8 files changed

+121
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: riscv64-qemu-test
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
env:
9+
riscv_gnu_toolchain_download_path: https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.07.03/riscv64-glibc-ubuntu-24.04-gcc-nightly-2025.07.03-nightly.tar.xz
10+
11+
steps:
12+
- name: Install depencencies
13+
run: |
14+
sudo apt update
15+
sudo apt install -y --no-install-recommends qemu-user wget
16+
wget ${riscv_gnu_toolchain_download_path}
17+
tar -xvf riscv64-glibc-ubuntu-24.04-gcc-nightly-2025.07.03-nightly.tar.xz -C /opt
18+
sed -i "s|libdir='/mnt/riscv/riscv64-unknown-linux-gnu/lib'|libdir='/opt/riscv/riscv64-unknown-linux-gnu/lib'|g" /opt/riscv/riscv64-unknown-linux-gnu/lib/libatomic.la
19+
20+
- name: Checkout Open MPI
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: recursive
24+
25+
- name: Bootstrap Open MPI
26+
run: |
27+
./autogen.pl
28+
sed -i '/^func_exec_program_core ()/,/^}/ s/\<exec\>/exec qemu-riscv64 -cpu rv64,v=true,vext_spec=v1.0,vlen=128 -L \/opt\/riscv\/sysroot/g' config/ltmain.sh
29+
30+
- name: Config Open MPI
31+
run: |
32+
export PATH="/opt/riscv/bin:$PATH"
33+
export LD_LIBRARY_PATH="/opt/riscv/lib:$LD_LIBRARY_PATH"
34+
./configure --prefix=/opt/riscv --host=riscv64-unknown-linux-gnu SYSROOT=/opt/riscv/sysroot CC=riscv64-unknown-linux-gnu-gcc LD=riscv64-unknown-linux-gnu-ld --disable-mpi-fortran --disable-sphinx LDFLAGS=-Wl,-rpath-link,/opt/riscv/lib CFLAGS="-march=rv64gcv"
35+
36+
- name: Build Open MPI
37+
run: |
38+
export PATH="/opt/riscv/bin:$PATH"
39+
export LD_LIBRARY_PATH="/opt/riscv/lib:$LD_LIBRARY_PATH"
40+
sed -i 's/#define OPAL_HAVE_GCC_BUILTIN_CSWAP_INT128 1/#define OPAL_HAVE_GCC_BUILTIN_CSWAP_INT128 0/' ./opal/include/opal_config.h
41+
make -j 8
42+
make install
43+
44+
- name: Run testsuite
45+
run: |
46+
export PATH="/opt/riscv/bin:$PATH"
47+
export LD_LIBRARY_PATH="/opt/riscv/lib:$LD_LIBRARY_PATH"
48+
make check

config/opal_config_asm.m4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ AC_DEFUN([OPAL_CHECK_INLINE_C_GCC],[
538538
powerpc-*|powerpc64-*|powerpcle-*|powerpc64le-*|rs6000-*|ppc-*)
539539
opal_gcc_inline_assign='"1: li %0,0" : "=&r"(ret)'
540540
;;
541+
riscv64*)
542+
opal_gcc_inline_assign='"li %0, 0" : "=&r"(ret)'
543+
;;
541544
esac
542545
543546
AS_IF([test "$opal_gcc_inline_assign" != ""],

opal/include/opal/sys/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ headers += \
4242
include opal/sys/x86_64/Makefile.am
4343
include opal/sys/arm64/Makefile.am
4444
include opal/sys/powerpc/Makefile.am
45+
include opal/sys/riscv64/Makefile.am
4546
include opal/sys/gcc_builtin/Makefile.am
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (c) 2025 Software System Team, SANECHIPS.
3+
# All rights reserved.
4+
# $COPYRIGHT$
5+
#
6+
# Additional copyrights may follow
7+
#
8+
# $HEADER$
9+
#
10+
11+
# This makefile.am does not stand on its own - it is included from opal/include/Makefile.am
12+
13+
headers += \
14+
opal/sys/riscv64/timer.h
15+

opal/include/opal/sys/riscv64/timer.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2025 Software System Team, SANECHIPS.
4+
* All rights reserved.
5+
* $COPYRIGHT$
6+
*
7+
* Additional copyrights may follow
8+
*
9+
* $HEADER$
10+
*/
11+
12+
#ifndef OPAL_SYS_ARCH_TIMER_H
13+
#define OPAL_SYS_ARCH_TIMER_H 1
14+
15+
typedef uint64_t opal_timer_t;
16+
17+
#if OPAL_C_GCC_INLINE_ASSEMBLY
18+
19+
static inline opal_timer_t opal_sys_timer_get_cycles(void)
20+
{
21+
opal_timer_t ret;
22+
__asm__ __volatile__("fence.i");
23+
__asm__ __volatile__("fence r, r" ::: "memory");
24+
__asm__ __volatile__("rdtime %0" : "=r"(ret));
25+
26+
return ret;
27+
}
28+
29+
#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1
30+
31+
#endif /* OPAL_C_GCC_INLINE_ASSEMBLY */
32+
33+
#endif /* ! OPAL_SYS_ARCH_TIMER_H */
34+

opal/include/opal/sys/timer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ BEGIN_C_DECLS
6363
# include "opal/sys/arm64/timer.h"
6464
#elif defined(PLATFORM_ARCH_POWERPC)
6565
# include "opal/sys/powerpc/timer.h"
66+
#elif defined(PLATFORM_ARCH_RISCV)
67+
# include "opal/sys/riscv64/timer.h"
6668
#endif
6769

6870
#ifndef DOXYGEN

opal/mca/timer/linux/configure.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ AC_DEFUN([MCA_opal_timer_linux_CONFIG],[
4747
[timer_linux_happy="no"])])
4848

4949
case "${host}" in
50-
i?86-*linux*|x86_64*linux*|ia64-*linux*|powerpc-*linux*|powerpc64-*linux*|powerpc64le-*linux*|powerpcle-*linux*|sparc*-*linux*|aarch64-*linux*)
50+
i?86-*linux*|x86_64*linux*|ia64-*linux*|powerpc-*linux*|powerpc64-*linux*|powerpc64le-*linux*|powerpcle-*linux*|sparc*-*linux*|aarch64-*linux*|riscv64-*linux*)
5151
AS_IF([test "$timer_linux_happy" = "yes"],
5252
[AS_IF([test -r "/proc/cpuinfo"],
5353
[timer_linux_happy="yes"],

opal/mca/timer/linux/timer_linux_component.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* Copyright (c) 2016 Broadcom Limited. All rights reserved.
1919
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
2020
* All Rights reserved.
21+
* Copyright (c) 2025 Software System Team, SANECHIPS.
22+
* All rights reserved.
2123
* $COPYRIGHT$
2224
*
2325
* Additional copyrights may follow
@@ -29,6 +31,7 @@
2931

3032
#include <string.h>
3133
#include <time.h>
34+
#include <arpa/inet.h>
3235

3336
#include "opal/constants.h"
3437
#include "opal/mca/timer/base/base.h"
@@ -177,6 +180,20 @@ static int opal_timer_linux_find_freq(void)
177180
}
178181
}
179182

183+
#if defined(PLATFORM_ARCH_RISCV)
184+
if (0 == opal_timer_linux_freq) {
185+
/* read timebase-frequency in device-tree */
186+
FILE *fp_rv = fopen("/proc/device-tree/cpus/timebase-frequency", "rb");
187+
if (NULL == fp_rv) {
188+
return OPAL_ERR_IN_ERRNO;
189+
}
190+
if (1 == fread(&opal_timer_linux_freq, 4, 1, fp_rv)){
191+
opal_timer_linux_freq = ntohl(opal_timer_linux_freq);
192+
}
193+
fclose(fp_rv);
194+
}
195+
#endif
196+
180197
fclose(fp);
181198

182199
/* convert the timer frequency to MHz to avoid an extra operation when

0 commit comments

Comments
 (0)