]> git.ipfire.org Git - thirdparty/glibc.git/blob - benchtests/Makefile
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / benchtests / Makefile
1 # Copyright (C) 2013-2021 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.
17
18 # Makefile for benchmark tests. The only useful target here is `bench`.
19 # Add benchmark functions in alphabetical order.
20
21 subdir := benchtests
22
23 include ../Makeconfig
24 bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 \
25 modf pow rint sin sincos sinh sqrt tan tanh fmin fmax fminf \
26 fmaxf powf trunc truncf roundeven roundevenf expf exp2f logf \
27 log2f sincosf sinf cosf isnan isinf isfinite hypot logb logbf \
28 exp10f
29
30 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
31 bench-math += expf128 powf128 sinf128
32 endif
33
34 bench-pthread := pthread_once thread_create pthread-locks
35
36 bench-string := ffs ffsll
37
38 ifeq (${BENCHSET},)
39 bench := $(bench-math) $(bench-pthread) $(bench-string)
40 else
41 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
42 endif
43
44 # String function benchmarks.
45 string-benchset := memccpy memchr memcmp memcpy memmem memmove \
46 mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
47 strcat strchr strchrnul strcmp strcpy strcspn strlen \
48 strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
49 strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
50 strcoll memcpy-large memcpy-random memmove-large memset-large \
51 memcpy-walk memset-walk memmove-walk
52
53 # Build and run locale-dependent benchmarks only if we're building natively.
54 ifeq (no,$(cross-compiling))
55 wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
56 wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
57 wmemchr wmemset wmemcmp
58 else
59 wcsmbs-benchset :=
60 endif
61
62 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
63
64 ifeq (no,$(cross-compiling))
65 # We have to generate locales
66 LOCALES := en_US.UTF-8 tr_TR.UTF-8 cs_CZ.UTF-8 fa_IR.UTF-8 fr_FR.UTF-8 \
67 ja_JP.UTF-8 si_LK.UTF-8 en_GB.UTF-8 vi_VN.UTF-8 ar_SA.UTF-8 \
68 da_DK.UTF-8 pl_PL.UTF-8 pt_PT.UTF-8 el_GR.UTF-8 ru_RU.UTF-8 \
69 he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \
70 hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8
71 include ../gen-locales.mk
72 endif
73
74 stdlib-benchset := strtod
75
76 stdio-common-benchset := sprintf
77
78 math-benchset := math-inlines
79
80 ifeq (${BENCHSET},)
81 benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
82 $(math-benchset)
83 else
84 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
85 endif
86
87 CFLAGS-bench-ffs.c += -fno-builtin
88 CFLAGS-bench-ffsll.c += -fno-builtin
89 CFLAGS-bench-sqrt.c += -fno-builtin
90 CFLAGS-bench-fmin.c += -fno-builtin
91 CFLAGS-bench-fminf.c += -fno-builtin
92 CFLAGS-bench-fmax.c += -fno-builtin
93 CFLAGS-bench-fmaxf.c += -fno-builtin
94 CFLAGS-bench-trunc.c += -fno-builtin
95 CFLAGS-bench-truncf.c += -fno-builtin
96 CFLAGS-bench-roundeven.c += -fno-builtin
97 CFLAGS-bench-roundevenf.c += -fno-builtin
98 CFLAGS-bench-isnan.c += -fsignaling-nans
99 CFLAGS-bench-isinf.c += -fsignaling-nans
100 CFLAGS-bench-isfinite.c += -fsignaling-nans
101
102 ifeq (${BENCHSET},)
103 bench-malloc := malloc-thread malloc-simple
104 else
105 bench-malloc := $(filter malloc-%,${BENCHSET})
106 endif
107
108 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm)
109 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm)
110 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(shared-thread-library)
111 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(shared-thread-library)
112 $(addprefix $(objpfx)bench-,pthread-locks): $(libm)
113
114 \f
115
116 # Rules to build and execute the benchmarks. Do not put any benchmark
117 # parameters beyond this point.
118
119 # We don't want the benchmark programs to run in parallel since that could
120 # affect their performance.
121 .NOTPARALLEL:
122
123 bench-extra-objs = json-lib.o
124
125 extra-objs += $(bench-extra-objs)
126 others-extras = $(bench-extra-objs)
127
128 include ../Rules
129
130 binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
131 binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
132 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
133
134 # The default duration: 1 seconds.
135 ifndef BENCH_DURATION
136 BENCH_DURATION := 1
137 endif
138
139 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
140
141 # Use clock_gettime to measure performance of functions. The default is
142 # to use the architecture-specific high precision timing instructions.
143 ifdef USE_CLOCK_GETTIME
144 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
145 else
146 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
147 # of functions. All x86 processors since 2010 support RDTSCP instruction.
148 ifdef USE_RDTSCP
149 CPPFLAGS-nonlib += -DUSE_RDTSCP
150 endif
151 endif
152
153 DETAILED_OPT :=
154
155 ifdef DETAILED
156 DETAILED_OPT := -d
157 endif
158
159 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
160 # for all these modules.
161 cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
162 $(binaries-bench-malloc:=.c)
163 lib := nonlib
164 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
165
166 bench-deps := bench-skeleton.c bench-timing.h Makefile
167
168 run-bench = $(test-wrapper-env) \
169 $(run-program-env) \
170 $($*-ENV) $(test-via-rtld-prefix) $${run}
171
172 timing-type := $(objpfx)bench-timing-type
173
174 bench-clean:
175 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
176 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
177 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
178 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
179 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
180
181 # Validate the passed in BENCHSET
182 ifneq ($(strip ${BENCHSET}),)
183 VALIDBENCHSETNAMES := bench-pthread bench-math bench-string string-benchset \
184 wcsmbs-benchset stdlib-benchset stdio-common-benchset math-benchset \
185 malloc-thread malloc-simple
186 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
187 ifneq (${INVALIDBENCHSETNAMES},)
188 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
189 $(info The valid ones are: ${VALIDBENCHSETNAMES})
190 $(error Invalid BENCHSET value)
191 endif
192 endif
193
194 bench: bench-build bench-set bench-func bench-malloc
195
196 # Target to only build the benchmark without running it. We generate locales
197 # only if we're building natively.
198 ifeq (no,$(cross-compiling))
199 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
200 $(binaries-benchset) $(binaries-bench-malloc)
201 else
202 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
203 $(binaries-bench-malloc)
204 endif
205
206 bench-set: $(binaries-benchset)
207 for run in $^; do \
208 echo "Running $${run}"; \
209 $(run-bench) > $${run}.out; \
210 done
211
212 bench-malloc: $(binaries-bench-malloc)
213 for run in $^; do \
214 echo "$${run}"; \
215 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
216 for thr in 1 8 16 32; do \
217 echo "Running $${run} $${thr}"; \
218 $(run-bench) $${thr} > $${run}-$${thr}.out; \
219 done;\
220 else \
221 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
222 echo "Running $${run} $${thr}"; \
223 $(run-bench) $${thr} > $${run}-$${thr}.out; \
224 done;\
225 fi;\
226 done
227
228 # Build and execute the benchmark functions. This target generates JSON
229 # formatted bench.out. Each of the programs produce independent JSON output,
230 # so one could even execute them individually and process it using any JSON
231 # capable language or tool.
232 bench-func: $(binaries-bench)
233 if [ -n '$^' ] ; then \
234 { timing_type=$$($(test-wrapper-env) \
235 $(run-program-env) \
236 $(test-via-rtld-prefix) \
237 $(timing-type)); \
238 echo "{\"timing_type\": \"$${timing_type}\","; \
239 echo " \"functions\": {"; \
240 for run in $^; do \
241 if ! [ "x$${run}" = "x$<" ]; then \
242 echo ","; \
243 fi; \
244 echo "Running $${run}" >&2; \
245 $(run-bench) $(DETAILED_OPT); \
246 done; \
247 echo; \
248 echo " }"; \
249 echo "}"; \
250 } > $(objpfx)bench.out-tmp; \
251 if [ -f $(objpfx)bench.out ]; then \
252 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
253 fi; \
254 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
255 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
256 scripts/benchout.schema.json; \
257 fi
258
259 ifeq ($(bind-now),yes)
260 link-bench-bind-now = -Wl,-z,now
261 endif
262
263 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
264 $(binaries-bench-malloc)
265
266 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
267 $(link-extra-libs-tests) \
268 $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
269 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
270 $(+link-tests)
271
272 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
273
274 $(objpfx)bench-%.c: %-inputs $(bench-deps)
275 { if [ -n "$($*-INCLUDE)" ]; then \
276 cat $($*-INCLUDE); \
277 fi; \
278 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
279 mv -f $@-tmp $@