diff mbox series

[V2,04/10] cpufreq: powerpc_cbe: Switch to QoS requests instead of cpufreq notifier

Message ID 524de8ace0596e68a24b57b3b4043c707db32ca7.1563862014.git.viresh.kumar@linaro.org
State Accepted
Commit afe969074eb7d0f52761ed80da15e9a282d19677
Headers show
Series None | expand

Commit Message

Viresh Kumar July 23, 2019, 6:14 a.m. UTC
The cpufreq core now takes the min/max frequency constraints via QoS
requests and the CPUFREQ_ADJUST notifier shall get removed later on.

Switch over to using the QoS request for maximum frequency constraint
for ppc_cbe_cpufreq driver.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

---
 drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-
 drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++
 drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------
 3 files changed, 86 insertions(+), 37 deletions(-)

-- 
2.21.0.rc0.269.g1a574e7a288b

Comments

Viresh Kumar Aug. 9, 2019, 2:34 a.m. UTC | #1
On 23-07-19, 11:44, Viresh Kumar wrote:
> The cpufreq core now takes the min/max frequency constraints via QoS

> requests and the CPUFREQ_ADJUST notifier shall get removed later on.

> 

> Switch over to using the QoS request for maximum frequency constraint

> for ppc_cbe_cpufreq driver.

> 

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

>  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

>  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

>  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

>  3 files changed, 86 insertions(+), 37 deletions(-)


-------------------------8<-------------------------
From b84e1c119d63ab842c9e4f3acbc3aec22efa866d Mon Sep 17 00:00:00 2001
Message-Id: <b84e1c119d63ab842c9e4f3acbc3aec22efa866d.1565318034.git.viresh.kumar@linaro.org>
From: Viresh Kumar <viresh.kumar@linaro.org>

Date: Fri, 5 Jul 2019 15:49:48 +0530
Subject: [PATCH] cpufreq: powerpc_cbe: Switch to QoS requests instead of
 cpufreq notifier

The cpufreq core now takes the min/max frequency constraints via QoS
requests and the CPUFREQ_ADJUST notifier shall get removed later on.

Switch over to using the QoS request for maximum frequency constraint
for ppc_cbe_cpufreq driver.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

---
- dev_pm_qos_update_request() can return 1 on success
 drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-
 drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++
 drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------
 3 files changed, 86 insertions(+), 37 deletions(-)

diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index b83f36febf03..c58abb4cca3a 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -110,6 +110,13 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
 #endif
 
 	policy->freq_table = cbe_freqs;
+	cbe_cpufreq_pmi_policy_init(policy);
+	return 0;
+}
+
+static int cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy)
+{
+	cbe_cpufreq_pmi_policy_exit(policy);
 	return 0;
 }
 
@@ -129,6 +136,7 @@ static struct cpufreq_driver cbe_cpufreq_driver = {
 	.verify		= cpufreq_generic_frequency_table_verify,
 	.target_index	= cbe_cpufreq_target,
 	.init		= cbe_cpufreq_cpu_init,
+	.exit		= cbe_cpufreq_cpu_exit,
 	.name		= "cbe-cpufreq",
 	.flags		= CPUFREQ_CONST_LOOPS,
 };
@@ -139,15 +147,24 @@ static struct cpufreq_driver cbe_cpufreq_driver = {
 
 static int __init cbe_cpufreq_init(void)
 {
+	int ret;
+
 	if (!machine_is(cell))
 		return -ENODEV;
 
-	return cpufreq_register_driver(&cbe_cpufreq_driver);
+	cbe_cpufreq_pmi_init();
+
+	ret = cpufreq_register_driver(&cbe_cpufreq_driver);
+	if (ret)
+		cbe_cpufreq_pmi_exit();
+
+	return ret;
 }
 
 static void __exit cbe_cpufreq_exit(void)
 {
 	cpufreq_unregister_driver(&cbe_cpufreq_driver);
+	cbe_cpufreq_pmi_exit();
 }
 
 module_init(cbe_cpufreq_init);
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.h b/drivers/cpufreq/ppc_cbe_cpufreq.h
index 9d973519d669..00cd8633b0d9 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.h
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.h
@@ -20,6 +20,14 @@ int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode);
 
 #if IS_ENABLED(CONFIG_CPU_FREQ_CBE_PMI)
 extern bool cbe_cpufreq_has_pmi;
+void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy);
+void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy);
+void cbe_cpufreq_pmi_init(void);
+void cbe_cpufreq_pmi_exit(void);
 #else
 #define cbe_cpufreq_has_pmi (0)
