1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2024 Intel Corporation 4# All rights reserved. 5# 6 7testdir=$(readlink -f "$(dirname "$0")") 8rootdir=$(readlink -f "$testdir/../../") 9 10source "$rootdir/test/common/autotest_common.sh" 11source "$testdir/common.sh" 12 13rpc=rpc_cmd 14 15function framework_get_governor() { 16 "${SPDK_APP[@]}" -m "$spdk_cpumask" & 17 spdk_pid=$! 18 trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT 19 waitforlisten $spdk_pid 20 21 # Static scheduler does not use any governor 22 [[ "$($rpc framework_get_scheduler | jq -r '.scheduler_name')" == "static" ]] 23 [[ -z "$($rpc framework_get_governor | jq -r '.[]')" ]] 24 25 # gscheduler uses the only currently implemented governor - dpdk_governor 26 $rpc framework_set_scheduler gscheduler 27 [[ "$($rpc framework_get_scheduler | jq -r '.scheduler_name')" == "gscheduler" ]] 28 [[ "$($rpc framework_get_governor | jq -r '.governor_name')" == "dpdk_governor" ]] 29 30 # Check that core length matches the cpumask and first one is the main core 31 [[ "$($rpc framework_get_governor | jq -r '.cores | length')" -eq "$spdk_cpus_no" ]] 32 [[ "$($rpc framework_get_governor | jq -r '.cores[0].lcore_id')" -eq "$spdk_main_core" ]] 33 [[ -n "$($rpc framework_get_governor | jq -r '.cores[0].current_frequency')" ]] 34 35 # dpdk_governor always has an env it uses 36 [[ -n "$($rpc framework_get_governor | jq -r '.module_specific.env')" ]] 37 38 trap - SIGINT SIGTERM EXIT 39 killprocess $spdk_pid 40} 41 42function scheduler_opts() { 43 "${SPDK_APP[@]}" -m "$spdk_cpumask" --wait-for-rpc & 44 spdk_pid=$! 45 trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT 46 waitforlisten $spdk_pid 47 48 # It should not be possible to change settings that a scheduler does not support 49 NOT $rpc framework_set_scheduler static --core-limit 42 50 51 # It is possible to change settings generic scheduler opts for schedulers in event framework 52 $rpc framework_set_scheduler dynamic -p 424242 53 [[ "$($rpc framework_get_scheduler | jq -r '. | select(.scheduler_name == "dynamic") | .scheduler_period')" -eq 424242 ]] 54 55 # Verify that the scheduler is changed and the non-default value is set 56 $rpc framework_set_scheduler dynamic --core-limit 42 57 [[ "$($rpc framework_get_scheduler | jq -r '. | select(.scheduler_name == "dynamic") | .core_limit')" -eq 42 ]] 58 59 # Switch scheduler back and forth and verify values are kept (scheduler implementation specific) 60 $rpc framework_set_scheduler gscheduler 61 [[ "$($rpc framework_get_scheduler | jq -r '.scheduler_name')" == "gscheduler" ]] 62 $rpc framework_set_scheduler dynamic 63 [[ "$($rpc framework_get_scheduler | jq -r '. | select(.scheduler_name == "dynamic") | .core_limit')" -eq 42 ]] 64 65 # All the above configuration can happen before subsystems initialize 66 $rpc framework_start_init 67 68 trap - SIGINT SIGTERM EXIT 69 killprocess $spdk_pid 70} 71 72function static_as_default() { 73 "${SPDK_APP[@]}" -m "$spdk_cpumask" --wait-for-rpc & 74 spdk_pid=$! 75 trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT 76 waitforlisten $spdk_pid 77 78 # Before initialization scheduler is set to NULL. If unchanged, set to static 79 # during subsystem initialization. 80 [[ "$($rpc framework_get_scheduler | jq -r '. | select(.scheduler_name == null)')" ]] 81 $rpc framework_start_init 82 [[ "$($rpc framework_get_scheduler | jq -r '.scheduler_name')" == "static" ]] 83 84 # It should never be possible to return to static scheduler after changing it 85 $rpc framework_set_scheduler dynamic 86 [[ "$($rpc framework_get_scheduler | jq -r '.scheduler_name')" == "dynamic" ]] 87 NOT $rpc framework_set_scheduler static 88 [[ "$($rpc framework_get_scheduler | jq -r '.scheduler_name')" == "dynamic" ]] 89 90 trap - SIGINT SIGTERM EXIT 91 killprocess $spdk_pid 92} 93 94run_test "scheduler_opts" scheduler_opts 95run_test "static_as_default" static_as_default 96run_test "framework_get_governor" framework_get_governor 97