[unix-pc.sources] Hard Disk Speedup Using WD2010

psfales@cbnewsc.ATT.COM (Peter Fales) (10/04/89)

#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	Files
#	INSTALL
#	Install
#	Makefile
#	Name
#	Remove
#	Size
#	fast.c
sed 's/^X//' << 'SHAR_EOF' > README
XThis archive includes a (sort of) installable driver for speeding up
Xdisk accesses when using the WD2010 controller.  I understand that
Xwhen the next fixdisk comes out this will no longer be necessary, but
Xfor you impatient people (like me), here it is.  
X
XThis is version 1.1.  The previously posted version, 1.0, 
Xcontained some flaws.  Though it worked, the only reason it 
Xdid was by getting the disk driver so confused, that is was forced
Xto execute a RESTORE to recover.  Version 1.1 is faster (uses a SEEK
Xto current track, rather than a RESTORE), and does not leave an
Xerror message in /usr/adm/unix.log.
X
XA number of people have speculated that changing the step parameter
Xin the VHB from its default value of zero to the value 14 could 
Ximprove disk accesses times if a WD2010 is installed in the UNIX-PC.
XWith the stock WD1010 chip, a value of zero corresponds to a step rate
Xof 35 microseconds and is the fastest available.  However, the WD2010
Xhas a faster step rate of 3.2 microseconds corresponding to a step
Xrate parameter of 14.  In fact, several people have found some 
Xdefinite improvement, while others have not.  For the ones that have
Xnot, the reason may be the one outlined below:
X
XSome people have found that simply changing the value in the VHB and
Xrebooting causes the new step rate to take effect, but I have found
Xthat the new step rate does not seem to be loaded into the controller
Xuntil a RESTORE or SEEK occurs, something that normally only happens
Xafter a disk read error.  If you never have a disk error, the value
Xin the VHB will be effectively ignored.
X
XThis driver contains only an "init" routine.  At driver installation
Xtime, this routine executes a SEEK to the current track, using
Xthe step rate value in the VHB.   Then it sets the error return, so
Xthe driver is not installed.   There is no need for the driver or
Xanything else to be saved in memory once the RESTORE has been executed.
X
XWARNINGS (DON'T SAY I DIDN'T WARN YOU)
X
X1) I take no responsibility for anything that may happen as a result
X	of using this information.  It has caused a measurable 
X	improvement in disk access times on my system.
X
X2) Do not use this unless you have a WD2010 installed.  The program
X	does check to verify that a WD2010 is installed.
X
X3) It is probably the case that not all hard drives can handle the
X	3.2 microsecond step rate.  Of the two drives I have been
X	able to find good specs on, the Miniscribe 6085 goes
X	down to 2 microseconds, but the 20 Meg LaPine drive in
X	my DOS PC specs a minimum step rate of 5 microseconds.
X        A step rate parameter of 15 (16 microseconds) would be
X	an alternative in this case.  The program will not run
X	unless the step rate is 0, 14, or 15.  I know of no reason
X	why any other value would ever be desired.
X
X4) If you have problems, one way to recover would be to boot the
X	floppy file system,  mount /dev/fp002 /mnt, and delete the
X	file /mnt/etc/lddrv/fast.o
X
XPeter Fales			AT&T, Room 5B-420
X				2000 N. Naperville Rd.
XUUCP:	...att!ihlpb!psfales	Naperville, IL 60566
XDomain: psfales@ihlpb.att.com	work:	(312) 979-8031
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > Files
XSize
XInstall
XName
XRemove
XFiles
XINSTALL
Xfast.o
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > INSTALL
XDRIVER=fast
X
Xif [ ! -f ${DRIVER}.o ]; then
X	echo "you must make ${DRIVER}.o before running INSTALL" 1>&2
X	exit 1
Xfi
X
Xecho Installing driver to execute SEEK.  
X
X/etc/masterupd -d ${DRIVER}  2> /dev/null
X/etc/masterupd -a init ${DRIVER}
X
Xcp ${DRIVER}.o /etc/lddrv/
X
Xcd /etc/lddrv
X
X# remove the driver if it's already running
X
X./lddrv -q ${DRIVER} && ./lddrv -d ${DRIVER}
X
X# allocate and load the module
X
X
X./lddrv -a ${DRIVER}
X
X
Xgrep "^${DRIVER}\$" drivers > /dev/null || echo ${DRIVER} >> drivers
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > Install
X# Install script for disk speedup
X
XDRIVER=fast
X
X./INSTALL || exit 1
X
Xcd /etc/lddrv
X
X# put an entry in InstDrv for ${DRIVER}
Xcat >> InstDrv << EOF
XName=Disk speedup driver
XFile=${DRIVER}
XEOF
X
X
Xecho "The disk speedup driver is now installed"
Xexit 0
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > Makefile
XD=-O
XCFLAGS= $D
XDRIVER=fast
X
Xinstall : $(DRIVER).o
X	./INSTALL
X
Xall : $(DRIVER)+IN
X
Xinstallable : $(DRIVER)+IN
X
X$(DRIVER)+IN : $(DRIVER).o
X	cpio -oBc < Files > $(DRIVER)+IN
X
Xfloppy : $(DRIVER)+IN
X	echo "Insert a formatted floppy disk and press return"; read foo
X	dd if=$(DRIVER)+IN of=/dev/rfp021 bs=16384
X
Xclean: 
X	rm $(DRIVER).o $(DRIVER)+IN
X
Xclobber: clean
X
Xshar:
X	shar README Files INSTALL Install Makefile Name Remove Size fast.c >fast.shar
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > Name
XDisk speedup driver by Peter Fales
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > Remove
Xcd /etc/lddrv
Xecho '/^fast$/d
Xw' | ed - drivers
Xrm -f ifile.fast fast fast.o
X
X/etc/masterupd -d fast
X
X
Xecho "Disk speedup driver REMOVED"
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > Size
X42
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > fast.c
Xstatic char SCCS[] = "@(#) Fast Driver for WD2010 Version 1.1.";
X
X/*
X * This program is an "Installable" driver for the UNIX-PC (3b1) 
X * which causes a SEEK to the current track,  then keeps itself 
X * from being installed.  The purpose of this is to cause the 
X * step rate value given in the VHB to be loaded into the disk 
X * controller.  For stock systems, the boot up value of 0 is the
X * fastest available.  However, if your system has been upgraded 
X * with a WD2010 hard disk controller chip, and your disk can
X * handle, step rates of 14 (3.2 microseconds) and 15 (16 microseconds)
X * are faster.
X *
X *  This code is hereby released to the public domain.
X
X * Peter Fales				AT&T, Room 5B-420
X * 					2000 N. Naperville Rd.
X * UUCP:	...att!ihlpb!psfales	Naperville, IL 60566
X * Domain: psfales@ihlpb.att.com	work:	(312) 979-8031
X
X*/
X
X#define KERNEL
X
X#include <sys/errno.h>
X#include <sys/user.h>
X#include <sys/iohw.h>
X#include <sys/gdisk.h>
X
Xfastinit()
X{
X	int	count=0;
X	short	oldcylhigh;
X	short 	oldpri;
X	
X	/* Wait until anything that is happening is done */
X
X	while ( HD_BASE[H_STATUSREG] & W_BUSY );
X	ldelay(10);
X	
X	oldpri = spl6();
X
X	/* Make sure we have a WD2010 */
X
X	oldcylhigh = HD_BASE[H_CYLHIGH];
X	
X	HD_BASE[H_CYLHIGH] = 0xff;
X	if ((HD_BASE[H_CYLHIGH] & 0xff) != 7) {
X		eprintf("Failed to load fast driver with WD1010 chip %d.",
X			HD_BASE[H_CYLHIGH]);
X		HD_BASE[H_CYLHIGH] = oldcylhigh;
X	} else if ( ( gdsw[HD].dsk.step & W_RATEMSK ) < 14  && 
X			( gdsw[HD].dsk.step & W_RATEMSK ) > 0 ) {
X		eprintf("Failed to load fast driver with bad step rate %d",
X			gdsw[HD].dsk.step);
X		HD_BASE[H_CYLHIGH] = oldcylhigh;
X	} else {
X		HD_BASE[H_CYLHIGH] = oldcylhigh;
X
X		/* Drive must be selected for seek */
X		dhselect( HD );
X
X		/* Next line probably not necessary, but doesn't hurt */
X 		while ( HD_BASE[H_STATUSREG] & W_BUSY );
X
X		/* Seek to current cylinder */
X
X		HD_BASE[H_COMMANDREG] = W_SEEK+
X			(gdsw[HD].dsk.step & W_RATEMSK);
X
X		while ( HD_BASE[H_STATUSREG] & W_BUSY ) count++;
X		while ( !(HD_BASE[H_STATUSREG] & W_SEKCMP) ) count++;
X
X		eprintf("#Step rate successfully set to %d.  (Loop=%d)",
X			gdsw[HD].dsk.step,count);
X
X		/* Clear out the interrupt this caused */
X		dhreset();
X	}
X	u.u_error = ENOENT;
X
X	splx(oldpri);
X}
X
SHAR_EOF
exit
-- 
Peter Fales			AT&T, Room 5B-420
				2000 N. Naperville Rd.
UUCP:	...att!peter.fales	Naperville, IL 60566
Domain: peter.fales@att.com	work:	(312) 979-8031