Skip to content

Commit a974eed

Browse files
committed
applications: nrf5340_audio: Added high CPU load print
Using the high CPU load monitoring feature, print a message using printk when the CPU load exceeds a defined threshold. OCT-3414 Signed-off-by: Kristoffer Skøien <[email protected]>
1 parent d0f84cb commit a974eed

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

applications/nrf5340_audio/prj.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,11 @@ CONFIG_BT_ATT_TX_COUNT=12
7979

8080
# Suppress the USB deprecation warning
8181
CONFIG_DEPRECATION_TEST=y
82+
83+
# Log high CPU load using printk
84+
CONFIG_CPU_LOAD=y
85+
# Disable LOG_PRINTK to ensure printk messages are displayed even under high CPU load,
86+
# by preventing them from being processed by the logging subsystem.
87+
CONFIG_LOG_PRINTK=n
88+
CONFIG_CPU_LOAD_LOG_PERIODICALLY=5000
89+
CONFIG_CPU_LOAD_LOG_LEVEL_WRN=y

applications/nrf5340_audio/src/utils/peripherals.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
#include "sd_card.h"
1515
#include "nrf5340_audio_dk_version.h"
1616
#include "device_location.h"
17-
1817
#include "sd_card_playback.h"
1918

19+
#include <zephyr/debug/cpu_load.h>
2020
#include <zephyr/logging/log.h>
2121
LOG_MODULE_REGISTER(peripherals, CONFIG_PERIPHERALS_LOG_LEVEL);
2222

2323
static struct board_version board_rev;
24+
#define CPU_LOAD_HIGH_THRESHOLD_PERCENT 98
25+
26+
static void cpu_load_cb(uint8_t percent)
27+
{
28+
printk("CPU load high: %d %%\n", percent);
29+
}
2430

2531
static int leds_set(void)
2632
{
@@ -153,5 +159,11 @@ int peripherals_init(void)
153159
return ret;
154160
}
155161

162+
ret = cpu_load_cb_reg(cpu_load_cb, CPU_LOAD_HIGH_THRESHOLD_PERCENT);
163+
if (ret) {
164+
LOG_ERR("Failed to register CPU load callback");
165+
return ret;
166+
}
167+
156168
return 0;
157169
}

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ Wi-Fi®
178178
Applications
179179
============
180180

181-
|no_changes_yet_note|
181+
nRF5340 Audio
182+
-------------
183+
184+
* Added high CPU load callback using the Zephyr CPU load subsystem.
185+
The callback uses a :c:func:`printk` function, as the logging subsystem is scheduled out if higher priority threads take all CPU time.
186+
This makes debugging high CPU load situations easier in the application.
187+
The threshold for high CPU load is set in :c:file:`peripherals.c` using :c:macro:`CPU_LOAD_HIGH_THRESHOLD_PERCENT`
182188

183189
Connectivity bridge
184190
-------------------

0 commit comments

Comments
 (0)