diff --git a/bench.sh b/bench.sh index 744505e..b843f75 100755 --- a/bench.sh +++ b/bench.sh @@ -6,10 +6,9 @@ # Allocators and tests # -------------------------------------------------------------------- -readonly alloc_all="sys kp dh ff fg gd hd hm hml iso je lf lp lt mi mi-sec mi2 mi2-sec mi3 mi3-sec mng mesh nomesh pa rp sc scudo sg sm sn sn-sec s tbb tc tcg mi-dbg mi2-dbg mi3-dbg xmi xsmi xmi-dbg yal rmalloc" +readonly alloc_all="sys dh ff fg gd hd hm hml iso je kp lf lp lt mi mi-dbg mi-sec mi2 mi2-dbg mi2-sec mi3 mi3-dbg mi3-sec mng mesh nomesh pa rmalloc rp s sc scudo sg sm sn sn-sec tbb tc tcg xmi xsmi xmi-dbg yal" readonly alloc_secure="dh ff gd hm hml iso mi-sec mi2-sec mi3-sec mng pa scudo sg sn-sec sg" alloc_run="" # allocators to run (expanded by command line options) -alloc_installed="sys" # later expanded to include all installed allocators alloc_libs="sys=" # mapping from allocator to its .so as "= ..." readonly tests_all1="cfrac espresso barnes redis lean larson-sized mstress rptest gs lua" @@ -199,26 +198,67 @@ function contains { # does string contain substring? return 1 } -function is_installed { # - contains "$alloc_installed" $1 +function get_so_path () { # : name of alloc to look up in alloc_libs + for entry in $alloc_libs; do + entry_name="${entry%=*}" + entry_lib="${entry#*=}" + if test "$entry_name" = "$1"; then + echo "$entry_lib" | cut -d: -f1 + fi + done } -function alloc_run_add { # :add to runnable - alloc_run="$alloc_run $1" +function alloc_is_installed { # : path to .$extso-file + if [ ! -f "$1" ]; then + return 1 + fi + # macos ignores a broken DYLD_INSERT_LIBRARIES silently and has no /proc + if test -n "$darwin"; then + return 0 + fi + err=$(LD_PRELOAD="$1" sh -c "grep -qF \"${1##*/}\" /proc/self/maps" 2>&1 >/dev/null) + if [ "$?" -ne 0 ]; then + echo "failed to LD_PRELOAD a selected allocator: $1" + test -n "$err" && echo "$err" + return 1 + fi + return 0 } -function alloc_run_remove { # :remove from runnables - if contains "$alloc_run" "$1"; then - alloc_run_old="$alloc_run" - alloc_run="" - for s in $alloc_run_old; do - if [ "$s" != "$1" ]; then - alloc_run_add "$s" +function list_installed { # print all allocators whose library exists + # (only a file check here; the LD_PRELOAD probe in + # alloc_is_installed would be too slow for --help) + printf " %-9s %s\n" "sys:" "$libc" + for alloc in $alloc_all; do + if test "$alloc" != "sys"; then + lib=$(get_so_path "$alloc") + if test -n "$lib" -a -f "$lib"; then + printf " %-9s %s\n" "$alloc:" "${lib#$localdevdir/}" fi - done + fi + done +} + +function alloc_run_add { # :add to runnable + if test "$1" = "sys"; then + alloc_run="$alloc_run $1" + return + fi + if alloc_is_installed $(get_so_path "$1"); then + alloc_run="$alloc_run $1" fi } +function alloc_run_remove { # :remove from runnables + alloc_run_old="$alloc_run" + alloc_run="" + for s in $alloc_run_old; do + if [ "$s" != "$1" ]; then + alloc_run_add "$s" + fi + done +} + function alloc_run_add_remove { # if test "$2" = "1"; then alloc_run_add "$1" @@ -227,25 +267,6 @@ function alloc_run_add_remove { # fi } -# read in the installed allocators -while read word _; do alloc_installed="$alloc_installed ${word%:*}"; done < ${localdevdir}/versions.txt -if is_installed "mi"; then - alloc_installed="$alloc_installed mi-sec mi-dbg" # secure mimalloc -fi -if is_installed "mi2"; then - alloc_installed="$alloc_installed mi2-sec mi2-dbg" # secure mimalloc -fi -if is_installed "mi3"; then - alloc_installed="$alloc_installed mi3-sec mi3-dbg" # secure mimalloc -fi -if is_installed "hm"; then - alloc_installed="$alloc_installed hml" # hardened_malloc light -fi -if is_installed "sn"; then - alloc_installed="$alloc_installed sn-sec" # secure snmalloc -fi - - alloc_lib="" function alloc_lib_set { # for entry in $alloc_libs; do @@ -265,15 +286,13 @@ function tests_run_add { # :add to runnable tests } function tests_run_remove { # :remove from runnable tests - if contains "$tests_run" "$1"; then - tests_run_old="$tests_run" - tests_run="" - for tst in $tests_run_old; do - if [ "$tst" != "$1" ]; then - tests_run_add "$tst" - fi - done - fi + tests_run_old="$tests_run" + tests_run="" + for tst in $tests_run_old; do + if [ "$tst" != "$1" ]; then + tests_run_add "$tst" + fi + done } function tests_run_add_remove { # @@ -330,9 +349,6 @@ while : ; do esac if contains "$alloc_all" "$flag"; then - if ! contains "$alloc_installed" "$flag"; then - warning "allocator '$flag' selected but it seems it is not installed ($alloc_installed)" - fi alloc_run_add_remove "$flag" "$flag_arg" else if contains "$tests_all" "$flag"; then @@ -342,17 +358,13 @@ while : ; do "") break;; alla) # use all installed allocators (iterate to maintain order as specified in alloc_all) - for alloc in $alloc_all; do - if is_installed "$alloc"; then - alloc_run_add_remove "$alloc" "$flag_arg" - fi + for alloc in $alloc_all; do + alloc_run_add_remove "$alloc" "$flag_arg" done;; allsa) # use all "secure" installed allocators (iterate to maintain order as specified in alloc_secure) for alloc in $alloc_secure; do - if is_installed "$alloc"; then - alloc_run_add_remove "$alloc" "$flag_arg" - fi + alloc_run_add_remove "$alloc" "$flag_arg" done;; allt) for tst in $tests_allt; do @@ -443,8 +455,7 @@ while : ; do echo " $alloc_secure" echo "" echo "installed allocators:" - echo " sys: $libc" - column -t "$localdevdir/versions.txt" | sed 's/^/ /' + list_installed echo "" exit 0;; *) warning "unknown option \"$1\"." 1>&2 @@ -475,8 +486,7 @@ if test "$verbose" = "yes"; then echo " $alloc_all" echo "" echo "installed allocators:" - echo " sys: $libc" - column -t "$localdevdir/versions.txt" | sed 's/^/ /' + list_installed echo "" fi