Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: curts@compgen.com (Curt Smith)
Subject: Re: Alpha UNIX Shared Memory - Need Ideas
Date: 1996/04/24	[thread overview]
Message-ID: <4llbgm$jlf@nntp.atlanta.com> (raw)
In-Reply-To: 317C6BFC.38CB@cao.mts.dec.com

Peter Mayne (peter.mayne@cao.mts.dec.com) wrote:
: Richard A. Surwilo wrote:
: > Our application is a very high volume message switching system and each
: > process currently utilizes thousands of locks. UNIX semaphores would appear
: > to be too inefficient. Using UNIX file/record locking has been suggested
: > but I think it too would exact too much of a performance penalty.
: > 
: > Is there a library of low-level, granular, atomic locking routines
: > available on an Alpha running UNIX? SVR4 compliance is immaterial. It just
: > needs to be fast.
: 
: From the TruCluster Software for Digital UNIX SPD:
: {
:  Distributed Lock Manager
: 
:  The Distributed Lock Manager (DLM) synchronizes access to the resources
:  that are shared among cooperating processes throughout the cluster.
:  DLM provides a software library that applications use to implement a
:  resource sharing policy. DLM provides services to notify a process 
:  owning a resource that it is blocking another process requesting the
:  resource. An application can also use DLM routines to coordinate the
:  application's activities efficiently with the state of the cluster.
: }
: 
: I imagine that the DLM wouldn't be terribly slow, plus you get the other 
: advantages of a cluster (memory channel, distributed raw disk, etc).
: 

