1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2021 Intel Corporation 4# All rights reserved. 5# 6testdir=$(readlink -f $(dirname $0)) 7rootdir=$(readlink -f $testdir/../..) 8source $rootdir/test/common/autotest_common.sh 9source $testdir/interrupt_common.sh 10 11export PYTHONPATH=$PYTHONPATH:$rootdir/examples/interrupt_tgt 12 13function reactor_set_intr_mode() { 14 local spdk_pid=$1 15 local without_thd=$2 16 17 thd0_ids=($(reactor_get_thread_ids $r0_mask)) 18 thd2_ids=($(reactor_get_thread_ids $r2_mask)) 19 20 # Number of thd0_ids shouldn't be zero 21 if [[ ${#thd0_ids[*]} -eq 0 ]]; then 22 echo "spdk_thread is expected in reactor 0." 23 return 1 24 else 25 echo "spdk_thread ids are ${thd0_ids[*]} on reactor0." 26 fi 27 28 # CPU utilization of reactor 0~2 should be idle 29 for i in {0..2}; do 30 reactor_is_idle $spdk_pid $i 31 done 32 33 if [ "$without_thd"x != x ]; then 34 # Schedule all spdk_threads to reactor 1 35 for i in "${thd0_ids[@]}"; do 36 $rpc_py thread_set_cpumask -i $i -m $r1_mask 37 done 38 for i in "${thd2_ids[@]}"; do 39 $rpc_py thread_set_cpumask -i $i -m $r1_mask 40 done 41 fi 42 # Set reactor 0 and 2 to be poll mode 43 $rpc_py --plugin interrupt_plugin reactor_set_interrupt_mode 0 -d 44 $rpc_py --plugin interrupt_plugin reactor_set_interrupt_mode 2 -d 45 # CPU utilization of reactor 0 and 2 should be busy 46 for i in 0 2; do 47 reactor_is_busy $spdk_pid $i 48 done 49 50 # Set reactor 2 back to intr mode 51 $rpc_py --plugin interrupt_plugin reactor_set_interrupt_mode 2 52 if [ "$without_thd"x != x ]; then 53 # Schedule spdk_threads in thd2_ids back to reactor 2 54 for i in "${thd2_ids[@]}"; do 55 $rpc_py thread_set_cpumask -i $i -m $r2_mask 56 done 57 fi 58 # CPU utilization of reactor 2 should be idle 59 reactor_is_idle $spdk_pid 2 60 61 # Set reactor 0 back to intr mode 62 $rpc_py --plugin interrupt_plugin reactor_set_interrupt_mode 0 63 if [ "$without_thd"x != x ]; then 64 # Schedule spdk_threads in thd2_ids back to reactor 0 65 for i in "${thd0_ids[@]}"; do 66 $rpc_py thread_set_cpumask -i $i -m $r0_mask 67 done 68 fi 69 # CPU utilization of reactor 0 should be idle 70 reactor_is_idle $spdk_pid 0 71 72 return 0 73} 74 75function reactor_set_mode_without_threads() { 76 reactor_set_intr_mode $1 "without_thd" 77 return 0 78} 79 80function reactor_set_mode_with_threads() { 81 reactor_set_intr_mode $1 82 return 0 83} 84 85# Set reactors with intr_tgt without spdk_thread 86start_intr_tgt 87setup_bdev_mem 88setup_bdev_aio 89 90reactor_set_mode_without_threads $intr_tgt_pid 91 92trap - SIGINT SIGTERM EXIT 93killprocess $intr_tgt_pid 94cleanup 95 96# Set reactors with intr_tgt with spdk_thread 97start_intr_tgt 98setup_bdev_mem 99setup_bdev_aio 100 101reactor_set_mode_with_threads $intr_tgt_pid 102 103trap - SIGINT SIGTERM EXIT 104killprocess $intr_tgt_pid 105cleanup 106