All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V5 0/1] firmware: arm_scmi: Register and handle limits change notification
@ 2024-06-03 19:26 ` Sibi Sankar
  0 siblings, 0 replies; 7+ messages in thread
From: Sibi Sankar @ 2024-06-03 19:26 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, rafael, viresh.kumar,
	morten.rasmussen, dietmar.eggemann, lukasz.luba, pierre.gondois,
	vincent.guittot
  Cc: linux-arm-kernel, linux-pm, linux-kernel, quic_mdtipton,
	linux-arm-msm, Sibi Sankar

This series registers for scmi limits change notifications to determine
the throttled frequency and apply HW pressure.

V5:
* Drop patch 1 and use pm_qos to update constraints. [Vincent]
* Use sdev instead of cpu_dev in dev_warn. [Christian]
* Pass sdev directly through private data. [Christian]
* Dropping Rb's for now.

V4:
* Use EXPORT_SYMBOL_GPL instead. [Trilok]
* Use a interim variable to show the khz calc. [Lukasz]
* Use driver_data to pass on the handle and scmi_dev instead of using
  global variables. Dropped Lukasz's Rb due to adding these minor
  changes.

V3:
* Sanitize range_max received from the notifier. [Pierre]
* Drop patches 1/2 from v2. [Cristian]
* Update commit message in patch 2.

V2:
* Rename opp_xlate -> freq_xlate [Viresh]
* Export cpufreq_update_pressure and use it directly [Lukasz]

Sibi Sankar (1):
  cpufreq: scmi: Register for limit change notifications

 drivers/cpufreq/scmi-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

-- 
2.34.1


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

* [PATCH V5 0/1] firmware: arm_scmi: Register and handle limits change notification
@ 2024-06-03 19:26 ` Sibi Sankar
  0 siblings, 0 replies; 7+ messages in thread
From: Sibi Sankar @ 2024-06-03 19:26 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, rafael, viresh.kumar,
	morten.rasmussen, dietmar.eggemann, lukasz.luba, pierre.gondois,
	vincent.guittot
  Cc: linux-arm-kernel, linux-pm, linux-kernel, quic_mdtipton,
	linux-arm-msm, Sibi Sankar

This series registers for scmi limits change notifications to determine
the throttled frequency and apply HW pressure.

V5:
* Drop patch 1 and use pm_qos to update constraints. [Vincent]
* Use sdev instead of cpu_dev in dev_warn. [Christian]
* Pass sdev directly through private data. [Christian]
* Dropping Rb's for now.

V4:
* Use EXPORT_SYMBOL_GPL instead. [Trilok]
* Use a interim variable to show the khz calc. [Lukasz]
* Use driver_data to pass on the handle and scmi_dev instead of using
  global variables. Dropped Lukasz's Rb due to adding these minor
  changes.

V3:
* Sanitize range_max received from the notifier. [Pierre]
* Drop patches 1/2 from v2. [Cristian]
* Update commit message in patch 2.

V2:
* Rename opp_xlate -> freq_xlate [Viresh]
* Export cpufreq_update_pressure and use it directly [Lukasz]

Sibi Sankar (1):
  cpufreq: scmi: Register for limit change notifications

 drivers/cpufreq/scmi-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

-- 
2.34.1


_______________________________________________
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] 7+ messages in thread

* [PATCH V5 1/1] cpufreq: scmi: Register for limit change notifications
  2024-06-03 19:26 ` Sibi Sankar
@ 2024-06-03 19:26   ` Sibi Sankar
  -1 siblings, 0 replies; 7+ messages in thread
From: Sibi Sankar @ 2024-06-03 19:26 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, rafael, viresh.kumar,
	morten.rasmussen, dietmar.eggemann, lukasz.luba, pierre.gondois,
	vincent.guittot
  Cc: linux-arm-kernel, linux-pm, linux-kernel, quic_mdtipton,
	linux-arm-msm, Sibi Sankar

Register for limit change notifications if supported and use the throttled
frequency from the notification to apply HW pressure.

Signed-off-by: Sibi Sankar <quic_sibis@quicinc.com>
---