+static inline void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy) {}
+static inline void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy) {}
+static inline void cbe_cpufreq_pmi_init(void) {}
+static inline void cbe_cpufreq_pmi_exit(void) {}
 #endif
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c
index 97c8ee4614b7..bc9dd30395c4 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c
@@ -12,6 +12,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/of_platform.h>
+#include <linux/pm_qos.h>
 
 #include <asm/processor.h>
 #include <asm/prom.h>
@@ -24,8 +25,6 @@
 
 #include "ppc_cbe_cpufreq.h"
 
-static u8 pmi_slow_mode_limit[MAX_CBE];
-
 bool cbe_cpufreq_has_pmi = false;
 EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);
 
@@ -65,64 +64,89 @@ EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);
 
 static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)
 {
+	struct cpufreq_policy *policy;
+	struct dev_pm_qos_request *req;
 	u8 node, slow_mode;
+	int cpu, ret;
 
 	BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);
 
 	node = pmi_msg.data1;
 	slow_mode = pmi_msg.data2;
 
-	pmi_slow_mode_limit[node] = slow_mode;
+	cpu = cbe_node_to_cpu(node);
 
 	pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);
-}
-
-static int pmi_notifier(struct notifier_block *nb,
-				       unsigned long event, void *data)
-{
-	struct cpufreq_policy *policy = data;
-	struct cpufreq_frequency_table *cbe_freqs = policy->freq_table;
-	u8 node;
-
-	/* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY
-	 * policy events?)
-	 */
-	node = cbe_cpu_to_node(policy->cpu);
-
-	pr_debug("got notified, event=%lu, node=%u\n", event, node);
 
-	if (pmi_slow_mode_limit[node] != 0) {
-		pr_debug("limiting node %d to slow mode %d\n",
-			 node, pmi_slow_mode_limit[node]);
+	policy = cpufreq_cpu_get(cpu);
+	if (!policy) {
+		pr_warn("cpufreq policy not found cpu%d\n", cpu);
+		return;
+	}
 
-		cpufreq_verify_within_limits(policy, 0,
+	req = policy->driver_data;
 
-			cbe_freqs[pmi_slow_mode_limit[node]].frequency);
-	}
+	ret = dev_pm_qos_update_request(req,
+			policy->freq_table[slow_mode].frequency);
+	if (ret < 0)
+		pr_warn("Failed to update freq constraint: %d\n", ret);
+	else
+		pr_debug("limiting node %d to slow mode %d\n", node, slow_mode);
 
-	return 0;
+	cpufreq_cpu_put(policy);
 }
 
-static struct notifier_block pmi_notifier_block = {
-	.notifier_call = pmi_notifier,
-};
-
 static struct pmi_handler cbe_pmi_handler = {
 	.type			= PMI_TYPE_FREQ_CHANGE,
 	.handle_pmi_message	= cbe_cpufreq_handle_pmi,
 };
 
+void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy)
+{
+	struct dev_pm_qos_request *req;
+	int ret;
+
+	if (!cbe_cpufreq_has_pmi)
+		return;
+
+	req = kzalloc(sizeof(*req), GFP_KERNEL);
+	if (!req)
+		return;
+
+	ret = dev_pm_qos_add_request(get_cpu_device(policy->cpu), req,
+				     DEV_PM_QOS_MAX_FREQUENCY,
+				     policy->freq_table[0].frequency);
+	if (ret < 0) {
+		pr_err("Failed to add freq constraint (%d)\n", ret);
+		kfree(req);
+		return;
+	}
 
+	policy->driver_data = req;
+}
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_init);
 
-static int __init cbe_cpufreq_pmi_init(void)
+void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy)
 {
-	cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0;
+	struct dev_pm_qos_request *req = policy->driver_data;
 
-	if (!cbe_cpufreq_has_pmi)
-		return -ENODEV;
+	if (cbe_cpufreq_has_pmi) {
+		dev_pm_qos_remove_request(req);
+		kfree(req);
+	}
+}
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_exit);
 
-	cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
+void cbe_cpufreq_pmi_init(void)
+{
+	if (!pmi_register_handler(&cbe_pmi_handler))
+		cbe_cpufreq_has_pmi = true;
+}
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_init);
 
-	return 0;
+void cbe_cpufreq_pmi_exit(void)
+{
+	pmi_unregister_handler(&cbe_pmi_handler);
+	cbe_cpufreq_has_pmi = false;
 }
-device_initcall(cbe_cpufreq_pmi_init);
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_exit);
Rafael J. Wysocki Aug. 9, 2019, 9:01 a.m. UTC | #2
On Fri, Aug 9, 2019 at 4:34 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>

> On 23-07-19, 11:44, Viresh Kumar wrote:

> > The cpufreq core now takes the min/max frequency constraints via QoS

> > requests and the CPUFREQ_ADJUST notifier shall get removed later on.

