On 18.12.2023 11:49, Oleksii wrote: > On Thu, 2023-12-14 at 17:04 +0100, Jan Beulich wrote: >> On 24.11.2023 11:30, Oleksii Kurochko wrote: >>> +static inline void cpu_relax(void) >>> +{ >>> + int dummy; >>> + /* In lieu of a halt instruction, induce a long-latency >>> stall. */ >>> + __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy)); >> >> Any reason for this, when Arm's is just barrier(), and apparently >> they got >> away with this quite fine? Also isn't this causing a division by >> zero, >> which I'd expect to cause some kind of exception? (Terminology-wise >> I'm of >> course biased by x86, where "halt instruction" wouldn't be suitable >> to use >> here. But if that terminology is fine on RISC-V, then obviously no >> objection.) > It was based on Linux kernel code: > https://elixir.bootlin.com/linux/latest/source/arch/riscv/include/asm/vdso/processor.h#L9 > > But looks I missed barrier()... > Probably it will be better update cpu_relax() to: > > /* Encoding of the pause instruction */ > __asm__ __volatile__ (".4byte 0x100000F"); > > barrier();
But definitely without .4byte, which defines a piece of data. If for whatever reason you don't want to use "pause" directly, please use .insn. Jan