1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2021 Intel Corporation 4# Copyright (c) 2024 Samsung Electronics Corporation 5# All rights reserved. 6# 7testdir=$(readlink -f "$(dirname "$0")") 8rootdir=$(readlink -f "$testdir/../../") 9 10source "$rootdir/test/common/autotest_common.sh" 11source "$testdir/common.sh" 12 13trap 'killprocess "$spdk_pid"' EXIT 14 15fold_list_onto_array cpus $(parse_cpu_list <(echo "$spdk_cpus_csv")) 16# Normalize the indexes 17cpus=("${cpus[@]}") 18isolated_core=${cpus[1]} 19scheduling_core=${cpus[2]} 20 21set_scheduler_options() { 22 local isolated_core_mask 23 24 isolated_core_mask=$(mask_cpus ${isolated_core}) 25 rpc_cmd scheduler_set_options --scheduling-core ${scheduling_core} -i "${isolated_core_mask}" 26} 27 28set_scheduler_and_check_thread_status() { 29 local isolated_thread_count tmp_count total_thread_count=0 idle_thread_count 30 local core_mask reactors 31 32 for cpu in "${cpus[@]}"; do 33 core_mask=$(mask_cpus ${cpu}) 34 create_thread -n "thread${cpu}" -m "${core_mask}" -a 0 35 done 36 37 # Get current thread status. All threads are idle. 38 reactors=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 39 isolated_thread_count=$(jq -r "select(.lcore == ${isolated_core}) | .lw_threads | length" <<< "$reactors") 40 total_thread_count=$(echo "$reactors" | jq -r "select(.lcore) | .lw_threads | length" | awk '{s+=$1} END {print s}') 41 42 rpc_cmd framework_set_scheduler dynamic 43 44 reactors=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 45 isolated_thread_ids=($(echo "$reactors" | jq -r "select(.lcore == ${isolated_core}) | .lw_threads" | jq -r '.[].id')) 46 47 # Check if isolated core's thread counts stay the same. 48 tmp_count=$(jq -r "select(.lcore == ${isolated_core}) | .lw_threads | length" <<< "$reactors") 49 ((isolated_thread_count == tmp_count)) 50 51 # Check if rest of the idle threads are on the scheduling core. 52 idle_thread_count=$(jq -r "select(.lcore == ${scheduling_core}) | .lw_threads| length" <<< "$reactors") 53 tmp_count=$((total_thread_count - isolated_thread_count)) 54 55 # Make the thread on the isolated core busy and verify that it remains isolated. 56 for thread_id in "${isolated_thread_ids[@]}"; do 57 active_thread "$thread_id" 95 58 done 59 60 reactors=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 61 idle_thread_ids=($(echo "$reactors" | jq -r "select(.lcore == ${scheduling_core}) | .lw_threads" | jq -r '.[].id')) 62 # Make the threads on the scheudling core busy and verify that they are distributed. 63 for thread_id in "${idle_thread_ids[@]}"; do 64 if ((thread_id == 1)); then 65 continue 66 fi 67 active_thread "$thread_id" 80 68 done 69 sleep 20 70 71 reactors=$(rpc_cmd framework_get_reactors | jq -r '.reactors[]') 72 tmp_count=$(jq -r "select(.lcore == ${isolated_core}) | .lw_threads | length" <<< "$reactors") 73 ((isolated_thread_count == tmp_count)) 74 75 tmp_count=$(jq -r "select(.lcore == ${scheduling_core}) | .lw_threads| length" <<< "$reactors") 76 ((idle_thread_count >= tmp_count)) 77} 78 79exec_under_static_scheduler "$scheduler" -m "$spdk_cpumask" --main-core "$spdk_main_core" 80 81set_scheduler_options 82 83rpc_cmd framework_start_init 84 85set_scheduler_and_check_thread_status 86