diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/pm/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/pm/defconfig index 56914ba3026..2675c8d9872 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/pm/defconfig +++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/pm/defconfig @@ -33,7 +33,7 @@ CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y CONFIG_NSH_STRERROR=y CONFIG_PM=y -CONFIG_PM_GOVERNOR_EXPLICIT_RELAX=y +CONFIG_PM_GOVERNOR_EXPLICIT_RELAX=-1 CONFIG_PM_GOVERNOR_GREEDY=y CONFIG_PREALLOC_TIMERS=0 CONFIG_RR_INTERVAL=200 diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/pm/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/pm/defconfig index 32e0da49276..00bb99887aa 100644 --- a/boards/xtensa/esp32/esp32-devkitc/configs/pm/defconfig +++ b/boards/xtensa/esp32/esp32-devkitc/configs/pm/defconfig @@ -34,7 +34,7 @@ CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_LINELEN=64 CONFIG_NSH_READLINE=y CONFIG_PM=y -CONFIG_PM_GOVERNOR_EXPLICIT_RELAX=y +CONFIG_PM_GOVERNOR_EXPLICIT_RELAX=-1 CONFIG_PM_GOVERNOR_GREEDY=y CONFIG_PREALLOC_TIMERS=4 CONFIG_RAM_SIZE=114688 diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index c944ef9e405..5d4b615fe66 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -41,22 +41,25 @@ config PM_GOVERNOR_ACTIVITY menu "Governor options" -if PM_GOVERNOR_GREEDY - config PM_GOVERNOR_EXPLICIT_RELAX - bool "Stay initially at PM_NORMAL" + int "Stay initially at PM_NORMAL" + default 0 ---help--- - If you boot into NSH, when using the greedy PM governor, since NuttX will - almost immediately go idle (when waiting for a prompt), he lowest possible - run-level will be selected, which may not be desirable. + If you boot into NSH, especially using the greedy PM governor, since + NuttX will almost immediately go idle (when waiting for a prompt), the + lowest possible run-level will be selected, which may not be desirable. This is not a problem if you directly run you application at boot, which can hold off power levels using pm_stay() (via boardctl). - This option will initialize all run levels as if pm_stay() were to be - called once for each, so that your application needs to call pm_relax() - (via boardctl()) for every run-level you wish to allow to enter. + This option will initialize all run levels as if + pm_stay/pm_stay_timeout() were to be called once for each. -endif + if set to -1, that means pm_stay(), so that your application + needs to call pm_relax() (via boardctl()) for every run-level you + wish to allow to enter. + + if set to timeout (unit: ms), that means pm_stay_timeout(ms). + pm_relax() will be auto called after timeout. if PM_GOVERNOR_ACTIVITY diff --git a/drivers/power/greedy_governor.c b/drivers/power/greedy_governor.c index f4077bf7ebf..5db18c2e9c6 100644 --- a/drivers/power/greedy_governor.c +++ b/drivers/power/greedy_governor.c @@ -62,7 +62,6 @@ struct pm_greedy_governor_s /* PM governor methods */ -static void greedy_governor_initialize(void); static void greedy_governor_statechanged(int domain, enum pm_state_e newstate); static enum pm_state_e greedy_governor_checkstate(int domain); @@ -74,7 +73,6 @@ static void greedy_governor_activity(int domain, int count); static const struct pm_governor_s g_greedy_governor_ops = { - .initialize = greedy_governor_initialize, /* initialize */ .statechanged = greedy_governor_statechanged, /* statechanged */ .checkstate = greedy_governor_checkstate, /* checkstate */ .activity = greedy_governor_activity, /* activity */ @@ -86,23 +84,6 @@ static struct pm_greedy_governor_s g_pm_greedy_governor; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: greedy_governor_initialize - ****************************************************************************/ - -static void greedy_governor_initialize(void) -{ -#ifdef CONFIG_PM_GOVERNOR_EXPLICIT_RELAX - for (int dom = 0; dom < CONFIG_PM_NDOMAINS; dom++) - { - for (int state = 0; state < PM_COUNT; state++) - { - pm_stay(dom, state); - } - } -#endif -} - /**************************************************************************** * Name: greedy_governor_statechanged ****************************************************************************/ diff --git a/drivers/power/pm_governor.c b/drivers/power/pm_governor.c index cf587980721..590bd371f89 100644 --- a/drivers/power/pm_governor.c +++ b/drivers/power/pm_governor.c @@ -70,6 +70,11 @@ int pm_set_governor(int domain, FAR const struct pm_governor_s *gov) { +#if CONFIG_PM_GOVERNOR_EXPLICIT_RELAX + int state; + int dom; +#endif + if (gov == NULL) { return -EINVAL; @@ -88,5 +93,19 @@ int pm_set_governor(int domain, FAR const struct pm_governor_s *gov) g_pmglobals.domain[domain].governor->initialize(); } +#if CONFIG_PM_GOVERNOR_EXPLICIT_RELAX + for (dom = 0; dom < CONFIG_PM_NDOMAINS; dom++) + { + for (state = 0; state < PM_COUNT; state++) + { +#if CONFIG_PM_GOVERNOR_EXPLICIT_RELAX < 0 + pm_stay(dom, state); +#else + pm_stay_timeout(dom, state, CONFIG_PM_GOVERNOR_EXPLICIT_RELAX); +#endif + } + } +#endif + return 0; }