From d1f9c73e09bdd0e26cf0e379a255ea0fc287bee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 1 Mar 2023 13:07:46 +0100 Subject: [PATCH] [nrf fromtree] soc: nrf53: Change logging level of anomaly 160 message to DEBUG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit fe3b97a87f480eb473cd58cc1990a5845c2ca9c6. This message should not be a warning, as it does not actually indicate that something potentially bad happened. On the contrary, it informs that conditions in which the anomaly 160 could occur were detected and the anomaly was prevented from occurring. There is no need for this message to appear in the default configuration (INFO level). In fact, the message would undesirably flood the console in some cases (like the kernel/mem_protect/stack_random test) and sometimes it would also require enlarging the stack of the idle thread (the function is called underneath k_cpu_idle()). Therefore, the logging level of this message is changed to DEBUG. Signed-off-by: Andrzej Głąbek (cherry picked from commit 7195db01f45d8045c3dc8e982155694ee6d06928) --- soc/arm/nordic_nrf/nrf53/soc.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 7c9b12260bb..544ad02acaa 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -125,19 +125,17 @@ static void nrf53_anomaly_160_workaround(void) #endif } -bool z_arm_on_enter_cpu_idle(void) +/* This code prevents the CPU from entering sleep again if it already + * entered sleep 5 times within last 200 us. + */ +static bool nrf53_anomaly_160_check(void) { - /* This code prevents the CPU from entering sleep again if it already - * entered sleep 5 times within last 200 us. - */ - /* System clock cycles needed to cover 200 us window. */ const uint32_t window_cycles = ceiling_fraction(200 * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, 1000000); static uint32_t timestamps[5]; static bool timestamps_filled; - static bool suppress_warning; static uint8_t current; uint8_t oldest = (current + 1) % ARRAY_SIZE(timestamps); uint32_t now = k_cycle_get_32(); @@ -145,13 +143,8 @@ bool z_arm_on_enter_cpu_idle(void) if (timestamps_filled && /* + 1 because only fully elapsed cycles need to be counted. */ (now - timestamps[oldest]) < (window_cycles + 1)) { - if (!suppress_warning) { - LOG_WRN("Anomaly 160 trigger conditions detected."); - suppress_warning = true; - } return false; } - suppress_warning = false; /* Check if the CPU actually entered sleep since the last visit here * (WFE/WFI could return immediately if the wake-up event was already @@ -174,6 +167,24 @@ bool z_arm_on_enter_cpu_idle(void) return true; } + +bool z_arm_on_enter_cpu_idle(void) +{ + bool ok_to_sleep = nrf53_anomaly_160_check(); + +#if (LOG_LEVEL >= LOG_LEVEL_DBG) + static bool suppress_message; + + if (ok_to_sleep) { + suppress_message = false; + } else { + LOG_DBG("Anomaly 160 trigger conditions detected."); + suppress_message = true; + } +#endif + + return ok_to_sleep; +} #endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ static int nordicsemi_nrf53_init(const struct device *arg)