Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WT-8497 Initial riscv64 support #7269

Merged
merged 8 commits into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions SConstruct
Expand Up @@ -253,6 +253,7 @@ condition_map = {
'ARM64_HOST' : False,
'POSIX_HOST' : env['PLATFORM'] == 'posix',
'POWERPC_HOST' : False,
'RISCV64_HOST' : False,
keithbostic marked this conversation as resolved.
Show resolved Hide resolved
'WINDOWS_HOST' : env['PLATFORM'] == 'win32',
'X86_HOST' : True,
'ZSERIES_HOST' : False,
Expand Down
4 changes: 4 additions & 0 deletions build_posix/configure.ac.in
Expand Up @@ -64,6 +64,10 @@ AS_CASE([$host_cpu],
[s390x*], [wt_cv_zseries="yes"],
[wt_cv_zseries="no"])
AM_CONDITIONAL([ZSERIES_HOST], [test "$wt_cv_zseries" = "yes"])
AS_CASE([$host_cpu],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pure copy paste from the nearby arm stanza, but I did an autoreconf and configure / make and it all seemed to work OK.

[riscv64*], [wt_cv_riscv64="yes"],
[wt_cv_riscv64="no"])
AM_CONDITIONAL([RISCV64_HOST], [test "$wt_cv_riscv64" = "yes"])
AS_CASE([$host_cpu],
[aarch64*], [wt_cv_arm64="yes"],
[wt_cv_arm64="no"])
Expand Down
1 change: 1 addition & 0 deletions cmake/configs/base.cmake
Expand Up @@ -18,6 +18,7 @@ config_choice(
"aarch64;WT_AARCH64;"
"ppc64le;WT_PPC64;"
"s390x;WT_S390X;"
"riscv64;WT_RISCV64;"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By analogy with WT_AARCH64 case.

)

config_choice(
Expand Down
23 changes: 23 additions & 0 deletions cmake/configs/riscv64/linux/config.cmake
@@ -0,0 +1,23 @@
#
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By analogy with the aarch64 one.

# Public Domain 2014-present MongoDB, Inc.
# Public Domain 2008-2014 WiredTiger, Inc.
# All rights reserved.
#
# See the file LICENSE for redistribution information
#
include(CheckCCompilerFlag)

set(WT_ARCH "riscv64" CACHE STRING "")
set(WT_OS "linux" CACHE STRING "")
set(WT_POSIX ON CACHE BOOL "")

# Linux requires '_GNU_SOURCE' to be defined for access to GNU/Linux extension functions
# e.g. Access to O_DIRECT on Linux. Append this macro to our compiler flags for Linux-based
# builds.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE" CACHE STRING "" FORCE)

# Linux requires buffers aligned to 4KB boundaries for O_DIRECT to work.
set(WT_BUFFER_ALIGNMENT_DEFAULT "4096" CACHE STRING "")

# ARMv8-A is the 64-bit ARM architecture, turn on the optional CRC instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems to come from the aarch64 config. Might be worth rewording to quickly state what the rv64imafdc and lp64d flags are for.
(Thanks for the background link!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to update this comment, which seems to have been pasted from the arm file :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=rv64imafdc -mabi=lp64d" CACHE STRING "" FORCE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://www.sifive.com/blog/all-aboard-part-1-compiler-args for background on the mafdc and lp64d arguments here.

2 changes: 2 additions & 0 deletions cmake/helpers.cmake
Expand Up @@ -610,6 +610,8 @@ function(parse_filelist_source filelist output_var)
set(arch_host "POWERPC_HOST")
elseif(WT_S390X)
set(arch_host "ZSERIES_HOST")
elseif(WT_RISCV64)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By analogy with aarch64

set(arch_host "RISCV64_HOST")
endif()
# Determine platform host for our filelist parse.
if(WT_POSIX)
Expand Down
15 changes: 15 additions & 0 deletions cmake/toolchains/riscv64/linux/plat_clang.cmake
@@ -0,0 +1,15 @@
#
# Public Domain 2014-present MongoDB, Inc.
# Public Domain 2008-2014 WiredTiger, Inc.
# All rights reserved.
#
# See the file LICENSE for redistribution information.
#

if(CMAKE_CROSSCOMPILING)
set(TRIPLE_TARGET "riscv64-unknown-linux-gnu")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By analogy, untested

set(CROSS_COMPILER_PREFIX ${TRIPLE_TARGET}-)
set(CMAKE_C_COMPILER_TARGET "${TRIPLE_TARGET}")
set(CMAKE_CXX_COMPILER_TARGET "${TRIPLE_TARGET}")
set(CMAKE_ASM_COMPILER_TARGET "${TRIPLE_TARGET}")
endif()
11 changes: 11 additions & 0 deletions cmake/toolchains/riscv64/linux/plat_gcc.cmake
@@ -0,0 +1,11 @@
#
# Public Domain 2014-present MongoDB, Inc.
# Public Domain 2008-2014 WiredTiger, Inc.
# All rights reserved.
#
# See the file LICENSE for redistribution information.
#

if(CMAKE_CROSSCOMPILING)
set(CROSS_COMPILER_PREFIX "riscv64-linux-gnu-")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By analogy, untested

endif()
1 change: 1 addition & 0 deletions dist/filelist
Expand Up @@ -50,6 +50,7 @@ src/btree/row_srch.c
src/checksum/arm64/crc32-arm64.c ARM64_HOST
src/checksum/power8/crc32.sx POWERPC_HOST
src/checksum/power8/crc32_wrapper.c POWERPC_HOST
src/checksum/riscv64/crc32-riscv64.c RISCV64_HOST
keithbostic marked this conversation as resolved.
Show resolved Hide resolved
src/checksum/software/checksum.c
src/checksum/x86/crc32-x86-alt.c X86_HOST
src/checksum/x86/crc32-x86.c X86_HOST
Expand Down
2 changes: 2 additions & 0 deletions dist/prototypes.py 100644 → 100755
Expand Up @@ -60,6 +60,8 @@ def prototypes_extern():
continue
if fnmatch.fnmatch(name, '*/checksum/power8/*'):
continue
if fnmatch.fnmatch(name, '*/checksum/riscv64/*'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By analogy, untested.

continue
if fnmatch.fnmatch(name, '*/checksum/zseries/*'):
continue
if fnmatch.fnmatch(name, '*/os_posix/*'):
Expand Down
49 changes: 49 additions & 0 deletions src/checksum/riscv64/crc32-riscv64.c
@@ -0,0 +1,49 @@
/*-
* Public Domain 2014-present MongoDB, Inc.
* Public Domain 2008-2014 WiredTiger, Inc.
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* 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 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.
*/

#include <wiredtiger_config.h>
#include <inttypes.h>
#include <stddef.h>

extern uint32_t __wt_checksum_sw(const void *chunk, size_t len);

#if defined(__GNUC__)
extern uint32_t (*wiredtiger_crc32c_func(void))(const void *, size_t)
__attribute__((visibility("default")));
#else
extern uint32_t (*wiredtiger_crc32c_func(void))(const void *, size_t);
#endif

/*
* wiredtiger_crc32c_func --
* WiredTiger: detect CRC hardware and return the checksum function.
*/
uint32_t (*wiredtiger_crc32c_func(void))(const void *, size_t)
keithbostic marked this conversation as resolved.
Show resolved Hide resolved
{
return (__wt_checksum_sw);
}
4 changes: 2 additions & 2 deletions src/docs/arch-fs-os.dox
Expand Up @@ -56,6 +56,6 @@ is mainly used for non-critical functionalities such as writing verbose messages
writing to WiredTiger statistics logs.

@section filesystem_usage Multiple System Architecture Support
WiredTiger supports x86_64, i386, mips, ppc, aarch64, s390x, and sparc system architectures
which are found in gcc.h.
WiredTiger supports x86_64, i386, mips, ppc, aarch64, s390x, riscv64 and sparc system
architectures which are found in gcc.h.
*/
17 changes: 17 additions & 0 deletions src/include/gcc.h
Expand Up @@ -280,6 +280,23 @@ WT_ATOMIC_FUNC(size, size_t, size_t *vp, size_t v)
__asm__ volatile("" ::: "memory"); \
} while (0)


#elif defined(__riscv) && (__riscv_xlen == 64)
#define WT_PAUSE() __asm__ volatile("nop" ::: "memory")
keithbostic marked this conversation as resolved.
Show resolved Hide resolved
#define WT_FULL_BARRIER() \
keithbostic marked this conversation as resolved.
Show resolved Hide resolved
do { \
__asm__ volatile("fence rw, rw" ::: "memory"); \
} while (0)
#define WT_READ_BARRIER() \
do { \
__asm__ volatile("fence r, r" ::: "memory"); \
} while (0)
#define WT_WRITE_BARRIER() \
do { \
__asm__ volatile("fence w, w" ::: "memory"); \
} while (0)


#else
#error "No write barrier implementation for this hardware"
#endif