1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later 3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2007 4f08c3bdfSopenharmony_ci# Copyright (c) Linux Test Project, 2016-2020 5f08c3bdfSopenharmony_ci# Author: Sivakumar Chinnaiah <Sivakumar.C@in.ibm.com> 6f08c3bdfSopenharmony_ci# 7f08c3bdfSopenharmony_ci# Test Basic functionality of numactl command. 8f08c3bdfSopenharmony_ci# Test #1: Verifies cpunodebind and membind 9f08c3bdfSopenharmony_ci# Test #2: Verifies preferred node bind for memory allocation 10f08c3bdfSopenharmony_ci# Test #3: Verifies memory interleave on all nodes 11f08c3bdfSopenharmony_ci# Test #4: Verifies physcpubind 12f08c3bdfSopenharmony_ci# Test #5: Verifies localalloc 13f08c3bdfSopenharmony_ci# Test #6: Verifies memhog 14f08c3bdfSopenharmony_ci# Test #7: Verifies numa_node_size api 15f08c3bdfSopenharmony_ci# Test #8: Verifies hugepage alloacted on specified node 16f08c3bdfSopenharmony_ci# Test #9: Verifies THP memory allocated on preferred node 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ciTST_CNT=9 19f08c3bdfSopenharmony_ciTST_SETUP=setup 20f08c3bdfSopenharmony_ciTST_TESTFUNC=test 21f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1 22f08c3bdfSopenharmony_ciTST_NEEDS_ROOT=1 23f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="awk bc numactl numastat" 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci# Awk the field matching the node value for numastat 26f08c3bdfSopenharmony_ci# $1 - Pid number 27f08c3bdfSopenharmony_ci# $2 - Node number 28f08c3bdfSopenharmony_ciget_node_index() 29f08c3bdfSopenharmony_ci{ 30f08c3bdfSopenharmony_ci local pid=$1 31f08c3bdfSopenharmony_ci local nid="Node $2" 32f08c3bdfSopenharmony_ci echo $(numastat -p $pid | sed '3q;d' | awk -F '[[:space:]][[:space:]]+' \ 33f08c3bdfSopenharmony_ci -v node="$nid" '{ for (i = 1; i <= NF; ++i) if($i==node) print i; exit }') 34f08c3bdfSopenharmony_ci} 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci# Convert the value of given NUMA node from the `numastat -p` output, 37f08c3bdfSopenharmony_ci# multiply by size. 38f08c3bdfSopenharmony_ci# $1 - Pid number 39f08c3bdfSopenharmony_ci# $2 - Node number 40f08c3bdfSopenharmony_ci# $3 - Size for multiplication (e.g. 1024, $MB) 41f08c3bdfSopenharmony_ciget_mem_cur() 42f08c3bdfSopenharmony_ci{ 43f08c3bdfSopenharmony_ci local pid=$1 44f08c3bdfSopenharmony_ci local index=$(echo "$(get_node_index $pid $2)") 45f08c3bdfSopenharmony_ci local size=$3 46f08c3bdfSopenharmony_ci local numstat=$(numastat -p $pid |awk '/^Total/ {print $'$index'}') 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci if [ -z "$numstat" ]; then 49f08c3bdfSopenharmony_ci echo 0 50f08c3bdfSopenharmony_ci return 51f08c3bdfSopenharmony_ci fi 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci echo $(echo "$numstat * $size" | bc) 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cicheck_for_support_numa() 57f08c3bdfSopenharmony_ci{ 58f08c3bdfSopenharmony_ci local pid=$1 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ci local state=$(awk '{print $3}' /proc/$pid/stat) 61f08c3bdfSopenharmony_ci 62f08c3bdfSopenharmony_ci if [ $state = 'T' ]; then 63f08c3bdfSopenharmony_ci return 0 64f08c3bdfSopenharmony_ci fi 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ci return 1 67f08c3bdfSopenharmony_ci} 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_cisetup() 70f08c3bdfSopenharmony_ci{ 71f08c3bdfSopenharmony_ci export MB=$((1024*1024)) 72f08c3bdfSopenharmony_ci export PAGE_SIZE=$(tst_getconf PAGESIZE) 73f08c3bdfSopenharmony_ci export HPAGE_SIZE=$(awk '/Hugepagesize:/ {print $2}' /proc/meminfo) 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci total_nodes=0 76f08c3bdfSopenharmony_ci 77f08c3bdfSopenharmony_ci nodes_list=$(numactl --show | grep nodebind | cut -d ':' -f 2) 78f08c3bdfSopenharmony_ci for node in $nodes_list; do 79f08c3bdfSopenharmony_ci total_nodes=$((total_nodes+1)) 80f08c3bdfSopenharmony_ci done 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci tst_res TINFO "The system contains $total_nodes nodes: $nodes_list" 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_ci if [ $total_nodes -le 1 ]; then 85f08c3bdfSopenharmony_ci tst_brk TCONF "SUT does not support NUMA policy or not a NUMA machine" 86f08c3bdfSopenharmony_ci fi 87f08c3bdfSopenharmony_ci} 88f08c3bdfSopenharmony_ci 89f08c3bdfSopenharmony_ci# Verification of memory allocated on a node 90f08c3bdfSopenharmony_citest1() 91f08c3bdfSopenharmony_ci{ 92f08c3bdfSopenharmony_ci local mem_curr 93f08c3bdfSopenharmony_ci 94f08c3bdfSopenharmony_ci for node in $nodes_list; do 95f08c3bdfSopenharmony_ci numactl --cpunodebind=$node --membind=$node support_numa alloc_1MB & 96f08c3bdfSopenharmony_ci pid=$! 97f08c3bdfSopenharmony_ci 98f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_for_support_numa $pid" 0 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci mem_curr=$(get_mem_cur $pid $node $MB) 101f08c3bdfSopenharmony_ci if [ $(echo "$mem_curr < $MB" | bc) -eq 1 ]; then 102f08c3bdfSopenharmony_ci tst_res TFAIL \ 103f08c3bdfSopenharmony_ci "NUMA memory allocated in node$node is less than expected" 104f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 105f08c3bdfSopenharmony_ci return 106f08c3bdfSopenharmony_ci fi 107f08c3bdfSopenharmony_ci 108f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 109f08c3bdfSopenharmony_ci done 110f08c3bdfSopenharmony_ci 111f08c3bdfSopenharmony_ci tst_res TPASS "NUMA local node and memory affinity" 112f08c3bdfSopenharmony_ci} 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_ci# Verification of memory allocated on preferred node 115f08c3bdfSopenharmony_citest2() 116f08c3bdfSopenharmony_ci{ 117f08c3bdfSopenharmony_ci local mem_curr 118f08c3bdfSopenharmony_ci local cnt=1 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci for node in $nodes_list; do 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ci if [ $cnt -eq $total_nodes ]; then #wrap up for last node 123f08c3bdfSopenharmony_ci Preferred_node=$(echo $nodes_list | cut -d ' ' -f 1) 124f08c3bdfSopenharmony_ci else 125f08c3bdfSopenharmony_ci # always next node is preferred node 126f08c3bdfSopenharmony_ci Preferred_node=$(echo $nodes_list | cut -d ' ' -f $((cnt+1))) 127f08c3bdfSopenharmony_ci fi 128f08c3bdfSopenharmony_ci 129f08c3bdfSopenharmony_ci numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_1MB & 130f08c3bdfSopenharmony_ci pid=$! 131f08c3bdfSopenharmony_ci 132f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_for_support_numa $pid" 0 133f08c3bdfSopenharmony_ci 134f08c3bdfSopenharmony_ci mem_curr=$(get_mem_cur $pid $Preferred_node $MB) 135f08c3bdfSopenharmony_ci if [ $(echo "$mem_curr < $MB" |bc ) -eq 1 ]; then 136f08c3bdfSopenharmony_ci tst_res TFAIL \ 137f08c3bdfSopenharmony_ci "NUMA memory allocated in node$Preferred_node is less than expected" 138f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 139f08c3bdfSopenharmony_ci return 140f08c3bdfSopenharmony_ci fi 141f08c3bdfSopenharmony_ci 142f08c3bdfSopenharmony_ci cnt=$((cnt+1)) 143f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 144f08c3bdfSopenharmony_ci done 145f08c3bdfSopenharmony_ci 146f08c3bdfSopenharmony_ci tst_res TPASS "NUMA preferred node policy" 147f08c3bdfSopenharmony_ci} 148f08c3bdfSopenharmony_ci 149f08c3bdfSopenharmony_ci# Verification of memory interleaved on all nodes 150f08c3bdfSopenharmony_citest3() 151f08c3bdfSopenharmony_ci{ 152f08c3bdfSopenharmony_ci local mem_curr 153f08c3bdfSopenharmony_ci # Memory will be allocated using round robin on nodes. 154f08c3bdfSopenharmony_ci Exp_incr=$(echo "$MB / $total_nodes" |bc) 155f08c3bdfSopenharmony_ci 156f08c3bdfSopenharmony_ci numactl --interleave=all support_numa alloc_1MB & 157f08c3bdfSopenharmony_ci pid=$! 158f08c3bdfSopenharmony_ci 159f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_for_support_numa $pid" 0 160f08c3bdfSopenharmony_ci 161f08c3bdfSopenharmony_ci for node in $nodes_list; do 162f08c3bdfSopenharmony_ci mem_curr=$(get_mem_cur $pid $node $MB) 163f08c3bdfSopenharmony_ci 164f08c3bdfSopenharmony_ci if [ $(echo "$mem_curr < $Exp_incr" |bc ) -eq 1 ]; then 165f08c3bdfSopenharmony_ci tst_res TFAIL \ 166f08c3bdfSopenharmony_ci "NUMA interleave memory allocated in node$node is less than expected" 167f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 168f08c3bdfSopenharmony_ci return 169f08c3bdfSopenharmony_ci fi 170f08c3bdfSopenharmony_ci done 171f08c3bdfSopenharmony_ci 172f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 173f08c3bdfSopenharmony_ci tst_res TPASS "NUMA interleave policy" 174f08c3bdfSopenharmony_ci} 175f08c3bdfSopenharmony_ci 176f08c3bdfSopenharmony_ci# Verification of physical cpu bind 177f08c3bdfSopenharmony_citest4() 178f08c3bdfSopenharmony_ci{ 179f08c3bdfSopenharmony_ci no_of_cpus=0 #no. of cpu's exist 180f08c3bdfSopenharmony_ci run_on_cpu=0 181f08c3bdfSopenharmony_ci running_on_cpu=0 182f08c3bdfSopenharmony_ci 183f08c3bdfSopenharmony_ci no_of_cpus=$(tst_ncpus) 184f08c3bdfSopenharmony_ci # not sure whether cpu's can't be in odd number 185f08c3bdfSopenharmony_ci run_on_cpu=$(($((no_of_cpus+1))/2)) 186f08c3bdfSopenharmony_ci numactl --all --physcpubind=$run_on_cpu support_numa pause & #just waits for sigint 187f08c3bdfSopenharmony_ci pid=$! 188f08c3bdfSopenharmony_ci var=`awk '{ print $2 }' /proc/$pid/stat` 189f08c3bdfSopenharmony_ci while [ $var = '(numactl)' ]; do 190f08c3bdfSopenharmony_ci var=`awk '{ print $2 }' /proc/$pid/stat` 191f08c3bdfSopenharmony_ci tst_sleep 100ms 192f08c3bdfSopenharmony_ci done 193f08c3bdfSopenharmony_ci # Warning !! 39 represents cpu number, on which process pid is currently running and 194f08c3bdfSopenharmony_ci # this may change if Some more fields are added in the middle, may be in future 195f08c3bdfSopenharmony_ci running_on_cpu=$(awk '{ print $39; }' /proc/$pid/stat) 196f08c3bdfSopenharmony_ci if [ $running_on_cpu -ne $run_on_cpu ]; then 197f08c3bdfSopenharmony_ci tst_res TFAIL \ 198f08c3bdfSopenharmony_ci "Process running on cpu$running_on_cpu but expected to run on cpu$run_on_cpu" 199f08c3bdfSopenharmony_ci ROD kill -INT $pid 200f08c3bdfSopenharmony_ci return 201f08c3bdfSopenharmony_ci fi 202f08c3bdfSopenharmony_ci 203f08c3bdfSopenharmony_ci ROD kill -INT $pid 204f08c3bdfSopenharmony_ci 205f08c3bdfSopenharmony_ci tst_res TPASS "NUMA phycpubind policy" 206f08c3bdfSopenharmony_ci} 207f08c3bdfSopenharmony_ci 208f08c3bdfSopenharmony_ci# Verification of local node allocation 209f08c3bdfSopenharmony_citest5() 210f08c3bdfSopenharmony_ci{ 211f08c3bdfSopenharmony_ci local mem_curr 212f08c3bdfSopenharmony_ci 213f08c3bdfSopenharmony_ci for node in $nodes_list; do 214f08c3bdfSopenharmony_ci numactl --cpunodebind=$node --localalloc support_numa alloc_1MB & 215f08c3bdfSopenharmony_ci pid=$! 216f08c3bdfSopenharmony_ci 217f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_for_support_numa $pid" 0 218f08c3bdfSopenharmony_ci 219f08c3bdfSopenharmony_ci mem_curr=$(get_mem_cur $pid $node $MB) 220f08c3bdfSopenharmony_ci if [ $(echo "$mem_curr < $MB" |bc ) -eq 1 ]; then 221f08c3bdfSopenharmony_ci tst_res TFAIL \ 222f08c3bdfSopenharmony_ci "NUMA localnode memory allocated in node$node is less than expected" 223f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 224f08c3bdfSopenharmony_ci return 225f08c3bdfSopenharmony_ci fi 226f08c3bdfSopenharmony_ci 227f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 228f08c3bdfSopenharmony_ci done 229f08c3bdfSopenharmony_ci 230f08c3bdfSopenharmony_ci tst_res TPASS "NUMA local node allocation" 231f08c3bdfSopenharmony_ci} 232f08c3bdfSopenharmony_ci 233f08c3bdfSopenharmony_cicheck_ltp_numa_test8_log() 234f08c3bdfSopenharmony_ci{ 235f08c3bdfSopenharmony_ci grep -m1 -q '.' ltp_numa_test8.log 236f08c3bdfSopenharmony_ci} 237f08c3bdfSopenharmony_ci 238f08c3bdfSopenharmony_ci# Verification of memhog with interleave policy 239f08c3bdfSopenharmony_citest6() 240f08c3bdfSopenharmony_ci{ 241f08c3bdfSopenharmony_ci local mem_curr 242f08c3bdfSopenharmony_ci # Memory will be allocated using round robin on nodes. 243f08c3bdfSopenharmony_ci Exp_incr=$(echo "$MB / $total_nodes" |bc) 244f08c3bdfSopenharmony_ci 245f08c3bdfSopenharmony_ci numactl --interleave=all memhog -r1000000 1MB >ltp_numa_test8.log 2>&1 & 246f08c3bdfSopenharmony_ci pid=$! 247f08c3bdfSopenharmony_ci 248f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_ltp_numa_test8_log" 0 249f08c3bdfSopenharmony_ci 250f08c3bdfSopenharmony_ci for node in $nodes_list; do 251f08c3bdfSopenharmony_ci mem_curr=$(get_mem_cur $pid $node $MB) 252f08c3bdfSopenharmony_ci 253f08c3bdfSopenharmony_ci if [ $(echo "$mem_curr < $Exp_incr" |bc ) -eq 1 ]; then 254f08c3bdfSopenharmony_ci tst_res TFAIL \ 255f08c3bdfSopenharmony_ci "NUMA interleave memhog in node$node is less than expected" 256f08c3bdfSopenharmony_ci kill -KILL $pid >/dev/null 2>&1 257f08c3bdfSopenharmony_ci return 258f08c3bdfSopenharmony_ci fi 259f08c3bdfSopenharmony_ci done 260f08c3bdfSopenharmony_ci 261f08c3bdfSopenharmony_ci kill -KILL $pid >/dev/null 2>&1 262f08c3bdfSopenharmony_ci tst_res TPASS "NUMA MEMHOG policy" 263f08c3bdfSopenharmony_ci} 264f08c3bdfSopenharmony_ci 265f08c3bdfSopenharmony_ci# Function: hardware cheking with numa_node_size api 266f08c3bdfSopenharmony_ci# 267f08c3bdfSopenharmony_ci# Description: - Returns the size of available nodes if success. 268f08c3bdfSopenharmony_ci# 269f08c3bdfSopenharmony_ci# Input: - o/p of numactl --hardware command which is expected in the format 270f08c3bdfSopenharmony_ci# shown below 271f08c3bdfSopenharmony_ci# available: 2 nodes (0-1) 272f08c3bdfSopenharmony_ci# node 0 size: 7808 MB 273f08c3bdfSopenharmony_ci# node 0 free: 7457 MB 274f08c3bdfSopenharmony_ci# node 1 size: 5807 MB 275f08c3bdfSopenharmony_ci# node 1 free: 5731 MB 276f08c3bdfSopenharmony_ci# node distances: 277f08c3bdfSopenharmony_ci# node 0 1 278f08c3bdfSopenharmony_ci# 0: 10 20 279f08c3bdfSopenharmony_ci# 1: 20 10 280f08c3bdfSopenharmony_ci# 281f08c3bdfSopenharmony_citest7() 282f08c3bdfSopenharmony_ci{ 283f08c3bdfSopenharmony_ci RC=0 284f08c3bdfSopenharmony_ci 285f08c3bdfSopenharmony_ci numactl --hardware > gavail_nodes 286f08c3bdfSopenharmony_ci RC=$(awk '{ if ( NR == 1 ) {print $1;} }' gavail_nodes) 287f08c3bdfSopenharmony_ci if [ $RC = "available:" ]; then 288f08c3bdfSopenharmony_ci RC=$(awk '{ if ( NR == 1 ) {print $3;} }' gavail_nodes) 289f08c3bdfSopenharmony_ci if [ $RC = "nodes" ]; then 290f08c3bdfSopenharmony_ci RC=$(awk '{ if ( NR == 1 ) {print $2;} }' gavail_nodes) 291f08c3bdfSopenharmony_ci tst_res TPASS "NUMA policy on lib NUMA_NODE_SIZE API" 292f08c3bdfSopenharmony_ci else 293f08c3bdfSopenharmony_ci tst_res TFAIL "Failed with NUMA policy" 294f08c3bdfSopenharmony_ci fi 295f08c3bdfSopenharmony_ci else 296f08c3bdfSopenharmony_ci tst_res TFAIL "Failed with NUMA policy" 297f08c3bdfSopenharmony_ci fi 298f08c3bdfSopenharmony_ci} 299f08c3bdfSopenharmony_ci 300f08c3bdfSopenharmony_ci# Verification of hugepage memory allocated on a node 301f08c3bdfSopenharmony_citest8() 302f08c3bdfSopenharmony_ci{ 303f08c3bdfSopenharmony_ci Mem_huge=0 304f08c3bdfSopenharmony_ci Sys_node=/sys/devices/system/node 305f08c3bdfSopenharmony_ci 306f08c3bdfSopenharmony_ci if [ ! -d "/sys/kernel/mm/hugepages/" ]; then 307f08c3bdfSopenharmony_ci tst_res TCONF "hugepage is not supported" 308f08c3bdfSopenharmony_ci return 309f08c3bdfSopenharmony_ci fi 310f08c3bdfSopenharmony_ci 311f08c3bdfSopenharmony_ci for node in $nodes_list; do 312f08c3bdfSopenharmony_ci Ori_hpgs=$(cat ${Sys_node}/node${node}/hugepages/hugepages-${HPAGE_SIZE}kB/nr_hugepages) 313f08c3bdfSopenharmony_ci New_hpgs=$((Ori_hpgs + 1)) 314f08c3bdfSopenharmony_ci echo $New_hpgs >${Sys_node}/node${node}/hugepages/hugepages-${HPAGE_SIZE}kB/nr_hugepages 315f08c3bdfSopenharmony_ci 316f08c3bdfSopenharmony_ci Chk_hpgs=$(cat ${Sys_node}/node${node}/hugepages/hugepages-${HPAGE_SIZE}kB/nr_hugepages) 317f08c3bdfSopenharmony_ci if [ "$Chk_hpgs" -ne "$New_hpgs" ]; then 318f08c3bdfSopenharmony_ci tst_res TCONF "hugepage is not enough to test" 319f08c3bdfSopenharmony_ci return 320f08c3bdfSopenharmony_ci fi 321f08c3bdfSopenharmony_ci 322f08c3bdfSopenharmony_ci numactl --cpunodebind=$node --membind=$node support_numa alloc_1huge_page & 323f08c3bdfSopenharmony_ci pid=$! 324f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_for_support_numa $pid" 0 325f08c3bdfSopenharmony_ci 326f08c3bdfSopenharmony_ci local index=$(echo "$(get_node_index $pid $node)") 327f08c3bdfSopenharmony_ci Mem_huge=$(echo $(numastat -p $pid |awk '/^Huge/ {print $'$index'}')) 328f08c3bdfSopenharmony_ci Mem_huge=$((${Mem_huge%.*} * 1024)) 329f08c3bdfSopenharmony_ci 330f08c3bdfSopenharmony_ci if [ "$Mem_huge" -lt "$HPAGE_SIZE" ]; then 331f08c3bdfSopenharmony_ci tst_res TFAIL \ 332f08c3bdfSopenharmony_ci "NUMA memory allocated in node$node is less than expected" 333f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 334f08c3bdfSopenharmony_ci echo $Ori_hpgs >${Sys_node}/node${node}/hugepages/hugepages-${HPAGE_SIZE}kB/nr_hugepages 335f08c3bdfSopenharmony_ci return 336f08c3bdfSopenharmony_ci fi 337f08c3bdfSopenharmony_ci 338f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 339f08c3bdfSopenharmony_ci echo $Ori_hpgs >${Sys_node}/node${node}/hugepages/hugepages-${HPAGE_SIZE}kB/nr_hugepages 340f08c3bdfSopenharmony_ci done 341f08c3bdfSopenharmony_ci 342f08c3bdfSopenharmony_ci tst_res TPASS "NUMA local node hugepage memory allocated" 343f08c3bdfSopenharmony_ci} 344f08c3bdfSopenharmony_ci 345f08c3bdfSopenharmony_ci# Verification of THP memory allocated on preferred node 346f08c3bdfSopenharmony_citest9() 347f08c3bdfSopenharmony_ci{ 348f08c3bdfSopenharmony_ci local mem_curr 349f08c3bdfSopenharmony_ci local cnt=1 350f08c3bdfSopenharmony_ci 351f08c3bdfSopenharmony_ci if ! grep -q '\[always\]' /sys/kernel/mm/transparent_hugepage/enabled; then 352f08c3bdfSopenharmony_ci tst_res TCONF "THP is not supported/enabled" 353f08c3bdfSopenharmony_ci return 354f08c3bdfSopenharmony_ci fi 355f08c3bdfSopenharmony_ci 356f08c3bdfSopenharmony_ci for node in $nodes_list; do 357f08c3bdfSopenharmony_ci if [ $cnt -eq $total_nodes ]; then #wrap up for last node 358f08c3bdfSopenharmony_ci Preferred_node=$(echo $nodes_list | cut -d ' ' -f 1) 359f08c3bdfSopenharmony_ci else 360f08c3bdfSopenharmony_ci # always next node is preferred node 361f08c3bdfSopenharmony_ci Preferred_node=$(echo $nodes_list | cut -d ' ' -f $((cnt+1))) 362f08c3bdfSopenharmony_ci fi 363f08c3bdfSopenharmony_ci 364f08c3bdfSopenharmony_ci numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_2HPSZ_THP & 365f08c3bdfSopenharmony_ci pid=$! 366f08c3bdfSopenharmony_ci 367f08c3bdfSopenharmony_ci TST_RETRY_FUNC "check_for_support_numa $pid" 0 368f08c3bdfSopenharmony_ci 369f08c3bdfSopenharmony_ci mem_curr=$(get_mem_cur $pid $Preferred_node 1024) 370f08c3bdfSopenharmony_ci if [ $(echo "$mem_curr < $HPAGE_SIZE * 2" |bc ) -eq 1 ]; then 371f08c3bdfSopenharmony_ci tst_res TFAIL \ 372f08c3bdfSopenharmony_ci "NUMA memory allocated in node$Preferred_node is less than expected" 373f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 374f08c3bdfSopenharmony_ci return 375f08c3bdfSopenharmony_ci fi 376f08c3bdfSopenharmony_ci 377f08c3bdfSopenharmony_ci cnt=$((cnt+1)) 378f08c3bdfSopenharmony_ci kill -CONT $pid >/dev/null 2>&1 379f08c3bdfSopenharmony_ci done 380f08c3bdfSopenharmony_ci 381f08c3bdfSopenharmony_ci tst_res TPASS "NUMA preferred node policy verified with THP enabled" 382f08c3bdfSopenharmony_ci} 383f08c3bdfSopenharmony_ci 384f08c3bdfSopenharmony_ci. tst_test.sh 385f08c3bdfSopenharmony_citst_run 386