94084c
objpfx = $(prefix)/$(ver)/usr/libexec/glibc-benchtests/
94084c
94084c
bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 ffs ffsll \
94084c
	      log log2 modf pow rint sin sincos sinh sqrt tan tanh
94084c
94084c
bench-pthread := pthread_once
94084c
94084c
bench := $(bench-math) $(bench-pthread)
94084c
94084c
run-bench := $(prefix)/$(ver)/lib64/ld-linux-x86-64.so.2 --library-path $(prefix)/$(ver)/lib64 $${run}
94084c
94084c
# String function benchmarks.
94084c
string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
94084c
		mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
94084c
		strcat strchr strchrnul strcmp strcpy strcspn strlen \
94084c
		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
94084c
		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
94084c
string-bench-all := $(string-bench)
94084c
94084c
stdlib-bench := strtod
94084c
94084c
benchset := $(string-bench-all) $(stdlib-bench)
94084c
94084c
bench-malloc := malloc-thread
94084c
94084c
binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
94084c
binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
94084c
binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
94084c
94084c
DETAILED_OPT :=
94084c
94084c
ifdef DETAILED
94084c
	DETAILED_OPT := -d
94084c
endif
94084c
94084c
bench: bench-set bench-func bench-malloc
94084c
94084c
bench-set: $(binaries-benchset)
94084c
	for run in $^; do \
94084c
	  outfile=$(prefix)/$$(basename $${run}.$(ver).out); \
94084c
	  echo "Running $${run}"; \
94084c
	  $(run-bench) > $${outfile}.tmp; \
94084c
	  mv $${outfile}{.tmp,}; \
94084c
	done
94084c
94084c
bench-malloc: $(binaries-bench-malloc)
94084c
	run=$(objpfx)bench-malloc-thread; \
94084c
	outfile=$(prefix)/$$(basename $${run}.$(ver).out); \
94084c
	for thr in 1 8 16 32; do \
94084c
	  echo "Running $${run} $${thr}"; \
94084c
	  $(run-bench) $${thr} > $${outfile}.tmp; \
94084c
	  mv $${outfile}{.tmp,}; \
94084c
	done
94084c
94084c
# Build and execute the benchmark functions.  This target generates JSON
94084c
# formatted bench.out.  Each of the programs produce independent JSON output,
94084c
# so one could even execute them individually and process it using any JSON
94084c
# capable language or tool.
94084c
bench-func: $(binaries-bench)
94084c
	{ echo "{\"timing_type\": \"hp-timing\","; \
94084c
	echo " \"functions\": {"; \
94084c
	for run in $^; do \
94084c
	  if ! [ "x$${run}" = "x$<" ]; then \
94084c
	    echo ","; \
94084c
	  fi; \
94084c
	  echo "Running $${run}" >&2; \
94084c
	  $(run-bench) $(DETAILED_OPT); \
94084c
	done; \
94084c
	echo; \
94084c
	echo " }"; \
94084c
	echo "}"; } > $(prefix)/bench.$(ver).out-tmp; \
94084c
	if [ -f $(prefix)/bench.$(ver).out ]; then \
94084c
	  mv -f $(prefix)/bench.$(ver).out{,.old}; \
94084c
	fi; \
94084c
	mv -f $(prefix)/bench.$(ver).out{-tmp,}
94084c
#	scripts/validate_benchout.py bench.out \
94084c
#		scripts/benchout.schema.json