Re: Suboptimal spinlock code due to volatile

2024-07-30 Thread Robert Haas
On Tue, Jul 30, 2024 at 3:46 AM Heikki Linnakangas wrote: > Aside from performance, I find "volatile" difficult to reason about. I > feel more comfortable with atomics and memory barriers. I think nearly everyone feels more comfortable with atomics and memory barriers. The semantics of volatile a

Re: Suboptimal spinlock code due to volatile

2024-07-30 Thread Heikki Linnakangas
On 29/07/2024 22:59, Andres Freund wrote: After being confused for a while, the explanation is fairly simple: We use volatile and dereference the address: static __inline__ int tas(volatile slock_t *lock) { slock_t _res = 1; __asm__ __volatile__( " lock

Suboptimal spinlock code due to volatile

2024-07-29 Thread Andres Freund
Hi, As part of [1] I was staring at the assembly code generated for SpinLockAcquire(), fairly randomly using GetRecoveryState() as the example. On master, in an optimized build this generates the following code (gcc 12 in this case, but it doesn't really matter): 4220 : 4220: