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.
89 ifneq (,$(filter yes
,$(float96-fcts
)))
95 ifneq (,$(filter yes
,$(float128-fcts
) $(float128-alias-fcts
)))
106 pthread-mutex-locks \
116 # String function benchmarks.
169 # Build and run locale-dependent benchmarks only if we're building natively.
170 ifeq (no
,$(cross-compiling
))
197 string-benchset-all
:= $(string-benchset
) ${wcsmbs-benchset
}
199 ifeq (no
,$(cross-compiling
))
200 # We have to generate locales
227 include ..
/gen-locales.mk
241 stdio-common-benchset
:= sprintf
243 math-benchset
:= math-inlines
246 benchset
:= $(string-benchset-all
) $(stdlib-benchset
) $(stdio-common-benchset
) \
247 $(math-benchset
) $(hash-benchset
)
249 benchset
:= $(foreach B
,$(filter %-benchset
,${BENCHSET}), ${${B}})
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
268 bench-malloc
:= malloc-thread malloc-simple
270 bench-malloc
:= $(filter malloc-
%,${BENCHSET})
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
)
279 link-libc-benchtests
= $(link-libc
)
280 +link-benchtests
= $(+link-tests
)
281 thread-library-benchtests
= $(shared-thread-library
)
282 libm-benchtests
= $(libm
)
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.
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
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
318 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
319 # of functions. All x86 processors since 2010 support RDTSCP instruction.
321 CPPFLAGS-nonlib
+= -DUSE_RDTSCP
331 bench-deps
:= bench-skeleton.c bench-timing.h Makefile
333 run-bench
= $(test-wrapper-env
) \
335 $($*-ENV
) $(test-via-rtld-prefix
) $${run}
337 timing-type
:= $(objpfx
)bench-timing-type
338 extra-objs
+= bench-timing-type.o
342 bench-math
+= $(bench-libmvec
)
345 bench
:= $(bench-math
) $(bench-pthread
) $(bench-string
)
347 bench
:= $(foreach B
,$(filter bench-
%,${BENCHSET}), ${${B}})
350 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
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
)
364 include $(patsubst %,$(..
)libof-iterator.mk
,$(cpp-srcs-left
))
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
:= \
383 stdio-common-benchset \
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
)
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
)
405 bench-build
: $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
406 $(binaries-bench-malloc
)
409 bench-set
: $(binaries-benchset
)
411 echo
"Running $${run}"; \
412 $(run-bench
) > $${run}.out
; \
415 bench-malloc
: $(binaries-bench-malloc
)
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
; \
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
; \
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
) \
439 $(test-via-rtld-prefix
) \
441 echo
"{\"timing_type\": \"$${timing_type}\","; \
442 echo
" \"functions\": {"; \
444 op
=$$($(run-bench
) $(DETAILED_OPT
)); \
448 echo
"UNSUPPORTED $${run}: $${op}" >&2; \
451 echo
"Running $${run}" >&2; \
452 if
[ "$${run}" != "$<" ]; then \
458 echo
"FAILED $${run}" >&2; \
465 } > $(objpfx
)bench.out-tmp
; \
466 if
[ -f
$(objpfx
)bench.out
]; then \
467 mv
-f
$(objpfx
)bench.out
$(objpfx
)bench.out.old
; \
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
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
)
487 $(bench-link-targets
): LDFLAGS
+= $(link-bench-bind-now
)
489 $(objpfx
)bench-
%.c
: %-inputs
$(bench-deps
)
490 { if
[ -n
"$($*-INCLUDE)" ]; then \
493 $(PYTHON
) scripts
/bench.py
$(patsubst %-inputs
,%,$<); } > $@
-tmp