2024-01-17 10:51:22

by Sibi Sankar

[permalink] [raw]
Subject: [PATCH V2 0/4] firmware: arm_scmi: Register and handle limits change notification

This series registers for scmi limits change notifications and adds
perf_notify_support/perf_opp_xlate interfaces which are used by the
scmi cpufreq driver to determine the throttled frequency and apply HW
pressure.

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

Depends on:
HW pressure v4: https://patchwork.kernel.org/project/linux-arm-msm/cover/[email protected]/

Sibi Sankar (4):
firmware: arm_scmi: Add perf_notify_support interface
firmware: arm_scmi: Add perf_freq_xlate interface
cpufreq: Export cpufreq_update_pressure
cpufreq: scmi: Register for limit change notifications

drivers/cpufreq/cpufreq.c | 3 ++-
drivers/cpufreq/scmi-cpufreq.c | 42 +++++++++++++++++++++++++++++++-
drivers/firmware/arm_scmi/perf.c | 37 ++++++++++++++++++++++++++++
include/linux/cpufreq.h | 2 ++
include/linux/scmi_protocol.h | 11 +++++++++
5 files changed, 93 insertions(+), 2 deletions(-)

--
2.34.1



2024-01-17 10:56:26

by Sibi Sankar

[permalink] [raw]
Subject: [PATCH V2 4/4] cpufreq: scmi: Register for limit change notifications

Register for limit change notifications if supported with the help of
perf_notify_support interface and determine the throttled frequency
using the perf_freq_xlate to apply HW pressure.

Signed-off-by: Sibi Sankar <[email protected]>
---

v2:
* Export cpufreq_update_pressure and use it directly [Lukasz]

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

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index 4ee23f4ebf4a..e0aa85764451 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -25,9 +25,13 @@ 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;
};

+const struct scmi_handle *handle;
+static struct scmi_device *scmi_dev;
static struct scmi_protocol_handle *ph;
static const struct scmi_perf_proto_ops *perf_ops;

@@ -144,6 +148,22 @@ scmi_get_cpu_power(struct device *cpu_dev, unsigned long *power,
return 0;
}

