diff options
author | Santosh Shukla <santosh.shukla@linaro.org> | 2014-08-19 00:21:09 +0530 |
---|---|---|
committer | santosh shukla <santosh.shukla@linaro.org> | 2014-08-19 01:40:42 +0530 |
commit | 990d57b0c11d14076c8b062e432f9eaea6ae0aa7 (patch) | |
tree | 61171794c174db5bfbb30e4ad4716507d84385eb | |
parent | edcfbc8baed91b7831405be6c4db911b07390f9e (diff) |
odp-on-isolated-cpu.sh: Initial script for odp isolationisol-v4
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.
Signed-off-by: Santosh Shukla <santosh.shukla@linaro.org>
-rwxr-xr-x | common/scripts/odp-on-isolated-cpu.sh | 128 |
1 files changed, 128 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..5f0fbb6 --- /dev/null +++ b/common/scripts/odp-on-isolated-cpu.sh @@ -0,0 +1,128 @@ +#!/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 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() { + # Move thread to isolated CPU + echo $1 > /dev/cpuset/dplane/cpu$2/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 for isolation +odp_isol_setup() { + + # Parse odp_ string and store them in variable + parse=$(echo $ODP_CMD | cut -d " " -f 2-) + + # Get actual odp binary name out from "parse" variable + ODP_APP=`echo $parse | cut -f1 -d " "` + + # Isolate cpu + $(pwd)/is-cpu-isolated.sh -q -c $ISOL_CPUS -t $ODP_APP -f "isolate" + + # Run odp application + $parse & + + # 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 odp main() process pid + echo "$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 $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)/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" +} + +# Parse argument +[ $1 ] && ISOL_CPUS=$1 + +# get full command 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" + exit 0 +fi + +# Create odp setup for isolation +odp_isol_setup + |