On Tue, Oct 18, 2011 at 2:20 AM, Pavan Deolasee <pavan.deola...@gmail.com> wrote: > On Tue, Oct 18, 2011 at 10:04 AM, Robert Haas <robertmh...@gmail.com> wrote: >> Hmm, so you added the non-locked test in TAS()? Did you try adding it >> just to TAS_SPIN()? On Itanium, I found that it was slightly better >> to do it only in TAS_SPIN() - i.e. in the contended case. > > Would it be a good change for S_LOCK() to use TAS_SPIN() as well ?
Well, that would be sort of missing the point of why we invented TAS_SPIN() in the first place. What we found on Itanium is that using the unlocked test always was better than never doing it, but what was even slightly better was to use the unlocked first test *only when spinning*. In other words, on the very first go-around, we use the atomic instruction right away. Only if that fails do we switch to using the unlocked test first. Now it's possible that on some other architecture it's better to do the unlocked test first every time. But it seems somewhat unlikely, because in the hopefully-common case where the spinlock is uncontended, it's just a waste. If you're having enough spinlock contention that the first TAS() is failing frequently, you need to fix the underlying cause of the spinlock contention... -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers