Could std::hint::spin_loop actually be undesirable in aarch64 spin locks?

Today I found, that on aarch64, the std::hint::spin_loop translates to ISB SY. This instruction invalidates instruction caches, essentially throwing away all prefetched instructions, so that CPU has to redo the prefetch.

I was looking for the reason for why this is the case. Searching through the repo, I found that it is done as something that tries to put the processor to sleep.

Question: does that mean, that this hint is undesirable when doing spin locks that one expects to succeed on the first try (e.g. when performing optimistic concurrency control)?

It varies processor to processor. Only benchmark your case will tell you.
First try would likely be written not call the hint if successful.

1 Like

@jonh oh, right, I'm a dummy, I got so confused by the other answer to my SO question that I've forgotten that you wouldn't even get to that instruction in that case.

Thanks for straightening up my mind!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.