Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Alpha UNIX Shared Memory - Need Ideas
@ 1996-04-20  4:00 Richard A. Surwilo
  1996-04-23  4:00 ` Peter Mayne
  1996-04-23  4:00 ` Dirk Grunwald
  0 siblings, 2 replies; 7+ messages in thread
From: Richard A. Surwilo @ 1996-04-20  4:00 UTC (permalink / raw)


We are contemplating porting an OLTP application that runs on Stratus
hardware under their proprietary VOS operating system to an Alpha running
UNIX. This application was originally designed for a port to UNIX and
VOS-specific code has been kept to an absolute minimum.  
 
However, the application does make heavy use of shared memory with multiple
processes requiring access to shared resources. The biggest potential snag
would seem to be coming up with an efficient method of shared memory
locking under UNIX. Stratus VOS allows processes to connect to shared
memory and designate a mode (read-only, read/write, or read/write
interlock) for this shared memory region. Connecting using read/write
interlock mode configures the memory locations in this region as
hardware-based locks. Processes can interrogate and set these memory
locations using atomic operations to effect mutual exclusion in a very
efficient manner. Obtaining a lock essentially consists of testing a memory
location waiting for a bit to be flipped. In this way developers can work
out very efficient locking schemes. 
 
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. 
 
TIA 
 
Rick Surwilo 
 
 
 




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Alpha UNIX Shared Memory - Need Ideas
@ 1996-04-21  4:00 Richard A. Surwilo
  1996-04-23  4:00 ` David Mosberger-Tang
  1996-04-24  4:00 ` Eric Werme
  0 siblings, 2 replies; 7+ messages in thread
From: Richard A. Surwilo @ 1996-04-21  4:00 UTC (permalink / raw)


We are contemplating porting an OLTP application that runs on Stratus
hardware under their proprietary VOS operating system to an Alpha running
UNIX. This application was originally designed for a port to UNIX and
VOS-specific code has been kept to an absolute minimum.  
 
However, the application does make heavy use of shared memory with multiple
processes requiring access to shared resources. The biggest potential snag
would seem to be coming up with an efficient method of shared memory
locking under UNIX. Stratus VOS allows processes to connect to shared
memory and designate a mode (read-only, read/write, or read/write
interlock) for this shared memory region. Connecting using read/write
interlock mode configures the memory locations in this region as
hardware-based locks. Processes can interrogate and set these memory
locations using atomic operations to effect mutual exclusion in a very
efficient manner. Obtaining a lock essentially consists of testing a memory
location waiting for a bit to be flipped. In this way developers can work
out very efficient locking schemes. 
 
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. 
 
TIA 
 
Rick Surwilo 
 
 
 




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Alpha UNIX Shared Memory - Need Ideas
  1996-04-20  4:00 Alpha UNIX Shared Memory - Need Ideas Richard A. Surwilo
@ 1996-04-23  4:00 ` Peter Mayne
  1996-04-24  4:00   ` Curt Smith
  1996-04-23  4:00 ` Dirk Grunwald
  1 sibling, 1 reply; 7+ messages in thread
From: Peter Mayne @ 1996-04-23  4:00 UTC (permalink / raw)


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).

See http://www.unix.digital.com/trucluster.html for more.

If you want something more basic, the ARM contains examples of how to use Load 
Locked/Store Conditional (LDx_L/STx_C) instructions and the Memory Barrier (MB) 
instruction to create your own locking mechanisms.
-- 
PJDM
Digital Equipment Corporation (Australia), Canberra, ACT
--------------------------------------------------------------------------------
These are my opinions, and have nothing to do with Digital.
I design Internet Service Providers. It's a job.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Alpha UNIX Shared Memory - Need Ideas
  1996-04-20  4:00 Alpha UNIX Shared Memory - Need Ideas Richard A. Surwilo
  1996-04-23  4:00 ` Peter Mayne
