Skip to content

Commit

Permalink
idxd: Add cases for idxd interrupt test in Host OS
Browse files Browse the repository at this point in the history
Signed-off-by: Rex Zhang <[email protected]>
  • Loading branch information
zhangl6 committed Mar 6, 2024
1 parent 03acb5f commit 6bfe1ef
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
1 change: 0 additions & 1 deletion idxd/intr.guest_test_executor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ source ../guest-test/test_params.py
###################### Do Works ######################
## common works example ##
cd "$(dirname "$0")" 2>/dev/null || exit 1
# shellcheck source=../.env
source ../.env
source ../common/common.sh

Expand Down
127 changes: 127 additions & 0 deletions idxd/intr.host_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash -Ex
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2024 Intel Corporation

# @desc This script verify idxd interrupts
# @returns Fail the test if return code is non-zero

cd "$(dirname "$0")" 2>/dev/null || exit 1
source ../.env
source ../common/common.sh

# helper function
usage() {
cat <<-EOF
usage: ./${0##*/}
-m workqueue mode, dedicated or shared
-i times of iteriration
-t number of thread
-h HELP info
EOF
}

while getopts :m:i:t:h arg; do
case $arg in
m)
wq_mode=$OPTARG
;;
i)
iterations=$OPTARG
;;
t)
threads=$OPTARG
;;
h)
usage && exit 0
;;
\?)
usage
die "Invalid Option -$OPTARG"
;;
:)
usage
die "Option -$OPTARG requires an argument."
;;
esac
done

./remove_iaa_crypto.sh
rmmod idxd_vdev
if ! rmmod idxd;
then
die "Faile to rmmod idxd"
fi
modprobe idxd

# parse dsa0 pcie bus:device.function
domain=$(readlink /sys/bus/dsa/devices/dsa0 | awk -F '/' '{print $(NF - 1)}' | awk -F ':' '{print $1}')
bus=$(readlink /sys/bus/dsa/devices/dsa0 | awk -F '/' '{print $(NF - 1)}' | awk -F ':' '{print $2}')
dev_func=$(readlink /sys/bus/dsa/devices/dsa0 | awk -F '/' '{print $(NF - 1)}' | awk -F ':' '{print $3}')
dbdf="$domain:$bus:$dev_func"
bdf="$bus:$dev_func"

# turn on and clear the trace event for irq vector
echo > /sys/kernel/debug/tracing/trace
echo 1 > /sys/kernel/debug/tracing/events/irq_vectors/vector_config/enable

# config and enable work queue
if [ "$wq_mode" = "dedicated" ]; then
./accel_config.sh config-wq --group-id=0 --mode="dedicated" --name="wq0.0" --type="kernel" --driver-name="dmaengine" --priority=10 --wq-size=16 --block-on-fault=1 dsa0/wq0.0
elif [ "$wq_mode" = "shared" ]; then
./accel_config.sh config-wq --group-id=0 --mode="shared" --name="wq0.0" --type="kernel" --driver-name="dmaengine" --priority=10 --wq-size=16 --block-on-fault=1 --threshold=16 dsa0/wq0.0
else
die "Unknown wq mode: $wq_mode"
fi
./accel_config.sh config-engine dsa0/engine0.0 --group-id=0
./accel_config.sh enable-device dsa0
./accel_config.sh enable-wq dsa0/wq0.0

# parse the dynamically allocated irq number, vector number, cpu index, lapic index and the value in interrupt remapping table
irq_assigned=$(tail -n1 /sys/kernel/debug/tracing/trace | awk -F ' ' '{print $6}' | awk -F '=' '{print $2}')
vector_assigned=$(tail -n1 /sys/kernel/debug/tracing/trace | awk -F ' ' '{print $7}' | awk -F '=' '{print $2}')
cpu_assigned=$(tail -n1 /sys/kernel/debug/tracing/trace | awk -F ' ' '{print $8}' | awk -F '=' '{print $2}')
lapic_assigned=$(tail -n1 /sys/kernel/debug/tracing/trace | awk -F ' ' '{print $9}' | awk -F 'x' '{print $2}')
lapic_assigned=${lapic_assigned:2}
vector_in_irte=$(grep "$bdf $lapic_assigned" /sys/kernel/debug/iommu/intel/ir_translation_struct | awk -F ' ' '{print $4}')
vector_in_irte="0x$vector_in_irte"
vector_in_irte=$((vector_in_irte)) # hex to decimal

# do dmatest to generate interrupts
modprobe dmatest
echo 2000 > /sys/module/dmatest/parameters/timeout
echo "$iterations" > /sys/module/dmatest/parameters/iterations
echo "$threads" > /sys/module/dmatest/parameters/threads_per_chan
echo "" > /sys/module/dmatest/parameters/channel
echo 0 > /sys/module/dmatest/parameters/polled
echo 1 > /sys/module/dmatest/parameters/run
cat /sys/module/dmatest/parameters/wait

# parse the actual irq number and count
irq_num=$(grep "$dbdf" /proc/interrupts | grep "idxd-portal" | awk -F ' ' '{print $1}' | awk -F ':' '{print $1}')
irq_count=$(grep "$dbdf" /proc/interrupts | grep "idxd-portal" | awk -F ' ' -v n=$((cpu_assigned+2)) '{print $n}')

# unload and disable work queue
rmmod dmatest
./accel_config.sh disable-wq dsa0/wq0.0
./accel_config.sh disable-device dsa0

# turn off and clear the trace event for irq vector
echo 0 > /sys/kernel/debug/tracing/events/irq_vectors/vector_config/enable
echo > /sys/kernel/debug/tracing/trace

# check result
if [ "$vector_assigned" != "$vector_in_irte" ]; then
die "allocated vector $vector_assigned is different with $vector_in_irte in interrupt remapping table"
fi

if [ "$irq_assigned" != "$irq_num" ]; then
die "allocated irq $irq_assigned is different with $irq_num"
fi

if [ "$irq_count" != "$iterations" ]; then
die "actual irq count $irq_count is not $iterations"
fi

echo "$wq_mode wq: intr test passed!"

exit 0
13 changes: 13 additions & 0 deletions idxd/remove_iaa_crypto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

iaa_dev_id="0cfe"
num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)

for ((i = 1; i < num_iaa * 2; i += 2)); do
echo disable wq iax${i}/wq${i}.0
accel-config disable-wq iax${i}/wq${i}.0
echo disable iaa iax${i}
accel-config disable-device iax${i}
done

rmmod iaa_crypto
4 changes: 4 additions & 0 deletions idxd/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./intr.host_test.sh -m dedicated -i 10 -t 1
./intr.host_test.sh -m shared -i 10 -t 1
./intr.host_test.sh -m dedicated -i 1000000 -t 1
./intr.host_test.sh -m shared -i 1000000 -t 1

0 comments on commit 6bfe1ef

Please sign in to comment.