#!/bin/sh # define CPU affinity for setiathome instances and BOINC, # if not already done... should work on any vanilla Solaris since release 8 # (at least, maybe on older ones too) numCPUsAv=`/usr/sbin/psrinfo | grep on-line | wc -l` setiRun=`ps -U $LOGNAME -o comm | grep setiathome | wc -l` bindcmd=/usr/sbin/pbind if [ $setiRun -gt 0 -a $setiRun -le $numCPUsAv ]; then # try to pin them to CPUs: setiIDs=`ps -U $LOGNAME -o pid,comm | grep setiathome | awk '{print $1}'` listPinned=`$bindcmd -q $setiIDs | grep -v "not bound" | awk '{print $(NF-1)$NF}'` listCPUs=`echo $listPinned | awk -F: 'BEGIN{RS=" "}{print $2}'` listIDs=`echo $listPinned | awk -F: 'BEGIN{RS=" "}{print $1}'` # first always bind/unbind boinc to cpu id 1, regardless if already done if [ $setiRun -lt $numCPUsAv ]; then # one remains bindopt="-b 0" else # let it free, all CPUs are occupied by SETI instances: bindopt=-u fi $bindcmd $bindopt `ps -U $LOGNAME -o pid,comm | grep boinc | awk '{print $1}'` # now start with highest CPU id: currCPU=`expr $numCPUsAv - 1` # counting begins with 0, so max id = num-1 for setiID in `echo $setiIDs`; do echo $listIDs | grep "\<$setiID\>" >/dev/null 2>&1 if [ $? -ne 0 ]; then # not yet bound: while (true) ; do echo $listCPUs | grep "\<$currCPU\>" >/dev/null 2>&1 if [ $? -eq 0 ]; then # already used for another, choose next currCPU=`expr $currCPU - 1` else break # found empty one fi done $bindcmd -b $currCPU $setiID currCPU=`expr $currCPU - 1` fi done fi