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

perf test: Allow tolerance for leader sampling test

There is a known issue that the leader sampling is inconsistent, since
throttle only affect leader, not the slave. The detail is in [1].

To maintain test coverage, this patch sets a tolerance rate of 80% to
accommodate the throttled samples and prevent test failures due to
throttling.

[1] lore.kernel.org/20250328182752.769662-1-ctshao@google.com

Suggested-by: Ian Rogers <irogers@google.com>
Suggested-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Co-developed-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Tested-by: Thomas Richter <tmricht@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: https://lore.kernel.org/r/20250430140611.599078-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Chun-Tse Shao and committed by
Arnaldo Carvalho de Melo
1c5721ca cb422594

+27 -6
+27 -6
tools/perf/tests/shell/record.sh
··· 240 240 err=1 241 241 return 242 242 fi 243 + perf script -i "${perfdata}" | grep brstack > $script_output 244 + # Check if the two instruction counts are equal in each record. 245 + # However, the throttling code doesn't consider event grouping. During throttling, only the 246 + # leader is stopped, causing the slave's counts significantly higher. To temporarily solve this, 247 + # let's set the tolerance rate to 80%. 248 + # TODO: Revert the code for tolerance once the throttling mechanism is fixed. 243 249 index=0 244 - perf script -i "${perfdata}" > "${script_output}" 250 + valid_counts=0 251 + invalid_counts=0 252 + tolerance_rate=0.8 245 253 while IFS= read -r line 246 254 do 247 - # Check if the two instruction counts are equal in each record 248 255 cycles=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="cycles:") print $(i-1)}') 249 256 if [ $(($index%2)) -ne 0 ] && [ ${cycles}x != ${prev_cycles}x ] 250 257 then 251 - echo "Leader sampling [Failed inconsistent cycles count]" 252 - err=1 253 - return 258 + invalid_counts=$(($invalid_counts+1)) 259 + else 260 + valid_counts=$(($valid_counts+1)) 254 261 fi 255 262 index=$(($index+1)) 256 263 prev_cycles=$cycles 257 264 done < "${script_output}" 258 - echo "Basic leader sampling test [Success]" 265 + total_counts=$(bc <<< "$invalid_counts+$valid_counts") 266 + if (( $(bc <<< "$total_counts <= 0") )) 267 + then 268 + echo "Leader sampling [No sample generated]" 269 + err=1 270 + return 271 + fi 272 + isok=$(bc <<< "scale=2; if (($invalid_counts/$total_counts) < (1-$tolerance_rate)) { 0 } else { 1 };") 273 + if [ $isok -eq 1 ] 274 + then 275 + echo "Leader sampling [Failed inconsistent cycles count]" 276 + err=1 277 + else 278 + echo "Basic leader sampling test [Success]" 279 + fi 259 280 } 260 281 261 282 test_topdown_leader_sampling() {