Update install.texi, and regenerate INSTALL.
[glibc.git] / benchtests / Makefile
blob721f32afdbc93da42b4f4ce6ba09e92c18613607
1 # Copyright (C) 2013-2023 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-lock \
107 pthread-mutex-trylock \
108 pthread-spin-lock \
109 pthread-spin-trylock \
110 pthread_once \
111 thread_create \
112 # bench-pthread
114 LDLIBS-bench-pthread-mutex-lock += -lm
115 LDLIBS-bench-pthread-mutex-trylock += -lm
116 LDLIBS-bench-pthread-spin-lock += -lm
117 LDLIBS-bench-pthread-spin-trylock += -lm
119 bench-string := \
120 ffs \
121 ffsll \
122 # bench-string
124 # String function benchmarks.
125 string-benchset := \
126 bzero \
127 bzero-large \
128 bzero-walk \
129 memccpy \
130 memchr \
131 memcmp \
132 memcmpeq \
133 memcpy \
134 memcpy-large \
135 memcpy-random \
136 memcpy-walk \
137 memmem \
138 memmove \
139 memmove-large \
140 memmove-walk \
141 mempcpy \
142 memrchr \
143 memset \
144 memset-large \
145 memset-walk \
146 memset-zero \
147 memset-zero-large \
148 memset-zero-walk \
149 rawmemchr \
150 stpcpy \
151 stpcpy_chk \
152 stpncpy \
153 strcasecmp \
154 strcasestr \
155 strcat \
156 strchr \
157 strchrnul \
158 strcmp \
159 strcoll \
160 strcpy \
161 strcpy_chk \
162 strcspn \
163 strlen \
164 strncasecmp \
165 strncat \
166 strncmp \
167 strncpy \
168 strnlen \
169 strpbrk \
170 strrchr \
171 strsep \
172 strspn \
173 strstr \
174 strtok \
175 # string-benchset
177 # Build and run locale-dependent benchmarks only if we're building natively.
178 ifeq (no,$(cross-compiling))
179 wcsmbs-benchset := \
180 wcpcpy \
181 wcpncpy \
182 wcrtomb \
183 wcscat \
184 wcschr \
185 wcschrnul \
186 wcscmp \
187 wcscpy \
188 wcscspn \
189 wcslen \
190 wcsncat \
191 wcsncmp \
192 wcsncpy \
193 wcsnlen \
194 wcspbrk \
195 wcsrchr \
196 wcsspn \
197 wmemchr \
198 wmemcmp \
199 wmemset \
200 # wcsmbs-benchset
201 else
202 wcsmbs-benchset :=
203 endif
205 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
207 ifeq (no,$(cross-compiling))
208 # We have to generate locales
209 LOCALES := \
210 ar_SA.UTF-8 \
211 cs_CZ.UTF-8 \
212 da_DK.UTF-8 \
213 el_GR.UTF-8 \
214 en_GB.UTF-8 \
215 en_US.UTF-8 \
216 es_ES.UTF-8 \
217 fa_IR.UTF-8 \
218 fr_FR.UTF-8 \
219 he_IL.UTF-8 \
220 hi_IN.UTF-8 \
221 hu_HU.UTF-8 \
222 is_IS.UTF-8 \
223 it_IT.UTF-8 \
224 ja_JP.UTF-8 \
225 pl_PL.UTF-8 \
226 pt_PT.UTF-8 \
227 ru_RU.UTF-8 \
228 si_LK.UTF-8 \
229 sr_RS.UTF-8 \
230 sv_SE.UTF-8 \
231 tr_TR.UTF-8 \
232 vi_VN.UTF-8 \
233 zh_CN.UTF-8 \
234 # LOCALES
235 include ../gen-locales.mk
236 endif
238 hash-benchset := \
239 dl-elf-hash \
240 dl-new-hash \
241 nss-hash \
242 # hash-benchset
244 stdlib-benchset := \
245 arc4random \
246 strtod \
247 # stdlib-benchset
249 stdio-common-benchset := sprintf
251 math-benchset := math-inlines
253 ifeq (${BENCHSET},)
254 benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
255 $(math-benchset) $(hash-benchset)
256 else
257 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
258 endif
260 CFLAGS-bench-ffs.c += -fno-builtin
261 CFLAGS-bench-ffsll.c += -fno-builtin
262 CFLAGS-bench-sqrt.c += -fno-builtin
263 CFLAGS-bench-fmin.c += -fno-builtin
264 CFLAGS-bench-fminf.c += -fno-builtin
265 CFLAGS-bench-fmax.c += -fno-builtin
266 CFLAGS-bench-fmaxf.c += -fno-builtin
267 CFLAGS-bench-trunc.c += -fno-builtin
268 CFLAGS-bench-truncf.c += -fno-builtin
269 CFLAGS-bench-roundeven.c += -fno-builtin
270 CFLAGS-bench-roundevenf.c += -fno-builtin
271 CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
272 CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
273 CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
275 ifeq (${BENCHSET},)
276 bench-malloc := malloc-thread malloc-simple
277 else
278 bench-malloc := $(filter malloc-%,${BENCHSET})
279 endif
281 ifeq (${STATIC-BENCHTESTS},yes)
282 +link-benchtests = $(+link-static-tests)
283 link-libc-benchtests = $(link-libc-static)
284 libm-benchtests = $(common-objpfx)math/libm.a
285 thread-library-benchtests = $(static-thread-library)
286 else
287 link-libc-benchtests = $(link-libc)
288 +link-benchtests = $(+link-tests)
289 thread-library-benchtests = $(shared-thread-library)
290 libm-benchtests = $(libm)
291 endif
293 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
294 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
295 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
296 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
297 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
298 $(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
302 # Rules to build and execute the benchmarks. Do not put any benchmark
303 # parameters beyond this point.
305 # We don't want the benchmark programs to run in parallel since that could
306 # affect their performance.
307 .NOTPARALLEL:
309 bench-extra-objs = json-lib.o
311 extra-objs += $(bench-extra-objs)
312 others-extras = $(bench-extra-objs)
314 # The default duration: 1 seconds.
315 ifndef BENCH_DURATION
316 BENCH_DURATION := 1
317 endif
319 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
321 # Use clock_gettime to measure performance of functions. The default is
322 # to use the architecture-specific high precision timing instructions.
323 ifdef USE_CLOCK_GETTIME
324 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
325 else
326 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
327 # of functions. All x86 processors since 2010 support RDTSCP instruction.
328 ifdef USE_RDTSCP
329 CPPFLAGS-nonlib += -DUSE_RDTSCP
330 endif
331 endif
333 DETAILED_OPT :=
335 ifdef DETAILED
336 DETAILED_OPT := -d
337 endif
339 bench-deps := bench-skeleton.c bench-timing.h Makefile
341 run-bench = $(test-wrapper-env) \
342 $(run-program-env) \
343 $($*-ENV) $(test-via-rtld-prefix) $${run}
345 timing-type := $(objpfx)bench-timing-type
346 extra-objs += bench-timing-type.o
348 include ../Rules
350 bench-math += $(bench-libmvec)
352 ifeq (${BENCHSET},)
353 bench := $(bench-math) $(bench-pthread) $(bench-string)
354 else
355 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
356 endif
358 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
359 # benches.
360 binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
361 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
362 binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
363 extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
364 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
365 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
367 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
368 # for all these modules.
369 cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
370 $(binaries-bench-malloc:=.c) $(timing-type:=.c)
371 lib := nonlib
372 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
374 bench-clean:
375 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
376 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
377 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
378 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
379 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
381 # Validate the passed in BENCHSET
382 ifneq ($(strip ${BENCHSET}),)
383 VALIDBENCHSETNAMES := \
384 bench-math \
385 bench-pthread \
386 bench-string \
387 hash-benchset \
388 malloc-simple \
389 malloc-thread \
390 math-benchset \
391 stdio-common-benchset \
392 stdlib-benchset \
393 string-benchset \
394 wcsmbs-benchset \
395 # VALIDBENCHSETNAMES
397 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
398 ifneq (${INVALIDBENCHSETNAMES},)
399 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
400 $(info The valid ones are: ${VALIDBENCHSETNAMES})
401 $(error Invalid BENCHSET value)
402 endif
403 endif
405 bench: bench-build bench-set bench-func bench-malloc
407 # Target to only build the benchmark without running it. We generate locales
408 # only if we're building natively.
409 ifeq (no,$(cross-compiling))
410 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
411 $(binaries-benchset) $(binaries-bench-malloc)
412 else
413 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
414 $(binaries-bench-malloc)
415 endif
417 bench-set: $(binaries-benchset)
418 for run in $^; do \
419 echo "Running $${run}"; \
420 $(run-bench) > $${run}.out; \
421 done
423 bench-malloc: $(binaries-bench-malloc)
424 for run in $^; do \
425 echo "$${run}"; \
426 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
427 for thr in 1 8 16 32; do \
428 echo "Running $${run} $${thr}"; \
429 $(run-bench) $${thr} > $${run}-$${thr}.out; \
430 done;\
431 else \
432 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
433 echo "Running $${run} $${thr}"; \
434 $(run-bench) $${thr} > $${run}-$${thr}.out; \
435 done;\
436 fi;\
437 done
439 # Build and execute the benchmark functions. This target generates JSON
440 # formatted bench.out. Each of the programs produce independent JSON output,
441 # so one could even execute them individually and process it using any JSON
442 # capable language or tool.
443 bench-func: $(binaries-bench)
444 if [ -n '$^' ] ; then \
445 { timing_type=$$($(test-wrapper-env) \
446 $(run-program-env) \
447 $(test-via-rtld-prefix) \
448 $(timing-type)); \
449 echo "{\"timing_type\": \"$${timing_type}\","; \
450 echo " \"functions\": {"; \
451 for run in $^; do \
452 op=$$($(run-bench) $(DETAILED_OPT)); \
453 ret=$$?; \
454 case "$${ret}" in \
455 77) \
456 echo "UNSUPPORTED $${run}: $${op}" >&2; \
457 ;; \
458 0) \
459 echo "Running $${run}" >&2; \
460 if [ "$${run}" != "$<" ]; then \
461 echo ","; \
462 fi; \
463 echo "$${op}"; \
464 ;; \
465 *) \
466 echo "FAILED $${run}" >&2; \
467 ;; \
468 esac; \
469 done; \
470 echo; \
471 echo " }"; \
472 echo "}"; \
473 } > $(objpfx)bench.out-tmp; \
474 if [ -f $(objpfx)bench.out ]; then \
475 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
476 fi; \
477 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
478 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
479 scripts/benchout.schema.json; \
482 ifeq ($(bind-now),yes)
483 link-bench-bind-now = -Wl,-z,now
484 endif
486 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
487 $(binaries-bench-malloc)
489 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
490 $(link-extra-libs-tests) \
491 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
492 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
493 $(+link-benchtests)
495 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
497 $(objpfx)bench-%.c: %-inputs $(bench-deps)
498 { if [ -n "$($*-INCLUDE)" ]; then \
499 cat $($*-INCLUDE); \
500 fi; \
501 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
502 mv -f $@-tmp $@