scripts: factor out iter_pci helper functions
Add a new file, scripts/common.sh, that can be shared between not only autotest scripts, but also scripts/setup.sh, scripts/gen_nvme.sh, etc., and move the PCI iteration functions there. The iterators are also expanded to work identically for both dev_id and class_code on Linux and FreeBSD. Change-Id: I98423cd06242e78535f5da4fce82166812ea96a8 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/393416 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
581107c77a
commit
f0c2093477
44
scripts/common.sh
Normal file
44
scripts/common.sh
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Common shell utility functions
|
||||||
|
|
||||||
|
function iter_pci_class_code() {
|
||||||
|
local class="$(printf %02x $((0x$1)))"
|
||||||
|
local subclass="$(printf %02x $((0x$2)))"
|
||||||
|
local progif="$(printf %02x $((0x$3)))"
|
||||||
|
|
||||||
|
if hash lspci &>/dev/null; then
|
||||||
|
if [ "$progif" != "00" ]; then
|
||||||
|
lspci -mm -n -D | \
|
||||||
|
grep -i -- "-p${progif}" | \
|
||||||
|
awk -v cc="\"${class}${subclass}\"" -F " " \
|
||||||
|
'{if (cc ~ $2) print $1}' | tr -d '"'
|
||||||
|
else
|
||||||
|
lspci -mm -n -D | \
|
||||||
|
awk -v cc="\"${class}${subclass}\"" -F " " \
|
||||||
|
'{if (cc ~ $2) print $1}' | tr -d '"'
|
||||||
|
fi
|
||||||
|
elif hash pciconf &>/dev/null; then
|
||||||
|
addr=($(pciconf -l | grep -i "class=0x${class}${subclass}${progif}" | \
|
||||||
|
cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' '))
|
||||||
|
printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]}
|
||||||
|
else
|
||||||
|
echo "Missing PCI enumeration utility"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function iter_pci_dev_id() {
|
||||||
|
local ven_id="$(printf %04x $((0x$1)))"
|
||||||
|
local dev_id="$(printf %04x $((0x$2)))"
|
||||||
|
|
||||||
|
if hash lspci &>/dev/null; then
|
||||||
|
lspci -mm -n -D | awk -v ven="\"$ven_id\"" -v dev="\"${dev_id}\"" -F " " \
|
||||||
|
'{if (ven ~ $3 && dev ~ $4) print $1}' | tr -d '"'
|
||||||
|
elif hash pciconf &>/dev/null; then
|
||||||
|
addr=($(pciconf -l | grep -i "chip=0x${dev_id}${ven_id}" | \
|
||||||
|
cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' '))
|
||||||
|
printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]}
|
||||||
|
else
|
||||||
|
echo "Missing PCI enumeration utility"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
@ -2,17 +2,10 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
case `uname` in
|
rootdir=$(readlink -f $(dirname $0))/..
|
||||||
FreeBSD)
|
source "$rootdir/scripts/common.sh"
|
||||||
bdfs=$(pciconf -l | grep "class=0x010802" | awk -F: ' {printf "0000:%02X:%02X.%X\n", $2, $3, $4}')
|
|
||||||
;;
|
bdfs=$(iter_pci_class_code 01 08 02)
|
||||||
Linux)
|
|
||||||
bdfs=$(lspci -mm -n | grep 0108 | tr -d '"' | awk -F " " '{print "0000:"$1}')
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "[Nvme]"
|
echo "[Nvme]"
|
||||||
i=0
|
i=0
|
||||||
|
@ -3,17 +3,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
rootdir=$(readlink -f $(dirname $0))/..
|
rootdir=$(readlink -f $(dirname $0))/..
|
||||||
|
source "$rootdir/scripts/common.sh"
|
||||||
function linux_iter_pci_class_code {
|
|
||||||
# Argument is the class code
|
|
||||||
lspci -mm -n -D | awk -v cc="\"$1\"" -F " " '{if (cc ~ $2) print $1}' | tr -d '"'
|
|
||||||
}
|
|
||||||
|
|
||||||
function linux_iter_pci_dev_id {
|
|
||||||
# Argument 1 is the vendor id
|
|
||||||
# Argument 2 is the device id
|
|
||||||
lspci -mm -n -D | awk -v ven="\"$1\"" -v dev="\"$2\"" -F " " '{if (ven ~ $3 && dev ~ $4) print $1}' | tr -d '"'
|
|
||||||
}
|
|
||||||
|
|
||||||
function linux_bind_driver() {
|
function linux_bind_driver() {
|
||||||
bdf="$1"
|
bdf="$1"
|
||||||
@ -90,7 +80,7 @@ function configure_linux_pci {
|
|||||||
|
|
||||||
# NVMe
|
# NVMe
|
||||||
modprobe $driver_name || true
|
modprobe $driver_name || true
|
||||||
for bdf in $(linux_iter_pci_class_code 0108); do
|
for bdf in $(iter_pci_class_code 01 08 02); do
|
||||||
blkname=''
|
blkname=''
|
||||||
get_nvme_name_from_bdf "$bdf" blkname
|
get_nvme_name_from_bdf "$bdf" blkname
|
||||||
if [ "$blkname" != "" ]; then
|
if [ "$blkname" != "" ]; then
|
||||||
@ -112,7 +102,7 @@ function configure_linux_pci {
|
|||||||
| awk -F"x" '{print $2}' > $TMP
|
| awk -F"x" '{print $2}' > $TMP
|
||||||
|
|
||||||
for dev_id in `cat $TMP`; do
|
for dev_id in `cat $TMP`; do
|
||||||
for bdf in $(linux_iter_pci_dev_id 8086 $dev_id); do
|
for bdf in $(iter_pci_dev_id 8086 $dev_id); do
|
||||||
linux_bind_driver "$bdf" "$driver_name"
|
linux_bind_driver "$bdf" "$driver_name"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@ -125,7 +115,7 @@ function configure_linux_pci {
|
|||||||
| awk -F"x" '{print $2}' > $TMP
|
| awk -F"x" '{print $2}' > $TMP
|
||||||
|
|
||||||
for dev_id in `cat $TMP`; do
|
for dev_id in `cat $TMP`; do
|
||||||
for bdf in $(linux_iter_pci_dev_id 1af4 $dev_id); do
|
for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
|
||||||
linux_bind_driver "$bdf" "$driver_name"
|
linux_bind_driver "$bdf" "$driver_name"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@ -196,7 +186,7 @@ function reset_linux_pci {
|
|||||||
lsmod | grep nvme > /dev/null
|
lsmod | grep nvme > /dev/null
|
||||||
driver_loaded=$?
|
driver_loaded=$?
|
||||||
set -e
|
set -e
|
||||||
for bdf in $(linux_iter_pci_class_code 0108); do
|
for bdf in $(iter_pci_class_code 01 08 02); do
|
||||||
if [ $driver_loaded -eq 0 ]; then
|
if [ $driver_loaded -eq 0 ]; then
|
||||||
linux_bind_driver "$bdf" nvme
|
linux_bind_driver "$bdf" nvme
|
||||||
else
|
else
|
||||||
@ -215,7 +205,7 @@ function reset_linux_pci {
|
|||||||
driver_loaded=$?
|
driver_loaded=$?
|
||||||
set -e
|
set -e
|
||||||
for dev_id in `cat $TMP`; do
|
for dev_id in `cat $TMP`; do
|
||||||
for bdf in $(linux_iter_pci_dev_id 8086 $dev_id); do
|
for bdf in $(iter_pci_dev_id 8086 $dev_id); do
|
||||||
if [ $driver_loaded -eq 0 ]; then
|
if [ $driver_loaded -eq 0 ]; then
|
||||||
linux_bind_driver "$bdf" ioatdma
|
linux_bind_driver "$bdf" ioatdma
|
||||||
else
|
else
|
||||||
@ -237,7 +227,7 @@ function reset_linux_pci {
|
|||||||
# underscore vs. dash right in the virtio_scsi name.
|
# underscore vs. dash right in the virtio_scsi name.
|
||||||
modprobe virtio-pci || true
|
modprobe virtio-pci || true
|
||||||
for dev_id in `cat $TMP`; do
|
for dev_id in `cat $TMP`; do
|
||||||
for bdf in $(linux_iter_pci_dev_id 1af4 $dev_id); do
|
for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
|
||||||
linux_bind_driver "$bdf" virtio-pci
|
linux_bind_driver "$bdf" virtio-pci
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@ -260,7 +250,7 @@ function status_linux {
|
|||||||
echo "NVMe devices"
|
echo "NVMe devices"
|
||||||
|
|
||||||
echo -e "BDF\t\tNuma Node\tDriver name\t\tDevice name"
|
echo -e "BDF\t\tNuma Node\tDriver name\t\tDevice name"
|
||||||
for bdf in $(linux_iter_pci_class_code 0108); do
|
for bdf in $(iter_pci_class_code 01 08 02); do
|
||||||
driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
|
driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
|
||||||
node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
|
node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
|
||||||
if [ "$driver" = "nvme" ]; then
|
if [ "$driver" = "nvme" ]; then
|
||||||
@ -278,7 +268,7 @@ function status_linux {
|
|||||||
| awk -F"x" '{print $2}'`
|
| awk -F"x" '{print $2}'`
|
||||||
echo -e "BDF\t\tNuma Node\tDriver Name"
|
echo -e "BDF\t\tNuma Node\tDriver Name"
|
||||||
for dev_id in $TMP; do
|
for dev_id in $TMP; do
|
||||||
for bdf in $(linux_iter_pci_dev_id 8086 $dev_id); do
|
for bdf in $(iter_pci_dev_id 8086 $dev_id); do
|
||||||
driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
|
driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
|
||||||
node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
|
node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
|
||||||
echo -e "$bdf\t$node\t\t$driver"
|
echo -e "$bdf\t$node\t\t$driver"
|
||||||
@ -292,7 +282,7 @@ function status_linux {
|
|||||||
| awk -F"x" '{print $2}'`
|
| awk -F"x" '{print $2}'`
|
||||||
echo -e "BDF\t\tNuma Node\tDriver Name"
|
echo -e "BDF\t\tNuma Node\tDriver Name"
|
||||||
for dev_id in $TMP; do
|
for dev_id in $TMP; do
|
||||||
for bdf in $(linux_iter_pci_dev_id 1af4 $dev_id); do
|
for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
|
||||||
driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
|
driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
|
||||||
node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
|
node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
|
||||||
echo -e "$bdf\t$node\t\t$driver"
|
echo -e "$bdf\t$node\t\t$driver"
|
||||||
|
@ -4,12 +4,9 @@ set -e
|
|||||||
|
|
||||||
testdir=$(readlink -f $(dirname $0))
|
testdir=$(readlink -f $(dirname $0))
|
||||||
rootdir=$(readlink -f $testdir/../../..)
|
rootdir=$(readlink -f $testdir/../../..)
|
||||||
|
source $rootdir/scripts/common.sh
|
||||||
source $rootdir/scripts/autotest_common.sh
|
source $rootdir/scripts/autotest_common.sh
|
||||||
|
|
||||||
function linux_iter_pci {
|
|
||||||
lspci -mm -n -D | grep $1 | tr -d '"' | awk -F " " '{print $1}'
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_nvme_name_from_bdf {
|
function get_nvme_name_from_bdf {
|
||||||
lsblk -d --output NAME
|
lsblk -d --output NAME
|
||||||
if ! [ $(lsblk -d --output NAME | grep "^nvme") ]; then
|
if ! [ $(lsblk -d --output NAME | grep "^nvme") ]; then
|
||||||
@ -44,7 +41,7 @@ if [ `uname` = Linux ]; then
|
|||||||
#
|
#
|
||||||
# note: more work probably needs to be done to properly handle devices with multiple
|
# note: more work probably needs to be done to properly handle devices with multiple
|
||||||
# namespaces
|
# namespaces
|
||||||
for bdf in $(linux_iter_pci 0108); do
|
for bdf in $(iter_pci_class_code 01 08 02); do
|
||||||
get_nvme_name_from_bdf "$bdf" blkname
|
get_nvme_name_from_bdf "$bdf" blkname
|
||||||
if [ "$blkname" != "" ]; then
|
if [ "$blkname" != "" ]; then
|
||||||
mountpoints=$(lsblk /dev/$blkname --output MOUNTPOINT -n | wc -w)
|
mountpoints=$(lsblk /dev/$blkname --output MOUNTPOINT -n | wc -w)
|
||||||
@ -107,7 +104,7 @@ fi
|
|||||||
|
|
||||||
timing_enter identify
|
timing_enter identify
|
||||||
$rootdir/examples/nvme/identify/identify -i 0
|
$rootdir/examples/nvme/identify/identify -i 0
|
||||||
for bdf in $(linux_iter_pci 0108); do
|
for bdf in $(iter_pci_class_code 01 08 02); do
|
||||||
$rootdir/examples/nvme/identify/identify -r "trtype:PCIe traddr:${bdf}" -i 0
|
$rootdir/examples/nvme/identify/identify -r "trtype:PCIe traddr:${bdf}" -i 0
|
||||||
done
|
done
|
||||||
timing_exit identify
|
timing_exit identify
|
||||||
@ -168,7 +165,7 @@ PLUGIN_DIR=$rootdir/examples/nvme/fio_plugin
|
|||||||
|
|
||||||
if [ -d /usr/src/fio ]; then
|
if [ -d /usr/src/fio ]; then
|
||||||
timing_enter fio_plugin
|
timing_enter fio_plugin
|
||||||
for bdf in $(linux_iter_pci 0108); do
|
for bdf in $(iter_pci_class_code 01 08 02); do
|
||||||
# Only test when ASAN is not enabled. If ASAN is enabled, we cannot test.
|
# Only test when ASAN is not enabled. If ASAN is enabled, we cannot test.
|
||||||
if [ $SPDK_RUN_ASAN -eq 0 ]; then
|
if [ $SPDK_RUN_ASAN -eq 0 ]; then
|
||||||
LD_PRELOAD=$PLUGIN_DIR/fio_plugin /usr/src/fio/fio $PLUGIN_DIR/example_config.fio --filename="trtype=PCIe traddr=${bdf//:/.} ns=1"
|
LD_PRELOAD=$PLUGIN_DIR/fio_plugin /usr/src/fio/fio $PLUGIN_DIR/example_config.fio --filename="trtype=PCIe traddr=${bdf//:/.} ns=1"
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
rootdir=$(readlink -f $(dirname $0))/../../..
|
||||||
|
source "$rootdir/scripts/common.sh"
|
||||||
|
|
||||||
BASE_DIR=$(readlink -f $(dirname $0))
|
BASE_DIR=$(readlink -f $(dirname $0))
|
||||||
[[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../../../ && pwd)"
|
[[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../../../ && pwd)"
|
||||||
[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $BASE_DIR/../common && pwd)"
|
[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $BASE_DIR/../common && pwd)"
|
||||||
@ -91,7 +95,7 @@ while getopts 'xh-:' optchar; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "INFO: Get NVMe disks:"
|
echo "INFO: Get NVMe disks:"
|
||||||
nvmes=($(lspci -mm -n | grep 0108 | tr -d '"' | awk -F " " '{print "0000:"$1}'))
|
nvmes=($(iter_pci_class_code 01 08 02))
|
||||||
|
|
||||||
if [[ -z $max_disks ]]; then
|
if [[ -z $max_disks ]]; then
|
||||||
max_disks=${#nvmes[@]}
|
max_disks=${#nvmes[@]}
|
||||||
|
Loading…
Reference in New Issue
Block a user