summaryrefslogtreecommitdiffstats
path: root/src/seastar/scripts/run_with_dpdk.sh
blob: e00fbc29f1aa9829e25942e8049f7dac118aa21f (plain)
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
#!/bin/bash
# !
# ! Usage: ./prepare_dpdk_env.sh <NIC to use> <number of huge pages per NUMA Node> <command to execute> [command parameters]
# !
# ! Prepares the DPDK environment (binds a given NIC to UIO, allocates the required
# ! number of huge pages) and executes the given command in it.
# ! After the command terminates the original environment is restored apart from
# ! huge pages, that remain allocated.
# !

usage()
{
    cat $0 | grep ^"# !" | cut -d"!" -f2-
}

#
#  check_stat_and_exit <error message>
#
check_stat_and_exit()
{
    if [[ $? -ne 0 ]]; then
        echo $@
        exit 1
    fi
}

rollback()
{
    echo "Binding $NIC($BDF) back to $DRIVER..."
    $SCRIPTS_DIR/dpdk_nic_bind.py -u $BDF
    $SCRIPTS_DIR/dpdk_nic_bind.py -b $DRIVER $BDF
}

check_stat_and_rollback()
{
    if [[ $? -ne 0 ]]; then
        echo $@
        rollback
        exit 1
    fi
}

# Check number of parameters
if [[ $# -lt 3 ]]; then
    usage
    exit 1
fi

NIC=$1
shift
NUM_HUGE_PAGES_PER_NODE=$1
shift
SCRIPTS_DIR=`dirname $0`


ifconfig $NIC down
check_stat_and_exit "Failed to shut down $NIC. Is $NIC present? Are your permissions sufficient?"

DRIVER=`ethtool -i $NIC | grep driver | cut -d":" -f2- | tr -d ' '`
BDF=`ethtool -i $NIC | grep bus-info | cut -d":" -f2- |  tr -d ' '`

# command to execute
CMD=$@

echo "Binding $NIC($BDF) to uio_pci_generic..."
$SCRIPTS_DIR/dpdk_nic_bind.py -u $BDF
check_stat_and_exit
$SCRIPTS_DIR/dpdk_nic_bind.py -b uio_pci_generic $BDF
check_stat_and_rollback

echo "Allocating $NUM_HUGE_PAGES_PER_NODE 2MB huge pages on each NUMA Node:"
for d in /sys/devices/system/node/node? ; do
    echo $NUM_HUGE_PAGES_PER_NODE > $d/hugepages/hugepages-2048kB/nr_hugepages
    check_stat_and_rollback
    cur_node=`basename $d`
    echo "...$cur_node done..."
done

mkdir -p /mnt/huge
check_stat_and_rollback

grep -s '/mnt/huge' /proc/mounts > /dev/null
if [[ $? -ne 0 ]] ; then
    echo "Mounting hugetlbfs at /mnt/huge..."
    mount -t hugetlbfs nodev /mnt/huge
    check_stat_and_rollback
fi

# Run scylla
echo "Running: $CMD"
$CMD
ret=$?

# Revert the NIC binding
rollback

exit $ret