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
236 stdlib-benchset
:= strtod
238 stdio-common-benchset
:= sprintf
240 math-benchset
:= math-inlines
243 benchset
:= $(string-benchset-all
) $(stdlib-benchset
) $(stdio-common-benchset
) \
244 $(math-benchset
) $(hash-benchset
)
246 benchset
:= $(foreach B
,$(filter %-benchset
,${BENCHSET}), ${${B}})
249 CFLAGS-bench-ffs.c
+= -fno-builtin
250 CFLAGS-bench-ffsll.c
+= -fno-builtin
251 CFLAGS-bench-sqrt.c
+= -fno-builtin
252 CFLAGS-bench-fmin.c
+= -fno-builtin
253 CFLAGS-bench-fminf.c
+= -fno-builtin
254 CFLAGS-bench-fmax.c
+= -fno-builtin
255 CFLAGS-bench-fmaxf.c
+= -fno-builtin
256 CFLAGS-bench-trunc.c
+= -fno-builtin
257 CFLAGS-bench-truncf.c
+= -fno-builtin
258 CFLAGS-bench-roundeven.c
+= -fno-builtin
259 CFLAGS-bench-roundevenf.c
+= -fno-builtin
260 CFLAGS-bench-isnan.c
+= -fsignaling-nans
261 CFLAGS-bench-isinf.c
+= -fsignaling-nans
262 CFLAGS-bench-isfinite.c
+= -fsignaling-nans
265 bench-malloc
:= malloc-thread malloc-simple
267 bench-malloc
:= $(filter malloc-
%,${BENCHSET})
270 ifeq (${STATIC-BENCHTESTS
},yes
)
271 +link-benchtests
= $(+link-static-tests
)
272 link-libc-benchtests
= $(link-libc-static
)
273 libm-benchtests
= $(common-objpfx
)math
/libm.a
274 thread-library-benchtests
= $(static-thread-library
)
276 link-libc-benchtests
= $(link-libc
)
277 +link-benchtests
= $(+link-tests
)
278 thread-library-benchtests
= $(shared-thread-library
)
279 libm-benchtests
= $(libm
)
282 $(addprefix $(objpfx
)bench-
,$(bench-math
)): $(libm-benchtests
)
283 $(addprefix $(objpfx
)bench-
,$(math-benchset
)): $(libm-benchtests
)
284 $(addprefix $(objpfx
)bench-
,$(bench-pthread
)): $(thread-library-benchtests
)
285 $(addprefix $(objpfx
)bench-
,$(bench-malloc
)): $(thread-library-benchtests
)
286 $(addprefix $(objpfx
)bench-
,pthread-locks
): $(libm-benchtests
)
287 $(addprefix $(objpfx
)bench-
,pthread-mutex-locks
): $(libm-benchtests
)
291 # Rules to build and execute the benchmarks. Do not put any benchmark
292 # parameters beyond this point.
294 # We don't want the benchmark programs to run in parallel since that could
295 # affect their performance.
298 bench-extra-objs
= json-lib.o
300 extra-objs
+= $(bench-extra-objs
)
301 others-extras
= $(bench-extra-objs
)
303 # The default duration: 1 seconds.
304 ifndef BENCH_DURATION
308 CPPFLAGS-nonlib
+= -DDURATION
=$(BENCH_DURATION
) -D_ISOMAC
310 # Use clock_gettime to measure performance of functions. The default is
311 # to use the architecture-specific high precision timing instructions.
312 ifdef USE_CLOCK_GETTIME
313 CPPFLAGS-nonlib
+= -DUSE_CLOCK_GETTIME
315 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
316 # of functions. All x86 processors since 2010 support RDTSCP instruction.
318 CPPFLAGS-nonlib
+= -DUSE_RDTSCP
328 bench-deps
:= bench-skeleton.c bench-timing.h Makefile
330 run-bench
= $(test-wrapper-env
) \
332 $($*-ENV
) $(test-via-rtld-prefix
) $${run}
334 timing-type
:= $(objpfx
)bench-timing-type
335 extra-objs
+= bench-timing-type.o
339 bench-math
+= $(bench-libmvec
)
342 bench
:= $(bench-math
) $(bench-pthread
) $(bench-string
)
344 bench
:= $(foreach B
,$(filter bench-
%,${BENCHSET}), ${${B}})
347 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
349 binaries-bench
= $(addprefix $(objpfx
)bench-
,$(bench
))
350 extra-objs
+= $(addsuffix .o
,$(addprefix bench-
,$(bench
)))
351 binaries-benchset
= $(addprefix $(objpfx
)bench-
,$(benchset
))
352 extra-objs
+= $(addsuffix .o
,$(addprefix bench-
,$(benchset
)))
353 binaries-bench-malloc
:= $(addprefix $(objpfx
)bench-
,$(bench-malloc
))
354 extra-objs
+= $(addsuffix .o
,$(addprefix bench-
,$(bench-malloc
)))
356 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
357 # for all these modules.
358 cpp-srcs-left
:= $(binaries-benchset
:=.c
) $(binaries-bench
:=.c
) \
359 $(binaries-bench-malloc
:=.c
) $(timing-type
:=.c
)
361 include $(patsubst %,$(..
)libof-iterator.mk
,$(cpp-srcs-left
))
364 rm -f
$(binaries-bench
) $(addsuffix .o
,$(binaries-bench
))
365 rm -f
$(binaries-benchset
) $(addsuffix .o
,$(binaries-benchset
))
366 rm -f
$(binaries-bench-malloc
) $(addsuffix .o
,$(binaries-bench-malloc
))
367 rm -f
$(timing-type
) $(addsuffix .o
,$(timing-type
))
368 rm -f
$(addprefix $(objpfx
),$(bench-extra-objs
))
370 # Validate the passed in BENCHSET
371 ifneq ($(strip ${BENCHSET}),)
372 VALIDBENCHSETNAMES
:= \
380 stdio-common-benchset \
386 INVALIDBENCHSETNAMES
:= $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
387 ifneq (${INVALIDBENCHSETNAMES},)
388 $(info The following values in BENCHSET are invalid
: ${INVALIDBENCHSETNAMES})
389 $(info The valid ones are
: ${VALIDBENCHSETNAMES})
390 $(error Invalid BENCHSET value
)
394 bench
: bench-build bench-set bench-func bench-malloc
396 # Target to only build the benchmark without running it. We generate locales
397 # only if we're building natively.
398 ifeq (no
,$(cross-compiling
))
399 bench-build
: $(gen-locales
) $(timing-type
) $(binaries-bench
) \
400 $(binaries-benchset
) $(binaries-bench-malloc
)
402 bench-build
: $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
403 $(binaries-bench-malloc
)
406 bench-set
: $(binaries-benchset
)
408 echo
"Running $${run}"; \
409 $(run-bench
) > $${run}.out
; \
412 bench-malloc
: $(binaries-bench-malloc
)
415 if
[ `basename $${run}` = "bench-malloc-thread" ]; then \
416 for thr in
1 8 16 32; do \
417 echo
"Running $${run} $${thr}"; \
418 $(run-bench
) $${thr} > $${run}-$${thr}.out
; \
421 for thr in
8 16 32 64 128 256 512 1024 2048 4096; do \
422 echo
"Running $${run} $${thr}"; \
423 $(run-bench
) $${thr} > $${run}-$${thr}.out
; \
428 # Build and execute the benchmark functions. This target generates JSON
429 # formatted bench.out. Each of the programs produce independent JSON output,
430 # so one could even execute them individually and process it using any JSON
431 # capable language or tool.
432 bench-func
: $(binaries-bench
)
433 if
[ -n
'$^' ] ; then \
434 { timing_type
=$$($(test-wrapper-env
) \
436 $(test-via-rtld-prefix
) \
438 echo
"{\"timing_type\": \"$${timing_type}\","; \
439 echo
" \"functions\": {"; \
441 op
=$$($(run-bench
) $(DETAILED_OPT
)); \
445 echo
"UNSUPPORTED $${run}: $${op}" >&2; \
448 echo
"Running $${run}" >&2; \
449 if
[ "$${run}" != "$<" ]; then \
455 echo
"FAILED $${run}" >&2; \
462 } > $(objpfx
)bench.out-tmp
; \
463 if
[ -f
$(objpfx
)bench.out
]; then \
464 mv
-f
$(objpfx
)bench.out
$(objpfx
)bench.out.old
; \
466 mv
-f
$(objpfx
)bench.out-tmp
$(objpfx
)bench.out
; \
467 $(PYTHON
) scripts
/validate_benchout.py
$(objpfx
)bench.out \
468 scripts
/benchout.schema.json
; \
471 ifeq ($(bind-now
),yes
)
472 link-bench-bind-now
= -Wl
,-z
,now
475 bench-link-targets
= $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
476 $(binaries-bench-malloc
)
478 $(bench-link-targets
): %: %.o
$(objpfx
)json-lib.o \
479 $(link-extra-libs-tests
) \
480 $(sort $(filter $(common-objpfx
)lib
%,$(link-libc-benchtests
))) \
481 $(addprefix $(csu-objpfx
),start.o
) $(+preinit
) $(+postinit
)
484 $(bench-link-targets
): LDFLAGS
+= $(link-bench-bind-now
)
486 $(objpfx
)bench-
%.c
: %-inputs
$(bench-deps
)
487 { if
[ -n
"$($*-INCLUDE)" ]; then \
490 $(PYTHON
) scripts
/bench.py
$(patsubst %-inputs
,%,$<); } > $@
-tmp