Debian Codegraph @

benchtests/Makefile

raw symbols SCIP
1 # Copyright (C) 2013-2026 Free Software Foundation, Inc.
2 # Copyright The GNU Toolchain Authors.
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
17 # <https://www.gnu.org/licenses/>.
18
19 # Makefile for benchmark tests. The only useful target here is `bench`.
20 # Add benchmark functions in alphabetical order.
21
22 subdir := benchtests
23
24 include ../Makeconfig
25
26 bench-math := \
27 acos \
28 acosf \
29 acosh \
30 acoshf \
31 acospi \
32 acospif \
33 asin \
34 asinf \
35 asinh \
36 asinhf \
37 asinpi \
38 asinpif \
39 atan \
40 atan2 \
41 atan2f \
42 atan2pi \
43 atan2pif \
44 atanf \
45 atanh \
46 atanhf \
47 atanpi \
48 atanpif \
49 cbrt \
50 cbrtf \
51 ceil \
52 ceilf \
53 cos \
54 cosf \
55 cosh \
56 coshf \
57 cospi \
58 cospif \
59 erf \
60 erfc \
61 erfcf \
62 erff \
63 exp \
64 exp10 \
65 exp10f \
66 exp10m1 \
67 exp10m1f \
68 exp2 \
69 exp2f \
70 exp2m1 \
71 exp2m1f \
72 expf \
73 expl \
74 expm1 \
75 expm1f \
76 floor \
77 floorf \
78 fma \
79 fmaf \
80 fmal \
81 fmax \
82 fmaxf \
83 fmin \
84 fminf \
85 fmod \
86 fmodf \
87 frexp \
88 frexpf \
89 frexpl \
90 hypot \
91 hypotf \
92 ilogb \
93 ilogbf \
94 isfinite \
95 isinf \
96 isnan \
97 j0 \
98 j1 \
99 lgamma \
100 lgammaf \
101 lgammaf_r \
102 llrint \
103 llrintf \
104 log \
105 log10 \
106 log10f \
107 log10p1 \
108 log10p1f \
109 log1p \
110 log1pf \
111 log2 \
112 log2f \
113 log2l \
114 log2p1 \
115 log2p1f \
116 logb \
117 logbf \
118 logf \
119 lrint \
120 lrintf \
121 modf \
122 modff \
123 nearbyint \
124 nearbyintf \
125 pow \
126 powf \
127 powl \
128 remainder \
129 remainderf \
130 rint \
131 rintf \
132 roundeven \
133 roundevenf \
134 rsqrt \
135 rsqrtf \
136 sin \
137 sincos \
138 sincosf \
139 sinf \
140 sinh \
141 sinhf \
142 sinpi \
143 sinpif \
144 sqrt \
145 tan \
146 tanf \
147 tanh \
148 tanhf \
149 tanpi \
150 tanpif \
151 tgamma \
152 tgammaf \
153 trunc \
154 truncf \
155 y0 \
156 y1 \
157 # bench-math
158
159 ifneq (,$(filter yes,$(float96-fcts)))
160 bench-math += \
161 cbrtl \
162 # bench-math
163 endif
164
165 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
166 bench-math += \
167 expf128 \
168 ilogbf128 \
169 powf128 \
170 sinf128 \
171 # bench-math
172 endif
173
174 bench-pthread := \
175 pthread-locks \
176 pthread-mutex-lock \
177 pthread-mutex-trylock \
178 pthread-mutex-trylock-recursive-throughput \
179 pthread-mutex-trylock-throughput \
180 pthread-spin-lock \
181 pthread-spin-trylock \
182 pthread_once \
183 thread_create \
184 # bench-pthread
185
186 bench-resolv := \
187 inet_ntop_ipv4 \
188 inet_ntop_ipv6 \
189 # bench-resolv
190
191 LDLIBS-bench-pthread-mutex-lock += -lm
192 LDLIBS-bench-pthread-mutex-trylock += -lm
193 LDLIBS-bench-pthread-mutex-trylock-recursive-throughput += -lm
194 LDLIBS-bench-pthread-mutex-trylock-throughput += -lm
195 LDLIBS-bench-pthread-spin-lock += -lm
196 LDLIBS-bench-pthread-spin-trylock += -lm
197
198 bench-string := \
199 ffs \
200 ffsll \
201 # bench-string
202
203 # String function benchmarks.
204 string-benchset := \
205 bzero \
206 bzero-large \
207 memccpy \
208 memchr \
209 memcmp \
210 memcmpeq \
211 memcpy \
212 memcpy-large \
213 memcpy-random \
214 memmem \
215 memmove \
216 memmove-large \
217 mempcpy \
218 memrchr \
219 memset \
220 memset-large \
221 memset-random \
222 memset-zero \
223 memset-zero-large \
224 rawmemchr \
225 stpcpy \
226 stpcpy_chk \
227 stpncpy \
228 strcasecmp \
229 strcasestr \
230 strcat \
231 strchr \
232 strchrnul \
233 strcmp \
234 strcoll \
235 strcpy \
236 strcpy_chk \
237 strcspn \
238 strlen \
239 strlen-random \
240 strncasecmp \
241 strncat \
242 strncmp \
243 strncpy \
244 strnlen \
245 strpbrk \
246 strrchr \
247 strsep \
248 strspn \
249 strstr \
250 strtok \
251 # string-benchset
252
253 # Build and run locale-dependent benchmarks only if we're building natively.
254 ifeq (no,$(cross-compiling))
255 wcsmbs-benchset := \
256 wcpcpy \
257 wcpncpy \
258 wcrtomb \
259 wcscat \
260 wcschr \
261 wcschrnul \
262 wcscmp \
263 wcscpy \
264 wcscspn \
265 wcslen \
266 wcsncat \
267 wcsncmp \
268 wcsncpy \
269 wcsnlen \
270 wcspbrk \
271 wcsrchr \
272 wcsspn \
273 wmemchr \
274 wmemcmp \
275 wmemset \
276 # wcsmbs-benchset
277 else
278 wcsmbs-benchset :=
279 endif
280
281 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
282
283 ifeq (no,$(cross-compiling))
284 # We have to generate locales
285 LOCALES := \
286 ar_SA.UTF-8 \
287 cs_CZ.UTF-8 \
288 da_DK.UTF-8 \
289 el_GR.UTF-8 \
290 en_GB.UTF-8 \
291 en_US.UTF-8 \
292 es_ES.UTF-8 \
293 fa_IR.UTF-8 \
294 fr_FR.UTF-8 \
295 he_IL.UTF-8 \
296 hi_IN.UTF-8 \
297 hu_HU.UTF-8 \
298 is_IS.UTF-8 \
299 it_IT.UTF-8 \
300 ja_JP.UTF-8 \
301 pl_PL.UTF-8 \
302 pt_PT.UTF-8 \
303 ru_RU.UTF-8 \
304 si_LK.UTF-8 \
305 sr_RS.UTF-8 \
306 sv_SE.UTF-8 \
307 tr_TR.UTF-8 \
308 vi_VN.UTF-8 \
309 zh_CN.UTF-8 \
310 # LOCALES
311 include ../gen-locales.mk
312 endif
313
314 hash-benchset := \
315 dl-elf-hash \
316 dl-new-hash \
317 nss-hash \
318 # hash-benchset
319
320 stdlib-benchset := \
321 arc4random \
322 bsearch \
323 random-lock \
324 strtod \
325 # stdlib-benchset
326
327 stdio-benchset := \
328 fclose \
329 # stdio-benchset
330
331 stdio-common-benchset := sprintf
332
333 math-benchset := math-inlines
334
335 ifeq (${BENCHSET},)
336 benchset := \
337 $(hash-benchset) \
338 $(math-benchset) \
339 $(stdio-benchset) \
340 $(stdio-common-benchset) \
341 $(stdlib-benchset) \
342 $(string-benchset-all) \
343 # benchset
344 else
345 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
346 endif
347
348 CFLAGS-bench-ffs.c += -fno-builtin
349 CFLAGS-bench-ffsll.c += -fno-builtin
350 CFLAGS-bench-sqrt.c += -fno-builtin
351 CFLAGS-bench-fmin.c += -fno-builtin
352 CFLAGS-bench-fminf.c += -fno-builtin
353 CFLAGS-bench-fma.c += -fno-builtin
354 CFLAGS-bench-fmaf.c += -fno-builtin
355 CFLAGS-bench-fmax.c += -fno-builtin
356 CFLAGS-bench-fmaxf.c += -fno-builtin
357 CFLAGS-bench-trunc.c += -fno-builtin
358 CFLAGS-bench-truncf.c += -fno-builtin
359 CFLAGS-bench-fmod.c += -fno-builtin
360 CFLAGS-bench-fmodf.c += -fno-builtin
361 CFLAGS-bench-frexp.c += -fno-builtin
362 CFLAGS-bench-frexpf.c += -fno-builtin
363 CFLAGS-bench-frexpl.c += -fno-builtin
364 CFLAGS-bench-remainder.c += -fno-builtin
365 CFLAGS-bench-remainderf.c += -fno-builtin
366 CFLAGS-bench-roundeven.c += -fno-builtin
367 CFLAGS-bench-roundevenf.c += -fno-builtin
368 CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
369 CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
370 CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
371
372 ifeq (${BENCHSET},)
373 bench-malloc := \
374 calloc-simple \
375 calloc-tcache \
376 calloc-thread \
377 malloc-simple \
378 malloc-tcache \
379 malloc-thread \
380 # bench-malloc
381 else
382 bench-malloc := $(filter malloc-%,${BENCHSET})
383 bench-malloc += $(filter calloc-%,${BENCHSET})
384 endif
385
386 ifeq (${STATIC-BENCHTESTS},yes)
387 +link-benchtests = $(+link-static-tests)
388 link-libc-benchtests = $(link-libc-static)
389 libm-benchtests = $(common-objpfx)math/libm.a
390 thread-library-benchtests = $(static-thread-library)
391 else
392 link-libc-benchtests = $(link-libc)
393 +link-benchtests = $(+link-tests)
394 thread-library-benchtests = $(shared-thread-library)
395 libm-benchtests = $(libm)
396 endif
397
398 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
399 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
400 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
401 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
402 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
403 $(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
404 $(addprefix $(objpfx)bench-,malloc-thread): $(libm-benchtests)
405 $(addprefix $(objpfx)bench-,calloc-thread): $(libm-benchtests)
406
407
408
409 # Rules to build and execute the benchmarks. Do not put any benchmark
410 # parameters beyond this point.
411
412 # We don't want the benchmark programs to run in parallel since that could
413 # affect their performance.
414 .NOTPARALLEL:
415
416 bench-extra-objs = json-lib.o
417
418 extra-objs += $(bench-extra-objs)
419 others-extras = $(bench-extra-objs)
420
421 # The default duration: 1 seconds.
422 ifndef BENCH_DURATION
423 BENCH_DURATION := 1
424 endif
425
426 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
427
428 # Use clock_gettime to measure performance of functions. The default is
429 # to use the architecture-specific high precision timing instructions.
430 ifdef USE_CLOCK_GETTIME
431 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
432 else
433 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
434 # of functions. All x86 processors since 2010 support RDTSCP instruction.
435 ifdef USE_RDTSCP
436 CPPFLAGS-nonlib += -DUSE_RDTSCP
437 endif
438 endif
439
440 DETAILED_OPT :=
441
442 ifdef DETAILED
443 DETAILED_OPT := -d
444 endif
445
446 bench-deps := bench-skeleton.c bench-timing.h Makefile
447
448 run-bench = $(test-wrapper-env) \
449 $(run-program-env) \
450 $($*-ENV) $(test-via-rtld-prefix) $${run}
451
452 timing-type := $(objpfx)bench-timing-type
453 extra-objs += bench-timing-type.o
454
455 include ../Rules
456
457 bench-math += $(bench-libmvec)
458
459 ifeq (${BENCHSET},)
460 bench := \
461 $(bench-math) \
462 $(bench-pthread) \
463 $(bench-resolv) \
464 $(bench-string) \
465 # bench
466 else
467 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
468 endif
469
470 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
471 # benches.
472 binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
473 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
474 binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
475 extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
476 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
477 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
478
479 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
480 # for all these modules.
481 cpp-srcs-left := \
482 $(binaries-bench-malloc:=.c) \
483 $(binaries-bench:=.c) \
484 $(binaries-benchset:=.c) \
485 $(timing-type:=.c) \
486 # cpp-srcs-left
487 lib := nonlib
488 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
489
490 bench-clean:
491 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
492 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
493 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
494 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
495 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
496
497 # Validate the passed in BENCHSET
498 ifneq ($(strip ${BENCHSET}),)
499 VALIDBENCHSETNAMES := \
500 bench-math \
501 bench-pthread \
502 bench-resolv \
503 bench-string \
504 calloc-simple \
505 calloc-tcache \
506 calloc-thread \
507 hash-benchset \
508 malloc-simple \
509 malloc-tcache \
510 malloc-thread \
511 math-benchset \
512 stdio-benchset \
513 stdio-common-benchset \
514 stdlib-benchset \
515 string-benchset \
516 wcsmbs-benchset \
517 # VALIDBENCHSETNAMES
518
519 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
520 ifneq (${INVALIDBENCHSETNAMES},)
521 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
522 $(info The valid ones are: ${VALIDBENCHSETNAMES})
523 $(error Invalid BENCHSET value)
524 endif
525 endif
526
527 bench: bench-build bench-set bench-func bench-malloc
528
529 # Target to only build the benchmark without running it. We generate locales
530 # only if we're building natively.
531 ifeq (no,$(cross-compiling))
532 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
533 $(binaries-benchset) $(binaries-bench-malloc)
534 else
535 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
536 $(binaries-bench-malloc)
537 endif
538
539 bench-set: $(binaries-benchset)
540 for run in $^; do \
541 echo "Running $${run}"; \
542 $(run-bench) > $${run}.out; \
543 done
544
545 bench-malloc: $(binaries-bench-malloc)
546 for run in $^; do \
547 echo "$${run}"; \
548 if basename $${run} | grep -q "bench-[cm]alloc-thread"; then \
549 for thr in 1 8 16 32; do \
550 echo "Running $${run} $${thr}"; \
551 $(run-bench) $${thr} > $${run}-$${thr}.out; \
552 done;\
553 elif basename $${run} | grep -q "bench-[cm]alloc-tcache"; then \
554 for thr in 64 512 1024; do \
555 echo "Running $${run} $${thr}"; \
556 $(run-bench) $${thr} > $${run}-$${thr}.out; \
557 done;\
558 else \
559 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
560 echo "Running $${run} $${thr}"; \
561 $(run-bench) $${thr} > $${run}-$${thr}.out; \
562 done;\
563 fi;\
564 done
565
566 # Build and execute the benchmark functions. This target generates JSON
567 # formatted bench.out. Each of the programs produce independent JSON output,
568 # so one could even execute them individually and process it using any JSON
569 # capable language or tool.
570 bench-func: $(binaries-bench)
571 if [ -n '$^' ] ; then \
572 { timing_type=$$($(test-wrapper-env) \
573 $(run-program-env) \
574 $(test-via-rtld-prefix) \
575 $(timing-type)); \
576 echo "{\"timing_type\": \"$${timing_type}\","; \
577 echo " \"functions\": {"; \
578 for run in $^; do \
579 op=$$($(run-bench) $(DETAILED_OPT)); \
580 ret=$$?; \
581 case "$${ret}" in \
582 77) \
583 echo "UNSUPPORTED $${run}: $${op}" >&2; \
584 ;; \
585 0) \
586 echo "Running $${run}" >&2; \
587 if [ "$${run}" != "$<" ]; then \
588 echo ","; \
589 fi; \
590 echo "$${op}"; \
591 ;; \
592 *) \
593 echo "FAILED $${run}" >&2; \
594 ;; \
595 esac; \
596 done; \
597 echo; \
598 echo " }"; \
599 echo "}"; \
600 } > $(objpfx)bench.out-tmp; \
601 if [ -f $(objpfx)bench.out ]; then \
602 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
603 fi; \
604 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
605 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
606 scripts/benchout.schema.json; \
607 fi
608
609 ifeq ($(bind-now),yes)
610 link-bench-bind-now = -Wl,-z,now
611 endif
612
613 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
614 $(binaries-bench-malloc)
615
616 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
617 $(link-extra-libs-tests) \
618 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
619 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
620 $(+link-benchtests)
621
622 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
623
624 $(objpfx)bench-%.c: %-inputs $(bench-deps)
625 { if [ -n "$($*-INCLUDE)" ]; then \
626 cat $($*-INCLUDE); \
627 fi; \
628 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
629 mv -f $@-tmp $@