> >

> > Switch over to using the QoS request for maximum frequency constraint

> > for ppc_cbe_cpufreq driver.

> >

> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > ---

> >  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

> >  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

> >  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

> >  3 files changed, 86 insertions(+), 37 deletions(-)

>

> -------------------------8<-------------------------


If you do it this way, Patchwork will not pick up the patch.

Please send afresh with "[Update]" or bumped up version number in the
subject (or both).

> From b84e1c119d63ab842c9e4f3acbc3aec22efa866d Mon Sep 17 00:00:00 2001

> Message-Id: <b84e1c119d63ab842c9e4f3acbc3aec22efa866d.1565318034.git.viresh.kumar@linaro.org>

> From: Viresh Kumar <viresh.kumar@linaro.org>

> Date: Fri, 5 Jul 2019 15:49:48 +0530

> Subject: [PATCH] cpufreq: powerpc_cbe: Switch to QoS requests instead of

>  cpufreq notifier

>

> The cpufreq core now takes the min/max frequency constraints via QoS

> requests and the CPUFREQ_ADJUST notifier shall get removed later on.

>

> Switch over to using the QoS request for maximum frequency constraint

> for ppc_cbe_cpufreq driver.

>

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>


And here you can say that it replaces an earlier patch.

> ---

> - dev_pm_qos_update_request() can return 1 on success

>  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

>  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

>  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

>  3 files changed, 86 insertions(+), 37 deletions(-)

>

> diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c

> index b83f36febf03..c58abb4cca3a 100644

> --- a/drivers/cpufreq/ppc_cbe_cpufreq.c

> +++ b/drivers/cpufreq/ppc_cbe_cpufreq.c

> @@ -110,6 +110,13 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)

>  #endif

>

>         policy->freq_table = cbe_freqs;

> +       cbe_cpufreq_pmi_policy_init(policy);

> +       return 0;

> +}

> +

> +static int cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy)

> +{

> +       cbe_cpufreq_pmi_policy_exit(policy);

>         return 0;

>  }

>

> @@ -129,6 +136,7 @@ static struct cpufreq_driver cbe_cpufreq_driver = {

>         .verify         = cpufreq_generic_frequency_table_verify,

>         .target_index   = cbe_cpufreq_target,

>         .init           = cbe_cpufreq_cpu_init,

> +       .exit           = cbe_cpufreq_cpu_exit,

>         .name           = "cbe-cpufreq",

>         .flags          = CPUFREQ_CONST_LOOPS,

>  };

> @@ -139,15 +147,24 @@ static struct cpufreq_driver cbe_cpufreq_driver = {

>

>  static int __init cbe_cpufreq_init(void)

>  {

> +       int ret;

> +

>         if (!machine_is(cell))

>                 return -ENODEV;

>

> -       return cpufreq_register_driver(&cbe_cpufreq_driver);

> +       cbe_cpufreq_pmi_init();

> +

> +       ret = cpufreq_register_driver(&cbe_cpufreq_driver);

> +       if (ret)

> +               cbe_cpufreq_pmi_exit();

> +

> +       return ret;

>  }

>

>  static void __exit cbe_cpufreq_exit(void)

>  {

>         cpufreq_unregister_driver(&cbe_cpufreq_driver);

> +       cbe_cpufreq_pmi_exit();

>  }

>

>  module_init(cbe_cpufreq_init);

> diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.h b/drivers/cpufreq/ppc_cbe_cpufreq.h

> index 9d973519d669..00cd8633b0d9 100644

> --- a/drivers/cpufreq/ppc_cbe_cpufreq.h

> +++ b/drivers/cpufreq/ppc_cbe_cpufreq.h

> @@ -20,6 +20,14 @@ int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode);

>

>  #if IS_ENABLED(CONFIG_CPU_FREQ_CBE_PMI)

>  extern bool cbe_cpufreq_has_pmi;

> +void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy);

> +void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy);

> +void cbe_cpufreq_pmi_init(void);

> +void cbe_cpufreq_pmi_exit(void);

>  #else

>  #define cbe_cpufreq_has_pmi (0)

> +static inline void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy) {}

> +static inline void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy) {}

> +static inline void cbe_cpufreq_pmi_init(void) {}

> +static inline void cbe_cpufreq_pmi_exit(void) {}

>  #endif

> diff --git a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c

> index 97c8ee4614b7..bc9dd30395c4 100644

> --- a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c

> +++ b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c

> @@ -12,6 +12,7 @@

>  #include <linux/timer.h>

>  #include <linux/init.h>

>  #include <linux/of_platform.h>

> +#include <linux/pm_qos.h>

>

>  #include <asm/processor.h>

