Santosh Shukla | 28322da | 2014-08-19 21:53:01 +0530 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Author: Santosh Shukla <santosh.shukla@linaro.org> |
| 4 | # |
| 5 | # This script uses is-cpu-isolated.sh script (superset script) to isolate |
| 6 | # a cpu or set of cpus (comma separated cpus list passed as argument $1 to |
| 7 | # this script, Migrate possible kernel background tasks to boot cpu) |
| 8 | # |
| 9 | # We record odp app isolation time using is-cpu-isolated.sh script's "duration" argument. |
| 10 | # |
| 11 | # SCRIPT ARGUMENTS |
| 12 | # $1: Comma separated list of CPUs to isolate |
| 13 | # $2: Full odp command format like below |
| 14 | # |
| 15 | # "odp_l2fwd -i 0,2 -m 0 -c 2" |
| 16 | # "odp_isolation -l 1,2" |
| 17 | # |
| 18 | # cut-n-paste below example to test the script : |
| 19 | # ./odp-on-isolated-cpu.sh 1,2 "odp_l2fwd -i 0,2 -m 0 -c 2" & |
| 20 | # ./odp-on-isolated-cpu.sh |
| 21 | # |
| 22 | # NOTE: it is assumed that odp bin copied to filesystem location /usr/local/bin |
| 23 | # |
| 24 | |
| 25 | # Script arguments |
| 26 | ISOL_CPUS="1,2" # CPU to isolate, default 1,2. Comma-separated list of CPUs. |
| 27 | ODP_CMD="odp_isolation -l 1,2" # Default odp cmd to run |
| 28 | |
| 29 | # get number of isol cpus |
| 30 | get_cpu_count() { |
| 31 | |
| 32 | cpu_count=0 |
| 33 | for i in `echo $ISOL_CPUS | sed 's/,/ /g'`; do |
| 34 | let cpu_count++ |
| 35 | done |
| 36 | |
| 37 | echo $cpu_count |
| 38 | } |
| 39 | |
| 40 | # Create odp setup for isolation |
| 41 | odp_isol_setup() { |
| 42 | # Get actual odp binary name out from $ODP_CMD |
| 43 | ODP_APP=`echo $ODP_CMD | cut -d " " -f1` |
| 44 | |
| 45 | # Isolate cpu |
| 46 | $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "isolate" |
| 47 | |
| 48 | # Run odp application |
| 49 | $ODP_CMD & |
| 50 | |
| 51 | # Get odp main() process pid |
| 52 | proc_pid=$! |
| 53 | |
| 54 | # Few big application initialization takes more time to launch DP threads, |
| 55 | # In that duration NO thread pid entry found in /proc/$proc_pid/tasks. |
| 56 | # So better wait till application launches all the possible threads |
| 57 | # and its pid reflected in /proc/$proc_pid/tasks. |
| 58 | # for example : dpdk-l2fwd takes more time to launch thread. |
| 59 | while : |
| 60 | do |
| 61 | # loop until all thread pid found in /proc/$proc_pid/task |
| 62 | if [ $(ls /proc/$proc_pid/task | wc -l) -gt $(get_cpu_count) ]; |
| 63 | then |
| 64 | break |
| 65 | fi |
| 66 | done |
| 67 | |
| 68 | # Echo odp main() process pid |
| 69 | echo "ODP process id: $proc_pid" |
| 70 | |
| 71 | # List odp threads pid in variable thd_pid_list |
| 72 | thd_pid_list=$(ls /proc/$proc_pid/task | grep -v $proc_pid) |
| 73 | |
| 74 | # Print thread pid list |
| 75 | echo "ODP threads: $thd_pid_list" |
| 76 | |
| 77 | # Fill odp threads pid into arr[] |
| 78 | k=0 |
| 79 | for i in $thd_pid_list; do |
| 80 | arr[k]=$i; |
| 81 | let k++ |
| 82 | done |
| 83 | |
| 84 | k=0 |
| 85 | for i in `echo $ISOL_CPUS | sed 's/,/ /g'`; do |
| 86 | # Move thread to isolated CPU |
| 87 | echo ${arr[$k]} > /dev/cpuset/dplane/cpu$i/tasks |
| 88 | let k++ |
| 89 | done |
| 90 | |
| 91 | echo "DP Application isolation duration" |
| 92 | $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "duration" |
| 93 | |
| 94 | echo "DP Application clear isol cpuset" |
| 95 | $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "clear" |
| 96 | } |
| 97 | |
| 98 | ## Check validity of arguments |
| 99 | USAGE="Usage: $0 <CPUs to isolate (default 1,2), comma separated list> <odp_* binary full command in double quote (default odp_isolation)>" |
| 100 | |
| 101 | if [ "$1" = "-h" -o "$1" = "--help" ]; then |
| 102 | echo "$USAGE" |
| 103 | exit 0 |
| 104 | fi |
| 105 | |
| 106 | # Parse argument |
| 107 | [ "$1" ] && ISOL_CPUS=$1 |
| 108 | [ "$2" ] && ODP_CMD=$2 |
| 109 | |
| 110 | # Create odp setup for isolation |
| 111 | odp_isol_setup |