@ 1996-04-23  4:00 ` Dirk Grunwald
  1 sibling, 0 replies; 7+ messages in thread
From: Dirk Grunwald @ 1996-04-23  4:00 UTC (permalink / raw)


>>>>> "PM" == Peter Mayne <peter.mayne@cao.mts.dec.com> writes:
In article <317C6BFC.38CB@cao.mts.dec.com> Peter Mayne <peter.mayne@cao.mts.dec.com> writes:
>> 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.
--

I believe he's asking about *within* a given multiprocessor (e.g.,
within an 8400).

PM>  Distributed Lock Manager
--

Yes, the TruCluster software supports DLM, and the MemoryChannel
hardware has support for locks. I haven't timed the lock acquire
functions, but they're very fast for uncontested locks.

The MemoryChannel hardware also provides a way to remotely signal a
process in another system. We've built a messaging library on top of
the locks & signals and have also built a DSM system using
MemoryChannel. Nice hardware.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Alpha UNIX Shared Memory - Need Ideas
  1996-04-21  4:00 Richard A. Surwilo
@ 1996-04-23  4:00 ` David Mosberger-Tang
  1996-04-24  4:00 ` Eric Werme
  1 sibling, 0 replies; 7+ messages in thread
From: David Mosberger-Tang @ 1996-04-23  4:00 UTC (permalink / raw)


In article <4ledut$nql@news1.h1.usa.pipeline.com> rsurwilo@usa.pipeline.com(Richard A. Surwilo) writes:

  Richard> Our application is a very high volume message switching
  Richard> system and each process currently utilizes thousands of
  Richard> locks. UNIX semaphores would appear to be too
  Richard> inefficient. Using UNIX file/record locking has been
  Richard> suggested but I think it too would exact too much of a
  Richard> performance penalty.
 
  Richard> Is there a library of low-level, granular, atomic locking
  Richard> routines available on an Alpha running UNIX? SVR4
  Richard> compliance is immaterial. It just needs to be fast.
 
Wouldn't msem_init()/msem_lock()/msem_unlock() together with a shared
memory segment do what you want?  I haven't looked at exactly how
they're implemented, but msem_lock() does call a library internal
function called _msem_tas() which uses the load linked/store
conditional instructions of the Alpha to do an atomic test-and-set.
Of course, if you don't mind Alpha assembly, you could just use loaded
linked/store conditional directly.

	--david
-- 
David Mosberger-Tang; Dept. of CS; The University of Arizona; Tucson, AZ 85721
davidm@cs.arizona.edu                         http://www.AZStarNet.com/~davidm



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Alpha UNIX Shared Memory - Need Ideas
  1996-04-23  4:00 ` Peter Mayne
@ 1996-04-24  4:00   ` Curt Smith
  0 siblings, 0 replies; 7+ messages in thread
From: Curt Smith @ 1996-04-24  4:00 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Alpha UNIX Shared Memory - Need Ideas
  1996-04-21  4:00 Richard A. Surwilo
  1996-04-23  4:00 ` David Mosberger-Tang