>  #include <asm/prom.h>

> @@ -24,8 +25,6 @@

>

>  #include "ppc_cbe_cpufreq.h"

>

> -static u8 pmi_slow_mode_limit[MAX_CBE];

> -

>  bool cbe_cpufreq_has_pmi = false;

>  EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);

>

> @@ -65,64 +64,89 @@ EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);

>

>  static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)

>  {

> +       struct cpufreq_policy *policy;

> +       struct dev_pm_qos_request *req;

>         u8 node, slow_mode;

> +       int cpu, ret;

>

>         BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);

>

>         node = pmi_msg.data1;

>         slow_mode = pmi_msg.data2;

>

> -       pmi_slow_mode_limit[node] = slow_mode;

> +       cpu = cbe_node_to_cpu(node);

>

>         pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);

> -}

> -

> -static int pmi_notifier(struct notifier_block *nb,

> -                                      unsigned long event, void *data)

> -{

> -       struct cpufreq_policy *policy = data;

> -       struct cpufreq_frequency_table *cbe_freqs = policy->freq_table;

> -       u8 node;

> -

> -       /* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY

> -        * policy events?)

> -        */

> -       node = cbe_cpu_to_node(policy->cpu);

> -

> -       pr_debug("got notified, event=%lu, node=%u\n", event, node);

>

> -       if (pmi_slow_mode_limit[node] != 0) {

> -               pr_debug("limiting node %d to slow mode %d\n",

> -                        node, pmi_slow_mode_limit[node]);

> +       policy = cpufreq_cpu_get(cpu);

> +       if (!policy) {

> +               pr_warn("cpufreq policy not found cpu%d\n", cpu);

> +               return;

> +       }

>

> -               cpufreq_verify_within_limits(policy, 0,

> +       req = policy->driver_data;

>

> -                       cbe_freqs[pmi_slow_mode_limit[node]].frequency);

> -       }

> +       ret = dev_pm_qos_update_request(req,

> +                       policy->freq_table[slow_mode].frequency);

> +       if (ret < 0)

> +               pr_warn("Failed to update freq constraint: %d\n", ret);

> +       else

> +               pr_debug("limiting node %d to slow mode %d\n", node, slow_mode);

>

> -       return 0;

> +       cpufreq_cpu_put(policy);

>  }

>

> -static struct notifier_block pmi_notifier_block = {

> -       .notifier_call = pmi_notifier,

> -};

> -

>  static struct pmi_handler cbe_pmi_handler = {

>         .type                   = PMI_TYPE_FREQ_CHANGE,

>         .handle_pmi_message     = cbe_cpufreq_handle_pmi,

>  };

>

> +void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy)

> +{

> +       struct dev_pm_qos_request *req;

> +       int ret;

> +

> +       if (!cbe_cpufreq_has_pmi)

> +               return;

> +

> +       req = kzalloc(sizeof(*req), GFP_KERNEL);

> +       if (!req)

> +               return;

> +

> +       ret = dev_pm_qos_add_request(get_cpu_device(policy->cpu), req,

> +                                    DEV_PM_QOS_MAX_FREQUENCY,

> +                                    policy->freq_table[0].frequency);

> +       if (ret < 0) {

> +               pr_err("Failed to add freq constraint (%d)\n", ret);

> +               kfree(req);

> +               return;

> +       }

>

> +       policy->driver_data = req;

> +}

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_init);

>

> -static int __init cbe_cpufreq_pmi_init(void)

> +void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy)

>  {

> -       cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0;

> +       struct dev_pm_qos_request *req = policy->driver_data;

>

> -       if (!cbe_cpufreq_has_pmi)

> -               return -ENODEV;

> +       if (cbe_cpufreq_has_pmi) {

> +               dev_pm_qos_remove_request(req);

> +               kfree(req);

> +       }

> +}

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_exit);

>

> -       cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);

> +void cbe_cpufreq_pmi_init(void)

> +{

> +       if (!pmi_register_handler(&cbe_pmi_handler))

> +               cbe_cpufreq_has_pmi = true;

> +}

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_init);

>

> -       return 0;

> +void cbe_cpufreq_pmi_exit(void)

> +{

> +       pmi_unregister_handler(&cbe_pmi_handler);

> +       cbe_cpufreq_has_pmi = false;

>  }

> -device_initcall(cbe_cpufreq_pmi_init);

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_exit);
Rafael J. Wysocki Aug. 10, 2019, 12:19 p.m. UTC | #3
On Fri, Aug 9, 2019 at 4:34 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>

> On 23-07-19, 11:44, Viresh Kumar wrote:

> > The cpufreq core now takes the min/max frequency constraints via QoS

> > requests and the CPUFREQ_ADJUST notifier shall get removed later on.

