diff options
author | Santosh Shukla <santosh.shukla@linaro.org> | 2014-08-19 21:53:01 +0530 |
---|---|---|
committer | Viresh Kumar <viresh.kumar@linaro.org> | 2014-08-20 14:21:01 +0530 |
commit | 28322da9a22fce846d816eb9e7a0cd4e3297917b (patch) | |
tree | c943dc6d7c5f4399ef9cbe0d4d946d5c843321e3 /common | |
parent | 79127ad5e22376f4d6e6a1c9e33fce5a2b3e2e0d (diff) |
odp-on-isolated-cpu.sh: Initial script for odp isolation
Script to run odp application on isolated cores.
This script will isolate CPUs using is-cpu-isolated.sh, will then start odp
threads on isolated CPUs. It will then get isolation time and clear cpusets
using is-cpu-isolated.sh.
Command to run ./odp-on-isolated-cpu.sh
This will run odp threads on isolated cores 1 and 2.
Change-Id: I5e7b4b7e0ffd3fc50b04987ed50835cc1c490bd8
Signed-off-by: Santosh Shukla <santosh.shukla@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Not-Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Diffstat (limited to 'common')
-rwxr-xr-x | common/scripts/odp-on-isolated-cpu.sh | 111 |
1 files changed, 111 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..287e116 --- /dev/null +++ b/common/scripts/odp-on-isolated-cpu.sh @@ -0,0 +1,111 @@ +#!/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) +# +# We record odp app isolation time using is-cpu-isolated.sh script's "duration" argument. +# +# SCRIPT ARGUMENTS +# $1: Comma separated list of CPUs to isolate +# $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 : +# ./odp-on-isolated-cpu.sh 1,2 "odp_l2fwd -i 0,2 -m 0 -c 2" & +# ./odp-on-isolated-cpu.sh +# +# 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="odp_isolation -l 1,2" # Default odp cmd to run + +# 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 for isolation +odp_isol_setup() { + # Get actual odp binary name out from $ODP_CMD + ODP_APP=`echo $ODP_CMD | cut -d " " -f1` + + # Isolate cpu + $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "isolate" + + # Run odp application + $ODP_CMD & + + # Get odp main() process pid + proc_pid=$! + + # Few big application initialization takes more time to launch DP threads, + # In that duration NO thread pid entry found in /proc/$proc_pid/tasks. + # So better wait till application launches all the possible threads + # and its pid reflected in /proc/$proc_pid/tasks. + # 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 odp main() process pid + echo "ODP process id: $proc_pid" + + # List odp threads pid in variable thd_pid_list + thd_pid_list=$(ls /proc/$proc_pid/task | grep -v $proc_pid) + + # Print thread pid list + echo "ODP threads: $thd_pid_list" + + # Fill odp threads pid into arr[] + k=0 + for i in $thd_pid_list; do + arr[k]=$i; + let k++ + done + + k=0 + for i in `echo $ISOL_CPUS | sed 's/,/ /g'`; do + # Move thread to isolated CPU + echo ${arr[$k]} > /dev/cpuset/dplane/cpu$i/tasks + let k++ + done + + echo "DP Application isolation duration" + $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "duration" + + echo "DP Application clear isol cpuset" + $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "clear" +} + +## Check validity of arguments +USAGE="Usage: $0 <CPUs to isolate (default 1,2), comma separated list> <odp_* binary full command in double quote (default odp_isolation)>" + +if [ "$1" = "-h" -o "$1" = "--help" ]; then + echo "$USAGE" + exit 0 +fi + +# Parse argument +[ "$1" ] && ISOL_CPUS=$1 +[ "$2" ] && ODP_CMD=$2 + +# Create odp setup for isolation +odp_isol_setup |