laforge has submitted this change. ( https://gerrit.osmocom.org/c/upf-benchmark/+/39845?usp=email )
Change subject: Add scripts/ dir with helpers to operate on net iface irqs ......................................................................
Add scripts/ dir with helpers to operate on net iface irqs
Fetched from https://github.com/Mellanox/mlnx-tools b25ae28bb0f55375390c71a3f32f67c1264cf6c9, they can be used either as BSD or GPL2 license.
Change-Id: I646f57cb3940dbbd4e6606e013651116c38c9534 --- A scripts/common_irq_affinity.sh A scripts/set_irq_affinity_cpulist.sh A scripts/show_irq_affinity.sh A scripts/show_irq_affinity_hints.sh 4 files changed, 326 insertions(+), 0 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/scripts/common_irq_affinity.sh b/scripts/common_irq_affinity.sh new file mode 100644 index 0000000..df42833 --- /dev/null +++ b/scripts/common_irq_affinity.sh @@ -0,0 +1,132 @@ +#!/bin/bash +# +# Copyright (c) 2017 Mellanox Technologies. All rights reserved. +# +# This Software is licensed under one of the following licenses: +# +# 1) under the terms of the "Common Public License 1.0" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/cpl.php. +# +# 2) under the terms of the "The BSD License" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/bsd-license.php. +# +# 3) under the terms of the "GNU General Public License (GPL) Version 2" a +# copy of which is available from the Open Source Initiative, see +# http://www.opensource.org/licenses/gpl-license.php. +# +# Licensee has the right to choose one of the above licenses. +# +# Redistributions of source code must retain the above copyright +# notice and one of the license notices. +# +# Redistributions in binary form must reproduce both the above copyright +# notice, one of the license notices in the documentation +# and/or other materials provided with the distribution. +# +# Fetched from https://github.com/Mellanox/mlnx-tools/blob/mlnx_ofed/sbin/common_irq_affini... b25ae28bb0f55375390c71a3f32f67c1264cf6c9 + +function add_comma_every_eight +{ + echo " $1 " | sed -r ':L;s=\b([0-9]+)([0-9]{8})\b=\1,\2=g;t L' +} + +function int2hex +{ + CHUNKS=$(( $1/64 )) + COREID=$1 + HEX="" + for (( CHUNK=0; CHUNK<${CHUNKS} ; CHUNK++ )) + do + HEX=$HEX"0000000000000000" + COREID=$((COREID-64)) + done + printf "%x$HEX" $(echo $((2**$COREID)) ) +} + + +function core_to_affinity +{ + echo $( add_comma_every_eight $( int2hex $1) ) +} + +function get_irq_list +{ + interface=$1 + pci_dev=$(ethtool -i $interface | grep "bus-info:" | cut -d ' ' -f 2) + infiniband_device_irqs_path="/sys/class/infiniband/$interface/device/msi_irqs" + net_device_irqs_path="/sys/class/net/$interface/device/msi_irqs" + interface_in_proc_interrupts=$(grep -P "$interface[^0-9,a-z,A-Z]" /proc/interrupts | cut -d":" -f1) + pci_in_proc_interrupts=$(grep "$pci_dev" /proc/interrupts | grep -v "async" | cut -d":" -f1) + + if [ -d "$infiniband_device_irqs_path" ]; then + irq_list=$(/bin/ls -1 "$infiniband_device_irqs_path" | tail -n +2) + elif [ "$interface_in_proc_interrupts" != "" ]; then + irq_list=$interface_in_proc_interrupts + elif [ "$pci_in_proc_interrupts" != "" ]; then + irq_list=$pci_in_proc_interrupts + elif [ -d "$net_device_irqs_path" ]; then + irq_list=$(/bin/ls -1 "$net_device_irqs_path" | tail -n +2) + else + echo "Error - interface or device "$interface" does not exist" 1>&2 + exit 1 + fi + sorted_irq_list=$(echo "$irq_list" | sort -g) + echo "$sorted_irq_list" +} + +function show_irq_affinity +{ + irq_num=$1 + show_cpu_number=$2 + smp_affinity_path="/proc/irq/$irq_num/smp_affinity" + cpu_number_path="/proc/irq/$irq_num/smp_affinity_list" + if [ -f $smp_affinity_path ]; then + if [ -f $cpu_number_path ] && [ "$show_cpu_number" == "show_cpu_number" ]; then + echo -n "$irq_num (cpu #`cat $cpu_number_path`): " + else + echo -n "$irq_num: " + fi + cat $smp_affinity_path + fi +} + +function show_irq_affinity_hints +{ + irq_num=$1 + affinity_hint_path="/proc/irq/$irq_num/affinity_hint" + if [ -f $affinity_hint_path ]; then + echo -n "$irq_num: " + cat $affinity_hint_path + fi +} + +function set_irq_affinity +{ + irq_num=$1 + affinity_mask=$2 + smp_affinity_path="/proc/irq/$irq_num/smp_affinity" + if [ -f $smp_affinity_path ]; then + echo $affinity_mask > $smp_affinity_path + fi +} + +function is_affinity_hint_set +{ + irq_num=$1 + hint_not_set=0 + affinity_hint_path="/proc/irq/$irq_num/affinity_hint" + if [ -f $affinity_hint_path ]; then + TOTAL_CHAR=$( wc -c < $affinity_hint_path ) + NUM_OF_COMMAS=$( grep -o "," $affinity_hint_path | wc -l ) + NUM_OF_ZERO=$( grep -o "0" $affinity_hint_path | wc -l ) + NUM_OF_F=$( grep -i -o "f" $affinity_hint_path | wc -l ) + if [[ $((TOTAL_CHAR-1-NUM_OF_COMMAS)) -eq $NUM_OF_ZERO || $((TOTAL_CHAR-1-NUM_OF_COMMAS)) -eq $NUM_OF_F ]]; then + hint_not_set=1 + fi + else + hint_not_set=1 + fi + return $hint_not_set +} diff --git a/scripts/set_irq_affinity_cpulist.sh b/scripts/set_irq_affinity_cpulist.sh new file mode 100755 index 0000000..5e7a5fc --- /dev/null +++ b/scripts/set_irq_affinity_cpulist.sh @@ -0,0 +1,94 @@ +#! /bin/bash +# +# Copyright (c) 2017 Mellanox Technologies. All rights reserved. +# +# This Software is licensed under one of the following licenses: +# +# 1) under the terms of the "Common Public License 1.0" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/cpl.php. +# +# 2) under the terms of the "The BSD License" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/bsd-license.php. +# +# 3) under the terms of the "GNU General Public License (GPL) Version 2" a +# copy of which is available from the Open Source Initiative, see +# http://www.opensource.org/licenses/gpl-license.php. +# +# Licensee has the right to choose one of the above licenses. +# +# Redistributions of source code must retain the above copyright +# notice and one of the license notices. +# +# Redistributions in binary form must reproduce both the above copyright +# notice, one of the license notices in the documentation +# and/or other materials provided with the distribution. +# +# Fetched from https://raw.githubusercontent.com/Mellanox/mlnx-tools/refs/heads/mlnx_ofed/s... b25ae28bb0f55375390c71a3f32f67c1264cf6c9 + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [ -z $2 ]; then + echo "usage: $0 <cpu list> <interface or IB device> " + echo " <cpu list> can be either a comma separated list of single core numbers (0,1,2,3) or core groups (0-3)" + exit 1 +fi +cpulist=$1 +interface=$2 +NCPUS=$(cat /proc/cpuinfo | grep -c processor) +ONLINE_CPUS=$(cat /proc/cpuinfo | grep processor | cut -d ":" -f 2) + +source "$SCRIPT_DIR/common_irq_affinity.sh" + +IRQS=$( get_irq_list $interface ) + +if [ -z "$IRQS" ] ; then + echo No IRQs found for $interface. + exit 1 +fi + +CORES=$( echo $cpulist | sed 's/,/ /g' | wc -w ) +for word in $(seq 1 $CORES) +do + SEQ=$(echo $cpulist | cut -d "," -f $word | sed 's/-/ /') + if [ "$(echo $SEQ | wc -w)" != "1" ]; then + CPULIST="$CPULIST $( echo $(seq $SEQ) | sed 's/ /,/g' )" + fi +done +if [ "$CPULIST" != "" ]; then + cpulist=$(echo $CPULIST | sed 's/ /,/g') +fi +CORES=$( echo $cpulist | sed 's/,/ /g' | wc -w ) + + +echo Discovered irqs for $interface: $IRQS +I=1 +for IRQ in $IRQS +do + core_id=$(echo $cpulist | cut -d "," -f $I) + online=1 + if [ $core_id -ge $NCPUS ] + then + online=0 + for online_cpu in $ONLINE_CPUS + do + if [ "$online_cpu" == "$core_id" ] + then + online=1 + break + fi + done + fi + if [ $online -eq 0 ] + then + echo "irq $IRQ: Error - core $core_id does not exist" + else + echo Assign irq $IRQ core_id $core_id + affinity=$( core_to_affinity $core_id ) + set_irq_affinity $IRQ $affinity + fi + I=$(( (I%CORES) + 1 )) +done +echo +echo done. diff --git a/scripts/show_irq_affinity.sh b/scripts/show_irq_affinity.sh new file mode 100755 index 0000000..24535d8 --- /dev/null +++ b/scripts/show_irq_affinity.sh @@ -0,0 +1,51 @@ +#! /bin/bash +# +# Copyright (c) 2017 Mellanox Technologies. All rights reserved. +# +# This Software is licensed under one of the following licenses: +# +# 1) under the terms of the "Common Public License 1.0" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/cpl.php. +# +# 2) under the terms of the "The BSD License" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/bsd-license.php. +# +# 3) under the terms of the "GNU General Public License (GPL) Version 2" a +# copy of which is available from the Open Source Initiative, see +# http://www.opensource.org/licenses/gpl-license.php. +# +# Licensee has the right to choose one of the above licenses. +# +# Redistributions of source code must retain the above copyright +# notice and one of the license notices. +# +# Redistributions in binary form must reproduce both the above copyright +# notice, one of the license notices in the documentation +# and/or other materials provided with the distribution. +# +# Fetched from https://raw.githubusercontent.com/Mellanox/mlnx-tools/refs/heads/mlnx_ofed/s... b25ae28bb0f55375390c71a3f32f67c1264cf6c9 + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [ -z $1 ]; then + echo "usage: $0 <interface or IB device> [show_cpu_number]" + exit 1 +fi + +source "$SCRIPT_DIR/common_irq_affinity.sh" + +IRQS=$( get_irq_list $1 ) +if [ -z "$IRQS" ] ; then + echo No IRQs found for $1. + exit 1 +fi + +show_cpu=$2 + +for irq in $IRQS +do + show_irq_affinity $irq $show_cpu +done + diff --git a/scripts/show_irq_affinity_hints.sh b/scripts/show_irq_affinity_hints.sh new file mode 100755 index 0000000..ec26cf1 --- /dev/null +++ b/scripts/show_irq_affinity_hints.sh @@ -0,0 +1,49 @@ +#! /bin/bash +# +# Copyright (c) 2017 Mellanox Technologies. All rights reserved. +# +# This Software is licensed under one of the following licenses: +# +# 1) under the terms of the "Common Public License 1.0" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/cpl.php. +# +# 2) under the terms of the "The BSD License" a copy of which is +# available from the Open Source Initiative, see +# http://www.opensource.org/licenses/bsd-license.php. +# +# 3) under the terms of the "GNU General Public License (GPL) Version 2" a +# copy of which is available from the Open Source Initiative, see +# http://www.opensource.org/licenses/gpl-license.php. +# +# Licensee has the right to choose one of the above licenses. +# +# Redistributions of source code must retain the above copyright +# notice and one of the license notices. +# +# Redistributions in binary form must reproduce both the above copyright +# notice, one of the license notices in the documentation +# and/or other materials provided with the distribution. +# +# Fetched from https://raw.githubusercontent.com/Mellanox/mlnx-tools/refs/heads/mlnx_ofed/s... b25ae28bb0f55375390c71a3f32f67c1264cf6c9 + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [ -z $1 ]; then + echo "usage: $0 <interface or IB device> " + exit 1 +fi + +source "$SCRIPT_DIR/common_irq_affinity.sh" + +IRQS=$( get_irq_list $1 ) +if [ -z "$IRQS" ] ; then + echo No IRQs found for $1. + exit 1 +fi + +for irq in $IRQS +do + show_irq_affinity_hints $irq +done +