Update install.texi, and regenerate INSTALL.
[glibc.git] / benchtests / Makefile
blobd99771be74b40f8afa3953f61c0721b19658d4b7
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 := \
237 arc4random \
238 strtod \
239 # stdlib-benchset
241 stdio-common-benchset := sprintf
243 math-benchset := math-inlines
245 ifeq (${BENCHSET},)
246 benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
247 $(math-benchset) $(hash-benchset)
248 else
249 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
250 endif
252 CFLAGS-bench-ffs.c += -fno-builtin
253 CFLAGS-bench-ffsll.c += -fno-builtin
254 CFLAGS-bench-sqrt.c += -fno-builtin
255 CFLAGS-bench-fmin.c += -fno-builtin
256 CFLAGS-bench-fminf.c += -fno-builtin
257 CFLAGS-bench-fmax.c += -fno-builtin
258 CFLAGS-bench-fmaxf.c += -fno-builtin
259 CFLAGS-bench-trunc.c += -fno-builtin
260 CFLAGS-bench-truncf.c += -fno-builtin
261 CFLAGS-bench-roundeven.c += -fno-builtin
262 CFLAGS-bench-roundevenf.c += -fno-builtin
263 CFLAGS-bench-isnan.c += -fsignaling-nans
264 CFLAGS-bench-isinf.c += -fsignaling-nans
265 CFLAGS-bench-isfinite.c += -fsignaling-nans
267 ifeq (${BENCHSET},)
268 bench-malloc := malloc-thread malloc-simple
269 else
270 bench-malloc := $(filter malloc-%,${BENCHSET})
271 endif
273 ifeq (${STATIC-BENCHTESTS},yes)
274 +link-benchtests = $(+link-static-tests)
275 link-libc-benchtests = $(link-libc-static)
276 libm-benchtests = $(common-objpfx)math/libm.a
277 thread-library-benchtests = $(static-thread-library)
278 else
279 link-libc-benchtests = $(link-libc)
280 +link-benchtests = $(+link-tests)
281 thread-library-benchtests = $(shared-thread-library)
282 libm-benchtests = $(libm)
283 endif
285 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
286 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
287 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
288 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
289 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
290 $(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
294 # Rules to build and execute the benchmarks. Do not put any benchmark
295 # parameters beyond this point.
297 # We don't want the benchmark programs to run in parallel since that could
298 # affect their performance.
299 .NOTPARALLEL:
301 bench-extra-objs = json-lib.o
303 extra-objs += $(bench-extra-objs)
304 others-extras = $(bench-extra-objs)
306 # The default duration: 1 seconds.
307 ifndef BENCH_DURATION
308 BENCH_DURATION := 1
309 endif
311 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
313 # Use clock_gettime to measure performance of functions. The default is
314 # to use the architecture-specific high precision timing instructions.
315 ifdef USE_CLOCK_GETTIME
316 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
317 else
318 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
319 # of functions. All x86 processors since 2010 support RDTSCP instruction.
320 ifdef USE_RDTSCP
321 CPPFLAGS-nonlib += -DUSE_RDTSCP
322 endif
323 endif
325 DETAILED_OPT :=
327 ifdef DETAILED
328 DETAILED_OPT := -d
329 endif
331 bench-deps := bench-skeleton.c bench-timing.h Makefile
333 run-bench = $(test-wrapper-env) \
334 $(run-program-env) \
335 $($*-ENV) $(test-via-rtld-prefix) $${run}
337 timing-type := $(objpfx)bench-timing-type
338 extra-objs += bench-timing-type.o
340 include ../Rules
342 bench-math += $(bench-libmvec)
344 ifeq (${BENCHSET},)
345 bench := $(bench-math) $(bench-pthread) $(bench-string)
346 else
347 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
348 endif
350 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
351 # benches.
352 binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
353 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
354 binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
355 extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
356 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
357 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
359 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
360 # for all these modules.
361 cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
362 $(binaries-bench-malloc:=.c) $(timing-type:=.c)
363 lib := nonlib
364 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
366 bench-clean:
367 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
368 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
369 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
370 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
371 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
373 # Validate the passed in BENCHSET
374 ifneq ($(strip ${BENCHSET}),)
375 VALIDBENCHSETNAMES := \
376 bench-math \
377 bench-pthread \
378 bench-string \
379 hash-benchset \
380 malloc-simple \
381 malloc-thread \
382 math-benchset \
383 stdio-common-benchset \
384 stdlib-benchset \
385 string-benchset \
386 wcsmbs-benchset \
387 # VALIDBENCHSETNAMES
389 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
390 ifneq (${INVALIDBENCHSETNAMES},)
391 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
392 $(info The valid ones are: ${VALIDBENCHSETNAMES})
393 $(error Invalid BENCHSET value)
394 endif
395 endif
397 bench: bench-build bench-set bench-func bench-malloc
399 # Target to only build the benchmark without running it. We generate locales
400 # only if we're building natively.
401 ifeq (no,$(cross-compiling))
402 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
403 $(binaries-benchset) $(binaries-bench-malloc)
404 else
405 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
406 $(binaries-bench-malloc)
407 endif
409 bench-set: $(binaries-benchset)
410 for run in $^; do \
411 echo "Running $${run}"; \
412 $(run-bench) > $${run}.out; \
413 done
415 bench-malloc: $(binaries-bench-malloc)
416 for run in $^; do \
417 echo "$${run}"; \
418 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
419 for thr in 1 8 16 32; do \
420 echo "Running $${run} $${thr}"; \
421 $(run-bench) $${thr} > $${run}-$${thr}.out; \
422 done;\
423 else \
424 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
425 echo "Running $${run} $${thr}"; \
426 $(run-bench) $${thr} > $${run}-$${thr}.out; \
427 done;\
428 fi;\
429 done
431 # Build and execute the benchmark functions. This target generates JSON
432 # formatted bench.out. Each of the programs produce independent JSON output,
433 # so one could even execute them individually and process it using any JSON
434 # capable language or tool.
435 bench-func: $(binaries-bench)
436 if [ -n '$^' ] ; then \
437 { timing_type=$$($(test-wrapper-env) \
438 $(run-program-env) \
439 $(test-via-rtld-prefix) \
440 $(timing-type)); \
441 echo "{\"timing_type\": \"$${timing_type}\","; \
442 echo " \"functions\": {"; \
443 for run in $^; do \
444 op=$$($(run-bench) $(DETAILED_OPT)); \
445 ret=$$?; \
446 case "$${ret}" in \
447 77) \
448 echo "UNSUPPORTED $${run}: $${op}" >&2; \
449 ;; \
450 0) \
451 echo "Running $${run}" >&2; \
452 if [ "$${run}" != "$<" ]; then \
453 echo ","; \
454 fi; \
455 echo "$${op}"; \
456 ;; \
457 *) \
458 echo "FAILED $${run}" >&2; \
459 ;; \
460 esac; \
461 done; \
462 echo; \
463 echo " }"; \
464 echo "}"; \
465 } > $(objpfx)bench.out-tmp; \
466 if [ -f $(objpfx)bench.out ]; then \
467 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
468 fi; \
469 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
470 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
471 scripts/benchout.schema.json; \
474 ifeq ($(bind-now),yes)
475 link-bench-bind-now = -Wl,-z,now
476 endif
478 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
479 $(binaries-bench-malloc)
481 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
482 $(link-extra-libs-tests) \
483 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
484 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
485 $(+link-benchtests)
487 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
489 $(objpfx)bench-%.c: %-inputs $(bench-deps)
490 { if [ -n "$($*-INCLUDE)" ]; then \
491 cat $($*-INCLUDE); \
492 fi; \
493 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
494 mv -f $@-tmp $@