-
Notifications
You must be signed in to change notification settings - Fork 2
/
set_irq_affinity.sh
executable file
·83 lines (74 loc) · 1.9 KB
/
set_irq_affinity.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /bin/bash
if [ -z $1 ]; then
echo "usage: $0 <interface or IB device> [2nd interface or IB device]"
exit 1
fi
source common_irq_affinity.sh
CORES=$((`cat /proc/cpuinfo | grep processor | tail -1 | awk '{print $3}'`+1))
hop=1
INT1=$1
INT2=$2
if [ -z $INT2 ]; then
limit_1=$CORES
echo "---------------------------------------"
echo "Optimizing IRQs for Single port traffic"
echo "---------------------------------------"
else
echo "-------------------------------------"
echo "Optimizing IRQs for Dual port traffic"
echo "-------------------------------------"
limit_1=$((CORES/2))
limit_2=$CORES
IRQS_2=$( get_irq_list $INT2 )
if [ -z "$IRQS_2" ] ; then
echo No IRQs found for $INT2.
exit 1
fi
fi
IRQS_1=$( get_irq_list $INT1 )
if [ -z "$IRQS_1" ] ; then
echo No IRQs found for $INT1.
else
echo Discovered irqs for $INT1: $IRQS_1
core_id=0
for IRQ in $IRQS_1
do
if is_affinity_hint_set $IRQ ; then
affinity=$(cat /proc/irq/$IRQ/affinity_hint)
set_irq_affinity $IRQ $affinity
echo Assign irq $IRQ to its affinity_hint $affinity
else
echo Assign irq $IRQ core_id $core_id
affinity=$( core_to_affinity $core_id )
set_irq_affinity $IRQ $affinity
core_id=$(( core_id + $hop ))
if [ $core_id -ge $limit_1 ] ; then core_id=0; fi
fi
done
fi
echo
if [ "$INT2" != "" ]; then
IRQS_2=$( get_irq_list $INT2 )
if [ -z "$IRQS_2" ]; then
echo No IRQs found for $INT2.
exit 1
fi
echo Discovered irqs for $INT2: $IRQS_2
core_id=$limit_1
for IRQ in $IRQS_2
do
if is_affinity_hint_set $IRQ ; then
affinity=$(cat /proc/irq/$IRQ/affinity_hint)
set_irq_affinity $IRQ $affinity
echo Assign irq $IRQ to its affinity_hint $affinity
else
echo Assign irq $IRQ core_id $core_id
affinity=$( core_to_affinity $core_id )
set_irq_affinity $IRQ $affinity
core_id=$(( core_id + $hop ))
if [ $core_id -ge $limit_2 ] ; then core_id=$limit_1; fi
fi
done
fi
echo
echo done.