Skip to content

Commit 24400a1

Browse files
committed
pm: device_runtime: Allow to use system wq
Add an option to use the system work queue instead of defining its own queue for asynchronous API. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent c58bb12 commit 24400a1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

subsys/pm/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ config PM_DEVICE_RUNTIME_ASYNC
110110
in the power management device runtime.
111111

112112
if PM_DEVICE_RUNTIME_ASYNC
113+
config PM_DEVICE_RUNTIME_USE_SYSTEM_WQ
114+
bool "Use the system workqueue"
115+
default n
116+
help
117+
When this option is enabled the power management subsystem will
118+
use the system worqueue instead of defining its own queue.
119+
113120
config PM_DEVICE_RUNTIME_WQ_STACK_SIZE
114121
int "Stack size for pm runtime async workqueue"
115122
default 1024
@@ -119,6 +126,7 @@ config PM_DEVICE_RUNTIME_WQ_STACK_SIZE
119126

120127
config PM_DEVICE_RUNTIME_WQ_PRIO
121128
int "PM device runtime workqueue priority. Should be pre-emptible."
129+
default SYSTEM_WORKQUEUE_PRIORITY if PM_DEVICE_RUNTIME_USE_SYSTEM_WQ
122130
default 0
123131

124132
config PM_DEVICE_RUNTIME_WQ_INIT_PRIO

subsys/pm/device_runtime.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ LOG_MODULE_DECLARE(pm_device, CONFIG_PM_DEVICE_LOG_LEVEL);
2121
#endif
2222

2323
#ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
24+
#ifndef CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ
2425
K_THREAD_STACK_DEFINE(pm_device_runtime_stack, CONFIG_PM_DEVICE_RUNTIME_WQ_STACK_SIZE);
2526
static struct k_work_q pm_device_runtime_wq;
27+
#endif /* !CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ */
2628
#endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
2729

2830
#define EVENT_STATE_ACTIVE BIT(PM_DEVICE_STATE_ACTIVE)
@@ -86,7 +88,11 @@ static int runtime_suspend(const struct device *dev, bool async,
8688
/* queue suspend */
8789
#ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
8890
pm->base.state = PM_DEVICE_STATE_SUSPENDING;
91+
#ifdef CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ
92+
(void)k_work_schedule(&pm->work, delay);
93+
#else
8994
(void)k_work_schedule_for_queue(&pm_device_runtime_wq, &pm->work, delay);
95+
#endif /* CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ */
9096
#endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
9197
} else {
9298
/* suspend now */
@@ -592,6 +598,7 @@ int pm_device_runtime_usage(const struct device *dev)
592598
}
593599

594600
#ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
601+
#ifndef CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ
595602

596603
static int pm_device_runtime_wq_init(void)
597604
{
@@ -608,4 +615,5 @@ static int pm_device_runtime_wq_init(void)
608615

609616
SYS_INIT(pm_device_runtime_wq_init, POST_KERNEL, CONFIG_PM_DEVICE_RUNTIME_WQ_INIT_PRIO);
610617

618+
#endif /* !CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ */
611619
#endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */

tests/subsys/pm/device_runtime_api/testcase.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ tests:
1010
- native_sim
1111
extra_configs:
1212
- CONFIG_TEST_PM_DEVICE_ISR_SAFE=y
13+
pm.device_runtime.async_system_wq.api:
14+
platform_allow:
15+
- native_sim
16+
extra_configs:
17+
- CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ=y
1318
pm.device_runtime.async_disabled.api:
1419
platform_allow:
1520
- native_sim

0 commit comments

Comments
 (0)