All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/9] Add callback to register with energy model
@ 2021-08-12  4:35 ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Andy Gross, Bjorn Andersson, Cristian Marussi, Fabio Estevam,
	Kevin Hilman, Matthias Brugger, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Sudeep Holla,
	Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-mediatek, linux-omap

Many cpufreq drivers register with the energy model for each policy and
do exactly the same thing. Follow the footsteps of thermal-cooling, to
get it done from the cpufreq core itself.

Provide a new callback, which will be called, if present, by the cpufreq
core at the right moment (more on that in the code's comment). Also
provide a generic implementation that uses dev_pm_opp_of_register_em().

This also allows us to register with the EM at a later point of time,
compared to ->init(), from where the EM core can access cpufreq policy
directly using cpufreq_cpu_get() type of helpers and perform other work,
like marking few frequencies inefficient, this will be done separately.

This is build/boot tested by the bot for a couple of boards.

https://gitlab.com/vireshk/pmko/-/pipelines/351965580

FWIW, I have queued up the series for linux-next to get more testing, but your
reviews are welcome. Thanks.

V2->V3:
- Drop the auto-register part from all logs, this isn't called auto registration
  anymore.
- Call register_em() only for new policies.
- Update scmi driver to register with EM only when required.
- Add Rby tags.

V1->V2:
- Add a callback instead of flag.
- Register before governor is initialized.
- Update scmi driver as well.
- Don't unregister from the EM core.

--
Viresh

Viresh Kumar (9):
  cpufreq: Add callback to register with energy model
  cpufreq: dt: Use .register_em() to register with energy model
  cpufreq: imx6q: Use .register_em() to register with energy model
  cpufreq: mediatek: Use .register_em() to register with energy model
  cpufreq: omap: Use .register_em() to register with energy model
  cpufreq: qcom-cpufreq-hw: Use .register_em() to register with energy
    model
  cpufreq: scpi: Use .register_em() to register with energy model
  cpufreq: vexpress: Use .register_em() to register with energy model
  cpufreq: scmi: Use .register_em() to register with energy model

 drivers/cpufreq/cpufreq-dt.c           |  3 +-
 drivers/cpufreq/cpufreq.c              | 13 ++++++
 drivers/cpufreq/imx6q-cpufreq.c        |  2 +-
 drivers/cpufreq/mediatek-cpufreq.c     |  3 +-
 drivers/cpufreq/omap-cpufreq.c         |  2 +-
 drivers/cpufreq/qcom-cpufreq-hw.c      |  3 +-
 drivers/cpufreq/scmi-cpufreq.c         | 65 +++++++++++++++++---------
 drivers/cpufreq/scpi-cpufreq.c         |  3 +-
 drivers/cpufreq/vexpress-spc-cpufreq.c |  3 +-
 include/linux/cpufreq.h                | 14 ++++++
 10 files changed, 76 insertions(+), 35 deletions(-)

-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH V3 0/9] Add callback to register with energy model
@ 2021-08-12  4:35 ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Andy Gross, Bjorn Andersson, Cristian Marussi, Fabio Estevam,
	Kevin Hilman, Matthias Brugger, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Sudeep Holla,
	Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-mediatek, linux-omap

Many cpufreq drivers register with the energy model for each policy and
do exactly the same thing. Follow the footsteps of thermal-cooling, to
get it done from the cpufreq core itself.

Provide a new callback, which will be called, if present, by the cpufreq
core at the right moment (more on that in the code's comment). Also
provide a generic implementation that uses dev_pm_opp_of_register_em().

This also allows us to register with the EM at a later point of time,
compared to ->init(), from where the EM core can access cpufreq policy
directly using cpufreq_cpu_get() type of helpers and perform other work,
like marking few frequencies inefficient, this will be done separately.

This is build/boot tested by the bot for a couple of boards.

https://gitlab.com/vireshk/pmko/-/pipelines/351965580

FWIW, I have queued up the series for linux-next to get more testing, but your
reviews are welcome. Thanks.

V2->V3:
- Drop the auto-register part from all logs, this isn't called auto registration
  anymore.
- Call register_em() only for new policies.
- Update scmi driver to register with EM only when required.
- Add Rby tags.

V1->V2:
- Add a callback instead of flag.
- Register before governor is initialized.
- Update scmi driver as well.
- Don't unregister from the EM core.

--
Viresh

Viresh Kumar (9):
  cpufreq: Add callback to register with energy model
  cpufreq: dt: Use .register_em() to register with energy model
  cpufreq: imx6q: Use .register_em() to register with energy model
  cpufreq: mediatek: Use .register_em() to register with energy model
  cpufreq: omap: Use .register_em() to register with energy model
  cpufreq: qcom-cpufreq-hw: Use .register_em() to register with energy
    model
  cpufreq: scpi: Use .register_em() to register with energy model
  cpufreq: vexpress: Use .register_em() to register with energy model
  cpufreq: scmi: Use .register_em() to register with energy model

 drivers/cpufreq/cpufreq-dt.c           |  3 +-
 drivers/cpufreq/cpufreq.c              | 13 ++++++
 drivers/cpufreq/imx6q-cpufreq.c        |  2 +-
 drivers/cpufreq/mediatek-cpufreq.c     |  3 +-
 drivers/cpufreq/omap-cpufreq.c         |  2 +-
 drivers/cpufreq/qcom-cpufreq-hw.c      |  3 +-
 drivers/cpufreq/scmi-cpufreq.c         | 65 +++++++++++++++++---------
 drivers/cpufreq/scpi-cpufreq.c         |  3 +-
 drivers/cpufreq/vexpress-spc-cpufreq.c |  3 +-
 include/linux/cpufreq.h                | 14 ++++++
 10 files changed, 76 insertions(+), 35 deletions(-)

-- 
2.31.1.272.g89b43f80a514


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH V3 0/9] Add callback to register with energy model
@ 2021-08-12  4:35 ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Andy Gross, Bjorn Andersson, Cristian Marussi, Fabio Estevam,
	Kevin Hilman, Matthias Brugger, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Sudeep Holla,
	Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-mediatek, linux-omap

Many cpufreq drivers register with the energy model for each policy and
do exactly the same thing. Follow the footsteps of thermal-cooling, to
get it done from the cpufreq core itself.

