1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-06-30 21:52:36 +02:00

udelay: only use OS time for delays, except on DOS

As proposed on the mailing list ("RFC: remove the calibrated delay
loop" [1]), this removes the calibrated delay loop and uses OS-based
timing functions for all delays because the calibrated delay loop can
delay for shorter times than intended.

When sleeping this now uses nanosleep() unconditionally, since usleep
was only used on DOS (where DJGPP lacks nanosleep).  When busy-looping,
it uses clock_gettime() with CLOCK_MONOTONIC or CLOCK_REALTIME depending
on availability, and gettimeofday() otherwise.

The calibrated delay loop is retained for DOS only, because timer
resolution on DJGPP is only about 50 milliseconds. Since typical delays
in flashrom are around 10 microseconds, using OS timing there would
regress performance by around 500x. The old implementation is reused
with some branches removed based on the knowledge that timer resolution
will not be better than about 50 milliseconds.

Tested by reading and writing flash on several Intel and AMD systems:

 * Lenovo P920 (Intel C620, read/verify only)
 * "nissa" chromebook (Intel Alder Lake-N)
 * "zork" chromebook (AMD Zen+)

[1]: https://mail.coreboot.org/hyperkitty/list/flashrom@flashrom.org/thread/HFH6UHPAKA4JDL4YKPSQPO72KXSSRGME/

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I7ac5450d194a475143698d65d64d8bcd2fd25e3f
Reviewed-on: https://review.coreboot.org/c/flashrom/+/81545
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
This commit is contained in:
Peter Marheine
2024-03-27 10:54:01 +11:00
parent a79ec2425e
commit 183208b5cb
10 changed files with 268 additions and 178 deletions

View File

@ -100,13 +100,19 @@ srcs = files(
'sst49lfxxxc.c',
'sst_fwhub.c',
'stm50.c',
'udelay.c',
'w29ee011.c',
'w39.c',
'writeprotect.c',
'writeprotect_ranges.c',
)
# Select an appropriate delay implementation for the target OS
delay_src = files('udelay.c')
if target_machine.system() == 'dos'
delay_src = files('udelay_dos.c')
endif
srcs += delay_src
# check for required symbols
if cc.has_function('clock_gettime')
add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')