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] 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;