PM: QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
Subsystems (5)
v3 cover PM: QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
Support for frequency limits in dev_pm_qos was removed when cpufreq was switched to freq_qos, this series attempts to restore it by reimplementing on top of freq_qos.
Discussion about removal is here:
https://lore.kernel.org/linux-pm/VI1PR04MB7023DF47D046AEADB4E051EBEE680@VI1PR04MB7023.eurprd04.prod.outlook.com/T/#u
The cpufreq core switched away because it needs contraints at the level of a "cpufreq_policy" which cover multiple cpus so dev_pm_qos coupling to struct device was not useful. Cpufreq could only use dev_pm_qos by implementing an additional layer of aggregation anyway.
However in the devfreq subsystem scaling is always performed on a per-device basis so dev_pm_qos is a very good match. Support for dev_pm_qos in devfreq core is here:
https://patchwork.kernel.org/cover/11252409/
That series is RFC mostly because it needs these PM core patches. Earlier versions got entangled in some locking cleanups but those are not strictly necessary to get dev_pm_qos functionality.
In theory if freq_qos is extended to handle conflicting min/max values then this sharing would be valuable. Right now freq_qos just ties two unrelated pm_qos aggregations for min and max freq.
---
This is implemented by embeding a freq_qos_request inside dev_pm_qos_request:
the data field was already an union in order to deal with flag requests.
The internal freq_qos_apply is exported so that it can be called from dev_pm_qos apply_constraints.
The dev_pm_qos_constraints_destroy function has no obvious equivalent in freq_qos and the whole approach of "removing requests" is somewhat dubios:
request objects should be owned by consumers and the list of qos requests should be empty when the target device is deleted.
Changes since v2:
* #define PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE FREQ_QOS_MAX_DEFAULT_VALUE
* #define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX (in new patch)
* Add initial kunit test for freq_qos, validating the MAX_DEFAULT_VALUE found by Matthias.
Link to v2: https://patchwork.kernel.org/cover/11250413/
First two patches can be applied separated
Changes since v1:
* Don't rename or EXPORT_SYMBOL_GPL the freq_qos_apply function; just drop the static marker.
Link to v1: https://patchwork.kernel.org/cover/11212887/
Leonard Crestez (4):
PM / QoS: Initial kunit test
PM / QOS: Redefine FREQ_QOS_MAX_DEFAULT_VALUE to S32_MAX PM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 116 ++++++++++++++++++++++++++++++++++ drivers/base/power/qos.c | 69 ++++++++++++++++++-- include/linux/pm_qos.h | 86 ++++++++++++++----------- kernel/power/qos.c | 4 +- 6 files changed, 237 insertions(+), 43 deletions(-) create mode 100644 drivers/base/power/qos-test.c
Signature · 1 line
2.17.1
PATCH v3 1/4 PM / QoS: Initial kunit test
The pm_qos family of APIs are used in relatively difficult to reproduce scenarios such as thermal throttling so they benefit from unit testing.
Start by adding basic tests from the the freq_qos APIs. It includes tests for issues that were brought up on mailing lists:
https://patchwork.kernel.org/patch/11252425/#23017005
https://patchwork.kernel.org/patch/11253421/
--- drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 116 ++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/base/power/qos-test.c
drivers/base/Kconfig +4 -0
@@ -155,10 +155,14 @@ config DEBUG_TEST_DRIVER_REMOVE This option is expected to find errors and may render your system unusable. You should say N here unless you are explicitly looking to test this functionality. +config PM_QOS_KUNIT_TEST + bool "KUnit Test for PM QoS features" + depends on KUNIT + config HMEM_REPORTING bool default n depends on NUMA help
drivers/base/power/Makefile +1 -0
@@ -2,7 +2,8 @@ obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o obj-$(CONFIG_HAVE_CLK) += clock_ops.o +obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/power/qos-test.c new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 1/4] PM / QoS: Initial kunit test
Quoted 2 lines · Leonard Crestez
The
pm_qosfamily of APIs are used in relatively difficult to reproduce scenarios such as thermal throttling so they benefit from unit testing.
indeed, a unit test is useful in this case!
Quoted 69 lines
Start by adding basic tests from the the
freq_qosAPIs. It includes tests for issues that were brought up on mailing lists:https://patchwork.kernel.org/patch/11252425/#23017005
https://patchwork.kernel.org/patch/11253421/Signed-off-by Leonard Crestez <[email protected]>--- drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 116 ++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/base/power/qos-test.cdrivers/base/Kconfig +4
-0@@ -155,10 +155,14 @@ config DEBUG_TEST_DRIVER_REMOVE This option is expected to find errors and may render your system unusable. You should say N here unless you are explicitly looking to test this functionality. +config PM_QOS_KUNIT_TEST + bool "KUnit Test for PM QoS features" + depends on KUNIT + config HMEM_REPORTING bool default n depends on NUMA helpdrivers/base/power/Makefile +1
-0@@ -2,7 +2,8 @@ obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o obj-$(CONFIG_HAVE_CLK) += clock_ops.o +obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUGdrivers/base/power/qos-test.c new file +17
-0@@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 NXP +*/ +#include <kunit/test.h> +#include <linux/pm_qos.h> + +/* Basic test for aggregating two "min" requests */ +static void freq_qos_test_min (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req1, req2; +int ret; + +freq_constraints_init (&qos); +memset (&req1,0 ,sizeof (req1)); +memset (&req2,0 ,sizeof (req2));
drivers/base/power/qos-test.c line 27
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-0+ + ret =freq_qos_add_request (&qos, &req1,FREQ_QOS_MIN ,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); + ret =freq_qos_add_request (&qos, &req2,FREQ_QOS_MIN ,2000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); + +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),2000 ); + +freq_qos_remove_request (&req2); +KUNIT_EXPECT_EQ (test, ret,1 );
This checks (again) the return value of the above freq_qos_add_request() call, which I suppose is not intended. Remove?
drivers/base/power/qos-test.c line 31
Quoted 4 lines
drivers/base/power/qos-test.c new file +4
-0+KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 ); + +freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 );
ditto
Quoted 25 lines
drivers/base/power/qos-test.c new file +25
-0+KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ), +FREQ_QOS_MIN_DEFAULT_VALUE ); +} + +/* Test that requests for MAX_DEFAULT_VALUE have no effect */ +static void freq_qos_test_maxdef (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req1, req2; +int ret; + +freq_constraints_init (&qos); +memset (&req1,0 ,sizeof (req1)); +memset (&req2,0 ,sizeof (req2)); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ), +FREQ_QOS_MAX_DEFAULT_VALUE ); + + ret =freq_qos_add_request (&qos, &req1,FREQ_QOS_MAX , +FREQ_QOS_MAX_DEFAULT_VALUE ); +KUNIT_EXPECT_EQ (test, ret,0 ); + ret =freq_qos_add_request (&qos, &req2,FREQ_QOS_MAX , +FREQ_QOS_MAX_DEFAULT_VALUE ); +KUNIT_EXPECT_EQ (test, ret,0 ); + +/* Add max 1000 */
drivers/base/power/qos-test.c line 66
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-0+ ret =freq_qos_update_request (&req1,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ),1000 ); + +/* Add max 2000, no impact */ + ret =freq_qos_update_request (&req2,2000 ); +KUNIT_EXPECT_EQ (test, ret,0 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ),1000 ); + +/* Remove max 2000, new max 1000 */
the code doesn't match the comment, max 1000 is removed
drivers/base/power/qos-test.c line 73
Quoted 7 lines
drivers/base/power/qos-test.c new file +7
-0+ ret =freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ),2000 ); +} + +/* +* Test that a freq_qos_request can be readded after removal
nit: 're-added'. It took me a few secs to figure this is not a about 'read'ing something
Re: [PATCH v3 1/4] PM / QoS: Initial kunit test
Quoted 24 lines · Matthias Kaehlcke
Quoted 2 lines · Leonard Crestez
The
pm_qosfamily of APIs are used in relatively difficult to reproduce scenarios such as thermal throttling so they benefit from unit testing.indeed, a unit test is useful in this case!
Quoted 18 lines
Start by adding basic tests from the the
freq_qosAPIs. It includes tests for issues that were brought up on mailing lists:drivers/base/power/qos-test.c new file +15
-0+/* Basic test for aggregating two "min" requests */ +static void freq_qos_test_min (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req1, req2; +int ret; + +freq_constraints_init (&qos); +memset (&req1,0 ,sizeof (req1)); +memset (&req2,0 ,sizeof (req2)); + + ret =freq_qos_add_request (&qos, &req1,FREQ_QOS_MIN ,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); + ret =freq_qos_add_request (&qos, &req2,FREQ_QOS_MIN ,2000 ); +KUNIT_EXPECT_EQ (test, ret,1 );
Quoted 8 lines
drivers/base/power/qos-test.c line 27
Quoted 5 lines
drivers/base/power/qos-test.c new file +5
-0+ +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),2000 ); + +freq_qos_remove_request (&req2); +KUNIT_EXPECT_EQ (test, ret,1 );This checks (again) the return value of the above
freq_qos_add_request()call, which I suppose is not intended. Remove?
Should check the return value from freq_qos_remove_request
Quoted 36 lines
drivers/base/power/qos-test.c line 31
Quoted 4 lines
drivers/base/power/qos-test.c new file +4
-0+KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 ); + +freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 );ditto
Quoted 29 lines
drivers/base/power/qos-test.c new file +29
-0+KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ), +FREQ_QOS_MIN_DEFAULT_VALUE ); +} + +/* Test that requests for MAX_DEFAULT_VALUE have no effect */ +static void freq_qos_test_maxdef (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req1, req2; +int ret; + +freq_constraints_init (&qos); +memset (&req1,0 ,sizeof (req1)); +memset (&req2,0 ,sizeof (req2)); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ), +FREQ_QOS_MAX_DEFAULT_VALUE ); + + ret =freq_qos_add_request (&qos, &req1,FREQ_QOS_MAX , +FREQ_QOS_MAX_DEFAULT_VALUE ); +KUNIT_EXPECT_EQ (test, ret,0 ); + ret =freq_qos_add_request (&qos, &req2,FREQ_QOS_MAX , +FREQ_QOS_MAX_DEFAULT_VALUE ); +KUNIT_EXPECT_EQ (test, ret,0 ); + +/* Add max 1000 */ + ret =freq_qos_update_request (&req1,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ),1000 ); +
Quoted 8 lines
drivers/base/power/qos-test.c line 66
Quoted 6 lines
drivers/base/power/qos-test.c new file +6
-0+/* Add max 2000, no impact */ + ret =freq_qos_update_request (&req2,2000 ); +KUNIT_EXPECT_EQ (test, ret,0 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ),1000 ); + +/* Remove max 2000, new max 1000 */ the code doesn't match the comment, max 1000 is removed
Fixed
Quoted 10 lines
drivers/base/power/qos-test.c line 73
Quoted 7 lines
drivers/base/power/qos-test.c new file +7
-0+ ret =freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MAX ),2000 ); +} + +/* +* Test that a freq_qos_request can be readded after removal nit: 're-added'. It took me a few secs to figure this is not a about 'read'ing something
Both re-add and readd seem to be valid, I'll change to "added again".
--
Regards,
Leonard
PATCH v3 2/4 PM / QOS: Redefine FREQ_QOS_MAX_DEFAULT_VALUE to S32_MAX
In reply to Leonard CrestezQOS requests for DEFAULT_VALUE are supposed to be ignored but this is not the case for FREQ_QOS_MAX. Adding one request for MAX_DEFAULT_VALUE and one for a real value will cause freq_qos_read_value to unexpectedly return MAX_DEFAULT_VALUE (-1).
This happens because freq_qos max value is aggregated with PM_QOS_MIN but FREQ_QOS_MAX_DEFAULT_VALUE is (-1) so it's smaller than other values.
Fix this by redefining FREQ_QOS_MAX_DEFAULT_VALUE to S32_MAX.
Looking at current users for freq_qos it seems that none of them create requests for FREQ_QOS_MAX_DEFAULT_VALUE.
--- include/linux/pm_qos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pm_qos.h +1 -1
@@ -254,11 +254,11 @@ static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; }#endif #define FREQ_QOS_MIN_DEFAULT_VALUE 0 -#define FREQ_QOS_MAX_DEFAULT_VALUE (-1) +#define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAXenum freq_qos_req_type {FREQ_QOS_MIN =1 ,FREQ_QOS_MAX , };
Signature · 1 line
2.17.1
Re: [PATCH v3 2/4] PM / QOS: Redefine FREQ_QOS_MAX_DEFAULT_VALUE to S32_MAX
Quoted 9 lines · Leonard Crestez
QOS requests for
DEFAULT_VALUEare supposed to be ignored but this is not the case forFREQ_QOS_MAX. Adding one request forMAX_DEFAULT_VALUEand one for a real value will causefreq_qos_read_valueto unexpectedly returnMAX_DEFAULT_VALUE(-1).This happens because
freq_qosmax value is aggregated withPM_QOS_MINbutFREQ_QOS_MAX_DEFAULT_VALUEis (-1) so it's smaller than other values.
Quoted 6 lines
Fix this by redefining
FREQ_QOS_MAX_DEFAULT_VALUEtoS32_MAX.Looking at current users for
freq_qosit seems that none of them create requests forFREQ_QOS_MAX_DEFAULT_VALUE.Fixes 77751a466ebd ("PM: QoS: Introduce frequency QoS")
nit: you could add:
Quoted 10 lines
Signed-off-by Leonard Crestez <[email protected]>--- include/linux/pm_qos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/pm_qos.h +0
-0
include/linux/pm_qos.h static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) · line 259
Quoted 7 lines
include/linux/pm_qos.h +1
-1@@ -254,11 +254,11 @@ static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; }#endif #define FREQ_QOS_MIN_DEFAULT_VALUE 0 -#define FREQ_QOS_MAX_DEFAULT_VALUE (-1) +#define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX
PATCH v3 3/4 PM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs
In reply to Leonard CrestezThis allows dev_pm_qos to embed freq_qos structs, which is done in the next patch. Separate commit to make it easier to review.
--- include/linux/pm_qos.h | 74 ++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 36 deletions(-)
include/linux/pm_qos.h +38 -36
@@ -47,25 +47,10 @@ struct pm_qos_request {struct pm_qos_flags_request {struct list_head node;s32 flags;/* Do not change to 64 bit */ }; -enum dev_pm_qos_req_type { -DEV_PM_QOS_RESUME_LATENCY =1 , -DEV_PM_QOS_LATENCY_TOLERANCE , -DEV_PM_QOS_FLAGS , -}; - -struct dev_pm_qos_request { -enum dev_pm_qos_req_type type; -union { -struct plist_node pnode; -struct pm_qos_flags_request flr; - } data; -struct device *dev; -}; -enum pm_qos_type {PM_QOS_UNITIALIZED ,PM_QOS_MAX ,/* return the largest value */ PM_QOS_MIN ,/* return the smallest value */ PM_QOS_SUM /* return the sum */
@@ -88,10 +73,48 @@ struct pm_qos_constraints {struct pm_qos_flags {struct list_head list;s32 effective_flags;/* Do not change to 64 bit */ }; + +#define FREQ_QOS_MIN_DEFAULT_VALUE 0 +#define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX + +enum freq_qos_req_type { +FREQ_QOS_MIN =1 , +FREQ_QOS_MAX , +}; + +struct freq_constraints { +struct pm_qos_constraints min_freq; +struct blocking_notifier_head min_freq_notifiers; +struct pm_qos_constraints max_freq; +struct blocking_notifier_head max_freq_notifiers; +}; + +struct freq_qos_request { +enum freq_qos_req_type type; +struct plist_node pnode; +struct freq_constraints *qos; +}; + + +enum dev_pm_qos_req_type { +DEV_PM_QOS_RESUME_LATENCY =1 , +DEV_PM_QOS_LATENCY_TOLERANCE , +DEV_PM_QOS_FLAGS , +}; + +struct dev_pm_qos_request { +enum dev_pm_qos_req_type type; +union { +struct plist_node pnode; +struct pm_qos_flags_request flr; + } data; +struct device *dev; +}; +struct dev_pm_qos {struct pm_qos_constraints resume_latency;struct pm_qos_constraints latency_tolerance;struct pm_qos_flags flags;struct dev_pm_qos_request *resume_latency_req;
@@ -253,31 +276,10 @@ static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) {return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT ; }#endif -#define FREQ_QOS_MIN_DEFAULT_VALUE 0 -#define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX - -enum freq_qos_req_type { -FREQ_QOS_MIN =1 , -FREQ_QOS_MAX , -}; - -struct freq_constraints { -struct pm_qos_constraints min_freq; -struct blocking_notifier_head min_freq_notifiers; -struct pm_qos_constraints max_freq; -struct blocking_notifier_head max_freq_notifiers; -}; - -struct freq_qos_request { -enum freq_qos_req_type type; -struct plist_node pnode; -struct freq_constraints *qos; -}; -static inline int freq_qos_request_active (struct freq_qos_request *req) {return !IS_ERR_OR_NULL (req->qos); }
Signature · 1 line
2.17.1
Re: [PATCH v3 3/4] PM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs
Quoted 122 lines · Leonard Crestez
This allows
dev_pm_qosto embedfreq_qosstructs, which is done in the next patch. Separate commit to make it easier to review.Signed-off-by Leonard Crestez <[email protected]>--- include/linux/pm_qos.h | 74 ++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 36 deletions(-)include/linux/pm_qos.h +38
-36@@ -47,25 +47,10 @@ struct pm_qos_request {struct pm_qos_flags_request {struct list_head node;s32 flags;/* Do not change to 64 bit */ }; -enum dev_pm_qos_req_type { -DEV_PM_QOS_RESUME_LATENCY =1 , -DEV_PM_QOS_LATENCY_TOLERANCE , -DEV_PM_QOS_FLAGS , -}; - -struct dev_pm_qos_request { -enum dev_pm_qos_req_type type; -union { -struct plist_node pnode; -struct pm_qos_flags_request flr; - } data; -struct device *dev; -}; -enum pm_qos_type {PM_QOS_UNITIALIZED ,PM_QOS_MAX ,/* return the largest value */ PM_QOS_MIN ,/* return the smallest value */ PM_QOS_SUM /* return the sum */ @@ -88,10 +73,48 @@ struct pm_qos_constraints {struct pm_qos_flags {struct list_head list;s32 effective_flags;/* Do not change to 64 bit */ }; + +#define FREQ_QOS_MIN_DEFAULT_VALUE 0 +#define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX + +enum freq_qos_req_type { +FREQ_QOS_MIN =1 , +FREQ_QOS_MAX , +}; + +struct freq_constraints { +struct pm_qos_constraints min_freq; +struct blocking_notifier_head min_freq_notifiers; +struct pm_qos_constraints max_freq; +struct blocking_notifier_head max_freq_notifiers; +}; + +struct freq_qos_request { +enum freq_qos_req_type type; +struct plist_node pnode; +struct freq_constraints *qos; +}; + + +enum dev_pm_qos_req_type { +DEV_PM_QOS_RESUME_LATENCY =1 , +DEV_PM_QOS_LATENCY_TOLERANCE , +DEV_PM_QOS_FLAGS , +}; + +struct dev_pm_qos_request { +enum dev_pm_qos_req_type type; +union { +struct plist_node pnode; +struct pm_qos_flags_request flr; + } data; +struct device *dev; +}; +struct dev_pm_qos {struct pm_qos_constraints resume_latency;struct pm_qos_constraints latency_tolerance;struct pm_qos_flags flags;struct dev_pm_qos_request *resume_latency_req;@@ -253,31 +276,10 @@ static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) {return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT ; }#endif -#define FREQ_QOS_MIN_DEFAULT_VALUE 0 -#define FREQ_QOS_MAX_DEFAULT_VALUE S32_MAX - -enum freq_qos_req_type { -FREQ_QOS_MIN =1 , -FREQ_QOS_MAX , -}; - -struct freq_constraints { -struct pm_qos_constraints min_freq; -struct blocking_notifier_head min_freq_notifiers; -struct pm_qos_constraints max_freq; -struct blocking_notifier_head max_freq_notifiers; -}; - -struct freq_qos_request { -enum freq_qos_req_type type; -struct plist_node pnode; -struct freq_constraints *qos; -}; -static inline int freq_qos_request_active (struct freq_qos_request *req) {return !IS_ERR_OR_NULL (req->qos); }Signature · 1 line
2.17.1
PATCH v3 4/4 PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
In reply to Leonard CrestezSupport for adding per-device frequency limits was removed in commit 2aac8bdf7a0f ("PM: QoS: Drop frequency QoS types from device PM QoS") after cpufreq switched to use a new "freq_constraints" construct.
Restore support for per-device freq limits but base this upon freq_constraints. This is primarily meant to be used by the devfreq subsystem.
This removes the "static" marking on freq_qos_apply but does not export it for modules.
--- drivers/base/power/qos.c | 69 ++++++++++++++++++++++++++++++++++++---- include/linux/pm_qos.h | 12 +++++++ kernel/power/qos.c | 4 ++- 3 files changed, 78 insertions(+), 7 deletions(-)
drivers/base/power/qos.c +63 -6
@@ -113,14 +113,24 @@ s32 dev_pm_qos_read_value(struct device *dev, enum dev_pm_qos_req_type type)unsigned long flags;s32 ret;spin_lock_irqsave (&dev->power.lock, flags); -if (type ==DEV_PM_QOS_RESUME_LATENCY ) { +switch (type) { +case DEV_PM_QOS_RESUME_LATENCY : ret =IS_ERR_OR_NULL (qos) ?PM_QOS_RESUME_LATENCY_NO_CONSTRAINT :pm_qos_read_value (&qos->resume_latency); - }else { +break ; +case DEV_PM_QOS_MIN_FREQUENCY : + ret =IS_ERR_OR_NULL (qos) ?PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE + :freq_qos_read_value (&qos->freq,FREQ_QOS_MIN ); +break ; +case DEV_PM_QOS_MAX_FREQUENCY : + ret =IS_ERR_OR_NULL (qos) ?PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE + :freq_qos_read_value (&qos->freq,FREQ_QOS_MAX ); +break ; +default :WARN_ON (1 ); ret =0 ; }spin_unlock_irqrestore (&dev->power.lock, flags);
@@ -157,10 +167,14 @@ static int apply_constraint(struct dev_pm_qos_request *req,if (ret) { value =pm_qos_read_value (&qos->latency_tolerance); req->dev->power.set_latency_tolerance (req->dev, value); }break ; +case DEV_PM_QOS_MIN_FREQUENCY : +case DEV_PM_QOS_MAX_FREQUENCY : + ret =freq_qos_apply (&req->data.freq, action, value); +break ;case DEV_PM_QOS_FLAGS : ret =pm_qos_update_flags (&qos->flags, &req->data.flr, action, value);break ;default :
@@ -207,10 +221,12 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) c->target_value =PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE ; c->default_value =PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE ; c->no_constraint_value =PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT ; c->type =PM_QOS_MIN ; +freq_constraints_init (&qos->freq); +INIT_LIST_HEAD (&qos->flags.list);spin_lock_irq (&dev->power.lock); dev->power.qos = qos;spin_unlock_irq (&dev->power.lock);
@@ -267,10 +283,22 @@ void dev_pm_qos_constraints_destroy(struct device *dev)plist_for_each_entry_safe (req, tmp, &c->list, data.pnode) {apply_constraint (req,PM_QOS_REMOVE_REQ ,PM_QOS_DEFAULT_VALUE );memset (req,0 ,sizeof (*req)); } + c = &qos->freq.min_freq; +plist_for_each_entry_safe (req, tmp, &c->list, data.freq.pnode) { +apply_constraint (req,PM_QOS_REMOVE_REQ ,PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE ); +memset (req,0 ,sizeof (*req)); + } + + c = &qos->freq.max_freq; +plist_for_each_entry_safe (req, tmp, &c->list, data.freq.pnode) { +apply_constraint (req,PM_QOS_REMOVE_REQ ,PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE ); +memset (req,0 ,sizeof (*req)); + } + f = &qos->flags;list_for_each_entry_safe (req, tmp, &f->list, data.flr.node) {apply_constraint (req,PM_QOS_REMOVE_REQ ,PM_QOS_DEFAULT_VALUE );memset (req,0 ,sizeof (*req)); }
@@ -312,15 +340,26 @@ static int __dev_pm_qos_add_request(struct device *dev, ret = -ENODEV ; else if (!dev->power.qos) ret =dev_pm_qos_constraints_allocate (dev);trace_dev_pm_qos_add_request (dev_name (dev), type, value); -if (!ret) { - req->dev = dev; - req->type = type; +if (ret) +return ret; + + req->dev = dev; + req->type = type; +if (req->type ==DEV_PM_QOS_MIN_FREQUENCY ) + ret =freq_qos_add_request (&dev->power.qos->freq, + &req->data.freq, +FREQ_QOS_MIN , value); +else if (req->type ==DEV_PM_QOS_MAX_FREQUENCY ) + ret =freq_qos_add_request (&dev->power.qos->freq, + &req->data.freq, +FREQ_QOS_MAX , value); +else ret =apply_constraint (req,PM_QOS_ADD_REQ , value); - } +return ret; }/** * dev_pm_qos_add_request - inserts new qos request into the list
@@ -380,10 +419,14 @@ static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,switch (req->type) {case DEV_PM_QOS_RESUME_LATENCY :case DEV_PM_QOS_LATENCY_TOLERANCE : curr_value = req->data.pnode.prio;break ; +case DEV_PM_QOS_MIN_FREQUENCY : +case DEV_PM_QOS_MAX_FREQUENCY : + curr_value = req->data.freq.pnode.prio; +break ;case DEV_PM_QOS_FLAGS : curr_value = req->data.flr.flags;break ;default :return -EINVAL ;
@@ -505,10 +548,16 @@ int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier,switch (type) {case DEV_PM_QOS_RESUME_LATENCY : ret =blocking_notifier_chain_register (dev->power.qos->resume_latency.notifiers, notifier);break ; +case DEV_PM_QOS_MIN_FREQUENCY : + ret =freq_qos_add_notifier (&dev->power.qos->freq,FREQ_QOS_MIN , notifier); +break ; +case DEV_PM_QOS_MAX_FREQUENCY : + ret =freq_qos_add_notifier (&dev->power.qos->freq,FREQ_QOS_MAX , notifier); +break ;default :WARN_ON (1 ); ret = -EINVAL ; }
@@ -544,10 +593,18 @@ int dev_pm_qos_remove_notifier(struct device *dev,switch (type) {case DEV_PM_QOS_RESUME_LATENCY : ret =blocking_notifier_chain_unregister (dev->power.qos->resume_latency.notifiers, notifier);break ; +case DEV_PM_QOS_MIN_FREQUENCY : + ret =freq_qos_remove_notifier (&dev->power.qos->freq, +FREQ_QOS_MIN , notifier); +break ; +case DEV_PM_QOS_MAX_FREQUENCY : + ret =freq_qos_remove_notifier (&dev->power.qos->freq, +FREQ_QOS_MAX , notifier); +break ;default :WARN_ON (1 ); ret = -EINVAL ; }
include/linux/pm_qos.h +12 -0
@@ -32,10 +32,12 @@ enum pm_qos_flags_status {#define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)#define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE PM_QOS_LATENCY_ANY#define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT PM_QOS_LATENCY_ANY#define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS PM_QOS_LATENCY_ANY_NS#define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE 0 +#define PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE 0 +#define PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE FREQ_QOS_MAX_DEFAULT_VALUE#define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT (-1)#define PM_QOS_FLAG_NO_POWER_OFF (1 << 0)struct pm_qos_request {
@@ -99,25 +101,29 @@ struct freq_qos_request {enum dev_pm_qos_req_type {DEV_PM_QOS_RESUME_LATENCY =1 ,DEV_PM_QOS_LATENCY_TOLERANCE , +DEV_PM_QOS_MIN_FREQUENCY , +DEV_PM_QOS_MAX_FREQUENCY ,DEV_PM_QOS_FLAGS , };struct dev_pm_qos_request {enum dev_pm_qos_req_type type;union {struct plist_node pnode;struct pm_qos_flags_request flr; +struct freq_qos_request freq; } data;struct device *dev; };struct dev_pm_qos {struct pm_qos_constraints resume_latency;struct pm_qos_constraints latency_tolerance; +struct freq_constraints freq;struct pm_qos_flags flags;struct dev_pm_qos_request *resume_latency_req;struct dev_pm_qos_request *latency_tolerance_req;struct dev_pm_qos_request *flags_req; };
@@ -212,10 +218,14 @@ static inline s32 dev_pm_qos_read_value(struct device *dev, enum dev_pm_qos_req_type type) {switch (type) {case DEV_PM_QOS_RESUME_LATENCY :return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT ; +case DEV_PM_QOS_MIN_FREQUENCY : +return PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE ; +case DEV_PM_QOS_MAX_FREQUENCY : +return PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE ;default :WARN_ON (1 );return 0 ; } }
@@ -291,10 +301,12 @@ s32 freq_qos_read_value(struct freq_constraints *qos,int freq_qos_add_request (struct freq_constraints *qos,struct freq_qos_request *req,enum freq_qos_req_type type,s32 value);int freq_qos_update_request (struct freq_qos_request *req,s32 new_value);int freq_qos_remove_request (struct freq_qos_request *req); +int freq_qos_apply (struct freq_qos_request *req, +enum pm_qos_req_action action,s32 value);int freq_qos_add_notifier (struct freq_constraints *qos,enum freq_qos_req_type type,struct notifier_block *notifier); int freq_qos_remove_notifier(struct freq_constraints *qos,
kernel/power/qos.c +3 -1
@@ -712,12 +712,14 @@ s32 freq_qos_read_value(struct freq_constraints *qos,/** * freq_qos_apply - Add/modify/remove frequency QoS request. * @req: Constraint request to apply. * @action: Action to perform (add/update/remove). * @value: Value to assign to the QoS request. +* +* This is only meant to be called from inside pm_qos, not drivers. */ -static int freq_qos_apply (struct freq_qos_request *req, +int freq_qos_apply (struct freq_qos_request *req,enum pm_qos_req_action action,s32 value) {int ret;switch (req->type) {
Signature · 1 line
2.17.1