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

cpufreq: Simplify userspace governor

Userspace governor has got more code than what it needs for its
functioning, so simplify it.

Portions of code removed are:
- Extra header files which aren't required anymore (rearrange them
as well).
- cpu_{max|min|cur|set}_freq, as they are always the same as
policy->{max|min|cur}.
- userspace_cpufreq_notifier_block as we don't need to set
cpu_cur_freq anymore.
- cpus_using_userspace_governor as it was for the notifier code.

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
d1922f02 7fb6a53d

+13 -97
+13 -97
drivers/cpufreq/cpufreq_userspace.c
··· 13 13 14 14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 15 16 - #include <linux/kernel.h> 17 - #include <linux/module.h> 18 - #include <linux/smp.h> 19 - #include <linux/init.h> 20 - #include <linux/spinlock.h> 21 - #include <linux/interrupt.h> 22 16 #include <linux/cpufreq.h> 23 - #include <linux/cpu.h> 24 - #include <linux/types.h> 25 - #include <linux/fs.h> 26 - #include <linux/sysfs.h> 17 + #include <linux/init.h> 18 + #include <linux/module.h> 27 19 #include <linux/mutex.h> 28 20 29 - /** 30 - * A few values needed by the userspace governor 31 - */ 32 - static DEFINE_PER_CPU(unsigned int, cpu_max_freq); 33 - static DEFINE_PER_CPU(unsigned int, cpu_min_freq); 34 - static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */ 35 - static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by 36 - userspace */ 37 21 static DEFINE_PER_CPU(unsigned int, cpu_is_managed); 38 - 39 22 static DEFINE_MUTEX(userspace_mutex); 40 - static int cpus_using_userspace_governor; 41 - 42 - /* keep track of frequency transitions */ 43 - static int 44 - userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, 45 - void *data) 46 - { 47 - struct cpufreq_freqs *freq = data; 48 - 49 - if (!per_cpu(cpu_is_managed, freq->cpu)) 50 - return 0; 51 - 52 - if (val == CPUFREQ_POSTCHANGE) { 53 - pr_debug("saving cpu_cur_freq of cpu %u to be %u kHz\n", 54 - freq->cpu, freq->new); 55 - per_cpu(cpu_cur_freq, freq->cpu) = freq->new; 56 - } 57 - 58 - return 0; 59 - } 60 - 61 - static struct notifier_block userspace_cpufreq_notifier_block = { 62 - .notifier_call = userspace_cpufreq_notifier 63 - }; 64 - 65 23 66 24 /** 67 25 * cpufreq_set - set the CPU frequency ··· 37 79 mutex_lock(&userspace_mutex); 38 80 if (!per_cpu(cpu_is_managed, policy->cpu)) 39 81 goto err; 40 - 41 - per_cpu(cpu_set_freq, policy->cpu) = freq; 42 - 43 - if (freq < per_cpu(cpu_min_freq, policy->cpu)) 44 - freq = per_cpu(cpu_min_freq, policy->cpu); 45 - if (freq > per_cpu(cpu_max_freq, policy->cpu)) 46 - freq = per_cpu(cpu_max_freq, policy->cpu); 47 82 48 83 /* 49 84 * We're safe from concurrent calls to ->target() here ··· 58 107 59 108 static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) 60 109 { 61 - return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu)); 110 + return sprintf(buf, "%u\n", policy->cur); 62 111 } 63 112 64 113 static int cpufreq_governor_userspace(struct cpufreq_policy *policy, ··· 70 119 switch (event) { 71 120 case CPUFREQ_GOV_START: 72 121 BUG_ON(!policy->cur); 122 + pr_debug("started managing cpu %u\n", cpu); 123 + 73 124 mutex_lock(&userspace_mutex); 74 - 75 - if (cpus_using_userspace_governor == 0) { 76 - cpufreq_register_notifier( 77 - &userspace_cpufreq_notifier_block, 78 - CPUFREQ_TRANSITION_NOTIFIER); 79 - } 80 - cpus_using_userspace_governor++; 81 - 82 125 per_cpu(cpu_is_managed, cpu) = 1; 83 - per_cpu(cpu_min_freq, cpu) = policy->min; 84 - per_cpu(cpu_max_freq, cpu) = policy->max; 85 - per_cpu(cpu_cur_freq, cpu) = policy->cur; 86 - per_cpu(cpu_set_freq, cpu) = policy->cur; 87 - pr_debug("managing cpu %u started " 88 - "(%u - %u kHz, currently %u kHz)\n", 89 - cpu, 90 - per_cpu(cpu_min_freq, cpu), 91 - per_cpu(cpu_max_freq, cpu), 92 - per_cpu(cpu_cur_freq, cpu)); 93 - 94 126 mutex_unlock(&userspace_mutex); 95 127 break; 96 128 case CPUFREQ_GOV_STOP: 97 - mutex_lock(&userspace_mutex); 98 - cpus_using_userspace_governor--; 99 - if (cpus_using_userspace_governor == 0) { 100 - cpufreq_unregister_notifier( 101 - &userspace_cpufreq_notifier_block, 102 - CPUFREQ_TRANSITION_NOTIFIER); 103 - } 104 - 105 - per_cpu(cpu_is_managed, cpu) = 0; 106 - per_cpu(cpu_min_freq, cpu) = 0; 107 - per_cpu(cpu_max_freq, cpu) = 0; 108 - per_cpu(cpu_set_freq, cpu) = 0; 109 129 pr_debug("managing cpu %u stopped\n", cpu); 130 + 131 + mutex_lock(&userspace_mutex); 132 + per_cpu(cpu_is_managed, cpu) = 0; 110 133 mutex_unlock(&userspace_mutex); 111 134 break; 112 135 case CPUFREQ_GOV_LIMITS: 113 136 mutex_lock(&userspace_mutex); 114 - pr_debug("limit event for cpu %u: %u - %u kHz, " 115 - "currently %u kHz, last set to %u kHz\n", 137 + pr_debug("limit event for cpu %u: %u - %u kHz, currently %u kHz\n", 116 138 cpu, policy->min, policy->max, 117 - per_cpu(cpu_cur_freq, cpu), 118 - per_cpu(cpu_set_freq, cpu)); 119 - if (policy->max < per_cpu(cpu_set_freq, cpu)) { 139 + policy->cur); 140 + 141 + if (policy->max < policy->cur) 120 142 __cpufreq_driver_target(policy, policy->max, 121 143 CPUFREQ_RELATION_H); 122 - } else if (policy->min > per_cpu(cpu_set_freq, cpu)) { 144 + else if (policy->min > policy->cur) 123 145 __cpufreq_driver_target(policy, policy->min, 124 146 CPUFREQ_RELATION_L); 125 - } else { 126 - __cpufreq_driver_target(policy, 127 - per_cpu(cpu_set_freq, cpu), 128 - CPUFREQ_RELATION_L); 129 - } 130 - per_cpu(cpu_min_freq, cpu) = policy->min; 131 - per_cpu(cpu_max_freq, cpu) = policy->max; 132 - per_cpu(cpu_cur_freq, cpu) = policy->cur; 133 147 mutex_unlock(&userspace_mutex); 134 148 break; 135 149 }