Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: ifs: verify IFS scan test functionality

Two selftests are added to verify IFS scan test feature:

1. Perform IFS scan test once on each CPU using all the available image
files.
2. Perform IFS scan test with the default image on a random cpu for 3
rounds.

Reviewed-by: Jithu Joseph <jithu.joseph@intel.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Co-developed-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Pengfei Xu <pengfei.xu@intel.com>
Acked-by: Jithu Joseph <jithu.joseph@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Pengfei Xu and committed by
Shuah Khan
3170f7ac 20cef303

+189 -1
+189 -1
tools/testing/selftests/drivers/platform/x86/intel/ifs/test_ifs.sh
··· 10 10 readonly KSFT_XFAIL=2 11 11 readonly KSFT_SKIP=4 12 12 13 + readonly CPU_SYSFS="/sys/devices/system/cpu" 14 + readonly CPU_OFFLINE_SYSFS="${CPU_SYSFS}/offline" 13 15 readonly IMG_PATH="/lib/firmware/intel/ifs_0" 14 16 readonly IFS_SCAN_MODE="0" 17 + readonly IFS_ARRAY_BIST_SCAN_MODE="1" 15 18 readonly IFS_PATH="/sys/devices/virtual/misc/intel_ifs" 16 19 readonly IFS_SCAN_SYSFS_PATH="${IFS_PATH}_${IFS_SCAN_MODE}" 20 + readonly RUN_TEST="run_test" 21 + readonly STATUS="status" 22 + readonly DETAILS="details" 23 + readonly STATUS_PASS="pass" 17 24 readonly PASS="PASS" 18 25 readonly FAIL="FAIL" 19 26 readonly INFO="INFO" 20 27 readonly XFAIL="XFAIL" 21 28 readonly SKIP="SKIP" 22 29 readonly IFS_NAME="intel_ifs" 30 + readonly ALL="all" 31 + readonly SIBLINGS="siblings" 23 32 24 33 # Matches arch/x86/include/asm/intel-family.h and 25 34 # drivers/platform/x86/intel/ifs/core.c requirement as follows ··· 37 28 38 29 readonly INTEL_FAM6="06" 39 30 31 + LOOP_TIMES=3 40 32 FML="" 41 33 MODEL="" 42 34 STEPPING="" ··· 46 36 FALSE="false" 47 37 RESULT=$KSFT_PASS 48 38 IMAGE_NAME="" 49 - export INTERVAL_TIME=1 39 + INTERVAL_TIME=1 40 + OFFLINE_CPUS="" 50 41 # For IFS cleanup tags 51 42 ORIGIN_IFS_LOADED="" 52 43 IFS_IMAGE_NEED_RESTORE=$FALSE 53 44 IFS_LOG="/tmp/ifs_logs.$$" 45 + RANDOM_CPU="" 54 46 DEFAULT_IMG_ID="" 55 47 56 48 append_log() 57 49 { 58 50 echo -e "$1" | tee -a "$IFS_LOG" 51 + } 52 + 53 + online_offline_cpu_list() 54 + { 55 + local on_off=$1 56 + local target_cpus=$2 57 + local cpu="" 58 + local cpu_start="" 59 + local cpu_end="" 60 + local i="" 61 + 62 + if [[ -n "$target_cpus" ]]; then 63 + for cpu in $(echo "$target_cpus" | tr ',' ' '); do 64 + if [[ "$cpu" == *"-"* ]]; then 65 + cpu_start="" 66 + cpu_end="" 67 + i="" 68 + cpu_start=$(echo "$cpu" | cut -d "-" -f 1) 69 + cpu_end=$(echo "$cpu" | cut -d "-" -f 2) 70 + for((i=cpu_start;i<=cpu_end;i++)); do 71 + append_log "[$INFO] echo $on_off > \ 72 + ${CPU_SYSFS}/cpu${i}/online" 73 + echo "$on_off" > "$CPU_SYSFS"/cpu"$i"/online 74 + done 75 + else 76 + set_target_cpu "$on_off" "$cpu" 77 + fi 78 + done 79 + fi 59 80 } 60 81 61 82 ifs_scan_result_summary() ··· 120 79 [[ "$IFS_IMAGE_NEED_RESTORE" == "$TRUE" ]] && { 121 80 mv -f "$IMG_PATH"/"$IMAGE_NAME"_origin "$IMG_PATH"/"$IMAGE_NAME" 122 81 } 82 + 83 + # Restore the CPUs to the state before testing 84 + [[ -z "$OFFLINE_CPUS" ]] || online_offline_cpu_list "0" "$OFFLINE_CPUS" 123 85 124 86 lsmod | grep -q "$IFS_NAME" && [[ "$ORIGIN_IFS_LOADED" == "$FALSE" ]] && { 125 87 echo "[$INFO] modprobe -r $IFS_NAME" ··· 164 120 165 121 append_log "[${EXIT_MAP[$RESULT]}] $info" 166 122 ifs_cleanup 123 + } 124 + 125 + online_all_cpus() 126 + { 127 + local off_cpus="" 128 + 129 + OFFLINE_CPUS=$(cat "$CPU_OFFLINE_SYSFS") 130 + online_offline_cpu_list "1" "$OFFLINE_CPUS" 131 + 132 + off_cpus=$(cat "$CPU_OFFLINE_SYSFS") 133 + if [[ -z "$off_cpus" ]]; then 134 + append_log "[$INFO] All CPUs are online." 135 + else 136 + append_log "[$XFAIL] There is offline cpu:$off_cpus after online all cpu!" 137 + RESULT=$KSFT_XFAIL 138 + ifs_cleanup 139 + fi 167 140 } 168 141 169 142 get_cpu_fms() ··· 329 268 append_log "[$INFO] Loading invalid IFS image and then loading initial image passed.\n" 330 269 } 331 270 271 + ifs_test_cpu() 272 + { 273 + local ifs_mode=$1 274 + local cpu_num=$2 275 + local image_id status details ret result result_info 276 + 277 + echo "$cpu_num" > "$IFS_PATH"_"$ifs_mode"/"$RUN_TEST" 278 + ret=$? 279 + 280 + status=$(cat "${IFS_PATH}_${ifs_mode}/${STATUS}") 281 + details=$(cat "${IFS_PATH}_${ifs_mode}/${DETAILS}") 282 + 283 + if [[ "$ret" -eq 0 && "$status" == "$STATUS_PASS" ]]; then 284 + result="$PASS" 285 + else 286 + result="$FAIL" 287 + fi 288 + 289 + cpu_num=$(cat "${CPU_SYSFS}/cpu${cpu_num}/topology/thread_siblings_list") 290 + 291 + # There is no image file for IFS ARRAY BIST scan 292 + if [[ -e "${IFS_PATH}_${ifs_mode}/current_batch" ]]; then 293 + image_id=$(cat "${IFS_PATH}_${ifs_mode}/current_batch") 294 + result_info=$(printf "[%s] ifs_%1d cpu(s):%s, current_batch:0x%02x, \ 295 + ret:%2d, status:%s, details:0x%016x" \ 296 + "$result" "$ifs_mode" "$cpu_num" "$image_id" "$ret" \ 297 + "$status" "$details") 298 + else 299 + result_info=$(printf "[%s] ifs_%1d cpu(s):%s, ret:%2d, status:%s, details:0x%016x" \ 300 + "$result" "$ifs_mode" "$cpu_num" "$ret" "$status" "$details") 301 + fi 302 + 303 + append_log "$result_info" 304 + } 305 + 306 + ifs_test_cpus() 307 + { 308 + local cpus_type=$1 309 + local ifs_mode=$2 310 + local image_id=$3 311 + local cpu_max_num="" 312 + local cpu_num="" 313 + 314 + case "$cpus_type" in 315 + "$ALL") 316 + cpu_max_num=$(($(nproc) - 1)) 317 + cpus=$(seq 0 $cpu_max_num) 318 + ;; 319 + "$SIBLINGS") 320 + cpus=$(cat ${CPU_SYSFS}/cpu*/topology/thread_siblings_list \ 321 + | sed -e 's/,.*//' \ 322 + | sed -e 's/-.*//' \ 323 + | sort -n \ 324 + | uniq) 325 + ;; 326 + *) 327 + test_exit "Invalid cpus_type:$cpus_type" "$KSFT_XFAIL" 328 + ;; 329 + esac 330 + 331 + for cpu_num in $cpus; do 332 + ifs_test_cpu "$ifs_mode" "$cpu_num" 333 + done 334 + 335 + if [[ -z "$image_id" ]]; then 336 + append_log "[$INFO] ifs_$ifs_mode test $cpus_type cpus completed\n" 337 + else 338 + append_log "[$INFO] ifs_$ifs_mode $cpus_type cpus with $CPU_FMS-$image_id.scan \ 339 + completed\n" 340 + fi 341 + } 342 + 343 + test_ifs_same_cpu_loop() 344 + { 345 + local ifs_mode=$1 346 + local cpu_num=$2 347 + local loop_times=$3 348 + 349 + append_log "[$INFO] Test ifs mode $ifs_mode on CPU:$cpu_num for $loop_times rounds:" 350 + [[ "$ifs_mode" == "$IFS_SCAN_MODE" ]] && { 351 + load_image "$DEFAULT_IMG_ID" || return $? 352 + } 353 + for (( i=1; i<=loop_times; i++ )); do 354 + append_log "[$INFO] Loop iteration: $i in total of $loop_times" 355 + # Only IFS scan needs the interval time 356 + if [[ "$ifs_mode" == "$IFS_SCAN_MODE" ]]; then 357 + do_cmd "sleep $INTERVAL_TIME" 358 + elif [[ "$ifs_mode" == "$IFS_ARRAY_BIST_SCAN_MODE" ]]; then 359 + true 360 + else 361 + test_exit "Invalid ifs_mode:$ifs_mode" "$KSFT_XFAIL" 362 + fi 363 + 364 + ifs_test_cpu "$ifs_mode" "$cpu_num" 365 + done 366 + append_log "[$INFO] $loop_times rounds of ifs_$ifs_mode test on CPU:$cpu_num completed.\n" 367 + } 368 + 369 + test_ifs_scan_available_imgs() 370 + { 371 + local image_ids="" 372 + local image_id="" 373 + 374 + append_log "[$INFO] Test ifs scan with available images:" 375 + image_ids=$(find "$IMG_PATH" -maxdepth 1 -name "${CPU_FMS}-[0-9a-fA-F][0-9a-fA-F].scan" \ 376 + 2>/dev/null \ 377 + | sort \ 378 + | awk -F "-" '{print $NF}' \ 379 + | cut -d "." -f 1) 380 + 381 + for image_id in $image_ids; do 382 + load_image "$image_id" || return $? 383 + 384 + ifs_test_cpus "$SIBLINGS" "$IFS_SCAN_MODE" "$image_id" 385 + # IFS scan requires time interval for the scan on the same CPU 386 + do_cmd "sleep $INTERVAL_TIME" 387 + done 388 + } 389 + 332 390 prepare_ifs_test_env() 333 391 { 392 + local max_cpu="" 393 + 334 394 check_cpu_ifs_support_interval_time 395 + 396 + online_all_cpus 397 + max_cpu=$(($(nproc) - 1)) 398 + RANDOM_CPU=$(shuf -i 0-$max_cpu -n 1) 335 399 336 400 DEFAULT_IMG_ID=$(find $IMG_PATH -maxdepth 1 -name "${CPU_FMS}-[0-9a-fA-F][0-9a-fA-F].scan" \ 337 401 2>/dev/null \ ··· 476 290 append_log "[$SKIP] No proper ${IMG_PATH}/${CPU_FMS}-*.scan, skip ifs_0 scan" 477 291 else 478 292 test_bad_and_origin_ifs_image "$DEFAULT_IMG_ID" 293 + test_ifs_scan_available_imgs 294 + test_ifs_same_cpu_loop "$IFS_SCAN_MODE" "$RANDOM_CPU" "$LOOP_TIMES" 479 295 fi 480 296 } 481 297