From 554aef5b4de19a5804cda8b7ddc0c7e3b26cfb05 Mon Sep 17 00:00:00 2001 From: Santosh Shukla Date: Mon, 11 Aug 2014 14:53:33 +0530 Subject: is-cpu-isolated.sh: use getopts for argument parsing Currently argument list has to be passed in a specific order for it to work. This isn't scalable as argument list grows. Lets parse arguments with getopts instead to scale better. New command format to test isolation. ./is-cpu-isolated.sh -hv -c -t -f -s -d By default , , , and Possible function types (-f) 1. isolate : Isolate core(s) for task 2. duration : Application isolation duration 3. clear : Clear cpuset rules used for step1 4. nonisol_list : Update list of all nonisol cpus 5. all : do step1,2,3 Examples : 1) run odp_isolation application on cpu no 1 and 2, function type ./is-cpu-isolated.sh -c 1,2 -t odp_isolation -f isolate 2) Get step1 isolate ./is-cpu-isolated.sh -c 1,2 -t odp_isolation -f duration 3) cpuset for step1 ./is-cpu-isolated.sh -c 1,2 -t odp_isolation -f clear 4) "-f all" == do step1),2),3) ./is-cpu-isolated.sh -c 1,2 -t odp_isolation -f all 5) Update list of all nonisol cpus ./is-cpu-isolated.sh -c 1,2 -t odp_isolation -f nonisol_list 6) Running with no argument execute default ./is-cpu-isolated.sh From now onwards is-cpu-isolated.sh script will run other isolation application unlike default stress application. Signed-off-by: Santosh Shukla --- common/scripts/is-cpu-isolated.sh | 113 ++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/common/scripts/is-cpu-isolated.sh b/common/scripts/is-cpu-isolated.sh index d7dfb15..5be2e6f 100755 --- a/common/scripts/is-cpu-isolated.sh +++ b/common/scripts/is-cpu-isolated.sh @@ -5,7 +5,7 @@ # This script is used for isolating $1 (comma separated list of CPUs) CPUs from # other kernel background activities. # -# This runs 'stress' test on the isolated CPUs and Figures out if CPUs are +# This runs task on the isolated CPUs and Figures out if CPUs are # isolated or not by reading 'cat /proc/interrupts' for all interrupts. # SCRIPT ARGUMENTS @@ -19,9 +19,11 @@ SAMPLE_COUNT=1 # How many samples to be taken MIN_ISOLATION=10 # Minimum isolation expected # Global variables -STRESS_DURATION=5000 # Run 'stress' for this duration +STRESS_DURATION=5000 # Run task for this duration NON_ISOL_CPUS="0" # CPU not to isolate, zero will always be there as we can't stop ticks on boot CPU. DEBUG_SCRIPT=1 # Print debug messages, set 0 if not required +TASK="stress" # Single threaded task to Run on Isolated CPUs +FUNC="all" # Perform complete isolation test by default RESULT="PASS" # Variables to keep an eye on total interrupt counts @@ -148,7 +150,7 @@ create_dplane_cpuset() { # Move shell to isolated CPU echo $$ > /dev/cpuset/dplane/cpu$1/tasks - # Start single cpu bound stress thread + # Start single cpu bound task stress -q --cpu 1 --timeout $STRESS_DURATION & # Move shell back to control plane CPU @@ -308,7 +310,7 @@ sense_infinite_isolation() { # process interrupts refresh_interrupts - ps h -C stress -o pid > /dev/null + ps h -C $TASK -o pid > /dev/null if [ $? != 0 ]; then T2="$(date +%s)" T=$(($T2-$T1)) @@ -395,8 +397,8 @@ clear_cpusets() { # Cleanup # - # kill all instances of stress - for i in `ps | grep stress | sed 's/^\ *//g' | cut -d' ' -f1`; + # kill all instances of task + for i in `ps | grep $TASK | sed 's/^\ *//g' | cut -d' ' -f1`; do kill -9 $i; done @@ -426,31 +428,86 @@ clear_cpusets() { # Execution starts from HERE -# Check validity of arguments -if [ "$1" = "-h" -o "$1" = "--help" ]; then - echo "Usage: $0 " - exit -fi - -# Parse arguments -[ $1 ] && ISOL_CPUS=$1 -[ $2 ] && SAMPLE_COUNT=$2 -[ $3 ] && MIN_ISOLATION=$3 +USAGE="Usage: $0 [-h] [-ctfsd args] [-c ] [-t ] [-f ] [-s ] [-d ]" +# Run isolation test for $FUNC +run_func() +{ + isdebug echo "" + isdebug echo "Function type: $FUNC" -# Run tests -if [ $4 ]; then - if [ $4 -eq 1 ]; then + case "$FUNC" in + "isolate") isolate_cpu - elif [ $4 -eq 2 ]; then + ;; + + "duration") get_isolation_duration - elif [ $4 -eq 3 ]; then + ;; + + "clear") clear_cpusets - else + ;; + + "nonisol_list") update_non_isol_cpus - fi -else - isolate_cpu - get_isolation_duration - clear_cpusets -fi + ;; + + "all") + isolate_cpu + get_isolation_duration + clear_cpusets + ;; + + *) + echo "Invalid [-f] function type" + ;; + esac +} + +# Parse isol arguments +parse_arguments() +{ + while getopts hc:t:f:s:d: arguments 2>/dev/null + do + case $arguments in + h) # --help + echo "$USAGE" + exit 0 + ;; + + c) # --cpu (comma separated isol cpulist, default cpu1) + ISOL_CPUS=$OPTARG + ;; + + t) # --task (task to run, default stress) + TASK=$OPTARG + ;; + + f) # --func_type (Function to perform: Isolate, Duration, + # Clear, Nonisol_list, all. default all) + FUNC=$OPTARG + ;; + + s) # --sample_count (no of samples to take, default 1) + SAMPLE_COUNT=$OPTARG + ;; + + d) # --duration (min isolation time duration, default 10) + MIN_ISOLATION=$OPTARG + ;; + + \?) # getopts issues an error message + echo "$USAGE " + exit 1 + ;; + esac + done +} + +# Parse isol arguments +parse_arguments $@ + +# Run isolation test for requested functionality +run_func + -- cgit v1.2.3