-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools_physical.sh
More file actions
146 lines (125 loc) · 3.03 KB
/
Copy pathtools_physical.sh
File metadata and controls
146 lines (125 loc) · 3.03 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# update parameters
PCI_PATH="03:00.1"
# fixed parameters
Pages=2048
HUGEPGSZ=`cat /proc/meminfo | grep Hugepagesize | cut -d : -f 2 | tr -d ' '`
#
# Loads vfio-pci.
#
load_vfio_pci_module()
{
modinfo vfio-pci > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "## ERROR: vfio-pci module not found in this kernel."
echo " Please make sure your kernel has VFIO support."
return 1
fi
echo $passwd | sudo -S modprobe vfio-pci
if [ $? -ne 0 ]; then
echo "## ERROR: Failed to load vfio-pci"
return 1
fi
}
#
# Creates hugepage filesystem.
#
create_mnt_huge()
{
echo "Creating /mnt/huge and mounting as hugetlbfs"
echo $passwd | sudo -S mkdir -p /mnt/huge
grep -s '/mnt/huge' /proc/mounts > /dev/null
if [ $? -ne 0 ] ; then
echo $passwd | sudo -S mount -t hugetlbfs nodev /mnt/huge
fi
}
#
# Removes hugepage filesystem.
#
remove_mnt_huge()
{
echo "Unmounting /mnt/huge and removing directory"
grep -s '/mnt/huge' /proc/mounts > /dev/null
if [ $? -eq 0 ] ; then
echo $passwd | sudo -S umount /mnt/huge
fi
if [ -d /mnt/huge ] ; then
echo $passwd | sudo -S rm -R /mnt/huge
fi
}
#
# Removes all reserved hugepages.
#
clear_huge_pages()
{
echo > .echo_tmp
for d in /sys/devices/system/node/node? ; do
echo "echo 0 > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
done
echo "Removing currently reserved hugepages"
echo $passwd | sudo -S sh .echo_tmp
rm -f .echo_tmp
remove_mnt_huge
}
#
# Creates hugepages on specific NUMA nodes.
#
set_numa_pages()
{
clear_huge_pages
echo > .echo_tmp
for d in /sys/devices/system/node/node? ; do
node=$(basename $d)
echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
done
echo "Reserving hugepages"
echo $passwd | sudo -S sh .echo_tmp
rm -f .echo_tmp
create_mnt_huge
}
#
# Uses dpdk-devbind.py to move devices to work with igb_uio
#
bind_devices_to_vfio_pci()
{
echo "Bind device to DPDK"
echo $passwd | sudo -S $RTE_SDK/usertools/dpdk-devbind.py -b vfio-pci $PCI_PATH
}
show_device() {
$RTE_SDK/usertools/dpdk-devbind.py --status
}
setup_dpdk() {
# insert Insert vfio_pci module
load_vfio_pci_module
# set hugepage mapping
set_numa_pages
# bind device
bind_devices_to_vfio_pci
}
bind_dpdk() {
bind_devices_to_vfio_pci
}
unbind_dpdk() {
echo $passwd | sudo -S ${RTE_SDK}/usertools/dpdk-devbind.py -u $PCI_PATH
echo $passwd | sudo -S ${RTE_SDK}/usertools/dpdk-devbind.py -b i40e $PCI_PATH
}
option="${1}"
case ${option} in
show_device)
show_device
;;
setup_dpdk)
setup_dpdk
;;
bind_dpdk)
bind_dpdk
;;
unbind_dpdk)
unbind_dpdk
;;
*) echo "usage:"
echo " ./tools.sh show_device: show device"
echo " ./tools.sh setup_dpdk: setup dpdk"
echo " ./tools.sh bind_dpdk: bind dpdk"
echo " ./tools.sh unbind_dpdk: unbind dpdk"
esac