Re: [HACKERS] Compiling 6.4 on NetBSD-current/pc532

Bruce Momjian <maillist@candle.pha.pa.us>

From: Bruce Momjian <maillist@candle.pha.pa.us>
To: dg@informix.com (David Gould)
Cc: jonb@metronet.com, pgsql-hackers@postgreSQL.org
Date: 1998-09-18T17:09:03Z
Lists: pgsql-hackers
> > 
> > Applied.
> > 
> > > OK,
> > > 
> > > I have a current version of PostgreSQL running on my pc532 now.
> > > (It's a NS32K based machine.  Somewhat of an antique really...)
> > > 
> > > 
> > > *** /usr/local/pgsql/src/include/storage/s_lock.h	Fri Sep 11 19:00:55 1998
> > > --- s_lock.h	Sat Sep 12 00:27:51 1998
> > > ***************
> > > *** 213,219 ****
> > >   #endif	 /* NEED_I386_TAS_ASM */
> > >   
> > >   
> > > ! /* NS32K code is in s_lock.c */
> > >   
> > >   #endif	 /* defined(__GNUC__) */
> > >   
> > > --- 213,234 ----
> > >   #endif	 /* NEED_I386_TAS_ASM */
> > >   
> > >   
> > > ! 
> > > ! #if defined(NEED_NS32K_TAS_ASM)
> > > ! 
> > > ! #define S_LOCK(lock)				\
> > > ! {						\
> > > ! 	slock_t res = 1;				\
> > > ! 	while (res) {				\
> > > ! 	  __asm__("movqd 0, r0");			\
> > > ! 	  __asm__("sbitd r0, %0" : "=m"(*lock));	\
> > > ! 	  __asm__("sprb us, %0" : "=r" (res));	\
> > > ! 	  res = ((res >> 5) & 1);			\
> > > ! 	}						\
> > > ! }
> > > ! 
> > > ! #endif	 /* NEED_NS32K_TAS_ASM */
> > > ! 
> > >   
> > >   #endif	 /* defined(__GNUC__) */
> > >   
> > > *** /usr/local/pgsql/src/backend/storage/buffer/s_lock.c	Thu Sep 10 23:08:00 1998
> > > --- s_lock.c	Sat Sep 12 00:23:04 1998
> > > ***************
> > > *** 118,134 ****
> > >   #endif	 /* PPC */
> > >   
> > >   
> > > - #if defined(__ns32k__)
> > > - int
> > > - tas(volatile slock_t *lock)
> > > - {
> > > -   int res;
> > > -   __asm__("sbitb 0, %0" : "=m"(*lock));
> > > -   __asm__("sprb us, %0" : "=r"(res));
> > > -   res = (res >> 5) & 1;
> > > -   return res;
> > > - }
> > > - #endif
> > >   
> > >   #else							/* defined(__GNUC__) */
> > >   /***************************************************************************
> > > --- 118,123 ----
> > > 
> > > 
> > > BTW, does the spinlock code need a TAS function so it can spin for
> > > a while and then declare itself stuck, or does a second process/thread
> > > take care of that.  It would be simpler for the NS32K to just make
> > > the whole lock function be 2 lines of inline assembler, but that
> > > would contain an infinite loop if the lock was stuck...
> > > 
> > > Jon Buller  <jonb@metronet.com>
> 
> I wish I had noticed this before Bruce applied it.
> 
> The TAS function is needed so that stuck spinlocks can be recovered from.
> Also, it enables the pseudo random back off which helps performance when
> there are many backends.
> 
> In any case, this patch does not "follow the one true path" that I tried
> to outline in s_lock.c and s_lock.h. In fact it is exactly backwards.
> 
> Basically the preferred way is:
> 
>  - in s_lock.h do nothing, the defaults should take care of you.
> 
>   -in s_lock.c define a TAS function that sets the spinlock and returns the
>    previous state of the lock.
> 
> I see from your asm()s that you are using gcc. In this case, your TAS function
> should be called tas(), and should be defined inside the __GNUC__ section.

The patch had been on the list for a while, so I figured it was safe. 
I will back it out, and the user will have to study what is already
there and resubmit a new patch.

I belive the problem is that 6.3 users are trying to get their platforms
into the new locking code, and naturally using their old code to do it.


-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
http://www.op.net/~candle              |  (610) 353-9879(w)
  +  If your life is a hard drive,     |  (610) 853-3000(h)
  +  Christ can be your backup.        |