v5:
* Drop patch 1 and use pm_qos to update constraints. [Vincent]
* Use sdev instead of cpu_dev in dev_warn. [Christian]
* Pass sdev directly through private data. [Christian]
* Dropping Rb's for now.

 drivers/cpufreq/scmi-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index b87fd127aa43..0edfa55d8e49 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -16,6 +16,7 @@
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/pm_opp.h>
+#include <linux/pm_qos.h>
 #include <linux/slab.h>
 #include <linux/scmi_protocol.h>
 #include <linux/types.h>
@@ -25,7 +26,9 @@ struct scmi_data {
 	int domain_id;
 	int nr_opp;
 	struct device *cpu_dev;
+	struct cpufreq_policy *policy;
 	cpumask_var_t opp_shared_cpus;
+	struct notifier_block limit_notify_nb;
 };
 
 static struct scmi_protocol_handle *ph;
@@ -174,6 +177,25 @@ static struct freq_attr *scmi_cpufreq_hw_attr[] = {
 	NULL,
 };
 
+static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
+{
+	struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
+	struct scmi_perf_limits_report *limit_notify = data;
+	struct cpufreq_policy *policy = priv->policy;
+	unsigned int limit_freq_khz;
+	int ret;
+
+	limit_freq_khz = limit_notify->range_max_freq / HZ_PER_KHZ;
+
+	policy->max = clamp(limit_freq_khz, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
+
+	ret = freq_qos_update_request(policy->max_freq_req, policy->max);
+	if (ret < 0)
+		pr_warn("failed to update freq constraint: %d\n", ret);
+
+	return NOTIFY_OK;
+}
+
 static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 {
 	int ret, nr_opp, domain;
@@ -181,6 +203,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct scmi_data *priv;
 	struct cpufreq_frequency_table *freq_table;
+	struct scmi_device *sdev = cpufreq_get_driver_data();
 
 	cpu_dev = get_cpu_device(policy->cpu);
 	if (!cpu_dev) {
@@ -294,6 +317,17 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 		}
 	}
 
+	priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb;
+	ret = sdev->handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_PERF,
+							SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
+							&domain,
+							&priv->limit_notify_nb);
+	if (ret)
+		dev_warn(&sdev->dev,
+			 "failed to register for limits change notifier for domain %d\n", domain);
+
+	priv->policy = policy;
+
 	return 0;
 
 out_free_opp:
@@ -372,6 +406,8 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
 	if (!handle)
 		return -ENODEV;
 
+	scmi_cpufreq_driver.driver_data = sdev;
+
 	perf_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_PERF, &ph);
 	if (IS_ERR(perf_ops))
 		return PTR_ERR(perf_ops);
-- 
2.34.1


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

