1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#!/bin/bash
# This simple script checks --all/-a option which is used for
# suppressing of default cpuset awareness of options --cpunodebind,
# --physcpubind, --interleave, --preferred and --membind.
# NOTE: Test needs two nodes and two cpus at least
testdir=`dirname "$0"`
: ${srcdir:=${testdir}/..}
: ${builddir:=${srcdir}}
export PATH=${builddir}:$PATH
export old_mask
eval_test() {
# echo "Running $1.."
$1
if [ $? == 1 ] ; then
echo -e "$1 FAILED!"
reset_mask
exit 1
fi
echo -e "$1 PASSED"
}
function check_arg_order
{
numactl --all --physcpubind=$HIGHESTCPU ls > /dev/null 2>&1
if [ $? == 1 ] ; then
return 1;
fi
numactl --physcpubind=$HIGHESTCPU --all ls > /dev/null 2>&1
if [ $? == 0 ] ; then
return 1;
fi
return 0
}
function check_physcpubind
{
reset_mask
set_cpu_affinity 0
numactl --physcpubind=$HIGHESTCPU ls > /dev/null 2>&1
if [ $? == 0 ] ; then # shouldn't pass so easy
return 1;
fi
numactl --all --physcpubind=$HIGHESTCPU ls > /dev/null 2>&1
if [ $? == 1 ] ; then # shouldn't fail
return 1;
fi
return 0
}
function check_cpunodebind
{
local low_cpu_range
local high_cpu
reset_mask
low_cpu_range=$(cat /sys/devices/system/node/node$LOWESTNODE/cpulist)
set_cpu_affinity $low_cpu_range
numactl --cpunodebind=$HIGHESTNODE ls > /dev/null 2>&1
if [ $? == 1 ] ; then # should pass
return 1;
fi
numactl --all --cpunodebind=$HIGHESTNODE ls > /dev/null 2>&1
if [ $? == 1 ] ; then # should pass for sure
return 1;
fi
return 0
}
function set_cpu_affinity
{
taskset -p -c $1 $$ > /dev/null
#echo -e "\taffinity of shell was set to" $1
}
function get_mask
{
old_mask=$(taskset -p $$ | cut -f2 -d: | sed -e 's/^[ \t]*//')
}
function reset_mask
{
taskset -p $old_mask $$ > /dev/null
#echo -e "\taffinity of shell was reset to" $old_mask
}
HIGHESTCPU=$(ls /sys/bus/cpu/devices | sed s/cpu// | sort -n | tail -1)
HIGHESTNODE=$(numactl -H | grep -Pzo 'node [0-9]* cpus: [0-9].*(.|\n)node [0-9]* size: [1-9].* MB' | tail -n1 | cut -f2 -d' ')
LOWESTNODE=$(numactl -H | grep -Pzo 'node [0-9]* cpus: [0-9].*(.|\n)node [0-9]* size: [1-9].* MB' | head -n1 | cut -f2 -d' ')
get_mask
eval_test check_arg_order
eval_test check_physcpubind
eval_test check_cpunodebind
reset_mask
exit 0
|