RFR: 8295282: Use Zicboz/cbo.zero to zero-out memory on RISC-V [v6]

Fei Yang fyang at openjdk.org
Thu Oct 20 14:23:53 UTC 2022


On Wed, 19 Oct 2022 10:28:20 GMT, Ludovic Henry <luhenry at openjdk.org> wrote:

>> Similarly to AArch64 DC.ZVA, the RISC-V Zicboz [1] extension provides the cbo.zero [2] instruction that allows to zero out memory a cache-line at a time. This should be faster than storing zeroes 64bits at a time.
>> 
>> [1] https://github.com/riscv/riscv-CMOs
>> [2] https://github.com/riscv/riscv-CMOs/blob/master/cmobase/Zicboz.adoc#insns-cbo_zero
>
> Ludovic Henry has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Explicit use of temp registers
>  - fixup! Add -XX:CacheLineSize= to set cache line size

Changes requested by fyang (Reviewer).

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp line 4127:

> 4125:   sub(cnt, cnt, tmp2);
> 4126:   add(tmp3, zr, zr);
> 4127:   movptr(tmp3, initial_table_end);

I think it will be more efficient if we make use of 'auipc' instruction here for this purpose. The current version which makes use of 'movptr' will emits 6 instructions.

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp line 4136:

> 4134:   bind(initial_table_end);
> 4135: 
> 4136:   li(tmp1, CacheLineSize >> 3);

It will be more consistent to use 'mv' here instead of 'li'. I am considering making 'li' a private method.

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp line 685:

> 683:       Label small;
> 684:       int low_limit = MAX2(CacheLineSize, BlockZeroingLowLimit);
> 685:       __ li(t0, low_limit);

Save as above.

src/hotspot/cpu/riscv/vm_version_riscv.cpp line 48:

> 46: 
> 47:   if (!FLAG_IS_DEFAULT(CacheLineSize) && !is_power_of_2(CacheLineSize)) {
> 48:     warning("CacheLineSize must be a power of 2");

TBH, I am worried about the case when user specified some inaccurate cache-line size here, especially when the specified value is bigger than the actual cache-line size. The currently implementation won't work in that case. We really need some way to determine the cache-line size at runtime to be safe.

-------------

PR: https://git.openjdk.org/jdk/pull/10718


More information about the hotspot-dev mailing list