> >

> > Switch over to using the QoS request for maximum frequency constraint

> > for ppc_cbe_cpufreq driver.

> >

> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > ---

> >  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

> >  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

> >  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

> >  3 files changed, 86 insertions(+), 37 deletions(-)


OK, picked up from email this time, but in the future please let
Patchwork pick up new versions of patches.

Thanks!

> -------------------------8<-------------------------

> From b84e1c119d63ab842c9e4f3acbc3aec22efa866d Mon Sep 17 00:00:00 2001

> Message-Id: <b84e1c119d63ab842c9e4f3acbc3aec22efa866d.1565318034.git.viresh.kumar@linaro.org>

> From: Viresh Kumar <viresh.kumar@linaro.org>

> Date: Fri, 5 Jul 2019 15:49:48 +0530

> Subject: [PATCH] cpufreq: powerpc_cbe: Switch to QoS requests instead of

>  cpufreq notifier

>

> The cpufreq core now takes the min/max frequency constraints via QoS

> requests and the CPUFREQ_ADJUST notifier shall get removed later on.

>

> Switch over to using the QoS request for maximum frequency constraint

> for ppc_cbe_cpufreq driver.

>

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

> - dev_pm_qos_update_request() can return 1 on success

>  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

>  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

>  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

>  3 files changed, 86 insertions(+), 37 deletions(-)

>

> diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c

> index b83f36febf03..c58abb4cca3a 100644

> --- a/drivers/cpufreq/ppc_cbe_cpufreq.c

> +++ b/drivers/cpufreq/ppc_cbe_cpufreq.c

> @@ -110,6 +110,13 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)

>  #endif

>

>         policy->freq_table = cbe_freqs;

> +       cbe_cpufreq_pmi_policy_init(policy);

> +       return 0;

> +}

> +

> +static int cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy)

> +{

> +       cbe_cpufreq_pmi_policy_exit(policy);

>         return 0;

>  }

>

> @@ -129,6 +136,7 @@ static struct cpufreq_driver cbe_cpufreq_driver = {

>         .verify         = cpufreq_generic_frequency_table_verify,

>         .target_index   = cbe_cpufreq_target,

>         .init           = cbe_cpufreq_cpu_init,

> +       .exit           = cbe_cpufreq_cpu_exit,

>         .name           = "cbe-cpufreq",

>         .flags          = CPUFREQ_CONST_LOOPS,

>  };

> @@ -139,15 +147,24 @@ static struct cpufreq_driver cbe_cpufreq_driver = {

>

>  static int __init cbe_cpufreq_init(void)

>  {

> +       int ret;

> +

>         if (!machine_is(cell))

>                 return -ENODEV;

>

> -       return cpufreq_register_driver(&cbe_cpufreq_driver);

> +       cbe_cpufreq_pmi_init();

> +

> +       ret = cpufreq_register_driver(&cbe_cpufreq_driver);

> +       if (ret)

> +               cbe_cpufreq_pmi_exit();

> +

> +       return ret;

>  }

>

>  static void __exit cbe_cpufreq_exit(void)

>  {

>         cpufreq_unregister_driver(&cbe_cpufreq_driver);

> +       cbe_cpufreq_pmi_exit();

>  }

>

>  module_init(cbe_cpufreq_init);

> diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.h b/drivers/cpufreq/ppc_cbe_cpufreq.h

> index 9d973519d669..00cd8633b0d9 100644

> --- a/drivers/cpufreq/ppc_cbe_cpufreq.h

> +++ b/drivers/cpufreq/ppc_cbe_cpufreq.h

> @@ -20,6 +20,14 @@ int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode);

>

>  #if IS_ENABLED(CONFIG_CPU_FREQ_CBE_PMI)

>  extern bool cbe_cpufreq_has_pmi;

> +void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy);

> +void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy);

> +void cbe_cpufreq_pmi_init(void);

> +void cbe_cpufreq_pmi_exit(void);

>  #else

>  #define cbe_cpufreq_has_pmi (0)

> +static inline void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy) {}

> +static inline void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy) {}

> +static inline void cbe_cpufreq_pmi_init(void) {}

> +static inline void cbe_cpufreq_pmi_exit(void) {}

>  #endif

> diff --git a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c

> index 97c8ee4614b7..bc9dd30395c4 100644

> --- a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c

> +++ b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c

> @@ -12,6 +12,7 @@

>  #include <linux/timer.h>

>  #include <linux/init.h>

>  #include <linux/of_platform.h>

> +#include <linux/pm_qos.h>

>

>  #include <asm/processor.h>

>  #include <asm/prom.h>

> @@ -24,8 +25,6 @@

>

>  #include "ppc_cbe_cpufreq.h"

