#!/bin/sh

# Configure parameters for lmbench.
# $Id: config-run,v 1.8 1995/11/03 23:04:19 lm Exp $

cat<<EOF;

You need to configure some parameters to lmbench.  Once you have configured
these parameters, you may do multiple runs by saying

	make rerun

in the src subdirectory.

NOTICE: please do not have any other activity on the system if you can
help it.  The context switch benchmark is especially sensitive.

EOF

# Figure out echo.
if [ `echo -n "foo" | wc -l` -eq 0 ]
then	ECHON="-n"; ECHOC=
else	ECHON= ; ECHOC='\c'
fi

AGAIN=Y
while [ $AGAIN = Y ]
do
	cat<<EOF;

In order to get disk latency results, we need to be able to read a disk
drive.  The simplest way to do this is to run the benchmark as root.
If you are paranoid about running code as root, good for you, you should
be.  The paranoid solution is to grab another window, pick the disk
drive, make it world readable ( chmod a+r /dev/rsd0a ), and then specify
that drive below.  Remember to change the permissions back after running
the benchmark if you took the paranoid route.

If you want to get disk latency results, please specify the disk device
to use, such as /dev/rsd0a.

EOF
	echo $ECHON "DISK [default none] $ECHOC"
	read DISK
	if [ -c "$DISK" -o X$DISK = X ]
	then	AGAIN=N
	else	echo $DISK is not a raw disk device
	fi
done

cat<<EOF;

Several benchmarks operate on a range of memory.  This memory should be
sized such that it is at least 4 times as big as the external cache[s] on
your system.  

The bigger the range, the more accurate the results, but larger sizes
take somewhat longer to run the benchmark.

EOF
echo $ECHON "MB [default 16] $ECHOC"
read MB
if [ X$MB = X ]
then	MB=16
fi

# Certain machines tend to barf when you try and bcopy 8MB.
# Figure out how much we can use.
echo "Calculating available memory size; please wait for a moment..."
OS=`../scripts/os`
AVAILMEM=`../bin/$OS/memsize $MB`
if [ $AVAILMEM -lt 8 ]
then    echo $0 aborted: Not enough memory, only ${AVAILMEM}MB available. 
	exit 1
fi
if [ $AVAILMEM -lt 16 ]
then	echo Warning: you have only ${AVAILMEM}MB available memory. 
	echo Some benchmark results will be less meaningful. 
fi
MB=`expr $AVAILMEM / 2`

AGAIN=Y
while [ $AGAIN = Y ]
do
	cat<<EOF;

We need a place to store a $MB Mbyte file as well as create and delete a
large number of small files.  We default to /usr/tmp.  If /usr/tmp is a
memory resident file system (i.e., tmpfs), pick a different place.
Please specify a directory that has enough space and is a local file
system.

EOF
	echo $ECHON "FSDIR [default /usr/tmp] $ECHOC"
	read FSDIR
	if [ X$FSDIR = X ]
	then	FSDIR=/usr/tmp
	else	mkdir -p $FSDIR 2>/dev/null
	fi
	if [ -d $FSDIR -a -w $FSDIR ]
	then	AGAIN=N
		FILE=$FSDIR/XXX
	else	echo $FSDIR is not a directory or is not writable
	fi
done

cat<<EOF;

If you are running on an idle network and there are other, identically
configured systems, on the same wire (no gateway between you and them),
and you have rsh access to them, then you should run the network part
of the benchmarks to them.  Please specify any such systems as a space
separated list such as: ether-host fddi-host hippi-host.

EOF
echo $ECHON "REMOTE [default none] $ECHOC"
read REMOTE

if [ "X$REMOTE" != X ]
then	cat<<EOF;

Thanks for doing remote testing, that is a hard thing to get.  Could you
do me one more favor and tell me the networking you think will be used
to get to each of the remote hosts.  By networking I mean one of the
following (or whatever you use if you use something else):

ethernet		aka 10baseT, thinnet, thicknet, etc
ethernet-100		aka 100baseT, 100VG
fddi			aka cddi
hippi
others?

Please type it just like the above if you can, it makes parsing easier.

EOF

	RSH=rsh
	case `uname -s` in
		*HP-UX*)	RSH=remsh;;
	esac
	for r in $REMOTE
	do	echo $ECHON "Network type for $r: $ECHOC"
		read n
		X=`$RSH $r echo foo`
		if [ X$X = Xfoo ]
		then	echo Remote access to $r worked, thanks.
		else	echo Remote access to $r did not work, please check and retry,
			exit 1
		fi
		NETWORKS="${NETWORKS}$r:$n "
	done
fi

cat<<EOF;

There is a database of benchmark results that is shipped with new
releases of lmbench.  Your results can be included in the database
if you wish.  The more results the better, especially if they include
remote networking.

EOF

echo $ECHON "Mail results [default yes] $ECHOC"
read MAIL
case $MAIL in 
    [Nn]*)	MAIL=no
		echo OK, no results mailed.
	;;
    *)		MAIL=yes
		echo Thanks for adding your results to the database.
	;;
esac

echo ""
echo "Confguration done, thanks."
echo ""

if [ X$1 != X ]
then	OUTPUT=$1
else	OUTPUT=/dev/tty
fi
cat<<EOF > $OUTPUT
DISK=$DISK
FILE=$FILE
FSDIR=$FSDIR
MB=$MB
REMOTE="$REMOTE"
NETWORKS="$NETWORKS"
MAIL=$MAIL
EOF

exit 0
