linux: Sync Linux 6.6 elf.h
[glibc.git] / benchtests / Makefile
blobe1346bbda125be9fc2b216f9e8be3f2ee7cb0c4d
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 fmod \
52 fmodf \
53 hypot \
54 hypotf \
55 ilogb \
56 ilogbf \
57 isfinite \
58 isinf \
59 isnan \
60 j0 \
61 j1 \
62 lgamma \
63 log \
64 log10 \
65 log1p \
66 log2 \
67 log2f \
68 logb \
69 logbf \
70 logf \
71 modf \
72 pow \
73 powf \
74 rint \
75 roundeven \
76 roundevenf \
77 sin \
78 sincos \
79 sincosf \
80 sinf \
81 sinh \
82 sqrt \
83 tan \
84 tanh \
85 tgamma \
86 trunc \
87 truncf \
88 y0 \
89 y1 \
90 # bench-math
92 ifneq (,$(filter yes,$(float96-fcts)))
93 bench-math += \
94 cbrtl \
95 # bench-math
96 endif
98 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
99 bench-math += \
100 expf128 \
101 ilogbf128 \
102 powf128 \
103 sinf128 \
104 # bench-math
105 endif
107 bench-pthread := \
108 pthread-locks \
109 pthread-mutex-lock \
110 pthread-mutex-trylock \
111 pthread-spin-lock \
112 pthread-spin-trylock \
113 pthread_once \
114 thread_create \
115 # bench-pthread
117 LDLIBS-bench-pthread-mutex-lock += -lm
118 LDLIBS-bench-pthread-mutex-trylock += -lm
119 LDLIBS-bench-pthread-spin-lock += -lm
120 LDLIBS-bench-pthread-spin-trylock += -lm
122 bench-string := \
123 ffs \
124 ffsll \
125 # bench-string
127 # String function benchmarks.
128 string-benchset := \
129 bzero \
130 bzero-large \
131 bzero-walk \
132 memccpy \
133 memchr \
134 memcmp \
135 memcmpeq \
136 memcpy \
137 memcpy-large \
138 memcpy-random \
139 memcpy-walk \
140 memmem \
141 memmove \
142 memmove-large \
143 memmove-walk \
144 mempcpy \
145 memrchr \
146 memset \
147 memset-large \
148 memset-walk \
149 memset-zero \
150 memset-zero-large \
151 memset-zero-walk \
152 rawmemchr \
153 stpcpy \
154 stpcpy_chk \
155 stpncpy \
156 strcasecmp \
157 strcasestr \
158 strcat \
159 strchr \
160 strchrnul \
161 strcmp \
162 strcoll \
163 strcpy \
164 strcpy_chk \
165 strcspn \
166 strlen \
167 strncasecmp \
168 strncat \
169 strncmp \
170 strncpy \
171 strnlen \
172 strpbrk \
173 strrchr \
174 strsep \
175 strspn \
176 strstr \
177 strtok \
178 # string-benchset
180 # Build and run locale-dependent benchmarks only if we're building natively.
181 ifeq (no,$(cross-compiling))
182 wcsmbs-benchset := \
183 wcpcpy \
184 wcpncpy \
185 wcrtomb \
186 wcscat \
187 wcschr \
188 wcschrnul \
189 wcscmp \
190 wcscpy \
191 wcscspn \
192 wcslen \
193 wcsncat \
194 wcsncmp \
195 wcsncpy \
196 wcsnlen \
197 wcspbrk \
198 wcsrchr \
199 wcsspn \
200 wmemchr \
201 wmemcmp \
202 wmemset \
203 # wcsmbs-benchset
204 else
205 wcsmbs-benchset :=
206 endif
208 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
210 ifeq (no,$(cross-compiling))
211 # We have to generate locales
212 LOCALES := \
213 ar_SA.UTF-8 \
214 cs_CZ.UTF-8 \
215 da_DK.UTF-8 \
216 el_GR.UTF-8 \
217 en_GB.UTF-8 \
218 en_US.UTF-8 \
219 es_ES.UTF-8 \
220 fa_IR.UTF-8 \
221 fr_FR.UTF-8 \
222 he_IL.UTF-8 \
223 hi_IN.UTF-8 \
224 hu_HU.UTF-8 \
225 is_IS.UTF-8 \
226 it_IT.UTF-8 \
227 ja_JP.UTF-8 \
228 pl_PL.UTF-8 \
229 pt_PT.UTF-8 \
230 ru_RU.UTF-8 \
231 si_LK.UTF-8 \
232 sr_RS.UTF-8 \
233 sv_SE.UTF-8 \
234 tr_TR.UTF-8 \
235 vi_VN.UTF-8 \
236 zh_CN.UTF-8 \
237 # LOCALES
238 include ../gen-locales.mk
239 endif
241 hash-benchset := \
242 dl-elf-hash \
243 dl-new-hash \
244 nss-hash \
245 # hash-benchset
247 stdlib-benchset := \
248 arc4random \
249 strtod \
250 # stdlib-benchset
252 stdio-common-benchset := sprintf
254 math-benchset := math-inlines
256 ifeq (${BENCHSET},)
257 benchset := \
258 $(hash-benchset) \
259 $(math-benchset) \
260 $(stdio-common-benchset) \
261 $(stdlib-benchset) \
262 $(string-benchset-all) \
263 # benchset
264 else
265 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
266 endif
268 CFLAGS-bench-ffs.c += -fno-builtin
269 CFLAGS-bench-ffsll.c += -fno-builtin
270 CFLAGS-bench-sqrt.c += -fno-builtin
271 CFLAGS-bench-fmin.c += -fno-builtin
272 CFLAGS-bench-fminf.c += -fno-builtin
273 CFLAGS-bench-fmax.c += -fno-builtin
274 CFLAGS-bench-fmaxf.c += -fno-builtin
275 CFLAGS-bench-trunc.c += -fno-builtin
276 CFLAGS-bench-truncf.c += -fno-builtin
277 CFLAGS-bench-roundeven.c += -fno-builtin
278 CFLAGS-bench-roundevenf.c += -fno-builtin
279 CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
280 CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
281 CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
283 ifeq (${BENCHSET},)
284 bench-malloc := \
285 malloc-simple \
286 malloc-thread \
287 # bench-malloc
288 else
289 bench-malloc := $(filter malloc-%,${BENCHSET})
290 endif
292 ifeq (${STATIC-BENCHTESTS},yes)
293 +link-benchtests = $(+link-static-tests)
294 link-libc-benchtests = $(link-libc-static)
295 libm-benchtests = $(common-objpfx)math/libm.a
296 thread-library-benchtests = $(static-thread-library)
297 else
298 link-libc-benchtests = $(link-libc)
299 +link-benchtests = $(+link-tests)
300 thread-library-benchtests = $(shared-thread-library)
301 libm-benchtests = $(libm)
302 endif
304 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
305 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
306 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
307 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
308 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
309 $(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
313 # Rules to build and execute the benchmarks. Do not put any benchmark
314 # parameters beyond this point.
316 # We don't want the benchmark programs to run in parallel since that could
317 # affect their performance.
318 .NOTPARALLEL:
320 bench-extra-objs = json-lib.o
322 extra-objs += $(bench-extra-objs)
323 others-extras = $(bench-extra-objs)
325 # The default duration: 1 seconds.
326 ifndef BENCH_DURATION
327 BENCH_DURATION := 1
328 endif
330 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
332 # Use clock_gettime to measure performance of functions. The default is
333 # to use the architecture-specific high precision timing instructions.
334 ifdef USE_CLOCK_GETTIME
335 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
336 else
337 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
338 # of functions. All x86 processors since 2010 support RDTSCP instruction.
339 ifdef USE_RDTSCP
340 CPPFLAGS-nonlib += -DUSE_RDTSCP
341 endif
342 endif
344 DETAILED_OPT :=
346 ifdef DETAILED
347 DETAILED_OPT := -d
348 endif
350 bench-deps := bench-skeleton.c bench-timing.h Makefile
352 run-bench = $(test-wrapper-env) \
353 $(run-program-env) \
354 $($*-ENV) $(test-via-rtld-prefix) $${run}
356 timing-type := $(objpfx)bench-timing-type
357 extra-objs += bench-timing-type.o
359 include ../Rules
361 bench-math += $(bench-libmvec)
363 ifeq (${BENCHSET},)
364 bench := \
365 $(bench-math) \
366 $(bench-pthread) \
367 $(bench-string) \
368 # bench
369 else
370 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
371 endif
373 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
374 # benches.
375 binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
376 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
377 binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
378 extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
379 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
380 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
382 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
383 # for all these modules.
384 cpp-srcs-left := \
385 $(binaries-bench-malloc:=.c) \
386 $(binaries-bench:=.c) \
387 $(binaries-benchset:=.c) \
388 $(timing-type:=.c) \
389 # cpp-srcs-left
390 lib := nonlib
391 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
393 bench-clean:
394 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
395 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
396 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
397 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
398 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
400 # Validate the passed in BENCHSET
401 ifneq ($(strip ${BENCHSET}),)
402 VALIDBENCHSETNAMES := \
403 bench-math \
404 bench-pthread \
405 bench-string \
406 hash-benchset \
407 malloc-simple \
408 malloc-thread \
409 math-benchset \
410 stdio-common-benchset \
411 stdlib-benchset \
412 string-benchset \
413 wcsmbs-benchset \
414 # VALIDBENCHSETNAMES
416 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
417 ifneq (${INVALIDBENCHSETNAMES},)
418 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
419 $(info The valid ones are: ${VALIDBENCHSETNAMES})
420 $(error Invalid BENCHSET value)
421 endif
422 endif
424 bench: bench-build bench-set bench-func bench-malloc
426 # Target to only build the benchmark without running it. We generate locales
427 # only if we're building natively.
428 ifeq (no,$(cross-compiling))
429 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
430 $(binaries-benchset) $(binaries-bench-malloc)
431 else
432 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
433 $(binaries-bench-malloc)
434 endif
436 bench-set: $(binaries-benchset)
437 for run in $^; do \
438 echo "Running $${run}"; \
439 $(run-bench) > $${run}.out; \
440 done
442 bench-malloc: $(binaries-bench-malloc)
443 for run in $^; do \
444 echo "$${run}"; \
445 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
446 for thr in 1 8 16 32; do \
447 echo "Running $${run} $${thr}"; \
448 $(run-bench) $${thr} > $${run}-$${thr}.out; \
449 done;\
450 else \
451 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
452 echo "Running $${run} $${thr}"; \
453 $(run-bench) $${thr} > $${run}-$${thr}.out; \
454 done;\
455 fi;\
456 done
458 # Build and execute the benchmark functions. This target generates JSON
459 # formatted bench.out. Each of the programs produce independent JSON output,
460 # so one could even execute them individually and process it using any JSON
461 # capable language or tool.
462 bench-func: $(binaries-bench)
463 if [ -n '$^' ] ; then \
464 { timing_type=$$($(test-wrapper-env) \
465 $(run-program-env) \
466 $(test-via-rtld-prefix) \
467 $(timing-type)); \
468 echo "{\"timing_type\": \"$${timing_type}\","; \
469 echo " \"functions\": {"; \
470 for run in $^; do \
471 op=$$($(run-bench) $(DETAILED_OPT)); \
472 ret=$$?; \
473 case "$${ret}" in \
474 77) \
475 echo "UNSUPPORTED $${run}: $${op}" >&2; \
476 ;; \
477 0) \
478 echo "Running $${run}" >&2; \
479 if [ "$${run}" != "$<" ]; then \
480 echo ","; \
481 fi; \
482 echo "$${op}"; \
483 ;; \
484 *) \
485 echo "FAILED $${run}" >&2; \
486 ;; \
487 esac; \
488 done; \
489 echo; \
490 echo " }"; \
491 echo "}"; \
492 } > $(objpfx)bench.out-tmp; \
493 if [ -f $(objpfx)bench.out ]; then \
494 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
495 fi; \
496 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
497 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
498 scripts/benchout.schema.json; \
501 ifeq ($(bind-now),yes)
502 link-bench-bind-now = -Wl,-z,now
503 endif
505 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
506 $(binaries-bench-malloc)
508 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
509 $(link-extra-libs-tests) \
510 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
511 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
512 $(+link-benchtests)
514 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
516 $(objpfx)bench-%.c: %-inputs $(bench-deps)
517 { if [ -n "$($*-INCLUDE)" ]; then \
518 cat $($*-INCLUDE); \
519 fi; \
520 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
521 mv -f $@-tmp $@