glibc/benchtests/Makefile

146 lines
4.5 KiB
Makefile
Raw Normal View History

# Copyright (C) 2013-2014 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`.
2013-05-22 07:35:04 +02:00
# Add benchmark functions in alphabetical order.
subdir := benchtests
Consistently include Makeconfig after defining subdir. In <https://sourceware.org/ml/libc-alpha/2014-01/msg00196.html> I noted it was necessary to add includes of Makeconfig early in various subdirectory makefiles for the tests-special variable settings added by that patch to be conditional on configuration information. No-one commented on the general question there of whether Makeconfig should always be included immediately after the definition of subdir. This patch implements that early inclusion of Makeconfig in each directory (which is a lot easier than consistent placement of includes of Rules). Includes are added if needed, or moved up if already present. Subdirectory "all:" targets are removed, since Makeconfig provides one. There is potential for further cleanups I haven't done. Rules and Makerules have code such as ifneq "$(findstring env,$(origin headers))" "" headers := endif to override to empty any value of various variables that came from the environment. I think there is a case for Makeconfig setting all the subdirectory variables (other than subdir) to empty to ensure no outside value is going to take effect if a subdirectory fails to define a variable. (A list of such variables, possibly out of date and incomplete, is in manual/maint.texi.) Rules and Makerules would give errors if Makeconfig hadn't already been included, instead of including it themselves. The special code to override values coming from the environment would then be obsolete and could be removed. Tested x86_64, including that installed binaries are identical before and after the patch. * argp/Makefile: Include Makeconfig immediately after defining subdir. * assert/Makefile: Likewise. * benchtests/Makefile: Likewise. * catgets/Makefile: Likewise. * conform/Makefile: Likewise. * crypt/Makefile: Likewise. * csu/Makefile: Likewise. (all): Remove target. * ctype/Makefile: Include Makeconfig immediately after defining subdir. * debug/Makefile: Likewise. * dirent/Makefile: Likewise. * dlfcn/Makefile: Likewise. * gmon/Makefile: Likewise. * gnulib/Makefile: Likewise. * grp/Makefile: Likewise. * gshadow/Makefile: Likewise. * hesiod/Makefile: Likewise. * hurd/Makefile: Likewise. (all): Remove target. * iconvdata/Makefile: Include Makeconfig immediately after defining subdir. * inet/Makefile: Likewise. * intl/Makefile: Likewise. * io/Makefile: Likewise. * libio/Makefile: Likewise. (all): Remove target. * locale/Makefile: Include Makeconfig immediately after defining subdir. * login/Makefile: Likewise. * mach/Makefile: Likewise. (all): Remove target. * malloc/Makefile: Include Makeconfig immediately after defining subdir. (all): Remove target. * manual/Makefile: Include Makeconfig immediately after defining subdir. * math/Makefile: Likewise. * misc/Makefile: Likewise. * nis/Makefile: Likewise. * nss/Makefile: Likewise. * po/Makefile: Likewise. (all): Remove target. * posix/Makefile: Include Makeconfig immediately after defining subdir. * pwd/Makefile: Likewise. * resolv/Makefile: Likewise. * resource/Makefile: Likewise. * rt/Makefile: Likewise. * setjmp/Makefile: Likewise. * shadow/Makefile: Likewise. * signal/Makefile: Likewise. * socket/Makefile: Likewise. * soft-fp/Makefile: Likewise. * stdio-common/Makefile: Likewise. * stdlib/Makefile: Likewise. * streams/Makefile: Likewise. * string/Makefile: Likewise. * sunrpc/Makefile: Likewise. (all): Remove target. * sysvipc/Makefile: Include Makeconfig immediately after defining subdir. * termios/Makefile: Likewise. * time/Makefile: Likewise. * timezone/Makefile: Likewise. (all): Remove target. * wcsmbs/Makefile: Include Makeconfig immediately after defining subdir. * wctype/Makefile: Likewise. libidn/ChangeLog: * Makefile: Include Makeconfig immediately after defining subdir. localedata/ChangeLog: * Makefile: Include Makeconfig immediately after defining subdir. (all): Remove target. nptl/ChangeLog: * Makefile: Include Makeconfig immediately after defining subdir. nptl_db/ChangeLog: * Makefile: Include Makeconfig immediately after defining subdir.
2014-02-27 00:12:03 +01:00
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 := $(bench-math) $(bench-pthread)
2013-05-22 07:35:04 +02:00
# String function benchmarks.
string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
strcat strchr strchrnul strcmp strcpy strcspn strlen \
strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
2013-12-19 12:45:54 +01:00
strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
2013-11-26 12:48:33 +01:00
string-bench-all := $(string-bench)
2013-11-11 14:23:02 +01:00
stdlib-bench := strtod
benchset := $(string-bench-all) $(stdlib-bench)
CFLAGS-bench-ffs.c += -fno-builtin
CFLAGS-bench-ffsll.c += -fno-builtin
Use existing makefile variables for dependencies on glibc libraries. glibc's Makeconfig defines some variables such as $(libm) and $(libdl) for linking with libraries built by glibc, and nptl/Makeconfig (included by the toplevel Makeconfig) defines others such as $(shared-thread-library). In some places glibc's Makefiles use those variables when linking against the relevant libraries, but in other places they hardcode the location of the libraries in the build tree. This patch cleans up various places to use the variables that already exist (in the case of libm, replacing several duplicate definitions of a $(link-libm) variable in subdirectory Makefiles). (It's not necessarily exactly equivalent to what the existing code does - in particular, $(shared-thread-library) includes libpthread_nonshared, but is replacing places that just referred to libpthread.so. But I think that change is desirable on the general principle of linking things as close as possible to the way in which they would be linked with an installed library, unless there is a clear reason not to do so.) To support running tests with an installed copy of glibc without needing the full build tree from when that copy was built, I think it will be useful to use such variables more generally and systematically - every time the rules for building a test refer to some file from the build tree that's also installed by glibc, use a makefile variable so that the installed-testing case can point those variables to installed copies of the files. This patch just deals with straightforward cases where such variables already exist. It's quite possible some uses of $(shared-thread-library) should actually be a new $(thread-library) variable that's set appropriately in the --disable-shared case, if those uses would in fact work without shared libraries. I didn't change the status quo that those cases hardcode use of a shared library whether or not it's actually needed (but other uses such as $(libm) and $(libdl) would now get the static library if the shared library isn't built, when some previously hardcoded use of the shared library - if they actually need shared libraries, the test itself needs an enable-shared conditional anyway). Tested x86_64. * benchtests/Makefile ($(addprefix $(objpfx)bench-,$(bench-math))): Depend on $(libm), not $(common-objpfx)math/libm.so. ($(addprefix $(objpfx)bench-,$(bench-pthread))): Depend on $(shared-thread-library), not $(common-objpfx)nptl/libpthread.so. * elf/Makefile ($(objpfx)noload): Depend on $(libdl), not $(common-objpfx)dlfcn/libdl.so. ($(objpfx)tst-audit8): Depend on $(libm), not $(common-objpfx)math/libm.so. * malloc/Makefile ($(objpfx)libmemusage.so): Depend on $(libdl), not $(common-objpfx)dlfcn/libdl.so. * math/Makefile ($(addprefix $(objpfx),$(filter-out $(tests-static),$(tests)))): Depend on $(libm), not $(objpfx)libm.so. Do not condition on [$(build-shared) = yes]. ($(objpfx)test-fenv-tls): Depend on $(shared-thread-library), not $(common-objpfx)nptl/libpthread.so. * misc/Makefile ($(objpfx)tst-tsearch): Depend on $(libm), not $(common-objpfx)math/libm.so$(libm.so-version) or $(common-objpfx)math/libm.a depending on [$(build-shared) = yes]. * nptl/Makefile ($(objpfx)tst-unload): Depend on $(libdl), not $(common-objpfx)dlfcn/libdl.so. * setjmp/Makefile (link-libm): Remove variable. ($(objpfx)tst-setjmp-fp): Depend on $(libm), not $(link-libm). * stdio-common/Makefile (link-libm): Remove variable. ($(objpfx)tst-printf-round): Depend on $(libm), not $(link-libm). * stdlib/Makefile (link-libm): Remove variable. ($(objpfx)bug-getcontext): Depend on $(libm), not $(link-libm). ($(objpfx)tst-strtod-round): Likewise. ($(objpfx)tst-tininess): Likewise. ($(objpfx)tst-strtod-underflow): Likewise. ($(objpfx)tst-strtod6): Likewise. ($(objpfx)tst-tls-atexit): Depend on $(shared-thread-library) and $(libdl), not $(common-objpfx)nptl/libpthread.so and $(common-objpfx)dlfcn/libdl.so.
2014-05-16 23:38:08 +02:00
$(addprefix $(objpfx)bench-,$(bench-math)): $(libm)
$(addprefix $(objpfx)bench-,$(bench-pthread)): $(shared-thread-library)
2013-09-19 13:25:27 +02:00
# Rules to build and execute the benchmarks. Do not put any benchmark
# parameters beyond this point.
# We don't want the benchmark programs to run in parallel since that could
# affect their performance.
.NOTPARALLEL:
include ../Rules
binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
# The default duration: 10 seconds.
ifndef BENCH_DURATION
BENCH_DURATION := 10
endif
CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION)
# Use clock_gettime to measure performance of functions. The default is to use
# HP_TIMING if it is available.
ifdef USE_CLOCK_GETTIME
CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
endif
DETAILED_OPT :=
ifdef DETAILED
DETAILED_OPT := -d
endif
# This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
# for all these modules.
cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c)
lib := nonlib
include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
extra-objs += json-lib.o
bench-deps := bench-skeleton.c bench-timing.h Makefile
run-bench = $(test-wrapper-env) \
GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
$($*-ENV) $(rtld-prefix) $${run}
timing-type := $(objpfx)bench-timing-type
2013-04-16 10:37:21 +02:00
bench-clean:
rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
rm -f $(timing-type) $(addsuffix .o,$(timing-type))
bench: $(timing-type) bench-set bench-func
bench-set: $(binaries-benchset)
for run in $^; do \
echo "Running $${run}"; \
$(run-bench) > $${run}.out; \
done
2013-04-16 10:37:21 +02:00
# Build and execute the benchmark functions. This target generates JSON
# formatted bench.out. Each of the programs produce independent JSON output,
# so one could even execute them individually and process it using any JSON
# capable language or tool.
bench-func: $(binaries-bench)
{ timing_type=$$($(timing-type)); \
echo "{\"timing_type\": \"$${timing_type}\","; \
echo " \"functions\": {"; \
for run in $^; do \
if ! [ "x$${run}" = "x$<" ]; then \
echo ","; \
fi; \
echo "Running $${run}" >&2; \
$(run-bench) $(DETAILED_OPT); \
done; \
echo; \
echo " }"; \
echo "}"; } > $(objpfx)bench.out-tmp; \
if [ -f $(objpfx)bench.out ]; then \
mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
fi; \
mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out
$(timing-type) $(binaries-bench) $(binaries-benchset): %: %.o $(objpfx)json-lib.o \
$(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
$(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
$(+link)
$(objpfx)bench-%.c: %-inputs $(bench-deps)
{ if [ -n "$($*-INCLUDE)" ]; then \
cat $($*-INCLUDE); \
fi; \
$(.)scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
mv -f $@-tmp $@