]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/scripts/run_with_dpdk.sh
import quincy beta 17.1.0
[ceph.git] / ceph / src / seastar / scripts / run_with_dpdk.sh
1 #!/bin/bash
2 # !
3 # ! Usage: ./prepare_dpdk_env.sh <NIC to use> <number of huge pages per NUMA Node> <command to execute> [command parameters]
4 # !
5 # ! Prepares the DPDK environment (binds a given NIC to UIO, allocates the required
6 # ! number of huge pages) and executes the given command in it.
7 # ! After the command terminates the original environment is restored apart from
8 # ! huge pages, that remain allocated.
9 # !
10
11 usage()
12 {
13 cat $0 | grep ^"# !" | cut -d"!" -f2-
14 }
15
16 #
17 # check_stat_and_exit <error message>
18 #
19 check_stat_and_exit()
20 {
21 if [[ $? -ne 0 ]]; then
22 echo $@
23 exit 1
24 fi
25 }
26
27 rollback()
28 {
29 echo "Binding $NIC($BDF) back to $DRIVER..."
30 $SCRIPTS_DIR/dpdk_nic_bind.py -u $BDF
31 $SCRIPTS_DIR/dpdk_nic_bind.py -b $DRIVER $BDF
32 }
33
34 check_stat_and_rollback()
35 {
36 if [[ $? -ne 0 ]]; then
37 echo $@
38 rollback
39 exit 1
40 fi
41 }
42
43 # Check number of parameters
44 if [[ $# -lt 3 ]]; then
45 usage
46 exit 1
47 fi
48
49 NIC=$1
50 shift
51 NUM_HUGE_PAGES_PER_NODE=$1
52 shift
53 SCRIPTS_DIR=`dirname $0`
54
55
56 ifconfig $NIC down
57 check_stat_and_exit "Failed to shut down $NIC. Is $NIC present? Are your permissions sufficient?"
58
59 DRIVER=`ethtool -i $NIC | grep driver | cut -d":" -f2- | tr -d ' '`
60 BDF=`ethtool -i $NIC | grep bus-info | cut -d":" -f2- | tr -d ' '`
61
62 # command to execute
63 CMD=$@
64
65 echo "Binding $NIC($BDF) to uio_pci_generic..."
66 $SCRIPTS_DIR/dpdk_nic_bind.py -u $BDF
67 check_stat_and_exit
68 $SCRIPTS_DIR/dpdk_nic_bind.py -b uio_pci_generic $BDF
69 check_stat_and_rollback
70
71 echo "Allocating $NUM_HUGE_PAGES_PER_NODE 2MB huge pages on each NUMA Node:"
72 for d in /sys/devices/system/node/node? ; do
73 echo $NUM_HUGE_PAGES_PER_NODE > $d/hugepages/hugepages-2048kB/nr_hugepages
74 check_stat_and_rollback
75 cur_node=`basename $d`
76 echo "...$cur_node done..."
77 done
78
79 mkdir -p /mnt/huge
80 check_stat_and_rollback
81
82 grep -s '/mnt/huge' /proc/mounts > /dev/null
83 if [[ $? -ne 0 ]] ; then
84 echo "Mounting hugetlbfs at /mnt/huge..."
85 mount -t hugetlbfs nodev /mnt/huge
86 check_stat_and_rollback
87 fi
88
89 # Run scylla
90 echo "Running: $CMD"
91 $CMD
92 ret=$?
93
94 # Revert the NIC binding
95 rollback
96
97 exit $ret
98