From 8624e8cfa88ebd17ecf3bfd55c8dc1a799f47573 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Mon, 5 Nov 2012 21:46:33 +0100 Subject: udelay: Use clock_gettime() if available and precise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of calibrating our busy loop against a coarse clock, check if a precise clock is available and loop against that. The former is unre- liable by definition on any modern system that may dynamically reclock the processor. v2: Apparently _POSIX_MONOTONIC_CLOCK being defined only means that the library knows about CLOCK_MONOTONIC. So check for its support at runtime and fall back to CLOCK_REALTIME if it's missing. TEST=Manually added a 10s loop and compared to real time. Run on Linux RPi3, Linux x86 and my original use case Linux in VirtualBox (Linux host). Change-Id: I85ad359823875237ada9cd027af3017d62e9a235 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/19391 Reviewed-by: Stefan Reinauer Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: David Hendricks Tested-by: build bot (Jenkins) --- Makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 65026dae..8b21431e 100644 --- a/Makefile +++ b/Makefile @@ -1003,6 +1003,9 @@ FEATURE_CFLAGS += $(call debug_shell,grep -q "UTSNAME := yes" .features && print # We could use PULLED_IN_LIBS, but that would be ugly. FEATURE_LIBS += $(call debug_shell,grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz") +FEATURE_CFLAGS += $(call debug_shell,grep -q "CLOCK_GETTIME := yes" .features && printf "%s" "-D'HAVE_CLOCK_GETTIME=1'") +FEATURE_LIBS += $(call debug_shell,grep -q "CLOCK_GETTIME := yes" .features && printf "%s" "-lrt") + LIBFLASHROM_OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS) OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS) @@ -1299,6 +1302,18 @@ int main(int argc, char **argv) endef export LINUX_I2C_TEST +define CLOCK_GETTIME_TEST +#include + +int main(int argc, char **argv) +{ + struct timespec res; + clock_gettime(CLOCK_REALTIME, &res); + return 0; +} +endef +export CLOCK_GETTIME_TEST + features: compiler @echo "FEATURES := yes" > .features.tmp ifneq ($(NEED_LIBFTDI), ) @@ -1341,6 +1356,13 @@ endif @ { $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >&2 && \ ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \ ( echo "not found."; echo "UTSNAME := no" >> .features.tmp ) } 2>>$(BUILD_DETAILS_FILE) | tee -a $(BUILD_DETAILS_FILE) + @printf "Checking for clock_gettime support... " | tee -a $(BUILD_DETAILS_FILE) + @echo "$$CLOCK_GETTIME_TEST" >.featuretest.c + @printf "\nexec: %s\n" "$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lrt .featuretest.c -o .featuretest$(EXEC_SUFFIX)" >>$(BUILD_DETAILS_FILE) + @ { $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lrt .featuretest.c -o .featuretest$(EXEC_SUFFIX) >&2 && \ + ( echo "found."; echo "CLOCK_GETTIME := yes" >>.features.tmp ) || \ + ( echo "not found."; echo "CLOCK_GETTIME := no" >>.features.tmp ) } \ + 2>>$(BUILD_DETAILS_FILE) | tee -a $(BUILD_DETAILS_FILE) @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features @rm -f .featuretest.c .featuretest$(EXEC_SUFFIX) -- cgit v1.2.3