OSF/1/Digital UNIX/Tru64 UNIX spinlock code

From: Arrigo Triulzi <arrigo(at)albourne(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: OSF/1/Digital UNIX/Tru64 UNIX spinlock code
Date: 2000-06-14 15:22:04
Message-ID: 14663.41756.457531.918074@caffeine.northsea.sevenseas.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I've managed to speak to someone knowledgeable at Digital in the UK
who pointed me in the direction of a very interesting include file for
Digital C/C++, namely /usr/include/alpha/builtins.h.

It contains a series of function prototypes which are then converted
into fast assembler sequences by the compiler. In particular a number
of these seem highly suited for the task of rewriting the alpha
spinlock code avoiding IPC semaphores.

Amongst the many functions I believe the most relevant are, for the
TAS() macro in s_lock.h:

/*
** Interlocked "test for bit set and then set". Returns non-zero
** if bit was already set.
*/
int __INTERLOCKED_TESTBITSS_QUAD(volatile void *__address, int __bit_position);
int __INTERLOCKED_TESTBITSS_QUAD_RETRY(volatile void *__address,
int __bit_position,
int __retry,
int *__status);

Note that this call does _not_ generate a memory barrier. For the
others, i.e. S_LOCK and S_UNLOCK perhaps the following might help:

/*
** Acquire/release binary spinlock based on low-order bit of a longword.
** NOTE: Memory barrier generated after lock, before unlock.
** _RETRY variant returns non-zero on success within retry attempts.
*/
void __LOCK_LONG(volatile void *__address);
int __LOCK_LONG_RETRY(volatile void *__address, int __retry);
void __UNLOCK_LONG(volatile void *__address);

There are also counting semaphores if need be (all in the same file).
If we change s_lock from msemaphore to long then the following patch
compiles and is being tested by Adriaan Joubert as we speak. It
probably crashes & burns but at least we can see if we get anywhere.
My personal opinion is that it might be the way to go, I haven't
looked carefully at S_LOCK etc. but will do so once Adriaan has
crashed the copy of Postgres currently being compiled.

===File ~/src/hacks/s_lock.diff=====================
--- s_lock.h.orig Wed Jun 14 15:33:28 2000
+++ s_lock.h Wed Jun 14 16:11:29 2000
@@ -252,10 +252,18 @@
* Note that slock_t on the Alpha AXP is msemaphore instead of char
* (see storage/ipc.h).
*/
-#define TAS(lock) (msem_lock((lock), MSEM_IF_NOWAIT) < 0)
-#define S_UNLOCK(lock) msem_unlock((lock), 0)
-#define S_INIT_LOCK(lock) msem_init((lock), MSEM_UNLOCKED)
-#define S_LOCK_FREE(lock) (!(lock)->msem_state)
+#if 0
+/* Original hack */
+# define TAS(lock) (msem_lock((lock), MSEM_IF_NOWAIT) < 0)
+# define S_UNLOCK(lock) msem_unlock((lock), 0)
+# define S_INIT_LOCK(lock) msem_init((lock), MSEM_UNLOCKED)
+# define S_LOCK_FREE(lock) (!(lock)->msem_state)
+#else
+/* Arrigo's hack */
+# include <alpha/builtins.h>
+# define TAS(lock) (__INTERLOCKED_TESTBITSS_QUAD(lock,0))
+#endif
+

#else /* i.e. not __osf__ */

============================================================

Ciao,

Arrigo

P.S. Yes, I don't really know what I am doing but trying my best to
learn ;-)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-06-14 15:23:42 Re: 7.0.2 cuts off attribute name
Previous Message Bruce Momjian 2000-06-14 14:42:15 Re: Big 7.1 open items