diff mbox series

[01/33] cpufreq: Always create freq-table related sysfs file

Message ID 22b68afa4ce5a0a2e77bb3a08e1cb7ac75f70f72.1737631669.git.viresh.kumar@linaro.org (mailing list archive)
State New
Delegated to: viresh kumar
Headers show
Series cpufreq: manage common sysfs attributes from core | expand

Commit Message

Viresh Kumar Jan. 23, 2025, 11:35 a.m. UTC
Currently it is left for the individual drivers to set the available and
boost frequencies related attributes in the cpufreq_driver->attr field.
Some drivers provide them, while others don't.

A quick search revealed that only the drivers that set the
policy->freq_table field, enable these attributes. Which makes sense as
well, since the show_available_freqs() helper works only if the
freq_table is present.

In order to simplify drivers, create the relevant sysfs files forcefully
from cpufreq core.

For now, skip adding them twice. This can be removed once all the
drivers are updated.

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

Comments

Rafael J. Wysocki Jan. 23, 2025, 7:39 p.m. UTC | #1
On Thu, Jan 23, 2025 at 12:38 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> Currently it is left for the individual drivers to set the available and
> boost frequencies related attributes in the cpufreq_driver->attr field.
> Some drivers provide them, while others don't.
>
> A quick search revealed that only the drivers that set the
> policy->freq_table field, enable these attributes. Which makes sense as
> well, since the show_available_freqs() helper works only if the
> freq_table is present.
>
> In order to simplify drivers, create the relevant sysfs files forcefully
> from cpufreq core.
>
> For now, skip adding them twice. This can be removed once all the
> drivers are updated.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

> ---
>  drivers/cpufreq/cpufreq.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 1a4cae54a01b..973bd6e4bdd4 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1058,9 +1058,31 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
>         struct freq_attr **drv_attr;
>         int ret = 0;
>
> +       /* Attributes that need freq_table */
> +       if (policy->freq_table) {
> +               ret = sysfs_create_file(&policy->kobj,
> +                               &cpufreq_freq_attr_scaling_available_freqs.attr);
> +               if (ret)
> +                       return ret;
> +
> +               if (cpufreq_boost_supported()) {
> +                       ret = sysfs_create_file(&policy->kobj,
> +                               &cpufreq_freq_attr_scaling_boost_freqs.attr);
> +                       if (ret)
> +                               return ret;
> +               }
> +       }
> +
>         /* set up files for this cpu device */
>         drv_attr = cpufreq_driver->attr;
>         while (drv_attr && *drv_attr) {
> +               /* These are already added, skip them */
> +               if (*drv_attr == &cpufreq_freq_attr_scaling_available_freqs ||
> +                   *drv_attr == &cpufreq_freq_attr_scaling_boost_freqs) {
> +                       drv_attr++;
> +                       continue;
> +               }
> +
>                 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
>                 if (ret)
>                         return ret;
> --
> 2.31.1.272.g89b43f80a514
>
diff mbox series

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 1a4cae54a01b..973bd6e4bdd4 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1058,9 +1058,31 @@  static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
 	struct freq_attr **drv_attr;
 	int ret = 0;
 
+	/* Attributes that need freq_table */
+	if (policy->freq_table) {
+		ret = sysfs_create_file(&policy->kobj,
+				&cpufreq_freq_attr_scaling_available_freqs.attr);
+		if (ret)
+			return ret;
+
+		if (cpufreq_boost_supported()) {
+			ret = sysfs_create_file(&policy->kobj,
+				&cpufreq_freq_attr_scaling_boost_freqs.attr);
+			if (ret)
+				return ret;
+		}
+	}
+
 	/* set up files for this cpu device */
 	drv_attr = cpufreq_driver->attr;
 	while (drv_attr && *drv_attr) {
+		/* These are already added, skip them */
+		if (*drv_attr == &cpufreq_freq_attr_scaling_available_freqs ||
+		    *drv_attr == &cpufreq_freq_attr_scaling_boost_freqs) {
+			drv_attr++;
+			continue;
+		}
+
 		ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
 		if (ret)
 			return ret;