elf: Add #include <errno.h> for use of E* constants.
[glibc.git] / benchtests / Makefile
blobc279041e193cc43ed9075fde4eba4db8c8670773
1 # Copyright (C) 2013-2022 Free Software Foundation, Inc.
2 # Copyright The GNU Toolchain Authors.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
19 # Makefile for benchmark tests. The only useful target here is `bench`.
20 # Add benchmark functions in alphabetical order.
22 subdir := benchtests
24 include ../Makeconfig
26 bench-math := \
27 acos \
28 acosh \
29 asin \
30 asinh \
31 atan \
32 atan2 \
33 atanh \
34 cbrt \
35 cos \
36 cosf \
37 cosh \
38 erf \
39 erfc \
40 exp \
41 exp10 \
42 exp10f \
43 exp2 \
44 exp2f \
45 expf \
46 expm1 \
47 fmax \
48 fmaxf \
49 fmin \
50 fminf \
51 hypot \
52 hypotf \
53 ilogb \
54 ilogbf \
55 isfinite \
56 isinf \
57 isnan \
58 j0 \
59 j1 \
60 lgamma \
61 log \
62 log10 \
63 log1p \
64 log2 \
65 log2f \
66 logb \
67 logbf \
68 logf \
69 modf \
70 pow \
71 powf \
72 rint \
73 roundeven \
74 roundevenf \
75 sin \
76 sincos \
77 sincosf \
78 sinf \
79 sinh \
80 sqrt \
81 tan \
82 tanh \
83 tgamma \
84 trunc \
85 truncf \
86 y0 \
87 y1 \
89 ifneq (,$(filter yes,$(float96-fcts)))
90 bench-math += \
91 cbrtl \
92 # bench-math
93 endif
95 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
96 bench-math += \
97 expf128 \
98 ilogbf128 \
99 powf128 \
100 sinf128 \
101 # bench-math
102 endif
104 bench-pthread := \
105 pthread-locks \
106 pthread-mutex-locks \
107 pthread_once \
108 thread_create \
109 # bench-pthread
111 bench-string := \
112 ffs \
113 ffsll \
114 # bench-string
116 # String function benchmarks.
117 string-benchset := \
118 bzero \
119 bzero-large \
120 bzero-walk \
121 memccpy \
122 memchr \
123 memcmp \
124 memcmpeq \
125 memcpy \
126 memcpy-large \
127 memcpy-random \
128 memcpy-walk \
129 memmem \
130 memmove \
131 memmove-large \
132 memmove-walk \
133 mempcpy \
134 memrchr \
135 memset \
136 memset-large \
137 memset-walk \
138 memset-zero \
139 memset-zero-large \
140 memset-zero-walk \
141 rawmemchr \
142 stpcpy \
143 stpcpy_chk \
144 stpncpy \
145 strcasecmp \
146 strcasestr \
147 strcat \
148 strchr \
149 strchrnul \
150 strcmp \
151 strcoll \
152 strcpy \
153 strcpy_chk \
154 strcspn \
155 strlen \
156 strncasecmp \
157 strncat \
158 strncmp \
159 strncpy \
160 strnlen \
161 strpbrk \
162 strrchr \
163 strsep \
164 strspn \
165 strstr \
166 strtok \
167 # string-benchset
169 # Build and run locale-dependent benchmarks only if we're building natively.
170 ifeq (no,$(cross-compiling))
171 wcsmbs-benchset := \
172 wcpcpy \
173 wcpncpy \
174 wcrtomb \
175 wcscat \
176 wcschr \
177 wcschrnul \
178 wcscmp \
179 wcscpy \
180 wcscspn \
181 wcslen \
182 wcsncat \
183 wcsncmp \
184 wcsncpy \
185 wcsnlen \
186 wcspbrk \
187 wcsrchr \
188 wcsspn \
189 wmemchr \
190 wmemcmp \
191 wmemset \
192 # wcsmbs-benchset
193 else
194 wcsmbs-benchset :=
195 endif
197 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
199 ifeq (no,$(cross-compiling))
200 # We have to generate locales
201 LOCALES := \
202 ar_SA.UTF-8 \
203 cs_CZ.UTF-8 \
204 da_DK.UTF-8 \
205 el_GR.UTF-8 \
206 en_GB.UTF-8 \
207 en_US.UTF-8 \
208 es_ES.UTF-8 \
209 fa_IR.UTF-8 \
210 fr_FR.UTF-8 \
211 he_IL.UTF-8 \
212 hi_IN.UTF-8 \
213 hu_HU.UTF-8 \
214 is_IS.UTF-8 \
215 it_IT.UTF-8 \
216 ja_JP.UTF-8 \
217 pl_PL.UTF-8 \
218 pt_PT.UTF-8 \
219 ru_RU.UTF-8 \
220 si_LK.UTF-8 \
221 sr_RS.UTF-8 \
222 sv_SE.UTF-8 \
223 tr_TR.UTF-8 \
224 vi_VN.UTF-8 \
225 zh_CN.UTF-8 \
226 # LOCALES
227 include ../gen-locales.mk
228 endif
230 hash-benchset := \
231 dl-elf-hash \
232 dl-new-hash \
233 nss-hash \
234 # hash-benchset
236 stdlib-benchset := strtod
238 stdio-common-benchset := sprintf
240 math-benchset := math-inlines
242 ifeq (${BENCHSET},)
243 benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
244 $(math-benchset) $(hash-benchset)
245 else
246 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
247 endif
249 CFLAGS-bench-ffs.c += -fno-builtin
250 CFLAGS-bench-ffsll.c += -fno-builtin
251 CFLAGS-bench-sqrt.c += -fno-builtin
252 CFLAGS-bench-fmin.c += -fno-builtin
253 CFLAGS-bench-fminf.c += -fno-builtin
254 CFLAGS-bench-fmax.c += -fno-builtin
255 CFLAGS-bench-fmaxf.c += -fno-builtin
256 CFLAGS-bench-trunc.c += -fno-builtin
257 CFLAGS-bench-truncf.c += -fno-builtin
258 CFLAGS-bench-roundeven.c += -fno-builtin
259 CFLAGS-bench-roundevenf.c += -fno-builtin
260 CFLAGS-bench-isnan.c += -fsignaling-nans
261 CFLAGS-bench-isinf.c += -fsignaling-nans
262 CFLAGS-bench-isfinite.c += -fsignaling-nans
264 ifeq (${BENCHSET},)
265 bench-malloc := malloc-thread malloc-simple
266 else
267 bench-malloc := $(filter malloc-%,${BENCHSET})
268 endif
270 ifeq (${STATIC-BENCHTESTS},yes)
271 +link-benchtests = $(+link-static-tests)
272 link-libc-benchtests = $(link-libc-static)
273 libm-benchtests = $(common-objpfx)math/libm.a
274 thread-library-benchtests = $(static-thread-library)
275 else
276 link-libc-benchtests = $(link-libc)
277 +link-benchtests = $(+link-tests)
278 thread-library-benchtests = $(shared-thread-library)
279 libm-benchtests = $(libm)
280 endif
282 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
283 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
284 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
285 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
286 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
287 $(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
291 # Rules to build and execute the benchmarks. Do not put any benchmark
292 # parameters beyond this point.
294 # We don't want the benchmark programs to run in parallel since that could
295 # affect their performance.
296 .NOTPARALLEL:
298 bench-extra-objs = json-lib.o
300 extra-objs += $(bench-extra-objs)
301 others-extras = $(bench-extra-objs)
303 # The default duration: 1 seconds.
304 ifndef BENCH_DURATION
305 BENCH_DURATION := 1
306 endif
308 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
310 # Use clock_gettime to measure performance of functions. The default is
311 # to use the architecture-specific high precision timing instructions.
312 ifdef USE_CLOCK_GETTIME
313 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
314 else
315 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
316 # of functions. All x86 processors since 2010 support RDTSCP instruction.
317 ifdef USE_RDTSCP
318 CPPFLAGS-nonlib += -DUSE_RDTSCP
319 endif
320 endif
322 DETAILED_OPT :=
324 ifdef DETAILED
325 DETAILED_OPT := -d
326 endif
328 bench-deps := bench-skeleton.c bench-timing.h Makefile
330 run-bench = $(test-wrapper-env) \
331 $(run-program-env) \
332 $($*-ENV) $(test-via-rtld-prefix) $${run}
334 timing-type := $(objpfx)bench-timing-type
335 extra-objs += bench-timing-type.o
337 include ../Rules
339 bench-math += $(bench-libmvec)
341 ifeq (${BENCHSET},)
342 bench := $(bench-math) $(bench-pthread) $(bench-string)
343 else
344 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
345 endif
347 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
348 # benches.
349 binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
350 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
351 binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
352 extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
353 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
354 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
356 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
357 # for all these modules.
358 cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
359 $(binaries-bench-malloc:=.c) $(timing-type:=.c)
360 lib := nonlib
361 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
363 bench-clean:
364 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
365 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
366 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
367 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
368 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
370 # Validate the passed in BENCHSET
371 ifneq ($(strip ${BENCHSET}),)
372 VALIDBENCHSETNAMES := \
373 bench-math \
374 bench-pthread \
375 bench-string \
376 hash-benchset \
377 malloc-simple \
378 malloc-thread \
379 math-benchset \
380 stdio-common-benchset \
381 stdlib-benchset \
382 string-benchset \
383 wcsmbs-benchset \
384 # VALIDBENCHSETNAMES
386 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
387 ifneq (${INVALIDBENCHSETNAMES},)
388 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
389 $(info The valid ones are: ${VALIDBENCHSETNAMES})
390 $(error Invalid BENCHSET value)
391 endif
392 endif
394 bench: bench-build bench-set bench-func bench-malloc
396 # Target to only build the benchmark without running it. We generate locales
397 # only if we're building natively.
398 ifeq (no,$(cross-compiling))
399 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
400 $(binaries-benchset) $(binaries-bench-malloc)
401 else
402 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
403 $(binaries-bench-malloc)
404 endif
406 bench-set: $(binaries-benchset)
407 for run in $^; do \
408 echo "Running $${run}"; \
409 $(run-bench) > $${run}.out; \
410 done
412 bench-malloc: $(binaries-bench-malloc)
413 for run in $^; do \
414 echo "$${run}"; \
415 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
416 for thr in 1 8 16 32; do \
417 echo "Running $${run} $${thr}"; \
418 $(run-bench) $${thr} > $${run}-$${thr}.out; \
419 done;\
420 else \
421 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
422 echo "Running $${run} $${thr}"; \
423 $(run-bench) $${thr} > $${run}-$${thr}.out; \
424 done;\
425 fi;\
426 done
428 # Build and execute the benchmark functions. This target generates JSON
429 # formatted bench.out. Each of the programs produce independent JSON output,
430 # so one could even execute them individually and process it using any JSON
431 # capable language or tool.
432 bench-func: $(binaries-bench)
433 if [ -n '$^' ] ; then \
434 { timing_type=$$($(test-wrapper-env) \
435 $(run-program-env) \
436 $(test-via-rtld-prefix) \
437 $(timing-type)); \
438 echo "{\"timing_type\": \"$${timing_type}\","; \
439 echo " \"functions\": {"; \
440 for run in $^; do \
441 op=$$($(run-bench) $(DETAILED_OPT)); \
442 ret=$$?; \
443 case "$${ret}" in \
444 77) \
445 echo "UNSUPPORTED $${run}: $${op}" >&2; \
446 ;; \
447 0) \
448 echo "Running $${run}" >&2; \
449 if [ "$${run}" != "$<" ]; then \
450 echo ","; \
451 fi; \
452 echo "$${op}"; \
453 ;; \
454 *) \
455 echo "FAILED $${run}" >&2; \
456 ;; \
457 esac; \
458 done; \
459 echo; \
460 echo " }"; \
461 echo "}"; \
462 } > $(objpfx)bench.out-tmp; \
463 if [ -f $(objpfx)bench.out ]; then \
464 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
465 fi; \
466 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
467 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
468 scripts/benchout.schema.json; \
471 ifeq ($(bind-now),yes)
472 link-bench-bind-now = -Wl,-z,now
473 endif
475 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
476 $(binaries-bench-malloc)
478 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
479 $(link-extra-libs-tests) \
480 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
481 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
482 $(+link-benchtests)
484 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
486 $(objpfx)bench-%.c: %-inputs $(bench-deps)
487 { if [ -n "$($*-INCLUDE)" ]; then \
488 cat $($*-INCLUDE); \
489 fi; \
490 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
491 mv -f $@-tmp $@