* [PATCH V5 1/1] cpufreq: scmi: Register for limit change notifications
@ 2024-06-03 19:26   ` Sibi Sankar
  0 siblings, 0 replies; 7+ messages in thread
From: Sibi Sankar @ 2024-06-03 19:26 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, rafael, viresh.kumar,
	morten.rasmussen, dietmar.eggemann, lukasz.luba, pierre.gondois,
	vincent.guittot
  Cc: linux-arm-kernel, linux-pm, linux-kernel, quic_mdtipton,
	linux-arm-msm, Sibi Sankar

Register for limit change notifications if supported and use the throttled
frequency from the notification to apply HW pressure.

Signed-off-by: Sibi Sankar <quic_sibis@quicinc.com>
---

v5:
* Drop patch 1 and use pm_qos to update constraints. [Vincent]
* Use sdev instead of cpu_dev in dev_warn. [Christian]
* Pass sdev directly through private data. [Christian]
* Dropping Rb's for now.

 drivers/cpufreq/scmi-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index b87fd127aa43..0edfa55d8e49 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -16,6 +16,7 @@
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/pm_opp.h>
+#include <linux/pm_qos.h>
 #include <linux/slab.h>
 #include <linux/scmi_protocol.h>
 #include <linux/types.h>
@@ -25,7 +26,9 @@ struct scmi_data {
 	int domain_id;
 	int nr_opp;
 	struct device *cpu_dev;
+	struct cpufreq_policy *policy;
 	cpumask_var_t opp_shared_cpus;
+	struct notifier_block limit_notify_nb;
 };
 
 static struct scmi_protocol_handle *ph;
@@ -174,6 +177,25 @@ static struct freq_attr *scmi_cpufreq_hw_attr[] = {
 	NULL,
 };
 
+static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
+{
+	struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
+	struct scmi_perf_limits_report *limit_notify = data;
+	struct cpufreq_policy *policy = priv->policy;
+	unsigned int limit_freq_khz;
+	int ret;
+
+	limit_freq_khz = limit_notify->range_max_freq / HZ_PER_KHZ;
+
+	policy->max = clamp(limit_freq_khz, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
+
+	ret = freq_qos_update_request(policy->max_freq_req, policy->max);
+	if (ret < 0)
+		pr_warn("failed to update freq constraint: %d\n", ret);
+
+	return NOTIFY_OK;
+}
+
 static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 {
 	int ret, nr_opp, domain;
@@ -181,6 +203,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	struct scmi_data *priv;
 	struct cpufreq_frequency_table *freq_table;
+	struct scmi_device *sdev = cpufreq_get_driver_data();
 
 	cpu_dev = get_cpu_device(policy->cpu);
 	if (!cpu_dev) {
@@ -294,6 +317,17 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 		}
 	}
 
+	priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb;
+	ret = sdev->handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_PERF,
+							SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
+							&domain,
+							&priv->limit_notify_nb);
+	if (ret)
+		dev_warn(&sdev->dev,
+			 "failed to register for limits change notifier for domain %d\n", domain);
+
+	priv->policy = policy;
+
 	return 0;
 
 out_free_opp:
@@ -372,6 +406,8 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
 	if (!handle)
 		return -ENODEV;
 
+	scmi_cpufreq_driver.driver_data = sdev;
+
 	perf_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_PERF, &ph);
 	if (IS_ERR(perf_ops))
 		return PTR_ERR(perf_ops);
-- 
2.34.1


_______________________________________________
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] 7+ messages in thread

* Re: [PATCH V5 1/1] cpufreq: scmi: Register for limit change notifications
  2024-06-03 19:26   ` Sibi Sankar
  (?)
@ 2024-10-16 23:45   ` Mike Tipton
  -1 siblings, 0 replies; 7+ messages in thread
From: Mike Tipton @ 2024-10-16 23:45 UTC (permalink / raw)
  To: Sibi Sankar
  Cc: sudeep.holla, cristian.marussi, rafael, viresh.kumar,
	morten.rasmussen, dietmar.eggemann, lukasz.luba, pierre.gondois,
	vincent.guittot, linux-arm-kernel, linux-pm, linux-kernel,
	linux-arm-msm

On Tue, Jun 04, 2024 at 12:56:54AM +0530, Sibi Sankar wrote:
> Register for limit change notifications if supported and use the throttled
> frequency from the notification to apply HW pressure.
> 
> Signed-off-by: Sibi Sankar <quic_sibis@quicinc.com>
> ---
> 
> v5:
> * Drop patch 1 and use pm_qos to update constraints. [Vincent]
> * Use sdev instead of cpu_dev in dev_warn. [Christian]
> * Pass sdev directly through private data. [Christian]
> * Dropping Rb's for now.
> 
>  drivers/cpufreq/scmi-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)

Tested-by: Mike Tipton <quic_mdtipton@quicinc.com>

> 
> diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
> index b87fd127aa43..0edfa55d8e49 100644
> --- a/drivers/cpufreq/scmi-cpufreq.c
> +++ b/drivers/cpufreq/scmi-cpufreq.c
> @@ -16,6 +16,7 @@
>  #include <linux/export.h>
>  #include <linux/module.h>
>  #include <linux/pm_opp.h>
> +#include <linux/pm_qos.h>
>  #include <linux/slab.h>
>  #include <linux/scmi_protocol.h>
>  #include <linux/types.h>
> @@ -25,7 +26,9 @@ struct scmi_data {
>  	int domain_id;
>  	int nr_opp;
>  	struct device *cpu_dev;
> +	struct cpufreq_policy *policy;
>  	cpumask_var_t opp_shared_cpus;
> +	struct notifier_block limit_notify_nb;
>  };
>  
>  static struct scmi_protocol_handle *ph;
> @@ -174,6 +177,25 @@ static struct freq_attr *scmi_cpufreq_hw_attr[] = {
>  	NULL,
>  };
>  
> +static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
> +{
> +	struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
> +	struct scmi_perf_limits_report *limit_notify = data;
> +	struct cpufreq_policy *policy = priv->policy;
> +	unsigned int limit_freq_khz;
> +	int ret;
> +
> +	limit_freq_khz = limit_notify->range_max_freq / HZ_PER_KHZ;
> +
> +	policy->max = clamp(limit_freq_khz, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
> +
> +	ret = freq_qos_update_request(policy->max_freq_req, policy->max);
> +	if (ret < 0)
> +		pr_warn("failed to update freq constraint: %d\n", ret);

This would be better as a dev_warn() with the cpu device. Other than
that, looks good to me.

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

* Re: [PATCH V5 1/1] cpufreq: scmi: Register for limit change notifications
  2024-06-03 19:26   ` Sibi Sankar
  (?)
  (?)
