linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Revert "delay: Rework udelay and ndelay"
@ 2024-11-21  9:55 Chen-Yu Tsai
  2024-11-21 11:36 ` Frederic Weisbecker
  0 siblings, 1 reply; 2+ messages in thread
From: Chen-Yu Tsai @ 2024-11-21  9:55 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Chen-Yu Tsai, Nícolas F. R. A. Prado,
	AngeloGioacchino Del Regno, linux-arch, linux-kernel,
	Anna-Maria Behnsen, Thomas Gleixner, Frederic Weisbecker

This reverts commit 19e2d91d8cb1f333adf04731f2788ff6ca06cebd.

Journald was recently observed to continuely crash at startup, causing
the system to not be able to finish booting. This was observed locally
on my MT8195 based Chromebook while doing development, and on KernelCI
on a MT8192 based Chromebook [1].

A bisect found this commit to be the first bad commit. Reverting it
seems to have fixed the issue.

[1] https://lava.collabora.dev/scheduler/job/16123429

Fixes: 19e2d91d8cb1 ("delay: Rework udelay and ndelay")
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Honestly I have no idea what's going on under the hood. Journald getting
stuck means the system doesn't boot to the login prompt. And turning on
journald's debug output didn't produce anything.

 include/asm-generic/delay.h | 65 ++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 37 deletions(-)

diff --git a/include/asm-generic/delay.h b/include/asm-generic/delay.h
index 76cf237b6e4c..a8cee41cc51b 100644
--- a/include/asm-generic/delay.h
+++ b/include/asm-generic/delay.h
@@ -2,9 +2,6 @@
 #ifndef __ASM_GENERIC_DELAY_H
 #define __ASM_GENERIC_DELAY_H
 
-#include <linux/math.h>
-#include <vdso/time64.h>
-
 /* Undefined functions to get compile-time errors */
 extern void __bad_udelay(void);
 extern void __bad_ndelay(void);
@@ -15,18 +12,13 @@ extern void __const_udelay(unsigned long xloops);
 extern void __delay(unsigned long loops);
 
 /*
- * The microseconds/nanosecond delay multiplicators are used to convert a
- * constant microseconds/nanoseconds value to a value which can be used by the
- * architectures specific implementation to transform it into loops.
- */
-#define UDELAY_CONST_MULT	((unsigned long)DIV_ROUND_UP(1ULL << 32, USEC_PER_SEC))
-#define NDELAY_CONST_MULT	((unsigned long)DIV_ROUND_UP(1ULL << 32, NSEC_PER_SEC))
-
-/*
- * The maximum constant udelay/ndelay value picked out of thin air to prevent
- * too long constant udelays/ndelays.
+ * Implementation details:
+ *
+ * * The weird n/20000 thing suppresses a "comparison is always false due to
+ *   limited range of data type" warning with non-const 8-bit arguments.
+ * * 0x10c7 is 2**32 / 1000000 (rounded up) -> udelay
+ * * 0x5 is 2**32 / 1000000000 (rounded up) -> ndelay
  */
-#define DELAY_CONST_MAX   20000
 
 /**
  * udelay - Inserting a delay based on microseconds with busy waiting
@@ -53,17 +45,17 @@ extern void __delay(unsigned long loops);
  * #. cache behaviour affecting the time it takes to execute the loop function.
  * #. CPU clock rate changes.
  */
-static __always_inline void udelay(unsigned long usec)
-{
-	if (__builtin_constant_p(usec)) {
-		if (usec >= DELAY_CONST_MAX)
-			__bad_udelay();
-		else
-			__const_udelay(usec * UDELAY_CONST_MULT);
-	} else {
-		__udelay(usec);
-	}
-}
+#define udelay(n)							\
+	({								\
+		if (__builtin_constant_p(n)) {				\
+			if ((n) / 20000 >= 1)				\
+				 __bad_udelay();			\
+			else						\
+				__const_udelay((n) * 0x10c7ul);		\
+		} else {						\
+			__udelay(n);					\
+		}							\
+	})
 
 /**
  * ndelay - Inserting a delay based on nanoseconds with busy waiting
@@ -71,17 +63,16 @@ static __always_inline void udelay(unsigned long usec)
  *
  * See udelay() for basic information about ndelay() and it's variants.
  */
-static __always_inline void ndelay(unsigned long nsec)
-{
-	if (__builtin_constant_p(nsec)) {
-		if (nsec >= DELAY_CONST_MAX)
-			__bad_udelay();
-		else
-			__const_udelay(nsec * NDELAY_CONST_MULT);
-	} else {
-		__udelay(nsec);
-	}
-}
-#define ndelay(x) ndelay(x)
+#define ndelay(n)							\
+	({								\
+		if (__builtin_constant_p(n)) {				\
+			if ((n) / 20000 >= 1)				\
+				__bad_ndelay();				\
+			else						\
+				__const_udelay((n) * 5ul);		\
+		} else {						\
+			__ndelay(n);					\
+		}							\
+	})
 
 #endif /* __ASM_GENERIC_DELAY_H */
-- 
2.47.0.338.g60cca15819-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-21 11:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-21  9:55 [PATCH] Revert "delay: Rework udelay and ndelay" Chen-Yu Tsai
2024-11-21 11:36 ` Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).