1#!/usr/bin/env bash 2 3testdir=$(readlink -f "$(dirname "$0")") 4rootdir=$(readlink -f "$testdir/../../") 5 6source "$rootdir/test/common/autotest_common.sh" 7source "$testdir/common.sh" 8 9trap 'killprocess "$spdk_pid"' EXIT 10 11declare -a cpus=() 12declare -a cpus_to_collect=() 13 14fold_list_onto_array cpus $(parse_cpu_list <(echo "$spdk_cpus_csv")) 15# Normalize the indexes 16cpus=("${cpus[@]}") 17 18interrupt() { 19 local busy_cpus 20 local cpu thread 21 22 local reactor_framework 23 24 cpus_to_collect=("${cpus[@]}") 25 collect_cpu_idle 26 27 # Verify that each cpu, except the main cpu, has no threads assigned 28 reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 29 for cpu in "${cpus[@]:1}"; do 30 [[ -z $(jq -r "select(.lcore == $cpu) | .lw_threads[].id" <<< "$reactor_framework") ]] 31 done 32 33 # Standard scenario - spdk app is idle, all cpus, except the main cpu, should be 34 # switched into interrupt mode. main cpu should remain busy, all remaining cpus 35 # should become idle. 36 for cpu in "${!is_idle[@]}"; do 37 if ((cpu == spdk_main_core)); then 38 ((is_idle[cpu] == 0)) # main cpu must not be idle 39 fi 40 if ((cpu != spdk_main_core)); then 41 ((is_idle[cpu] == 1)) # all cpus except the main cpu must be idle 42 fi 43 done 44 45 # select 3 cpus except the main one 46 busy_cpus=("${cpus[@]:1:3}") threads=() 47 48 # Create busy thread on each of the selected cpus, then verify if given cpu has become busy 49 # and that newly created thread was assigned to a proper lcore. 50 for cpu in "${busy_cpus[@]}"; do 51 threads[cpu]=$(create_thread -n "thread$cpu" -m "$(mask_cpus "$cpu")" -a 100) cpus_to_collect=("$cpu") 52 collect_cpu_idle 53 reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 54 [[ -n $(jq -r "select(.lcore == $cpu) | .lw_threads[] | select(.name == \"thread$cpu\")" <<< "$reactor_framework") ]] 55 ((is_idle[cpu] == 0)) 56 done 57 58 # Make all the threads idle and verify if their cpus have become idle as well and if they were 59 # moved away out of their lcores. 60 for cpu in "${!threads[@]}"; do 61 active_thread "${threads[cpu]}" 0 62 cpus_to_collect=("$cpu") 63 collect_cpu_idle 64 reactor_framework=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 65 [[ -z $(jq -r "select(.lcore == $cpu) | .lw_threads[].id" <<< "$reactor_framework") ]] 66 [[ -n $(jq -r "select(.lcore == $spdk_main_core) | .lw_threads[] | select(.name == \"thread$cpu\")" <<< "$reactor_framework") ]] 67 ((is_idle[cpu] == 1)) 68 done 69 70 for cpu in "${!threads[@]}"; do 71 destroy_thread "${threads[cpu]}" 72 done 73} 74 75exec_under_dynamic_scheduler "$scheduler" -m "$spdk_cpusmask" --main-core "$spdk_main_core" 76 77interrupt 78