elf: Add a DTV setup test [BZ #27136]
[glibc.git] / benchtests / Makefile
blob4bc702a275600ebfb75dad91aecca61fff70d1d2
1 # Copyright (C) 2013-2021 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <https://www.gnu.org/licenses/>.
18 # Makefile for benchmark tests. The only useful target here is `bench`.
19 # Add benchmark functions in alphabetical order.
21 subdir := benchtests
23 include ../Makeconfig
24 bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 \
25 modf pow rint sin sincos sinh sqrt tan tanh fmin fmax fminf \
26 fmaxf powf trunc truncf roundeven roundevenf expf exp2f logf \
27 log2f sincosf sinf cosf isnan isinf isfinite hypot logb logbf \
28 exp10f ilogb ilogbf cbrt erf erfc exp10 expm1 j0 j1 lgamma \
29 log10 log1p tgamma y0 y1 atan2
31 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
32 bench-math += expf128 powf128 sinf128 ilogbf128
33 endif
35 bench-pthread := pthread_once thread_create pthread-locks
37 bench-string := ffs ffsll
39 ifeq (${BENCHSET},)
40 bench := $(bench-math) $(bench-pthread) $(bench-string)
41 else
42 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
43 endif
45 # String function benchmarks.
46 string-benchset := memccpy memchr memcmp memcpy memmem memmove \
47 mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
48 strcat strchr strchrnul strcmp strcpy strcspn strlen \
49 strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
50 strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
51 strcoll memcpy-large memcpy-random memmove-large memset-large \
52 memcpy-walk memset-walk memmove-walk
54 # Build and run locale-dependent benchmarks only if we're building natively.
55 ifeq (no,$(cross-compiling))
56 wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
57 wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
58 wmemchr wmemset wmemcmp
59 else
60 wcsmbs-benchset :=
61 endif
63 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
65 ifeq (no,$(cross-compiling))
66 # We have to generate locales
67 LOCALES := en_US.UTF-8 tr_TR.UTF-8 cs_CZ.UTF-8 fa_IR.UTF-8 fr_FR.UTF-8 \
68 ja_JP.UTF-8 si_LK.UTF-8 en_GB.UTF-8 vi_VN.UTF-8 ar_SA.UTF-8 \
69 da_DK.UTF-8 pl_PL.UTF-8 pt_PT.UTF-8 el_GR.UTF-8 ru_RU.UTF-8 \
70 he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \
71 hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8
72 include ../gen-locales.mk
73 endif
75 stdlib-benchset := strtod
77 stdio-common-benchset := sprintf
79 math-benchset := math-inlines
81 ifeq (${BENCHSET},)
82 benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
83 $(math-benchset)
84 else
85 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
86 endif
88 CFLAGS-bench-ffs.c += -fno-builtin
89 CFLAGS-bench-ffsll.c += -fno-builtin
90 CFLAGS-bench-sqrt.c += -fno-builtin
91 CFLAGS-bench-fmin.c += -fno-builtin
92 CFLAGS-bench-fminf.c += -fno-builtin
93 CFLAGS-bench-fmax.c += -fno-builtin
94 CFLAGS-bench-fmaxf.c += -fno-builtin
95 CFLAGS-bench-trunc.c += -fno-builtin
96 CFLAGS-bench-truncf.c += -fno-builtin
97 CFLAGS-bench-roundeven.c += -fno-builtin
98 CFLAGS-bench-roundevenf.c += -fno-builtin
99 CFLAGS-bench-isnan.c += -fsignaling-nans
100 CFLAGS-bench-isinf.c += -fsignaling-nans
101 CFLAGS-bench-isfinite.c += -fsignaling-nans
103 ifeq (${BENCHSET},)
104 bench-malloc := malloc-thread malloc-simple
105 else
106 bench-malloc := $(filter malloc-%,${BENCHSET})
107 endif
109 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm)
110 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm)
111 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(shared-thread-library)
112 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(shared-thread-library)
113 $(addprefix $(objpfx)bench-,pthread-locks): $(libm)
117 # Rules to build and execute the benchmarks. Do not put any benchmark
118 # parameters beyond this point.
120 # We don't want the benchmark programs to run in parallel since that could
121 # affect their performance.
122 .NOTPARALLEL:
124 bench-extra-objs = json-lib.o
126 extra-objs += $(bench-extra-objs)
127 others-extras = $(bench-extra-objs)
129 include ../Rules
131 binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
132 binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
133 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
135 # The default duration: 1 seconds.
136 ifndef BENCH_DURATION
137 BENCH_DURATION := 1
138 endif
140 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
142 # Use clock_gettime to measure performance of functions. The default is
143 # to use the architecture-specific high precision timing instructions.
144 ifdef USE_CLOCK_GETTIME
145 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
146 else
147 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
148 # of functions. All x86 processors since 2010 support RDTSCP instruction.
149 ifdef USE_RDTSCP
150 CPPFLAGS-nonlib += -DUSE_RDTSCP
151 endif
152 endif
154 DETAILED_OPT :=
156 ifdef DETAILED
157 DETAILED_OPT := -d
158 endif
160 bench-deps := bench-skeleton.c bench-timing.h Makefile
162 run-bench = $(test-wrapper-env) \
163 $(run-program-env) \
164 $($*-ENV) $(test-via-rtld-prefix) $${run}
166 timing-type := $(objpfx)bench-timing-type
168 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
169 # for all these modules.
170 cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
171 $(binaries-bench-malloc:=.c) $(timing-type:=.c)
172 lib := nonlib
173 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
175 bench-clean:
176 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
177 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
178 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
179 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
180 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
182 # Validate the passed in BENCHSET
183 ifneq ($(strip ${BENCHSET}),)
184 VALIDBENCHSETNAMES := bench-pthread bench-math bench-string string-benchset \
185 wcsmbs-benchset stdlib-benchset stdio-common-benchset math-benchset \
186 malloc-thread malloc-simple
187 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
188 ifneq (${INVALIDBENCHSETNAMES},)
189 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
190 $(info The valid ones are: ${VALIDBENCHSETNAMES})
191 $(error Invalid BENCHSET value)
192 endif
193 endif
195 bench: bench-build bench-set bench-func bench-malloc
197 # Target to only build the benchmark without running it. We generate locales
198 # only if we're building natively.
199 ifeq (no,$(cross-compiling))
200 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
201 $(binaries-benchset) $(binaries-bench-malloc)
202 else
203 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
204 $(binaries-bench-malloc)
205 endif
207 bench-set: $(binaries-benchset)
208 for run in $^; do \
209 echo "Running $${run}"; \
210 $(run-bench) > $${run}.out; \
211 done
213 bench-malloc: $(binaries-bench-malloc)
214 for run in $^; do \
215 echo "$${run}"; \
216 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
217 for thr in 1 8 16 32; do \
218 echo "Running $${run} $${thr}"; \
219 $(run-bench) $${thr} > $${run}-$${thr}.out; \
220 done;\
221 else \
222 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
223 echo "Running $${run} $${thr}"; \
224 $(run-bench) $${thr} > $${run}-$${thr}.out; \
225 done;\
226 fi;\
227 done
229 # Build and execute the benchmark functions. This target generates JSON
230 # formatted bench.out. Each of the programs produce independent JSON output,
231 # so one could even execute them individually and process it using any JSON
232 # capable language or tool.
233 bench-func: $(binaries-bench)
234 if [ -n '$^' ] ; then \
235 { timing_type=$$($(test-wrapper-env) \
236 $(run-program-env) \
237 $(test-via-rtld-prefix) \
238 $(timing-type)); \
239 echo "{\"timing_type\": \"$${timing_type}\","; \
240 echo " \"functions\": {"; \
241 for run in $^; do \
242 if ! [ "x$${run}" = "x$<" ]; then \
243 echo ","; \
244 fi; \
245 echo "Running $${run}" >&2; \
246 $(run-bench) $(DETAILED_OPT); \
247 done; \
248 echo; \
249 echo " }"; \
250 echo "}"; \
251 } > $(objpfx)bench.out-tmp; \
252 if [ -f $(objpfx)bench.out ]; then \
253 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
254 fi; \
255 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
256 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
257 scripts/benchout.schema.json; \
260 ifeq ($(bind-now),yes)
261 link-bench-bind-now = -Wl,-z,now
262 endif
264 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
265 $(binaries-bench-malloc)
267 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
268 $(link-extra-libs-tests) \
269 $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
270 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
271 $(+link-tests)
273 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
275 $(objpfx)bench-%.c: %-inputs $(bench-deps)
276 { if [ -n "$($*-INCLUDE)" ]; then \
277 cat $($*-INCLUDE); \
278 fi; \
279 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
280 mv -f $@-tmp $@