[Concept,02/42] cyclic: Avoid showing messages when debugging

Message ID 20250919201507.4024144-3-sjg@u-boot.org
State New
Headers
Series video: Support a cursor more generally |

Commit Message

Simon Glass Sept. 19, 2025, 8:14 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

When using a debugger it is common to single step through functions. If
one of those functions happens to be called from a cyclic function, then
a warning messages is shown. When debugging the console itself, this can
mess up the session.

Add a Kconfig to control whether the message is shown. Disable it by
default if CONFIG_CC_OPTIMIZE_FOR_DEBUG is enabled.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/Kconfig  | 9 +++++++++
 common/cyclic.c | 5 +++--
 2 files changed, 12 insertions(+), 2 deletions(-)
  

Patch

diff --git a/common/Kconfig b/common/Kconfig
index 55e9bcdfa2b..3bd11f44c51 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -666,6 +666,15 @@  config CYCLIC_MAX_CPU_TIME_US
 	  takes longer than this duration this function will get unregistered
 	  automatically.
 
+config CYCLIC_WARN_LATE
+	bool "Warn if a cyclic function takes too long"
+	default y if !CC_OPTIMIZE_FOR_DEBUG
+	help
+	  Show a warning on the console if a cyclic function goes over the
+	  alotted maximum time. The message is of the form:
+
+	     cyclic_run() cyclic function <func_name> took too long: x vs y max
+
 endif # CYCLIC
 
 config EVENT
diff --git a/common/cyclic.c b/common/cyclic.c
index 196797fd61e..e5a2ad302af 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -71,8 +71,9 @@  static void cyclic_run(void)
 			cyclic->cpu_time_us += cpu_time;
 
 			/* Check if cpu-time exceeds max allowed time */
-			if ((cpu_time > CONFIG_CYCLIC_MAX_CPU_TIME_US) &&
-			    (!cyclic->already_warned)) {
+			if (IS_ENABLED(CONFIG_CYCLIC_WARN_LATE) &&
+			    cpu_time > CONFIG_CYCLIC_MAX_CPU_TIME_US &&
+			    !cyclic->already_warned) {
 				pr_err("cyclic function %s took too long: %lldus vs %dus max\n",
 				       cyclic->name, cpu_time,
 				       CONFIG_CYCLIC_MAX_CPU_TIME_US);