]>
Commit | Line | Data |
---|---|---|
bfff8b1b | 1 | # Copyright (C) 2013-2017 Free Software Foundation, Inc. |
8cfdb7e0 SP |
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 | # <http://www.gnu.org/licenses/>. | |
17 | ||
8cfdb7e0 | 18 | # Makefile for benchmark tests. The only useful target here is `bench`. |
3ce9e010 | 19 | # Add benchmark functions in alphabetical order. |
8cfdb7e0 | 20 | |
8cfdb7e0 | 21 | subdir := benchtests |
a5f891ac JM |
22 | |
23 | include ../Makeconfig | |
aad287f3 | 24 | bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 \ |
da16c9b5 | 25 | modf pow rint sin sincos sinh sqrt tan tanh fmin fmax fminf \ |
077ee129 RS |
26 | fmaxf powf trunc truncf expf exp2f logf log2f sincosf sinf \ |
27 | cosf | |
bb9c256f | 28 | |
0edbf123 | 29 | bench-pthread := pthread_once thread_create |
bb9c256f | 30 | |
aad287f3 SP |
31 | bench-string := ffs ffsll |
32 | ||
33 | bench := $(bench-math) $(bench-pthread) $(bench-string) | |
3ce9e010 | 34 | |
c1f75dc3 | 35 | # String function benchmarks. |
aad287f3 SP |
36 | string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \ |
37 | mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \ | |
38 | strcat strchr strchrnul strcmp strcpy strcspn strlen \ | |
39 | strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \ | |
40 | strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \ | |
9ec87fd2 | 41 | strcoll memcpy-large memcpy-random memmove-large memset-large \ |
5bfb0404 | 42 | memcpy-walk memset-walk memmove-walk |
2d304f3c SP |
43 | |
44 | # Build and run locale-dependent benchmarks only if we're building natively. | |
45 | ifeq (no,$(cross-compiling)) | |
aad287f3 SP |
46 | wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \ |
47 | wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \ | |
48 | wmemchr wmemset wmemcmp | |
2d304f3c SP |
49 | else |
50 | wcsmbs-benchset := | |
51 | endif | |
52 | ||
aad287f3 | 53 | string-benchset-all := $(string-benchset) ${wcsmbs-benchset} |
c1f75dc3 | 54 | |
2d304f3c | 55 | ifeq (no,$(cross-compiling)) |
60ccaf75 LH |
56 | # We have to generate locales |
57 | LOCALES := en_US.UTF-8 tr_TR.UTF-8 cs_CZ.UTF-8 fa_IR.UTF-8 fr_FR.UTF-8 \ | |
58 | ja_JP.UTF-8 si_LK.UTF-8 en_GB.UTF-8 vi_VN.UTF-8 ar_SA.UTF-8 \ | |
59 | da_DK.UTF-8 pl_PL.UTF-8 pt_PT.UTF-8 el_GR.UTF-8 ru_RU.UTF-8 \ | |
20003c49 | 60 | he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \ |
60ccaf75 LH |
61 | hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8 |
62 | include ../gen-locales.mk | |
2d304f3c | 63 | endif |
60ccaf75 | 64 | |
aad287f3 | 65 | stdlib-benchset := strtod |
450a2e2d | 66 | |
aad287f3 | 67 | stdio-common-benchset := sprintf |
608f8971 | 68 | |
cb2f668d WD |
69 | math-benchset := math-inlines |
70 | ||
aad287f3 | 71 | benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \ |
cb2f668d | 72 | $(math-benchset) |
c1f75dc3 | 73 | |
f6c55796 WN |
74 | CFLAGS-bench-ffs.c += -fno-builtin |
75 | CFLAGS-bench-ffsll.c += -fno-builtin | |
7a8330c0 | 76 | CFLAGS-bench-sqrt.c += -fno-builtin |
5d1f604a | 77 | CFLAGS-bench-fmin.c += -fno-builtin |
da16c9b5 | 78 | CFLAGS-bench-fminf.c += -fno-builtin |
5d1f604a | 79 | CFLAGS-bench-fmax.c += -fno-builtin |
da16c9b5 | 80 | CFLAGS-bench-fmaxf.c += -fno-builtin |
eb375def JM |
81 | CFLAGS-bench-trunc.c += -fno-builtin |
82 | CFLAGS-bench-truncf.c += -fno-builtin | |
f6c55796 | 83 | |
b01ee67c WN |
84 | bench-malloc := malloc-thread |
85 | ||
79520f4b | 86 | $(addprefix $(objpfx)bench-,$(bench-math)): $(libm) |
cb2f668d | 87 | $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm) |
79520f4b | 88 | $(addprefix $(objpfx)bench-,$(bench-pthread)): $(shared-thread-library) |
b01ee67c | 89 | $(objpfx)bench-malloc-thread: $(shared-thread-library) |
7849ff93 | 90 | |
8fc1bee5 SP |
91 | \f |
92 | ||
93 | # Rules to build and execute the benchmarks. Do not put any benchmark | |
94 | # parameters beyond this point. | |
95 | ||
c1f75dc3 SP |
96 | # We don't want the benchmark programs to run in parallel since that could |
97 | # affect their performance. | |
98 | .NOTPARALLEL: | |
99 | ||
4504783c FW |
100 | bench-extra-objs = json-lib.o |
101 | ||
102 | extra-objs += $(bench-extra-objs) | |
103 | others-extras = $(bench-extra-objs) | |
104 | ||
8cfdb7e0 | 105 | include ../Rules |
8fc1bee5 SP |
106 | |
107 | binaries-bench := $(addprefix $(objpfx)bench-,$(bench)) | |
c1f75dc3 | 108 | binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset)) |
b01ee67c | 109 | binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc)) |
8fc1bee5 | 110 | |
d569c6ee SP |
111 | # The default duration: 10 seconds. |
112 | ifndef BENCH_DURATION | |
113 | BENCH_DURATION := 10 | |
114 | endif | |
115 | ||
50b818bf | 116 | CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) |
d569c6ee | 117 | |
43fe811b SP |
118 | # Use clock_gettime to measure performance of functions. The default is to use |
119 | # HP_TIMING if it is available. | |
120 | ifdef USE_CLOCK_GETTIME | |
121 | CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME | |
122 | endif | |
123 | ||
56737508 SP |
124 | DETAILED_OPT := |
125 | ||
126 | ifdef DETAILED | |
127 | DETAILED_OPT := -d | |
128 | endif | |
129 | ||
4856bcd2 SP |
130 | # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed |
131 | # for all these modules. | |
b01ee67c WN |
132 | cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \ |
133 | $(binaries-bench-malloc:=.c) | |
4856bcd2 | 134 | lib := nonlib |
2bfdaedd | 135 | include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left)) |
4856bcd2 | 136 | |
43fe811b | 137 | bench-deps := bench-skeleton.c bench-timing.h Makefile |
acb4325f | 138 | |
8fc1bee5 | 139 | run-bench = $(test-wrapper-env) \ |
8540f6d2 | 140 | $(run-program-env) \ |
87da630b | 141 | $($*-ENV) $(test-via-rtld-prefix) $${run} |
8fc1bee5 | 142 | |
cb5e4aad SP |
143 | timing-type := $(objpfx)bench-timing-type |
144 | ||
a2964074 SP |
145 | bench-clean: |
146 | rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench)) | |
c1f75dc3 | 147 | rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset)) |
b01ee67c | 148 | rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc)) |
cb5e4aad | 149 | rm -f $(timing-type) $(addsuffix .o,$(timing-type)) |
d7aea0cf | 150 | rm -f $(addprefix $(objpfx),$(bench-extra-objs)) |
c1f75dc3 | 151 | |
8ce8299f SP |
152 | # Define the bench target only if the target has a usable python installation. |
153 | ifdef PYTHON | |
2d304f3c | 154 | bench: bench-build bench-set bench-func bench-malloc |
8ce8299f SP |
155 | else |
156 | bench: | |
157 | @echo "The bench target needs python to run." | |
158 | @exit 1 | |
159 | endif | |
160 | ||
2d304f3c SP |
161 | # Target to only build the benchmark without running it. We generate locales |
162 | # only if we're building natively. | |
163 | ifeq (no,$(cross-compiling)) | |
164 | bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \ | |
165 | $(binaries-benchset) $(binaries-bench-malloc) | |
166 | else | |
167 | bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \ | |
168 | $(binaries-bench-malloc) | |
169 | endif | |
c1f75dc3 SP |
170 | |
171 | bench-set: $(binaries-benchset) | |
172 | for run in $^; do \ | |
173 | echo "Running $${run}"; \ | |
174 | $(run-bench) > $${run}.out; \ | |
175 | done | |
a2964074 | 176 | |
b01ee67c WN |
177 | bench-malloc: $(binaries-bench-malloc) |
178 | run=$(objpfx)bench-malloc-thread; \ | |
179 | for thr in 1 8 16 32; do \ | |
180 | echo "Running $${run} $${thr}"; \ | |
181 | $(run-bench) $${thr} > $${run}-$${thr}.out; \ | |
182 | done | |
183 | ||
cb5e4aad SP |
184 | # Build and execute the benchmark functions. This target generates JSON |
185 | # formatted bench.out. Each of the programs produce independent JSON output, | |
186 | # so one could even execute them individually and process it using any JSON | |
187 | # capable language or tool. | |
c1f75dc3 | 188 | bench-func: $(binaries-bench) |
970c602a WN |
189 | { timing_type=$$($(timing-type)); \ |
190 | echo "{\"timing_type\": \"$${timing_type}\","; \ | |
191 | echo " \"functions\": {"; \ | |
cb5e4aad SP |
192 | for run in $^; do \ |
193 | if ! [ "x$${run}" = "x$<" ]; then \ | |
194 | echo ","; \ | |
195 | fi; \ | |
206a6699 | 196 | echo "Running $${run}" >&2; \ |
56737508 | 197 | $(run-bench) $(DETAILED_OPT); \ |
cb5e4aad | 198 | done; \ |
970c602a WN |
199 | echo; \ |
200 | echo " }"; \ | |
cb5e4aad | 201 | echo "}"; } > $(objpfx)bench.out-tmp; \ |
8fc1bee5 SP |
202 | if [ -f $(objpfx)bench.out ]; then \ |
203 | mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \ | |
204 | fi; \ | |
205 | mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out | |
67fc5637 | 206 | $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \ |
42b1161e | 207 | scripts/benchout.schema.json |
8fc1bee5 | 208 | |
b01ee67c WN |
209 | $(timing-type) $(binaries-bench) $(binaries-benchset) \ |
210 | $(binaries-bench-malloc): %: %.o $(objpfx)json-lib.o \ | |
009ba649 | 211 | $(link-extra-libs-tests) \ |
8fc1bee5 SP |
212 | $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \ |
213 | $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit) | |
87da630b | 214 | $(+link-tests) |
8fc1bee5 | 215 | |
acb4325f | 216 | $(objpfx)bench-%.c: %-inputs $(bench-deps) |
8fc1bee5 SP |
217 | { if [ -n "$($*-INCLUDE)" ]; then \ |
218 | cat $($*-INCLUDE); \ | |
219 | fi; \ | |
67fc5637 | 220 | $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp |
8fc1bee5 | 221 | mv -f $@-tmp $@ |