Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Viresh Kumar and committed by
Rafael J. Wysocki
2361be23 72a4ce34

+56 -6
+2 -2
drivers/cpufreq/acpi-cpufreq.c
··· 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 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);
+44 -4
drivers/cpufreq/cpufreq.c
··· 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 ··· 747 750 .default_attrs = default_attrs, 748 751 .release = cpufreq_sysfs_release, 749 752 }; 753 + 754 + struct kobject *cpufreq_global_kobject; 755 + EXPORT_SYMBOL(cpufreq_global_kobject); 756 + 757 + static int cpufreq_global_kobject_usage; 758 + 759 + int cpufreq_get_global_kobject(void) 760 + { 761 + if (!cpufreq_global_kobject_usage++) 762 + return kobject_add(cpufreq_global_kobject, 763 + &cpu_subsys.dev_root->kobj, "%s", "cpufreq"); 764 + 765 + return 0; 766 + } 767 + EXPORT_SYMBOL(cpufreq_get_global_kobject); 768 + 769 + void cpufreq_put_global_kobject(void) 770 + { 771 + if (!--cpufreq_global_kobject_usage) 772 + kobject_del(cpufreq_global_kobject); 773 + } 774 + EXPORT_SYMBOL(cpufreq_put_global_kobject); 775 + 776 + int cpufreq_sysfs_create_file(const struct attribute *attr) 777 + { 778 + int ret = cpufreq_get_global_kobject(); 779 + 780 + if (!ret) { 781 + ret = sysfs_create_file(cpufreq_global_kobject, attr); 782 + if (ret) 783 + cpufreq_put_global_kobject(); 784 + } 785 + 786 + return ret; 787 + } 788 + EXPORT_SYMBOL(cpufreq_sysfs_create_file); 789 + 790 + void cpufreq_sysfs_remove_file(const struct attribute *attr) 791 + { 792 + sysfs_remove_file(cpufreq_global_kobject, attr); 793 + cpufreq_put_global_kobject(); 794 + } 795 + EXPORT_SYMBOL(cpufreq_sysfs_remove_file); 750 796 751 797 /* symlink affected CPUs */ 752 798 static int cpufreq_add_dev_symlink(unsigned int cpu, ··· 2060 2020 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); 2061 2021 } 2062 2022 2063 - cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); 2023 + cpufreq_global_kobject = kobject_create(); 2064 2024 BUG_ON(!cpufreq_global_kobject); 2065 2025 register_syscore_ops(&cpufreq_syscore_ops); 2066 2026
+6
drivers/cpufreq/cpufreq_governor.c
··· 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) { ··· 271 268 if (!--dbs_data->usage_count) { 272 269 sysfs_remove_group(get_governor_parent_kobj(policy), 273 270 get_sysfs_attr(dbs_data)); 271 + 272 + if (!have_governor_per_policy()) 273 + cpufreq_put_global_kobject(); 274 274 275 275 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) && 276 276 (policy->governor->initialized == 1)) {
+4
include/linux/cpufreq.h
··· 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 {