Anicdotal info that I've heard from a DEC insider, *suggests* that DLM is
not that fast or CPU inexpensive on DEC Unix.  I (we'd) like to see benchmarks
for N box DUX Cluster DLM performance and CPU utilization data from DEC??

If you are working on a single box, SMP, design, then spin locks is your best
technology.  My spin lock library gets 65k lock/unlocks/sec on a 4/266.  This
is without task context switching, since spin locks are by design an application
layer activity, not an OS service, as semaphors and memcntl() is.

See the following emails that I have saved over the years from other
contributors, to get the needed info to write your own spin lock function:

*****************************


From nntp.atlanta.com!metro.atlanta.com!news.sprintlink.net!howland.reston.ans.net!swrinde!newsfeed.internetmci.com!info.ucla.edu!library.ucla.edu!agate!aoki Sat Nov 18 09:39:56 1995
Path: nntp.atlanta.com!metro.atlanta.com!news.sprintlink.net!howland.reston.ans.net!swrinde!newsfeed.internetmci.com!info.ucla.edu!library.ucla.edu!agate!aoki
From: aoki@faerie.CS.Berkeley.EDU (Paul M. Aoki)
Newsgroups: comp.unix.osf.osf1
Subject: Re: TEST and SET/Spin lock for Alpha/Unix?
Date: 18 Nov 1995 05:11:14 GMT
Organization: University of California at Berkeley
Lines: 24
Message-ID: <48jpti$pkl@agate.berkeley.edu>
References: <48imk7$j65@nntp.atlanta.com>
Reply-To: aoki@CS.Berkeley.EDU (Paul M. Aoki)
NNTP-Posting-Host: faerie.cs.berkeley.edu

curts@compgen.com (Curt Smith) writes:
| Anybody have the small bit of assembly it takes for a test and 
| set / spin lock in user space??

you might try using msem_lock(3).  it tries to use the LDL_L/STL_C 
load-linked/store-conditional instructions to obtain a semaphore 
from user mode before calling __msleep to sleep on the semaphore.
(if you use the MSEM_IF_NOWAIT flag, it returns immediately with 
an error instead of sleeping.)  furthermore, it gets the 
multiprocessor memory consistency protocol (i.e., use of the MB 
memory barrier instruction -- see the alpha architecture manual) 
right.

caveat 1: i have no idea how clustering affects all of this.  i've
only ever used standalone DS3000s and Sables.

caveat 2: before osf/1 3.0 (the first multiprocessor version), the 
msem_* routines *didn't* use the MB instruction.  hence, statically 
linking against pre-3.0 libraries is iffy if you are going to run 
the binaries on a multiprocessor.  however, things are fine >= 3.0.
-- 
  Paul M. Aoki          |  University of California at Berkeley
  aoki@CS.Berkeley.EDU  |  Dept. of EECS, Computer Science Division (#1776) 
                        |  Berkeley, CA 94720-1776

From mcintosh@zk3.dec.com Tue Sep 27 04:23:24 1994
Date: Mon, 26 Sep 94 16:14:31 -0400
From: "Steve McIntosh, DEC OSF/1 Product Marketing" <mcintosh@zk3.dec.com>
To: cgi@crl.com
Cc: mcintosh@zk3.dec.com
Subject: spin locks from Paula Long

Hi,

  There are multiple ways to construct a spin lock using the existing 
  primitives in DEC OSF/1.  One can use the BSB V4.4 semaphores or the
  Realtime (POSIX) semaphores.  One could also use the msem_tas()
  function (test and set, and shared memory to construct your own).

  Remember that spin locks are only really "goodness" on an MP configuration.
  You probably want to use blocking locks on uni processor configuration.

  I personally would develop a generic set of locks which would work in
  either environment.  It's probably easier to do this with either the
  BSD V4.4 semaphores, msem_*() or the Realtime Semaphores, sem_*().
  Note, the code fragments below are just that frags, you probably want
  to customize things for your environment. I also believe spin_locks
  with no exit hatch are probably dangerous, because you could wedge
  the system.

Paula

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

Options:
  The _msem_tas() function is a simple assembler routine which performs
  an atomic test-and-set.  It expects as input a pointer to an int.
  
   extern int _msem_tas(int *lock);

  It returns a 0 if update is successful , 1 if it's not. 

  A simple spin lock using this technique might look as follows (assumes no
  simple lock for none MP case):


Init Semaphores: 

  < create a shared memory region, using either mmap() or system V
  < shared memory. and make sure your semaphores lives here
     
  processors_in_box = getsysinfo((GSI_CPUS_IN_BOX,maxcpu,sizeof(maxcpu),0,0);
  spin_count = (processors_in_box - 1) * spins; /*unclear what this should be */


Lock Routine:
/*
 * attempt to get the lock, spin_count times.   If you don't win the lock, 
 * yield to another process  and try again later.  In a uni-processor case 
 * you might always yield in the lock lost case.
 */

void
spin_lock(int *lock) {
     int spins;
 
     spins = spin_count; 
     while (_msem_tas(lock) !=0 ) {   
	if (!(spins--)) {
	   <block/yield> 
	   spins = spin_count;
        }
     }
}

/* 
 * release the lock.
 */

void
spin_unlock(int *lock) {
      mb();		/* order exit from critical section */
      *lock = 0;	/* release lock	                    */
      mb();		/* order release of lock            */
}

BSD V4.4 Semaphore:

This case is similar to the msem_tas() case except, that you actually
have a semaphore you can block on and be woken-up on.  The Realtime
Semaphore model would look about the same except that you'd use the
sem_trywait function to spin with.

Init Semaphores: 

  Create Semaphores (see msem_init man page)
 
  processors_in_box = getsysinfo((GSI_CPUS_IN_BOX,maxcpu,sizeof(maxcpu),0,0);
  spin_count = (processors_in_box - 1) * spins; /*unclear what this should be */


/* 
 * lock (doesn't handel errors correctly (you could -1 for more then
 * just you didn't win the lock).
 */

void
spin_lock(msemaphore *sem) {

	int spins=0;
        spins = spin_count;
	while (msem_lock(sem,MSEM_IF_NOWAIT) == -1) {
	   if (!(spins--))
		msem_lock(sem,0);
        }
}

For the unlock case, simply call the msem_unlock() function directly.

From mario@zk3.dec.comWed Feb 21 09:29:49 1996
Date: Thu, 15 Feb 96 16:38:18 -0500
From: mario@zk3.dec.com
To: Curt Smith <curts@compgen.com>
Subject: Re: AXP advice on code for byte parsing?? 

Curt:
	The memory barrier instruction guarantees that all subsequent
	loads or stores will not access memory until after all previous
	loads and stores have accessed memory, as observed by other 
	processors.  This is not applicable on Intel.

Joe

> On Thu, 15 Feb 1996, Joe Mario wrote:
> 
> > RE: AXP advice on code for byte parsing??
> 
> Thanks for the feed back!  
> 
> Another DEC Unix question I have is on the memory barrier operator: mb().
> 
> What is a memory barrier operation / operator?
> 
> Code I got from a DEC type for spin lock and unlock had for the unlock
> function:
> 
> spin_unlock ( int *lock )
> {
> 	mb();
> 	*lock = 0;
> 	mb();
> }
> 
> Any idea on what mb() is doing here?  Intel unlock does not need this?
> 
> Thanks.
> 
> Curt Smith
> curts@compgen.com
> 
> 



From mario@zk3.dec.comWed Feb 21 09:30:45 1996
Date: Tue, 20 Feb 96 10:40:24 -0500
From: mario@zk3.dec.com
To: Curt Smith <curts@compgen.com>
Subject: Re: mb() 

Curt:
	If you're running Digital UNIX V3.* your choices are:
	
	1) With cc, you can implement mb() only via an asm.
	   See the Digital UNIX Programmer's Guide and/or
	   /usr/include/*asm*.h

	2) With cc -migrate, you can implement mb() using a builtin.
	   If you provide a prototype, then the compiler will recognize
	   the call as a builtin.  The prototype, (only for -migrate)
	   is 
		/*
		**  Memory Barrier
		*/
		void    __MB(void);

	Beginning with Digital UNIX V4.*, the -migrate compiler becomes
	the default compiler and it can handle asms(), so both approaches
	will work.  I don't know anything about the _mb symbol in libc.

Joe

> Hi Joe,
> 
> I got my spinlock functions finished for Intel, now I find that I don't know
> where the mb() function prototype is on DEC Unix?
> 
> on v3.2 there's /usr/lib/mb.o, no header though?
> On v3.0 there's NO /usr/lib/mb.o.
> 
> No man pages on either DUX version.
> 
> Any helps on linking to mb()?
> 
> Thanks.
> 
> Curt Smith
> curts@compgen.com
> 
> 



Curt Smith
curts@compgen.com




  reply	other threads:[~1996-04-24  4:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-20  4:00 Alpha UNIX Shared Memory - Need Ideas Richard A. Surwilo
1996-04-23  4:00 ` Dirk Grunwald
1996-04-23  4:00 ` Peter Mayne
1996-04-24  4:00   ` Curt Smith [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-04-21  4:00 Richard A. Surwilo
1996-04-23  4:00 ` David Mosberger-Tang
1996-04-24  4:00 ` Eric Werme
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox