From 35bccacb6618e9ec686be895a9ef6ba8f3375ef0 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 11 Sep 2023 09:02:40 +0000 Subject: [PATCH] 8315841: RISC-V: Check for hardware TSO support Reviewed-by: vkempik, rehn, fyang --- src/hotspot/cpu/riscv/globals_riscv.hpp | 1 + src/hotspot/cpu/riscv/macroAssembler_riscv.hpp | 18 +++++++++++++++++- src/hotspot/cpu/riscv/vm_version_riscv.cpp | 8 ++++++++ src/hotspot/cpu/riscv/vm_version_riscv.hpp | 1 + .../linux_riscv/vm_version_linux_riscv.cpp | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/hotspot/cpu/riscv/globals_riscv.hpp b/src/hotspot/cpu/riscv/globals_riscv.hpp index ce572fd9a4d..8b98198df4a 100644 --- a/src/hotspot/cpu/riscv/globals_riscv.hpp +++ b/src/hotspot/cpu/riscv/globals_riscv.hpp @@ -109,6 +109,7 @@ define_pd_global(intx, InlineSmallCode, 1000); product(bool, UseZicbom, false, EXPERIMENTAL, "Use Zicbom instructions") \ product(bool, UseZicbop, false, EXPERIMENTAL, "Use Zicbop instructions") \ product(bool, UseZicboz, false, EXPERIMENTAL, "Use Zicboz instructions") \ + product(bool, UseZtso, false, EXPERIMENTAL, "Assume Ztso memory model") \ product(bool, UseZihintpause, false, EXPERIMENTAL, \ "Use Zihintpause instructions") \ product(bool, UseRVVForBigIntegerShiftIntrinsics, true, \ diff --git a/src/hotspot/cpu/riscv/macroAssembler_riscv.hpp b/src/hotspot/cpu/riscv/macroAssembler_riscv.hpp index 346acab60fb..c0cef96e305 100644 --- a/src/hotspot/cpu/riscv/macroAssembler_riscv.hpp +++ b/src/hotspot/cpu/riscv/macroAssembler_riscv.hpp @@ -376,8 +376,24 @@ class MacroAssembler: public Assembler { return ((predecessor & 0x3) << 2) | (successor & 0x3); } + void fence(uint32_t predecessor, uint32_t successor) { + if (UseZtso) { + if ((pred_succ_to_membar_mask(predecessor, successor) & StoreLoad) == StoreLoad) { + // TSO allows for stores to be reordered after loads. When the compiler + // generates a fence to disallow that, we are required to generate the + // fence for correctness. + Assembler::fence(predecessor, successor); + } else { + // TSO guarantees other fences already. + } + } else { + // always generate fence for RVWMO + Assembler::fence(predecessor, successor); + } + } + void pause() { - fence(w, 0); + Assembler::fence(w, 0); } // prints msg, dumps registers and stops execution diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.cpp b/src/hotspot/cpu/riscv/vm_version_riscv.cpp index cf64e08ebc8..78b64456dfa 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.cpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.cpp @@ -210,6 +210,14 @@ void VM_Version::initialize() { unaligned_access.value() == MISALIGNED_FAST); } +#ifdef __riscv_ztso + // Hotspot is compiled with TSO support, it will only run on hardware which + // supports Ztso + if (FLAG_IS_DEFAULT(UseZtso)) { + FLAG_SET_DEFAULT(UseZtso, true); + } +#endif + if (UseZbb) { if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { FLAG_SET_DEFAULT(UsePopCountInstruction, true); diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.hpp b/src/hotspot/cpu/riscv/vm_version_riscv.hpp index 39c4150cea8..6bfb139486b 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.hpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.hpp @@ -134,6 +134,7 @@ class VM_Version : public Abstract_VM_Version { decl(ext_Zicsr , "Zicsr" , RV_NO_FLAG_BIT, true , NO_UPDATE_DEFAULT) \ decl(ext_Zifencei , "Zifencei" , RV_NO_FLAG_BIT, true , NO_UPDATE_DEFAULT) \ decl(ext_Zic64b , "Zic64b" , RV_NO_FLAG_BIT, true , UPDATE_DEFAULT(UseZic64b)) \ + decl(ext_Ztso , "Ztso" , RV_NO_FLAG_BIT, true , UPDATE_DEFAULT(UseZtso)) \ decl(ext_Zihintpause , "Zihintpause" , RV_NO_FLAG_BIT, true , UPDATE_DEFAULT(UseZihintpause)) \ decl(mvendorid , "VendorId" , RV_NO_FLAG_BIT, false, NO_UPDATE_DEFAULT) \ decl(marchid , "ArchId" , RV_NO_FLAG_BIT, false, NO_UPDATE_DEFAULT) \ 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 c3544a4d9fc..454ffbb06d3 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 @@ -236,6 +236,7 @@ void VM_Version::rivos_features() { ext_Zicsr.enable_feature(); ext_Zifencei.enable_feature(); ext_Zic64b.enable_feature(); + ext_Ztso.enable_feature(); ext_Zihintpause.enable_feature(); unaligned_access.enable_feature(MISALIGNED_FAST);