]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/Makefile
malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101)
[thirdparty/glibc.git] / benchtests / Makefile
CommitLineData
6d7e8eda 1# Copyright (C) 2013-2023 Free Software Foundation, Inc.
944afe6d 2# Copyright The GNU Toolchain Authors.
8cfdb7e0
SP
3# This file is part of the GNU C Library.
4
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.
9
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.
14
15# You should have received a copy of the GNU Lesser General Public
16# License along with the GNU C Library; if not, see
5a82c748 17# <https://www.gnu.org/licenses/>.
8cfdb7e0 18
8cfdb7e0 19# Makefile for benchmark tests. The only useful target here is `bench`.
3ce9e010 20# Add benchmark functions in alphabetical order.
8cfdb7e0 21
8cfdb7e0 22subdir := benchtests
a5f891ac
JM
23
24include ../Makeconfig
d8e7d063
L
25
26bench-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 \
3ba0c959 51 fmod \
5c11701c 52 fmodf \
d8e7d063 53 hypot \
b8a6ee43 54 hypotf \
d8e7d063
L
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 \
03e26098 90
8d0985b0 91ifneq (,$(filter yes,$(float96-fcts)))
03c9c4fc
L
92bench-math += \
93 cbrtl \
94# bench-math
8d0985b0
PZ
95endif
96
03e26098 97ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
03c9c4fc
L
98bench-math += \
99 expf128 \
100 ilogbf128 \
101 powf128 \
102 sinf128 \
103# bench-math
03e26098 104endif
bb9c256f 105
03c9c4fc
L
106bench-pthread := \
107 pthread-locks \
10c779f4
NG
108 pthread-mutex-lock \
109 pthread-mutex-trylock \
110 pthread-spin-lock \
111 pthread-spin-trylock \
03c9c4fc
L
112 pthread_once \
113 thread_create \
114# bench-pthread
bb9c256f 115
10c779f4
NG
116LDLIBS-bench-pthread-mutex-lock += -lm
117LDLIBS-bench-pthread-mutex-trylock += -lm
118LDLIBS-bench-pthread-spin-lock += -lm
119LDLIBS-bench-pthread-spin-trylock += -lm
120
03c9c4fc
L
121bench-string := \
122 ffs \
123 ffsll \
124# bench-string
aad287f3 125
c1f75dc3 126# String function benchmarks.
03c9c4fc 127string-benchset := \
dc98eeeb
L
128 bzero \
129 bzero-large \
130 bzero-walk \
03c9c4fc
L
131 memccpy \
132 memchr \
133 memcmp \
134 memcmpeq \
135 memcpy \
136 memcpy-large \
137 memcpy-random \
138 memcpy-walk \
139 memmem \
140 memmove \
141 memmove-large \
142 memmove-walk \
143 mempcpy \
144 memrchr \
145 memset \
146 memset-large \
147 memset-walk \
cf975913
L
148 memset-zero \
149 memset-zero-large \
150 memset-zero-walk \
03c9c4fc
L
151 rawmemchr \
152 stpcpy \
153 stpcpy_chk \
154 stpncpy \
155 strcasecmp \
156 strcasestr \
157 strcat \
158 strchr \
159 strchrnul \
160 strcmp \
161 strcoll \
162 strcpy \
163 strcpy_chk \
164 strcspn \
165 strlen \
166 strncasecmp \
167 strncat \
168 strncmp \
169 strncpy \
170 strnlen \
171 strpbrk \
172 strrchr \
173 strsep \
174 strspn \
175 strstr \
176 strtok \
177# string-benchset
2d304f3c
SP
178
179# Build and run locale-dependent benchmarks only if we're building natively.
180ifeq (no,$(cross-compiling))
03c9c4fc
L
181wcsmbs-benchset := \
182 wcpcpy \
183 wcpncpy \
050cc5f7 184 wcrtomb \
03c9c4fc
L
185 wcscat \
186 wcschr \
187 wcschrnul \
188 wcscmp \
189 wcscpy \
190 wcscspn \
191 wcslen \
192 wcsncat \
193 wcsncmp \
194 wcsncpy \
195 wcsnlen \
196 wcspbrk \
197 wcsrchr \
198 wcsspn \
199 wmemchr \
200 wmemcmp \
201 wmemset \
202# wcsmbs-benchset
2d304f3c
SP
203else
204wcsmbs-benchset :=
205endif
206
aad287f3 207string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
c1f75dc3 208
2d304f3c 209ifeq (no,$(cross-compiling))
60ccaf75 210# We have to generate locales
03c9c4fc
L
211LOCALES := \
212 ar_SA.UTF-8 \
213 cs_CZ.UTF-8 \
214 da_DK.UTF-8 \
215 el_GR.UTF-8 \
216 en_GB.UTF-8 \
217 en_US.UTF-8 \
218 es_ES.UTF-8 \
219 fa_IR.UTF-8 \
220 fr_FR.UTF-8 \
221 he_IL.UTF-8 \
222 hi_IN.UTF-8 \
223 hu_HU.UTF-8 \
224 is_IS.UTF-8 \
225 it_IT.UTF-8 \
226 ja_JP.UTF-8 \
227 pl_PL.UTF-8 \
228 pt_PT.UTF-8 \
229 ru_RU.UTF-8 \
230 si_LK.UTF-8 \
231 sr_RS.UTF-8 \
232 sv_SE.UTF-8 \
233 tr_TR.UTF-8 \
234 vi_VN.UTF-8 \
235 zh_CN.UTF-8 \
236# LOCALES
60ccaf75 237include ../gen-locales.mk
2d304f3c 238endif
60ccaf75 239
319dddc1
NG
240hash-benchset := \
241 dl-elf-hash \
242 dl-new-hash \
243 nss-hash \
244# hash-benchset
245
5d765ada
AZN
246stdlib-benchset := \
247 arc4random \
248 strtod \
249 # stdlib-benchset
450a2e2d 250
aad287f3 251stdio-common-benchset := sprintf
608f8971 252
cb2f668d
WD
253math-benchset := math-inlines
254
0422ed1e 255ifeq (${BENCHSET},)
aad287f3 256benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
319dddc1 257 $(math-benchset) $(hash-benchset)
0422ed1e
VR
258else
259benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
260endif
c1f75dc3 261
f6c55796
WN
262CFLAGS-bench-ffs.c += -fno-builtin
263CFLAGS-bench-ffsll.c += -fno-builtin
7a8330c0 264CFLAGS-bench-sqrt.c += -fno-builtin
5d1f604a 265CFLAGS-bench-fmin.c += -fno-builtin
da16c9b5 266CFLAGS-bench-fminf.c += -fno-builtin
5d1f604a 267CFLAGS-bench-fmax.c += -fno-builtin
da16c9b5 268CFLAGS-bench-fmaxf.c += -fno-builtin
eb375def
JM
269CFLAGS-bench-trunc.c += -fno-builtin
270CFLAGS-bench-truncf.c += -fno-builtin
642d5aba
STH
271CFLAGS-bench-roundeven.c += -fno-builtin
272CFLAGS-bench-roundevenf.c += -fno-builtin
5c5a8b99
AZ
273CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
274CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
275CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
f6c55796 276
0422ed1e 277ifeq (${BENCHSET},)
3904fd85 278bench-malloc := malloc-thread malloc-simple
0422ed1e
VR
279else
280bench-malloc := $(filter malloc-%,${BENCHSET})
281endif
b01ee67c 282
de0a7c5a
L
283ifeq (${STATIC-BENCHTESTS},yes)
284+link-benchtests = $(+link-static-tests)
285link-libc-benchtests = $(link-libc-static)
286libm-benchtests = $(common-objpfx)math/libm.a
287thread-library-benchtests = $(static-thread-library)
288else
289link-libc-benchtests = $(link-libc)
290+link-benchtests = $(+link-tests)
291thread-library-benchtests = $(shared-thread-library)
292libm-benchtests = $(libm)
293endif
294
295$(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
296$(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
297$(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
298$(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
299$(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
9e5daa1f 300$(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
7849ff93 301
8fc1bee5
SP
302\f
303
304# Rules to build and execute the benchmarks. Do not put any benchmark
305# parameters beyond this point.
306
c1f75dc3
SP
307# We don't want the benchmark programs to run in parallel since that could
308# affect their performance.
309.NOTPARALLEL:
310
4504783c
FW
311bench-extra-objs = json-lib.o
312
313extra-objs += $(bench-extra-objs)
314others-extras = $(bench-extra-objs)
315
fe92a91f 316# The default duration: 1 seconds.
d569c6ee 317ifndef BENCH_DURATION
fe92a91f 318BENCH_DURATION := 1
d569c6ee
SP
319endif
320
f1c8185d 321CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
d569c6ee 322
e52434a2
L
323# Use clock_gettime to measure performance of functions. The default is
324# to use the architecture-specific high precision timing instructions.
325ifdef USE_CLOCK_GETTIME
326CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
327else
7cc65773
L
328# On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
329# of functions. All x86 processors since 2010 support RDTSCP instruction.
330ifdef USE_RDTSCP
331CPPFLAGS-nonlib += -DUSE_RDTSCP
332endif
e52434a2 333endif
43fe811b 334
56737508
SP
335DETAILED_OPT :=
336
337ifdef DETAILED
338DETAILED_OPT := -d
339endif
340
43fe811b 341bench-deps := bench-skeleton.c bench-timing.h Makefile
acb4325f 342
8fc1bee5 343run-bench = $(test-wrapper-env) \
8540f6d2 344 $(run-program-env) \
87da630b 345 $($*-ENV) $(test-via-rtld-prefix) $${run}
8fc1bee5 346
cb5e4aad 347timing-type := $(objpfx)bench-timing-type
c12c2a41
L
348extra-objs += bench-timing-type.o
349
350include ../Rules
cb5e4aad 351
5b5b1012
SP
352bench-math += $(bench-libmvec)
353
354ifeq (${BENCHSET},)
355bench := $(bench-math) $(bench-pthread) $(bench-string)
356else
357bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
358endif
359
360# NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
361# benches.
362binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
363extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
364binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
365extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
366binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
367extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
368
3725ee39
AS
369# This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
370# for all these modules.
371cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
372 $(binaries-bench-malloc:=.c) $(timing-type:=.c)
373lib := nonlib
374include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
375
a2964074
SP
376bench-clean:
377 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
c1f75dc3 378 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
b01ee67c 379 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
cb5e4aad 380 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
d7aea0cf 381 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
c1f75dc3 382
0422ed1e
VR
383# Validate the passed in BENCHSET
384ifneq ($(strip ${BENCHSET}),)
319dddc1
NG
385VALIDBENCHSETNAMES := \
386 bench-math \
387 bench-pthread \
388 bench-string \
389 hash-benchset \
390 malloc-simple \
391 malloc-thread \
392 math-benchset \
393 stdio-common-benchset \
394 stdlib-benchset \
395 string-benchset \
396 wcsmbs-benchset \
397# VALIDBENCHSETNAMES
398
0422ed1e
VR
399INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
400ifneq (${INVALIDBENCHSETNAMES},)
401$(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
402$(info The valid ones are: ${VALIDBENCHSETNAMES})
403$(error Invalid BENCHSET value)
404endif
405endif
406
2d304f3c 407bench: bench-build bench-set bench-func bench-malloc
8ce8299f 408
2d304f3c
SP
409# Target to only build the benchmark without running it. We generate locales
410# only if we're building natively.
411ifeq (no,$(cross-compiling))
412bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
413 $(binaries-benchset) $(binaries-bench-malloc)
414else
415bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
416 $(binaries-bench-malloc)
417endif
c1f75dc3
SP
418
419bench-set: $(binaries-benchset)
420 for run in $^; do \
421 echo "Running $${run}"; \
422 $(run-bench) > $${run}.out; \
423 done
a2964074 424
b01ee67c 425bench-malloc: $(binaries-bench-malloc)
0422ed1e 426 for run in $^; do \
3904fd85
WD
427 echo "$${run}"; \
428 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
0422ed1e
VR
429 for thr in 1 8 16 32; do \
430 echo "Running $${run} $${thr}"; \
3904fd85
WD
431 $(run-bench) $${thr} > $${run}-$${thr}.out; \
432 done;\
433 else \
434 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
435 echo "Running $${run} $${thr}"; \
436 $(run-bench) $${thr} > $${run}-$${thr}.out; \
437 done;\
438 fi;\
b01ee67c
WN
439 done
440
cb5e4aad
SP
441# Build and execute the benchmark functions. This target generates JSON
442# formatted bench.out. Each of the programs produce independent JSON output,
443# so one could even execute them individually and process it using any JSON
444# capable language or tool.
c1f75dc3 445bench-func: $(binaries-bench)
0422ed1e 446 if [ -n '$^' ] ; then \
92ce43ee
JM
447 { timing_type=$$($(test-wrapper-env) \
448 $(run-program-env) \
449 $(test-via-rtld-prefix) \
450 $(timing-type)); \
0422ed1e
VR
451 echo "{\"timing_type\": \"$${timing_type}\","; \
452 echo " \"functions\": {"; \
453 for run in $^; do \
944afe6d
SP
454 op=$$($(run-bench) $(DETAILED_OPT)); \
455 ret=$$?; \
456 case "$${ret}" in \
457 77) \
458 echo "UNSUPPORTED $${run}: $${op}" >&2; \
459 ;; \
460 0) \
461 echo "Running $${run}" >&2; \
462 if [ "$${run}" != "$<" ]; then \
463 echo ","; \
464 fi; \
465 echo "$${op}"; \
466 ;; \
467 *) \
468 echo "FAILED $${run}" >&2; \
469 ;; \
470 esac; \
0422ed1e
VR
471 done; \
472 echo; \
473 echo " }"; \
474 echo "}"; \
475 } > $(objpfx)bench.out-tmp; \
476 if [ -f $(objpfx)bench.out ]; then \
477 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
cb5e4aad 478 fi; \
0422ed1e
VR
479 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
480 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
481 scripts/benchout.schema.json; \
482 fi
8fc1bee5 483
b5ffdc48
FW
484ifeq ($(bind-now),yes)
485link-bench-bind-now = -Wl,-z,now
486endif
487
488bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
489 $(binaries-bench-malloc)
490
491$(bench-link-targets): %: %.o $(objpfx)json-lib.o \
009ba649 492 $(link-extra-libs-tests) \
de0a7c5a 493 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
8fc1bee5 494 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
de0a7c5a 495 $(+link-benchtests)
8fc1bee5 496
b5ffdc48
FW
497$(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
498
acb4325f 499$(objpfx)bench-%.c: %-inputs $(bench-deps)
8fc1bee5
SP
500 { if [ -n "$($*-INCLUDE)" ]; then \
501 cat $($*-INCLUDE); \
502 fi; \
67fc5637 503 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
8fc1bee5 504 mv -f $@-tmp $@