#!/bin/sh # kernbench by Con Kolivas # based on a benchmark by Martin J. Bligh trap 'echo "ABORTING";exit' 1 2 15 VERSION=0.20 num_runs=5 single_runs=0 half_runs=1 opti_runs=1 max_runs=1 while getopts vsHOMn:o:h i do case $i in h) echo "kernbench v$VERSION by Con Kolivas " echo "Usage:" echo "kernbench [-n runs] [-o jobs] [-s] [-H] [-O] [-M] [-h] [-v]" echo "n : number of times to perform benchmark (default 5)" echo "o : number of jobs for optimum run (default 4 * cpu)" echo "s : perform single threaded runs (default don't)" echo "H : don't perform half load runs (default do)" echo "O : don't perform optimal load runs (default do)" echo "M : don't perform maximal load runs (default do)" echo "h : print this help" echo "v : print version number" exit ;; v) echo "kernbench Version $VERSION by Con Kolivas " ; exit ;; n) num_runs=$OPTARG ;; o) optijobs=$OPTARG ;; s) single_runs=1 ;; H) half_runs=0 ;; O) opti_runs=0 ;; M) max_runs=0 ;; esac done if [[ ! -f include/linux/kernel.h ]] ; then echo "No kernel source found; exiting" exit fi time=`which time` if [[ ! -a $time ]] ; then echo "time not found in path, please install it; exiting" exit fi if (($num_runs < 1)) ; then echo "Nothing to do; exiting" exit fi if (($num_runs > 10)) ; then echo "Trimming number of runs to 10" num_runs=10 fi if [[ ! -d /proc ]] ; then echo "Can't find proc filesystem; exiting" exit fi awk=`which awk` if [[ ! -a $awk ]] ; then echo "awk not found in path, please install it; exiting" exit fi mem=`awk '/MemTotal/ {print $2}' /proc/meminfo` if (($mem < 2000000)) ; then echo Less than 2Gb ram! This benchmark will not measure cpu throughput and may cause a swapstorm! fi (( single_runs *= $num_runs )) (( half_runs *= $num_runs )) (( opti_runs *= $num_runs )) (( max_runs *= $num_runs )) cpus=`grep -c processor /proc/cpuinfo` echo $cpus cpus found echo Cleaning source tree... make clean > /dev/null 2>&1 make mrproper > /dev/null 2>&1 echo Making defconfig... make defconfig > /dev/null 2>&1 echo Making dep if needed... make dep > /dev/null 2>&1 echo Caching kernel source in ram... for i in `find -type f` do cat $i > /dev/null done halfjobs=$(( $cpus / 2 )) optijobs=${optijobs:=$(( $cpus * 4 ))} if echo $halfjobs 1 | awk '{exit $1>=$2}' ; then echo "Half load is no greater than single; disabling" half_runs=0 fi if [[ ! $single_runs -eq 0 ]] ; then echo Warmup single threaded run... make > /dev/null 2>&1 fi temp_runs=$single_runs single_elapsed="a" for (( i=1 ; i <= temp_runs ; i++ )) do echo Single threaded run number $i... make clean > /dev/null 2>&1 sleep 5 $time -f "%e %U %S %P %c %w" -o timelog make > /dev/null 2>&1 read elapsed_time user_time sys_time percent ctx sleeps /dev/null 2>&1 fi temp_runs=$half_runs half_elapsed="a" for (( i=1 ; i <= temp_runs ; i++ )) do echo Half load -j$halfjobs run number $i... make clean > /dev/null 2>&1 sleep 5 $time -f "%e %U %S %P %c %w" -o timelog make -j $halfjobs> /dev/null 2>&1 read elapsed_time user_time sys_time percent ctx sleeps /dev/null 2>&1 fi temp_runs=$opti_runs opti_elapsed="a" for (( i=1 ; i <= temp_runs ; i++ )) do echo Optimum load -j$optijobs run number $i... make clean > /dev/null 2>&1 sleep 5 $time -f "%e %U %S %P %c %w" -o timelog make -j $optijobs > /dev/null 2>&1 read elapsed_time user_time sys_time percent ctx sleeps /dev/null 2>&1 fi temp_runs=$max_runs max_elapsed="a" for (( i=1 ; i <= temp_runs ; i++ )) do echo Maximum load -j run number $i... make clean > /dev/null 2>&1 sleep 5 $time -f "%e %U %S %P %c %w" -o timelog make -j > /dev/null 2>&1 read elapsed_time user_time sys_time percent ctx sleeps