Provide a new callback, which will be called, if present, by the cpufreq
core at the right moment (more on that in the code's comment). Also
provide a generic implementation that uses dev_pm_opp_of_register_em().

This also allows us to register with the EM at a later point of time,
compared to ->init(), from where the EM core can access cpufreq policy
directly using cpufreq_cpu_get() type of helpers and perform other work,
like marking few frequencies inefficient, this will be done separately.

This is build/boot tested by the bot for a couple of boards.

https://gitlab.com/vireshk/pmko/-/pipelines/351965580

FWIW, I have queued up the series for linux-next to get more testing, but your
reviews are welcome. Thanks.

V2->V3:
- Drop the auto-register part from all logs, this isn't called auto registration
  anymore.
- Call register_em() only for new policies.
- Update scmi driver to register with EM only when required.
- Add Rby tags.

V1->V2:
- Add a callback instead of flag.
- Register before governor is initialized.
- Update scmi driver as well.
- Don't unregister from the EM core.

--
Viresh

Viresh Kumar (9):
  cpufreq: Add callback to register with energy model
  cpufreq: dt: Use .register_em() to register with energy model
  cpufreq: imx6q: Use .register_em() to register with energy model
  cpufreq: mediatek: Use .register_em() to register with energy model
  cpufreq: omap: Use .register_em() to register with energy model
  cpufreq: qcom-cpufreq-hw: Use .register_em() to register with energy
    model
  cpufreq: scpi: Use .register_em() to register with energy model
  cpufreq: vexpress: Use .register_em() to register with energy model
  cpufreq: scmi: Use .register_em() to register with energy model

 drivers/cpufreq/cpufreq-dt.c           |  3 +-
 drivers/cpufreq/cpufreq.c              | 13 ++++++
 drivers/cpufreq/imx6q-cpufreq.c        |  2 +-
 drivers/cpufreq/mediatek-cpufreq.c     |  3 +-
 drivers/cpufreq/omap-cpufreq.c         |  2 +-
 drivers/cpufreq/qcom-cpufreq-hw.c      |  3 +-
 drivers/cpufreq/scmi-cpufreq.c         | 65 +++++++++++++++++---------
 drivers/cpufreq/scpi-cpufreq.c         |  3 +-
 drivers/cpufreq/vexpress-spc-cpufreq.c |  3 +-
 include/linux/cpufreq.h                | 14 ++++++
 10 files changed, 76 insertions(+), 35 deletions(-)

-- 
2.31.1.272.g89b43f80a514


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH V3 1/9] cpufreq: Add callback to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
  (?)
  (?)
@ 2021-08-12  4:35 ` Viresh Kumar
  2021-09-01  8:32   ` Vincent Donnefort
  -1 siblings, 1 reply; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-kernel

Many cpufreq drivers register with the energy model for each policy and
do exactly the same thing. Follow the footsteps of thermal-cooling, to
get it done from the cpufreq core itself.

Provide a new callback, which will be called, if present, by the cpufreq
core at the right moment (more on that in the code's comment). Also
provide a generic implementation that uses dev_pm_opp_of_register_em().

This also allows us to register with the EM at a later point of time,
compared to ->init(), from where the EM core can access cpufreq policy
directly using cpufreq_cpu_get() type of helpers and perform other work,
like marking few frequencies inefficient, this will be done separately.

Reviewed-by: Quentin Perret <qperret@google.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq.c | 13 +++++++++++++
 include/linux/cpufreq.h   | 14 ++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 45f3416988f1..d301f39248a0 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1491,6 +1491,19 @@ static int cpufreq_online(unsigned int cpu)
 		write_lock_irqsave(&cpufreq_driver_lock, flags);
 		list_add(&policy->policy_list, &cpufreq_policy_list);
 		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
+
+		/*
+		 * Register with the energy model before
+		 * sched_cpufreq_governor_change() is called, which will result
+		 * in rebuilding of the sched domains, which should only be done
+		 * once the energy model is properly initialized for the policy
+		 * first.
+		 *
+		 * Also, this should be called before the policy is registered
+		 * with cooling framework.
+		 */
+		if (cpufreq_driver->register_em)
+			cpufreq_driver->register_em(policy);
 	}
 
 	ret = cpufreq_init_policy(policy);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 9fd719475fcd..c65a1d7385f8 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -9,10 +9,12 @@
 #define _LINUX_CPUFREQ_H
 
 #include <linux/clk.h>
+#include <linux/cpu.h>
 #include <linux/cpumask.h>
 #include <linux/completion.h>
 #include <linux/kobject.h>
 #include <linux/notifier.h>
+#include <linux/pm_opp.h>
 #include <linux/pm_qos.h>
 #include <linux/spinlock.h>
 #include <linux/sysfs.h>
@@ -373,6 +375,12 @@ struct cpufreq_driver {
 	/* platform specific boost support code */
 	bool		boost_enabled;
 	int		(*set_boost)(struct cpufreq_policy *policy, int state);
+
+	/*
+	 * Set by drivers that want to register with the energy model after the
+	 * policy is properly initialized, but before the governor is started.
+	 */
+	void		(*register_em)(struct cpufreq_policy *policy);
 };
 
 /* flags */
@@ -1046,4 +1054,10 @@ unsigned int cpufreq_generic_get(unsigned int cpu);
 void cpufreq_generic_init(struct cpufreq_policy *policy,
 		struct cpufreq_frequency_table *table,
 		unsigned int transition_latency);
+
+static inline void cpufreq_register_em_with_opp(struct cpufreq_policy *policy)
+{
+	dev_pm_opp_of_register_em(get_cpu_device(policy->cpu),
+				  policy->related_cpus);
+}
 #endif /* _LINUX_CPUFREQ_H */
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 2/9] cpufreq: dt: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
                   ` (2 preceding siblings ...)
  (?)
@ 2021-08-12  4:35 ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq-dt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index ece52863ba62..8fcaba541539 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -143,8 +143,6 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		cpufreq_dt_attr[1] = &cpufreq_freq_attr_scaling_boost_freqs;
 	}
 
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
-
 	return 0;
 
 out_clk_put:
@@ -184,6 +182,7 @@ static struct cpufreq_driver dt_cpufreq_driver = {
 	.exit = cpufreq_exit,
 	.online = cpufreq_online,
 	.offline = cpufreq_offline,
+	.register_em = cpufreq_register_em_with_opp,
 	.name = "cpufreq-dt",
 	.attr = cpufreq_dt_attr,
 	.suspend = cpufreq_generic_suspend,
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 3/9] cpufreq: imx6q: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
@ 2021-08-12  4:35   ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, NXP Linux Team
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/imx6q-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index 5bf5fc759881..90beb26ed34e 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -192,7 +192,6 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
 	policy->clk = clks[ARM].clk;
 	cpufreq_generic_init(policy, freq_table, transition_latency);
 	policy->suspend_freq = max_freq;
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
 
 	return 0;
 }
@@ -204,6 +203,7 @@ static struct cpufreq_driver imx6q_cpufreq_driver = {
 	.target_index = imx6q_set_target,
 	.get = cpufreq_generic_get,
 	.init = imx6q_cpufreq_init,
+	.register_em = cpufreq_register_em_with_opp,
 	.name = "imx6q-cpufreq",
 	.attr = cpufreq_generic_attr,
 	.suspend = cpufreq_generic_suspend,
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 3/9] cpufreq: imx6q: Use .register_em() to register with energy model
@ 2021-08-12  4:35   ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, NXP Linux Team
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/imx6q-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index 5bf5fc759881..90beb26ed34e 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -192,7 +192,6 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
 	policy->clk = clks[ARM].clk;
 	cpufreq_generic_init(policy, freq_table, transition_latency);
 	policy->suspend_freq = max_freq;
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
 
 	return 0;
 }
@@ -204,6 +203,7 @@ static struct cpufreq_driver imx6q_cpufreq_driver = {
 	.target_index = imx6q_set_target,
 	.get = cpufreq_generic_get,
 	.init = imx6q_cpufreq_init,
+	.register_em = cpufreq_register_em_with_opp,
 	.name = "imx6q-cpufreq",
 	.attr = cpufreq_generic_attr,
 	.suspend = cpufreq_generic_suspend,
-- 
2.31.1.272.g89b43f80a514


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 4/9] cpufreq: mediatek: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
  (?)
@ 2021-08-12  4:35   ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Matthias Brugger
  Cc: linux-pm, Vincent Guittot, linux-kernel, linux-arm-kernel,
	linux-mediatek

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/mediatek-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 87019d5a9547..866163883b48 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -448,8 +448,6 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
 	policy->driver_data = info;
 	policy->clk = info->cpu_clk;
 
-	dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus);
-
 	return 0;
 }
 
@@ -471,6 +469,7 @@ static struct cpufreq_driver mtk_cpufreq_driver = {
 	.get = cpufreq_generic_get,
 	.init = mtk_cpufreq_init,
 	.exit = mtk_cpufreq_exit,
+	.register_em = cpufreq_register_em_with_opp,
 	.name = "mtk-cpufreq",
 	.attr = cpufreq_generic_attr,
 };
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 4/9] cpufreq: mediatek: Use .register_em() to register with energy model
@ 2021-08-12  4:35   ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Matthias Brugger
  Cc: linux-pm, Vincent Guittot, linux-kernel, linux-arm-kernel,
	linux-mediatek

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/mediatek-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 87019d5a9547..866163883b48 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -448,8 +448,6 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
 	policy->driver_data = info;
 	policy->clk = info->cpu_clk;
 
-	dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus);
-
 	return 0;
 }
 
@@ -471,6 +469,7 @@ static struct cpufreq_driver mtk_cpufreq_driver = {
 	.get = cpufreq_generic_get,
 	.init = mtk_cpufreq_init,
 	.exit = mtk_cpufreq_exit,
+	.register_em = cpufreq_register_em_with_opp,
 	.name = "mtk-cpufreq",
 	.attr = cpufreq_generic_attr,
 };
-- 
2.31.1.272.g89b43f80a514


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 4/9] cpufreq: mediatek: Use .register_em() to register with energy model
@ 2021-08-12  4:35   ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Matthias Brugger
  Cc: linux-pm, Vincent Guittot, linux-kernel, linux-arm-kernel,
	linux-mediatek

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/mediatek-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 87019d5a9547..866163883b48 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -448,8 +448,6 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
 	policy->driver_data = info;
 	policy->clk = info->cpu_clk;
 
-	dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus);
-
 	return 0;
 }
 
@@ -471,6 +469,7 @@ static struct cpufreq_driver mtk_cpufreq_driver = {
 	.get = cpufreq_generic_get,
 	.init = mtk_cpufreq_init,
 	.exit = mtk_cpufreq_exit,
+	.register_em = cpufreq_register_em_with_opp,
 	.name = "mtk-cpufreq",
 	.attr = cpufreq_generic_attr,
 };
-- 
2.31.1.272.g89b43f80a514


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 5/9] cpufreq: omap: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
                   ` (5 preceding siblings ...)
  (?)
