1 # Copyright (C) 2013-2022 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <https://www.gnu.org/licenses/>.
18 # Makefile for benchmark tests. The only useful target here is `bench`.
19 # Add benchmark functions in alphabetical order.
88 ifneq (,$(filter yes
,$(float96-fcts
)))
92 ifneq (,$(filter yes
,$(float128-fcts
) $(float128-alias-fcts
)))
93 bench-math
+= expf128 powf128 sinf128 ilogbf128
96 bench-pthread
:= pthread_once thread_create pthread-locks
98 bench-string
:= ffs ffsll
101 bench
:= $(bench-math
) $(bench-pthread
) $(bench-string
)
103 bench
:= $(foreach B
,$(filter bench-
%,${BENCHSET}), ${${B}})
106 # String function benchmarks.
107 string-benchset
:= memccpy memchr memcmp memcmpeq memcpy memmem memmove \
108 mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
109 strcat strchr strchrnul strcmp strcpy strcspn strlen \
110 strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
111 strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
112 strcoll memcpy-large memcpy-random memmove-large memset-large \
113 memcpy-walk memset-walk memmove-walk
115 # Build and run locale-dependent benchmarks only if we're building natively.
116 ifeq (no
,$(cross-compiling
))
117 wcsmbs-benchset
:= wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
118 wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
119 wmemchr wmemset wmemcmp
124 string-benchset-all
:= $(string-benchset
) ${wcsmbs-benchset
}
126 ifeq (no
,$(cross-compiling
))
127 # We have to generate locales
128 LOCALES
:= en_US.UTF-8 tr_TR.UTF-8 cs_CZ.UTF-8 fa_IR.UTF-8 fr_FR.UTF-8 \
129 ja_JP.UTF-8 si_LK.UTF-8 en_GB.UTF-8 vi_VN.UTF-8 ar_SA.UTF-8 \
130 da_DK.UTF-8 pl_PL.UTF-8 pt_PT.UTF-8 el_GR.UTF-8 ru_RU.UTF-8 \
131 he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \
132 hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8
133 include ..
/gen-locales.mk
136 stdlib-benchset
:= strtod
138 stdio-common-benchset
:= sprintf
140 math-benchset
:= math-inlines
143 benchset
:= $(string-benchset-all
) $(stdlib-benchset
) $(stdio-common-benchset
) \
146 benchset
:= $(foreach B
,$(filter %-benchset
,${BENCHSET}), ${${B}})
149 CFLAGS-bench-ffs.c
+= -fno-builtin
150 CFLAGS-bench-ffsll.c
+= -fno-builtin
151 CFLAGS-bench-sqrt.c
+= -fno-builtin
152 CFLAGS-bench-fmin.c
+= -fno-builtin
153 CFLAGS-bench-fminf.c
+= -fno-builtin
154 CFLAGS-bench-fmax.c
+= -fno-builtin
155 CFLAGS-bench-fmaxf.c
+= -fno-builtin
156 CFLAGS-bench-trunc.c
+= -fno-builtin
157 CFLAGS-bench-truncf.c
+= -fno-builtin
158 CFLAGS-bench-roundeven.c
+= -fno-builtin
159 CFLAGS-bench-roundevenf.c
+= -fno-builtin
160 CFLAGS-bench-isnan.c
+= -fsignaling-nans
161 CFLAGS-bench-isinf.c
+= -fsignaling-nans
162 CFLAGS-bench-isfinite.c
+= -fsignaling-nans
165 bench-malloc
:= malloc-thread malloc-simple
167 bench-malloc
:= $(filter malloc-
%,${BENCHSET})
170 ifeq (${STATIC-BENCHTESTS
},yes
)
171 +link-benchtests
= $(+link-static-tests
)
172 link-libc-benchtests
= $(link-libc-static
)
173 libm-benchtests
= $(common-objpfx
)math
/libm.a
174 thread-library-benchtests
= $(static-thread-library
)
176 link-libc-benchtests
= $(link-libc
)
177 +link-benchtests
= $(+link-tests
)
178 thread-library-benchtests
= $(shared-thread-library
)
179 libm-benchtests
= $(libm
)
182 $(addprefix $(objpfx
)bench-
,$(bench-math
)): $(libm-benchtests
)
183 $(addprefix $(objpfx
)bench-
,$(math-benchset
)): $(libm-benchtests
)
184 $(addprefix $(objpfx
)bench-
,$(bench-pthread
)): $(thread-library-benchtests
)
185 $(addprefix $(objpfx
)bench-
,$(bench-malloc
)): $(thread-library-benchtests
)
186 $(addprefix $(objpfx
)bench-
,pthread-locks
): $(libm-benchtests
)
190 # Rules to build and execute the benchmarks. Do not put any benchmark
191 # parameters beyond this point.
193 # We don't want the benchmark programs to run in parallel since that could
194 # affect their performance.
197 bench-extra-objs
= json-lib.o
199 extra-objs
+= $(bench-extra-objs
)
200 others-extras
= $(bench-extra-objs
)
204 binaries-bench
:= $(addprefix $(objpfx
)bench-
,$(bench
))
205 binaries-benchset
:= $(addprefix $(objpfx
)bench-
,$(benchset
))
206 binaries-bench-malloc
:= $(addprefix $(objpfx
)bench-
,$(bench-malloc
))
208 # The default duration: 1 seconds.
209 ifndef BENCH_DURATION
213 CPPFLAGS-nonlib
+= -DDURATION
=$(BENCH_DURATION
) -D_ISOMAC
215 # Use clock_gettime to measure performance of functions. The default is
216 # to use the architecture-specific high precision timing instructions.
217 ifdef USE_CLOCK_GETTIME
218 CPPFLAGS-nonlib
+= -DUSE_CLOCK_GETTIME
220 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
221 # of functions. All x86 processors since 2010 support RDTSCP instruction.
223 CPPFLAGS-nonlib
+= -DUSE_RDTSCP
233 bench-deps
:= bench-skeleton.c bench-timing.h Makefile
235 run-bench
= $(test-wrapper-env
) \
237 $($*-ENV
) $(test-via-rtld-prefix
) $${run}
239 timing-type
:= $(objpfx
)bench-timing-type
241 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
242 # for all these modules.
243 cpp-srcs-left
:= $(binaries-benchset
:=.c
) $(binaries-bench
:=.c
) \
244 $(binaries-bench-malloc
:=.c
) $(timing-type
:=.c
)
246 include $(patsubst %,$(..
)libof-iterator.mk
,$(cpp-srcs-left
))
249 rm -f
$(binaries-bench
) $(addsuffix .o
,$(binaries-bench
))
250 rm -f
$(binaries-benchset
) $(addsuffix .o
,$(binaries-benchset
))
251 rm -f
$(binaries-bench-malloc
) $(addsuffix .o
,$(binaries-bench-malloc
))
252 rm -f
$(timing-type
) $(addsuffix .o
,$(timing-type
))
253 rm -f
$(addprefix $(objpfx
),$(bench-extra-objs
))
255 # Validate the passed in BENCHSET
256 ifneq ($(strip ${BENCHSET}),)
257 VALIDBENCHSETNAMES
:= bench-pthread bench-math bench-string string-benchset \
258 wcsmbs-benchset stdlib-benchset stdio-common-benchset math-benchset \
259 malloc-thread malloc-simple
260 INVALIDBENCHSETNAMES
:= $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
261 ifneq (${INVALIDBENCHSETNAMES},)
262 $(info The following values in BENCHSET are invalid
: ${INVALIDBENCHSETNAMES})
263 $(info The valid ones are
: ${VALIDBENCHSETNAMES})
264 $(error Invalid BENCHSET value
)
268 bench
: bench-build bench-set bench-func bench-malloc
270 # Target to only build the benchmark without running it. We generate locales
271 # only if we're building natively.
272 ifeq (no
,$(cross-compiling
))
273 bench-build
: $(gen-locales
) $(timing-type
) $(binaries-bench
) \
274 $(binaries-benchset
) $(binaries-bench-malloc
)
276 bench-build
: $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
277 $(binaries-bench-malloc
)
280 bench-set
: $(binaries-benchset
)
282 echo
"Running $${run}"; \
283 $(run-bench
) > $${run}.out
; \
286 bench-malloc
: $(binaries-bench-malloc
)
289 if
[ `basename $${run}` = "bench-malloc-thread" ]; then \
290 for thr in
1 8 16 32; do \
291 echo
"Running $${run} $${thr}"; \
292 $(run-bench
) $${thr} > $${run}-$${thr}.out
; \
295 for thr in
8 16 32 64 128 256 512 1024 2048 4096; do \
296 echo
"Running $${run} $${thr}"; \
297 $(run-bench
) $${thr} > $${run}-$${thr}.out
; \
302 # Build and execute the benchmark functions. This target generates JSON
303 # formatted bench.out. Each of the programs produce independent JSON output,
304 # so one could even execute them individually and process it using any JSON
305 # capable language or tool.
306 bench-func
: $(binaries-bench
)
307 if
[ -n
'$^' ] ; then \
308 { timing_type
=$$($(test-wrapper-env
) \
310 $(test-via-rtld-prefix
) \
312 echo
"{\"timing_type\": \"$${timing_type}\","; \
313 echo
" \"functions\": {"; \
315 if
! [ "x$${run}" = "x$<" ]; then \
318 echo
"Running $${run}" >&2; \
319 $(run-bench
) $(DETAILED_OPT
); \
324 } > $(objpfx
)bench.out-tmp
; \
325 if
[ -f
$(objpfx
)bench.out
]; then \
326 mv
-f
$(objpfx
)bench.out
$(objpfx
)bench.out.old
; \
328 mv
-f
$(objpfx
)bench.out-tmp
$(objpfx
)bench.out
; \
329 $(PYTHON
) scripts
/validate_benchout.py
$(objpfx
)bench.out \
330 scripts
/benchout.schema.json
; \
333 ifeq ($(bind-now
),yes
)
334 link-bench-bind-now
= -Wl
,-z
,now
337 bench-link-targets
= $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
338 $(binaries-bench-malloc
)
340 $(bench-link-targets
): %: %.o
$(objpfx
)json-lib.o \
341 $(link-extra-libs-tests
) \
342 $(sort $(filter $(common-objpfx
)lib
%,$(link-libc-benchtests
))) \
343 $(addprefix $(csu-objpfx
),start.o
) $(+preinit
) $(+postinit
)
346 $(bench-link-targets
): LDFLAGS
+= $(link-bench-bind-now
)
348 $(objpfx
)bench-
%.c
: %-inputs
$(bench-deps
)
349 { if
[ -n
"$($*-INCLUDE)" ]; then \
352 $(PYTHON
) scripts
/bench.py
$(patsubst %-inputs
,%,$<); } > $@
-tmp