linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors
@ 2023-09-19 15:02 vmolnaro
  2023-09-19 15:02 ` [PATCH 2/2] perf test lock_contention.sh: Skip test if not enough CPUs vmolnaro
  2023-09-20 10:57 ` [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors Michael Petlan
  0 siblings, 2 replies; 5+ messages in thread
From: vmolnaro @ 2023-09-19 15:02 UTC (permalink / raw)
  To: vmolnaro, linux-perf-users, acme, acme; +Cc: mpetlan

From: Veronika Molnarova <vmolnaro@redhat.com>

The test was failing in specific scenarios due to imperfection of FP
arithmetics. The `bc` command wasn't correctly rounding the result of
division causing the failure.

Replace the `bc` with `awk` which should work with more decimal places
and add a threshold to catch any possible rounding errors.  The
acceptable rounding error is set to 0.01 when the test passes with a
warning message.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
---
Resending the patches with sign-off as it didn't go through last time,
also tried to fix the found issues.

 tools/perf/tests/shell/stat+shadow_stat.sh | 30 +++++++++++++++++-----
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/tools/perf/tests/shell/stat+shadow_stat.sh b/tools/perf/tests/shell/stat+shadow_stat.sh
index 0e9cba84e75..6be3b4f80e5 100755
--- a/tools/perf/tests/shell/stat+shadow_stat.sh
+++ b/tools/perf/tests/shell/stat+shadow_stat.sh
@@ -4,6 +4,8 @@
 
 set -e
 
+THRESHOLD=0.015
+
 # skip if system-wide mode is forbidden
 perf stat -a true > /dev/null 2>&1 || exit 2
 
@@ -33,10 +35,18 @@ test_global_aggr()
 		fi
 
 		# use printf for rounding and a leading zero
-		res=`printf "%.2f" "$(echo "scale=6; $num / $cyc" | bc -q)"`
+		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
 		if [ "$ipc" != "$res" ]; then
-			echo "IPC is different: $res != $ipc  ($num / $cyc)"
-			exit 1
+			# check the difference from the real result for FP imperfections
+			diff=`echo $ipc $res $THRESHOLD | \
+			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
+
+			if [ $diff -eq 1 ]; then
+				echo "IPC is different: $res != $ipc  ($num / $cyc)"
+				exit 1
+			fi
+
+			echo "Warning: Difference of IPC is under the threshold"
 		fi
 	done
 }
@@ -67,10 +77,18 @@ test_no_aggr()
 		fi
 
 		# use printf for rounding and a leading zero
-		res=`printf "%.2f" "$(echo "scale=6; $num / $cyc" | bc -q)"`
+		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
 		if [ "$ipc" != "$res" ]; then
-			echo "IPC is different for $cpu: $res != $ipc  ($num / $cyc)"
-			exit 1
+			# check difference from the real result for FP imperfections
+			diff=`echo $ipc $res $THRESHOLD | \
+			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
+
+			if [ $diff -eq 1 ]; then
+				echo "IPC is different: $res != $ipc  ($num / $cyc)"
+				exit 1
+			fi
+
+			echo "Warning: Difference of IPC is under the threshold"
 		fi
 	done
 }
-- 
2.41.0


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

* [PATCH 2/2] perf test lock_contention.sh: Skip test if not enough CPUs
  2023-09-19 15:02 [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors vmolnaro
@ 2023-09-19 15:02 ` vmolnaro
  2023-09-20 10:57   ` Michael Petlan
  2023-09-20 10:57 ` [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors Michael Petlan
  1 sibling, 1 reply; 5+ messages in thread
From: vmolnaro @ 2023-09-19 15:02 UTC (permalink / raw)
  To: vmolnaro, linux-perf-users, acme, acme; +Cc: mpetlan

From: Veronika Molnarova <vmolnaro@redhat.com>

Machines with less then 4 CPUs weren't consistently triggering lock
events required for the test.

Skip the test on those machines. The limit of 4 CPUs is set as it
generates around 100 lock events for a test.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
---
Resending the patches with sign-off as it didn't go through last time, 
also tried to fix the found issues.

 tools/perf/tests/shell/lock_contention.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
index f2cc187b618..768c10f1d6b 100755
--- a/tools/perf/tests/shell/lock_contention.sh
+++ b/tools/perf/tests/shell/lock_contention.sh
@@ -32,6 +32,12 @@ check() {
 		err=2
 		exit
 	fi
+
+	if [ `nproc` -lt 4 ]; then
+		echo "[Skip] Low number of CPUs (`nproc`), lock event cannot be triggered certainly"
+		err=2
+		exit
+	fi
 }
 
 test_record()
-- 
2.41.0


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

* Re: [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors
  2023-09-19 15:02 [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors vmolnaro
  2023-09-19 15:02 ` [PATCH 2/2] perf test lock_contention.sh: Skip test if not enough CPUs vmolnaro
@ 2023-09-20 10:57 ` Michael Petlan
  2023-09-26 22:54   ` Namhyung Kim
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Petlan @ 2023-09-20 10:57 UTC (permalink / raw)
  To: vmolnaro; +Cc: linux-perf-users, acme, acme

On Tue, 19 Sep 2023, vmolnaro@redhat.com wrote:
> From: Veronika Molnarova <vmolnaro@redhat.com>
> 
> The test was failing in specific scenarios due to imperfection of FP
> arithmetics. The `bc` command wasn't correctly rounding the result of
> division causing the failure.
> 
> Replace the `bc` with `awk` which should work with more decimal places
> and add a threshold to catch any possible rounding errors.  The
> acceptable rounding error is set to 0.01 when the test passes with a
> warning message.
> 
> Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>

Acked-by: Michael Petlan <mpetlan@redhat.com>

> ---
> Resending the patches with sign-off as it didn't go through last time,
> also tried to fix the found issues.
> 
>  tools/perf/tests/shell/stat+shadow_stat.sh | 30 +++++++++++++++++-----
>  1 file changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/perf/tests/shell/stat+shadow_stat.sh b/tools/perf/tests/shell/stat+shadow_stat.sh
> index 0e9cba84e75..6be3b4f80e5 100755
> --- a/tools/perf/tests/shell/stat+shadow_stat.sh
> +++ b/tools/perf/tests/shell/stat+shadow_stat.sh
> @@ -4,6 +4,8 @@
>  
>  set -e
>  
> +THRESHOLD=0.015
> +
>  # skip if system-wide mode is forbidden
>  perf stat -a true > /dev/null 2>&1 || exit 2
>  
> @@ -33,10 +35,18 @@ test_global_aggr()
>  		fi
>  
>  		# use printf for rounding and a leading zero
> -		res=`printf "%.2f" "$(echo "scale=6; $num / $cyc" | bc -q)"`
> +		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
>  		if [ "$ipc" != "$res" ]; then
> -			echo "IPC is different: $res != $ipc  ($num / $cyc)"
> -			exit 1
> +			# check the difference from the real result for FP imperfections
> +			diff=`echo $ipc $res $THRESHOLD | \
> +			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
> +
> +			if [ $diff -eq 1 ]; then
> +				echo "IPC is different: $res != $ipc  ($num / $cyc)"
> +				exit 1
> +			fi
> +
> +			echo "Warning: Difference of IPC is under the threshold"
>  		fi
>  	done
>  }
> @@ -67,10 +77,18 @@ test_no_aggr()
>  		fi
>  
>  		# use printf for rounding and a leading zero
> -		res=`printf "%.2f" "$(echo "scale=6; $num / $cyc" | bc -q)"`
> +		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
>  		if [ "$ipc" != "$res" ]; then
> -			echo "IPC is different for $cpu: $res != $ipc  ($num / $cyc)"
> -			exit 1
> +			# check difference from the real result for FP imperfections
> +			diff=`echo $ipc $res $THRESHOLD | \
> +			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
> +
> +			if [ $diff -eq 1 ]; then
> +				echo "IPC is different: $res != $ipc  ($num / $cyc)"
> +				exit 1
> +			fi
> +
> +			echo "Warning: Difference of IPC is under the threshold"
>  		fi
>  	done
>  }
> -- 
> 2.41.0
> 
> 


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

