include/asm-generic/delay.h | 65 ++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 37 deletions(-)
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
Le Thu, Nov 21, 2024 at 05:55:38PM +0800, Chen-Yu Tsai a écrit : > 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> Ah wait, can you please try this instead? diff --git a/include/asm-generic/delay.h b/include/asm-generic/delay.h index 76cf237b6e4c..03b0ec7afca6 100644 --- a/include/asm-generic/delay.h +++ b/include/asm-generic/delay.h @@ -75,11 +75,11 @@ static __always_inline void ndelay(unsigned long nsec) { if (__builtin_constant_p(nsec)) { if (nsec >= DELAY_CONST_MAX) - __bad_udelay(); + __bad_ndelay(); else __const_udelay(nsec * NDELAY_CONST_MULT); } else { - __udelay(nsec); + __ndelay(nsec); } } #define ndelay(x) ndelay(x) Thanks!
© 2016 - 2024 Red Hat, Inc.