Atomic macros versus Spin locks
Once in a while, I do Kernel programming in kernel space. I was told that atomic operations uses LOCK instruction in x86 and hence these are not good to use. I was told that incrementing variable under spin locks is a better option than using atomic_inc.
Based on number of instructions that gets executed in atomic_inc function is very small compared to instructions it takes to do lock, increment variables and release lock. Hence I expect using atomic_inc is better option from performance perspective. My simple experiment also proved this. But my colleague says that when there is any PCI traffic such as Ethernet traffic, then one would see the atomic_inc is not relatively good.
Any comments?
Thanks
Ravi
|