From 0d3a8749fedf8c51ee614f16d3fa664a94de8d27 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 4 Mar 2026 00:57:48 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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. -- cgit v1.2.1