This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Preheat CPU in benchtests
- From: Andrew Pinski <pinskia at gmail dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 23 Apr 2013 00:25:38 -0700
- Subject: Re: [PATCH] Preheat CPU in benchtests
- References: <20130423061028 dot GA6257 at domone dot kolej dot mff dot cuni dot cz>
On Mon, Apr 22, 2013 at 11:10 PM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> Hi,
>
> Benchmarks now are affected by cpu scaling when initialy run at low
> frequency.
>
> Following benchmark runs nonsensial loop first to ensure that benchmark
> are measured at maximal frequency. This greatly cuts time needed to
> get accurate results.
>
> Ondra
>
> * benchtests/bench-skeleton.c (main): Preheat CPU.
>
> ---
> benchtests/bench-skeleton.c | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c
> index 13f986d..08d7c20 100644
> --- a/benchtests/bench-skeleton.c
> +++ b/benchtests/bench-skeleton.c
> @@ -21,6 +21,9 @@
> #include <stdio.h>
> #include <time.h>
> #include <inttypes.h>
> +#include <math.h>
> +
> +double dontoptimize = 0.0;
I think you should also mark this variable as volatile so that GCC
does not remove it as unused in the end.
Thanks,
Andrew
>
> int
> main (int argc, char **argv)
> @@ -29,6 +32,12 @@ main (int argc, char **argv)
> uint64_t total = 0, max = 0, min = 0x7fffffffffffffff;
> struct timespec start, end;
>
> + /* This loop should cause CPU switch to maximal freqency. This makes
> + subsequent measurement more accurate. We need side effect to avoid loop
> + being deleted by compiler. */
> + for(k = 0; k < 1000000; k++)
> + dontoptimize += exp(k);
> +
> memset (&start, 0, sizeof (start));
> memset (&end, 0, sizeof (end));
>
> --
> 1.7.4.4
>
On Mon, Apr 22, 2013 at 11:10 PM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> Hi,
>
> Benchmarks now are affected by cpu scaling when initialy run at low
> frequency.
>
> Following benchmark runs nonsensial loop first to ensure that benchmark
> are measured at maximal frequency. This greatly cuts time needed to
> get accurate results.
>
> Ondra
>
> * benchtests/bench-skeleton.c (main): Preheat CPU.
>
> ---
> benchtests/bench-skeleton.c | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c
> index 13f986d..08d7c20 100644
> --- a/benchtests/bench-skeleton.c
> +++ b/benchtests/bench-skeleton.c
> @@ -21,6 +21,9 @@
> #include <stdio.h>
> #include <time.h>
> #include <inttypes.h>
> +#include <math.h>
> +
> +double dontoptimize = 0.0;
>
> int
> main (int argc, char **argv)
> @@ -29,6 +32,12 @@ main (int argc, char **argv)
> uint64_t total = 0, max = 0, min = 0x7fffffffffffffff;
> struct timespec start, end;
>
> + /* This loop should cause CPU switch to maximal freqency. This makes
> + subsequent measurement more accurate. We need side effect to avoid loop
> + being deleted by compiler. */
> + for(k = 0; k < 1000000; k++)
> + dontoptimize += exp(k);
> +
> memset (&start, 0, sizeof (start));
> memset (&end, 0, sizeof (end));
>
> --
> 1.7.4.4
>