1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (C) 2021 Intel Corporation. 3# All rights reserved. 4 5function cleanup() { 6 rm -f "$SPDK_TEST_STORAGE/aiofile" 7} 8 9function reactor_is_busy_or_idle() { 10 local pid=$1 11 local idx=$2 12 local state=$3 13 14 if [[ $state != "busy" ]] && [[ $state != "idle" ]]; then 15 return 1 16 fi 17 18 if ! hash top; then 19 # Fail this test if top is missing from system. 20 return 1 21 fi 22 23 for ((j = 10; j != 0; j--)); do 24 top_reactor=$(top -bHn 1 -p $pid -w 256 | grep reactor_$idx) 25 cpu_rate=$(echo $top_reactor | sed -e 's/^\s*//g' | awk '{print $9}') 26 cpu_rate=${cpu_rate%.*} 27 28 if [[ $state = "busy" ]] && [[ $cpu_rate -lt 70 ]]; then 29 sleep 1 30 elif [[ $state = "idle" ]] && [[ $cpu_rate -gt 30 ]]; then 31 sleep 1 32 else 33 return 0 34 fi 35 done 36 37 if [[ $state = "busy" ]]; then 38 echo "cpu rate ${cpu_rate} of reactor $i probably is not busy polling" 39 else 40 echo "cpu rate ${cpu_rate} of reactor $i probably is not idle interrupt" 41 fi 42 43 return 1 44} 45 46function reactor_is_busy() { 47 reactor_is_busy_or_idle $1 $2 "busy" 48} 49 50function reactor_is_idle() { 51 reactor_is_busy_or_idle $1 $2 "idle" 52} 53 54function reactor_get_thread_ids() { 55 local reactor_cpumask=$1 56 local grep_str 57 58 reactor_cpumask=$((reactor_cpumask)) 59 jq_str='.threads|.[]|select(.cpumask == $reactor_cpumask)|.id' 60 61 # shellcheck disable=SC2005 62 echo "$($rpc_py thread_get_stats | jq --arg reactor_cpumask "$reactor_cpumask" "$jq_str")" 63 64} 65 66function setup_bdev_mem() { 67 "$rpc_py" <<- RPC 68 bdev_malloc_create -b Malloc0 32 512 69 bdev_malloc_create -b Malloc1 32 512 70 bdev_malloc_create -b Malloc2 32 512 71 RPC 72} 73 74function setup_bdev_aio() { 75 if [[ $(uname -s) != "FreeBSD" ]]; then 76 dd if=/dev/zero of="$SPDK_TEST_STORAGE/aiofile" bs=2048 count=5000 77 "$rpc_py" bdev_aio_create "$SPDK_TEST_STORAGE/aiofile" AIO0 2048 78 fi 79} 80