Call just once all these sed/awk/cut etc. when finding mac addresses.
From 2437e980e6a8f0bcd123ddab077f00908069d379 Mon Sep 17 00:00:00 2001 From: Aleksey Senin <aleks...@voltaire.com> Date: Thu, 8 Apr 2010 11:53:07 +0300 Subject: [PATCH] Optimized when looking ethernet data.
I have two adapters with two ports on each one. This optimization gives me 6 sec. run-time instead of 19 sec. Signed-off-by: Aleksey Senin <aleks...@voltaire.com> --- ofed_scripts/ibdev2netdev | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ofed_scripts/ibdev2netdev b/ofed_scripts/ibdev2netdev index b436c05..adb5eba 100755 --- a/ofed_scripts/ibdev2netdev +++ b/ofed_scripts/ibdev2netdev @@ -30,12 +30,12 @@ function find_mac() for port in $ports; do gids=$(ls /sys/class/infiniband/$ibdev/ports/$port/gids) for gid in $gids; do - first=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut -b 21-22) + pmac=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut -b 21-24,26-27,33-34,36-) + first=${pmac:0:2} + pmac=${pmac:2} first=$(( first ^ 2 )) first=$(printf "%02x" $first) - second=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut -b 21- | sed -e 's/://g' | cut -b 3-6) - third=$(cat /sys/class/infiniband/$ibdev/ports/$port/gids/$gid | cut -b 21- | sed -e 's/://g' | cut -b 11-) - pmac=$first$second$third + pmac=$first$pmac if [ x$pmac == x$1 ]; then print_line $ibdev $port $2 fi -- 1.6.4.2