@ 2021-08-12  4:35 ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Kevin Hilman, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-omap, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/omap-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
index e035ee216b0f..1b50df06c6bc 100644
--- a/drivers/cpufreq/omap-cpufreq.c
+++ b/drivers/cpufreq/omap-cpufreq.c
@@ -131,7 +131,6 @@ static int omap_cpu_init(struct cpufreq_policy *policy)
 
 	/* FIXME: what's the actual transition time? */
 	cpufreq_generic_init(policy, freq_table, 300 * 1000);
-	dev_pm_opp_of_register_em(mpu_dev, policy->cpus);
 
 	return 0;
 }
@@ -150,6 +149,7 @@ static struct cpufreq_driver omap_driver = {
 	.get		= cpufreq_generic_get,
 	.init		= omap_cpu_init,
 	.exit		= omap_cpu_exit,
+	.register_em	= cpufreq_register_em_with_opp,
 	.name		= "omap",
 	.attr		= cpufreq_generic_attr,
 };
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 6/9] cpufreq: qcom-cpufreq-hw: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
                   ` (6 preceding siblings ...)
  (?)
@ 2021-08-12  4:35 ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Andy Gross, Bjorn Andersson, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-msm, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/qcom-cpufreq-hw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
index f86859bf76f1..c2e71c430fbf 100644
--- a/drivers/cpufreq/qcom-cpufreq-hw.c
+++ b/drivers/cpufreq/qcom-cpufreq-hw.c
@@ -362,8 +362,6 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
 		goto error;
 	}
 
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
-
 	if (policy_has_boost_freq(policy)) {
 		ret = cpufreq_enable_boost_support();
 		if (ret)
@@ -412,6 +410,7 @@ static struct cpufreq_driver cpufreq_qcom_hw_driver = {
 	.get		= qcom_cpufreq_hw_get,
 	.init		= qcom_cpufreq_hw_cpu_init,
 	.exit		= qcom_cpufreq_hw_cpu_exit,
+	.register_em	= cpufreq_register_em_with_opp,
 	.fast_switch    = qcom_cpufreq_hw_fast_switch,
 	.name		= "qcom-cpufreq-hw",
 	.attr		= qcom_cpufreq_hw_attr,
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 7/9] cpufreq: scpi: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
@ 2021-08-12  4:35   ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Sudeep Holla, Cristian Marussi, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/scpi-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
index d6a698a1b5d1..bda3e7d42964 100644
--- a/drivers/cpufreq/scpi-cpufreq.c
+++ b/drivers/cpufreq/scpi-cpufreq.c
@@ -163,8 +163,6 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
 
 	policy->fast_switch_possible = false;
 
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
-
 	return 0;
 
 out_free_cpufreq_table:
@@ -200,6 +198,7 @@ static struct cpufreq_driver scpi_cpufreq_driver = {
 	.init	= scpi_cpufreq_init,
 	.exit	= scpi_cpufreq_exit,
 	.target_index	= scpi_cpufreq_set_target,
+	.register_em	= cpufreq_register_em_with_opp,
 };
 
 static int scpi_cpufreq_probe(struct platform_device *pdev)
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 7/9] cpufreq: scpi: Use .register_em() to register with energy model
@ 2021-08-12  4:35   ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Sudeep Holla, Cristian Marussi, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/scpi-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
index d6a698a1b5d1..bda3e7d42964 100644
--- a/drivers/cpufreq/scpi-cpufreq.c
+++ b/drivers/cpufreq/scpi-cpufreq.c
@@ -163,8 +163,6 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
 
 	policy->fast_switch_possible = false;
 
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
-
 	return 0;
 
 out_free_cpufreq_table:
@@ -200,6 +198,7 @@ static struct cpufreq_driver scpi_cpufreq_driver = {
 	.init	= scpi_cpufreq_init,
 	.exit	= scpi_cpufreq_exit,
 	.target_index	= scpi_cpufreq_set_target,
+	.register_em	= cpufreq_register_em_with_opp,
 };
 
 static int scpi_cpufreq_probe(struct platform_device *pdev)
-- 
2.31.1.272.g89b43f80a514


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 8/9] cpufreq: vexpress: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
@ 2021-08-12  4:35   ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Sudeep Holla
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/vexpress-spc-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
index ab56813b7256..284b6bd040b1 100644
--- a/drivers/cpufreq/vexpress-spc-cpufreq.c
+++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
@@ -440,8 +440,6 @@ static int ve_spc_cpufreq_init(struct cpufreq_policy *policy)
 	policy->freq_table = freq_table[cur_cluster];
 	policy->cpuinfo.transition_latency = 1000000; /* 1 ms */
 
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
-
 	if (is_bL_switching_enabled())
 		per_cpu(cpu_last_req_freq, policy->cpu) =
 						clk_get_cpu_rate(policy->cpu);
@@ -475,6 +473,7 @@ static struct cpufreq_driver ve_spc_cpufreq_driver = {
 	.get			= ve_spc_cpufreq_get_rate,
 	.init			= ve_spc_cpufreq_init,
 	.exit			= ve_spc_cpufreq_exit,
+	.register_em		= cpufreq_register_em_with_opp,
 	.attr			= cpufreq_generic_attr,
 };
 
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 8/9] cpufreq: vexpress: Use .register_em() to register with energy model
@ 2021-08-12  4:35   ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Viresh Kumar, Sudeep Holla
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback with
cpufreq_register_em_with_opp() to register with the EM core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/vexpress-spc-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
index ab56813b7256..284b6bd040b1 100644
--- a/drivers/cpufreq/vexpress-spc-cpufreq.c
+++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
@@ -440,8 +440,6 @@ static int ve_spc_cpufreq_init(struct cpufreq_policy *policy)
 	policy->freq_table = freq_table[cur_cluster];
 	policy->cpuinfo.transition_latency = 1000000; /* 1 ms */
 
-	dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
-
 	if (is_bL_switching_enabled())
 		per_cpu(cpu_last_req_freq, policy->cpu) =
 						clk_get_cpu_rate(policy->cpu);
@@ -475,6 +473,7 @@ static struct cpufreq_driver ve_spc_cpufreq_driver = {
 	.get			= ve_spc_cpufreq_get_rate,
 	.init			= ve_spc_cpufreq_init,
 	.exit			= ve_spc_cpufreq_exit,
+	.register_em		= cpufreq_register_em_with_opp,
 	.attr			= cpufreq_generic_attr,
 };
 
-- 
2.31.1.272.g89b43f80a514


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 9/9] cpufreq: scmi: Use .register_em() to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
@ 2021-08-12  4:35   ` Viresh Kumar
  -1 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Sudeep Holla, Cristian Marussi, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback to register with the EM
