Skip to content

Commit 5d2bddc

Browse files
committed
Add RISC64 Timer Implemention.To ensure the timer works properly on the RISC-V platform.
Signed-off-by: heyujiao99 <[email protected]>
1 parent d9cccba commit 5d2bddc

File tree

8 files changed

+91
-1
lines changed

8 files changed

+91
-1
lines changed

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

opal/include/opal/sys/cma.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
# define __NR_process_vm_readv 270
6060
# define __NR_process_vm_writev 271
6161

62+
# elif defined(PLATFORM_ARCH_RISCV)
63+
# define __NR_process_vm_readv 270
64+
# define __NR_process_vm_writev 271
65+
6266
# else
6367
# error "Unsupported architecture for process_vm_readv and process_vm_writev syscalls"
6468
# endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3+
# University Research and Technology
4+
# Corporation. All rights reserved.
5+
# Copyright (c) 2004-2005 The University of Tennessee and The University
6+
# of Tennessee Research Foundation. All rights
7+
# reserved.
8+
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9+
# University of Stuttgart. All rights reserved.
10+
# Copyright (c) 2004-2005 The Regents of the University of California.
11+
# All rights reserved.
12+
# Copyright (c) 2017 Research Organization for Information Science
13+
# and Technology (RIST). All rights reserved.
14+
# $COPYRIGHT$
15+
#
16+
# Additional copyrights may follow
17+
#
18+
# $HEADER$
19+
#
20+
21+
# This makefile.am does not stand on its own - it is included from opal/include/Makefile.am
22+
23+
headers += \
24+
opal/sys/riscv64/timer.h
25+

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2008 The University of Tennessee and The University
4+
* of Tennessee Research Foundation. All rights
5+
* reserved.
6+
* Copyright (c) 2016 Broadcom Limited. All rights reserved.
7+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
8+
* reserved.
9+
* Copyright (c) 2021 Google, LLC. All rights reserved.
10+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
11+
* All Rights reserved.
12+
* $COPYRIGHT$
13+
*
14+
* Additional copyrights may follow
15+
*
16+
* $HEADER$
17+
*/
18+
19+
#ifndef OPAL_SYS_ARCH_TIMER_H
20+
#define OPAL_SYS_ARCH_TIMER_H 1
21+
22+
typedef uint64_t opal_timer_t;
23+
24+
#if OPAL_C_GCC_INLINE_ASSEMBLY
25+
26+
static inline opal_timer_t opal_sys_timer_get_cycles(void)
27+
{
28+
opal_timer_t ret;
29+
__asm__ __volatile__("fence iorw, iorw" ::: "memory");
30+
__asm__ __volatile__("rdtime %0" : "=r"(ret));
31+
32+
return ret;
33+
}
34+
35+
#define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1
36+
37+
#endif /* OPAL_C_GCC_INLINE_ASSEMBLY */
38+
39+
#endif /* ! OPAL_SYS_ARCH_TIMER_H */
40+

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <string.h>
3131
#include <time.h>
32+
#include <arpa/inet.h>
3233

3334
#include "opal/constants.h"
3435
#include "opal/mca/timer/base/base.h"
@@ -177,6 +178,20 @@ static int opal_timer_linux_find_freq(void)
177178
}
178179
}
179180

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

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

0 commit comments

Comments
 (0)