Re: i386 spinlock fairness: bizarre test results

From: Robert Hancock
Date: Mon Oct 10 2005 - 23:29:22 EST


Chuck Ebbert wrote:
After seeing Kirill's message about spinlocks I decided to do my own
testing with the userspace program below; the results were very strange.

When using the 'mov' instruction to do the unlock I was able to reproduce
hogging of the spinlock by a single CPU even on Pentium II under some
conditions, while using 'xchg' always allowed the other CPU to get the
lock:

This might not necessarily be a win in all situations. If two CPUs A and B are trying to get into a spinlock-protected critical section to do 5 operations, it may well be more efficient for them to do AAAAABBBBB as opposed to ABABABABAB, as the second situation may result in cache lines bouncing between the two CPUs each time, etc.

I don't know that making spinlocks "fairer" is really very worthwhile. If some spinlocks are so heavily contented that fairness becomes an issue, it would be better to find a way to reduce that contention.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@xxxxxxxxxxxxx
Home Page: http://www.roberthancock.com/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/