after the cpufreq policy is properly initialized.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/scmi-cpufreq.c | 65 ++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 23 deletions(-)

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index 75f818d04b48..1e0cd4d165f0 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -22,7 +22,9 @@
 
 struct scmi_data {
 	int domain_id;
+	int nr_opp;
 	struct device *cpu_dev;
+	cpumask_var_t opp_shared_cpus;
 };
 
 static struct scmi_protocol_handle *ph;
@@ -123,9 +125,6 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct scmi_data *priv;
 	struct cpufreq_frequency_table *freq_table;
-	struct em_data_callback em_cb = EM_DATA_CB(scmi_get_cpu_power);
-	cpumask_var_t opp_shared_cpus;
-	bool power_scale_mw;
 
 	cpu_dev = get_cpu_device(policy->cpu);
 	if (!cpu_dev) {
@@ -133,9 +132,15 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 		return -ENODEV;
 	}
 
-	if (!zalloc_cpumask_var(&opp_shared_cpus, GFP_KERNEL))
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv)
 		return -ENOMEM;
 
+	if (!zalloc_cpumask_var(&priv->opp_shared_cpus, GFP_KERNEL)) {
+		ret = -ENOMEM;
+		goto out_free_priv;
+	}
+
 	/* Obtain CPUs that share SCMI performance controls */
 	ret = scmi_get_sharing_cpus(cpu_dev, policy->cpus);
 	if (ret) {
@@ -148,14 +153,14 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	 * The OPP 'sharing cpus' info may come from DT through an empty opp
 	 * table and opp-shared.
 	 */
-	ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, opp_shared_cpus);
-	if (ret || !cpumask_weight(opp_shared_cpus)) {
+	ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, priv->opp_shared_cpus);
+	if (ret || !cpumask_weight(priv->opp_shared_cpus)) {
 		/*
 		 * Either opp-table is not set or no opp-shared was found.
 		 * Use the CPU mask from SCMI to designate CPUs sharing an OPP
 		 * table.
 		 */
-		cpumask_copy(opp_shared_cpus, policy->cpus);
+		cpumask_copy(priv->opp_shared_cpus, policy->cpus);
 	}
 
 	 /*
@@ -180,7 +185,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 			goto out_free_opp;
 		}
 
-		ret = dev_pm_opp_set_sharing_cpus(cpu_dev, opp_shared_cpus);
+		ret = dev_pm_opp_set_sharing_cpus(cpu_dev, priv->opp_shared_cpus);
 		if (ret) {
 			dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
 				__func__, ret);
@@ -188,21 +193,13 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 			goto out_free_opp;
 		}
 
-		power_scale_mw = perf_ops->power_scale_mw_get(ph);
-		em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb,
-					    opp_shared_cpus, power_scale_mw);
-	}
-
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		ret = -ENOMEM;
-		goto out_free_opp;
+		priv->nr_opp = nr_opp;
 	}
 
 	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
 	if (ret) {
 		dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-		goto out_free_priv;
+		goto out_free_opp;
 	}
 
 	priv->cpu_dev = cpu_dev;
@@ -223,17 +220,16 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	policy->fast_switch_possible =
 		perf_ops->fast_switch_possible(ph, cpu_dev);
 
-	free_cpumask_var(opp_shared_cpus);
 	return 0;
 
-out_free_priv:
-	kfree(priv);
-
 out_free_opp:
 	dev_pm_opp_remove_all_dynamic(cpu_dev);
 
 out_free_cpumask:
-	free_cpumask_var(opp_shared_cpus);
+	free_cpumask_var(priv->opp_shared_cpus);
+
+out_free_priv:
+	kfree(priv);
 
 	return ret;
 }
@@ -244,11 +240,33 @@ static int scmi_cpufreq_exit(struct cpufreq_policy *policy)
 
 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
 	dev_pm_opp_remove_all_dynamic(priv->cpu_dev);
+	free_cpumask_var(priv->opp_shared_cpus);
 	kfree(priv);
 
 	return 0;
 }
 
+static void scmi_cpufreq_register_em(struct cpufreq_policy *policy)
+{
+	struct em_data_callback em_cb = EM_DATA_CB(scmi_get_cpu_power);
+	bool power_scale_mw = perf_ops->power_scale_mw_get(ph);
+	struct scmi_data *priv = policy->driver_data;
+
+	/*
+	 * This callback will be called for each policy, but we don't need to
+	 * register with EM every time. Despite not being part of the same
+	 * policy, some CPUs may still share their perf-domains, and a CPU from
+	 * another policy may already have registered with EM on behalf of CPUs
+	 * of this policy.
+	 */
+	if (!priv->nr_opp)
+		return;
+
+	em_dev_register_perf_domain(get_cpu_device(policy->cpu), priv->nr_opp,
+				    &em_cb, priv->opp_shared_cpus,
+				    power_scale_mw);
+}
+
 static struct cpufreq_driver scmi_cpufreq_driver = {
 	.name	= "scmi",
 	.flags	= CPUFREQ_HAVE_GOVERNOR_PER_POLICY |
@@ -261,6 +279,7 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
 	.get	= scmi_cpufreq_get_rate,
 	.init	= scmi_cpufreq_init,
 	.exit	= scmi_cpufreq_exit,
+	.register_em	= scmi_cpufreq_register_em,
 };
 
 static int scmi_cpufreq_probe(struct scmi_device *sdev)
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH V3 9/9] cpufreq: scmi: Use .register_em() to register with energy model
@ 2021-08-12  4:35   ` Viresh Kumar
  0 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2021-08-12  4:35 UTC (permalink / raw)
  To: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Sudeep Holla, Cristian Marussi, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-kernel

Set the newly added .register_em() callback to register with the EM
after the cpufreq policy is properly initialized.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/scmi-cpufreq.c | 65 ++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 23 deletions(-)

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index 75f818d04b48..1e0cd4d165f0 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -22,7 +22,9 @@
 
 struct scmi_data {
 	int domain_id;
+	int nr_opp;
 	struct device *cpu_dev;
+	cpumask_var_t opp_shared_cpus;
 };
 
 static struct scmi_protocol_handle *ph;
@@ -123,9 +125,6 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct scmi_data *priv;
 	struct cpufreq_frequency_table *freq_table;
-	struct em_data_callback em_cb = EM_DATA_CB(scmi_get_cpu_power);
-	cpumask_var_t opp_shared_cpus;
-	bool power_scale_mw;
 
 	cpu_dev = get_cpu_device(policy->cpu);
 	if (!cpu_dev) {
@@ -133,9 +132,15 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 		return -ENODEV;
 	}
 
-	if (!zalloc_cpumask_var(&opp_shared_cpus, GFP_KERNEL))
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv)
 		return -ENOMEM;
 
+	if (!zalloc_cpumask_var(&priv->opp_shared_cpus, GFP_KERNEL)) {
+		ret = -ENOMEM;
+		goto out_free_priv;
+	}
+
 	/* Obtain CPUs that share SCMI performance controls */
 	ret = scmi_get_sharing_cpus(cpu_dev, policy->cpus);
 	if (ret) {
@@ -148,14 +153,14 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	 * The OPP 'sharing cpus' info may come from DT through an empty opp
 	 * table and opp-shared.
 	 */
-	ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, opp_shared_cpus);
-	if (ret || !cpumask_weight(opp_shared_cpus)) {
+	ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, priv->opp_shared_cpus);
+	if (ret || !cpumask_weight(priv->opp_shared_cpus)) {
 		/*
 		 * Either opp-table is not set or no opp-shared was found.
 		 * Use the CPU mask from SCMI to designate CPUs sharing an OPP
 		 * table.
 		 */
-		cpumask_copy(opp_shared_cpus, policy->cpus);
+		cpumask_copy(priv->opp_shared_cpus, policy->cpus);
 	}
 
 	 /*
@@ -180,7 +185,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 			goto out_free_opp;
 		}
 
-		ret = dev_pm_opp_set_sharing_cpus(cpu_dev, opp_shared_cpus);
+		ret = dev_pm_opp_set_sharing_cpus(cpu_dev, priv->opp_shared_cpus);
 		if (ret) {
 			dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
 				__func__, ret);
@@ -188,21 +193,13 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 			goto out_free_opp;
 		}
 
-		power_scale_mw = perf_ops->power_scale_mw_get(ph);
-		em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb,
-					    opp_shared_cpus, power_scale_mw);
-	}
-
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		ret = -ENOMEM;
-		goto out_free_opp;
+		priv->nr_opp = nr_opp;
 	}
 
 	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
 	if (ret) {
 		dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-		goto out_free_priv;
+		goto out_free_opp;
 	}
 
 	priv->cpu_dev = cpu_dev;
@@ -223,17 +220,16 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	policy->fast_switch_possible =
 		perf_ops->fast_switch_possible(ph, cpu_dev);
 
-	free_cpumask_var(opp_shared_cpus);
 	return 0;
 
-out_free_priv:
-	kfree(priv);
-
 out_free_opp:
 	dev_pm_opp_remove_all_dynamic(cpu_dev);
 
 out_free_cpumask:
-	free_cpumask_var(opp_shared_cpus);
+	free_cpumask_var(priv->opp_shared_cpus);
+
+out_free_priv:
+	kfree(priv);
 
 	return ret;
 }
@@ -244,11 +240,33 @@ static int scmi_cpufreq_exit(struct cpufreq_policy *policy)
 
 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
 	dev_pm_opp_remove_all_dynamic(priv->cpu_dev);
+	free_cpumask_var(priv->opp_shared_cpus);
 	kfree(priv);
 
 	return 0;
 }
 
+static void scmi_cpufreq_register_em(struct cpufreq_policy *policy)
+{
+	struct em_data_callback em_cb = EM_DATA_CB(scmi_get_cpu_power);
+	bool power_scale_mw = perf_ops->power_scale_mw_get(ph);
+	struct scmi_data *priv = policy->driver_data;
+
+	/*
+	 * This callback will be called for each policy, but we don't need to
+	 * register with EM every time. Despite not being part of the same
+	 * policy, some CPUs may still share their perf-domains, and a CPU from
+	 * another policy may already have registered with EM on behalf of CPUs
+	 * of this policy.
+	 */
+	if (!priv->nr_opp)
+		return;
+
+	em_dev_register_perf_domain(get_cpu_device(policy->cpu), priv->nr_opp,
+				    &em_cb, priv->opp_shared_cpus,
+				    power_scale_mw);
+}
+
 static struct cpufreq_driver scmi_cpufreq_driver = {
 	.name	= "scmi",
 	.flags	= CPUFREQ_HAVE_GOVERNOR_PER_POLICY |
@@ -261,6 +279,7 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
 	.get	= scmi_cpufreq_get_rate,
 	.init	= scmi_cpufreq_init,
 	.exit	= scmi_cpufreq_exit,
+	.register_em	= scmi_cpufreq_register_em,
 };
 
 static int scmi_cpufreq_probe(struct scmi_device *sdev)
-- 
2.31.1.272.g89b43f80a514


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 7/9] cpufreq: scpi: Use .register_em() to register with energy model
  2021-08-12  4:35   ` Viresh Kumar
