Skip to content

Commit

Permalink
[nrf fromtree] soc: nrf53: Change logging level of anomaly 160 messag…
Browse files Browse the repository at this point in the history
…e to DEBUG

This is a follow-up to commit fe3b97a.

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 <[email protected]>
(cherry picked from commit 7195db0)
  • Loading branch information
anangl authored and rlubos committed Mar 15, 2023
1 parent 76acbd0 commit d1f9c73
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions soc/arm/nordic_nrf/nrf53/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,26 @@ 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();

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
Expand All @@ -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)
Expand Down

0 comments on commit d1f9c73

Please sign in to comment.