From c41738c8f3fd7ad6bd293c73414c3da32a12ebf4 Mon Sep 17 00:00:00 2001 From: jiangfeilong Date: Sat, 26 Nov 2022 15:59:37 +0800 Subject: [PATCH 1/3] Add detection of satp mode --- src/hotspot/cpu/riscv/vm_version_riscv.cpp | 7 ++++++ src/hotspot/cpu/riscv/vm_version_riscv.hpp | 12 +++++++++ .../linux_riscv/vm_version_linux_riscv.cpp | 25 ++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.cpp b/src/hotspot/cpu/riscv/vm_version_riscv.cpp index 560d7e6961464..f03990496ea6b 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.cpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.cpp @@ -31,11 +31,18 @@ #include "utilities/macros.hpp" const char* VM_Version::_uarch = ""; +const char* VM_Version::_vm_mode = ""; uint32_t VM_Version::_initial_vector_length = 0; void VM_Version::initialize() { get_os_cpu_info(); + // check if satp.mode is supported, currently supports up to SV48(rv64)/SV32(rv32) + VM_MODE mode = get_satp_mode(); + if (mode > RISCV64_ONLY(VM_SV48) RISCV32_ONLY(VM_SV32)) { + vm_exit_during_initialization(err_msg("Unsupported satp mode: %d", mode)); + } + // https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva20-profiles if (UseRVA20U64) { if (FLAG_IS_DEFAULT(UseRVC)) { diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.hpp b/src/hotspot/cpu/riscv/vm_version_riscv.hpp index 1d6eeb97504c9..52b51f65a242d 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.hpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.hpp @@ -38,11 +38,23 @@ class VM_Version : public Abstract_VM_Version { static void c2_initialize(); #endif // COMPILER2 +// VM modes (satp.mode) privileged ISA 1.10 +enum VM_MODE { + VM_MBARE = 0, + VM_SV32 = 1, + VM_SV39 = 8, + VM_SV48 = 9, + VM_SV57 = 10, + VM_SV64 = 11 +}; + protected: static const char* _uarch; + static const char* _vm_mode; static uint32_t _initial_vector_length; static void get_os_cpu_info(); static uint32_t get_current_vector_length(); + static VM_MODE get_satp_mode(); public: // Initialization diff --git a/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp b/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp index a954dcf5768ce..df4da9894dd9a 100644 --- a/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp +++ b/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp @@ -75,6 +75,22 @@ uint32_t VM_Version::get_current_vector_length() { return (uint32_t)read_csr(CSR_VLENB); } +VM_Version::VM_MODE VM_Version::get_satp_mode() { + if (!strcmp(_vm_mode, "sv32")) { + return VM_SV32; + } else if (!strcmp(_vm_mode, "sv39")) { + return VM_SV39; + } else if (!strcmp(_vm_mode, "sv48")) { + return VM_SV48; + } else if (!strcmp(_vm_mode, "sv57")) { + return VM_SV57; + } else if (!strcmp(_vm_mode, "sv64")) { + return VM_SV64; + } else { + return VM_MBARE; + } +} + void VM_Version::get_os_cpu_info() { uint64_t auxv = getauxval(AT_HWCAP); @@ -103,7 +119,14 @@ void VM_Version::get_os_cpu_info() { char buf[512], *p; while (fgets(buf, sizeof (buf), f) != NULL) { if ((p = strchr(buf, ':')) != NULL) { - if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) { + if (strncmp(buf, "mmu", sizeof "mmu" - 1) == 0) { + if (_vm_mode[0] != '\0') { + continue; + } + char* vm_mode = os::strdup(p + 2); + vm_mode[strcspn(vm_mode, "\n")] = '\0'; + _vm_mode = vm_mode; + } else if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) { char* uarch = os::strdup(p + 2); uarch[strcspn(uarch, "\n")] = '\0'; _uarch = uarch; From abfa5f97b2f73bdde8d2116882424ba2c52c7751 Mon Sep 17 00:00:00 2001 From: jiangfeilong Date: Tue, 29 Nov 2022 09:37:57 +0800 Subject: [PATCH 2/3] print vm mode string instead of vm mode code --- src/hotspot/cpu/riscv/vm_version_riscv.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.cpp b/src/hotspot/cpu/riscv/vm_version_riscv.cpp index f03990496ea6b..99d4b7e41ec01 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.cpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.cpp @@ -37,10 +37,9 @@ uint32_t VM_Version::_initial_vector_length = 0; void VM_Version::initialize() { get_os_cpu_info(); - // check if satp.mode is supported, currently supports up to SV48(rv64)/SV32(rv32) - VM_MODE mode = get_satp_mode(); - if (mode > RISCV64_ONLY(VM_SV48) RISCV32_ONLY(VM_SV32)) { - vm_exit_during_initialization(err_msg("Unsupported satp mode: %d", mode)); + // check if satp.mode is supported, currently supports up to SV48(RV64)/SV32(RV32) + if (get_satp_mode() > RISCV64_ONLY(VM_SV48) RISCV32_ONLY(VM_SV32)) { + vm_exit_during_initialization(err_msg("Unsupported satp mode: %s", _vm_mode)); } // https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva20-profiles From 297ce94ba9faa3379fa297ec6e61a759c8a15749 Mon Sep 17 00:00:00 2001 From: FreedomLy Date: Tue, 29 Nov 2022 22:21:51 +0800 Subject: [PATCH 3/3] remove sv32 --- src/hotspot/cpu/riscv/vm_version_riscv.cpp | 4 ++-- src/hotspot/cpu/riscv/vm_version_riscv.hpp | 1 - src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.cpp b/src/hotspot/cpu/riscv/vm_version_riscv.cpp index 99d4b7e41ec01..6afef7ae546f2 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.cpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.cpp @@ -37,8 +37,8 @@ uint32_t VM_Version::_initial_vector_length = 0; void VM_Version::initialize() { get_os_cpu_info(); - // check if satp.mode is supported, currently supports up to SV48(RV64)/SV32(RV32) - if (get_satp_mode() > RISCV64_ONLY(VM_SV48) RISCV32_ONLY(VM_SV32)) { + // check if satp.mode is supported, currently supports up to SV48(RV64) + if (get_satp_mode() > VM_SV48) { vm_exit_during_initialization(err_msg("Unsupported satp mode: %s", _vm_mode)); } diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.hpp b/src/hotspot/cpu/riscv/vm_version_riscv.hpp index 52b51f65a242d..39c127e9285b7 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.hpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.hpp @@ -41,7 +41,6 @@ class VM_Version : public Abstract_VM_Version { // VM modes (satp.mode) privileged ISA 1.10 enum VM_MODE { VM_MBARE = 0, - VM_SV32 = 1, VM_SV39 = 8, VM_SV48 = 9, VM_SV57 = 10, diff --git a/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp b/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp index df4da9894dd9a..8d13894031287 100644 --- a/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp +++ b/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp @@ -76,9 +76,7 @@ uint32_t VM_Version::get_current_vector_length() { } VM_Version::VM_MODE VM_Version::get_satp_mode() { - if (!strcmp(_vm_mode, "sv32")) { - return VM_SV32; - } else if (!strcmp(_vm_mode, "sv39")) { + if (!strcmp(_vm_mode, "sv39")) { return VM_SV39; } else if (!strcmp(_vm_mode, "sv48")) { return VM_SV48;