@ 2021-08-26 11:26     ` Sudeep Holla
  -1 siblings, 0 replies; 30+ messages in thread
From: Sudeep Holla @ 2021-08-26 11:26 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Cristian Marussi, linux-pm, Sudeep Holla, Vincent Guittot,
	linux-arm-kernel, linux-kernel

On Thu, Aug 12, 2021 at 10:05:20AM +0530, Viresh Kumar wrote:
> Set the newly added .register_em() callback with
> cpufreq_register_em_with_opp() to register with the EM core.
> 

If not too late,

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 7/9] cpufreq: scpi: Use .register_em() to register with energy model
@ 2021-08-26 11:26     ` Sudeep Holla
  0 siblings, 0 replies; 30+ messages in thread
From: Sudeep Holla @ 2021-08-26 11:26 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Cristian Marussi, linux-pm, Sudeep Holla, Vincent Guittot,
	linux-arm-kernel, linux-kernel

On Thu, Aug 12, 2021 at 10:05:20AM +0530, Viresh Kumar wrote:
> Set the newly added .register_em() callback with
> cpufreq_register_em_with_opp() to register with the EM core.
> 

If not too late,

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 9/9] cpufreq: scmi: Use .register_em() to register with energy model
  2021-08-12  4:35   ` Viresh Kumar
@ 2021-08-26 11:27     ` Sudeep Holla
  -1 siblings, 0 replies; 30+ messages in thread
From: Sudeep Holla @ 2021-08-26 11:27 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Cristian Marussi, Sudeep Holla, linux-pm, Vincent Guittot,
	linux-arm-kernel, linux-kernel

On Thu, Aug 12, 2021 at 10:05:22AM +0530, Viresh Kumar wrote:
> Set the newly added .register_em() callback to register with the EM
> after the cpufreq policy is properly initialized.
> 

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 9/9] cpufreq: scmi: Use .register_em() to register with energy model
@ 2021-08-26 11:27     ` Sudeep Holla
  0 siblings, 0 replies; 30+ messages in thread
From: Sudeep Holla @ 2021-08-26 11:27 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	Cristian Marussi, Sudeep Holla, linux-pm, Vincent Guittot,
	linux-arm-kernel, linux-kernel

On Thu, Aug 12, 2021 at 10:05:22AM +0530, Viresh Kumar wrote:
> Set the newly added .register_em() callback to register with the EM
> after the cpufreq policy is properly initialized.
> 

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 8/9] cpufreq: vexpress: Use .register_em() to register with energy model
  2021-08-12  4:35   ` Viresh Kumar
