9fans archive / 1997 / 05 / 41 /    prev next

From: G. David Butler gdb@dbS...
Subject: calling sleep() while holding lock()
Date: Fri, 9 May 1997 02:22:24 -0500

Thanks for the input!

After having the stuff scared out of me with the mail from ncube, I
started to see just how bad it was.  I have not finished by any means,
but I now have a system not sleeping on spin locks!

A summary of the changes:

port/devbit.c
	move the smalloc outside the lock adding a free if necessary.

port/fault.c
	change the smalloc to a malloc with a panic if it fails.
	smalloc is the "sleeping" malloc.  malloc does not sleep,
	it returns 0 if there is no memory.

port/proc.c
	added a zero assignment to hasspin on newproc()
	added a panic if hasspin is set for the process sleeping.
	added a panic if hasspin is set for the process in sched.

port/taslock.c
	changed flagging hasspin to increment and decrement.

port/segment.c
	added a missing unlock (found by adding a "stack" to lock and
	unlock that is not included.)

pc/clock.c (All my machines are PCs)
	removed the zero of hasspin.

The boddles follow relative to /sys/src/9 with the original files
called file_name.cdrom (e.g. port/fault.c.cdrom)

To make sure you get the whole thing, the last line says ThEeNd.
Remove it before you send it to rc -X.

Let me know how it goes.

BTW: THIS is the future of Plan9.  What ever we make of it.

David Butler
gdb@dbS...

#!/bin/rc
#
# command: /bin/boddle pc/clock.c.cdrom pc/clock.c
# srcdir: pc
# version: 863162201
# date: Fri May 9 02:16:41 CDT 1997
#
myname=$0
doextract=no

fn usage{
	echo $myname: usage: $myname '[-X] [src-directory]' >[1=2]
	exit usage
}

fn sigint{
	rm -rf 863162201
	exit interrupt
}

while(~ $1 -*){
	switch($1){
	case -X
		doextract=yes
	case -*
		usage
	}
	shift
}

switch($#*){
case 0
	srcdir=pc
case 1
	srcdir=$1
case *
	usage
}

if(! ~ $doextract yes){
	echo This shell file contains a bundle of diffs representing changes
	echo to original source files in the Plan 9 distribution. It will run
	echo against the files in
	echo ' ' $srcdir
	echo '(unless overridden by the optional source directory argument)'
	echo and create a directory 863162201 containing the updated files.
	echo It will NOT automatically update the original files.
	echo
	echo Invoke with argument -X to perform the actual extraction.
	exit 0
}

rm -rf 863162201
mkdir 863162201

target=863162201/clock.c.cdrom
echo -n '863162201/clock.c.cdrom: '
if(! test -f $srcdir/clock.c.cdrom || ! test -r $srcdir/clock.c.cdrom){
	echo $srcdir/clock.c.cdrom unreadable
	exit unreadable
}
sum=`{sum < $srcdir/clock.c.cdrom}
if(! ~ a11baa684391  $sum(1)^$sum(2)){
	echo $srcdir/clock.c.cdrom is not the original distribution file
	exit original
}
cp $srcdir/clock.c.cdrom 863162201/clock.c.cdrom
ed 863162201/clock.c.cdrom >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM clock.c.cdrom'
66,70c
		if(p->hasspin == 0 && anyready()){
			sched();