Commit 37c956ff authored by Gerard Marull-Paretas's avatar Gerard Marull-Paretas Committed by Carles Cufi
Browse files

samples: pm: demonstrate usage of the policy latency APIs



Even though we have unit tests that cover the PM policy latency APIs, it
may not be obvious on how to use it in practice. This patch adds a new
sample where both the application and a device driver impose latency
requirements. The sample illustrates how latency requirements are
aggregated and are taken into account when choosing the CPU power state.
The test has been designed to run on native_posix, since it only serves
for demonstration purposes.

Signed-off-by: default avatarGerard Marull-Paretas <gerard@teslabs.com>
parent 897ae4a2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line

# Copyright (c) 2022 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(latency)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
+10 −0
Original line number Diff line number Diff line
# Copyright (c) 2022 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

menu "Zephyr"
source "Kconfig.zephyr"
endmenu

module = APP
module-str = Application
source "subsys/logging/Kconfig.template.log_config"
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022 Nordic Semiconductor ASA
 * SPDX-License-Identifier: Apache-2.0
 */

/ {
	power-states {
		runtime_idle: runtime-idle {
			compatible = "zephyr,power-state";
			power-state-name = "runtime-idle";
			min-residency-us = <1000000>;
			exit-latency-us = <10000>;
		};
		suspend_to_idle: suspend-to-idle {
			compatible = "zephyr,power-state";
			power-state-name = "suspend-to-idle";
			min-residency-us = <1100000>;
			exit-latency-us = <20000>;
		};
		standby: standby {
			compatible = "zephyr,power-state";
			power-state-name = "standby";
			min-residency-us = <1200000>;
			exit-latency-us = <30000>;
		};
	};
};

&cpu0 {
	cpu-power-states = <&runtime_idle &suspend_to_idle &standby>;
};
+2 −0
Original line number Diff line number Diff line
CONFIG_PM=y
CONFIG_LOG=y
+55 −0
Original line number Diff line number Diff line
sample:
  name: Demonstrate usage of the PM policy latency APIs
tests:
  sample.pm.latency:
    platform_allow: native_posix
    tags: pm
    harness: console
    harness_config:
      type: multi_line
      regex:
        - "<inf> app: Sleeping for 1.1 seconds, we should enter RUNTIME_IDLE"
        - "<inf> soc_pm: Entering RUNTIME_IDLE{0}"
        - "<inf> app: Sleeping for 1.2 seconds, we should enter SUSPEND_TO_IDLE"
        - "<inf> soc_pm: Entering SUSPEND_TO_IDLE{0}"
        - "<inf> app: Sleeping for 1.3 seconds, we should enter STANDBY"
        - "<inf> soc_pm: Entering STANDBY{0}"
        - "<inf> app: Setting latency constraint: 30ms"
        - "<inf> app: Sleeping for 1.1 seconds, we should enter RUNTIME_IDLE"
        - "<inf> soc_pm: Entering RUNTIME_IDLE{0}"
        - "<inf> app: Sleeping for 1.2 seconds, we should enter SUSPEND_TO_IDLE"
        - "<inf> soc_pm: Entering SUSPEND_TO_IDLE{0}"
        - "<inf> app: Sleeping for 1.3 seconds, we should enter SUSPEND_TO_IDLE"
        - "<inf> soc_pm: Entering SUSPEND_TO_IDLE{0}"
        - "<inf> app: Opening test device"
        - "<inf> dev_test: Adding latency constraint: 20ms"
        - "<inf> app: Latency constraint changed: 20ms"
        - "<inf> app: Sleeping for 1.1 seconds, we should enter RUNTIME_IDLE"
        - "<inf> soc_pm: Entering RUNTIME_IDLE{0}"
        - "<inf> app: Sleeping for 1.2 seconds, we should enter RUNTIME_IDLE"
        - "<inf> soc_pm: Entering RUNTIME_IDLE{0}"
        - "<inf> app: Sleeping for 1.3 seconds, we should enter RUNTIME_IDLE"
        - "<inf> soc_pm: Entering RUNTIME_IDLE{0}"
        - "<inf> app: Updating latency constraint: 10ms"
        - "<inf> app: Latency constraint changed: 10ms"
        - "<inf> dev_test: Latency constraint changed: 10ms"
        - "<inf> app: Sleeping for 1.1 seconds, we should stay ACTIVE"
        - "<inf> app: Sleeping for 1.2 seconds, we should stay ACTIVE"
        - "<inf> app: Sleeping for 1.3 seconds, we should stay ACTIVE"
        - "<inf> app: Updating latency constraint: 30ms"
        - "<inf> app: Latency constraint changed: 20ms"
        - "<inf> dev_test: Latency constraint changed: 20ms"
        - "<inf> app: Closing test device"
        - "<inf> dev_test: Removing latency constraint"
        - "<inf> app: Latency constraint changed: 30ms"
        - "<inf> dev_test: Latency constraint changed: 30ms"
        - "<inf> app: Sleeping for 1.1 seconds, we should enter RUNTIME_IDLE"
        - "<inf> soc_pm: Entering RUNTIME_IDLE{0}"
        - "<inf> app: Sleeping for 1.2 seconds, we should enter SUSPEND_TO_IDLE"
        - "<inf> soc_pm: Entering SUSPEND_TO_IDLE{0}"
        - "<inf> app: Sleeping for 1.3 seconds, we should enter SUSPEND_TO_IDLE"
        - "<inf> soc_pm: Entering SUSPEND_TO_IDLE{0}"
        - "<inf> app: Removing latency constraint"
        - "<inf> app: Latency constraint changed: none"
        - "<inf> app: Finished, we should now enter STANDBY"
        - "<inf> soc_pm: Entering STANDBY{0}"
Loading