Skip to content

Commit 5b2912d

Browse files
MarekPietakapi-no
authored andcommitted
applications: nrf_desktop: Require zero latency in PM while USB active
Require zero latency in Power Management while USB is active to ensure high performance. While USB is active, application power down is blocked anyway. Jira: NCSDK-30503 Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no> Signed-off-by: Pekka Niskanen <pekka.niskanen@nordicsemi.no>
1 parent d126fff commit 5b2912d

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

applications/nrf_desktop/doc/usb_state_pm.rst

+31-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ USB state power manager module
77
:local:
88
:depth: 2
99

10-
The |usb_state_pm| is minor, stateless module that imposes an application power level restriction related to the USB state.
11-
The application power level is managed by the :ref:`power manager module <caf_power_manager>`.
10+
The |usb_state_pm| is a minor, stateless module that imposes the following power state restrictions related to the USB state:
11+
12+
* Application power level restrictions.
13+
The application power level is managed by the :ref:`caf_power_manager`.
14+
* Zephyr's :ref:`zephyr:pm-system` latency restrictions.
1215

1316
Module events
1417
*************
@@ -24,20 +27,41 @@ Configuration
2427
*************
2528

2629
To enable the module, use the :ref:`CONFIG_DESKTOP_USB_PM_ENABLE <config_desktop_app_options>` Kconfig option.
27-
It depends on the options :ref:`CONFIG_DESKTOP_USB_ENABLE <config_desktop_app_options>` and :kconfig:option:`CONFIG_CAF_POWER_MANAGER`.
30+
It depends on the options :ref:`CONFIG_DESKTOP_USB_ENABLE <config_desktop_app_options>` and :kconfig:option:`CONFIG_CAF_PM_EVENTS`.
2831

2932
The log level is inherited from the :ref:`nrf_desktop_usb_state`.
3033

34+
System Power Management integration
35+
===================================
36+
37+
Zephyr's System Power Management (:kconfig:option:`CONFIG_PM`) does not automatically take into account (expect) wakeups related to user input and finalized HID report transfers over USB.
38+
This results in entering low power states if no work is scheduled to be done in the nearest future.
39+
If you use Zephyr's System Power Management, the module automatically requires zero latency in the Power Management while USB is active.
40+
This is done to prevent entering power states that introduce wakeup latency and ensure high performance.
41+
You can control this feature using the :ref:`CONFIG_DESKTOP_USB_PM_REQ_NO_PM_LATENCY <config_desktop_app_options>` Kconfig option.
42+
3143
Implementation details
3244
**********************
3345

34-
For the change of the restricted power level, the module reacts to :c:struct:`usb_state_event`.
35-
Upon reception of the event and depending on the current USB state, the module requests different power restrictions:
46+
The module reacts to the :c:struct:`usb_state_event`.
47+
Upon reception of the event and depending on the current USB state, the module requests different power restrictions.
48+
For more information about the USB states in nRF Desktop, see the :ref:`nrf_desktop_usb_state`.
49+
50+
Application power level
51+
=======================
52+
53+
The application power level is imposed using the :c:struct:`power_manager_restrict_event`.
3654

3755
* If the USB state is set to :c:enum:`USB_STATE_POWERED`, the module restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED`.
3856
* If the USB state is set to :c:enum:`USB_STATE_ACTIVE`, the :c:enum:`POWER_MANAGER_LEVEL_ALIVE` is required.
3957
* If the USB state is set to :c:enum:`USB_STATE_DISCONNECTED`, any power level is allowed.
4058
* If the USB state is set to :c:enum:`USB_STATE_SUSPENDED`, the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED` is imposed.
41-
The module restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED` and generates :c:struct:`force_power_down_event`.
59+
The module restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED`.
60+
The module also submits a :c:struct:`force_power_down_event` to force a quick power down.
4261

