1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (C) 2021 Intel Corporation. 3# All rights reserved. 4 5testdir=$(readlink -f $(dirname $0)) 6rootdir=$(readlink -f $testdir/../..) 7source $rootdir/test/common/autotest_common.sh 8 9rpc_py="$rootdir/scripts/rpc.py" 10 11r0_mask=0x1 12r1_mask=0x2 13r2_mask=0x4 14 15cpu_server_mask=0x07 16rpc_server_addr="/var/tmp/spdk.sock" 17 18function cleanup() { 19 rm -f "$SPDK_TEST_STORAGE/aiofile" 20} 21 22function start_intr_tgt() { 23 local rpc_addr="${1:-$rpc_server_addr}" 24 local cpu_mask="${2:-$cpu_server_mask}" 25 26 "$SPDK_EXAMPLE_DIR/interrupt_tgt" -m $cpu_mask -r $rpc_addr -E -g & 27 intr_tgt_pid=$! 28 trap 'killprocess "$intr_tgt_pid"; cleanup; exit 1' SIGINT SIGTERM EXIT 29 waitforlisten "$intr_tgt_pid" $rpc_addr 30} 31 32function reactor_is_busy_or_idle() { 33 local pid=$1 34 local idx=$2 35 local state=$3 36 37 if [[ $state != "busy" ]] && [[ $state != "idle" ]]; then 38 return 1 39 fi 40 41 if ! hash top; then 42 # Fail this test if top is missing from system. 43 return 1 44 fi 45 46 for ((j = 10; j != 0; j--)); do 47 top_reactor=$(top -bHn 1 -p $pid -w 256 | grep reactor_$idx) 48 cpu_rate=$(echo $top_reactor | sed -e 's/^\s*//g' | awk '{print $9}') 49 cpu_rate=${cpu_rate%.*} 50 51 if [[ $state = "busy" ]] && [[ $cpu_rate -lt 70 ]]; then 52 sleep 1 53 elif [[ $state = "idle" ]] && [[ $cpu_rate -gt 30 ]]; then 54 sleep 1 55 else 56 return 0 57 fi 58 done 59 60 if [[ $state = "busy" ]]; then 61 echo "cpu rate ${cpu_rate} of reactor $i probably is not busy polling" 62 else 63 echo "cpu rate ${cpu_rate} of reactor $i probably is not idle interrupt" 64 fi 65 66 return 1 67} 68 69function reactor_is_busy() { 70 reactor_is_busy_or_idle $1 $2 "busy" 71} 72 73function reactor_is_idle() { 74 reactor_is_busy_or_idle $1 $2 "idle" 75} 76 77function reactor_get_thread_ids() { 78 local reactor_cpumask=$1 79 local grep_str 80 81 reactor_cpumask=$((reactor_cpumask)) 82 jq_str='.threads|.[]|select(.cpumask == $reactor_cpumask)|.id' 83 84 # shellcheck disable=SC2005 85 echo "$($rpc_py thread_get_stats | jq --arg reactor_cpumask "$reactor_cpumask" "$jq_str")" 86 87} 88 89function setup_bdev_mem() { 90 "$rpc_py" <<- RPC 91 bdev_malloc_create -b Malloc0 32 512 92 bdev_malloc_create -b Malloc1 32 512 93 bdev_malloc_create -b Malloc2 32 512 94 RPC 95} 96 97function setup_bdev_aio() { 98 if [[ $(uname -s) != "FreeBSD" ]]; then 99 dd if=/dev/zero of="$SPDK_TEST_STORAGE/aiofile" bs=2048 count=5000 100 "$rpc_py" bdev_aio_create "$SPDK_TEST_STORAGE/aiofile" AIO0 2048 101 fi 102} 103