Commit 2361be23666232dbb4851a527f466c4cbf5340fc
Committed by
Rafael J. Wysocki
1 parent
72a4ce340a
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
cpufreq: Don't create empty /sys/devices/system/cpu/cpufreq directory
When we don't have any file in cpu/cpufreq directory we shouldn't create it. Specially with the introduction of per-policy governor instance patchset, even governors are moved to cpu/cpu*/cpufreq/governor-name directory and so this directory is just not required. Lets have it only when required. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Showing 4 changed files with 56 additions and 6 deletions Side-by-side Diff
drivers/cpufreq/acpi-cpufreq.c
... | ... | @@ -947,7 +947,7 @@ |
947 | 947 | /* We create the boost file in any case, though for systems without |
948 | 948 | * hardware support it will be read-only and hardwired to return 0. |
949 | 949 | */ |
950 | - if (sysfs_create_file(cpufreq_global_kobject, &(global_boost.attr))) | |
950 | + if (cpufreq_sysfs_create_file(&(global_boost.attr))) | |
951 | 951 | pr_warn(PFX "could not register global boost sysfs file\n"); |
952 | 952 | else |
953 | 953 | pr_debug("registered global boost sysfs file\n"); |
... | ... | @@ -955,7 +955,7 @@ |
955 | 955 | |
956 | 956 | static void __exit acpi_cpufreq_boost_exit(void) |
957 | 957 | { |
958 | - sysfs_remove_file(cpufreq_global_kobject, &(global_boost.attr)); | |
958 | + cpufreq_sysfs_remove_file(&(global_boost.attr)); | |
959 | 959 | |
960 | 960 | if (msrs) { |
961 | 961 | unregister_cpu_notifier(&boost_nb); |
drivers/cpufreq/cpufreq.c
... | ... | @@ -678,9 +678,6 @@ |
678 | 678 | NULL |
679 | 679 | }; |
680 | 680 | |
681 | -struct kobject *cpufreq_global_kobject; | |
682 | -EXPORT_SYMBOL(cpufreq_global_kobject); | |
683 | - | |
684 | 681 | #define to_policy(k) container_of(k, struct cpufreq_policy, kobj) |
685 | 682 | #define to_attr(a) container_of(a, struct freq_attr, attr) |
686 | 683 | |
... | ... | @@ -751,6 +748,49 @@ |
751 | 748 | .release = cpufreq_sysfs_release, |
752 | 749 | }; |
753 | 750 | |
751 | +struct kobject *cpufreq_global_kobject; | |
752 | +EXPORT_SYMBOL(cpufreq_global_kobject); | |
753 | + | |
754 | +static int cpufreq_global_kobject_usage; | |
755 | + | |
756 | +int cpufreq_get_global_kobject(void) | |
757 | +{ | |
758 | + if (!cpufreq_global_kobject_usage++) | |
759 | + return kobject_add(cpufreq_global_kobject, | |
760 | + &cpu_subsys.dev_root->kobj, "%s", "cpufreq"); | |
761 | + | |
762 | + return 0; | |
763 | +} | |
764 | +EXPORT_SYMBOL(cpufreq_get_global_kobject); | |
765 | + | |
766 | +void cpufreq_put_global_kobject(void) | |
767 | +{ | |
768 | + if (!--cpufreq_global_kobject_usage) | |
769 | + kobject_del(cpufreq_global_kobject); | |
770 | +} | |
771 | +EXPORT_SYMBOL(cpufreq_put_global_kobject); | |
772 | + | |
773 | +int cpufreq_sysfs_create_file(const struct attribute *attr) | |
774 | +{ | |
775 | + int ret = cpufreq_get_global_kobject(); | |
776 | + | |
777 | + if (!ret) { | |
778 | + ret = sysfs_create_file(cpufreq_global_kobject, attr); | |
779 | + if (ret) | |
780 | + cpufreq_put_global_kobject(); | |
781 | + } | |
782 | + | |
783 | + return ret; | |
784 | +} | |
785 | +EXPORT_SYMBOL(cpufreq_sysfs_create_file); | |
786 | + | |
787 | +void cpufreq_sysfs_remove_file(const struct attribute *attr) | |
788 | +{ | |
789 | + sysfs_remove_file(cpufreq_global_kobject, attr); | |
790 | + cpufreq_put_global_kobject(); | |
791 | +} | |
792 | +EXPORT_SYMBOL(cpufreq_sysfs_remove_file); | |
793 | + | |
754 | 794 | /* symlink affected CPUs */ |
755 | 795 | static int cpufreq_add_dev_symlink(unsigned int cpu, |
756 | 796 | struct cpufreq_policy *policy) |
... | ... | @@ -2020,7 +2060,7 @@ |
2020 | 2060 | init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); |
2021 | 2061 | } |
2022 | 2062 | |
2023 | - cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); | |
2063 | + cpufreq_global_kobject = kobject_create(); | |
2024 | 2064 | BUG_ON(!cpufreq_global_kobject); |
2025 | 2065 | register_syscore_ops(&cpufreq_syscore_ops); |
2026 | 2066 |
drivers/cpufreq/cpufreq_governor.c
... | ... | @@ -231,6 +231,9 @@ |
231 | 231 | return rc; |
232 | 232 | } |
233 | 233 | |
234 | + if (!have_governor_per_policy()) | |
235 | + WARN_ON(cpufreq_get_global_kobject()); | |
236 | + | |
234 | 237 | rc = sysfs_create_group(get_governor_parent_kobj(policy), |
235 | 238 | get_sysfs_attr(dbs_data)); |
236 | 239 | if (rc) { |
... | ... | @@ -268,6 +271,9 @@ |
268 | 271 | if (!--dbs_data->usage_count) { |
269 | 272 | sysfs_remove_group(get_governor_parent_kobj(policy), |
270 | 273 | get_sysfs_attr(dbs_data)); |
274 | + | |
275 | + if (!have_governor_per_policy()) | |
276 | + cpufreq_put_global_kobject(); | |
271 | 277 | |
272 | 278 | if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) && |
273 | 279 | (policy->governor->initialized == 1)) { |
include/linux/cpufreq.h
... | ... | @@ -71,6 +71,10 @@ |
71 | 71 | |
72 | 72 | /* /sys/devices/system/cpu/cpufreq: entry point for global variables */ |
73 | 73 | extern struct kobject *cpufreq_global_kobject; |
74 | +int cpufreq_get_global_kobject(void); | |
75 | +void cpufreq_put_global_kobject(void); | |
76 | +int cpufreq_sysfs_create_file(const struct attribute *attr); | |
77 | +void cpufreq_sysfs_remove_file(const struct attribute *attr); | |
74 | 78 | |
75 | 79 | #define CPUFREQ_ETERNAL (-1) |
76 | 80 | struct cpufreq_cpuinfo { |