@ 1996-04-24  4:00 ` Eric Werme
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Werme @ 1996-04-24  4:00 UTC (permalink / raw)


rsurwilo@usa.pipeline.com(Richard A. Surwilo) writes:

>However, the application does make heavy use of shared memory with multiple
>processes requiring access to shared resources. The biggest potential snag
>would seem to be coming up with an efficient method of shared memory
>locking under UNIX.

I believe the following acquire locks in a few instructions, as long as
the locks are available.

173% man pthread_mutex_lock 

pthread_mutex_lock(3)                                   pthread_mutex_lock(3)

NAME

  pthread_mutex_lock - Locks an unlocked mutex. If the mutex is already
  locked, the calling thread blocks until the mutex becomes available.

LIBRARY

  DECthreads POSIX 1003.1c Library (libpthread.so)

SYNOPSIS

  #include <pthread.h>

  int   pthread_mutex_lock(
                         pthread_mutex_t   *mutex);

STANDARDS

  Interfaces documented on this reference page conform to industry standards
  as follows:

  IEEE Std 1003.1c-1995, POSIX System Application Program Interface

PARAMETERS

  mutex     Mutex to be locked.

DESCRIPTION

  This routine locks a mutex with varying behavior as follows:

    +  If a recursive mutex was specified, the current owner of a mutex can
       relock the same mutex without blocking.  The lock count is incremented
       for each recursive lock within the thread.

    +  If an error-check mutex was specified and the current owner tries to
       lock the mutex a second time, the EDEADLK error is reported.  If the
       mutex is locked by another thread, the calling thread waits for the
       mutex to become available.

    +  If a normal mutex is specified, a deadlock can result if the current
       owner of a mutex calls this routine in an attempt to lock the mutex a
       second time. (The deadlock is not detected or reported.)

  See pthread_mutexattr_settype_np for information about normal, recursive,
  and  error-check mutexes.

  The thread that has locked a mutex becomes its current owner and  remains
  the owner until the same thread has  unlocked it. This routine returns with
  the mutex in the locked state and with the current thread as the mutex's
  current owner.

RETURN VALUES

  If an error condition occurs, this routine returns an integer value indi-
  cating the type of error.  Possible return values are as follows:

  0         Successful completion.

  [EINVAL]  The value specified for mutex is invalid, or
            The mutex was created with the protocol attribute set to
            PTHREAD_PRIO_PROTECT and the calling thread's priority set higher
            than the mutex's current priority ceiling.)

  [EDEADLK] A deadlock condition is detected.

ERRORS

  None

RELATED INFORMATION

  Functions: pthread_mutexattr_settype_np(3), pthread_mutex_destroy(3),
  pthread_mutex_init(3), pthread_mutex_lock(3), pthread_mutex_trylock(3),
  pthread_mutex_unlock(3)

  Manuals: Guide to DECthreads and Programmer's Guide

174% man tis_mutex_lock

tis_mutex_lock(3)                                           tis_mutex_lock(3)

NAME

  tis_mutex_lock - Locks an unlocked mutex.

LIBRARY

  Standard C Library (libc.so, libc.a)

SYNOPSIS

  #include <tis.h>

  int   tis_mutex_lock(
                         pthread_mutex_t   *mutex);

STANDARDS

  None

PARAMETERS

  mutex     Mutex to be locked.

DESCRIPTION

  The tis_mutex_lock() function locks a mutex. A deadlock can result if the
  current owner of a mutex calls this routine in an attempt to lock the mutex
  a second time. (The deadlock is not detected or reported.)

  The thread that has locked a mutex becomes its current owner and  remains
  the owner until the same thread has  unlocked it. This routine returns with
  the mutex in the locked state and with the current thread as the mutex's
  current owner.

RETURN VALUES

  If an error condition occurs, this routine returns an integer value indi-
  cating the type of error.  Possible return values are as follows:

  0         Successful completion.

  [EINVAL]  The value specified for mutex is invalid.

  [EDEADLK] A deadlock condition is detected.

ERRORS

  None

RELATED INFORMATION

  Functions: tis_mutex_destroy(3), tis_mutex_init(3), tis_mutex_lock(3),
  tis_mutex_trylock(3), tis_mutex_unlock(3)

  Manuals: Guide to DECthreads and Programmer's Guide
-- 
Eric (Ric) Werme         |  werme@zk3.dec.com
Digital Equipment Corp.  |  This space intentionally left blank.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1996-04-24  4:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-20  4:00 Alpha UNIX Shared Memory - Need Ideas Richard A. Surwilo
1996-04-23  4:00 ` Peter Mayne
1996-04-24  4:00   ` Curt Smith
1996-04-23  4:00 ` Dirk Grunwald
  -- 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

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