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