linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PING PATCH v3] perf test: Allow tolerance for leader sampling test
@ 2025-04-22 11:06 Thomas Richter
  2025-04-30 12:56 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Richter @ 2025-04-22 11:06 UTC (permalink / raw)
  To: linux-kernel, linux-s390, linux-perf-users, acme, namhyung,
	ctshao, irogers
  Cc: agordeev, gor, sumanthk, hca, Thomas Richter

V3: Added check for missing samples as suggested by Chun-Tse.
V2: Changed bc invocation to return 0 on success and 1 on error.

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

Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Suggested-by: Ian Rogers <irogers@google.com>
Suggested-by: Thomas Richter <tmricht@linux.ibm.com>
Tested-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
---
 tools/perf/tests/shell/record.sh | 33 ++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index ba8d873d3ca7..0075ffe783ad 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -238,22 +238,43 @@ test_leader_sampling() {
     err=1
     return
   fi
+  perf script -i "${perfdata}" | grep brstack > $script_output
+  # Check if the two instruction counts are equal in each record.
+  # However, the throttling code doesn't consider event grouping. During throttling, only the
+  # leader is stopped, causing the slave's counts significantly higher. To temporarily solve this,
+  # let's set the tolerance rate to 80%.
+  # TODO: Revert the code for tolerance once the throttling mechanism is fixed.
   index=0
-  perf script -i "${perfdata}" > $script_output
+  valid_counts=0
+  invalid_counts=0
+  tolerance_rate=0.8
   while IFS= read -r line
   do
-    # Check if the two instruction counts are equal in each record
     cycles=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="cycles:") print $(i-1)}')
     if [ $(($index%2)) -ne 0 ] && [ ${cycles}x != ${prev_cycles}x ]
     then
-      echo "Leader sampling [Failed inconsistent cycles count]"
-      err=1
-      return
+      invalid_counts=$(($invalid_counts+1))
+    else
+      valid_counts=$(($valid_counts+1))
     fi
     index=$(($index+1))
     prev_cycles=$cycles
   done < $script_output
-  echo "Basic leader sampling test [Success]"
+  total_counts=$(bc <<< "$invalid_counts+$valid_counts")
+  if (( $(bc <<< "$total_counts <= 0") ))
+  then
+    echo "Leader sampling [No sample generated]"
+    err=1
+    return
+  fi
+  isok=$(bc <<< "scale=2; if (($invalid_counts/$total_counts) < (1-$tolerance_rate)) { 0 } else { 1 };")
+  if [ $isok -eq 1 ]
+  then
+     echo "Leader sampling [Failed inconsistent cycles count]"
+     err=1
+  else
+    echo "Basic leader sampling test [Success]"
+  fi
 }
 
 test_topdown_leader_sampling() {
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PING PATCH v3] perf test: Allow tolerance for leader sampling test
  2025-04-22 11:06 [PING PATCH v3] perf test: Allow tolerance for leader sampling test Thomas Richter
@ 2025-04-30 12:56 ` Arnaldo Carvalho de Melo
  2025-04-30 14:00   ` Thomas Richter
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-04-30 12:56 UTC (permalink / raw)
  To: Thomas Richter
  Cc: linux-kernel, linux-s390, linux-perf-users, namhyung, ctshao,
	irogers, agordeev, gor, sumanthk, hca

On Tue, Apr 22, 2025 at 01:06:43PM +0200, Thomas Richter wrote:
> V3: Added check for missing samples as suggested by Chun-Tse.
> V2: Changed bc invocation to return 0 on success and 1 on error.
 
> 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
 
> Signed-off-by: Chun-Tse Shao <ctshao@google.com>
> Suggested-by: Ian Rogers <irogers@google.com>
> Suggested-by: Thomas Richter <tmricht@linux.ibm.com>
> Tested-by: Thomas Richter <tmricht@linux.ibm.com>
> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>

This doesn't apply to perf-tools-next:

⬢ [acme@toolbx perf-tools-next]$        git am ./v3_20250422_tmricht_perf_test_allow_tolerance_for_leader_sampling_test.mbx
Applying: perf test: Allow tolerance for leader sampling test
error: patch failed: tools/perf/tests/shell/record.sh:238
error: tools/perf/tests/shell/record.sh: patch does not apply
Patch failed at 0001 perf test: Allow tolerance for leader sampling test
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
⬢ [acme@toolbx perf-tools-next]$

