# RE: \[PATCH v2 3/4\] tools headers UAPI: add cpu\_relax() implementation for x86 and arm64

- From: David Laight \<hidden\>
- Date: 2021-07-21 20:53:41 
- List: virtualization
- Page: https://ratatoskr.run/virtualization/2021/07/1453860
- Thread: https://ratatoskr.run/netdev/2021/07/1451874/t.md

```text
From: Yunsheng Lin
> Sent: 20 July 2021 03:22
> 
> As x86 and arm64 is the two available systems that I can build
> and test the cpu_relax() implementation, so only add cpu_relax()
> implementation for x86 and arm64, other arches can be added easily
> when needed.
> 
...
> +#if defined(__i386__) || defined(__x86_64__)
> +/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
> +static __always_inline void rep_nop(void)
> +{
> +	asm volatile("rep; nop" ::: "memory");
> +}

Beware, Intel increased the stall for 'rep nop' in some recent
cpu to IIRC about 200 cycles.

They even document that this might have a detrimental effect.
It is basically far too long for the sort of thing it makes
sense to busy-wait for.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
```
