cpufreq: create cpu/cpufreq at boot time
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 15 Oct 2015 16:05:22 +0000 (21:35 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 28 Oct 2015 08:21:12 +0000 (09:21 +0100)
Later patches will need to create policy specific directories in
/sys/devices/system/cpu/cpufreq/ directory and so the cpufreq directory
wouldn't be ever empty.

And so no fun creating/destroying it on need basis anymore. Create it
once on system boot.

Reviewed-by: Saravana Kannan <skannan@codeaurora.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c
drivers/cpufreq/cpufreq_governor.c
include/linux/cpufreq.h

index 16b9e811ff01115eae1c3dd05bd018c773a0c85a..c1fd57db50bdc878540770b327f3ac5ffe9d93d0 100644 (file)
@@ -876,43 +876,15 @@ static struct kobj_type ktype_cpufreq = {
 struct kobject *cpufreq_global_kobject;
 EXPORT_SYMBOL(cpufreq_global_kobject);
 
-static int cpufreq_global_kobject_usage;
-
-int cpufreq_get_global_kobject(void)
-{
-       if (!cpufreq_global_kobject_usage++)
-               return kobject_add(cpufreq_global_kobject,
-                               &cpu_subsys.dev_root->kobj, "%s", "cpufreq");
-
-       return 0;
-}
-EXPORT_SYMBOL(cpufreq_get_global_kobject);
-
-void cpufreq_put_global_kobject(void)
-{
-       if (!--cpufreq_global_kobject_usage)
-               kobject_del(cpufreq_global_kobject);
-}
-EXPORT_SYMBOL(cpufreq_put_global_kobject);
-
 int cpufreq_sysfs_create_file(const struct attribute *attr)
 {
-       int ret = cpufreq_get_global_kobject();
-
-       if (!ret) {
-               ret = sysfs_create_file(cpufreq_global_kobject, attr);
-               if (ret)
-                       cpufreq_put_global_kobject();
-       }
-
-       return ret;
+       return sysfs_create_file(cpufreq_global_kobject, attr);
 }
 EXPORT_SYMBOL(cpufreq_sysfs_create_file);
 
 void cpufreq_sysfs_remove_file(const struct attribute *attr)
 {
        sysfs_remove_file(cpufreq_global_kobject, attr);
-       cpufreq_put_global_kobject();
 }
 EXPORT_SYMBOL(cpufreq_sysfs_remove_file);
 
@@ -2582,7 +2554,7 @@ static int __init cpufreq_core_init(void)
        if (cpufreq_disabled())
                return -ENODEV;
 
-       cpufreq_global_kobject = kobject_create();
+       cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
        BUG_ON(!cpufreq_global_kobject);
 
        register_syscore_ops(&cpufreq_syscore_ops);
index 750626d8fb0322547d7e86a2c3fc1270b9957d48..11258c4c1b175be37827c201a8d7a422a5d3eda3 100644 (file)
@@ -348,29 +348,21 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy,
        set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate,
                                        latency * LATENCY_MULTIPLIER));
 
-       if (!have_governor_per_policy()) {
-               if (WARN_ON(cpufreq_get_global_kobject())) {
-                       ret = -EINVAL;
-                       goto cdata_exit;
-               }
+       if (!have_governor_per_policy())
                cdata->gdbs_data = dbs_data;
-       }
 
        ret = sysfs_create_group(get_governor_parent_kobj(policy),
                                 get_sysfs_attr(dbs_data));
        if (ret)
-               goto put_kobj;
+               goto reset_gdbs_data;
 
        policy->governor_data = dbs_data;
 
        return 0;
 
-put_kobj:
-       if (!have_governor_per_policy()) {
+reset_gdbs_data:
+       if (!have_governor_per_policy())
                cdata->gdbs_data = NULL;
-               cpufreq_put_global_kobject();
-       }
-cdata_exit:
        cdata->exit(dbs_data, !policy->governor->initialized);
 free_common_dbs_info:
        free_common_dbs_info(policy, cdata);
@@ -394,10 +386,8 @@ static int cpufreq_governor_exit(struct cpufreq_policy *policy,
                sysfs_remove_group(get_governor_parent_kobj(policy),
                                   get_sysfs_attr(dbs_data));
 
-               if (!have_governor_per_policy()) {
+               if (!have_governor_per_policy())
                        cdata->gdbs_data = NULL;
-                       cpufreq_put_global_kobject();
-               }
 
                cdata->exit(dbs_data, policy->governor->initialized == 1);
                kfree(dbs_data);
index dca22de98d948480141c5806680ef167b35a7555..338bf0e59bb8d3a6e7dabde97a84436907388258 100644 (file)
@@ -149,8 +149,6 @@ static inline bool policy_is_shared(struct cpufreq_policy *policy)
 
 /* /sys/devices/system/cpu/cpufreq: entry point for global variables */
 extern struct kobject *cpufreq_global_kobject;
-int cpufreq_get_global_kobject(void);
-void cpufreq_put_global_kobject(void);
 int cpufreq_sysfs_create_file(const struct attribute *attr);
 void cpufreq_sysfs_remove_file(const struct attribute *attr);