From d33271ccc835e79e945d06185e09fda4c3c3e2c5 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 3 Feb 2025 11:02:00 -0500 Subject: ioq: Rewrite the spin loop to avoid a warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With some GCC versions, --enable-ubsan leads to this warning: src/ioq.c: In function ‘ioq_slot_wait’: src/ioq.c:287:17: warning: ignoring loop annotation 287 | for (int j = 0; j < (1 << i); ++j) { | ^~~ presumably due to UBSan rewriting the shift to check for overflow. Work around this by precomputing the iteration count. --- src/ioq.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ioq.c b/src/ioq.c index dd5d31e..6fc4cbb 100644 --- a/src/ioq.c +++ b/src/ioq.c @@ -279,12 +279,11 @@ _noinline static uintptr_t ioq_slot_wait(struct ioqq *ioqq, ioq_slot *slot, uintptr_t value) { uintptr_t ret; - // Try spinning a few times before blocking + // Try spinning a few times (with exponential backoff) before blocking _nounroll - for (int i = 0; i < 10; ++i) { - // Exponential backoff + for (int i = 1; i < 1024; i *= 2) { _nounroll - for (int j = 0; j < (1 << i); ++j) { + for (int j = 0; j < i; ++j) { spin_loop(); } -- cgit v1.2.3