@ 2021-08-26 11:28     ` Sudeep Holla
  -1 siblings, 0 replies; 30+ messages in thread
From: Sudeep Holla @ 2021-08-26 11:28 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	linux-pm, Vincent Guittot, Sudeep Holla, linux-arm-kernel,
	linux-kernel

On Thu, Aug 12, 2021 at 10:05:21AM +0530, Viresh Kumar wrote:
> Set the newly added .register_em() callback with
> cpufreq_register_em_with_opp() to register with the EM core.
>

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 8/9] cpufreq: vexpress: Use .register_em() to register with energy model
@ 2021-08-26 11:28     ` Sudeep Holla
  0 siblings, 0 replies; 30+ messages in thread
From: Sudeep Holla @ 2021-08-26 11:28 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, lukasz.luba, Quentin Perret,
	linux-pm, Vincent Guittot, Sudeep Holla, linux-arm-kernel,
	linux-kernel

On Thu, Aug 12, 2021 at 10:05:21AM +0530, Viresh Kumar wrote:
> Set the newly added .register_em() callback with
> cpufreq_register_em_with_opp() to register with the EM core.
>

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 0/9] Add callback to register with energy model
  2021-08-12  4:35 ` Viresh Kumar
  (?)
@ 2021-08-31  8:54   ` Dietmar Eggemann
  -1 siblings, 0 replies; 30+ messages in thread
From: Dietmar Eggemann @ 2021-08-31  8:54 UTC (permalink / raw)
  To: Viresh Kumar, Rafael Wysocki, Vincent Donnefort, lukasz.luba,
	Quentin Perret, Andy Gross, Bjorn Andersson, Cristian Marussi,
	Fabio Estevam, Kevin Hilman, Matthias Brugger, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Sudeep Holla
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-mediatek, linux-omap

On 12/08/2021 06:35, Viresh Kumar wrote:
> Many cpufreq drivers register with the energy model for each policy and
> do exactly the same thing. Follow the footsteps of thermal-cooling, to
> get it done from the cpufreq core itself.
> 
> Provide a new callback, which will be called, if present, by the cpufreq
> core at the right moment (more on that in the code's comment). Also
> provide a generic implementation that uses dev_pm_opp_of_register_em().
> 
> This also allows us to register with the EM at a later point of time,
> compared to ->init(), from where the EM core can access cpufreq policy
> directly using cpufreq_cpu_get() type of helpers and perform other work,
> like marking few frequencies inefficient, this will be done separately.
> 
> This is build/boot tested by the bot for a couple of boards.
> 
> https://gitlab.com/vireshk/pmko/-/pipelines/351965580
> 
> FWIW, I have queued up the series for linux-next to get more testing, but your
> reviews are welcome. Thanks.
> 
> V2->V3:
> - Drop the auto-register part from all logs, this isn't called auto registration
>   anymore.
> - Call register_em() only for new policies.
> - Update scmi driver to register with EM only when required.
> - Add Rby tags.

LGTM. Tested on TC2 (vexpress-spc), Juno-r0 (scpi-cpufreq and scmi).

Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 0/9] Add callback to register with energy model
@ 2021-08-31  8:54   ` Dietmar Eggemann
  0 siblings, 0 replies; 30+ messages in thread
From: Dietmar Eggemann @ 2021-08-31  8:54 UTC (permalink / raw)
  To: Viresh Kumar, Rafael Wysocki, Vincent Donnefort, lukasz.luba,
	Quentin Perret, Andy Gross, Bjorn Andersson, Cristian Marussi,
	Fabio Estevam, Kevin Hilman, Matthias Brugger, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Sudeep Holla
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-mediatek, linux-omap

On 12/08/2021 06:35, Viresh Kumar wrote:
> Many cpufreq drivers register with the energy model for each policy and
> do exactly the same thing. Follow the footsteps of thermal-cooling, to
> get it done from the cpufreq core itself.
> 
> Provide a new callback, which will be called, if present, by the cpufreq
> core at the right moment (more on that in the code's comment). Also
> provide a generic implementation that uses dev_pm_opp_of_register_em().
> 
> This also allows us to register with the EM at a later point of time,
> compared to ->init(), from where the EM core can access cpufreq policy
> directly using cpufreq_cpu_get() type of helpers and perform other work,
> like marking few frequencies inefficient, this will be done separately.
> 
> This is build/boot tested by the bot for a couple of boards.
> 
> https://gitlab.com/vireshk/pmko/-/pipelines/351965580
> 
> FWIW, I have queued up the series for linux-next to get more testing, but your
> reviews are welcome. Thanks.
> 
> V2->V3:
> - Drop the auto-register part from all logs, this isn't called auto registration
>   anymore.
> - Call register_em() only for new policies.
> - Update scmi driver to register with EM only when required.
> - Add Rby tags.

LGTM. Tested on TC2 (vexpress-spc), Juno-r0 (scpi-cpufreq and scmi).

Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>



_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 0/9] Add callback to register with energy model
@ 2021-08-31  8:54   ` Dietmar Eggemann
  0 siblings, 0 replies; 30+ messages in thread
From: Dietmar Eggemann @ 2021-08-31  8:54 UTC (permalink / raw)
  To: Viresh Kumar, Rafael Wysocki, Vincent Donnefort, lukasz.luba,
	Quentin Perret, Andy Gross, Bjorn Andersson, Cristian Marussi,
	Fabio Estevam, Kevin Hilman, Matthias Brugger, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Sudeep Holla
  Cc: linux-pm, Vincent Guittot, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-mediatek, linux-omap

On 12/08/2021 06:35, Viresh Kumar wrote:
> Many cpufreq drivers register with the energy model for each policy and
> do exactly the same thing. Follow the footsteps of thermal-cooling, to
> get it done from the cpufreq core itself.
> 
> Provide a new callback, which will be called, if present, by the cpufreq
> core at the right moment (more on that in the code's comment). Also
> provide a generic implementation that uses dev_pm_opp_of_register_em().
> 
> This also allows us to register with the EM at a later point of time,
> compared to ->init(), from where the EM core can access cpufreq policy
> directly using cpufreq_cpu_get() type of helpers and perform other work,
> like marking few frequencies inefficient, this will be done separately.
> 
> This is build/boot tested by the bot for a couple of boards.
> 
> https://gitlab.com/vireshk/pmko/-/pipelines/351965580
> 
> FWIW, I have queued up the series for linux-next to get more testing, but your
> reviews are welcome. Thanks.
> 
> V2->V3:
> - Drop the auto-register part from all logs, this isn't called auto registration
>   anymore.
> - Call register_em() only for new policies.
> - Update scmi driver to register with EM only when required.
> - Add Rby tags.

LGTM. Tested on TC2 (vexpress-spc), Juno-r0 (scpi-cpufreq and scmi).

Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 9/9] cpufreq: scmi: Use .register_em() to register with energy model
  2021-08-12  4:35   ` Viresh Kumar
@ 2021-08-31 16:17     ` Lukasz Luba
  -1 siblings, 0 replies; 30+ messages in thread
