-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetupnicirq.sh
69 lines (45 loc) · 1.41 KB
/
setupnicirq.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
if [ "x$1" == "x" ]; then
echo "Usage: $0 all"
exit 0
fi
CPUNUM=`cat /proc/cpuinfo | grep processor | wc -l`
NIC=$1
if [ "x$NIC" == "xall" ]; then
LOCALOFFSET=0
for nic in `ifconfig | grep "^[a-z]" | grep -v lo | awk {'print $1'} | tr "\n" " "`; do
if [ `ethtool -i $nic | grep bus | grep "0000" | wc -l` -eq 1 ]; then
MULTIIRQ=`cat /proc/interrupts | grep $nic | wc -l`
bash $0 $nic $LOCALOFFSET
let LOCALOFFSET=($LOCALOFFSET+$MULTIIRQ)%$CPUNUM
fi
done
exit 0
fi
if [ "x$2" == "x" ] || [ $2 -lt 0 ] || [ $2 -gt $CPUNUM ]; then
OFFSET=0
else
OFFSET=$2
fi
MULTIIRQ=`cat /proc/interrupts | grep $NIC | wc -l`
if [ $MULTIIRQ -eq 0 ]; then
echo "NIC $NIC not support MultiIRQ, exit."
exit 0
fi
NUMANODLIST=(`numactl --hardware | grep cpus | head -n 1 | awk -F: {'print $2'}`)
NUMANODS=${#NUMANODLIST[@]}
if [ $OFFSET -ge $NUMANODS ]; then
NUMANODLIST=(`numactl --hardware | grep cpus | head -n 2 | tail -n 1 | awk -F: {'print $2'}`)
OFFSET=$(($OFFSET-$NUMANODS))
NUMANODS=${#NUMANODLIST[@]}
fi
IRQS=(`cat /proc/interrupts | grep $NIC | awk -F: {'print $1'}`)
for ((i=0;i<${#IRQS[@]};i++)); do
let CUROFFSET=($OFFSET+$i)%$NUMANODS
cpu[$i]=${NUMANODLIST[$CUROFFSET]}
done
#echo ${cpu[@]} ${IRQS[@]}
for ((i=0;i<${#IRQS[@]};i++)); do
echo Setup $NIC irq ${IRQS[$i]} to cpu ${cpu[$i]}
echo ${cpu[$i]} > /proc/irq/${IRQS[$i]}/smp_affinity_list
done