Gzip ramdisk - booting is faster
[can-benchmark.git] / tests / _lib.sh
index 4dbbc40..930f688 100644 (file)
@@ -1,29 +1,36 @@
 
 while [ $# -gt 0 ]; do
     case "$1" in
+       -P) OPT_PLOT_DISABLE=1; shift;;
        -p) OPT_PLOT_ONLY=1; shift;;
-       --pdf-only) OPT_PDF_ONLY=1; shift;;
+       -X|--no-x11-plot) OPT_NO_X11=1; shift;;
     esac
 done
 
-set -x
+#set -x
 set -e
 
 PATH=$PWD/../_compiled/bin/:$PATH
 
-RTPRIO=60
+RTPRIO=${RTPRIO:-60}
+COUNT=${COUNT:-10000}
+export CANPING_MS=1            # Generate plots in milliseconds
 
 boost_irq_prio() {
     local PRIO=${1:-50}
     CAN_IRQ=`sed -ne '/can/ s/:.*//p' /proc/interrupts`
     if [ -n "$CAN_IRQ" ]; then
        IRQ_PID=`pidof IRQ-${CAN_IRQ/ /}` || true
-       [ -z "$IRQ_PID" ] || schedtool -F -p $PRIO $IRQ_PID 
+       if [ -n "$IRQ_PID" ]; then
+           schedtool -F -p $PRIO $IRQ_PID
+           return 0
+       fi
     fi
+    return 1
 }
 
 rmmod_can() {
-    modprobe -r lincan kvaser_pci vcan
+    modprobe -r lincan kvaser_pci vcan || true
 }
 
 prepare_lincan_hw() {
@@ -39,20 +46,29 @@ prepare_lincan_virtual() {
     rmmod_can
     modprobe -C /dev/null lincan hw=virtual io=0 baudrate=0
     CAN0=/dev/can0
+    CAN1=/dev/can0
     DRIVER=lincan-virtual
     sleep 0.1
 }
 
+socketcan_set_bitrate() {
+    local canX=$1
+    if [ -f /sys/class/net/$canX/can_bittiming/bitrate ]; then
+       echo 1000000 > /sys/class/net/$canX/can_bittiming/bitrate
+    else
+       ip link set $canX type can bitrate 1000000
+    fi
+}
 prepare_socketcan_hw() {
     rmmod_can
     modprobe kvaser_pci
-    echo 1000000 > /sys/class/net/can0/can_bittiming/bitrate
+    socketcan_set_bitrate can0
     ip link set up dev can0
-    echo 1000000 > /sys/class/net/can1/can_bittiming/bitrate
-    ip link set up dev can1
-    echo 1000000 > /sys/class/net/can2/can_bittiming/bitrate
+    socketcan_set_bitrate can1
+    ip link set up dev can1 
+    socketcan_set_bitrate can2
     ip link set up dev can2
-    echo 1000000 > /sys/class/net/can3/can_bittiming/bitrate
+    socketcan_set_bitrate can3
     ip link set up dev can3
     CAN0=socketcan:can0
     CAN1=socketcan:can1
@@ -62,39 +78,112 @@ prepare_socketcan_hw() {
 prepare_socketcan_virtual() {
     rmmod_can
     modprobe vcan
-    ip link add dev vcan0 type vcan
+    ip link add dev vcan0 type vcan || true
     ip link set up dev vcan0
     CAN0=socketcan:vcan0
+    CAN1=socketcan:vcan0
     DRIVER=socketcan-virtual
 }
 
 run_tests() {
     tests=${TESTS:-socketcan_hw lincan_hw}
-    for i in $tests; do
-       cpufreq-set -f 2400MHz
-       boost_irq_prio 50
-       prepare_$i
+    for tst in $tests; do
+       echo 300 > /proc/sys/net/core/netdev_budget
+       boost_irq_prio 50 || true
+       prepare_$tst
+       echo "----------------------"
        t
+       echo 300 > /proc/sys/net/core/netdev_budget
     done
 }
 
+kvers() {
+    local cmdline=$(cat /proc/cmdline|sed -e 's/BOOT_IMAGE=[^ ]*//' \
+                                         -e 's/root=[^ ]*//' \
+                                         -e 's/ro//' \
+                                         -e 's/quiet//' \
+                                         -e 's/rootfstype=[^ ]*//' \
+                                         -e 's/elevator=[^ ]*//' \
+                                         -e 's/^ *//' \
+                                         -e 's/ *$//'|tr -s ' ' '_')
+    v=$(uname -r)
+    [ -n "$cmdline" ] && v="$v:$cmdline"
+    [ -n "$KVERS" ] && v=$KVERS
+    echo $v
+}
+
 plot() {
-    if [ -n "$PLOT_CMD" ]; then
-       echo "set terminal postscript color eps enhanced;
-             $PLOT_CMD" | gnuplot | epstopdf --filter > `basename $0 .sh`.pdf
-       if [ -z "$OPT_PDF_ONLY" ]; then
-           echo "set terminal x11 enhanced; $PLOT_CMD" | gnuplot -persist
+#    for i in "${!PLOT_CMD[@]}"; do
+    local testname=`basename $0 .sh`
+    for i in 0; do
+       cmd=`p`                 # Get plot commands
+       cmd=$(echo "$cmd" | sed -e "/set title/ s/[\"']\(.*\)[\"']/\"\1\\\\n($(kvers), CPU\\\\\\\\@${clk}MHz)\"/")
+       if [ -z "$OPT_NO_X11" ]; then
+           echo "set terminal x11 enhanced; ${cmd}" | gnuplot -persist
        fi
-    fi
+       I=${i/0/}
+       echo 'set terminal postscript color eps enhanced size 6cm,4cm lw 1 "Times-Roman" 10;' \
+            'set lmargin 8;' \
+             "${cmd}" | gnuplot > ${testname}$I.eps
+       echo "set terminal postscript color eps enhanced;" \
+            "${cmd}" | gnuplot | epstopdf --filter > ${testname}$I.pdf
+       mkdir -p thumb
+       convert -density 30  -gamma 0.5 -quality 90 -type Palette -depth 8 ${testname}$I.pdf thumb/${testname}$I.png
+       convert -density 150 -gamma 0.7 -quality 90 -type Palette -depth 8 ${testname}$I.pdf ${testname}$I.png
+    done
 }
 
-go() {
-    d=results/`basename $0 .sh`/`uname -r`
+create_dirs_and_links() {
+    local test=$1
+    local kver=$2
+    local clck=$3
+
+    local  d=results/by-kern/$kver/$clck/$test
     mkdir -p $d
-    cd $d
-    
-    [ -n "$OPT_PLOT_ONLY" ] || run_tests
-    plot
+    mkdir -p results/by-kern/$kver/$test # 1
+    mkdir -p results/by-test/$test/$kver # 2
+    mkdir -p results/by-test/$test/$clck # 3
+    mkdir -p results/by-clck/$clck/$kver # 4
+    mkdir -p results/by-clck/$clck/$test # 5
+    ln -sfT ../../../${d#results/} results/by-kern/$kver/$test/$clck # 1
+    ln -sfT ../../../${d#results/} results/by-test/$test/$kver/$clck # 2
+    ln -sfT ../../../${d#results/} results/by-test/$test/$clck/$kver # 3
+    ln -sfT ../../../${d#results/} results/by-clck/$clck/$kver/$test # 4
+    ln -sfT ../../../${d#results/} results/by-clck/$clck/$test/$kver # 5
+    echo $d
+}
+
+go() {
+    echo "####################"
+    if [ ! -n "$OPT_PLOT_ONLY" ]; then
+       mhz=`sed -ne '/^cpu MHz/ s/.*:\([^.]\+\).*/\1/p' /proc/cpuinfo|head -n 1`
+       if [ -r /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq ]; then
+           local max=$((`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`/1000))
+           local min=$((`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`/1000))
+           mhz="$max $min"
+       fi
+    else
+       mhz=$(cd results/by-clck; echo *)
+    fi
+    for clk in $mhz; do
+    echo "===================="
+       dir=$(create_dirs_and_links `basename $0 .sh` `kvers` $clk)
+       set -x
+       pushd $dir
+
+       if [ ! -n "$OPT_PLOT_ONLY" ]; then
+           cpufreq-set -f ${clk}MHz
+           run_tests
+           cpufreq-set -f ${mhz}MHz
+       else
+           unset OPT_PLOT_DISABLE
+       fi
+       if [ ! -n "$OPT_PLOT_DISABLE" ]; then
+           plot
+       fi
+       popd
+       set +x
+    done
 
 }