#!/bin/bash

P='stress-highalloc'
. $SHELLPACK_INCLUDE/common.sh
KERNEL_VERSION=3.0
WEB_LOCATION=https://www.kernel.org/pub/linux/kernel/v3.0/linux-${KERNEL_VERSION}.tar.gz
MIRROR_LOCATION=$WEBROOT/kernbench/linux-${KERNEL_VERSION}.tar.gz

NUM_KERNELS=0
while [ $# -gt 0 ]; do
	case $1 in
	-k)
		NUM_KERNELS=$2
		shift 2
		;;
	*)
		echo Unrecognised, passing remainder through
		break
		;;
	esac
done

if [ "`which stap`" = "" ]; then
	echo systemtap is required
	exit -1
fi

# Autosize num kernels if necessary
if [ $NUM_KERNELS -eq 0 ]; then
	TOTALMEM=`free -m | grep Mem: | awk '{print $2}'`
	NUM_KERNELS=$(($TOTALMEM/400))
fi

# Setup a build directory
mkdir -p $SHELLPACK_TEMP/build
cd $SHELLPACK_TEMP || die Failed to cd to temp directory
sources_fetch $WEB_LOCATION $MIRROR_LOCATION $SHELLPACK_TEMP/linux-${KERNEL_VERSION}.tar.gz

# Begin the test
echo "Kernels to build:      $NUM_KERNELS"
echo "Kernel source:         $SHELLPACK_TEMP/linux-${KERNEL_VERSION}.tar.gz"
echo "Build directory:       $SHELLPACK_TEMP/build"
echo
$SHELLPACK_TOPLEVEL/vmr/bin/bench-stresshighalloc.sh $@ \
	-k $NUM_KERNELS \
	--vmr $SHELLPACK_TOPLEVEL/vmr \
	-t $SHELLPACK_TEMP/linux-${KERNEL_VERSION}.tar.gz \
	-b $SHELLPACK_TEMP/build \
	-r $LOGDIR_RESULTS/ | tee $LOGDIR_RESULTS/highallocout

rm -rf $SHELLPACK_TEMP
exit $SHELLPACK_SUCCESS
#### Description Stress test the allocation of huge pages
#### Details stress-highalloc-bench 7
#### Description Stress test the allocation of huge pages
#### Details stress-highalloc-bench 10
