Gzip ramdisk - booting is faster
[can-benchmark.git] / tests / _lib.sh
index 0df9d91..930f688 100644 (file)
@@ -1,6 +1,7 @@
 
 while [ $# -gt 0 ]; do
     case "$1" in
+       -P) OPT_PLOT_DISABLE=1; shift;;
        -p) OPT_PLOT_ONLY=1; shift;;
        -X|--no-x11-plot) OPT_NO_X11=1; shift;;
     esac
@@ -13,6 +14,7 @@ PATH=$PWD/../_compiled/bin/:$PATH
 
 RTPRIO=${RTPRIO:-60}
 COUNT=${COUNT:-10000}
+export CANPING_MS=1            # Generate plots in milliseconds
 
 boost_irq_prio() {
     local PRIO=${1:-50}
@@ -28,7 +30,7 @@ boost_irq_prio() {
 }
 
 rmmod_can() {
-    modprobe -r lincan kvaser_pci vcan
+    modprobe -r lincan kvaser_pci vcan || true
 }
 
 prepare_lincan_hw() {
@@ -49,16 +51,24 @@ prepare_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
@@ -68,7 +78,7 @@ 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
@@ -78,10 +88,12 @@ prepare_socketcan_virtual() {
 run_tests() {
     tests=${TESTS:-socketcan_hw lincan_hw}
     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
 }
 
@@ -96,23 +108,28 @@ kvers() {
                                          -e 's/ *$//'|tr -s ' ' '_')
     v=$(uname -r)
     [ -n "$cmdline" ] && v="$v:$cmdline"
+    [ -n "$KVERS" ] && v=$KVERS
     echo $v
 }
 
 plot() {
 #    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 ($(kvers), CPU\\\\@${clk}Mhz)'/")
+       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
        I=${i/0/}
-       echo "set terminal postscript color eps enhanced;
-             ${cmd}" | gnuplot | epstopdf --filter > `basename $0 .sh`$I.pdf
+       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 -geometry 1000x100 -gamma 0.3 `basename $0 .sh`$I.pdf thumb/`basename $0 .sh`$I.png
-       convert -density 200 -gamma 0.7 -geometry 1000x500 `basename $0 .sh`$I.pdf `basename $0 .sh`$I.png
+       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
 }
 
@@ -121,16 +138,16 @@ create_dirs_and_links() {
     local kver=$2
     local clck=$3
 
-    local  d=results/by-test/$test/$kver/$clck
+    local  d=results/by-kern/$kver/$clck/$test
     mkdir -p $d
-    mkdir -p results/by-test/$test/$clck # 1
-    mkdir -p results/by-kern/$kver/$clck # 2
-    mkdir -p results/by-kern/$kver/$test # 3
+    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-test/$test/$clck/$kver # 1
-    ln -sfT ../../../${d#results/} results/by-kern/$kver/$clck/$test # 2
-    ln -sfT ../../../${d#results/} results/by-kern/$kver/$test/$clck # 3
+    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
@@ -138,11 +155,15 @@ create_dirs_and_links() {
 
 go() {
     echo "####################"
-    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"
+    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 "===================="
@@ -153,9 +174,13 @@ go() {
        if [ ! -n "$OPT_PLOT_ONLY" ]; then
            cpufreq-set -f ${clk}MHz
            run_tests
-           cpufreq-set -f 2400MHz
+           cpufreq-set -f ${mhz}MHz
+       else
+           unset OPT_PLOT_DISABLE
+       fi
+       if [ ! -n "$OPT_PLOT_DISABLE" ]; then
+           plot
        fi
-       plot
        popd
        set +x
     done