Peter Marheine has uploaded this change for review.

View Change

Make sleep threshold for delays configurable

This allows the minimum time that default_delay() will choose to sleep
for instead of polling to be configured at build-time. The default
remains unchanged at 100 milliseconds for now.

Change-Id: Ida96e0816ac914ed69d6fd82ad90ebe89cdef1cc
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
---
M Makefile
M meson.build
M meson_options.txt
M udelay.c
M udelay_dos.c
5 files changed, 15 insertions(+), 8 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/06/81606/1
diff --git a/Makefile b/Makefile
index f8aa136..09b31b3 100644
--- a/Makefile
+++ b/Makefile
@@ -542,6 +542,8 @@
# Disable wiki printing by default. It is only useful if you have wiki access.
CONFIG_PRINT_WIKI ?= no

+CONFIG_DELAY_MINIMUM_SLEEP_US ?= 100000
+
# Disable all features if CONFIG_NOTHING=yes is given unless CONFIG_EVERYTHING was also set
ifeq ($(CONFIG_NOTHING), yes)
ifeq ($(CONFIG_EVERYTHING), yes)
@@ -587,6 +589,7 @@
endif

FEATURE_FLAGS += -D'CONFIG_DEFAULT_PROGRAMMER_ARGS="$(CONFIG_DEFAULT_PROGRAMMER_ARGS)"'
+FEATURE_FLAGS += -D'CONFIG_DELAY_MINIMUM_SLEEP_US=$(CONFIG_DELAY_MINIMUM_SLEEP_US)'

################################################################################

diff --git a/meson.build b/meson.build
index 1c8316e..d4a5b9c 100644
--- a/meson.build
+++ b/meson.build
@@ -112,6 +112,9 @@
delay_src = files('udelay_dos.c')
endif
srcs += delay_src
+cargs += ['-DCONFIG_DELAY_MINIMUM_SLEEP_US=@0@'.format(
+ get_option('delay_minimum_sleep_us')
+)]

# check for required symbols
if cc.has_function('clock_gettime')
diff --git a/meson_options.txt b/meson_options.txt
index e62deb6..8a04114 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -22,3 +22,6 @@
option('documentation', type : 'feature', value : 'auto', description : 'build the html documentation')
option('ni845x_search_path', type : 'string', value : 'C:\Program Files (x86)\National Instruments\Ni-845x\MS Visual C',
description : 'Path to search for the proprietary ni845x library and header (32-bit Windows only)')
+option('delay_minimum_sleep_us', type : 'integer', min : 0, value : 100000,
+ description : 'Minimum time in microseconds to suspend execution for (rather than polling) when a delay is required.'
+ + ' Larger values may perform better on machines with low timer resolution, at the cost of increased power.')
diff --git a/udelay.c b/udelay.c
index 14900c7..85ed5b3 100644
--- a/udelay.c
+++ b/udelay.c
@@ -96,11 +96,10 @@
/* Precise delay. */
void default_delay(unsigned int usecs)
{
- /* If the delay is >0.1 s, use internal_sleep because timing does not need to be so precise. */
- if (usecs > 100000) {
- internal_sleep(usecs);
- } else {
+ if (usecs < CONFIG_DELAY_MINIMUM_SLEEP_US) {
clock_usec_delay(usecs);
+ } else {
+ internal_sleep(usecs);
}
}

diff --git a/udelay_dos.c b/udelay_dos.c
index 4a29f73..21ca9b8 100644
--- a/udelay_dos.c
+++ b/udelay_dos.c
@@ -158,14 +158,13 @@
{
static bool calibrated = false;

- /* If the delay is >0.1 s, use internal_sleep because timing does not need to be so precise. */
- if (usecs > 100000) {
- internal_sleep(usecs);
- } else {
+ if (usecs < CONFIG_DELAY_MINIMUM_SLEEP_US) {
if (!calibrated) {
myusec_calibrate_delay();
calibrated = true;
}
myusec_delay(usecs);
+ } else {
+ internal_sleep(usecs);
}
}

To view, visit change 81606. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: Ida96e0816ac914ed69d6fd82ad90ebe89cdef1cc
Gerrit-Change-Number: 81606
Gerrit-PatchSet: 1
Gerrit-Owner: Peter Marheine <pmarheine@chromium.org>
Gerrit-MessageType: newchange