Commit fa52d995 authored by Veronika Molnarova's avatar Veronika Molnarova Committed by Namhyung Kim

perf test stat+shadow_stat.sh: Add threshold for rounding errors

The test was failing in specific scenarios due to imperfection of FP
arithmetics. The `bc` command wasn't correctly rounding the result of
division causing the failure.

Replace the `bc` with `awk` which should work with more decimal places
and add a threshold to catch any possible rounding errors.  The
acceptable rounding error is set to 0.01 when the test passes with a
warning message.
Signed-off-by: default avatarVeronika Molnarova <vmolnaro@redhat.com>
Acked-by: default avatarMichael Petlan <mpetlan@redhat.com>
Link: https://lore.kernel.org/r/20230919150419.23193-1-vmolnaro@redhat.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent e49be27e
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
set -e set -e
THRESHOLD=0.015
# skip if system-wide mode is forbidden # skip if system-wide mode is forbidden
perf stat -a true > /dev/null 2>&1 || exit 2 perf stat -a true > /dev/null 2>&1 || exit 2
...@@ -33,11 +35,19 @@ test_global_aggr() ...@@ -33,11 +35,19 @@ test_global_aggr()
fi fi
# use printf for rounding and a leading zero # use printf for rounding and a leading zero
res=`printf "%.2f" "$(echo "scale=6; $num / $cyc" | bc -q)"` res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
if [ "$ipc" != "$res" ]; then if [ "$ipc" != "$res" ]; then
# check the difference from the real result for FP imperfections
diff=`echo $ipc $res $THRESHOLD | \
awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
if [ $diff -eq 1 ]; then
echo "IPC is different: $res != $ipc ($num / $cyc)" echo "IPC is different: $res != $ipc ($num / $cyc)"
exit 1 exit 1
fi fi
echo "Warning: Difference of IPC is under the threshold"
fi
done done
} }
...@@ -67,11 +77,19 @@ test_no_aggr() ...@@ -67,11 +77,19 @@ test_no_aggr()
fi fi
# use printf for rounding and a leading zero # use printf for rounding and a leading zero
res=`printf "%.2f" "$(echo "scale=6; $num / $cyc" | bc -q)"` res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
if [ "$ipc" != "$res" ]; then if [ "$ipc" != "$res" ]; then
echo "IPC is different for $cpu: $res != $ipc ($num / $cyc)" # check difference from the real result for FP imperfections
diff=`echo $ipc $res $THRESHOLD | \
awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
if [ $diff -eq 1 ]; then
echo "IPC is different: $res != $ipc ($num / $cyc)"
exit 1 exit 1
fi fi
echo "Warning: Difference of IPC is under the threshold"
fi
done done
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment