This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ping: [v2][PATCH] Framework for performance benchmarking offunctions


On Thu, 2013-01-17 at 10:23 +0530, Siddhesh Poyarekar wrote:
> Ping!
> 
> On Fri, Jan 11, 2013 at 12:28:46PM +0530, Siddhesh Poyarekar wrote:
> > Hi,
> > 
> > Here's an updated version of this patch.  The programs were not using
> > the built libraries and were instead using the system libraries.
> > 
> > Siddhesh
> > 
> > 	* Makefile.in (bench): New target.
> > 	* Rules (bench): Likewise.
> > 	(binaries-bench): Generate binaries for functions to
> > 	benchmark.
> > 	* benchtests/Makefile: New makefile for benchmark tests.
> > 	* benchtests/bench-skeleton.c: New skeleton file for benchmark
> > 	programs.
> > 	* benchtests/exp-inputs: New input file for EXP function.
> > 	* benchtests/pow-inputs: New input file for POW function.
> > 	* scripts/bench.pl: New script to generate source files for
> > 	benchmark programs.
> >  
> > 
> > diff --git a/Makefile.in b/Makefile.in
> > index d73a78f..df75b8f 100644
> > --- a/Makefile.in
> > +++ b/Makefile.in
> > @@ -3,7 +3,7 @@ srcdir = @srcdir@
> >  # Uncomment the line below if you want to do parallel build.
> >  # PARALLELMFLAGS = -j 4
> >  
> > -.PHONY: all install
> > +.PHONY: all install bench
> >  
> >  all .DEFAULT:
> >  	$(MAKE) -r PARALLELMFLAGS="$(PARALLELMFLAGS)" -C $(srcdir) objdir=`pwd` $@
> > @@ -11,3 +11,6 @@ all .DEFAULT:
> >  install:
> >  	LANGUAGE=C LC_ALL=C; export LANGUAGE LC_ALL; \
> >  	$(MAKE) -r PARALLELMFLAGS="$(PARALLELMFLAGS)" -C $(srcdir) objdir=`pwd` $@
> > +
> > +bench:
> > +	$(MAKE) -C $(srcdir)/benchtests $(PARALLELMFLAGS) objdir=`pwd` $@
> > diff --git a/Rules b/Rules
> > index 5c5aa60..ff35d4e 100644
> > --- a/Rules
> > +++ b/Rules
> > @@ -83,7 +83,7 @@ common-generated += dummy.o dummy.c
> >  
> >  # This makes all the auxiliary and test programs.
> >  
> > -.PHONY: others tests
> > +.PHONY: others tests bench
> >  ifeq ($(multi-arch),no)
> >  tests := $(filter-out $(tests-ifunc), $(tests))
> >  xtests := $(filter-out $(xtests-ifunc), $(xtests))
> > @@ -191,6 +191,31 @@ $(objpfx)%.out: /dev/null $(objpfx)%	# Make it 2nd arg for canned sequence.
> >  	$(make-test-out) > $@
> >  
> >  endif	# tests
> > +
> > +# Build and run benchmark programs.
> > +binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
> > +
> > +run-bench = $(test-wrapper-env) \
> > +	    GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
> > +	    $($*-ENV) $(run-via-rtld-prefix) $${run}
> > +
> > +bench: $(binaries-bench)
> > +	if [ -f $(objpfx)bench.out ]; then \
> > +	  mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
> > +	fi
> > +	for run in $^; do \
> > +	  $(run-bench) >>  $(objpfx)bench.out; \
> > +	done
> > +
> > +$(binaries-bench): %: %.o \
> > +  $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
> > +  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
> > +	$(+link)
> > +
> > +$(objpfx)bench-%.c: %-inputs bench-skeleton.c
> > +	$(..)scripts/bench.pl $(patsubst %-inputs,%,$<) \
> > +	  $($*-ITER) $($*-ARGLIST) $($*-RET) > $@
> > +
> >  
> >  .PHONY: distclean realclean subdir_distclean subdir_realclean \
> >  	subdir_clean subdir_mostlyclean subdir_testclean
> > diff --git a/benchtests/Makefile b/benchtests/Makefile
> > new file mode 100644
> > index 0000000..7e514f0
> > --- /dev/null
> > +++ b/benchtests/Makefile
> > @@ -0,0 +1,57 @@
> > +# Copyright (C) 2013 Free Software Foundation, Inc.
> > +# This file is part of the GNU C Library.
> > +
> > +# The GNU C Library is free software; you can redistribute it and/or
> > +# modify it under the terms of the GNU Lesser General Public
> > +# License as published by the Free Software Foundation; either
> > +# version 2.1 of the License, or (at your option) any later version.
> > +
> > +# The GNU C Library is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > +# Lesser General Public License for more details.
> > +
> > +# You should have received a copy of the GNU Lesser General Public
> > +# License along with the GNU C Library; if not, see
> > +# <http://www.gnu.org/licenses/>.
> > +
> > +
> > +# Makefile for benchmark tests.  The only useful target here is `bench`.
> > +
> > +# Adding a new function `foo`:
> > +# ---------------------------
> > +
> > +# - Append the function name to the bench variable
> > +
> > +# - Define foo-ITER with the number of iterations you want to run
> > +
> > +# - Define foo-ARGLIST as a colon separated list of types of the input
> > +#   arguments.  Use `void` if function does not take any inputs.  Put in quotes
> > +#   if the input argument is a pointer, e.g.:
> > +
> > +#      malloc-ARGLIST: "void *"
> > +
> > +# - Define foo-RET as the type the function returns.  Skip if the function
> > +#   returns void.  One could even skip foo-ARGLIST if the function does not
> > +#   take any inputs AND the function returns void.
> > +
> > +
> > +# - Make a file called `foo-inputs` with one input value per line, an input
> > +#   being a comma separated list of arguments to be passed into the function.
> > +#   See pow-inputs for an example.
> > +
> > +subdir := benchtests
> > +bench := exp pow
> > +
> > +exp-ITER = 100000
> > +exp-ARGLIST = double
> > +exp-RET = double
> > +LDFLAGS-bench-exp = -lm
> > +
> > +pow-ITER = 100000
> > +pow-ARGLIST = double:double
> > +pow-RET = double
> > +LDFLAGS-bench-pow = -lm
> > +
> > +include ../Makeconfig
> > +include ../Rules
> > diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c
> > new file mode 100644
> > index 0000000..1dd1de7
> > --- /dev/null
> > +++ b/benchtests/bench-skeleton.c
> > @@ -0,0 +1,57 @@
> > +/* Skeleton for benchmark programs.
> > +   Copyright (C) 2013 Free Software Foundation, Inc.
> > +   This file is part of the GNU C Library.
> > +
> > +   The GNU C Library is free software; you can redistribute it and/or
> > +   modify it under the terms of the GNU Lesser General Public
> > +   License as published by the Free Software Foundation; either
> > +   version 2.1 of the License, or (at your option) any later version.
> > +
> > +   The GNU C Library is distributed in the hope that it will be useful,
> > +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > +   Lesser General Public License for more details.
> > +
> > +   You should have received a copy of the GNU Lesser General Public
> > +   License along with the GNU C Library; if not, see
> > +   <http://www.gnu.org/licenses/>.  */
> > +
> > +#include <string.h>
> > +#include <stdint.h>
> > +#include <stdio.h>
> > +#include <time.h>
> > +
> > +int
> > +main (int argc, char **argv)
> > +{
> > +  int i, j;
> > +  int64_t total = 0, max = 0, min = 0x7fffffffffffffff;
> > +  struct timespec start, end;
> > +
> > +  memset (&start, 0, sizeof (start));
> > +  memset (&end, 0, sizeof (end));
> > +
> > +  for (i = 0; i < ITER; i++)
> > +    {
> > +      for (j = 0; j < NUM_SAMPLES; j++)
> > +	{
> > +	  clock_gettime (CLOCK_MONOTONIC_RAW, &start);
> > +	  BENCH_FUNC(j);
> > +	  clock_gettime (CLOCK_MONOTONIC_RAW, &end);
> > +

On many platforms clock_gettime() still requires a system call, which is
swamp the measurement you are trying to make.

You need to make sure there are enough iterations within the BENCH_FUCC
so that the clock_gettime(0 overhead is less then 1% of the total.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]