Converted benchmark to benchtest.

Message ID 20140503104831.GA16118@domone.podge
State Superseded
Headers

Commit Message

Ondrej Bilka May 3, 2014, 10:48 a.m. UTC
  On Fri, May 02, 2014 at 02:33:03PM +0200, Torvald Riegel wrote:
> On Tue, 2014-04-29 at 19:13 -0400, Carlos O'Donell wrote:
> > On 04/18/2014 05:12 PM, Andi Kleen wrote:
> > > Andi Kleen <andi@firstfloor.org> writes:
> > > 
> > >> "Carlos O'Donell" <carlos@redhat.com> writes:
> > >>>
> > >>> That's right. I'd like to see the whatever code was used to benchmark
> > >>> the performance submitted as a microbenchmark so I can run it myself
> > >>> and verify. Again, it's not that I don't trust Andi, but an objective
> > >>> evaluation is always going to be the best defense for these changes.
> > >>
> > >> Here is the code I used:
> > > 
> > > Any comments now? Is the code ok to commit now?
> 
> I've seen a few minor issues (see reply to patch).
> 
> > > If yes please someone with access rights commit it.
> > 
> > Sorry, April is busy.
> > 
> > Torvlad, Have you had a chance to look at this?
> 
> Someone needs to put this benchmark into benchtest form.  (Otherwise, we
> won't fulfill your requirement of having microbenchmarks...)
>

Here is benchtest conversion. It really does not add new data so can you
say now that dropping assembly really makes no difference?

> We could also consider adding a scalability benchtest for the rwlock,
> and using the single thread data from it to compare.  That's on my list
> of things to do, but haven't gotten to this yet.

Its nice to have but orthogonal on proposed change, so it should not
block this patch


	* benchtests/Makefile (bench-pthread): Add rwlock.
	* benchtests/bench-rwlock.c: New file.

---
 benchtests/Makefile       |  2 +-
 benchtests/bench-rwlock.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 benchtests/bench-rwlock.c
  

Comments

Ondrej Bilka June 5, 2014, 11:58 a.m. UTC | #1
Ping

On Sat, May 03, 2014 at 12:48:31PM +0200, Ondřej Bílka wrote:
> On Fri, May 02, 2014 at 02:33:03PM +0200, Torvald Riegel wrote:
> > On Tue, 2014-04-29 at 19:13 -0400, Carlos O'Donell wrote:
> > > On 04/18/2014 05:12 PM, Andi Kleen wrote:
> > > > Andi Kleen <andi@firstfloor.org> writes:
> > > > 
> > > >> "Carlos O'Donell" <carlos@redhat.com> writes:
> > > >>>
> > > >>> That's right. I'd like to see the whatever code was used to benchmark
> > > >>> the performance submitted as a microbenchmark so I can run it myself
> > > >>> and verify. Again, it's not that I don't trust Andi, but an objective
> > > >>> evaluation is always going to be the best defense for these changes.
> > > >>
> > > >> Here is the code I used:
> > > > 
> > > > Any comments now? Is the code ok to commit now?
> > 
> > I've seen a few minor issues (see reply to patch).
> > 
> > > > If yes please someone with access rights commit it.
> > > 
> > > Sorry, April is busy.
> > > 
> > > Torvlad, Have you had a chance to look at this?
> > 
> > Someone needs to put this benchmark into benchtest form.  (Otherwise, we
> > won't fulfill your requirement of having microbenchmarks...)
> >
> 
> Here is benchtest conversion. It really does not add new data so can you
> say now that dropping assembly really makes no difference?
> 
> > We could also consider adding a scalability benchtest for the rwlock,
> > and using the single thread data from it to compare.  That's on my list
> > of things to do, but haven't gotten to this yet.
> 
> Its nice to have but orthogonal on proposed change, so it should not
> block this patch
> 
> 
> 	* benchtests/Makefile (bench-pthread): Add rwlock.
> 	* benchtests/bench-rwlock.c: New file.
> 
> ---
>  benchtests/Makefile       |  2 +-
>  benchtests/bench-rwlock.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 57 insertions(+), 1 deletion(-)
>  create mode 100644 benchtests/bench-rwlock.c
> 
> diff --git a/benchtests/Makefile b/benchtests/Makefile
> index a0954cd..67fa507 100644
> --- a/benchtests/Makefile
> +++ b/benchtests/Makefile
> @@ -25,7 +25,7 @@ include ../Makeconfig
>  bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 ffs ffsll \
>  	      log log2 modf pow rint sin sincos sinh sqrt tan tanh
>  
> -bench-pthread := pthread_once
> +bench-pthread := pthread_once rwlock
>  
>  bench := $(bench-math) $(bench-pthread)
>  
> diff --git a/benchtests/bench-rwlock.c b/benchtests/bench-rwlock.c
> new file mode 100644
> index 0000000..cc68f97
> --- /dev/null
> +++ b/benchtests/bench-rwlock.c
> @@ -0,0 +1,56 @@
> +#include <pthread.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +#include "bench-timing.h"
> +
> +
> +pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
> +
> +#define ITER 100
> +
> +int
> +main (void)
> +{
> +  int i, j;
> +
> +  timing_t start, end, cur;
> +  for (j = 0; j < 50; j++)
> +    {
> +      pthread_rwlock_rdlock (&rwlock);
> +      pthread_rwlock_unlock (&rwlock);
> +
> +      pthread_rwlock_wrlock (&rwlock);
> +      pthread_rwlock_unlock (&rwlock);
> +
> +      TIMING_NOW (start);
> +      for (i = 0; i < ITER; i++)
> +	{
> +	  pthread_rwlock_rdlock (&rwlock);
> +	  pthread_rwlock_unlock (&rwlock);
> +	}
> +      TIMING_NOW (end);
> +
> +      if (j > 0)
> +	{
> +	  printf ("\nrdlock avg");
> +	  TIMING_DIFF (cur, start, end);
> +	  TIMING_PRINT_MEAN ((double) cur, (double) ITER);
> +	}
> +
> +      TIMING_NOW (start);
> +      for (i = 0; i < ITER; i++)
> +	{
> +	  pthread_rwlock_wrlock (&rwlock);
> +	  pthread_rwlock_unlock (&rwlock);
> +	}
> +      TIMING_NOW (end);
> +
> +      if (j > 0)
> +	{
> +	  printf ("\nwrlock avg");
> +	  TIMING_DIFF (cur, start, end);
> +	  TIMING_PRINT_MEAN ((double) cur, (double) ITER);
> +	}
> +    }
> +  return 0;
> +}
> -- 
> 1.8.4.rc3
  

Patch

diff --git a/benchtests/Makefile b/benchtests/Makefile
index a0954cd..67fa507 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -25,7 +25,7 @@  include ../Makeconfig
 bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 ffs ffsll \
 	      log log2 modf pow rint sin sincos sinh sqrt tan tanh
 
-bench-pthread := pthread_once
+bench-pthread := pthread_once rwlock
 
 bench := $(bench-math) $(bench-pthread)
 
diff --git a/benchtests/bench-rwlock.c b/benchtests/bench-rwlock.c
new file mode 100644
index 0000000..cc68f97
--- /dev/null
+++ b/benchtests/bench-rwlock.c
@@ -0,0 +1,56 @@ 
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "bench-timing.h"
+
+
+pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+#define ITER 100
+
+int
+main (void)
+{
+  int i, j;
+
+  timing_t start, end, cur;
+  for (j = 0; j < 50; j++)
+    {
+      pthread_rwlock_rdlock (&rwlock);
+      pthread_rwlock_unlock (&rwlock);
+
+      pthread_rwlock_wrlock (&rwlock);
+      pthread_rwlock_unlock (&rwlock);
+
+      TIMING_NOW (start);
+      for (i = 0; i < ITER; i++)
+	{
+	  pthread_rwlock_rdlock (&rwlock);
+	  pthread_rwlock_unlock (&rwlock);
+	}
+      TIMING_NOW (end);
+
+      if (j > 0)
+	{
+	  printf ("\nrdlock avg");
+	  TIMING_DIFF (cur, start, end);
+	  TIMING_PRINT_MEAN ((double) cur, (double) ITER);
+	}
+
+      TIMING_NOW (start);
+      for (i = 0; i < ITER; i++)
+	{
+	  pthread_rwlock_wrlock (&rwlock);
+	  pthread_rwlock_unlock (&rwlock);
+	}
+      TIMING_NOW (end);
+
+      if (j > 0)
+	{
+	  printf ("\nwrlock avg");
+	  TIMING_DIFF (cur, start, end);
+	  TIMING_PRINT_MEAN ((double) cur, (double) ITER);
+	}
+    }
+  return 0;
+}