PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
Subsystems (5)
v4 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 (latest version, no dependencies outside this series):
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 will most likely be empty when the target device is deleted. Series follows current pattern for dev_pm_qos.
First two patches can be applied separately.
Changes since v3:
* Fix s/QOS/QoS in patch 2 title
* Improves comments in kunit test
* Fix assertions after freq_qos_remove_request
* Remove (c) from NXP copyright header
* Wrap long lines in qos.c to be under 80 chars. This fixes checkpatch but the rule is already broken by code in the files.
* Collect reviews
Link to v3: https://patchwork.kernel.org/cover/11260627/
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 and another recent fix. Testing this should be easier! Link to v2: https://patchwork.kernel.org/cover/11250413/
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 | 117 ++++++++++++++++++++++++++++++++++ drivers/base/power/qos.c | 73 +++++++++++++++++++-- include/linux/pm_qos.h | 86 ++++++++++++++----------- kernel/power/qos.c | 4 +- 6 files changed, 242 insertions(+), 43 deletions(-) create mode 100644 drivers/base/power/qos-test.c
Signature · 1 line
2.17.1
PATCH v4 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 | 117 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 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 +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 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
PATCH v4 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
PATCH v4 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 | 73 ++++++++++++++++++++++++++++++++++++---- include/linux/pm_qos.h | 12 +++++++ kernel/power/qos.c | 4 ++- 3 files changed, 82 insertions(+), 7 deletions(-)
drivers/base/power/qos.c +67 -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,24 @@ 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 +342,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 +421,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 +550,18 @@ 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 +597,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
Re: [PATCH v4 1/4] PM / QoS: Initial kunit test
In reply to Leonard CrestezQuoted 114 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.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 | 117 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 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 +59
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 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)); + + 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 ); + + ret =freq_qos_remove_request (&req2); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 ); + + ret =freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 ); +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 );
drivers/base/power/qos-test.c line 69
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-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 1000, new max 2000 */ + 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 );
nit: this last part isn't really related with MAX_DEFAULT_VALUE. It's a worthwhile test, but not necessarily in this test case. It might make more sense to set one of the constraints to FREQ_QOS_MAX_DEFAULT_VALUE again, and verify it doesn't have an impact.
Just a comment, there's nothing really wrong with how it is.
Quoted 8 lines
drivers/base/power/qos-test.c new file +8
-0+} + +/* +* Test that a freq_qos_request can be added again after removal +* +* This issue was solved by commit 05ff1ba412fd ("PM: QoS: Invalidate frequency +* QoS requests after removal") +*/
drivers/base/power/qos-test.c line 87
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-0+static void freq_qos_test_readd (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req; +int ret; + +freq_constraints_init (&qos); +memset (&req,0 ,sizeof (req)); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ), +FREQ_QOS_MIN_DEFAULT_VALUE );
nit: you could do this check once in a dedicated test and omit it in other tests to de-clutter
drivers/base/power/qos-test.c line 92
Quoted 5 lines
drivers/base/power/qos-test.c new file +5
-0+ +/* Add */ + ret =freq_qos_add_request (&qos, &req,FREQ_QOS_MIN ,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 );
similar here, this test validates re-adding, another dedicated test could verify once that the aggregate value is correct after adding a single request. Checking the return value still is sensible, just in case.
I guess it can be argued either way, checking the values every time is extra-safe, omitting the checks reduces clutter and might help to make it clearer what the test really intends to verify.
drivers/base/power/qos-test.c line 98
Quoted 6 lines
drivers/base/power/qos-test.c new file +6
-0+ +/* Remove */ + ret =freq_qos_remove_request (&req); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ), +FREQ_QOS_MIN_DEFAULT_VALUE );
ditto
drivers/base/power/qos-test.c line 103
Quoted 4 lines
drivers/base/power/qos-test.c new file +4
-0+/* Add again */ + ret =freq_qos_add_request (&qos, &req,FREQ_QOS_MIN ,2000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),2000 );
Here the explicit check makes sense, since we verify re-adding.
Anyway, my comments are just about possible improvements, it's also fine as is:
Quoted 87 lines · Leonard Crestez
Support 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_applybut does not export it for modules.Signed-off-by Leonard Crestez <[email protected]>--- drivers/base/power/qos.c | 73 ++++++++++++++++++++++++++++++++++++---- include/linux/pm_qos.h | 12 +++++++ kernel/power/qos.c | 4 ++- 3 files changed, 82 insertions(+), 7 deletions(-)drivers/base/power/qos.c +22
-2@@ -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,24 @@ 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 );
drivers/base/power/qos.c void dev_pm_qos_constraints_destroy(struct device *dev) · line 301
Quoted 10 lines
drivers/base/power/qos.c +10
-0+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)); + } +
nit: these loops look a bit redundant, might be worth to encapsulate them in a macro.
Quoted 174 lines
drivers/base/power/qos.c +35
-4f = &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 +342,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 +421,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 +550,18 @@ 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 +597,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 +0
-0@@ -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.
kernel/power/qos.c s32 freq_qos_read_value(struct freq_constraints *qos, · line 725
Quoted 10 lines
kernel/power/qos.c +3
-1+* +* 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) {
Re: [PATCH v4 1/4] PM / QoS: Initial kunit test
In reply to Matthias KaehlckeQuoted 162 lines · Matthias Kaehlcke
Quoted 111 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.Start by adding basic tests from the the
freq_qosAPIs. It includes tests for issues that were brought up on mailing lists:Signed-off-by Leonard Crestez <[email protected]>--- drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 117 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 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 +59
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 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)); + + 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 ); + + ret =freq_qos_remove_request (&req2); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 ); + + ret =freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 ); +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 );drivers/base/power/qos-test.c line 69
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-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 1000, new max 2000 */ + 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 );nit: this last part isn't really related with
MAX_DEFAULT_VALUE. It's a worthwhile test, but not necessarily in this test case. It might make more sense to set one of the constraints toFREQ_QOS_MAX_DEFAULT_VALUEagain, and verify it doesn't have an impact.Just a comment, there's nothing really wrong with how it is.
Quoted 8 lines
drivers/base/power/qos-test.c new file +8
-0+} + +/* +* Test that a freq_qos_request can be added again after removal +* +* This issue was solved by commit 05ff1ba412fd ("PM: QoS: Invalidate frequency +* QoS requests after removal") +*/ drivers/base/power/qos-test.c line 87
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-0+static void freq_qos_test_readd (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req; +int ret; + +freq_constraints_init (&qos); +memset (&req,0 ,sizeof (req)); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ), +FREQ_QOS_MIN_DEFAULT_VALUE );nit: you could do this check once in a dedicated test and omit it in other tests to de-clutter
drivers/base/power/qos-test.c line 92
Quoted 5 lines
drivers/base/power/qos-test.c new file +5
-0+ +/* Add */ + ret =freq_qos_add_request (&qos, &req,FREQ_QOS_MIN ,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 );similar here, this test validates re-adding, another dedicated test could verify once that the aggregate value is correct after adding a single request. Checking the return value still is sensible, just in case.
Quoted 3 lines
I guess it can be argued either way, checking the values every time is extra-safe, omitting the checks reduces clutter and might help to make it clearer what the test really intends to verify.
The complaint of "too many assertions" is odd for an unit test; I just wrote enough code to validate corectness without relying on a pile of external shell scripts and DTS hacks.
If we had more tests then the constant checking of every single return value might get tedious, but right now there are only 3 and their logic is reasonably easy to follow.
Quoted 4 lines
Anyway, my comments are just about possible improvements, it's also fine as is:
Reviewed-by Matthias Kaehlcke <[email protected]>
Quoted 93 lines · Matthias Kaehlcke
Quoted 92 lines · Leonard Crestez
Support 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_applybut does not export it for modules.Signed-off-by Leonard Crestez <[email protected]>--- drivers/base/power/qos.c | 73 ++++++++++++++++++++++++++++++++++++---- include/linux/pm_qos.h | 12 +++++++ kernel/power/qos.c | 4 ++- 3 files changed, 82 insertions(+), 7 deletions(-)drivers/base/power/qos.c +27
-2@@ -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,24 @@ 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) {
Quoted 8 lines
drivers/base/power/qos.c void dev_pm_qos_constraints_destroy(struct device *dev) · line 301
Quoted 5 lines
drivers/base/power/qos.c +5
-0+apply_constraint (req,PM_QOS_REMOVE_REQ , +PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE ); +memset (req,0 ,sizeof (*req)); + } +nit: these loops look a bit redundant, might be worth to encapsulate them in a macro.
There are only 2 identical loops though? Other requests to be cleared are enumerated in slightly different ways.
A pm_qos_for_each_request macro could be added but it would only be used in a handful of places.
Quoted 183 lines
Quoted 183 lines
drivers/base/power/qos.c +35
-4f = &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 +342,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 +421,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 +550,18 @@ 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 +597,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;
Quoted 4 lines
kernel/power/qos.c s32 freq_qos_read_value(struct freq_constraints *qos, · line 725
Quoted 1 line
kernel/power/qos.c +0
-0switch (req->type) {Reviewed-by Matthias Kaehlcke <[email protected]>Tested-by Matthias Kaehlcke <[email protected]>
Thanks for taking the time to look into this.
Quoted 69 lines · CET Leonard Crestez
Support for frequency limits in
dev_pm_qoswas removed when cpufreq was switched tofreq_qos, this series attempts to restore it by reimplementing on top offreq_qos.Discussion about removal is here:
https://lore.kernel.org/linux-pm/VI1PR04MB7023DF47D046AEADB4E051EBEE680@VI1PR04MB7023.eurprd04.prod.outlook.com/T/#uThe cpufreq core switched away because it needs contraints at the level of a "
cpufreq_policy" which cover multiple cpus sodev_pm_qoscoupling to struct device was not useful. Cpufreq could only usedev_pm_qosby implementing an additional layer of aggregation anyway.However in the devfreq subsystem scaling is always performed on a per-device basis so
dev_pm_qosis a very good match. Support fordev_pm_qosin devfreq core is here (latest version, no dependencies outside this series):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_qosfunctionality.In theory if
freq_qosis extended to handle conflicting min/max values then this sharing would be valuable. Right nowfreq_qosjust ties two unrelatedpm_qosaggregations for min and max freq.---
This is implemented by embeding afreq_qos_requestinsidedev_pm_qos_request:
the data field was already an union in order to deal with flag requests.The internal
freq_qos_applyis exported so that it can be called fromdev_pm_qosapply_constraints.The
dev_pm_qos_constraints_destroyfunction has no obvious equivalent infreq_qosand the whole approach of "removing requests" is somewhat dubios:
request objects should be owned by consumers and the list of qos requests will most likely be empty when the target device is deleted. Series follows current pattern fordev_pm_qos.First two patches can be applied separately.
Changes since v3:
* Fix s/QOS/QoS in patch 2 title
* Improves comments in kunit test
* Fix assertions afterfreq_qos_remove_request
* Remove (c) from NXP copyright header
* Wrap long lines inqos.cto be under 80 chars. This fixes checkpatch but the rule is already broken by code in the files.
* Collect reviews
Link to v3: https://patchwork.kernel.org/cover/11260627/Changes since v2:
* #definePM_QOS_MAX_FREQUENCY_DEFAULT_VALUEFREQ_QOS_MAX_DEFAULT_VALUE
* #defineFREQ_QOS_MAX_DEFAULT_VALUES32_MAX(in new patch)
* Add initial kunit test forfreq_qos, validating theMAX_DEFAULT_VALUEfound by Matthias and another recent fix. Testing this should be easier! Link to v2: https://patchwork.kernel.org/cover/11250413/Changes since v1:
* Don't rename orEXPORT_SYMBOL_GPLthefreq_qos_applyfunction; just drop the static marker.
Link to v1: https://patchwork.kernel.org/cover/11212887/Leonard Crestez (4):
PM / QoS: Initial kunit test
PM / QoS: RedefineFREQ_QOS_MAX_DEFAULT_VALUEtoS32_MAXPM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY
Quoted 10 lines
drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 117 ++++++++++++++++++++++++++++++++++ drivers/base/power/qos.c | 73 +++++++++++++++++++-- include/linux/pm_qos.h | 86 ++++++++++++++----------- kernel/power/qos.c | 4 +- 6 files changed, 242 insertions(+), 43 deletions(-) create mode 100644 drivers/base/power/qos-test.c
I have applied the whole series as 5.5 material, but I have reordered the fix (patch [2/4]) before the rest of it and marked it for -stable.
Thanks!
Quoted 81 lines · Rafael J. Wysocki
Quoted 69 lines · CET Leonard Crestez
Support for frequency limits in
dev_pm_qoswas removed when cpufreq was switched tofreq_qos, this series attempts to restore it by reimplementing on top offreq_qos.The cpufreq core switched away because it needs contraints at the level of a "
cpufreq_policy" which cover multiple cpus sodev_pm_qoscoupling to struct device was not useful. Cpufreq could only usedev_pm_qosby implementing an additional layer of aggregation anyway.However in the devfreq subsystem scaling is always performed on a per-device basis so
dev_pm_qosis a very good match. Support fordev_pm_qosin devfreq core is here (latest version, no dependencies outside this series):https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11252409%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=YodRx0IRVsjQXYA5X7UEosn%2FatO%2BWREfotwWrley2DQ%3D&reserved=0That 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_qosfunctionality.In theory if
freq_qosis extended to handle conflicting min/max values then this sharing would be valuable. Right nowfreq_qosjust ties two unrelatedpm_qosaggregations for min and max freq.---
This is implemented by embeding afreq_qos_requestinsidedev_pm_qos_request:
the data field was already an union in order to deal with flag requests.The internal
freq_qos_applyis exported so that it can be called fromdev_pm_qosapply_constraints.The
dev_pm_qos_constraints_destroyfunction has no obvious equivalent infreq_qosand the whole approach of "removing requests" is somewhat dubios:
request objects should be owned by consumers and the list of qos requests will most likely be empty when the target device is deleted. Series follows current pattern fordev_pm_qos.First two patches can be applied separately.
Changes since v3:
* Fix s/QOS/QoS in patch 2 title
* Improves comments in kunit test
* Fix assertions afterfreq_qos_remove_request
* Remove (c) from NXP copyright header
* Wrap long lines inqos.cto be under 80 chars. This fixes checkpatch but the
rule is already broken by code in the files.
* Collect reviews
Link to v3: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11260627%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=e%2B5SGU%2Bx4UjxlY292ejMO1kDewc3MmFvCpf0SDB0K4U%3D&reserved=0Changes since v2:
* #definePM_QOS_MAX_FREQUENCY_DEFAULT_VALUEFREQ_QOS_MAX_DEFAULT_VALUE
* #defineFREQ_QOS_MAX_DEFAULT_VALUES32_MAX(in new patch)
* Add initial kunit test forfreq_qos, validating theMAX_DEFAULT_VALUEfound
by Matthias and another recent fix. Testing this should be easier!
Link to v2: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11250413%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=vyz%2FN2x7OZPCSx4Md8yQkOSjPtfNUvW6%2FHtG0bTG1xU%3D&reserved=0Changes since v1:
* Don't rename orEXPORT_SYMBOL_GPLthefreq_qos_applyfunction; just
drop the static marker.
Link to v1: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11212887%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=SjcSQmMRZu0z3ATWygBpD8mRToCZT%2FBgQ7U3IRpMUB0%3D&reserved=0Leonard Crestez (4):
PM / QoS: Initial kunit test
PM / QoS: RedefineFREQ_QOS_MAX_DEFAULT_VALUEtoS32_MAXPM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCYQuoted 10 lines
drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 117 ++++++++++++++++++++++++++++++++++ drivers/base/power/qos.c | 73 +++++++++++++++++++-- include/linux/pm_qos.h | 86 ++++++++++++++----------- kernel/power/qos.c | 4 +- 6 files changed, 242 insertions(+), 43 deletions(-)create mode 100644
drivers/base/power/qos-test.c
Quoted 2 lines
I have applied the whole series as 5.5 material, but I have reordered the fix (patch [2/4]) before the rest of it and marked it for -stable.
Thanks!
Devfreq maintainers, do you think the devfreq parts could be queued for 5.5 as well? I'm not sure about the mechanics involved in this since devfreq qos depends at build time on this dev_pm_qos series.
Latest version is here: https://patchwork.kernel.org/cover/11252415/
It's RFC because it didn't compile against unpatched linux-next but it's otherwise a reduced version of a series that went through review and testing.
--
Regards,
Leonard
Quoted 85 lines · Leonard Crestez
Quoted 81 lines · Rafael J. Wysocki
Quoted 69 lines · CET Leonard Crestez
Support for frequency limits in
dev_pm_qoswas removed when cpufreq was switched tofreq_qos, this series attempts to restore it by reimplementing on top offreq_qos.The cpufreq core switched away because it needs contraints at the level of a "
cpufreq_policy" which cover multiple cpus sodev_pm_qoscoupling to struct device was not useful. Cpufreq could only usedev_pm_qosby implementing an additional layer of aggregation anyway.However in the devfreq subsystem scaling is always performed on a per-device basis so
dev_pm_qosis a very good match. Support fordev_pm_qosin devfreq core is here (latest version, no dependencies outside this series):https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11252409%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=YodRx0IRVsjQXYA5X7UEosn%2FatO%2BWREfotwWrley2DQ%3D&reserved=0That 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_qosfunctionality.In theory if
freq_qosis extended to handle conflicting min/max values then this sharing would be valuable. Right nowfreq_qosjust ties two unrelatedpm_qosaggregations for min and max freq.---
This is implemented by embeding afreq_qos_requestinsidedev_pm_qos_request:
the data field was already an union in order to deal with flag requests.The internal
freq_qos_applyis exported so that it can be called fromdev_pm_qosapply_constraints.The
dev_pm_qos_constraints_destroyfunction has no obvious equivalent infreq_qosand the whole approach of "removing requests" is somewhat dubios:
request objects should be owned by consumers and the list of qos requests will most likely be empty when the target device is deleted. Series follows current pattern fordev_pm_qos.First two patches can be applied separately.
Changes since v3:
* Fix s/QOS/QoS in patch 2 title
* Improves comments in kunit test
* Fix assertions afterfreq_qos_remove_request
* Remove (c) from NXP copyright header
* Wrap long lines inqos.cto be under 80 chars. This fixes checkpatch but the
rule is already broken by code in the files.
* Collect reviews
Link to v3: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11260627%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=e%2B5SGU%2Bx4UjxlY292ejMO1kDewc3MmFvCpf0SDB0K4U%3D&reserved=0Changes since v2:
* #definePM_QOS_MAX_FREQUENCY_DEFAULT_VALUEFREQ_QOS_MAX_DEFAULT_VALUE
* #defineFREQ_QOS_MAX_DEFAULT_VALUES32_MAX(in new patch)
* Add initial kunit test forfreq_qos, validating theMAX_DEFAULT_VALUEfound
by Matthias and another recent fix. Testing this should be easier!
Link to v2: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11250413%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=vyz%2FN2x7OZPCSx4Md8yQkOSjPtfNUvW6%2FHtG0bTG1xU%3D&reserved=0Changes since v1:
* Don't rename orEXPORT_SYMBOL_GPLthefreq_qos_applyfunction; just
drop the static marker.
Link to v1: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.kernel.org%2Fcover%2F11212887%2F&data=02%7C01%7Cleonard.crestez%40nxp.com%7C4531c54354d54442d71808d774c02866%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637106240968746397&sdata=SjcSQmMRZu0z3ATWygBpD8mRToCZT%2FBgQ7U3IRpMUB0%3D&reserved=0Leonard Crestez (4):
PM / QoS: Initial kunit test
PM / QoS: RedefineFREQ_QOS_MAX_DEFAULT_VALUEtoS32_MAXPM / QoS: Reorder pm_qos/freq_qos/dev_pm_qos structs PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCYQuoted 10 lines
drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 117 ++++++++++++++++++++++++++++++++++ drivers/base/power/qos.c | 73 +++++++++++++++++++-- include/linux/pm_qos.h | 86 ++++++++++++++----------- kernel/power/qos.c | 4 +- 6 files changed, 242 insertions(+), 43 deletions(-)create mode 100644
drivers/base/power/qos-test.cQuoted 2 lines
I have applied the whole series as 5.5 material, but I have reordered the fix (patch [2/4]) before the rest of it and marked it for -stable.
Quoted 7 lines
Thanks!
Devfreq maintainers, do you think the devfreq parts could be queued for 5.5 as well? I'm not sure about the mechanics involved in this since devfreq qos depends at build time on this
dev_pm_qosseries.Latest version is here: https://patchwork.kernel.org/cover/11252415/
Hi Leonard,
I agree devfreq's pm-qos patch.
[1] https://patchwork.kernel.org/cover/11252415/
But, I think need to discuss about this series[2]. Acutally, I don't want to split out the device_register. [2]https://patchwork.kernel.org/cover/11242865/
Quoted 10 lines
It's RFC because it didn't compile against unpatched linux-next but it's otherwise a reduced version of a series that went through review and testing.
--
Regards,
Leonard
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v4 1/4] PM / QoS: Initial kunit test
In reply to Leonard CrestezQuoted 10 lines · Leonard Crestez
Quoted 8 lines · Matthias Kaehlcke
Quoted 7 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.Start by adding basic tests from the the
freq_qosAPIs. It includes tests for issues that were brought up on mailing lists:Signed-off-by Leonard Crestez <[email protected]>
Quoted 154 lines
Quoted 154 lines
Quoted 104 lines
--- drivers/base/Kconfig | 4 ++ drivers/base/power/Makefile | 1 + drivers/base/power/qos-test.c | 117 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 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 +59
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 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)); + + 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 ); + + ret =freq_qos_remove_request (&req2); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 ); + + ret =freq_qos_remove_request (&req1); +KUNIT_EXPECT_EQ (test, ret,1 ); +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 );drivers/base/power/qos-test.c line 69
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-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 1000, new max 2000 */ + 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 );nit: this last part isn't really related with
MAX_DEFAULT_VALUE. It's a worthwhile test, but not necessarily in this test case. It might make more sense to set one of the constraints toFREQ_QOS_MAX_DEFAULT_VALUEagain, and verify it doesn't have an impact.Just a comment, there's nothing really wrong with how it is.
Quoted 8 lines
drivers/base/power/qos-test.c new file +8
-0+} + +/* +* Test that a freq_qos_request can be added again after removal +* +* This issue was solved by commit 05ff1ba412fd ("PM: QoS: Invalidate frequency +* QoS requests after removal") +*/ drivers/base/power/qos-test.c line 87
Quoted 10 lines
drivers/base/power/qos-test.c new file +10
-0+static void freq_qos_test_readd (struct kunit *test) +{ +struct freq_constraints qos; +struct freq_qos_request req; +int ret; + +freq_constraints_init (&qos); +memset (&req,0 ,sizeof (req)); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ), +FREQ_QOS_MIN_DEFAULT_VALUE );nit: you could do this check once in a dedicated test and omit it in other tests to de-clutter
drivers/base/power/qos-test.c line 92
Quoted 5 lines
drivers/base/power/qos-test.c new file +5
-0+ +/* Add */ + ret =freq_qos_add_request (&qos, &req,FREQ_QOS_MIN ,1000 ); +KUNIT_EXPECT_EQ (test, ret,1 ); +KUNIT_EXPECT_EQ (test,freq_qos_read_value (&qos,FREQ_QOS_MIN ),1000 );similar here, this test validates re-adding, another dedicated test could verify once that the aggregate value is correct after adding a single request. Checking the return value still is sensible, just in case.
Quoted 7 lines
Quoted 3 lines
I guess it can be argued either way, checking the values every time is extra-safe, omitting the checks reduces clutter and might help to make it clearer what the test really intends to verify.
The complaint of "too many assertions" is odd for an unit test; I just wrote enough code to validate corectness without relying on a pile of external shell scripts and DTS hacks.
I think Matthias was just trying to say that it might be a little cleaner if each test case only had expectations corresponding to the particular property that the test case is asserting, which I agree with.
I created the KUNIT_ASSERT_* variants just for this case; the idea is that you ASSERT the preconditions for the test case and you EXPECT the result you want. Hopefully this should make it immediately obvious when examining a test case what assertions/expectations correspond to the properties that the test is trying to prove and which are prerequisite.
Quoted 3 lines
If we had more tests then the constant checking of every single return value might get tedious, but right now there are only 3 and their logic is reasonably easy to follow.
I didn't have any trouble following your test. I agree with Matthias that these are potential minor improvements, but I also think it is fine as is.
Quoted 4 lines
Quoted 4 lines
Anyway, my comments are just about possible improvements, it's also fine as is:
Reviewed-by Matthias Kaehlcke <[email protected]>
Cheers!