43-
For more information about the USB states in nRF Desktop, see the :ref:`nrf_desktop_usb_state`.
62+
System Power Management latency
63+
===============================
64+
65+
The latency requirements of the System Power Management are updated using the :c:func:`pm_policy_latency_request_add` and :c:func:`pm_policy_latency_request_remove` functions.
66+
The zero latency requirement is added when USB state is set to :c:enum:`USB_STATE_ACTIVE`.
67+
The requirement is removed if USB enters another state.

applications/nrf_desktop/src/modules/Kconfig.usb_state

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ config DESKTOP_USB_PM_ENABLE
4747
help
4848
This enables small module that blocks power down if the USB is active.
4949

50+
config DESKTOP_USB_PM_REQ_NO_PM_LATENCY
51+
bool "Require zero latency in Power Management while USB is active"
52+
default y
53+
depends on PM
54+
depends on DESKTOP_USB_PM_ENABLE
55+
help
56+
The zero latency prevents entering power states that introduce wakeup
57+
latency and ensures high performance. While USB is active, application
58+
power down is blocked anyway.
59+
5060
config DESKTOP_USB_HID_REPORT_SENT_ON_SOF
5161
bool "Submit HID report sent event on USB Start of Frame (SOF) [EXPERIMENTAL]"
5262
select EXPERIMENTAL

applications/nrf_desktop/src/modules/usb_state_pm.c

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <zephyr/kernel.h>
77
#include <zephyr/types.h>
8+
#include <zephyr/pm/policy.h>
89

910
#include "usb_event.h"
1011

@@ -18,13 +19,37 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_DESKTOP_USB_STATE_LOG_LEVEL);
1819
#include <caf/events/force_power_down_event.h>
1920

2021

22+
static void update_pm_policy_latency_req(bool enable)
23+
{
24+
static bool enabled;
25+
static struct pm_policy_latency_request req;
26+
27+
if (enabled == enable) {
28+
/* Nothing to do. */
29+
return;
30+
}
31+
32+
if (enable) {
33+
/* Ensure no latency. */
34+
pm_policy_latency_request_add(&req, 0U);
35+
} else {
36+
pm_policy_latency_request_remove(&req);
37+
}
38+
39+
enabled = enable;
40+
}
41+
2142
static bool app_event_handler(const struct app_event_header *aeh)
2243
{
2344
if (is_usb_state_event(aeh)) {
2445
const struct usb_state_event *event = cast_usb_state_event(aeh);
2546

2647
LOG_DBG("USB state change detected");
2748

49+
if (IS_ENABLED(CONFIG_DESKTOP_USB_PM_REQ_NO_PM_LATENCY)) {
50+
update_pm_policy_latency_req(event->state == USB_STATE_ACTIVE);
51+
}
52+
2853
switch (event->state) {
2954
case USB_STATE_POWERED:
3055
power_manager_restrict(MODULE_IDX(MODULE), POWER_MANAGER_LEVEL_SUSPENDED);

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

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ nRF Desktop
287287
For details, see the :ref:`nrf_desktop_board_configuration`.
288288
* The ``dongle_small`` configuration for the nRF52833 DK.
289289
The configuration enables logs and mimics the dongle configuration used for small SoCs.
290+
* Requirement for zero latency in Zephyr's :ref:`zephyr:pm-system` while USB is active (:ref:`CONFIG_DESKTOP_USB_PM_REQ_NO_PM_LATENCY <config_desktop_app_options>` Kconfig option of the :ref:`nrf_desktop_usb_state_pm`).
291+
The feature is enabled by default if Zephyr Power Management (:kconfig:option:`CONFIG_PM`) is enabled to prevent entering power states that introduce wakeup latency and ensure high performance.
290292

291293
* Removed an imply from the nRF Desktop Bluetooth connectivity Kconfig option (:ref:`CONFIG_DESKTOP_BT <config_desktop_app_options>`).
292294
The imply enabled a separate workqueue for connection TX notify processing (:kconfig:option:`CONFIG_BT_CONN_TX_NOTIFY_WQ`) if MPSL was used for synchronization between the flash memory driver and radio (:kconfig:option:`CONFIG_SOC_FLASH_NRF_RADIO_SYNC_MPSL`).

0 commit comments

Comments
 (0)