+static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
+{
+ unsigned long freq_hz;
+ struct scmi_perf_limits_report *limit_notify = data;
+ struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
+ struct cpufreq_policy *policy = priv->policy;
+
+ if (perf_ops->perf_freq_xlate(ph, priv->domain_id, limit_notify->range_max, &freq_hz))
+ return NOTIFY_OK;
+
+ policy->max = freq_hz / HZ_PER_KHZ;
+ cpufreq_update_pressure(policy);
+
+ return NOTIFY_OK;
+}
+
static int scmi_cpufreq_init(struct cpufreq_policy *policy)
{
int ret, nr_opp, domain;
@@ -151,6 +171,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_perf_notify_info info = {};

cpu_dev = get_cpu_device(policy->cpu);
if (!cpu_dev) {
@@ -250,6 +271,25 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
policy->fast_switch_possible =
perf_ops->fast_switch_possible(ph, domain);

+ ret = perf_ops->perf_notify_support(ph, domain, &info);
+ if (ret)
+ dev_warn(cpu_dev, "failed to get supported notifications: %d\n", ret);
+
+ if (info.perf_limit_notify) {
+ priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb;
+ ret = handle->notify_ops->devm_event_notifier_register(scmi_dev, SCMI_PROTOCOL_PERF,
+ SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
+ &domain,
+ &priv->limit_notify_nb);
+ if (ret) {
+ dev_err(cpu_dev, "Error in registering limit change notifier for domain %d\n",
+ domain);
+ return ret;
+ }
+ }
+
+ priv->policy = policy;
+
return 0;

out_free_opp:
@@ -321,8 +361,8 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
{
int ret;
struct device *dev = &sdev->dev;
- const struct scmi_handle *handle;

+ scmi_dev = sdev;
handle = sdev->handle;

if (!handle)
--
2.34.1


2024-01-17 10:56:37

by Sibi Sankar

[permalink] [raw]
Subject: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface

Add a new perf_notify_support interface to the existing perf_ops to export
info regarding limit/level change notification support.

Signed-off-by: Sibi Sankar <[email protected]>
---
drivers/firmware/arm_scmi/perf.c | 16 ++++++++++++++++
include/linux/scmi_protocol.h | 8 ++++++++
2 files changed, 24 insertions(+)

diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
index 211e8e0aef2c..ae7681eda276 100644
--- a/drivers/firmware/arm_scmi/perf.c
+++ b/drivers/firmware/arm_scmi/perf.c
@@ -962,6 +962,21 @@ scmi_power_scale_get(const struct scmi_protocol_handle *ph)
return pi->power_scale;
}

+static int scmi_notify_support(const struct scmi_protocol_handle *ph, u32 domain,
+ struct scmi_perf_notify_info *info)
+{
+ struct perf_dom_info *dom;
+
+ dom = scmi_perf_domain_lookup(ph, domain);
+ if (IS_ERR(dom))
+ return -EINVAL;
+
+ info->perf_limit_notify = dom->perf_limit_notify;
+ info->perf_level_notify = dom->perf_level_notify;
+
+ return 0;
+}
+
static const struct scmi_perf_proto_ops perf_proto_ops = {
.num_domains_get = scmi_perf_num_domains_get,
.info_get = scmi_perf_info_get,
@@ -976,6 +991,7 @@ static const struct scmi_perf_proto_ops perf_proto_ops = {
.est_power_get = scmi_dvfs_est_power_get,
.fast_switch_possible = scmi_fast_switch_possible,
.power_scale_get = scmi_power_scale_get,
+ .perf_notify_support = scmi_notify_support,
};

static int scmi_perf_set_notify_enabled(const struct scmi_protocol_handle *ph,
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index f2f05fb42d28..b0947d004826 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -117,6 +117,11 @@ struct scmi_perf_domain_info {
bool set_perf;
};

+struct scmi_perf_notify_info {
+ bool perf_limit_notify;
+ bool perf_level_notify;
+};
+
/**
* struct scmi_perf_proto_ops - represents the various operations provided
* by SCMI Performance Protocol
@@ -139,6 +144,7 @@ struct scmi_perf_domain_info {
* for a given device
* @power_scale_mw_get: indicates if the power values provided are in milliWatts
* or in some other (abstract) scale
+ * @perf_notify_support: indicates if limit and level change notification is supported
*/
struct scmi_perf_proto_ops {
int (*num_domains_get)(const struct scmi_protocol_handle *ph);
@@ -165,6 +171,8 @@ struct scmi_perf_proto_ops {
bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
u32 domain);
enum scmi_power_scale (*power_scale_get)(const struct scmi_protocol_handle *ph);
+ int (*perf_notify_support)(const struct scmi_protocol_handle *ph, u32 domain,
+ struct scmi_perf_notify_info *info);
};

/**
--
2.34.1


2024-01-29 15:50:38

by Cristian Marussi

[permalink] [raw]
Subject: Re: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface

On Wed, Jan 17, 2024 at 04:11:13PM +0530, Sibi Sankar wrote:
> Add a new perf_notify_support interface to the existing perf_ops to export
> info regarding limit/level change notification support.
>

Hi Sibi,

as I mentioned previously, in order not to add a needless stream of SCMI
Perf accessors I posted this:

https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u

to expose all the Perf domains infos via the usual info_get(), similarly
to how other SCMI protocols do already.

I think that reworking this series on that, you can certainly drop this patch and just
check the _notify booleans on the retrieved domain info.

Thanks,
Cristian

2024-01-29 16:00:08

by Cristian Marussi

[permalink] [raw]
Subject: Re: [PATCH V2 4/4] cpufreq: scmi: Register for limit change notifications

On Wed, Jan 17, 2024 at 04:11:16PM +0530, Sibi Sankar wrote:
> Register for limit change notifications if supported with the help of
> perf_notify_support interface and determine the throttled frequency
> using the perf_freq_xlate to apply HW pressure.
>
> Signed-off-by: Sibi Sankar <[email protected]>
> ---
>
> v2:
> * Export cpufreq_update_pressure and use it directly [Lukasz]
>
> drivers/cpufreq/scmi-cpufreq.c | 42 +++++++++++++++++++++++++++++++++-
> 1 file changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
> index 4ee23f4ebf4a..e0aa85764451 100644
> --- a/drivers/cpufreq/scmi-cpufreq.c
> +++ b/drivers/cpufreq/scmi-cpufreq.c
> @@ -25,9 +25,13 @@ 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;
> };
>
> +const struct scmi_handle *handle;
> +static struct scmi_device *scmi_dev;
> static struct scmi_protocol_handle *ph;
> static const struct scmi_perf_proto_ops *perf_ops;
>
> @@ -144,6 +148,22 @@ scmi_get_cpu_power(struct device *cpu_dev, unsigned long *power,
> return 0;
> }
>
> +static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
> +{
> + unsigned long freq_hz;
> + struct scmi_perf_limits_report *limit_notify = data;
> + struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
> + struct cpufreq_policy *policy = priv->policy;
> +
> + if (perf_ops->perf_freq_xlate(ph, priv->domain_id, limit_notify->range_max, &freq_hz))
> + return NOTIFY_OK;
> +
> + policy->max = freq_hz / HZ_PER_KHZ;
> + cpufreq_update_pressure(policy);
> +
> + return NOTIFY_OK;
> +}
> +
> static int scmi_cpufreq_init(struct cpufreq_policy *policy)
> {
> int ret, nr_opp, domain;
> @@ -151,6 +171,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_perf_notify_info info = {};
>
> cpu_dev = get_cpu_device(policy->cpu);
> if (!cpu_dev) {
> @@ -250,6 +271,25 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
> policy->fast_switch_possible =
> perf_ops->fast_switch_possible(ph, domain);
>
> + ret = perf_ops->perf_notify_support(ph, domain, &info);
> + if (ret)
> + dev_warn(cpu_dev, "failed to get supported notifications: %d\n", ret);
> +
> + if (info.perf_limit_notify) {
> + priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb;
> + ret = handle->notify_ops->devm_event_notifier_register(scmi_dev, SCMI_PROTOCOL_PERF,
> + SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
> + &domain,
> + &priv->limit_notify_nb);
> + if (ret) {
> + dev_err(cpu_dev, "Error in registering limit change notifier for domain %d\n",
> + domain);
> + return ret;
> + }

Is there a reason to fail completely here if it was not possible to register
the notifier ? (even though expected to succeed given perf_limit_notify
was true...)

Maybe a big fat warn that the system perf could be degraded, but
carrying on ?

Or maybe you have in mind a good reason to fail like you did, so please
explain in that case in a comment.

Thanks,
Cristian

2024-01-29 17:33:59

by Cristian Marussi

[permalink] [raw]
Subject: Re: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface

On Mon, Jan 29, 2024 at 03:50:20PM +0000, Cristian Marussi wrote:
> On Wed, Jan 17, 2024 at 04:11:13PM +0530, Sibi Sankar wrote:
> > Add a new perf_notify_support interface to the existing perf_ops to export
> > info regarding limit/level change notification support.
> >
>
> Hi Sibi,
>
> as I mentioned previously, in order not to add a needless stream of SCMI
> Perf accessors I posted this:
>
> https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
>
> to expose all the Perf domains infos via the usual info_get(), similarly
> to how other SCMI protocols do already.
>
> I think that reworking this series on that, you can certainly drop this patch and just
> check the _notify booleans on the retrieved domain info.

Sorry, but hold on with this change, I will probably post an updated version
my patch above.

Thanks,
Cristian

2024-01-31 11:29:15

by Sudeep Holla

[permalink] [raw]
Subject: Re: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface

On Mon, Jan 29, 2024 at 05:33:42PM +0000, Cristian Marussi wrote:
> On Mon, Jan 29, 2024 at 03:50:20PM +0000, Cristian Marussi wrote:
> > On Wed, Jan 17, 2024 at 04:11:13PM +0530, Sibi Sankar wrote:
> > > Add a new perf_notify_support interface to the existing perf_ops to export
> > > info regarding limit/level change notification support.
> > >
> >
> > Hi Sibi,
> >
> > as I mentioned previously, in order not to add a needless stream of SCMI
> > Perf accessors I posted this:
> >
> > https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
> >
> > to expose all the Perf domains infos via the usual info_get(), similarly
> > to how other SCMI protocols do already.
> >
> > I think that reworking this series on that, you can certainly drop this patch and just
> > check the _notify booleans on the retrieved domain info.
>
> Sorry, but hold on with this change, I will probably post an updated version
> my patch above.
>

As discussed in private, I would prefer to avoid exposing all the internals
to the users of SCMI perf. At the same time may we can do better if we can
check the availability of notification as part of notification enablement
from the SCMI driver, I need to think the details yet.

--
Regards,
Sudeep

2024-01-31 12:01:32

by Cristian Marussi

[permalink] [raw]
Subject: Re: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface

On Wed, Jan 31, 2024 at 11:28:54AM +0000, Sudeep Holla wrote:
> On Mon, Jan 29, 2024 at 05:33:42PM +0000, Cristian Marussi wrote:
> > On Mon, Jan 29, 2024 at 03:50:20PM +0000, Cristian Marussi wrote:
> > > On Wed, Jan 17, 2024 at 04:11:13PM +0530, Sibi Sankar wrote:
> > > > Add a new perf_notify_support interface to the existing perf_ops to export
> > > > info regarding limit/level change notification support.
> > > >
> > >
> > > Hi Sibi,
> > >
> > > as I mentioned previously, in order not to add a needless stream of SCMI
> > > Perf accessors I posted this:
> > >
> > > https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
> > >
> > > to expose all the Perf domains infos via the usual info_get(), similarly
> > > to how other SCMI protocols do already.
> > >
> > > I think that reworking this series on that, you can certainly drop this patch and just
> > > check the _notify booleans on the retrieved domain info.
> >
> > Sorry, but hold on with this change, I will probably post an updated version
> > my patch above.
> >
>
> As discussed in private, I would prefer to avoid exposing all the internals
> to the users of SCMI perf. At the same time may we can do better if we can
> check the availability of notification as part of notification enablement
> from the SCMI driver, I need to think the details yet.

Yes a patch is under-work to avoid exposing too much Perf info AND to
avoid adding ad-hoc accessors like xlate, in this case.

Thanks,
Cristian

2024-01-31 14:29:43

by Pierre Gondois

[permalink] [raw]
Subject: Re: [PATCH V2 4/4] cpufreq: scmi: Register for limit change notifications

Hello Sibi,

On 1/17/24 11:41, Sibi Sankar wrote:
> Register for limit change notifications if supported with the help of
> perf_notify_support interface and determine the throttled frequency
> using the perf_freq_xlate to apply HW pressure.
>
> Signed-off-by: Sibi Sankar <[email protected]>
> ---
>
> v2:
> * Export cpufreq_update_pressure and use it directly [Lukasz]
>
> drivers/cpufreq/scmi-cpufreq.c | 42 +++++++++++++++++++++++++++++++++-
> 1 file changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
> index 4ee23f4ebf4a..e0aa85764451 100644
> --- a/drivers/cpufreq/scmi-cpufreq.c
> +++ b/drivers/cpufreq/scmi-cpufreq.c
> @@ -25,9 +25,13 @@ 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;
> };
>
> +const struct scmi_handle *handle;
> +static struct scmi_device *scmi_dev;
> static struct scmi_protocol_handle *ph;
> static const struct scmi_perf_proto_ops *perf_ops;
>
> @@ -144,6 +148,22 @@ scmi_get_cpu_power(struct device *cpu_dev, unsigned long *power,
> return 0;
> }
>
> +static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
> +{
> + unsigned long freq_hz;
> + struct scmi_perf_limits_report *limit_notify = data;
> + struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
> + struct cpufreq_policy *policy = priv->policy;
> +
> + if (perf_ops->perf_freq_xlate(ph, priv->domain_id, limit_notify->range_max, &freq_hz))
> + return NOTIFY_OK;
> +
> + policy->max = freq_hz / HZ_PER_KHZ;

Maybe 'policy->max' should be checked. The limits received by SCMI is blindly
trusted. This might be ok, but could also lead to some inconsistency.

The scmi_cpufreq_driver's verify() callback could be used.

---

I think there might also be corner cases where the SCP might advertise
the maximum boosted frequency as the max limit, but boosting might not
be enabled on the kernel side.
So I think this should be checked when setting 'policy->max',

Regards,
Pierre

> + cpufreq_update_pressure(policy);
> +
> + return NOTIFY_OK;
> +}
> +
> static int scmi_cpufreq_init(struct cpufreq_policy *policy)
> {
> int ret, nr_opp, domain;
> @@ -151,6 +171,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_perf_notify_info info = {};
>
> cpu_dev = get_cpu_device(policy->cpu);
> if (!cpu_dev) {
> @@ -250,6 +271,25 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
> policy->fast_switch_possible =
> perf_ops->fast_switch_possible(ph, domain);
>
> + ret = perf_ops->perf_notify_support(ph, domain, &info);
> + if (ret)
> + dev_warn(cpu_dev, "failed to get supported notifications: %d\n", ret);
> +
> + if (info.perf_limit_notify) {
> + priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb;
> + ret = handle->notify_ops->devm_event_notifier_register(scmi_dev, SCMI_PROTOCOL_PERF,
> + SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
> + &domain,
> + &priv->limit_notify_nb);
> + if (ret) {
> + dev_err(cpu_dev, "Error in registering limit change notifier for domain %d\n",
> + domain);
> + return ret;
> + }
> + }
> +
> + priv->policy = policy;
> +
> return 0;
>
> out_free_opp:
> @@ -321,8 +361,8 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
> {
> int ret;
> struct device *dev = &sdev->dev;
> - const struct scmi_handle *handle;
>
> + scmi_dev = sdev;
> handle = sdev->handle;
>
> if (!handle)

2024-02-12 13:06:06

by Cristian Marussi

[permalink] [raw]
Subject: Re: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface

On Wed, Jan 31, 2024 at 11:28:54AM +0000, Sudeep Holla wrote:
> On Mon, Jan 29, 2024 at 05:33:42PM +0000, Cristian Marussi wrote:

Hi Sibi,

> > On Mon, Jan 29, 2024 at 03:50:20PM +0000, Cristian Marussi wrote:
> > > On Wed, Jan 17, 2024 at 04:11:13PM +0530, Sibi Sankar wrote:
> > > > Add a new perf_notify_support interface to the existing perf_ops to export
> > > > info regarding limit/level change notification support.
> > > >
> > >
> > > Hi Sibi,
> > >
> > > as I mentioned previously, in order not to add a needless stream of SCMI
> > > Perf accessors I posted this:
> > >
> > > https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
> > >
> > > to expose all the Perf domains infos via the usual info_get(), similarly
> > > to how other SCMI protocols do already.
> > >
> > > I think that reworking this series on that, you can certainly drop this patch and just
> > > check the _notify booleans on the retrieved domain info.
> >
> > Sorry, but hold on with this change, I will probably post an updated version
> > my patch above.
> >
>
> As discussed in private, I would prefer to avoid exposing all the internals
> to the users of SCMI perf. At the same time may we can do better if we can
> check the availability of notification as part of notification enablement
> from the SCMI driver, I need to think the details yet.
>

as previously mentioned, after speaking with Sudeep, I posted a new
series at [1], that aims to solve your problem with registering
notifications and looking up reported Perf frequencies in a new way.

Using the changes at [1] you should be able to:

- register your notifier without caring to check if the notification
is supported, since the SCMI core will take care of checking that and
report an error if not supported, without sending any unneeded
attempted notification enable message (so you can drop 1/4 in this
series)

- retrieve the pre-calculated OPPs frequencies from the new extended
Perf notifications reports no matter if the system if operating in
level_indexing_mode or not. (so you can drop 2/4 in this series)

Thanks,
Cristian

[1]: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#ma68cefd753e34ba3e1f2d4392e978026a87e1bf8


2024-02-13 05:43:11

by Sibi Sankar

[permalink] [raw]
Subject: Re: [PATCH V2 4/4] cpufreq: scmi: Register for limit change notifications



On 1/29/24 21:29, Cristian Marussi wrote:
> On Wed, Jan 17, 2024 at 04:11:16PM +0530, Sibi Sankar wrote:
>> Register for limit change notifications if supported with the help of
>> perf_notify_support interface and determine the throttled frequency
>> using the perf_freq_xlate to apply HW pressure.
>>

Christian,

Thanks for taking time to review the series.

>> Signed-off-by: Sibi Sankar <[email protected]>
>> ---
>>
>> v2:
>> * Export cpufreq_update_pressure and use it directly [Lukasz]
>>
>> drivers/cpufreq/scmi-cpufreq.c | 42 +++++++++++++++++++++++++++++++++-
>> 1 file changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
>> index 4ee23f4ebf4a..e0aa85764451 100644
>> --- a/drivers/cpufreq/scmi-cpufreq.c
>> +++ b/drivers/cpufreq/scmi-cpufreq.c
>> @@ -25,9 +25,13 @@ 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;
>> };
>>
>> +const struct scmi_handle *handle;
>> +static struct scmi_device *scmi_dev;
>> static struct scmi_protocol_handle *ph;
>> static const struct scmi_perf_proto_ops *perf_ops;
>>
>> @@ -144,6 +148,22 @@ scmi_get_cpu_power(struct device *cpu_dev, unsigned long *power,
>> return 0;
>> }
>>
>> +static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data)
>> +{
>> + unsigned long freq_hz;
>> + struct scmi_perf_limits_report *limit_notify = data;
>> + struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb);
>> + struct cpufreq_policy *policy = priv->policy;
>> +
>> + if (perf_ops->perf_freq_xlate(ph, priv->domain_id, limit_notify->range_max, &freq_hz))
>> + return NOTIFY_OK;
>> +
>> + policy->max = freq_hz / HZ_PER_KHZ;
>> + cpufreq_update_pressure(policy);
>> +
>> + return NOTIFY_OK;
>> +}
>> +
>> static int scmi_cpufreq_init(struct cpufreq_policy *policy)
>> {
>> int ret, nr_opp, domain;
>> @@ -151,6 +171,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_perf_notify_info info = {};
>>
>> cpu_dev = get_cpu_device(policy->cpu);
>> if (!cpu_dev) {
>> @@ -250,6 +271,25 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
>> policy->fast_switch_possible =
>> perf_ops->fast_switch_possible(ph, domain);
>>
>> + ret = perf_ops->perf_notify_support(ph, domain, &info);
>> + if (ret)
>> + dev_warn(cpu_dev, "failed to get supported notifications: %d\n", ret);
>> +
>> + if (info.perf_limit_notify) {
>> + priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb;
>> + ret = handle->notify_ops->devm_event_notifier_register(scmi_dev, SCMI_PROTOCOL_PERF,
>> + SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
>> + &domain,
>> + &priv->limit_notify_nb);
>> + if (ret) {
>> + dev_err(cpu_dev, "Error in registering limit change notifier for domain %d\n",
>> + domain);
>> + return ret;
>> + }
>
> Is there a reason to fail completely here if it was not possible to register
> the notifier ? (even though expected to succeed given perf_limit_notify
> was true...)
>
> Maybe a big fat warn that the system perf could be degraded, but
> carrying on ?
>
> Or maybe you have in mind a good reason to fail like you did, so please
> explain in that case in a comment.

ack a warn should suffice here

-Sibi

>
> Thanks,
> Cristian

2024-02-13 05:46:22

by Sibi Sankar

[permalink] [raw]
Subject: Re: [PATCH V2 1/4] firmware: arm_scmi: Add perf_notify_support interface



On 2/12/24 18:14, Cristian Marussi wrote:
> On Wed, Jan 31, 2024 at 11:28:54AM +0000, Sudeep Holla wrote:
>> On Mon, Jan 29, 2024 at 05:33:42PM +0000, Cristian Marussi wrote:
>
> Hi Sibi,
>
>>> On Mon, Jan 29, 2024 at 03:50:20PM +0000, Cristian Marussi wrote:
>>>> On Wed, Jan 17, 2024 at 04:11:13PM +0530, Sibi Sankar wrote:
>>>>> Add a new perf_notify_support interface to the existing perf_ops to export
>>>>> info regarding limit/level change notification support.
>>>>>
>>>>
>>>> Hi Sibi,
>>>>
>>>> as I mentioned previously, in order not to add a needless stream of SCMI
>>>> Perf accessors I posted this:
>>>>
>>>> https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
>>>>
>>>> to expose all the Perf domains infos via the usual info_get(), similarly
>>>> to how other SCMI protocols do already.
>>>>
>>>> I think that reworking this series on that, you can certainly drop this patch and just
>>>> check the _notify booleans on the retrieved domain info.
>>>
>>> Sorry, but hold on with this change, I will probably post an updated version
>>> my patch above.
>>>
>>
>> As discussed in private, I would prefer to avoid exposing all the internals
>> to the users of SCMI perf. At the same time may we can do better if we can
>> check the availability of notification as part of notification enablement
>> from the SCMI driver, I need to think the details yet.
>>
>
> as previously mentioned, after speaking with Sudeep, I posted a new
> series at [1], that aims to solve your problem with registering
> notifications and looking up reported Perf frequencies in a new way.
>
> Using the changes at [1] you should be able to:
>
> - register your notifier without caring to check if the notification
> is supported, since the SCMI core will take care of checking that and
> report an error if not supported, without sending any unneeded
> attempted notification enable message (so you can drop 1/4 in this
> series)
>
> - retrieve the pre-calculated OPPs frequencies from the new extended
> Perf notifications reports no matter if the system if operating in
> level_indexing_mode or not. (so you can drop 2/4 in this series)

Christian/Sudeep,

Thanks a lot for spending time on this and simplifying the series.

Will re-spin the series with your recommendations.

-Sibi

>
> Thanks,
> Cristian
>
> [1]: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#ma68cefd753e34ba3e1f2d4392e978026a87e1bf8
>

2024-02-13 05:46:32

by Sibi Sankar

[permalink] [raw]
Subject: Re: [PATCH V2 4/4] cpufreq: scmi: Register for limit change notifications



On 1/31/24 19:59, Pierre Gondois wrote:
> Hello Sibi,
>
> On 1/17/24 11:41, Sibi Sankar wrote:
>> Register for limit change notifications if supported with the help of
>> perf_notify_support interface and determine the throttled frequency
>> using the perf_freq_xlate to apply HW pressure.
>>

Hey Pierre,

Thanks for taking time to review the series.

>> Signed-off-by: Sibi Sankar <[email protected]>
>> ---
>>
>> v2:
>> * Export cpufreq_update_pressure and use it directly [Lukasz]
>>
>>   drivers/cpufreq/scmi-cpufreq.c | 42 +++++++++++++++++++++++++++++++++-
>>   1 file changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/scmi-cpufreq.c
>> b/drivers/cpufreq/scmi-cpufreq.c
>> index 4ee23f4ebf4a..e0aa85764451 100644
>> --- a/drivers/cpufreq/scmi-cpufreq.c
>> +++ b/drivers/cpufreq/scmi-cpufreq.c
>> @@ -25,9 +25,13 @@ 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;
>>   };
>> +const struct scmi_handle *handle;
>> +static struct scmi_device *scmi_dev;
>>   static struct scmi_protocol_handle *ph;
>>   static const struct scmi_perf_proto_ops *perf_ops;
>> @@ -144,6 +148,22 @@ scmi_get_cpu_power(struct device *cpu_dev,
>> unsigned long *power,
>>       return 0;
>>   }
>> +static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned
>> long event, void *data)
>> +{
>> +    unsigned long freq_hz;
>> +    struct scmi_perf_limits_report *limit_notify = data;
>> +    struct scmi_data *priv = container_of(nb, struct scmi_data,
>> limit_notify_nb);
>> +    struct cpufreq_policy *policy = priv->policy;
>> +
>> +    if (perf_ops->perf_freq_xlate(ph, priv->domain_id,
>> limit_notify->range_max, &freq_hz))
>> +        return NOTIFY_OK;
>> +
>> +    policy->max = freq_hz / HZ_PER_KHZ;
>
> Maybe 'policy->max' should be checked. The limits received by SCMI is
> blindly
> trusted. This might be ok, but could also lead to some inconsistency.
>
> The scmi_cpufreq_driver's verify() callback could be used.

ack, will fix this in the next re-spin.

>
> ---
>
> I think there might also be corner cases where the SCP might advertise
> the maximum boosted frequency as the max limit, but boosting might not
> be enabled on the kernel side.
> So I think this should be checked when setting 'policy->max',

ack

-Sibi
>
> Regards,
> Pierre
>
[...]
>>       if (!handle)