Multiple intermediate states for genpd
Subsystems (8)
v12 cover Multiple intermediate states for genpd
From: Axel Haslam <[email protected]>
Some architectures may have intermediate power levels between on and off.
This patch set adds the ability to declare multiple states for a given generic power domain, the idea is that the deepest state will be entered which does not violate any of the device or sub-domain latency constraints.
Changes since v11
* Use static array of state instead of dynamic allocation
Changes since v10
* Several reworks after Ulf Hansson's comments:
- merge the governor changes and core changes into a single patch
- remove the "name" of the state.
- add a default state allocation function
- convert governor power done ok function to while loop.
- reword commit message
*rebased on next-20160205
Changes since v9
*rebased on linux-next
Changes since v8
* rebased to linux-pm next
Changes since v7:
* rebase to 4.3-rc5
* add genpd_init_simple (Lina's suggestion) for platforms that don't have multiple states and don't declare initial latencies. A default OFF state with initial 0 latencies will be used in this case.
* Append Mark's patch to add "states" and "timings" to the genpd debugfs
Changes since v6:
* change int to unsigned int were appropriate.
* spelling mistakes, and fix commit message for removal of latencies.
Changes since v5:
* rebase to 4.1-rc1
* Pass state array as an init argument on pm_genpd_init
* declare a default OFF state with no latencies, that will be used if a null state argument is given.
* set the deepest state when using sync_poweroff.
* create and use name allocation function in the debug area instead of inline.
Changes since v4:
* move to power_on/off callbacks out of the state array Platforms can check the state_idx to know what state the power on/off corresponds to.
* convert states to pointer,
Dynamically allocate the states array to save memory on platforms with several power domains.
* rename target_state to state_idx and remove init_state.
Changes since v3:
* remove old power on/off function at the end of the series so that compilation will not break in between.
Changes since v2:
* remove state argument and macros from save/restore callbacks.
* added init_state for platforms to pass the initial state when the genpd is initially off.
* convert current genpd users for the structure changes.
Changes since v1:
* split the changes so that the actual logic that selects the target state is a separate patch.
* move the cached logic out of the state function and add it back to default_power_down_ok.
* rename default_power_down_ok_state to power_down_ok_for_state Axel Haslam (3):
PM / Domains: Support for multiple states
ARM: imx6: pm: declare pm domain latency on power_state struct. PM / Domains: remove old power on/off latencies.
arch/arm/mach-imx/gpc.c | 9 +++-- drivers/base/power/domain.c | 33 ++++++++++++++++--- drivers/base/power/domain_governor.c | 64 ++++++++++++++++++++++-------------- include/linux/pm_domain.h | 13 ++++++-- 4 files changed, 86 insertions(+), 33 deletions(-)
Signature · 1 line
2.6.3
PATCH v12 1/3 PM / Domains: Support for multiple states
From: Axel Haslam <[email protected]>
Some hardware (eg. OMAP), has the ability to enter different low power modes for a given power domain. This allows for more fine grained control over the power state of the platform. As a typical example, some registers of the hardware may be implemented with retention flip-flops and be able to retain their state at lower voltages allowing for faster on/off latencies and an increased window of opportunity to enter an intermediate low power state other than "off"
When trying to set a power domain to off, the genpd governor will choose the deepest state that will respect the qos constraints of all the devices and sub-domains on the power domain. The state chosen by the governor is saved in the "state_idx" field of the generic_pm_domain structure and shall be used by the power_off and power_on callbacks to perform the necessary actions to set the power domain into (and out of) the state indicated by state_idx.
States must be declared in ascending order from shallowest to deepest, deepest meaning the state which takes longer to enter and exit.
For platforms that don't declare any states, a single a single "off" state is used. Once all platforms are converted to use the state array, the legacy on/off latencies will be removed.
[Lina: Modified genpd state initialization and remove use of save_state_latency_ns in genpd timing data]
--- drivers/base/power/domain.c | 39 +++++++++++++++++++--- drivers/base/power/domain_governor.c | 64 ++++++++++++++++++++++-------------- include/linux/pm_domain.h | 11 +++++++ 3 files changed, 85 insertions(+), 29 deletions(-)
drivers/base/power/domain.c +34 -5
@@ -104,6 +104,7 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)static int genpd_power_on (struct generic_pm_domain *genpd,bool timed) { +unsigned int state_idx = genpd->state_idx;ktime_t time_start;s64 elapsed_ns;int ret;
@@ -120,10 +121,10 @@ static int genpd_power_on(struct generic_pm_domain *genpd, bool timed)return ret; elapsed_ns =ktime_to_ns (ktime_sub (ktime_get (), time_start)); -if (elapsed_ns <= genpd->power_on_latency_ns) +if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns)return ret; - genpd->power_on_latency_ns = elapsed_ns; + genpd->states[state_idx].power_on_latency_ns = elapsed_ns; genpd->max_off_time_changed = true;pr_debug ("%s: Power-%s latency exceeded, new value %lld ns\n" , genpd->name,"on" , elapsed_ns);
@@ -133,6 +134,7 @@ static int genpd_power_on(struct generic_pm_domain *genpd, bool timed)static int genpd_power_off (struct generic_pm_domain *genpd,bool timed) { +unsigned int state_idx = genpd->state_idx;ktime_t time_start;s64 elapsed_ns;int ret;
@@ -149,10 +151,10 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool timed)return ret; elapsed_ns =ktime_to_ns (ktime_sub (ktime_get (), time_start)); -if (elapsed_ns <= genpd->power_off_latency_ns) +if (elapsed_ns <= genpd->states[state_idx].power_off_latency_ns)return ret; - genpd->power_off_latency_ns = elapsed_ns; + genpd->states[state_idx].power_off_latency_ns = elapsed_ns; genpd->max_off_time_changed = true;pr_debug ("%s: Power-%s latency exceeded, new value %lld ns\n" , genpd->name,"off" , elapsed_ns);
@@ -585,6 +587,8 @@ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd, || atomic_read(&genpd->sd_count) > 0)return ; +/* Choose the deepest state when suspending */ + genpd->state_idx = genpd->state_count -1 ;genpd_power_off (genpd, timed); genpd->status =GPD_STATE_POWER_OFF ;
@@ -1508,6 +1512,26 @@ void pm_genpd_init(struct generic_pm_domain *genpd, genpd->dev_ops.start = pm_clk_resume; } +if (genpd->state_idx >=GENPD_MAX_NUM_STATES ) { +pr_warn ("Initial state index out of bounds.\n" ); + genpd->state_idx =GENPD_MAX_NUM_STATES -1 ; + } + +if (genpd->state_count >GENPD_MAX_NUM_STATES ) { +pr_warn ("Limiting states to %d\n" ,GENPD_MAX_NUM_STATES ); + genpd->state_count =GENPD_MAX_NUM_STATES ; + } + +/* Use only one "off" state if there were no states declared */ +if (genpd->state_count ==0 ) { + genpd->states[0 ].power_on_latency_ns = + genpd->power_on_latency_ns; + genpd->states[0 ].power_off_latency_ns = + genpd->power_off_latency_ns; + + genpd->state_count =1 ; + } +mutex_lock (&gpd_list_lock);list_add (&genpd->gpd_list_node, &gpd_list);mutex_unlock (&gpd_list_lock);
@@ -1872,7 +1896,12 @@ static int pm_genpd_summary_one(struct seq_file *s,if (WARN_ON (genpd->status >=ARRAY_SIZE (status_lookup))) goto exit; -seq_printf (s,"%-30s %-15s " , genpd->name, status_lookup[genpd->status]); +seq_printf (s,"%-30s %s" , genpd->name, status_lookup[genpd->status]); + +if (genpd->status ==GPD_STATE_POWER_OFF ) +seq_printf (s," %-13d " , genpd->state_idx); +else +seq_printf (s," %-15s " ,"" );/* * Modifications on the list require holding locks on both
drivers/base/power/domain_governor.c +40 -24
92 lines not on this page · raw message
include/linux/pm_domain.h +11 -0
@@ -19,6 +19,8 @@/* Defines used for the flags field in the struct generic_pm_domain */ #define GENPD_FLAG_PM_CLK (1U << 0)/* PM domain uses PM clk */ +#define GENPD_MAX_NUM_STATES 8/* Number of possible low power states */ +enum gpd_status {GPD_STATE_ACTIVE =0 ,/* PM domain is active */ GPD_STATE_POWER_OFF ,/* PM domain is off */
@@ -37,6 +39,11 @@ struct gpd_dev_ops {bool (*active_wakeup)(struct device *dev); }; +struct genpd_power_state { +s64 power_off_latency_ns; +s64 power_on_latency_ns; +}; +struct generic_pm_domain {struct dev_pm_domain domain;/* PM domain operations */ struct list_head gpd_list_node;/* Node in the global PM domains list */
@@ -66,6 +73,10 @@ struct generic_pm_domain {void (*detach_dev)(struct generic_pm_domain *domain,struct device *dev);unsigned int flags;/* Bit field of configs for genpd */ +struct genpd_power_state states[GENPD_MAX_NUM_STATES ]; +unsigned int state_count;/* number of states */ +unsigned int state_idx;/* state that genpd will go to when off */ + };static inline struct generic_pm_domain *pd_to_genpd (struct dev_pm_domain *pd)
Signature · 1 line
2.6.3
PATCH v12 2/3 ARM: imx6: pm: declare pm domain latency on power_state struct.
In reply to [email protected]From: Axel Haslam <[email protected]>
The generic_pm_domain structure uses an array of latencies to be able to declare multiple intermediate states.
Declare a single "OFF" state with the default latencies So that the power_off_latency_ns and power_on_latency_ns fields of generic_pm_domain structure can be eventually removed.
--- arch/arm/mach-imx/gpc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/mach-imx/gpc.c +7 -2
@@ -374,8 +374,13 @@ static struct pu_domain imx6q_pu_domain = { .name = "PU", .power_off = imx6q_pm_pu_power_off, .power_on = imx6q_pm_pu_power_on, - .power_off_latency_ns = 25000, - .power_on_latency_ns = 2000000, + .states = { + [0] = { + .power_off_latency_ns = 25000, + .power_on_latency_ns = 2000000, + }, + }, + .state_count = 1, }, };
Signature · 1 line
2.6.3
PATCH v12 3/3 PM / Domains: remove old power on/off latencies.
In reply to [email protected]From: Axel Haslam <[email protected]>
Now that all known users have been converted to use state latencies, we can remove the latency field in the generic_pm_domain structure.
--- drivers/base/power/domain.c | 8 +------- include/linux/pm_domain.h | 2 -- 2 files changed, 1 insertion(+), 9 deletions(-)
drivers/base/power/domain.c +1 -7
@@ -1523,14 +1523,8 @@ void pm_genpd_init(struct generic_pm_domain *genpd, }/* Use only one "off" state if there were no states declared */ -if (genpd->state_count ==0 ) { - genpd->states[0 ].power_on_latency_ns = - genpd->power_on_latency_ns; - genpd->states[0 ].power_off_latency_ns = - genpd->power_off_latency_ns; - +if (genpd->state_count ==0 ) genpd->state_count =1 ; - }mutex_lock (&gpd_list_lock);list_add (&genpd->gpd_list_node, &gpd_list);
include/linux/pm_domain.h +0 -2
@@ -61,9 +61,7 @@ struct generic_pm_domain {unsigned int prepared_count;/* Suspend counter of prepared devices */ bool suspend_power_off;/* Power status before system suspend */ int (*power_off)(struct generic_pm_domain *domain); -s64 power_off_latency_ns;int (*power_on)(struct generic_pm_domain *domain); -s64 power_on_latency_ns;struct gpd_dev_ops dev_ops;s64 max_off_time_ns;/* Maximum allowed "suspended" time. */ bool max_off_time_changed;
Signature · 1 line
2.6.3
Quoted 89 lines · On 15 February 2016 at 11:10, <[email protected]> wrote:
From: Axel Haslam <[email protected]>
Some architectures may have intermediate power levels between on and off.
This patch set adds the ability to declare multiple states for a given generic power domain, the idea is that the deepest state will be entered which does not violate any of the device or sub-domain latency constraints.
Changes since v11
* Use static array of state instead of dynamic allocationChanges since v10
* Several reworks after Ulf Hansson's comments:
- merge the governor changes and core changes into a single patch
- remove the "name" of the state.
- add a default state allocation function
- convert governor power done ok function to while loop.
- reword commit message
*rebased on next-20160205Changes since v9
*rebased on linux-nextChanges since v8
* rebased to linux-pm nextChanges since v7:
* rebase to 4.3-rc5* add
genpd_init_simple(Lina's suggestion) for platforms that don't have multiple states and don't declare initial latencies. A default OFF state with initial 0 latencies will be used in this case.* Append Mark's patch to add "states" and "timings" to the genpd debugfs
Changes since v6:
* change int to unsigned int were appropriate.* spelling mistakes, and fix commit message for removal of latencies.
Changes since v5:
* rebase to 4.1-rc1* Pass state array as an init argument on
pm_genpd_init* declare a default OFF state with no latencies, that will be used if a null state argument is given.
* set the deepest state when using
sync_poweroff.* create and use name allocation function in the debug area instead of inline.
Changes since v4:
* move to power_on/off callbacks out of the state array Platforms can check thestate_idxto know what state the power on/off corresponds to.* convert states to pointer,
Dynamically allocate the states array to save memory on platforms with several power domains.* rename
target_statetostate_idxand removeinit_state.Changes since v3:
* remove old power on/off function at the end of the series so that compilation will not break in between.Changes since v2:
* remove state argument and macros from save/restore callbacks.* added
init_statefor platforms to pass the initial state when the genpd is initially off.* convert current genpd users for the structure changes.
Changes since v1:
* split the changes so that the actual logic that selects the target state is a separate patch.* move the cached logic out of the state function and add it back to
default_power_down_ok.* rename
default_power_down_ok_statetopower_down_ok_for_stateAxel Haslam (3):
PM / Domains: Support for multiple states
ARM: imx6: pm: declare pm domain latency onpower_statestruct. PM / Domains: remove old power on/off latencies.
Quoted 9 lines
arch/arm/mach-imx/gpc.c | 9 +++-- drivers/base/power/domain.c | 33 ++++++++++++++++--- drivers/base/power/domain_governor.c | 64 ++++++++++++++++++++++-------------- include/linux/pm_domain.h | 13 ++++++-- 4 files changed, 86 insertions(+), 33 deletions(-)--
2.6.3
For the series;
Kind regards
Uffe
Quoted 96 lines · Ulf Hansson
Quoted 95 lines · On 15 February 2016 at 11:10, <[email protected]> wrote:
From: Axel Haslam <[email protected]>
Some architectures may have intermediate power levels between on and off.
This patch set adds the ability to declare multiple states for a given generic power domain, the idea is that the deepest state will be entered which does not violate any of the device or sub-domain latency constraints.
Changes since v11
* Use static array of state instead of dynamic allocationChanges since v10
* Several reworks after Ulf Hansson's comments:
- merge the governor changes and core changes into a single patch
- remove the "name" of the state.
- add a default state allocation function
- convert governor power done ok function to while loop.
- reword commit message
*rebased on next-20160205Changes since v9
*rebased on linux-nextChanges since v8
* rebased to linux-pm nextChanges since v7:
* rebase to 4.3-rc5* add
genpd_init_simple(Lina's suggestion) for platforms that don't have multiple states and don't declare initial latencies. A default OFF state with initial 0 latencies will be used in this case.* Append Mark's patch to add "states" and "timings" to the genpd debugfs
Changes since v6:
* change int to unsigned int were appropriate.* spelling mistakes, and fix commit message for removal of latencies.
Changes since v5:
* rebase to 4.1-rc1* Pass state array as an init argument on
pm_genpd_init* declare a default OFF state with no latencies, that will be used if a null state argument is given.
* set the deepest state when using
sync_poweroff.* create and use name allocation function in the debug area instead of inline.
Changes since v4:
* move to power_on/off callbacks out of the state array Platforms can check thestate_idxto know what state the power on/off corresponds to.* convert states to pointer,
Dynamically allocate the states array to save memory on platforms with several power domains.* rename
target_statetostate_idxand removeinit_state.Changes since v3:
* remove old power on/off function at the end of the series so that compilation will not break in between.Changes since v2:
* remove state argument and macros from save/restore callbacks.* added
init_statefor platforms to pass the initial state when the genpd is initially off.* convert current genpd users for the structure changes.
Changes since v1:
* split the changes so that the actual logic that selects the target state is a separate patch.* move the cached logic out of the state function and add it back to
default_power_down_ok.* rename
default_power_down_ok_statetopower_down_ok_for_stateAxel Haslam (3):
PM / Domains: Support for multiple states
ARM: imx6: pm: declare pm domain latency onpower_statestruct. PM / Domains: remove old power on/off latencies.arch/arm/mach-imx/gpc.c | 9 +++-- drivers/base/power/domain.c | 33 ++++++++++++++++--- drivers/base/power/domain_governor.c | 64 ++++++++++++++++++++++-------------- include/linux/pm_domain.h | 13 ++++++-- 4 files changed, 86 insertions(+), 33 deletions(-)
Quoted 7 lines
Quoted 3 lines
--
2.6.3For the series;
Acked-by Ulf Hansson <[email protected]>
OK, queued up for 4.6, thanks!
Rafael