From: Lukasz Luba @ 2021-08-31 16:17 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, Quentin Perret, Sudeep Holla,
	Cristian Marussi, linux-pm, Vincent Guittot, linux-arm-kernel,
	linux-kernel

Hi Viresh,

My apologies for delay I was on holidays. I've seen the pull requests,
so it's too late, but just for history...

I have tested this new callback with hacked juno FW which works in
the per-cpu perf requests. There are no issues.

Some debug prints:

[    3.110072] cpu cpu0: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1
[    3.117666] cpu cpu0: Empty OPP table
[    3.121418] cpu cpu0: OPP table empty
[    3.131367] cpu cpu0: EM: created perf domain
[    3.137848] cpu cpu1: cpumask weight(opp_shared_cpus)=2 weight 
policy->cpus=1
[    3.145220] cpu cpu1: Empty OPP table
[    3.148961] cpu cpu1: OPP table empty
[    3.158193] cpu cpu1: EM: created perf domain
[    3.164325] cpu cpu2: cpumask weight(opp_shared_cpus)=2 weight 
policy->cpus=1
[    3.173430] cpu cpu3: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1
[    3.181947] cpu cpu4: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1
[    3.190620] cpu cpu5: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1

root@sqwt-ubuntu:~# grep . /sys/kernel/debug/energy_model/cpu0/ps\:*/*
/sys/kernel/debug/energy_model/cpu0/ps:450000/cost:79
/sys/kernel/debug/energy_model/cpu0/ps:450000/frequency:450000
/sys/kernel/debug/energy_model/cpu0/ps:450000/power:42
/sys/kernel/debug/energy_model/cpu0/ps:575000/cost:85
/sys/kernel/debug/energy_model/cpu0/ps:575000/frequency:575000
/sys/kernel/debug/energy_model/cpu0/ps:575000/power:58
/sys/kernel/debug/energy_model/cpu0/ps:700000/cost:95
/sys/kernel/debug/energy_model/cpu0/ps:700000/frequency:700000
/sys/kernel/debug/energy_model/cpu0/ps:700000/power:79
/sys/kernel/debug/energy_model/cpu0/ps:775000/cost:106
/sys/kernel/debug/energy_model/cpu0/ps:775000/frequency:775000
/sys/kernel/debug/energy_model/cpu0/ps:775000/power:97
/sys/kernel/debug/energy_model/cpu0/ps:850000/cost:119
/sys/kernel/debug/energy_model/cpu0/ps:850000/frequency:850000
/sys/kernel/debug/energy_model/cpu0/ps:850000/power:119
root@sqwt-ubuntu:~# cat /sys/kernel/debug/energy_model/cpu0/cpus
0,3-5
root@sqwt-ubuntu:~# cat /sys/kernel/debug/energy_model/cpu1/cpus
1-2
root@sqwt-ubuntu:~# grep . /sys/kernel/debug/energy_model/cpu1/ps\:*/*
/sys/kernel/debug/energy_model/cpu1/ps:1100000/cost:583
/sys/kernel/debug/energy_model/cpu1/ps:1100000/frequency:1100000
/sys/kernel/debug/energy_model/cpu1/ps:1100000/power:583
/sys/kernel/debug/energy_model/cpu1/ps:450000/cost:391
/sys/kernel/debug/energy_model/cpu1/ps:450000/frequency:450000
/sys/kernel/debug/energy_model/cpu1/ps:450000/power:160
/sys/kernel/debug/energy_model/cpu1/ps:625000/cost:420
/sys/kernel/debug/energy_model/cpu1/ps:625000/frequency:625000
/sys/kernel/debug/energy_model/cpu1/ps:625000/power:239
/sys/kernel/debug/energy_model/cpu1/ps:800000/cost:471
/sys/kernel/debug/energy_model/cpu1/ps:800000/frequency:800000
/sys/kernel/debug/energy_model/cpu1/ps:800000/power:343
/sys/kernel/debug/energy_model/cpu1/ps:950000/cost:525
/sys/kernel/debug/energy_model/cpu1/ps:950000/frequency:950000
/sys/kernel/debug/energy_model/cpu1/ps:950000/power:454
root@sqwt-ubuntu:~#

Regards,
Lukasz

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 9/9] cpufreq: scmi: Use .register_em() to register with energy model
@ 2021-08-31 16:17     ` Lukasz Luba
  0 siblings, 0 replies; 30+ messages in thread
From: Lukasz Luba @ 2021-08-31 16:17 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Vincent Donnefort, Quentin Perret, Sudeep Holla,
	Cristian Marussi, linux-pm, Vincent Guittot, linux-arm-kernel,
	linux-kernel

Hi Viresh,

My apologies for delay I was on holidays. I've seen the pull requests,
so it's too late, but just for history...

I have tested this new callback with hacked juno FW which works in
the per-cpu perf requests. There are no issues.

Some debug prints:

[    3.110072] cpu cpu0: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1
[    3.117666] cpu cpu0: Empty OPP table
[    3.121418] cpu cpu0: OPP table empty
[    3.131367] cpu cpu0: EM: created perf domain
[    3.137848] cpu cpu1: cpumask weight(opp_shared_cpus)=2 weight 
policy->cpus=1
[    3.145220] cpu cpu1: Empty OPP table
[    3.148961] cpu cpu1: OPP table empty
[    3.158193] cpu cpu1: EM: created perf domain
[    3.164325] cpu cpu2: cpumask weight(opp_shared_cpus)=2 weight 
policy->cpus=1
[    3.173430] cpu cpu3: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1
[    3.181947] cpu cpu4: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1
[    3.190620] cpu cpu5: cpumask weight(opp_shared_cpus)=4 weight 
policy->cpus=1

root@sqwt-ubuntu:~# grep . /sys/kernel/debug/energy_model/cpu0/ps\:*/*
/sys/kernel/debug/energy_model/cpu0/ps:450000/cost:79
/sys/kernel/debug/energy_model/cpu0/ps:450000/frequency:450000
/sys/kernel/debug/energy_model/cpu0/ps:450000/power:42
/sys/kernel/debug/energy_model/cpu0/ps:575000/cost:85
/sys/kernel/debug/energy_model/cpu0/ps:575000/frequency:575000
/sys/kernel/debug/energy_model/cpu0/ps:575000/power:58
/sys/kernel/debug/energy_model/cpu0/ps:700000/cost:95
/sys/kernel/debug/energy_model/cpu0/ps:700000/frequency:700000
/sys/kernel/debug/energy_model/cpu0/ps:700000/power:79
/sys/kernel/debug/energy_model/cpu0/ps:775000/cost:106
/sys/kernel/debug/energy_model/cpu0/ps:775000/frequency:775000
/sys/kernel/debug/energy_model/cpu0/ps:775000/power:97
/sys/kernel/debug/energy_model/cpu0/ps:850000/cost:119
/sys/kernel/debug/energy_model/cpu0/ps:850000/frequency:850000
/sys/kernel/debug/energy_model/cpu0/ps:850000/power:119
root@sqwt-ubuntu:~# cat /sys/kernel/debug/energy_model/cpu0/cpus
0,3-5
root@sqwt-ubuntu:~# cat /sys/kernel/debug/energy_model/cpu1/cpus
1-2
root@sqwt-ubuntu:~# grep . /sys/kernel/debug/energy_model/cpu1/ps\:*/*
/sys/kernel/debug/energy_model/cpu1/ps:1100000/cost:583
/sys/kernel/debug/energy_model/cpu1/ps:1100000/frequency:1100000
/sys/kernel/debug/energy_model/cpu1/ps:1100000/power:583
/sys/kernel/debug/energy_model/cpu1/ps:450000/cost:391
/sys/kernel/debug/energy_model/cpu1/ps:450000/frequency:450000
/sys/kernel/debug/energy_model/cpu1/ps:450000/power:160
/sys/kernel/debug/energy_model/cpu1/ps:625000/cost:420
/sys/kernel/debug/energy_model/cpu1/ps:625000/frequency:625000
/sys/kernel/debug/energy_model/cpu1/ps:625000/power:239
/sys/kernel/debug/energy_model/cpu1/ps:800000/cost:471
/sys/kernel/debug/energy_model/cpu1/ps:800000/frequency:800000
/sys/kernel/debug/energy_model/cpu1/ps:800000/power:343
/sys/kernel/debug/energy_model/cpu1/ps:950000/cost:525
/sys/kernel/debug/energy_model/cpu1/ps:950000/frequency:950000
/sys/kernel/debug/energy_model/cpu1/ps:950000/power:454
root@sqwt-ubuntu:~#

Regards,
Lukasz

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH V3 1/9] cpufreq: Add callback to register with energy model
  2021-08-12  4:35 ` [PATCH V3 1/9] cpufreq: " Viresh Kumar
