summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsantosh shukla <santosh.shukla@linaro.org>2014-08-16 12:29:01 +0530
committerSantosh Shukla <sshukla@mvista.com>2014-08-16 12:35:56 +0530
commit1844248f723b15663b5083207b18f6f84f4d1c5b (patch)
treeec7dbf8bb2e68fb2d2c7cca5a4a60e14370c1d29
parent0db3ca6bc3cb04cd3c4c197f88d0f1b2929d9966 (diff)
odp-on-isolated-cpu.sh : Initial script for odp isolationisol-v2
This script will use is-cpu-isolated.sh for cpu isolation, get_isolation_duration for odp application and clear the cpusets. For default case run cmd, ./common/scripts/odp-on-isolated-cpu.sh it will run odp_isolation on isol cpu 1,2 and will create 2 threads [p.s: assuming odp_isolation present in location /usr/local/bin] Signed-off-by: santosh shukla <santosh.shukla@linaro.org>
-rwxr-xr-xcommon/scripts/odp-on-isolated-cpu.sh130
1 files changed, 130 insertions, 0 deletions
diff --git a/common/scripts/odp-on-isolated-cpu.sh b/common/scripts/odp-on-isolated-cpu.sh
new file mode 100755
index 0000000..e020005
--- /dev/null
+++ b/common/scripts/odp-on-isolated-cpu.sh
@@ -0,0 +1,130 @@
+#!/bin/bash
+#
+# Author: Santosh Shukla <santosh.shukla@linaro.org>
+#
+# This script uses is-cpu-isolated.sh script (superset script) to isolate
+# a cpu or set of cpus (comma separated cpus list passed as argument $1 to
+# this script, Migrate possible kernel background tasks to boot cpu or other
+# non-isolated cpus)
+#
+# We record odp app isolation time using is-cpu-isolated.sh script "duration" argument.
+#
+# SCRIPT ARGUMENTS
+# $1: isolate cpu list comma separated
+# $2: Full odp command format like below
+#
+# "odp_l2fwd -i 0,2 -m 0 -c 2"
+# "odp_isolation -l 1,2"
+#
+# cut-n-paste below example to test the script :
+#./common/scripts/odp-on-isolated-cpu.sh 1,2 "odp_l2fwd -i 0,2 -m 0 -c 2" &
+#./common/scripts/odp-on-isolated-cpu.sh 1,2 "odp_isolation -l 1,2"
+#
+# note : it is assumed that odp bin copied to filesystem location /usr/local/bin
+#
+
+# Script arguments
+ISOL_CPUS="1,2" # CPU to isolate, default 1,2. Comma-separated list of CPUs.
+ODP_CMD="1,2 odp_isolation -l 1,2" # Default odp cmd to run
+
+# Global Var
+ODP_APP="odp_isolation" # Default odp binary to run
+
+# Migrate thread to dplane cpu
+# argument - $1=thread_pid
+# $2=isol cpu
+migrate_thread() {
+
+ cpu_mask=$2
+
+ # Move thread to isolated CPU
+ echo $1 > /dev/cpuset/dplane/cpu$cpu_mask/tasks
+}
+
+# get number of isol cpus
+get_cpu_count() {
+
+ cpu_count=0
+ for i in `echo $ISOL_CPUS | sed 's/,/ /g'`; do
+ let cpu_count++
+ done
+
+ echo $cpu_count
+}
+
+# Create odp setup
+odp_create_setup() {
+
+ # parse odp_ string and store them in variable
+ parsed=$(echo $ODP_CMD | cut -d " " -f 2-)
+
+ # get actual binary name out from big parsed string
+ ODP_APP=`echo $parsed | cut -f1 -d " "`
+
+ # Isolate cpu
+ $(pwd)/common/scripts/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "isolate"
+
+ # Run odp application
+ $parsed &
+
+ # get odp main() process pid
+ proc_pid=$!
+
+ # Few big application initialization takes more time to launch DP threads,
+ # this lead to NO thread pid entry found in /proc/$proc_pid/tasks.
+ # So better wait till application launches all the possible threads.
+ # for example : dpdk-l2fwd takes more time to launch thread.
+ while :
+ do
+ # loop until all thread pid found in /proc/$proc_pid/task
+ if [ $(ls /proc/$proc_pid/task | wc -l) -gt $(get_cpu_count) ];
+ then
+ break
+ fi
+ done
+
+ echo "$proc_pid"
+
+ # list odp thread pid in var thd_pid_list
+ thd_pid_list=$(ls /proc/$proc_pid/task | grep -v $proc_pid)
+
+ echo $thd_pid_list
+
+ # fill odp threads pid into arr[]
+ k=0
+ for i in `echo $thd_pid_list`; do
+ arr[k]=$i;
+ let k++
+ done
+
+ k=0
+ for i in `echo $ISOL_CPUS | sed 's/,/ /g'`; do
+ migrate_thread ${arr[$k]} $i
+ let k++
+ done
+
+ echo "DP Application isolation duration"
+ $(pwd)/common/scripts/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "duration"
+
+ echo "DP Application clear isol cpuset"
+ $(pwd)/common/scripts/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "clear"
+}
+
+# Parse argument
+[ $1 ] && ISOL_CPUS=$1
+
+# get full comand to parse
+if [ $# -gt 0 ]; then
+ ODP_CMD=$@
+fi
+
+## Check validity of arguments
+USAGE="Usage: $0 <CPUs to isolate (default 1), comma separated list> <odp_* binary full command in double quote>"
+
+if [ "$1" = "-h" -o "$1" = "--help" ]; then
+ echo $USAGE >&2
+ exit 0
+fi
+
+odp_create_setup
+