From nobody Mon May 25 01:58:01 2026 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B6033BCD0B for ; Tue, 19 May 2026 10:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779186365; cv=none; b=s9FkA4+NNnnu++Ottkp+9QGr6TWzVdTl9Op3FfNKT4QgXX3Lo1ea6zCC1nTE4NqpFzMVu7O7VcUTV/i2ZGkMDiTo929kROSz3elj9oM5Ue8B6Y7MXEOFYSpVrDKb2ep3ydlp9zYRsRXFqMOLGeyMIxnnB14ztIhZLppXBMeE3dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779186365; c=relaxed/simple; bh=0iubgivcayq+lyY69Sg+JRyvXsx29eB74VGe++/UMCY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ClGnWbneflqCmn1qwkKuAkFOv6Z1t2N5QOmAdsc2VVFZ7TYffvxK6hQyZZX9IkZJjEyos2hSurR0NfmeKJfGZvQPKVIreFz+RPHVfhFvAtZUd//76PByrBfLTi7pIvGKVtr2GbBysQLhfs2kq2QNypjo1+/EaEOWm5j71UL09TY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pcc.me.uk; spf=pass smtp.mailfrom=pcc.me.uk; dkim=pass (2048-bit key) header.d=pcc-me-uk.20251104.gappssmtp.com header.i=@pcc-me-uk.20251104.gappssmtp.com header.b=ianILBu0; arc=none smtp.client-ip=74.125.82.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pcc.me.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pcc.me.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pcc-me-uk.20251104.gappssmtp.com header.i=@pcc-me-uk.20251104.gappssmtp.com header.b="ianILBu0" Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-1329fc4bf77so9348700c88.1 for ; Tue, 19 May 2026 03:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pcc-me-uk.20251104.gappssmtp.com; s=20251104; t=1779186362; x=1779791162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zi8nkxTzh0Eo1ehnp7/9INpraaPZX523L/CWo/OlHz4=; b=ianILBu0MR6ck3JNfky/2eXt7oHM07/J2j3y3FGvhLEdYuKyvfR97in8sa7in8fHG/ ENTQfJZ7+XYHRaWVcGn93TkyOWa6kGMrg8vvZdbhwDjAee83pY2UY8aaN6BjlKOlEsnL x6j0PcvVWRf0ZLLwFPT3Q3ZFozTv+e16iSb128wfWeA8JHWVRTfMj5F+vLJywJk8GsIn ewnzSmANHtCKg2CZaNf6k9EInrFmAsIo17zGVGrK6dk18U0Z22kx4tTMugpYo39Hh2+k qRBEBR31MzJI0jp8Z9wtRl0pn1BLqTE7SnODpaAot9cMIKEa2to4QmsExNTgJfJjIl91 FT9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779186362; x=1779791162; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zi8nkxTzh0Eo1ehnp7/9INpraaPZX523L/CWo/OlHz4=; b=QsXutQfaYi4WEfpNzAU0eirOJCVv78TQ7a+x/SIOp6eKy1t+hpR2tZVHOnCeVU5NBX E40mknQHR1wEul77zzT2tgGFGlNNdEV05WiAhErEotTIEJierslZxahg8ARVU673IuZo x+8nshoNq7H6eytXCXIggEbLZErduBbQCUoAKoKnlc8MvHJvtSaZFG/1Xzu/idtCRE/R Q/+sYjt3OU9fifYK6fG4Az/DG0K75sj7erDV3S/eWuLN90vMEniptNCT5VoFww454S7h kfA+B6QpvWLRkdu9aZzWRgFb7LhiGWCzA8RqBcFZNY3bE+CLJ++JE6DGnMIkbm6N4Jb7 jCkQ== X-Forwarded-Encrypted: i=1; AFNElJ/9ek31w1hMDVL1oWDMMw1A9Ti0IcbT/GRYSajdI/g1M5mE5OfHvVpbdRUZn6BtBfcULBeaWiwgPkatj/I=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2nBD3ZeF/P99I8ymYHxtm0KIdVRlEmKYfoGeGi+6VIzLf7GNJ YfbUNjmlSUAO6ZYg03nBW+mRgn+M0PJ4Pc4yVJcHBECGpqYFjffRgZGatkknxRLxoE8= X-Gm-Gg: Acq92OHKjkXkpZBE55J6t/jpRmR7D5IQqKCJq8iBsFv0Vx09PDBO6xoIYARFIESzC9j 0Lmy0gAzSY3JhQYt85crSoCGLXJu3OOvqC1kB/5b1WFHv6ujq7iEBRO+R6xufF+rfPl6US88VqO 8R5ntbEwu6WcK43kJecmklOJ1KtlS4vxzhVEGw7RxUqe6U1xm4BurdzVrkRpzaiHsrK0F9aImUo rivveVOIJbtPNR8AN+VJThvlvQ99Q+q22vp/CD342I5ExPL7QSYvNA6a2OqHRvPve0FalLVwQDZ xARWLGEeZKkPEe8uyvkoiyc5BgXfYar+GTvCYtTnL5TuL+306VPPu0R265mJTHelwUbkn7lUkE7 Y7pMkcGHmDtYqCbAZSOIGpu2ciCccWbAuk3GMlSMD8oWUs/d5e1QcFsRChj4R5sexNRs8uDSpcf KBwzQC7/GlASWv76VBXSkfmM3rBAnmeLoHlxwLOSjaUfn6PAxa+cgOXjU= X-Received: by 2002:a05:7022:6890:b0:12d:de3e:cc01 with SMTP id a92af1059eb24-13504a4e7c1mr9034464c88.40.1779186362132; Tue, 19 May 2026 03:26:02 -0700 (PDT) Received: from localhost (c-67-180-161-137.hsd1.ca.comcast.net. [67.180.161.137]) by smtp.gmail.com with UTF8SMTPSA id a92af1059eb24-134cc3490bcsm19415549c88.15.2026.05.19.03.26.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 May 2026 03:26:01 -0700 (PDT) From: Peter Collingbourne To: Mark Brown Cc: David Laight , Christophe Kerello , Patrice Chotard , Boris Brezillon , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Jani Nikula , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Simona Vetter , Peter Collingbourne , Randy Dunlap Subject: [PATCH v2] iopoll: use udelay() for initial polling Date: Tue, 19 May 2026 03:24:46 -0700 Message-ID: <20260519102446.209723-1-peter@pcc.me.uk> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A short polling delay, such as the delay of 5us (SPINAND_READ_POLL_DELAY_US) provided by the SPI NAND driver, can become a 1/HZ (order of ms) delay caused by the usleep_range() call in read_poll_timeout(), significantly reducing SPI NAND access performance. Fix it by adjusting the read_poll_timeout() macro to use udelay() to delay until 1/10 of a timer tick after it is called, and only then sleep. Fixes: c955a0cc8a28 ("spi: spi-mem: add automatic poll status functions") Signed-off-by: Peter Collingbourne --- include/linux/iopoll.h | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) v2: * Fix it in read_poll_timeout() instead diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 53edd69acb9b..2ee89b76f072 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -19,9 +19,11 @@ * * @op: Operation * @cond: Break condition - * @sleep_us: Maximum time to sleep between operations in us (0 tight-loop= s). - * Please read usleep_range() function description for details = and - * limitations. + * @sleep_us: Maximum time to sleep or delay between operations in us + * (0 tight-loops). Please read usleep_range() and udelay() + * function descriptions for details and limitations. + * This macro will delay until 1/10 of a timer tick after + * it is called, and will then start sleeping. * @timeout_us: Timeout in us, 0 means never timeout * @sleep_before_op: if it is true, sleep @sleep_us before operation. * @@ -35,11 +37,18 @@ ({ \ u64 __timeout_us =3D (timeout_us); \ unsigned long __sleep_us =3D (sleep_us); \ - ktime_t __timeout =3D ktime_add_us(ktime_get(), __timeout_us); \ + ktime_t __start_time =3D ktime_get(); \ + u64 __delay_timeout_us =3D 100000/HZ; \ + ktime_t __delay_timeout =3D ktime_add_us(__start_time, __delay_timeout_us= ); \ + ktime_t __timeout =3D ktime_add_us(__start_time, __timeout_us); \ int ___ret; \ might_sleep_if((__sleep_us) !=3D 0); \ - if ((sleep_before_op) && __sleep_us) \ - usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + if ((sleep_before_op) && __sleep_us) { \ + if (__sleep_us <=3D __delay_timeout_us) \ + udelay(__sleep_us); \ + else \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + } \ for (;;) { \ bool __expired =3D __timeout_us && \ ktime_compare(ktime_get(), __timeout) > 0; \ @@ -54,8 +63,13 @@ ___ret =3D -ETIMEDOUT; \ break; \ } \ - if (__sleep_us) \ - usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + if (__sleep_us) { \ + if (__sleep_us <=3D __delay_timeout_us && \ + ktime_compare(ktime_get(), __delay_timeout) < 0) \ + udelay(__sleep_us); \ + else \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + } \ cpu_relax(); \ } \ ___ret; \ --=20 2.54.0