@ 2021-09-01  8:32   ` Vincent Donnefort
  0 siblings, 0 replies; 30+ messages in thread
From: Vincent Donnefort @ 2021-09-01  8:32 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, lukasz.luba, Quentin Perret, linux-pm,
	Vincent Guittot, linux-kernel

On Thu, Aug 12, 2021 at 10:05:14AM +0530, Viresh Kumar wrote:
> Many cpufreq drivers register with the energy model for each policy and
> do exactly the same thing. Follow the footsteps of thermal-cooling, to
> get it done from the cpufreq core itself.
> 
> Provide a new callback, which will be called, if present, by the cpufreq
> core at the right moment (more on that in the code's comment). Also
> provide a generic implementation that uses dev_pm_opp_of_register_em().
> 
> This also allows us to register with the EM at a later point of time,
> compared to ->init(), from where the EM core can access cpufreq policy
> directly using cpufreq_cpu_get() type of helpers and perform other work,
> like marking few frequencies inefficient, this will be done separately.
> 
> Reviewed-by: Quentin Perret <qperret@google.com>
> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/cpufreq/cpufreq.c | 13 +++++++++++++
>  include/linux/cpufreq.h   | 14 ++++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 45f3416988f1..d301f39248a0 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1491,6 +1491,19 @@ static int cpufreq_online(unsigned int cpu)
>  		write_lock_irqsave(&cpufreq_driver_lock, flags);
>  		list_add(&policy->policy_list, &cpufreq_policy_list);
>  		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> +
> +		/*
> +		 * Register with the energy model before
> +		 * sched_cpufreq_governor_change() is called, which will result
> +		 * in rebuilding of the sched domains, which should only be done
> +		 * once the energy model is properly initialized for the policy
> +		 * first.
> +		 *
> +		 * Also, this should be called before the policy is registered
> +		 * with cooling framework.
> +		 */
> +		if (cpufreq_driver->register_em)
> +			cpufreq_driver->register_em(policy);
>  	}
>  
>  	ret = cpufreq_init_policy(policy);
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 9fd719475fcd..c65a1d7385f8 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -9,10 +9,12 @@
>  #define _LINUX_CPUFREQ_H
>  
>  #include <linux/clk.h>
> +#include <linux/cpu.h>
>  #include <linux/cpumask.h>
>  #include <linux/completion.h>
>  #include <linux/kobject.h>
>  #include <linux/notifier.h>
> +#include <linux/pm_opp.h>
>  #include <linux/pm_qos.h>
>  #include <linux/spinlock.h>
>  #include <linux/sysfs.h>
> @@ -373,6 +375,12 @@ struct cpufreq_driver {
>  	/* platform specific boost support code */
>  	bool		boost_enabled;
>  	int		(*set_boost)(struct cpufreq_policy *policy, int state);
> +
> +	/*
> +	 * Set by drivers that want to register with the energy model after the
> +	 * policy is properly initialized, but before the governor is started.
> +	 */
> +	void		(*register_em)(struct cpufreq_policy *policy);
>  };
>  
>  /* flags */
> @@ -1046,4 +1054,10 @@ unsigned int cpufreq_generic_get(unsigned int cpu);
>  void cpufreq_generic_init(struct cpufreq_policy *policy,
>  		struct cpufreq_frequency_table *table,
>  		unsigned int transition_latency);
> +
> +static inline void cpufreq_register_em_with_opp(struct cpufreq_policy *policy)
> +{
> +	dev_pm_opp_of_register_em(get_cpu_device(policy->cpu),
> +				  policy->related_cpus);
> +}
>  #endif /* _LINUX_CPUFREQ_H */
> -- 
> 2.31.1.272.g89b43f80a514
> 

Tested on Hikey960 while working on the inefficient OPPs support.

Tested-by: Vincent Donnefort <vincent.donnefort@arm.com>

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2021-09-01  8:33 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12  4:35 [PATCH V3 0/9] Add callback to register with energy model Viresh Kumar
2021-08-12  4:35 ` Viresh Kumar
2021-08-12  4:35 ` Viresh Kumar
2021-08-12  4:35 ` [PATCH V3 1/9] cpufreq: " Viresh Kumar
2021-09-01  8:32   ` Vincent Donnefort
2021-08-12  4:35 ` [PATCH V3 2/9] cpufreq: dt: Use .register_em() " Viresh Kumar
2021-08-12  4:35 ` [PATCH V3 3/9] cpufreq: imx6q: " Viresh Kumar
2021-08-12  4:35   ` Viresh Kumar
2021-08-12  4:35 ` [PATCH V3 4/9] cpufreq: mediatek: " Viresh Kumar
2021-08-12  4:35   ` Viresh Kumar
2021-08-12  4:35   ` Viresh Kumar
2021-08-12  4:35 ` [PATCH V3 5/9] cpufreq: omap: " Viresh Kumar
2021-08-12  4:35 ` [PATCH V3 6/9] cpufreq: qcom-cpufreq-hw: " Viresh Kumar
2021-08-12  4:35 ` [PATCH V3 7/9] cpufreq: scpi: " Viresh Kumar
2021-08-12  4:35   ` Viresh Kumar
2021-08-26 11:26   ` Sudeep Holla
2021-08-26 11:26     ` Sudeep Holla
2021-08-12  4:35 ` [PATCH V3 8/9] cpufreq: vexpress: " Viresh Kumar
2021-08-12  4:35   ` Viresh Kumar
2021-08-26 11:28   ` Sudeep Holla
2021-08-26 11:28     ` Sudeep Holla
2021-08-12  4:35 ` [PATCH V3 9/9] cpufreq: scmi: " Viresh Kumar
2021-08-12  4:35   ` Viresh Kumar
2021-08-26 11:27   ` Sudeep Holla
2021-08-26 11:27     ` Sudeep Holla
2021-08-31 16:17   ` Lukasz Luba
2021-08-31 16:17     ` Lukasz Luba
2021-08-31  8:54 ` [PATCH V3 0/9] Add callback " Dietmar Eggemann
2021-08-31  8:54   ` Dietmar Eggemann
2021-08-31  8:54   ` Dietmar Eggemann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.