* Re: [PATCH 2/2] perf test lock_contention.sh: Skip test if not enough CPUs
  2023-09-19 15:02 ` [PATCH 2/2] perf test lock_contention.sh: Skip test if not enough CPUs vmolnaro
@ 2023-09-20 10:57   ` Michael Petlan
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Petlan @ 2023-09-20 10:57 UTC (permalink / raw)
  To: vmolnaro; +Cc: linux-perf-users, acme, acme

On Tue, 19 Sep 2023, vmolnaro@redhat.com wrote:
> From: Veronika Molnarova <vmolnaro@redhat.com>
> 
> Machines with less then 4 CPUs weren't consistently triggering lock
> events required for the test.
> 
> Skip the test on those machines. The limit of 4 CPUs is set as it
> generates around 100 lock events for a test.
> 
> Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>

Acked-by: Michael Petlan <mpetlan@redhat.com>
> ---
> Resending the patches with sign-off as it didn't go through last time, 
> also tried to fix the found issues.
> 
>  tools/perf/tests/shell/lock_contention.sh | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
> index f2cc187b618..768c10f1d6b 100755
> --- a/tools/perf/tests/shell/lock_contention.sh
> +++ b/tools/perf/tests/shell/lock_contention.sh
> @@ -32,6 +32,12 @@ check() {
>  		err=2
>  		exit
>  	fi
> +
> +	if [ `nproc` -lt 4 ]; then
> +		echo "[Skip] Low number of CPUs (`nproc`), lock event cannot be triggered certainly"
> +		err=2
> +		exit
> +	fi
>  }
>  
>  test_record()
> -- 
> 2.41.0
> 
> 


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

* Re: [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors
  2023-09-20 10:57 ` [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors Michael Petlan
@ 2023-09-26 22:54   ` Namhyung Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2023-09-26 22:54 UTC (permalink / raw)
  To: Michael Petlan; +Cc: vmolnaro, linux-perf-users, acme, acme

On Wed, Sep 20, 2023 at 5:39 AM Michael Petlan <mpetlan@redhat.com> wrote:
>
> On Tue, 19 Sep 2023, vmolnaro@redhat.com wrote:
> > From: Veronika Molnarova <vmolnaro@redhat.com>
> >
> > The test was failing in specific scenarios due to imperfection of FP
> > arithmetics. The `bc` command wasn't correctly rounding the result of
> > division causing the failure.
> >
> > Replace the `bc` with `awk` which should work with more decimal places
> > and add a threshold to catch any possible rounding errors.  The
> > acceptable rounding error is set to 0.01 when the test passes with a
> > warning message.
> >
> > Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
>
> Acked-by: Michael Petlan <mpetlan@redhat.com>

Applied both to perf-tools-next, thanks!

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

end of thread, other threads:[~2023-09-26 22:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-19 15:02 [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors vmolnaro
2023-09-19 15:02 ` [PATCH 2/2] perf test lock_contention.sh: Skip test if not enough CPUs vmolnaro
2023-09-20 10:57   ` Michael Petlan
2023-09-20 10:57 ` [PATCH 1/2] perf test stat+shadow_stat.sh: Add threshold for rounding errors Michael Petlan
2023-09-26 22:54   ` Namhyung Kim

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).