Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/cpufreq/cpufreq_conservative.c |
| 3 | * |
| 4 | * Copyright (C) 2001 Russell King |
| 5 | * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. |
| 6 | * Jun Nakajima <jun.nakajima@intel.com> |
Alexander Clouter | 11a80a9c76 | 2009-02-13 19:01:01 +0000 | [diff] [blame] | 7 | * (C) 2009 Alexander Clouter <alex@digriz.org.uk> |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 14 | #include <linux/cpufreq.h> |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 17 | #include <linux/kernel_stat.h> |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 18 | #include <linux/kobject.h> |
| 19 | #include <linux/module.h> |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 21 | #include <linux/notifier.h> |
| 22 | #include <linux/percpu-defs.h> |
| 23 | #include <linux/sysfs.h> |
| 24 | #include <linux/types.h> |
Alexander Clouter | 8e677ce | 2009-02-13 19:02:34 +0000 | [diff] [blame] | 25 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 26 | #include "cpufreq_governor.h" |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 27 | |
Stratos Karafotis | c88883c | 2013-02-08 17:24:24 +0000 | [diff] [blame] | 28 | /* Conservative governor macros */ |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 29 | #define DEF_FREQUENCY_UP_THRESHOLD (80) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 30 | #define DEF_FREQUENCY_DOWN_THRESHOLD (20) |
Alexander Clouter | 2c906b3 | 2006-03-22 09:54:10 +0000 | [diff] [blame] | 31 | #define DEF_SAMPLING_DOWN_FACTOR (1) |
| 32 | #define MAX_SAMPLING_DOWN_FACTOR (10) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 33 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 34 | static struct dbs_data cs_dbs_data; |
| 35 | static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 36 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 37 | static struct cs_dbs_tuners cs_tuners = { |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 38 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
| 39 | .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, |
| 40 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, |
| 41 | .ignore_nice = 0, |
| 42 | .freq_step = 5, |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 45 | /* |
| 46 | * Every sampling_rate, we check, if current idle time is less than 20% |
| 47 | * (default), then we try to increase frequency Every sampling_rate * |
| 48 | * sampling_down_factor, we check, if current idle time is more than 80%, then |
| 49 | * we try to decrease frequency |
| 50 | * |
| 51 | * Any frequency increase takes it to the maximum frequency. Frequency reduction |
| 52 | * happens at minimum steps of 5% (default) of maximum frequency |
| 53 | */ |
| 54 | static void cs_check_cpu(int cpu, unsigned int load) |
Elias Oltmanns | a8d7c3b | 2007-10-22 09:50:13 +0200 | [diff] [blame] | 55 | { |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 56 | struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu); |
| 57 | struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy; |
| 58 | unsigned int freq_target; |
Alexander Clouter | f407a08 | 2009-02-13 19:01:51 +0000 | [diff] [blame] | 59 | |
| 60 | /* |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 61 | * break out if we 'cannot' reduce the speed as the user might |
| 62 | * want freq_step to be zero |
| 63 | */ |
| 64 | if (cs_tuners.freq_step == 0) |
| 65 | return; |
| 66 | |
| 67 | /* Check for frequency increase */ |
| 68 | if (load > cs_tuners.up_threshold) { |
| 69 | dbs_info->down_skip = 0; |
| 70 | |
| 71 | /* if we are already at full speed then break out early */ |
| 72 | if (dbs_info->requested_freq == policy->max) |
| 73 | return; |
| 74 | |
| 75 | freq_target = (cs_tuners.freq_step * policy->max) / 100; |
| 76 | |
| 77 | /* max freq cannot be less than 100. But who knows.... */ |
| 78 | if (unlikely(freq_target == 0)) |
| 79 | freq_target = 5; |
| 80 | |
| 81 | dbs_info->requested_freq += freq_target; |
| 82 | if (dbs_info->requested_freq > policy->max) |
| 83 | dbs_info->requested_freq = policy->max; |
| 84 | |
| 85 | __cpufreq_driver_target(policy, dbs_info->requested_freq, |
| 86 | CPUFREQ_RELATION_H); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * The optimal frequency is the frequency that is the lowest that can |
| 92 | * support the current CPU usage without triggering the up policy. To be |
| 93 | * safe, we focus 10 points under the threshold. |
| 94 | */ |
| 95 | if (load < (cs_tuners.down_threshold - 10)) { |
| 96 | freq_target = (cs_tuners.freq_step * policy->max) / 100; |
| 97 | |
| 98 | dbs_info->requested_freq -= freq_target; |
| 99 | if (dbs_info->requested_freq < policy->min) |
| 100 | dbs_info->requested_freq = policy->min; |
| 101 | |
| 102 | /* |
| 103 | * if we cannot reduce the frequency anymore, break out early |
| 104 | */ |
| 105 | if (policy->cur == policy->min) |
| 106 | return; |
| 107 | |
| 108 | __cpufreq_driver_target(policy, dbs_info->requested_freq, |
| 109 | CPUFREQ_RELATION_H); |
| 110 | return; |
| 111 | } |
| 112 | } |
| 113 | |
Fabio Baltieri | 66df2a01 | 2012-12-27 14:55:41 +0000 | [diff] [blame] | 114 | static void cs_dbs_timer(struct work_struct *work) |
| 115 | { |
| 116 | struct delayed_work *dw = to_delayed_work(work); |
| 117 | struct cs_cpu_dbs_info_s *dbs_info = container_of(work, |
| 118 | struct cs_cpu_dbs_info_s, cdbs.work.work); |
Viresh Kumar | 4447266 | 2013-01-31 17:28:02 +0000 | [diff] [blame] | 119 | unsigned int cpu = dbs_info->cdbs.cur_policy->cpu; |
| 120 | struct cs_cpu_dbs_info_s *core_dbs_info = &per_cpu(cs_cpu_dbs_info, |
| 121 | cpu); |
| 122 | int delay = delay_for_sampling_rate(cs_tuners.sampling_rate); |
Fabio Baltieri | 66df2a01 | 2012-12-27 14:55:41 +0000 | [diff] [blame] | 123 | |
Viresh Kumar | 4447266 | 2013-01-31 17:28:02 +0000 | [diff] [blame] | 124 | mutex_lock(&core_dbs_info->cdbs.timer_mutex); |
| 125 | if (need_load_eval(&core_dbs_info->cdbs, cs_tuners.sampling_rate)) |
| 126 | dbs_check_cpu(&cs_dbs_data, cpu); |
| 127 | |
| 128 | schedule_delayed_work_on(smp_processor_id(), dw, delay); |
| 129 | mutex_unlock(&core_dbs_info->cdbs.timer_mutex); |
Fabio Baltieri | 66df2a01 | 2012-12-27 14:55:41 +0000 | [diff] [blame] | 130 | } |
Viresh Kumar | 4447266 | 2013-01-31 17:28:02 +0000 | [diff] [blame] | 131 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 132 | static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, |
| 133 | void *data) |
| 134 | { |
| 135 | struct cpufreq_freqs *freq = data; |
| 136 | struct cs_cpu_dbs_info_s *dbs_info = |
| 137 | &per_cpu(cs_cpu_dbs_info, freq->cpu); |
| 138 | struct cpufreq_policy *policy; |
| 139 | |
| 140 | if (!dbs_info->enable) |
| 141 | return 0; |
| 142 | |
| 143 | policy = dbs_info->cdbs.cur_policy; |
| 144 | |
| 145 | /* |
| 146 | * we only care if our internally tracked freq moves outside the 'valid' |
Stratos Karafotis | c88883c | 2013-02-08 17:24:24 +0000 | [diff] [blame] | 147 | * ranges of frequency available to us otherwise we do not change it |
Alexander Clouter | f407a08 | 2009-02-13 19:01:51 +0000 | [diff] [blame] | 148 | */ |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 149 | if (dbs_info->requested_freq > policy->max |
| 150 | || dbs_info->requested_freq < policy->min) |
| 151 | dbs_info->requested_freq = freq->new; |
Elias Oltmanns | a8d7c3b | 2007-10-22 09:50:13 +0200 | [diff] [blame] | 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 156 | /************************** sysfs interface ************************/ |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 157 | static ssize_t show_sampling_rate_min(struct kobject *kobj, |
| 158 | struct attribute *attr, char *buf) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 159 | { |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 160 | return sprintf(buf, "%u\n", cs_dbs_data.min_sampling_rate); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 163 | static ssize_t store_sampling_down_factor(struct kobject *a, |
| 164 | struct attribute *b, |
| 165 | const char *buf, size_t count) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 166 | { |
| 167 | unsigned int input; |
| 168 | int ret; |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 169 | ret = sscanf(buf, "%u", &input); |
Alexander Clouter | 8e677ce | 2009-02-13 19:02:34 +0000 | [diff] [blame] | 170 | |
Alexander Clouter | 2c906b3 | 2006-03-22 09:54:10 +0000 | [diff] [blame] | 171 | if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 172 | return -EINVAL; |
| 173 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 174 | cs_tuners.sampling_down_factor = input; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 175 | return count; |
| 176 | } |
| 177 | |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 178 | static ssize_t store_sampling_rate(struct kobject *a, struct attribute *b, |
| 179 | const char *buf, size_t count) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 180 | { |
| 181 | unsigned int input; |
| 182 | int ret; |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 183 | ret = sscanf(buf, "%u", &input); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 184 | |
Alexander Clouter | 8e677ce | 2009-02-13 19:02:34 +0000 | [diff] [blame] | 185 | if (ret != 1) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 186 | return -EINVAL; |
Alexander Clouter | 8e677ce | 2009-02-13 19:02:34 +0000 | [diff] [blame] | 187 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 188 | cs_tuners.sampling_rate = max(input, cs_dbs_data.min_sampling_rate); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 189 | return count; |
| 190 | } |
| 191 | |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 192 | static ssize_t store_up_threshold(struct kobject *a, struct attribute *b, |
| 193 | const char *buf, size_t count) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 194 | { |
| 195 | unsigned int input; |
| 196 | int ret; |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 197 | ret = sscanf(buf, "%u", &input); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 198 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 199 | if (ret != 1 || input > 100 || input <= cs_tuners.down_threshold) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 200 | return -EINVAL; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 201 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 202 | cs_tuners.up_threshold = input; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 203 | return count; |
| 204 | } |
| 205 | |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 206 | static ssize_t store_down_threshold(struct kobject *a, struct attribute *b, |
| 207 | const char *buf, size_t count) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 208 | { |
| 209 | unsigned int input; |
| 210 | int ret; |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 211 | ret = sscanf(buf, "%u", &input); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 212 | |
Alexander Clouter | 8e677ce | 2009-02-13 19:02:34 +0000 | [diff] [blame] | 213 | /* cannot be lower than 11 otherwise freq will not fall */ |
| 214 | if (ret != 1 || input < 11 || input > 100 || |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 215 | input >= cs_tuners.up_threshold) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 216 | return -EINVAL; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 217 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 218 | cs_tuners.down_threshold = input; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 219 | return count; |
| 220 | } |
| 221 | |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 222 | static ssize_t store_ignore_nice_load(struct kobject *a, struct attribute *b, |
| 223 | const char *buf, size_t count) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 224 | { |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 225 | unsigned int input, j; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 226 | int ret; |
| 227 | |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 228 | ret = sscanf(buf, "%u", &input); |
| 229 | if (ret != 1) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 230 | return -EINVAL; |
| 231 | |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 232 | if (input > 1) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 233 | input = 1; |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 234 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 235 | if (input == cs_tuners.ignore_nice) /* nothing to do */ |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 236 | return count; |
Thomas Renninger | 326c86d | 2011-03-03 21:31:27 +0100 | [diff] [blame] | 237 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 238 | cs_tuners.ignore_nice = input; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 239 | |
Alexander Clouter | 8e677ce | 2009-02-13 19:02:34 +0000 | [diff] [blame] | 240 | /* we need to re-evaluate prev_cpu_idle */ |
Dave Jones | dac1c1a | 2005-05-31 19:03:49 -0700 | [diff] [blame] | 241 | for_each_online_cpu(j) { |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 242 | struct cs_cpu_dbs_info_s *dbs_info; |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 243 | dbs_info = &per_cpu(cs_cpu_dbs_info, j); |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 244 | dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j, |
| 245 | &dbs_info->cdbs.prev_cpu_wall); |
| 246 | if (cs_tuners.ignore_nice) |
| 247 | dbs_info->cdbs.prev_cpu_nice = |
| 248 | kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 249 | } |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 250 | return count; |
| 251 | } |
| 252 | |
Thomas Renninger | 49b015c | 2009-10-01 19:49:28 +0200 | [diff] [blame] | 253 | static ssize_t store_freq_step(struct kobject *a, struct attribute *b, |
| 254 | const char *buf, size_t count) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 255 | { |
| 256 | unsigned int input; |
| 257 | int ret; |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 258 | ret = sscanf(buf, "%u", &input); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 259 | |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 260 | if (ret != 1) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 261 | return -EINVAL; |
| 262 | |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 263 | if (input > 100) |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 264 | input = 100; |
Dave Jones | 18a7247 | 2007-10-22 16:49:09 -0400 | [diff] [blame] | 265 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 266 | /* |
| 267 | * no need to test here if freq_step is zero as the user might actually |
| 268 | * want this, they would be crazy though :) |
| 269 | */ |
| 270 | cs_tuners.freq_step = input; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 271 | return count; |
| 272 | } |
| 273 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 274 | show_one(cs, sampling_rate, sampling_rate); |
| 275 | show_one(cs, sampling_down_factor, sampling_down_factor); |
| 276 | show_one(cs, up_threshold, up_threshold); |
| 277 | show_one(cs, down_threshold, down_threshold); |
| 278 | show_one(cs, ignore_nice_load, ignore_nice); |
| 279 | show_one(cs, freq_step, freq_step); |
| 280 | |
Borislav Petkov | 6dad2a2 | 2010-03-31 21:56:46 +0200 | [diff] [blame] | 281 | define_one_global_rw(sampling_rate); |
| 282 | define_one_global_rw(sampling_down_factor); |
| 283 | define_one_global_rw(up_threshold); |
| 284 | define_one_global_rw(down_threshold); |
| 285 | define_one_global_rw(ignore_nice_load); |
| 286 | define_one_global_rw(freq_step); |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 287 | define_one_global_ro(sampling_rate_min); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 288 | |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 289 | static struct attribute *dbs_attributes[] = { |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 290 | &sampling_rate_min.attr, |
| 291 | &sampling_rate.attr, |
| 292 | &sampling_down_factor.attr, |
| 293 | &up_threshold.attr, |
| 294 | &down_threshold.attr, |
Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 295 | &ignore_nice_load.attr, |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 296 | &freq_step.attr, |
| 297 | NULL |
| 298 | }; |
| 299 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 300 | static struct attribute_group cs_attr_group = { |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 301 | .attrs = dbs_attributes, |
| 302 | .name = "conservative", |
| 303 | }; |
| 304 | |
| 305 | /************************** sysfs end ************************/ |
| 306 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 307 | define_get_cpu_dbs_routines(cs_cpu_dbs_info); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 308 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 309 | static struct notifier_block cs_cpufreq_notifier_block = { |
| 310 | .notifier_call = dbs_cpufreq_notifier, |
| 311 | }; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 312 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 313 | static struct cs_ops cs_ops = { |
| 314 | .notifier_block = &cs_cpufreq_notifier_block, |
| 315 | }; |
Alexander Clouter | 08a28e2 | 2006-03-22 09:59:16 +0000 | [diff] [blame] | 316 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 317 | static struct dbs_data cs_dbs_data = { |
| 318 | .governor = GOV_CONSERVATIVE, |
| 319 | .attr_group = &cs_attr_group, |
| 320 | .tuners = &cs_tuners, |
| 321 | .get_cpu_cdbs = get_cpu_cdbs, |
| 322 | .get_cpu_dbs_info_s = get_cpu_dbs_info_s, |
| 323 | .gov_dbs_timer = cs_dbs_timer, |
| 324 | .gov_check_cpu = cs_check_cpu, |
| 325 | .gov_ops = &cs_ops, |
| 326 | }; |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 327 | |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 328 | static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy, |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 329 | unsigned int event) |
| 330 | { |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 331 | return cpufreq_governor_dbs(&cs_dbs_data, policy, event); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Sven Wegener | c4d14bc | 2008-09-20 16:50:08 +0200 | [diff] [blame] | 334 | #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE |
| 335 | static |
| 336 | #endif |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 337 | struct cpufreq_governor cpufreq_gov_conservative = { |
| 338 | .name = "conservative", |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 339 | .governor = cs_cpufreq_governor_dbs, |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 340 | .max_transition_latency = TRANSITION_LATENCY_LIMIT, |
| 341 | .owner = THIS_MODULE, |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | static int __init cpufreq_gov_dbs_init(void) |
| 345 | { |
Viresh Kumar | 4471a34 | 2012-10-26 00:47:42 +0200 | [diff] [blame] | 346 | mutex_init(&cs_dbs_data.mutex); |
Tejun Heo | 57df557 | 2011-01-26 12:12:50 +0100 | [diff] [blame] | 347 | return cpufreq_register_governor(&cpufreq_gov_conservative); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void __exit cpufreq_gov_dbs_exit(void) |
| 351 | { |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 352 | cpufreq_unregister_governor(&cpufreq_gov_conservative); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Alexander Clouter | 11a80a9c76 | 2009-02-13 19:01:01 +0000 | [diff] [blame] | 355 | MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>"); |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 356 | MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for " |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 357 | "Low Latency Frequency Transition capable processors " |
| 358 | "optimised for use in a battery environment"); |
Dave Jones | 9acef48 | 2009-01-18 01:39:51 -0500 | [diff] [blame] | 359 | MODULE_LICENSE("GPL"); |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 360 | |
Johannes Weiner | 6915719 | 2008-01-17 15:21:08 -0800 | [diff] [blame] | 361 | #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE |
| 362 | fs_initcall(cpufreq_gov_dbs_init); |
| 363 | #else |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 364 | module_init(cpufreq_gov_dbs_init); |
Johannes Weiner | 6915719 | 2008-01-17 15:21:08 -0800 | [diff] [blame] | 365 | #endif |
Dave Jones | b917083 | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 366 | module_exit(cpufreq_gov_dbs_exit); |