Are you proposing this for perf-tools, i.e. for this release cycles?

Namhyung, what do you think?

I think it is not applying in perf-tools-next due to this patch that
isn't in perf-tools:

⬢ [acme@toolbx perf-tools-next]$ git log --oneline -5 perf-tools-next/perf-tools-next tools/perf/tests/shell/record.sh
be8aefad33760dd8 perf tests record: Cleanup improvements <<<<<<<<<<<<<<<<<<<<<<<<<<<<
90d97674d4ad0166 perf test: Use cycles event in perf record test for leader_sampling
859199431d768091 perf test: Fix perf record test for precise_max
180fd0c1eac7cd8c perf tests: Make leader sampling test work without branch event
2532be3d219d8819 perf test: Tag parallel failing shell tests with "(exclusive)"
⬢ [acme@toolbx perf-tools-next]$

⬢ [acme@toolbx perf-tools-next]$ git log --oneline -5 perf-tools/perf-tools tools/perf/tests/shell/record.sh
90d97674d4ad0166 perf test: Use cycles event in perf record test for leader_sampling
859199431d768091 perf test: Fix perf record test for precise_max
180fd0c1eac7cd8c perf tests: Make leader sampling test work without branch event
2532be3d219d8819 perf test: Tag parallel failing shell tests with "(exclusive)"
36fae9f93e5f00eb perf test: Add precise_max subtest to the perf record shell test
⬢ [acme@toolbx perf-tools-next]$

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PING PATCH v3] perf test: Allow tolerance for leader sampling test
  2025-04-30 12:56 ` Arnaldo Carvalho de Melo
@ 2025-04-30 14:00   ` Thomas Richter
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Richter @ 2025-04-30 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-s390, linux-perf-users, namhyung, ctshao,
	irogers, agordeev, gor, sumanthk, hca

On 4/30/25 14:56, Arnaldo Carvalho de Melo wrote:
> On Tue, Apr 22, 2025 at 01:06:43PM +0200, Thomas Richter wrote:
>> V3: Added check for missing samples as suggested by Chun-Tse.
>> V2: Changed bc invocation to return 0 on success and 1 on error.
>  
>> 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
>  
>> Signed-off-by: Chun-Tse Shao <ctshao@google.com>
>> Suggested-by: Ian Rogers <irogers@google.com>
>> Suggested-by: Thomas Richter <tmricht@linux.ibm.com>
>> Tested-by: Thomas Richter <tmricht@linux.ibm.com>
>> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
> 
> This doesn't apply to perf-tools-next:
> 
> ⬢ [acme@toolbx perf-tools-next]$        git am ./v3_20250422_tmricht_perf_test_allow_tolerance_for_leader_sampling_test.mbx
> Applying: perf test: Allow tolerance for leader sampling test
> error: patch failed: tools/perf/tests/shell/record.sh:238
> error: tools/perf/tests/shell/record.sh: patch does not apply
> Patch failed at 0001 perf test: Allow tolerance for leader sampling test
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> hint: When you have resolved this problem, run "git am --continue".
> hint: If you prefer to skip this patch, run "git am --skip" instead.
> hint: To restore the original branch and stop patching, run "git am --abort".
> hint: Disable this message with "git config set advice.mergeConflict false"
> ⬢ [acme@toolbx perf-tools-next]$
> 
> Are you proposing this for perf-tools, i.e. for this release cycles?
> 
> Namhyung, what do you think?
> 
>

It would be good if this could go onto linux-next. However I noticed
this patch does not apply anymore on that tree. I will send updated
patch as version 4.

Thanks a lot

-- 
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH

Vorsitzender des Aufsichtsrats: Wolfgang Wendt

Geschäftsführung: David Faller

Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-30 14:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 11:06 [PING PATCH v3] perf test: Allow tolerance for leader sampling test Thomas Richter
2025-04-30 12:56 ` Arnaldo Carvalho de Melo
2025-04-30 14:00   ` Thomas Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).