@ 2024-10-30  9:32   ` Cristian Marussi
  2024-10-30  9:55     ` Lukasz Luba
  -1 siblings, 1 reply; 7+ messages in thread
From: Cristian Marussi @ 2024-10-30  9:32 UTC (permalink / raw)
  To: Sibi Sankar
  Cc: sudeep.holla, cristian.marussi, rafael, viresh.kumar,
	morten.rasmussen, dietmar.eggemann, lukasz.luba, pierre.gondois,
	vincent.guittot, linux-arm-kernel, linux-pm, linux-kernel,
	quic_mdtipton, linux-arm-msm

On Tue, Jun 04, 2024 at 12:56:54AM +0530, Sibi Sankar wrote:
> Register for limit change notifications if supported and use the throttled
> frequency from the notification to apply HW pressure.
> 

This sort of got lost in mbox...apologies.

As discussed offlist, the issue with cpufreq and multiple SCMI instances
remains BUT it will be solved later on with a different approach, so
as of now this LGTM.

Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>

Thanks,
Cristian

P.S.: have you got any chance to try the hack/experimental patch I CCed
you to address the multi/instance cpufreq issues ? (just to understand
if it is a viable option...)


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

* Re: [PATCH V5 1/1] cpufreq: scmi: Register for limit change notifications
  2024-10-30  9:32   ` Cristian Marussi
@ 2024-10-30  9:55     ` Lukasz Luba
  0 siblings, 0 replies; 7+ messages in thread
From: Lukasz Luba @ 2024-10-30  9:55 UTC (permalink / raw)
  To: Cristian Marussi, Sibi Sankar
  Cc: sudeep.holla, rafael, viresh.kumar, morten.rasmussen,
	dietmar.eggemann, pierre.gondois, vincent.guittot,
	linux-arm-kernel, linux-pm, linux-kernel, quic_mdtipton,
	linux-arm-msm



On 10/30/24 09:32, Cristian Marussi wrote:
> On Tue, Jun 04, 2024 at 12:56:54AM +0530, Sibi Sankar wrote:
>> Register for limit change notifications if supported and use the throttled
>> frequency from the notification to apply HW pressure.
>>
> 
> This sort of got lost in mbox...apologies.
> 
> As discussed offlist, the issue with cpufreq and multiple SCMI instances
> remains BUT it will be solved later on with a different approach, so
> as of now this LGTM.
> 
> Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>

Thank you Cristian for re-visiting this.

That code also LGTM and fits into my other construction built on top
of it [1] [2]. I had a talk with Rafael below that [1] about this
subject patch.

Feel free to add:

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

[1] 
https://lore.kernel.org/lkml/20241029094452.495439-1-lukasz.luba@arm.com/
[2] 
https://lore.kernel.org/lkml/20240403162315.1458337-1-lukasz.luba@arm.com/


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

end of thread, other threads:[~2024-10-30  9:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-03 19:26 [PATCH V5 0/1] firmware: arm_scmi: Register and handle limits change notification Sibi Sankar
2024-06-03 19:26 ` Sibi Sankar
2024-06-03 19:26 ` [PATCH V5 1/1] cpufreq: scmi: Register for limit change notifications Sibi Sankar
2024-06-03 19:26   ` Sibi Sankar
2024-10-16 23:45   ` Mike Tipton
2024-10-30  9:32   ` Cristian Marussi
2024-10-30  9:55     ` Lukasz Luba

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.