From e43d0a993beea8d8849563a6b1830c9e38ddaf74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 13 Jan 2025 10:12:48 +0100 Subject: [PATCH 1/3] tests: benchmarks: power_consumption: Allow controlled thread suspension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test was suspending test thread from the timer interrupt at random (but periodic) point. Some drivers which are tested in that framework handles power management in the thread context. Randomly suspending the test thread could lead to a case where driver did not finish requested operation and system goes to s2ram in the middle of the driver operation. Extending the test framework to allow more controlled thread suspension. Timer can indicate to the thread that is shall be suspended and thread calls self suspension when ready. Signed-off-by: Krzysztof Chruściński --- tests/benchmarks/power_consumption/common/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/power_consumption/common/main.c b/tests/benchmarks/power_consumption/common/main.c index e46ee0cc1b3b..c60445538b9b 100644 --- a/tests/benchmarks/power_consumption/common/main.c +++ b/tests/benchmarks/power_consumption/common/main.c @@ -12,6 +12,16 @@ const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios); static bool state = true; extern void thread_definition(void); +/* Some tests require that test thread controls the moment when it is + * suspended. In that case test implements this function and returns true to + * indicated that test thread will take case of the suspension and it can + * be skipped in the common code. + */ +__weak bool self_suspend_req(void) +{ + return false; +} + K_THREAD_DEFINE(thread_id, 500, thread_definition, NULL, NULL, NULL, 5, 0, 0); @@ -24,7 +34,9 @@ void timer_handler(struct k_timer *dummy) } else { state = true; gpio_pin_set_dt(&led, 0); - k_thread_suspend(thread_id); + if (self_suspend_req() == false) { + k_thread_suspend(thread_id); + } } } From 0c39c898b9e6b9d8bb82b50b05bad7f9af708de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 13 Jan 2025 09:59:30 +0100 Subject: [PATCH 2/3] tests: benchmarks: power_consumption: i2c: Improve thread suspend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test thread cannot be suspended at any time because driver power management happens in the thread context so if thread is suspended at the random moment and system goes to s2ram it can lead to increased power consumption because thread got suspended before i2c device got properly suspended. Signed-off-by: Krzysztof Chruściński --- .../power_consumption/i2c/src/driver_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/benchmarks/power_consumption/i2c/src/driver_test.c b/tests/benchmarks/power_consumption/i2c/src/driver_test.c index 1f39d89b46a6..1ead8ac0d807 100644 --- a/tests/benchmarks/power_consumption/i2c/src/driver_test.c +++ b/tests/benchmarks/power_consumption/i2c/src/driver_test.c @@ -9,6 +9,13 @@ static const struct device *i2c = DEVICE_DT_GET(DT_ALIAS(sensor_bme688)); +static bool suspend_req; + +bool self_suspend_req(void) +{ + suspend_req = true; + return true; +} void thread_definition(void) { @@ -17,6 +24,10 @@ void thread_definition(void) while (1) { ret = i2c_reg_read_byte(i2c, 0x76, 0x75, &value); + if (suspend_req) { + suspend_req = false; + k_thread_suspend(k_current_get()); + } if (ret < 0) { printk("Failure in reading byte %d", ret); return; From 7ab054fd8cc3914d7c060c992b06249cc5d4edd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 13 Jan 2025 10:29:37 +0100 Subject: [PATCH 3/3] boards: shields: pca63566: Enable runtime PM for i2c and spi nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add property to enable runtime PM for i2c and spi used for controlling the sensor. Signed-off-by: Krzysztof Chruściński --- boards/shields/pca63566/boards/nrf54h20dk_nrf54h20_common.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/boards/shields/pca63566/boards/nrf54h20dk_nrf54h20_common.dtsi b/boards/shields/pca63566/boards/nrf54h20dk_nrf54h20_common.dtsi index 57a99fe79836..b606bdb56006 100644 --- a/boards/shields/pca63566/boards/nrf54h20dk_nrf54h20_common.dtsi +++ b/boards/shields/pca63566/boards/nrf54h20dk_nrf54h20_common.dtsi @@ -55,6 +55,7 @@ pinctrl-1 = <&i2c130_sleep>; pinctrl-names = "default", "sleep"; zephyr,concat-buf-size = <255>; + zephyr,pm-device-runtime-auto; bme688: bme688@76 { compatible = "bosch,bme680"; @@ -82,6 +83,7 @@ pinctrl-1 = <&spi131_sleep>; pinctrl-names = "default", "sleep"; overrun-character = <0x00>; + zephyr,pm-device-runtime-auto; cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>, <&gpio1 2 GPIO_ACTIVE_LOW>;