>

> -static u8 pmi_slow_mode_limit[MAX_CBE];

> -

>  bool cbe_cpufreq_has_pmi = false;

>  EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);

>

> @@ -65,64 +64,89 @@ EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);

>

>  static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)

>  {

> +       struct cpufreq_policy *policy;

> +       struct dev_pm_qos_request *req;

>         u8 node, slow_mode;

> +       int cpu, ret;

>

>         BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);

>

>         node = pmi_msg.data1;

>         slow_mode = pmi_msg.data2;

>

> -       pmi_slow_mode_limit[node] = slow_mode;

> +       cpu = cbe_node_to_cpu(node);

>

>         pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);

> -}

> -

> -static int pmi_notifier(struct notifier_block *nb,

> -                                      unsigned long event, void *data)

> -{

> -       struct cpufreq_policy *policy = data;

> -       struct cpufreq_frequency_table *cbe_freqs = policy->freq_table;

> -       u8 node;

> -

> -       /* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY

> -        * policy events?)

> -        */

> -       node = cbe_cpu_to_node(policy->cpu);

> -

> -       pr_debug("got notified, event=%lu, node=%u\n", event, node);

>

> -       if (pmi_slow_mode_limit[node] != 0) {

> -               pr_debug("limiting node %d to slow mode %d\n",

> -                        node, pmi_slow_mode_limit[node]);

> +       policy = cpufreq_cpu_get(cpu);

> +       if (!policy) {

> +               pr_warn("cpufreq policy not found cpu%d\n", cpu);

> +               return;

> +       }

>

> -               cpufreq_verify_within_limits(policy, 0,

> +       req = policy->driver_data;

>

> -                       cbe_freqs[pmi_slow_mode_limit[node]].frequency);

> -       }

> +       ret = dev_pm_qos_update_request(req,

> +                       policy->freq_table[slow_mode].frequency);

> +       if (ret < 0)

> +               pr_warn("Failed to update freq constraint: %d\n", ret);

> +       else

> +               pr_debug("limiting node %d to slow mode %d\n", node, slow_mode);

>

> -       return 0;

> +       cpufreq_cpu_put(policy);

>  }

>

> -static struct notifier_block pmi_notifier_block = {

> -       .notifier_call = pmi_notifier,

> -};

> -

>  static struct pmi_handler cbe_pmi_handler = {

>         .type                   = PMI_TYPE_FREQ_CHANGE,

>         .handle_pmi_message     = cbe_cpufreq_handle_pmi,

>  };

>

> +void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy)

> +{

> +       struct dev_pm_qos_request *req;

> +       int ret;

> +

> +       if (!cbe_cpufreq_has_pmi)

> +               return;

> +

> +       req = kzalloc(sizeof(*req), GFP_KERNEL);

> +       if (!req)

> +               return;

> +

> +       ret = dev_pm_qos_add_request(get_cpu_device(policy->cpu), req,

> +                                    DEV_PM_QOS_MAX_FREQUENCY,

> +                                    policy->freq_table[0].frequency);

> +       if (ret < 0) {

> +               pr_err("Failed to add freq constraint (%d)\n", ret);

> +               kfree(req);

> +               return;

> +       }

>

> +       policy->driver_data = req;

> +}

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_init);

>

> -static int __init cbe_cpufreq_pmi_init(void)

> +void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy)

>  {

> -       cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0;

> +       struct dev_pm_qos_request *req = policy->driver_data;

>

> -       if (!cbe_cpufreq_has_pmi)

> -               return -ENODEV;

> +       if (cbe_cpufreq_has_pmi) {

> +               dev_pm_qos_remove_request(req);

> +               kfree(req);

> +       }

> +}

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_exit);

>

> -       cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);

> +void cbe_cpufreq_pmi_init(void)

> +{

> +       if (!pmi_register_handler(&cbe_pmi_handler))

> +               cbe_cpufreq_has_pmi = true;

> +}

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_init);

>

> -       return 0;

> +void cbe_cpufreq_pmi_exit(void)

> +{

> +       pmi_unregister_handler(&cbe_pmi_handler);

> +       cbe_cpufreq_has_pmi = false;

>  }

> -device_initcall(cbe_cpufreq_pmi_init);

> +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_exit);
Viresh Kumar Aug. 19, 2019, 2:26 a.m. UTC | #4
On 09-08-19, 11:01, Rafael J. Wysocki wrote:
> On Fri, Aug 9, 2019 at 4:34 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:

> >

> > On 23-07-19, 11:44, Viresh Kumar wrote:

> > > The cpufreq core now takes the min/max frequency constraints via QoS

> > > requests and the CPUFREQ_ADJUST notifier shall get removed later on.

