glibc/db2/mutex
Ulrich Drepper b9b49b44fd Update.
1997-12-28 15:08  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/powerpc/__longjmp.S: Define _SETJMP_H before including
	<bits/setjmp.h>.
	* sysdeps/powerpc/setjmp.S: Likewise.
	Patches by Matt McLean <keys@keys.got.net>.

	* Make-dist (sysdep_dirs): Ignore bits dirs while searching.

	* Makefile: Undo last patch.
	(distribute): Add test-installation.pl.

	* configure.in: Correct handling of --enable-add-ons without parameter.
	Correct address of WWW pages.

	* libc.map: Add _nl_domain_bindings.

	* db2/mutex/tsl_parisc.s: New file.

	* iconvdata/Makefile (distribute): Add jis0201.c, jis0208.c, jis0212.c,
	and extra-module.mk.

	* localedata/Makefile (distribute): New.  Add all the files.

	* stdlib/Makefile (headers): Add inttypes.h.
	(routines): Add strtoimax, strtoumax, wcstoimax, and wcstoumax.
	* sysdeps/generic/inttypes.h: New file.
	* sysdeps/generic/strtoimax.c: New file.
	* sysdeps/generic/strtoumax.c: New file.
	* sysdeps/generic/wcstoimax.c: New file.
	* sysdeps/generic/wcstoumax.c: New file.
	* sysdeps/wordsize-32/Dist: Removed.
	* sysdeps/wordsize-32/Makefile: Removed.
	* sysdeps/wordsize-64/Dist: Removed.
	* sysdeps/wordsize-64/Makefile: Removed.
	* sysdeps/generic/bits/environments.h: New file.

	* include/limits.h: Define MB_LEN_MAX in any case to 6.  The gcc
	header is still not correct.

	* io/fcntl.h [__USE_FILE_OFFSET64]: We have to use the __*64 types.
	* posix/unistd.h: Likewise.
	* sysdeps/generic/sys/mman.h: Likewise.
	* sysdeps/unix/sysv/linux/sys/mman.h: Likewise.

	* manual/arith.texi: Change definition of mul macro.
	* manual/math.texi: Likewise.

	* misc/Makefile (routines): Add mmap64.
	* sysdeps/generic/mmap64.c: New file.
	* sysdeps/unix/sysv/linux/alpha/mmap64.c: New file.
	* sysdeps/unix/sysv/linux/sparc/sparc64/mmap64.c: New file.
	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Add __mmap64 and mmap64
	aliases to mmap.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.

	* sysdeps/generic/setrlimit64.c: Don't mark as stub.

	* nis/nss_nis/nis-hosts.c (internal_nis_gethostent_r): Pretty print.

	* nis(rpcsvc/nis_tags.h: Prevent warning by unknown pragma.

	* sysdeps/posix/mk-stdiolim.c: Generate correct file which defines
	FOPEN_MAX also when included by limits.h.
	* sysdeps/unix/sysv/linux/stdio_lim.h.in: Likewise.

	* sysdeps/unix/sysv/linux/Dist: Add oldsiglist.c, netax25/ax25.h,
	and netrom/netrom.h.
	* sysdeps/unix/sysv/linux/Makefile [$(subdir)=stdio-common]: Add
	oldsiglist to sysdep_routines, not aux.
	[$(subdir)=inet] (sysdep_headers): Add netax25/ax25.h, netrom/netrom.h.

	* sysdeps/unix/sysv/linux/bits/socket.h: Remove SOL_AX25, SOL_ATALK,
	and SOL_NETROM definition.

	* sysdeps/unix/sysv/linux/i386/Dist: Add s_pwrite64.S and s_pread64.S.

	* sysdeps/unix/sysv/linux/net/route.h: Pretty print.
	* sysdeps/unix/sysv/linux/netatalk/at.h: Pretty print.

1997-12-25  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/alpha/net/route.h: New file.

	* sysdeps/unix/sysv/linux/alpha/kernel_sigaction.h: Replace
	sa_handler with k_sa_handler.
	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Add __getrlimit as
	strong alias.
	Reported by a sun.

	* sysdeps/unix/sysv/linux/sigsuspend.c: Don't define
	__libc_have_rt_sigs here.
	* sysdeps/unix/sysv/linux/sigaction.c: Do it instead here.
	* sysdeps/unix/sysv/linux/i386/sigaction.c: Likewise.
	* sysdeps/unix/sysv/linux/sigpending.c: Correct comment.
	* sysdeps/unix/sysv/linux/sigprocmask.c: Likewise.

1997-12-11 07:51  Geoff Keating  <geoffk@ozemail.com.au>

	* sysdeps/powerpc/atomicity.h: New file.
	* sysdeps/mach/powerpc/machine-lock.h: New file.

	* Rules: Use -fpic to build anything that might end up in a users'
	shared library.

	* sysdeps/powerpc/s_fdim.c: New file.
	* sysdeps/powerpc/s_fdimf.c: New file.
	* sysdeps/powerpc/s_fmax.S: New file.
	* sysdeps/powerpc/s_fmaxf.S: New file.
	* sysdeps/powerpc/s_fmin.S: New file.
	* sysdeps/powerpc/s_fminf.S: New file.
	* sysdeps/powerpc/s_llrint.c: Now is for double.
	* sysdeps/powerpc/s_llrintf.c: New file.
	* sysdeps/powerpc/s_llround.c: Now is for double.
	* sysdeps/powerpc/s_llroundf.c: New file.
	* sysdeps/powerpc/s_lrint.c: Now is for double.
	* sysdeps/powerpc/s_lrintf.S: New file.
	* sysdeps/powerpc/s_lround.c: Now is for double.
	* sysdeps/powerpc/s_lroundf.c: New file.
	* sysdeps/powerpc/bits/mathinlines.h: Add inline versions of lrint,
	lrintf, fdim, fdimf.

	* sysdeps/unix/sysv/linux/powerpc/kernel_termios.h: Don't use bits/
	file directly, use its parent.

	* sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c: Re-instate '++'
	(for the third time).

1997-12-20 13:50  Richard Henderson  <rth@cygnus.com>

	* posix/sched.h: timespec is in <time.h>.

	* sysdeps/unix/sysv/linux/sys/kd.h: Don't redefine _LINUX_TYPES_H.
1997-12-28 16:01:53 +00:00
..
68020.gcc Update. 1997-08-27 20:26:10 +00:00
alpha.dec Update. 1997-08-27 20:26:10 +00:00
alpha.gcc Update. 1997-08-27 20:26:10 +00:00
mutex.c Update. 1997-12-01 17:16:22 +00:00
parisc.gcc Update. 1997-08-27 20:26:10 +00:00
parisc.hp Update. 1997-08-27 20:26:10 +00:00
README Update. 1997-12-01 17:16:22 +00:00
sparc.gcc Update. 1997-08-27 20:26:10 +00:00
tsl_parisc.s Update. 1997-12-28 16:01:53 +00:00
uts4.cc.s Update. 1997-08-27 20:26:10 +00:00
x86.gcc Update. 1997-09-05 01:43:20 +00:00

# @(#)README	10.2 (Sleepycat) 11/25/97

Resource locking routines: lock based on a db_mutex_t.  All this gunk
(including trying to make assembly code portable), is necessary because
System V semaphores require system calls for uncontested locks and we
don't want to make two system calls per resource lock.

First, this is how it works.  The db_mutex_t structure contains a resource
test-and-set lock (tsl), a file offset, a pid for debugging and statistics
information.

If HAVE_SPINLOCKS is defined (i.e. we know how to do test-and-sets for
this compiler/architecture combination), we try and lock the resource tsl
__db_tsl_spins times.  If we can't acquire the lock that way, we use a
system call to sleep for 10ms, 20ms, 40ms, etc.  (The time is bounded at
1 second, just in case.)  Using the timer backoff means that there are
two assumptions: that locks are held for brief periods (never over system
calls or I/O) and that locks are not hotly contested.

If HAVE_SPINLOCKS is not defined, i.e. we can't do test-and-sets, we use
a file descriptor to do byte locking on a file at a specified offset.  In
this case, ALL of the locking is done in the kernel.  Because file
descriptors are allocated per process, we have to provide the file
descriptor as part of the lock/unlock call.  We still have to do timer
backoff because we need to be able to block ourselves, i.e. the lock
manager causes processes to wait by having the process acquire a mutex
and then attempting to re-acquire the mutex.  There's no way to use kernel
locking to block yourself, i.e. if you hold a lock and attempt to
re-acquire it, the attempt will succeed.

Next, let's talk about why it doesn't work the way a reasonable person
would think it should work.

Ideally, we'd have the ability to try to lock the resource tsl, and if
that fails, increment a counter of waiting processes, then block in the
kernel until the tsl is released.  The process holding the resource tsl
would see the wait counter when it went to release the resource tsl, and
would wake any waiting processes up after releasing the lock.  This would
actually require both another tsl (call it the mutex tsl) and
synchronization between the call that blocks in the kernel and the actual
resource tsl.  The mutex tsl would be used to protect accesses to the
db_mutex_t itself.  Locking the mutex tsl would be done by a busy loop,
which is safe because processes would never block holding that tsl (all
they would do is try to obtain the resource tsl and set/check the wait
count).  The problem in this model is that the blocking call into the
kernel requires a blocking semaphore, i.e. one whose normal state is
locked.

The only portable forms of locking under UNIX are fcntl(2) on a file
descriptor/offset, and System V semaphores.  Neither of these locking
methods are sufficient to solve the problem.

The problem with fcntl locking is that only the process that obtained the
lock can release it.  Remember, we want the normal state of the kernel
semaphore to be locked.  So, if the creator of the db_mutex_t were to
initialize the lock to "locked", then a second process locks the resource
tsl, and then a third process needs to block, waiting for the resource
tsl, when the second process wants to wake up the third process, it can't
because it's not the holder of the lock!  For the second process to be
the holder of the lock, we would have to make a system call per
uncontested lock, which is what we were trying to get away from in the
first place.

There are some hybrid schemes, such as signaling the holder of the lock,
or using a different blocking offset depending on which process is
holding the lock, but it gets complicated fairly quickly.  I'm open to
suggestions, but I'm not holding my breath.

Regardless, we use this form of locking when HAVE_SPINLOCKS is not
defined, (i.e. we're locking in the kernel) because it doesn't have the
limitations found in System V semaphores, and because the normal state of
the kernel object in that case is unlocked, so the process releasing the
lock is also the holder of the lock.

The System V semaphore design has a number of other limitations that make
it inappropriate for this task.  Namely:

First, the semaphore key name space is separate from the file system name
space (although there exist methods for using file names to create
semaphore keys).  If we use a well-known key, there's no reason to believe
that any particular key will not already be in use, either by another
instance of the DB application or some other application, in which case
the DB application will fail.  If we create a key, then we have to use a
file system name to rendezvous and pass around the key.

Second, System V semaphores traditionally have compile-time, system-wide
limits on the number of semaphore keys that you can have.  Typically, that
number is far too low for any practical purpose.  Since the semaphores
permit more than a single slot per semaphore key, we could try and get
around that limit by using multiple slots, but that means that the file
that we're using for rendezvous is going to have to contain slot
information as well as semaphore key information, and we're going to be
reading/writing it on every db_mutex_t init or destroy operation.  Anyhow,
similar compile-time, system-wide limits on the numbers of slots per
semaphore key kick in, and you're right back where you started.

My fantasy is that once POSIX.1 standard mutexes are in wide-spread use,
we can switch to them.  My guess is that it won't happen, because the
POSIX semaphores are only required to work for threads within a process,
and not independent processes.

Note: there are races in the statistics code, but since it's just that,
I didn't bother fixing them.  (The fix requires a mutex tsl, so, when/if
this code is fixed to do rational locking (see above), then change the
statistics update code to acquire/release the mutex tsl.