Re: spinlocks on powerpc - Mailing list pgsql-hackers

From Jeremy Harris
Subject Re: spinlocks on powerpc
Date
Msg-id 4F035F8D.6050709@wizmail.org
Whole thread Raw
In response to Re: spinlocks on powerpc  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: spinlocks on powerpc  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On 2012-01-03 04:44, Robert Haas wrote:
> On read-only workloads, you get spinlock contention, because everyone
> who wants a snapshot has to take the LWLock mutex to increment the
> shared lock count and again (just a moment later) to decrement it.

Does the LWLock protect anything but the shared lock count?  If not
then the usually quickest manipulation is along the lines of:

loop: lwarx r5,0,r3  #load and reserve        add     r0,r4,r5 #increment word        stwcx. r0,0,r3  #store new value
ifstill reserved        bne-    loop      #loop if lost reservation
 

(per IBM's software ref manual,
https://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2
)

The same sort of thing generally holds on other instruction-sets also.

Also, heavy-contention locks should be placed in cache lines away from other
data (to avoid thrashing the data cache lines when processors are fighting
over the lock cache lines).
-- 
Jeremy


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: patch: ALTER TABLE IF EXISTS
Next
From: Alexander Korotkov
Date:
Subject: Re: Collect frequency statistics for arrays