> > >

> > > Switch over to using the QoS request for maximum frequency constraint

> > > for ppc_cbe_cpufreq driver.

> > >

> > > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > > ---

> > >  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

> > >  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

> > >  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

> > >  3 files changed, 86 insertions(+), 37 deletions(-)

> >

> > -------------------------8<-------------------------

> 

> If you do it this way, Patchwork will not pick up the patch.

> 

> Please send afresh with "[Update]" or bumped up version number in the

> subject (or both).


Okay, will take care of this in future. Was away on holidays and so
the late reply. Thanks.

-- 
viresh
Rafael J. Wysocki Aug. 19, 2019, 6:42 a.m. UTC | #5
On Mon, Aug 19, 2019 at 4:26 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>

> On 09-08-19, 11:01, Rafael J. Wysocki wrote:

> > On Fri, Aug 9, 2019 at 4:34 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:

> > >

> > > On 23-07-19, 11:44, Viresh Kumar wrote:

> > > > The cpufreq core now takes the min/max frequency constraints via QoS

> > > > requests and the CPUFREQ_ADJUST notifier shall get removed later on.

> > > >

> > > > Switch over to using the QoS request for maximum frequency constraint

> > > > for ppc_cbe_cpufreq driver.

> > > >

> > > > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > > > ---

> > > >  drivers/cpufreq/ppc_cbe_cpufreq.c     | 19 +++++-

> > > >  drivers/cpufreq/ppc_cbe_cpufreq.h     |  8 +++

> > > >  drivers/cpufreq/ppc_cbe_cpufreq_pmi.c | 96 +++++++++++++++++----------

> > > >  3 files changed, 86 insertions(+), 37 deletions(-)

> > >

> > > -------------------------8<-------------------------

> >

> > If you do it this way, Patchwork will not pick up the patch.

> >

> > Please send afresh with "[Update]" or bumped up version number in the

> > subject (or both).

>

> Okay, will take care of this in future. Was away on holidays and so

> the late reply. Thanks.


OK, thanks!

The series is on hold, though, because the acpi-cpufreq patch turned
out to be problematic and I didn't have the time to have a deeper look
at the problem last week.
Viresh Kumar Aug. 19, 2019, 6:47 a.m. UTC | #6
On 19-08-19, 08:42, Rafael J. Wysocki wrote:
> OK, thanks!

> 

> The series is on hold, though, because the acpi-cpufreq patch turned

> out to be problematic and I didn't have the time to have a deeper look

> at the problem last week.


And so was I wondering why it is present in bleeding-edge only :)

I don't think I am cc'd to any bug reports on that, can you please help me with
some information on it ?

-- 
viresh
diff mbox series

Patch

diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index b83f36febf03..c58abb4cca3a 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -110,6 +110,13 @@  static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
 #endif
 
 	policy->freq_table = cbe_freqs;
+	cbe_cpufreq_pmi_policy_init(policy);
+	return 0;
+}
+
+static int cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy)
+{
+	cbe_cpufreq_pmi_policy_exit(policy);
 	return 0;
 }
 
@@ -129,6 +136,7 @@  static struct cpufreq_driver cbe_cpufreq_driver = {
 	.verify		= cpufreq_generic_frequency_table_verify,
 	.target_index	= cbe_cpufreq_target,
 	.init		= cbe_cpufreq_cpu_init,
+	.exit		= cbe_cpufreq_cpu_exit,
 	.name		= "cbe-cpufreq",
 	.flags		= CPUFREQ_CONST_LOOPS,
 };
@@ -139,15 +147,24 @@  static struct cpufreq_driver cbe_cpufreq_driver = {
 
 static int __init cbe_cpufreq_init(void)
 {
+	int ret;
+
 	if (!machine_is(cell))
 		return -ENODEV;
 
-	return cpufreq_register_driver(&cbe_cpufreq_driver);
+	cbe_cpufreq_pmi_init();
+
+	ret = cpufreq_register_driver(&cbe_cpufreq_driver);
+	if (ret)
+		cbe_cpufreq_pmi_exit();
+
+	return ret;
 }
 
 static void __exit cbe_cpufreq_exit(void)
 {
 	cpufreq_unregister_driver(&cbe_cpufreq_driver);
+	cbe_cpufreq_pmi_exit();
 }
 
 module_init(cbe_cpufreq_init);
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.h b/drivers/cpufreq/ppc_cbe_cpufreq.h
index 9d973519d669..00cd8633b0d9 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.h
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.h
@@ -20,6 +20,14 @@  int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode);
 
 #if IS_ENABLED(CONFIG_CPU_FREQ_CBE_PMI)
 extern bool cbe_cpufreq_has_pmi;
