diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-04 00:57:48 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-04 00:57:48 +0000 |
| commit | 0d3a8749fedf8c51ee614f16d3fa664a94de8d27 (patch) | |
| tree | f5176e8567e9e2ba6450ebe8a3124593fb960833 /util/nvmutil/nvmutil.c | |
| parent | 3d27c77a63773bae8e8153434769eba7c4925acc (diff) | |
util/nvmutil: usleep 1 on check_read_or_die
This prevents hogging the CPU in a tight loop,
while waiting for access.
I've also reduced the number of tries to 30, rather
than 200. This is more conservative, while still
being somewhat permissive.
The addition of the usleep delay probably makes
this more reliable than the previous behaviour of
quickly spinning through 200 tries, but without
hogging CPU resources.
I *could* allow this loop to be infinite, but
I regard infinite spin-lock as an error state.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 175683a5..ce628699 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -60,7 +60,7 @@ static void set_err(int); #define SIZE_16KB 0x4000 #define SIZE_128KB 0x20000 -#define MAX_RETRY_READ 200 +#define MAX_RETRY_READ 30 #define items(x) (sizeof((x)) / sizeof((x)[0])) @@ -446,6 +446,9 @@ check_read_or_die(const char *rpath, ssize_t rval, size_t rsize, err(EINTR, "%s: max retries exceeded on file: %s", readtype, rpath); + /* Prevent CPU hog when on spin-locked reads. */ + usleep(1); + /* * Bad read, with errno EINTR (syscall interrupted). * Reset the error state and try again. |
