1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (C) 2020 Intel Corporation. 3# All rights reserved. 4 5# Select cores for the test 6xtrace_disable 7 8source "$testdir/common.sh" 9 10restore_cgroups() { 11 xtrace_disable 12 remove_cpuset_cgroup 13 xtrace_restore 14} 15 16trap "restore_cgroups" EXIT 17 18# Number of cpus to include in the mask 19NUM_CPUS=${NUM_CPUS:-8} 20 21init_cpuset_cgroup 22map_cpus 23 24# Build core mask. Avoid all CPUs that may be offline and skip cpu0 25# (and all its potential thread siblings) as it's already doing an 26# extra work for the kernel. 27denied_list $(get_cpus "${cpu_node_map[0]}" "${cpu_core_map[0]}") 28# If there are any isolated cpus (as defined on the kernel cmdline 29# with isolcpus) they take the priority. We fill up the list up to 30# NUM_CPUS, applying filtering as per the denied list. All cpus are 31# taken from node0. 32allowed_list "$NUM_CPUS" 0 33 34# Assign proper resources to the cpuset/spdk 35spdk_cpus=("${allowed[@]}") 36spdk_cpus_csv=$(fold_array_onto_string "${spdk_cpus[@]}") 37spdk_cpumask=$(mask_cpus "${spdk_cpus[@]}") 38spdk_main_core=${spdk_cpus[0]} 39spdk_cpus_mems=0 40 41# Build list of remaining cpus for posterity 42denied_list "${spdk_cpus[@]}" 43fold_list_onto_array allowed "${cpus[@]}" 44filter_allowed_list 45 46all_cpus=("${allowed[@]}") 47all_cpus_csv=$(fold_array_onto_string "${all_cpus[@]}") 48all_cpumask=$(mask_cpus "${all_cpus[@]}") 49all_cpus_mems=0 50 51# For cgroupv2 it's required we jump first to the root cgroup ... 52move_proc "$$" "/" "" cgroup.procs 53# ... so we can now settle in a dedicated cgroup /cpuset 54move_proc "$$" "/cpuset" "" cgroup.procs 55 56set_cgroup_attr "/cpuset" cpuset.cpus "$spdk_cpus_csv" 57set_cgroup_attr "/cpuset" cpuset.mems "$spdk_cpus_mems" 58 59export \ 60 "spdk_cpumask=$spdk_cpumask" \ 61 "spdk_cpus_csv=$spdk_cpus_csv" \ 62 "spdk_cpus_no=${#spdk_cpus[@]}" \ 63 "spdk_main_core=$spdk_main_core" \ 64 "all_cpumask=$all_cpumask" \ 65 "all_cpus_csv=$all_cpus_csv" 66 67xtrace_restore 68