+void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy);
+void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy);
+void cbe_cpufreq_pmi_init(void);
+void cbe_cpufreq_pmi_exit(void);
 #else
 #define cbe_cpufreq_has_pmi (0)
+static inline void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy) {}
+static inline void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy) {}
+static inline void cbe_cpufreq_pmi_init(void) {}
+static inline void cbe_cpufreq_pmi_exit(void) {}
 #endif
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c
index 97c8ee4614b7..0babb27c1c72 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq_pmi.c
@@ -12,6 +12,7 @@ 
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/of_platform.h>
+#include <linux/pm_qos.h>
 
 #include <asm/processor.h>
 #include <asm/prom.h>
@@ -24,8 +25,6 @@ 
 
 #include "ppc_cbe_cpufreq.h"
 
-static u8 pmi_slow_mode_limit[MAX_CBE];
-
 bool cbe_cpufreq_has_pmi = false;
 EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);
 
@@ -65,64 +64,89 @@  EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);
 
 static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)
 {
+	struct cpufreq_policy *policy;
+	struct dev_pm_qos_request *req;
 	u8 node, slow_mode;
+	int cpu, ret;
 
 	BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);
 
 	node = pmi_msg.data1;
 	slow_mode = pmi_msg.data2;
 
-	pmi_slow_mode_limit[node] = slow_mode;
+	cpu = cbe_node_to_cpu(node);
 
 	pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);
-}
-
-static int pmi_notifier(struct notifier_block *nb,
-				       unsigned long event, void *data)
-{
-	struct cpufreq_policy *policy = data;
-	struct cpufreq_frequency_table *cbe_freqs = policy->freq_table;
-	u8 node;
-
-	/* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY
-	 * policy events?)
-	 */
-	node = cbe_cpu_to_node(policy->cpu);
-
-	pr_debug("got notified, event=%lu, node=%u\n", event, node);
 
-	if (pmi_slow_mode_limit[node] != 0) {
-		pr_debug("limiting node %d to slow mode %d\n",
-			 node, pmi_slow_mode_limit[node]);
+	policy = cpufreq_cpu_get(cpu);
+	if (!policy) {
+		pr_warn("cpufreq policy not found cpu%d\n", cpu);
+		return;
+	}
 
-		cpufreq_verify_within_limits(policy, 0,
+	req = policy->driver_data;
 
-			cbe_freqs[pmi_slow_mode_limit[node]].frequency);
-	}
+	ret = dev_pm_qos_update_request(req,
+			policy->freq_table[slow_mode].frequency);
+	if (ret)
+		pr_warn("Failed to update freq constraint: %d\n", ret);
+	else
+		pr_debug("limiting node %d to slow mode %d\n", node, slow_mode);
 
-	return 0;
+	cpufreq_cpu_put(policy);
 }
 
-static struct notifier_block pmi_notifier_block = {
-	.notifier_call = pmi_notifier,
-};
-
 static struct pmi_handler cbe_pmi_handler = {
 	.type			= PMI_TYPE_FREQ_CHANGE,
 	.handle_pmi_message	= cbe_cpufreq_handle_pmi,
 };
 
+void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy)
+{
+	struct dev_pm_qos_request *req;
+	int ret;
+
+	if (!cbe_cpufreq_has_pmi)
+		return;
+
+	req = kzalloc(sizeof(*req), GFP_KERNEL);
+	if (!req)
+		return;
+
+	ret = dev_pm_qos_add_request(get_cpu_device(policy->cpu), req,
+				     DEV_PM_QOS_MAX_FREQUENCY,
+				     policy->freq_table[0].frequency);
+	if (ret < 0) {
+		pr_err("Failed to add freq constraint (%d)\n", ret);
+		kfree(req);
+		return;
+	}
 
+	policy->driver_data = req;
+}
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_init);
 
-static int __init cbe_cpufreq_pmi_init(void)
+void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy)
 {
-	cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0;
+	struct dev_pm_qos_request *req = policy->driver_data;
 
-	if (!cbe_cpufreq_has_pmi)
-		return -ENODEV;
+	if (cbe_cpufreq_has_pmi) {
+		dev_pm_qos_remove_request(req);
+		kfree(req);
+	}
+}
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_exit);
 
-	cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
+void cbe_cpufreq_pmi_init(void)
+{
+	if (!pmi_register_handler(&cbe_pmi_handler))
+		cbe_cpufreq_has_pmi = true;
+}
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_init);
 
-	return 0;
+void cbe_cpufreq_pmi_exit(void)
+{
+	pmi_unregister_handler(&cbe_pmi_handler);
+	cbe_cpufreq_has_pmi = false;
 }
-device_initcall(cbe_cpufreq_pmi_init);
+EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_exit);