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