| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/cpufreq/cpufreq_ondemand.c |
| 3 | * |
| 4 | * Copyright (C) 2001 Russell King |
| 5 | * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. |
| 6 | * Jun Nakajima <jun.nakajima@intel.com> |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 7 | * (c) 2013 The Linux Foundation. All rights reserved. |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -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 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/cpufreq.h> |
| Andrew Morton | 138a0128 | 2006-06-23 03:31:19 -0700 | [diff] [blame] | 18 | #include <linux/cpu.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/jiffies.h> |
| 20 | #include <linux/kernel_stat.h> |
| akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 21 | #include <linux/mutex.h> |
| venkatesh.pallipadi@intel.com | 8080091 | 2008-08-04 11:59:12 -0700 | [diff] [blame] | 22 | #include <linux/hrtimer.h> |
| 23 | #include <linux/tick.h> |
| 24 | #include <linux/ktime.h> |
| myfluxi | 5ece427 | 2014-02-06 21:14:57 +0100 | [diff] [blame] | 25 | #include <linux/smpboot.h> |
| Thomas Renninger | 9411b4e | 2009-02-04 11:54:04 +0100 | [diff] [blame] | 26 | #include <linux/sched.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | #include <linux/input.h> |
| 28 | #include <linux/workqueue.h> |
| 29 | #include <linux/slab.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * dbs is used in this file as a shortform for demandbased switching |
| 33 | * It helps to keep variable names smaller, simpler |
| 34 | */ |
| 35 | |
| venkatesh.pallipadi@intel.com | e9d95bf | 2008-08-04 11:59:10 -0700 | [diff] [blame] | 36 | #define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define DEF_FREQUENCY_UP_THRESHOLD (80) |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 38 | #define DEF_SAMPLING_DOWN_FACTOR (1) |
| 39 | #define MAX_SAMPLING_DOWN_FACTOR (100000) |
| venkatesh.pallipadi@intel.com | 8080091 | 2008-08-04 11:59:12 -0700 | [diff] [blame] | 40 | #define MICRO_FREQUENCY_DOWN_DIFFERENTIAL (3) |
| 41 | #define MICRO_FREQUENCY_UP_THRESHOLD (95) |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 42 | #define MICRO_FREQUENCY_MIN_SAMPLE_RATE (10000) |
| Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 43 | #define MIN_FREQUENCY_UP_THRESHOLD (11) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define MAX_FREQUENCY_UP_THRESHOLD (100) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 45 | #define MIN_FREQUENCY_DOWN_DIFFERENTIAL (1) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 47 | /* |
| 48 | * The polling frequency of this governor depends on the capability of |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * the processor. Default polling frequency is 1000 times the transition |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 50 | * latency of the processor. The governor will work on any processor with |
| 51 | * transition latency <= 10mS, using appropriate sampling |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * rate. |
| 53 | * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL) |
| 54 | * this governor will not work. |
| 55 | * All times here are in uS. |
| 56 | */ |
| Dave Jones | df8b59b | 2005-09-20 12:39:35 -0700 | [diff] [blame] | 57 | #define MIN_SAMPLING_RATE_RATIO (2) |
| Thomas Renninger | 112124a | 2009-02-04 11:55:12 +0100 | [diff] [blame] | 58 | |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 59 | static unsigned int min_sampling_rate; |
| 60 | |
| Thomas Renninger | 112124a | 2009-02-04 11:55:12 +0100 | [diff] [blame] | 61 | #define LATENCY_MULTIPLIER (1000) |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 62 | #define MIN_LATENCY_MULTIPLIER (100) |
| Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 63 | #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 65 | #define POWERSAVE_BIAS_MAXLEVEL (1000) |
| 66 | #define POWERSAVE_BIAS_MINLEVEL (-1000) |
| 67 | |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 68 | static void do_dbs_timer(struct work_struct *work); |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 69 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, |
| 70 | unsigned int event); |
| 71 | |
| 72 | #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND |
| 73 | static |
| 74 | #endif |
| 75 | struct cpufreq_governor cpufreq_gov_ondemand = { |
| 76 | .name = "ondemand", |
| 77 | .governor = cpufreq_governor_dbs, |
| 78 | .max_transition_latency = TRANSITION_LATENCY_LIMIT, |
| 79 | .owner = THIS_MODULE, |
| 80 | }; |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 81 | |
| 82 | /* Sampling types */ |
| Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 83 | enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE}; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | struct cpu_dbs_info_s { |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 86 | cputime64_t prev_cpu_idle; |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 87 | cputime64_t prev_cpu_iowait; |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 88 | cputime64_t prev_cpu_wall; |
| venkatesh.pallipadi@intel.com | 8080091 | 2008-08-04 11:59:12 -0700 | [diff] [blame] | 89 | cputime64_t prev_cpu_nice; |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 90 | struct cpufreq_policy *cur_policy; |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 91 | struct delayed_work work; |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 92 | struct cpufreq_frequency_table *freq_table; |
| 93 | unsigned int freq_lo; |
| 94 | unsigned int freq_lo_jiffies; |
| 95 | unsigned int freq_hi_jiffies; |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 96 | unsigned int rate_mult; |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 97 | unsigned int prev_load; |
| 98 | unsigned int max_load; |
| Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 99 | int cpu; |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 100 | unsigned int sample_type:1; |
| 101 | /* |
| 102 | * percpu mutex that serializes governor limit change with |
| 103 | * do_dbs_timer invocation. We do not want do_dbs_timer to run |
| 104 | * when user is changing the governor or limits. |
| 105 | */ |
| 106 | struct mutex timer_mutex; |
| Steve Muckle | d5d59a5 | 2013-05-31 10:39:31 -0700 | [diff] [blame] | 107 | |
| Steve Muckle | d5d59a5 | 2013-05-31 10:39:31 -0700 | [diff] [blame] | 108 | atomic_t src_sync_cpu; |
| 109 | atomic_t sync_enabled; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 111 | static DEFINE_PER_CPU(struct cpu_dbs_info_s, od_cpu_dbs_info); |
| myfluxi | 5ece427 | 2014-02-06 21:14:57 +0100 | [diff] [blame] | 112 | static DEFINE_PER_CPU(struct task_struct *, sync_thread); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 114 | static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info); |
| 115 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info); |
| 116 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | static unsigned int dbs_enable; /* number of CPUs using this policy */ |
| 118 | |
| Venkatesh Pallipadi | 4ec223d | 2006-06-21 15:18:34 -0700 | [diff] [blame] | 119 | /* |
| Matt Wagantall | 5b71a82 | 2013-05-31 20:02:01 -0700 | [diff] [blame] | 120 | * dbs_mutex protects dbs_enable and dbs_info during start/stop. |
| Venkatesh Pallipadi | 4ec223d | 2006-06-21 15:18:34 -0700 | [diff] [blame] | 121 | */ |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 122 | static DEFINE_MUTEX(dbs_mutex); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 124 | static struct workqueue_struct *dbs_wq; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 125 | |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 126 | struct dbs_work_struct { |
| 127 | struct work_struct work; |
| 128 | unsigned int cpu; |
| 129 | }; |
| 130 | |
| 131 | static DEFINE_PER_CPU(struct dbs_work_struct, dbs_refresh_work); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 133 | static struct dbs_tuners { |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 134 | unsigned int sampling_rate; |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 135 | unsigned int up_threshold; |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 136 | unsigned int up_threshold_multi_core; |
| venkatesh.pallipadi@intel.com | e9d95bf | 2008-08-04 11:59:10 -0700 | [diff] [blame] | 137 | unsigned int down_differential; |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 138 | unsigned int down_differential_multi_core; |
| 139 | unsigned int optimal_freq; |
| 140 | unsigned int up_threshold_any_cpu_load; |
| 141 | unsigned int sync_freq; |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 142 | unsigned int ignore_nice; |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 143 | unsigned int sampling_down_factor; |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 144 | int powersave_bias; |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 145 | unsigned int io_is_busy; |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 146 | unsigned int input_boost; |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 147 | } dbs_tuners_ins = { |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 148 | .up_threshold_multi_core = DEF_FREQUENCY_UP_THRESHOLD, |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 149 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 150 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, |
| venkatesh.pallipadi@intel.com | e9d95bf | 2008-08-04 11:59:10 -0700 | [diff] [blame] | 151 | .down_differential = DEF_FREQUENCY_DOWN_DIFFERENTIAL, |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 152 | .down_differential_multi_core = MICRO_FREQUENCY_DOWN_DIFFERENTIAL, |
| 153 | .up_threshold_any_cpu_load = DEF_FREQUENCY_UP_THRESHOLD, |
| Eric Piel | 9cbad61 | 2006-03-10 11:35:27 +0200 | [diff] [blame] | 154 | .ignore_nice = 0, |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 155 | .powersave_bias = 0, |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 156 | .sync_freq = 0, |
| 157 | .optimal_freq = 0, |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 158 | .input_boost = 0, |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 161 | static inline cputime64_t get_cpu_iowait_time(unsigned int cpu, cputime64_t *wall) |
| 162 | { |
| 163 | u64 iowait_time = get_cpu_iowait_time_us(cpu, wall); |
| 164 | |
| 165 | if (iowait_time == -1ULL) |
| 166 | return 0; |
| 167 | |
| 168 | return iowait_time; |
| 169 | } |
| 170 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 171 | /* |
| 172 | * Find right freq to be set now with powersave_bias on. |
| 173 | * Returns the freq_hi to be used right now and will set freq_hi_jiffies, |
| 174 | * freq_lo, and freq_lo_jiffies in percpu area for averaging freqs. |
| 175 | */ |
| Adrian Bunk | b5ecf60 | 2006-08-13 23:00:08 +0200 | [diff] [blame] | 176 | static unsigned int powersave_bias_target(struct cpufreq_policy *policy, |
| 177 | unsigned int freq_next, |
| 178 | unsigned int relation) |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 179 | { |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 180 | unsigned int freq_req, freq_avg; |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 181 | unsigned int freq_hi, freq_lo; |
| 182 | unsigned int index = 0; |
| 183 | unsigned int jiffies_total, jiffies_hi, jiffies_lo; |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 184 | int freq_reduc; |
| Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 185 | struct cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, |
| 186 | policy->cpu); |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 187 | |
| 188 | if (!dbs_info->freq_table) { |
| 189 | dbs_info->freq_lo = 0; |
| 190 | dbs_info->freq_lo_jiffies = 0; |
| 191 | return freq_next; |
| 192 | } |
| 193 | |
| 194 | cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_next, |
| 195 | relation, &index); |
| 196 | freq_req = dbs_info->freq_table[index].frequency; |
| 197 | freq_reduc = freq_req * dbs_tuners_ins.powersave_bias / 1000; |
| 198 | freq_avg = freq_req - freq_reduc; |
| 199 | |
| 200 | /* Find freq bounds for freq_avg in freq_table */ |
| 201 | index = 0; |
| 202 | cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg, |
| 203 | CPUFREQ_RELATION_H, &index); |
| 204 | freq_lo = dbs_info->freq_table[index].frequency; |
| 205 | index = 0; |
| 206 | cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg, |
| 207 | CPUFREQ_RELATION_L, &index); |
| 208 | freq_hi = dbs_info->freq_table[index].frequency; |
| 209 | |
| 210 | /* Find out how long we have to be in hi and lo freqs */ |
| 211 | if (freq_hi == freq_lo) { |
| 212 | dbs_info->freq_lo = 0; |
| 213 | dbs_info->freq_lo_jiffies = 0; |
| 214 | return freq_lo; |
| 215 | } |
| 216 | jiffies_total = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
| 217 | jiffies_hi = (freq_avg - freq_lo) * jiffies_total; |
| 218 | jiffies_hi += ((freq_hi - freq_lo) / 2); |
| 219 | jiffies_hi /= (freq_hi - freq_lo); |
| 220 | jiffies_lo = jiffies_total - jiffies_hi; |
| 221 | dbs_info->freq_lo = freq_lo; |
| 222 | dbs_info->freq_lo_jiffies = jiffies_lo; |
| 223 | dbs_info->freq_hi_jiffies = jiffies_hi; |
| 224 | return freq_hi; |
| 225 | } |
| 226 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 227 | static int ondemand_powersave_bias_setspeed(struct cpufreq_policy *policy, |
| 228 | struct cpufreq_policy *altpolicy, |
| 229 | int level) |
| 230 | { |
| 231 | if (level == POWERSAVE_BIAS_MAXLEVEL) { |
| 232 | /* maximum powersave; set to lowest frequency */ |
| 233 | __cpufreq_driver_target(policy, |
| 234 | (altpolicy) ? altpolicy->min : policy->min, |
| 235 | CPUFREQ_RELATION_L); |
| 236 | return 1; |
| 237 | } else if (level == POWERSAVE_BIAS_MINLEVEL) { |
| 238 | /* minimum powersave; set to highest frequency */ |
| 239 | __cpufreq_driver_target(policy, |
| 240 | (altpolicy) ? altpolicy->max : policy->max, |
| 241 | CPUFREQ_RELATION_H); |
| 242 | return 1; |
| 243 | } |
| 244 | return 0; |
| 245 | } |
| 246 | |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 247 | static void ondemand_powersave_bias_init_cpu(int cpu) |
| 248 | { |
| Tejun Heo | 384be2b | 2009-08-14 14:41:02 +0900 | [diff] [blame] | 249 | struct cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu); |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 250 | dbs_info->freq_table = cpufreq_frequency_get_table(cpu); |
| 251 | dbs_info->freq_lo = 0; |
| 252 | } |
| 253 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 254 | static void ondemand_powersave_bias_init(void) |
| 255 | { |
| 256 | int i; |
| 257 | for_each_online_cpu(i) { |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 258 | ondemand_powersave_bias_init_cpu(i); |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | /************************** sysfs interface ************************/ |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 263 | |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 264 | static ssize_t show_sampling_rate_min(struct kobject *kobj, |
| 265 | struct attribute *attr, char *buf) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 267 | return sprintf(buf, "%u\n", min_sampling_rate); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| Borislav Petkov | 6dad2a2 | 2010-03-31 21:56:46 +0200 | [diff] [blame] | 270 | define_one_global_ro(sampling_rate_min); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | /* cpufreq_ondemand Governor Tunables */ |
| 273 | #define show_one(file_name, object) \ |
| 274 | static ssize_t show_##file_name \ |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 275 | (struct kobject *kobj, struct attribute *attr, char *buf) \ |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { \ |
| 277 | return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ |
| 278 | } |
| 279 | show_one(sampling_rate, sampling_rate); |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 280 | show_one(io_is_busy, io_is_busy); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | show_one(up_threshold, up_threshold); |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 282 | show_one(up_threshold_multi_core, up_threshold_multi_core); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 283 | show_one(down_differential, down_differential); |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 284 | show_one(sampling_down_factor, sampling_down_factor); |
| Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 285 | show_one(ignore_nice_load, ignore_nice); |
| Krishna Vanka | 6912b87 | 2013-12-11 14:56:15 +0530 | [diff] [blame] | 286 | show_one(down_differential_multi_core, down_differential_multi_core); |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 287 | show_one(optimal_freq, optimal_freq); |
| 288 | show_one(up_threshold_any_cpu_load, up_threshold_any_cpu_load); |
| 289 | show_one(sync_freq, sync_freq); |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 290 | show_one(input_boost, input_boost); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 291 | |
| 292 | static ssize_t show_powersave_bias |
| 293 | (struct kobject *kobj, struct attribute *attr, char *buf) |
| 294 | { |
| 295 | return snprintf(buf, PAGE_SIZE, "%d\n", dbs_tuners_ins.powersave_bias); |
| 296 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| MyungJoo Ham | fd0ef7a | 2012-02-29 17:54:41 +0900 | [diff] [blame] | 298 | /** |
| 299 | * update_sampling_rate - update sampling rate effective immediately if needed. |
| 300 | * @new_rate: new sampling rate |
| 301 | * |
| 302 | * If new rate is smaller than the old, simply updaing |
| 303 | * dbs_tuners_int.sampling_rate might not be appropriate. For example, |
| 304 | * if the original sampling_rate was 1 second and the requested new sampling |
| 305 | * rate is 10 ms because the user needs immediate reaction from ondemand |
| 306 | * governor, but not sure if higher frequency will be required or not, |
| 307 | * then, the governor may change the sampling rate too late; up to 1 second |
| 308 | * later. Thus, if we are reducing the sampling rate, we need to make the |
| 309 | * new value effective immediately. |
| 310 | */ |
| 311 | static void update_sampling_rate(unsigned int new_rate) |
| 312 | { |
| 313 | int cpu; |
| 314 | |
| 315 | dbs_tuners_ins.sampling_rate = new_rate |
| 316 | = max(new_rate, min_sampling_rate); |
| 317 | |
| Rohit Gupta | c4aeacb | 2013-07-31 15:33:24 -0700 | [diff] [blame] | 318 | get_online_cpus(); |
| MyungJoo Ham | fd0ef7a | 2012-02-29 17:54:41 +0900 | [diff] [blame] | 319 | for_each_online_cpu(cpu) { |
| 320 | struct cpufreq_policy *policy; |
| 321 | struct cpu_dbs_info_s *dbs_info; |
| 322 | unsigned long next_sampling, appointed_at; |
| 323 | |
| 324 | policy = cpufreq_cpu_get(cpu); |
| 325 | if (!policy) |
| 326 | continue; |
| 327 | dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu); |
| 328 | cpufreq_cpu_put(policy); |
| 329 | |
| 330 | mutex_lock(&dbs_info->timer_mutex); |
| 331 | |
| 332 | if (!delayed_work_pending(&dbs_info->work)) { |
| 333 | mutex_unlock(&dbs_info->timer_mutex); |
| 334 | continue; |
| 335 | } |
| 336 | |
| 337 | next_sampling = jiffies + usecs_to_jiffies(new_rate); |
| 338 | appointed_at = dbs_info->work.timer.expires; |
| 339 | |
| 340 | |
| 341 | if (time_before(next_sampling, appointed_at)) { |
| 342 | |
| 343 | mutex_unlock(&dbs_info->timer_mutex); |
| 344 | cancel_delayed_work_sync(&dbs_info->work); |
| 345 | mutex_lock(&dbs_info->timer_mutex); |
| 346 | |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 347 | queue_delayed_work_on(dbs_info->cpu, dbs_wq, |
| 348 | &dbs_info->work, usecs_to_jiffies(new_rate)); |
| MyungJoo Ham | fd0ef7a | 2012-02-29 17:54:41 +0900 | [diff] [blame] | 349 | |
| 350 | } |
| 351 | mutex_unlock(&dbs_info->timer_mutex); |
| 352 | } |
| Rohit Gupta | c4aeacb | 2013-07-31 15:33:24 -0700 | [diff] [blame] | 353 | put_online_cpus(); |
| MyungJoo Ham | fd0ef7a | 2012-02-29 17:54:41 +0900 | [diff] [blame] | 354 | } |
| 355 | |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 356 | static ssize_t store_sampling_rate(struct kobject *a, struct attribute *b, |
| 357 | const char *buf, size_t count) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
| 359 | unsigned int input; |
| 360 | int ret; |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 361 | ret = sscanf(buf, "%u", &input); |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 362 | if (ret != 1) |
| 363 | return -EINVAL; |
| MyungJoo Ham | fd0ef7a | 2012-02-29 17:54:41 +0900 | [diff] [blame] | 364 | update_sampling_rate(input); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return count; |
| 366 | } |
| 367 | |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 368 | static ssize_t store_input_boost(struct kobject *a, struct attribute *b, |
| 369 | const char *buf, size_t count) |
| 370 | { |
| 371 | unsigned int input; |
| 372 | int ret; |
| 373 | ret = sscanf(buf, "%u", &input); |
| 374 | if (ret != 1) |
| 375 | return -EINVAL; |
| 376 | dbs_tuners_ins.input_boost = input; |
| 377 | return count; |
| 378 | } |
| 379 | |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 380 | static ssize_t store_sync_freq(struct kobject *a, struct attribute *b, |
| 381 | const char *buf, size_t count) |
| 382 | { |
| 383 | unsigned int input; |
| 384 | int ret; |
| 385 | |
| 386 | ret = sscanf(buf, "%u", &input); |
| 387 | if (ret != 1) |
| 388 | return -EINVAL; |
| 389 | dbs_tuners_ins.sync_freq = input; |
| 390 | return count; |
| 391 | } |
| 392 | |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 393 | static ssize_t store_io_is_busy(struct kobject *a, struct attribute *b, |
| 394 | const char *buf, size_t count) |
| 395 | { |
| 396 | unsigned int input; |
| 397 | int ret; |
| 398 | |
| 399 | ret = sscanf(buf, "%u", &input); |
| 400 | if (ret != 1) |
| 401 | return -EINVAL; |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 402 | dbs_tuners_ins.io_is_busy = !!input; |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 403 | return count; |
| 404 | } |
| 405 | |
| Krishna Vanka | 6912b87 | 2013-12-11 14:56:15 +0530 | [diff] [blame] | 406 | static ssize_t store_down_differential_multi_core(struct kobject *a, |
| 407 | struct attribute *b, const char *buf, size_t count) |
| 408 | { |
| 409 | unsigned int input; |
| 410 | int ret; |
| 411 | |
| 412 | ret = sscanf(buf, "%u", &input); |
| 413 | if (ret != 1) |
| 414 | return -EINVAL; |
| 415 | dbs_tuners_ins.down_differential_multi_core = input; |
| 416 | return count; |
| 417 | } |
| 418 | |
| 419 | |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 420 | static ssize_t store_optimal_freq(struct kobject *a, struct attribute *b, |
| 421 | const char *buf, size_t count) |
| 422 | { |
| 423 | unsigned int input; |
| 424 | int ret; |
| 425 | |
| 426 | ret = sscanf(buf, "%u", &input); |
| 427 | if (ret != 1) |
| 428 | return -EINVAL; |
| 429 | dbs_tuners_ins.optimal_freq = input; |
| 430 | return count; |
| 431 | } |
| 432 | |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 433 | static ssize_t store_up_threshold(struct kobject *a, struct attribute *b, |
| 434 | const char *buf, size_t count) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
| 436 | unsigned int input; |
| 437 | int ret; |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 438 | ret = sscanf(buf, "%u", &input); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 440 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || |
| Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 441 | input < MIN_FREQUENCY_UP_THRESHOLD) { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | return -EINVAL; |
| 443 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | dbs_tuners_ins.up_threshold = input; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | return count; |
| 446 | } |
| 447 | |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 448 | static ssize_t store_up_threshold_multi_core(struct kobject *a, |
| 449 | struct attribute *b, const char *buf, size_t count) |
| 450 | { |
| 451 | unsigned int input; |
| 452 | int ret; |
| 453 | ret = sscanf(buf, "%u", &input); |
| 454 | |
| 455 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || |
| 456 | input < MIN_FREQUENCY_UP_THRESHOLD) { |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | dbs_tuners_ins.up_threshold_multi_core = input; |
| 460 | return count; |
| 461 | } |
| 462 | |
| 463 | static ssize_t store_up_threshold_any_cpu_load(struct kobject *a, |
| 464 | struct attribute *b, const char *buf, size_t count) |
| 465 | { |
| 466 | unsigned int input; |
| 467 | int ret; |
| 468 | ret = sscanf(buf, "%u", &input); |
| 469 | |
| 470 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || |
| 471 | input < MIN_FREQUENCY_UP_THRESHOLD) { |
| 472 | return -EINVAL; |
| 473 | } |
| 474 | dbs_tuners_ins.up_threshold_any_cpu_load = input; |
| 475 | return count; |
| 476 | } |
| 477 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 478 | static ssize_t store_down_differential(struct kobject *a, struct attribute *b, |
| 479 | const char *buf, size_t count) |
| 480 | { |
| 481 | unsigned int input; |
| 482 | int ret; |
| 483 | ret = sscanf(buf, "%u", &input); |
| 484 | |
| 485 | if (ret != 1 || input >= dbs_tuners_ins.up_threshold || |
| 486 | input < MIN_FREQUENCY_DOWN_DIFFERENTIAL) { |
| 487 | return -EINVAL; |
| 488 | } |
| 489 | |
| 490 | dbs_tuners_ins.down_differential = input; |
| 491 | |
| 492 | return count; |
| 493 | } |
| 494 | |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 495 | static ssize_t store_sampling_down_factor(struct kobject *a, |
| 496 | struct attribute *b, const char *buf, size_t count) |
| 497 | { |
| 498 | unsigned int input, j; |
| 499 | int ret; |
| 500 | ret = sscanf(buf, "%u", &input); |
| 501 | |
| 502 | if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1) |
| 503 | return -EINVAL; |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 504 | dbs_tuners_ins.sampling_down_factor = input; |
| 505 | |
| 506 | /* Reset down sampling multiplier in case it was active */ |
| 507 | for_each_online_cpu(j) { |
| 508 | struct cpu_dbs_info_s *dbs_info; |
| 509 | dbs_info = &per_cpu(od_cpu_dbs_info, j); |
| 510 | dbs_info->rate_mult = 1; |
| 511 | } |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 512 | return count; |
| 513 | } |
| 514 | |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 515 | static ssize_t store_ignore_nice_load(struct kobject *a, struct attribute *b, |
| 516 | const char *buf, size_t count) |
| Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 517 | { |
| 518 | unsigned int input; |
| 519 | int ret; |
| 520 | |
| 521 | unsigned int j; |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 522 | |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 523 | ret = sscanf(buf, "%u", &input); |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 524 | if (ret != 1) |
| Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 525 | return -EINVAL; |
| 526 | |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 527 | if (input > 1) |
| Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 528 | input = 1; |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 529 | |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 530 | if (input == dbs_tuners_ins.ignore_nice) { /* nothing to do */ |
| Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 531 | return count; |
| 532 | } |
| 533 | dbs_tuners_ins.ignore_nice = input; |
| 534 | |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 535 | /* we need to re-evaluate prev_cpu_idle */ |
| Dave Jones | dac1c1a | 2005-05-31 19:03:49 -0700 | [diff] [blame] | 536 | for_each_online_cpu(j) { |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 537 | struct cpu_dbs_info_s *dbs_info; |
| Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 538 | dbs_info = &per_cpu(od_cpu_dbs_info, j); |
| venkatesh.pallipadi@intel.com | 3430502 | 2008-08-04 11:59:09 -0700 | [diff] [blame] | 539 | dbs_info->prev_cpu_idle = get_cpu_idle_time(j, |
| Viresh Kumar | efa514d | 2013-05-17 11:26:32 +0000 | [diff] [blame^] | 540 | &dbs_info->prev_cpu_wall, dbs_tuners_ins.io_is_busy); |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 541 | if (dbs_tuners_ins.ignore_nice) |
| Glauber Costa | 3292beb | 2011-11-28 14:45:17 -0200 | [diff] [blame] | 542 | dbs_info->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 543 | |
| Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 544 | } |
| Dave Jones | 3d5ee9e | 2005-05-31 19:03:47 -0700 | [diff] [blame] | 545 | return count; |
| 546 | } |
| 547 | |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 548 | static ssize_t store_powersave_bias(struct kobject *a, struct attribute *b, |
| 549 | const char *buf, size_t count) |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 550 | { |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 551 | int input = 0; |
| 552 | int bypass = 0; |
| Krishna Vanka | ebf80eb | 2012-04-19 13:11:20 +0530 | [diff] [blame] | 553 | int ret, cpu, reenable_timer, j; |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 554 | struct cpu_dbs_info_s *dbs_info; |
| 555 | |
| Krishna Vanka | ebf80eb | 2012-04-19 13:11:20 +0530 | [diff] [blame] | 556 | struct cpumask cpus_timer_done; |
| 557 | cpumask_clear(&cpus_timer_done); |
| 558 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 559 | ret = sscanf(buf, "%d", &input); |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 560 | |
| 561 | if (ret != 1) |
| 562 | return -EINVAL; |
| 563 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 564 | if (input >= POWERSAVE_BIAS_MAXLEVEL) { |
| 565 | input = POWERSAVE_BIAS_MAXLEVEL; |
| 566 | bypass = 1; |
| 567 | } else if (input <= POWERSAVE_BIAS_MINLEVEL) { |
| 568 | input = POWERSAVE_BIAS_MINLEVEL; |
| 569 | bypass = 1; |
| 570 | } |
| 571 | |
| 572 | if (input == dbs_tuners_ins.powersave_bias) { |
| 573 | /* no change */ |
| 574 | return count; |
| 575 | } |
| 576 | |
| 577 | reenable_timer = ((dbs_tuners_ins.powersave_bias == |
| 578 | POWERSAVE_BIAS_MAXLEVEL) || |
| 579 | (dbs_tuners_ins.powersave_bias == |
| 580 | POWERSAVE_BIAS_MINLEVEL)); |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 581 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 582 | dbs_tuners_ins.powersave_bias = input; |
| Matt Wagantall | 5b71a82 | 2013-05-31 20:02:01 -0700 | [diff] [blame] | 583 | |
| Matt Wagantall | aa93be0 | 2013-05-31 13:14:44 -0700 | [diff] [blame] | 584 | get_online_cpus(); |
| Matt Wagantall | e1aa7a2 | 2013-08-22 10:40:48 -0700 | [diff] [blame] | 585 | mutex_lock(&dbs_mutex); |
| Matt Wagantall | 5b71a82 | 2013-05-31 20:02:01 -0700 | [diff] [blame] | 586 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 587 | if (!bypass) { |
| 588 | if (reenable_timer) { |
| 589 | /* reinstate dbs timer */ |
| 590 | for_each_online_cpu(cpu) { |
| 591 | if (lock_policy_rwsem_write(cpu) < 0) |
| 592 | continue; |
| 593 | |
| 594 | dbs_info = &per_cpu(od_cpu_dbs_info, cpu); |
| Krishna Vanka | ebf80eb | 2012-04-19 13:11:20 +0530 | [diff] [blame] | 595 | |
| 596 | for_each_cpu(j, &cpus_timer_done) { |
| 597 | if (!dbs_info->cur_policy) { |
| 598 | pr_err("Dbs policy is NULL\n"); |
| 599 | goto skip_this_cpu; |
| 600 | } |
| 601 | if (cpumask_test_cpu(j, dbs_info-> |
| 602 | cur_policy->cpus)) |
| 603 | goto skip_this_cpu; |
| 604 | } |
| 605 | |
| 606 | cpumask_set_cpu(cpu, &cpus_timer_done); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 607 | if (dbs_info->cur_policy) { |
| Osvaldo Banuelos | 38eadd2 | 2013-12-06 16:15:15 -0800 | [diff] [blame] | 608 | dbs_timer_exit(dbs_info); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 609 | /* restart dbs timer */ |
| Osvaldo Banuelos | 38eadd2 | 2013-12-06 16:15:15 -0800 | [diff] [blame] | 610 | mutex_lock(&dbs_info->timer_mutex); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 611 | dbs_timer_init(dbs_info); |
| Rohit Gupta | 92daa72 | 2013-06-17 17:56:27 -0700 | [diff] [blame] | 612 | /* Enable frequency synchronization |
| 613 | * of CPUs */ |
| Osvaldo Banuelos | 38eadd2 | 2013-12-06 16:15:15 -0800 | [diff] [blame] | 614 | mutex_unlock(&dbs_info->timer_mutex); |
| Rohit Gupta | 92daa72 | 2013-06-17 17:56:27 -0700 | [diff] [blame] | 615 | atomic_set(&dbs_info->sync_enabled, 1); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 616 | } |
| Krishna Vanka | ebf80eb | 2012-04-19 13:11:20 +0530 | [diff] [blame] | 617 | skip_this_cpu: |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 618 | unlock_policy_rwsem_write(cpu); |
| 619 | } |
| 620 | } |
| 621 | ondemand_powersave_bias_init(); |
| 622 | } else { |
| 623 | /* running at maximum or minimum frequencies; cancel |
| 624 | dbs timer as periodic load sampling is not necessary */ |
| 625 | for_each_online_cpu(cpu) { |
| 626 | if (lock_policy_rwsem_write(cpu) < 0) |
| 627 | continue; |
| 628 | |
| 629 | dbs_info = &per_cpu(od_cpu_dbs_info, cpu); |
| Krishna Vanka | ebf80eb | 2012-04-19 13:11:20 +0530 | [diff] [blame] | 630 | |
| 631 | for_each_cpu(j, &cpus_timer_done) { |
| 632 | if (!dbs_info->cur_policy) { |
| 633 | pr_err("Dbs policy is NULL\n"); |
| 634 | goto skip_this_cpu_bypass; |
| 635 | } |
| 636 | if (cpumask_test_cpu(j, dbs_info-> |
| 637 | cur_policy->cpus)) |
| 638 | goto skip_this_cpu_bypass; |
| 639 | } |
| 640 | |
| 641 | cpumask_set_cpu(cpu, &cpus_timer_done); |
| 642 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 643 | if (dbs_info->cur_policy) { |
| 644 | /* cpu using ondemand, cancel dbs timer */ |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 645 | dbs_timer_exit(dbs_info); |
| Rohit Gupta | 92daa72 | 2013-06-17 17:56:27 -0700 | [diff] [blame] | 646 | /* Disable frequency synchronization of |
| 647 | * CPUs to avoid re-queueing of work from |
| 648 | * sync_thread */ |
| 649 | atomic_set(&dbs_info->sync_enabled, 0); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 650 | |
| Rohit Gupta | ef9c574 | 2013-06-17 16:57:08 -0700 | [diff] [blame] | 651 | mutex_lock(&dbs_info->timer_mutex); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 652 | ondemand_powersave_bias_setspeed( |
| 653 | dbs_info->cur_policy, |
| 654 | NULL, |
| 655 | input); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 656 | mutex_unlock(&dbs_info->timer_mutex); |
| Rohit Gupta | ef9c574 | 2013-06-17 16:57:08 -0700 | [diff] [blame] | 657 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 658 | } |
| Krishna Vanka | ebf80eb | 2012-04-19 13:11:20 +0530 | [diff] [blame] | 659 | skip_this_cpu_bypass: |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 660 | unlock_policy_rwsem_write(cpu); |
| 661 | } |
| 662 | } |
| Matt Wagantall | 5b71a82 | 2013-05-31 20:02:01 -0700 | [diff] [blame] | 663 | |
| Matt Wagantall | 5b71a82 | 2013-05-31 20:02:01 -0700 | [diff] [blame] | 664 | mutex_unlock(&dbs_mutex); |
| Matt Wagantall | e1aa7a2 | 2013-08-22 10:40:48 -0700 | [diff] [blame] | 665 | put_online_cpus(); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 666 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 667 | return count; |
| 668 | } |
| 669 | |
| Borislav Petkov | 6dad2a2 | 2010-03-31 21:56:46 +0200 | [diff] [blame] | 670 | define_one_global_rw(sampling_rate); |
| Linus Torvalds | 07d7775 | 2010-05-18 08:49:13 -0700 | [diff] [blame] | 671 | define_one_global_rw(io_is_busy); |
| Borislav Petkov | 6dad2a2 | 2010-03-31 21:56:46 +0200 | [diff] [blame] | 672 | define_one_global_rw(up_threshold); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 673 | define_one_global_rw(down_differential); |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 674 | define_one_global_rw(sampling_down_factor); |
| Borislav Petkov | 6dad2a2 | 2010-03-31 21:56:46 +0200 | [diff] [blame] | 675 | define_one_global_rw(ignore_nice_load); |
| 676 | define_one_global_rw(powersave_bias); |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 677 | define_one_global_rw(up_threshold_multi_core); |
| Krishna Vanka | 6912b87 | 2013-12-11 14:56:15 +0530 | [diff] [blame] | 678 | define_one_global_rw(down_differential_multi_core); |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 679 | define_one_global_rw(optimal_freq); |
| 680 | define_one_global_rw(up_threshold_any_cpu_load); |
| 681 | define_one_global_rw(sync_freq); |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 682 | define_one_global_rw(input_boost); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 684 | static struct attribute *dbs_attributes[] = { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | &sampling_rate_min.attr, |
| 686 | &sampling_rate.attr, |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | &up_threshold.attr, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 688 | &down_differential.attr, |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 689 | &sampling_down_factor.attr, |
| Alexander Clouter | 001893c | 2005-12-01 01:09:25 -0800 | [diff] [blame] | 690 | &ignore_nice_load.attr, |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 691 | &powersave_bias.attr, |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 692 | &io_is_busy.attr, |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 693 | &up_threshold_multi_core.attr, |
| Krishna Vanka | 6912b87 | 2013-12-11 14:56:15 +0530 | [diff] [blame] | 694 | &down_differential_multi_core.attr, |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 695 | &optimal_freq.attr, |
| 696 | &up_threshold_any_cpu_load.attr, |
| 697 | &sync_freq.attr, |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 698 | &input_boost.attr, |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | NULL |
| 700 | }; |
| 701 | |
| 702 | static struct attribute_group dbs_attr_group = { |
| 703 | .attrs = dbs_attributes, |
| 704 | .name = "ondemand", |
| 705 | }; |
| 706 | |
| 707 | /************************** sysfs end ************************/ |
| 708 | |
| Mike Chan | 00e299f | 2010-01-26 17:06:47 -0800 | [diff] [blame] | 709 | static void dbs_freq_increase(struct cpufreq_policy *p, unsigned int freq) |
| 710 | { |
| 711 | if (dbs_tuners_ins.powersave_bias) |
| 712 | freq = powersave_bias_target(p, freq, CPUFREQ_RELATION_H); |
| 713 | else if (p->cur == p->max) |
| 714 | return; |
| 715 | |
| 716 | __cpufreq_driver_target(p, freq, dbs_tuners_ins.powersave_bias ? |
| 717 | CPUFREQ_RELATION_L : CPUFREQ_RELATION_H); |
| 718 | } |
| 719 | |
| Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 720 | static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
| Anitha Anand | cbeef6a | 2012-03-05 18:10:52 -0800 | [diff] [blame] | 722 | /* Extrapolated load of this CPU */ |
| 723 | unsigned int load_at_max_freq = 0; |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 724 | unsigned int max_load_freq; |
| Anitha Anand | cbeef6a | 2012-03-05 18:10:52 -0800 | [diff] [blame] | 725 | /* Current load across this CPU */ |
| 726 | unsigned int cur_load = 0; |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 727 | unsigned int max_load_other_cpu = 0; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | struct cpufreq_policy *policy; |
| 729 | unsigned int j; |
| 730 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 731 | this_dbs_info->freq_lo = 0; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | policy = this_dbs_info->cur_policy; |
| Swetha Chikkaboraiah | 23d4f37 | 2013-11-29 12:22:07 +0530 | [diff] [blame] | 733 | if(policy == NULL) |
| 734 | return; |
| Venki Pallipadi | ea48761 | 2007-06-20 14:26:24 -0700 | [diff] [blame] | 735 | |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 736 | /* |
| Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 737 | * Every sampling_rate, we check, if current idle time is less |
| 738 | * than 20% (default), then we try to increase frequency |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 739 | * Every sampling_rate, we look for a the lowest |
| Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 740 | * frequency which can sustain the load while keeping idle time over |
| 741 | * 30%. If such a frequency exist, we try to decrease to this frequency. |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | * |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 743 | * Any frequency increase takes it to the maximum frequency. |
| 744 | * Frequency reduction happens at minimum steps of |
| 745 | * 5% (default) of current frequency |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | */ |
| 747 | |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 748 | /* Get Absolute Load - in terms of freq */ |
| 749 | max_load_freq = 0; |
| 750 | |
| Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 751 | for_each_cpu(j, policy->cpus) { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | struct cpu_dbs_info_s *j_dbs_info; |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 753 | cputime64_t cur_wall_time, cur_idle_time, cur_iowait_time; |
| 754 | unsigned int idle_time, wall_time, iowait_time; |
| Anitha Anand | cbeef6a | 2012-03-05 18:10:52 -0800 | [diff] [blame] | 755 | unsigned int load_freq; |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 756 | int freq_avg; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
| Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 758 | j_dbs_info = &per_cpu(od_cpu_dbs_info, j); |
| venkatesh.pallipadi@intel.com | 3430502 | 2008-08-04 11:59:09 -0700 | [diff] [blame] | 759 | |
| Viresh Kumar | efa514d | 2013-05-17 11:26:32 +0000 | [diff] [blame^] | 760 | cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, dbs_tuners_ins.io_is_busy); |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 761 | cur_iowait_time = get_cpu_iowait_time(j, &cur_wall_time); |
| venkatesh.pallipadi@intel.com | 3430502 | 2008-08-04 11:59:09 -0700 | [diff] [blame] | 762 | |
| Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 763 | wall_time = (unsigned int) |
| 764 | (cur_wall_time - j_dbs_info->prev_cpu_wall); |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 765 | j_dbs_info->prev_cpu_wall = cur_wall_time; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
| Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 767 | idle_time = (unsigned int) |
| 768 | (cur_idle_time - j_dbs_info->prev_cpu_idle); |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 769 | j_dbs_info->prev_cpu_idle = cur_idle_time; |
| 770 | |
| Martin Schwidefsky | 6486163 | 2011-12-15 14:56:09 +0100 | [diff] [blame] | 771 | iowait_time = (unsigned int) |
| 772 | (cur_iowait_time - j_dbs_info->prev_cpu_iowait); |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 773 | j_dbs_info->prev_cpu_iowait = cur_iowait_time; |
| 774 | |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 775 | if (dbs_tuners_ins.ignore_nice) { |
| Glauber Costa | 3292beb | 2011-11-28 14:45:17 -0200 | [diff] [blame] | 776 | u64 cur_nice; |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 777 | unsigned long cur_nice_jiffies; |
| 778 | |
| Glauber Costa | 3292beb | 2011-11-28 14:45:17 -0200 | [diff] [blame] | 779 | cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE] - |
| 780 | j_dbs_info->prev_cpu_nice; |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 781 | /* |
| 782 | * Assumption: nice time between sampling periods will |
| 783 | * be less than 2^32 jiffies for 32 bit sys |
| 784 | */ |
| 785 | cur_nice_jiffies = (unsigned long) |
| 786 | cputime64_to_jiffies64(cur_nice); |
| 787 | |
| Glauber Costa | 3292beb | 2011-11-28 14:45:17 -0200 | [diff] [blame] | 788 | j_dbs_info->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 789 | idle_time += jiffies_to_usecs(cur_nice_jiffies); |
| 790 | } |
| 791 | |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 792 | /* |
| 793 | * For the purpose of ondemand, waiting for disk IO is an |
| 794 | * indication that you're performance critical, and not that |
| 795 | * the system is actually idle. So subtract the iowait time |
| 796 | * from the cpu idle time. |
| 797 | */ |
| 798 | |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 799 | if (dbs_tuners_ins.io_is_busy && idle_time >= iowait_time) |
| Arjan van de Ven | 6b8fcd9 | 2010-05-09 08:26:06 -0700 | [diff] [blame] | 800 | idle_time -= iowait_time; |
| 801 | |
| venkatesh.pallipadi@intel.com | 3430502 | 2008-08-04 11:59:09 -0700 | [diff] [blame] | 802 | if (unlikely(!wall_time || wall_time < idle_time)) |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 803 | continue; |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 804 | |
| Anitha Anand | cbeef6a | 2012-03-05 18:10:52 -0800 | [diff] [blame] | 805 | cur_load = 100 * (wall_time - idle_time) / wall_time; |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 806 | j_dbs_info->max_load = max(cur_load, j_dbs_info->prev_load); |
| 807 | j_dbs_info->prev_load = cur_load; |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 808 | freq_avg = __cpufreq_driver_getavg(policy, j); |
| Swetha Chikkaboraiah | 23d4f37 | 2013-11-29 12:22:07 +0530 | [diff] [blame] | 809 | if (policy == NULL) |
| 810 | return; |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 811 | if (freq_avg <= 0) |
| 812 | freq_avg = policy->cur; |
| 813 | |
| Anitha Anand | cbeef6a | 2012-03-05 18:10:52 -0800 | [diff] [blame] | 814 | load_freq = cur_load * freq_avg; |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 815 | if (load_freq > max_load_freq) |
| 816 | max_load_freq = load_freq; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 818 | |
| 819 | for_each_online_cpu(j) { |
| 820 | struct cpu_dbs_info_s *j_dbs_info; |
| 821 | j_dbs_info = &per_cpu(od_cpu_dbs_info, j); |
| 822 | |
| 823 | if (j == policy->cpu) |
| 824 | continue; |
| 825 | |
| 826 | if (max_load_other_cpu < j_dbs_info->max_load) |
| 827 | max_load_other_cpu = j_dbs_info->max_load; |
| 828 | /* |
| 829 | * The other cpu could be running at higher frequency |
| 830 | * but may not have completed it's sampling_down_factor. |
| 831 | * For that case consider other cpu is loaded so that |
| 832 | * frequency imbalance does not occur. |
| 833 | */ |
| 834 | |
| 835 | if ((j_dbs_info->cur_policy != NULL) |
| 836 | && (j_dbs_info->cur_policy->cur == |
| 837 | j_dbs_info->cur_policy->max)) { |
| 838 | |
| 839 | if (policy->cur >= dbs_tuners_ins.optimal_freq) |
| 840 | max_load_other_cpu = |
| 841 | dbs_tuners_ins.up_threshold_any_cpu_load; |
| 842 | } |
| 843 | } |
| 844 | |
| Anitha Anand | cbeef6a | 2012-03-05 18:10:52 -0800 | [diff] [blame] | 845 | /* calculate the scaled load across CPU */ |
| 846 | load_at_max_freq = (cur_load * policy->cur)/policy->cpuinfo.max_freq; |
| 847 | |
| 848 | cpufreq_notify_utilization(policy, load_at_max_freq); |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 849 | /* Check for frequency increase */ |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 850 | if (max_load_freq > dbs_tuners_ins.up_threshold * policy->cur) { |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 851 | /* If switching to max speed, apply sampling_down_factor */ |
| 852 | if (policy->cur < policy->max) |
| 853 | this_dbs_info->rate_mult = |
| 854 | dbs_tuners_ins.sampling_down_factor; |
| Mike Chan | 00e299f | 2010-01-26 17:06:47 -0800 | [diff] [blame] | 855 | dbs_freq_increase(policy, policy->max); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | return; |
| 857 | } |
| 858 | |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 859 | if (num_online_cpus() > 1) { |
| 860 | |
| 861 | if (max_load_other_cpu > |
| 862 | dbs_tuners_ins.up_threshold_any_cpu_load) { |
| 863 | if (policy->cur < dbs_tuners_ins.sync_freq) |
| 864 | dbs_freq_increase(policy, |
| 865 | dbs_tuners_ins.sync_freq); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | if (max_load_freq > dbs_tuners_ins.up_threshold_multi_core * |
| 870 | policy->cur) { |
| 871 | if (policy->cur < dbs_tuners_ins.optimal_freq) |
| 872 | dbs_freq_increase(policy, |
| 873 | dbs_tuners_ins.optimal_freq); |
| 874 | return; |
| 875 | } |
| 876 | } |
| 877 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | /* Check for frequency decrease */ |
| Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 879 | /* if we cannot reduce the frequency anymore, break out early */ |
| 880 | if (policy->cur == policy->min) |
| 881 | return; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
| Dave Jones | c29f140 | 2005-05-31 19:03:50 -0700 | [diff] [blame] | 883 | /* |
| 884 | * The optimal frequency is the frequency that is the lowest that |
| 885 | * can support the current CPU usage without triggering the up |
| 886 | * policy. To be safe, we focus 10 points under the threshold. |
| 887 | */ |
| venkatesh.pallipadi@intel.com | e9d95bf | 2008-08-04 11:59:10 -0700 | [diff] [blame] | 888 | if (max_load_freq < |
| 889 | (dbs_tuners_ins.up_threshold - dbs_tuners_ins.down_differential) * |
| 890 | policy->cur) { |
| venkatesh.pallipadi@intel.com | c43aa3b | 2008-08-04 11:59:08 -0700 | [diff] [blame] | 891 | unsigned int freq_next; |
| venkatesh.pallipadi@intel.com | e9d95bf | 2008-08-04 11:59:10 -0700 | [diff] [blame] | 892 | freq_next = max_load_freq / |
| 893 | (dbs_tuners_ins.up_threshold - |
| 894 | dbs_tuners_ins.down_differential); |
| Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 895 | |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 896 | /* No longer fully busy, reset rate_mult */ |
| 897 | this_dbs_info->rate_mult = 1; |
| 898 | |
| Nagananda.Chumbalkar@hp.com | 1dbf588 | 2009-12-21 23:40:52 +0100 | [diff] [blame] | 899 | if (freq_next < policy->min) |
| 900 | freq_next = policy->min; |
| 901 | |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 902 | if (num_online_cpus() > 1) { |
| 903 | if (max_load_other_cpu > |
| 904 | (dbs_tuners_ins.up_threshold_multi_core - |
| 905 | dbs_tuners_ins.down_differential) && |
| 906 | freq_next < dbs_tuners_ins.sync_freq) |
| 907 | freq_next = dbs_tuners_ins.sync_freq; |
| 908 | |
| 909 | if (max_load_freq > |
| Veena Sambasivan | 401092b | 2013-05-14 12:36:48 -0700 | [diff] [blame] | 910 | ((dbs_tuners_ins.up_threshold_multi_core - |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 911 | dbs_tuners_ins.down_differential_multi_core) * |
| Veena Sambasivan | 401092b | 2013-05-14 12:36:48 -0700 | [diff] [blame] | 912 | policy->cur) && |
| 913 | freq_next < dbs_tuners_ins.optimal_freq) |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 914 | freq_next = dbs_tuners_ins.optimal_freq; |
| 915 | |
| 916 | } |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 917 | if (!dbs_tuners_ins.powersave_bias) { |
| 918 | __cpufreq_driver_target(policy, freq_next, |
| 919 | CPUFREQ_RELATION_L); |
| 920 | } else { |
| 921 | int freq = powersave_bias_target(policy, freq_next, |
| 922 | CPUFREQ_RELATION_L); |
| 923 | __cpufreq_driver_target(policy, freq, |
| 924 | CPUFREQ_RELATION_L); |
| 925 | } |
| Venkatesh Pallipadi | ccb2fe2 | 2006-06-28 13:49:52 -0700 | [diff] [blame] | 926 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 929 | static void do_dbs_timer(struct work_struct *work) |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 930 | { |
| Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 931 | struct cpu_dbs_info_s *dbs_info = |
| 932 | container_of(work, struct cpu_dbs_info_s, work.work); |
| 933 | unsigned int cpu = dbs_info->cpu; |
| 934 | int sample_type = dbs_info->sample_type; |
| 935 | |
| Vincent Guittot | 5cb2c3b | 2011-02-07 17:14:25 +0100 | [diff] [blame] | 936 | int delay; |
| Jocelyn Falempe | a665df9 | 2010-03-11 14:01:11 -0800 | [diff] [blame] | 937 | |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 938 | mutex_lock(&dbs_info->timer_mutex); |
| Venkatesh Pallipadi | 56463b7 | 2007-02-05 16:12:45 -0800 | [diff] [blame] | 939 | |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 940 | /* Common NORMAL_SAMPLE setup */ |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 941 | dbs_info->sample_type = DBS_NORMAL_SAMPLE; |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 942 | if (!dbs_tuners_ins.powersave_bias || |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 943 | sample_type == DBS_NORMAL_SAMPLE) { |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 944 | dbs_check_cpu(dbs_info); |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 945 | if (dbs_info->freq_lo) { |
| 946 | /* Setup timer for SUB_SAMPLE */ |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 947 | dbs_info->sample_type = DBS_SUB_SAMPLE; |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 948 | delay = dbs_info->freq_hi_jiffies; |
| Vincent Guittot | 5cb2c3b | 2011-02-07 17:14:25 +0100 | [diff] [blame] | 949 | } else { |
| Vincent Guittot | 5cb2c3b | 2011-02-07 17:14:25 +0100 | [diff] [blame] | 950 | delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate |
| 951 | * dbs_info->rate_mult); |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 952 | } |
| 953 | } else { |
| 954 | __cpufreq_driver_target(dbs_info->cur_policy, |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 955 | dbs_info->freq_lo, CPUFREQ_RELATION_H); |
| Vincent Guittot | 5cb2c3b | 2011-02-07 17:14:25 +0100 | [diff] [blame] | 956 | delay = dbs_info->freq_lo_jiffies; |
| Alexey Starikovskiy | 05ca035 | 2006-07-31 22:28:12 +0400 | [diff] [blame] | 957 | } |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 958 | queue_delayed_work_on(cpu, dbs_wq, &dbs_info->work, delay); |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 959 | mutex_unlock(&dbs_info->timer_mutex); |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 960 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 962 | static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | { |
| Alexey Starikovskiy | 1ce28d6 | 2006-07-31 22:25:20 +0400 | [diff] [blame] | 964 | /* We want all CPUs to do sampling nearly on same jiffy */ |
| 965 | int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
| Jocelyn Falempe | a665df9 | 2010-03-11 14:01:11 -0800 | [diff] [blame] | 966 | |
| 967 | if (num_online_cpus() > 1) |
| 968 | delay -= jiffies % delay; |
| Venkatesh Pallipadi | 2f8a835 | 2006-06-28 13:51:19 -0700 | [diff] [blame] | 969 | |
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 970 | dbs_info->sample_type = DBS_NORMAL_SAMPLE; |
| Venki Pallipadi | 2828703 | 2007-05-08 00:27:47 -0700 | [diff] [blame] | 971 | INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer); |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 972 | queue_delayed_work_on(dbs_info->cpu, dbs_wq, &dbs_info->work, delay); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| Linus Torvalds | 2cd7cbd | 2006-07-23 12:05:00 -0700 | [diff] [blame] | 975 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | { |
| Mathieu Desnoyers | b14893a | 2009-05-17 10:30:45 -0400 | [diff] [blame] | 977 | cancel_delayed_work_sync(&dbs_info->work); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 980 | /* |
| 981 | * Not all CPUs want IO time to be accounted as busy; this dependson how |
| 982 | * efficient idling at a higher frequency/voltage is. |
| 983 | * Pavel Machek says this is not so for various generations of AMD and old |
| 984 | * Intel systems. |
| 985 | * Mike Chan (androidlcom) calis this is also not true for ARM. |
| 986 | * Because of this, whitelist specific known (series) of CPUs by default, and |
| 987 | * leave all others up to the user. |
| 988 | */ |
| 989 | static int should_io_be_busy(void) |
| 990 | { |
| 991 | #if defined(CONFIG_X86) |
| 992 | /* |
| 993 | * For Intel, Core 2 (model 15) andl later have an efficient idle. |
| 994 | */ |
| 995 | if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && |
| 996 | boot_cpu_data.x86 == 6 && |
| 997 | boot_cpu_data.x86_model >= 15) |
| 998 | return 1; |
| 999 | #endif |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 1003 | static void dbs_refresh_callback(struct work_struct *work) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1004 | { |
| 1005 | struct cpufreq_policy *policy; |
| 1006 | struct cpu_dbs_info_s *this_dbs_info; |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 1007 | struct dbs_work_struct *dbs_work; |
| 1008 | unsigned int cpu; |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 1009 | unsigned int target_freq; |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 1010 | |
| 1011 | dbs_work = container_of(work, struct dbs_work_struct, work); |
| 1012 | cpu = dbs_work->cpu; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1013 | |
| Krishna Vanka | a3e04d8 | 2012-06-08 11:35:43 +0530 | [diff] [blame] | 1014 | get_online_cpus(); |
| 1015 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1016 | if (lock_policy_rwsem_write(cpu) < 0) |
| Krishna Vanka | a3e04d8 | 2012-06-08 11:35:43 +0530 | [diff] [blame] | 1017 | goto bail_acq_sema_failed; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1018 | |
| 1019 | this_dbs_info = &per_cpu(od_cpu_dbs_info, cpu); |
| 1020 | policy = this_dbs_info->cur_policy; |
| David Ng | 4a0a023 | 2011-08-03 14:04:43 -0700 | [diff] [blame] | 1021 | if (!policy) { |
| 1022 | /* CPU not using ondemand governor */ |
| Krishna Vanka | a3e04d8 | 2012-06-08 11:35:43 +0530 | [diff] [blame] | 1023 | goto bail_incorrect_governor; |
| David Ng | 4a0a023 | 2011-08-03 14:04:43 -0700 | [diff] [blame] | 1024 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1025 | |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 1026 | if (dbs_tuners_ins.input_boost) |
| 1027 | target_freq = dbs_tuners_ins.input_boost; |
| 1028 | else |
| 1029 | target_freq = policy->max; |
| 1030 | |
| 1031 | if (policy->cur < target_freq) { |
| Anji Jonnala | b2408f4 | 2012-12-13 14:03:54 +0530 | [diff] [blame] | 1032 | /* |
| 1033 | * Arch specific cpufreq driver may fail. |
| 1034 | * Don't update governor frequency upon failure. |
| 1035 | */ |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 1036 | if (__cpufreq_driver_target(policy, target_freq, |
| Anji Jonnala | b2408f4 | 2012-12-13 14:03:54 +0530 | [diff] [blame] | 1037 | CPUFREQ_RELATION_L) >= 0) |
| Dilip Gudlur | 17cbd95 | 2013-06-17 13:04:31 -0700 | [diff] [blame] | 1038 | policy->cur = target_freq; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1039 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1040 | this_dbs_info->prev_cpu_idle = get_cpu_idle_time(cpu, |
| Viresh Kumar | efa514d | 2013-05-17 11:26:32 +0000 | [diff] [blame^] | 1041 | &this_dbs_info->prev_cpu_wall, dbs_tuners_ins.io_is_busy); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1042 | } |
| Krishna Vanka | a3e04d8 | 2012-06-08 11:35:43 +0530 | [diff] [blame] | 1043 | |
| 1044 | bail_incorrect_governor: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1045 | unlock_policy_rwsem_write(cpu); |
| Krishna Vanka | a3e04d8 | 2012-06-08 11:35:43 +0530 | [diff] [blame] | 1046 | |
| 1047 | bail_acq_sema_failed: |
| 1048 | put_online_cpus(); |
| 1049 | return; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1052 | static int dbs_migration_notify(struct notifier_block *nb, |
| 1053 | unsigned long target_cpu, void *arg) |
| 1054 | { |
| Steve Muckle | d5d59a5 | 2013-05-31 10:39:31 -0700 | [diff] [blame] | 1055 | struct cpu_dbs_info_s *target_dbs_info = |
| 1056 | &per_cpu(od_cpu_dbs_info, target_cpu); |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1057 | |
| Steve Muckle | d5d59a5 | 2013-05-31 10:39:31 -0700 | [diff] [blame] | 1058 | atomic_set(&target_dbs_info->src_sync_cpu, (int)arg); |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1059 | |
| 1060 | return NOTIFY_OK; |
| 1061 | } |
| 1062 | |
| 1063 | static struct notifier_block dbs_migration_nb = { |
| 1064 | .notifier_call = dbs_migration_notify, |
| 1065 | }; |
| 1066 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1067 | static void dbs_input_event(struct input_handle *handle, unsigned int type, |
| 1068 | unsigned int code, int value) |
| 1069 | { |
| 1070 | int i; |
| 1071 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 1072 | if ((dbs_tuners_ins.powersave_bias == POWERSAVE_BIAS_MAXLEVEL) || |
| 1073 | (dbs_tuners_ins.powersave_bias == POWERSAVE_BIAS_MINLEVEL)) { |
| 1074 | /* nothing to do */ |
| 1075 | return; |
| 1076 | } |
| 1077 | |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 1078 | for_each_online_cpu(i) |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 1079 | queue_work_on(i, dbs_wq, &per_cpu(dbs_refresh_work, i).work); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | static int dbs_input_connect(struct input_handler *handler, |
| 1083 | struct input_dev *dev, const struct input_device_id *id) |
| 1084 | { |
| 1085 | struct input_handle *handle; |
| 1086 | int error; |
| 1087 | |
| 1088 | handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); |
| 1089 | if (!handle) |
| 1090 | return -ENOMEM; |
| 1091 | |
| 1092 | handle->dev = dev; |
| 1093 | handle->handler = handler; |
| 1094 | handle->name = "cpufreq"; |
| 1095 | |
| 1096 | error = input_register_handle(handle); |
| 1097 | if (error) |
| 1098 | goto err2; |
| 1099 | |
| 1100 | error = input_open_device(handle); |
| 1101 | if (error) |
| 1102 | goto err1; |
| 1103 | |
| 1104 | return 0; |
| 1105 | err1: |
| 1106 | input_unregister_handle(handle); |
| 1107 | err2: |
| 1108 | kfree(handle); |
| 1109 | return error; |
| 1110 | } |
| 1111 | |
| 1112 | static void dbs_input_disconnect(struct input_handle *handle) |
| 1113 | { |
| 1114 | input_close_device(handle); |
| 1115 | input_unregister_handle(handle); |
| 1116 | kfree(handle); |
| 1117 | } |
| 1118 | |
| 1119 | static const struct input_device_id dbs_ids[] = { |
| Tingwei Zhang | f28dade | 2013-07-03 16:28:24 +0800 | [diff] [blame] | 1120 | /* multi-touch touchscreen */ |
| 1121 | { |
| 1122 | .flags = INPUT_DEVICE_ID_MATCH_EVBIT | |
| 1123 | INPUT_DEVICE_ID_MATCH_ABSBIT, |
| 1124 | .evbit = { BIT_MASK(EV_ABS) }, |
| 1125 | .absbit = { [BIT_WORD(ABS_MT_POSITION_X)] = |
| 1126 | BIT_MASK(ABS_MT_POSITION_X) | |
| 1127 | BIT_MASK(ABS_MT_POSITION_Y) }, |
| 1128 | }, |
| 1129 | /* touchpad */ |
| 1130 | { |
| 1131 | .flags = INPUT_DEVICE_ID_MATCH_KEYBIT | |
| 1132 | INPUT_DEVICE_ID_MATCH_ABSBIT, |
| 1133 | .keybit = { [BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) }, |
| 1134 | .absbit = { [BIT_WORD(ABS_X)] = |
| 1135 | BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) }, |
| 1136 | }, |
| 1137 | /* Keypad */ |
| 1138 | { |
| 1139 | .flags = INPUT_DEVICE_ID_MATCH_EVBIT, |
| 1140 | .evbit = { BIT_MASK(EV_KEY) }, |
| 1141 | }, |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1142 | { }, |
| 1143 | }; |
| 1144 | |
| 1145 | static struct input_handler dbs_input_handler = { |
| 1146 | .event = dbs_input_event, |
| 1147 | .connect = dbs_input_connect, |
| 1148 | .disconnect = dbs_input_disconnect, |
| 1149 | .name = "cpufreq_ond", |
| 1150 | .id_table = dbs_ids, |
| 1151 | }; |
| 1152 | |
| myfluxi | 5ece427 | 2014-02-06 21:14:57 +0100 | [diff] [blame] | 1153 | static int sync_pending(struct cpu_dbs_info_s *this_dbs_info) |
| 1154 | { |
| 1155 | return atomic_read(&this_dbs_info->src_sync_cpu) >= 0; |
| 1156 | } |
| 1157 | |
| 1158 | static int dbs_sync_should_run(unsigned int dest_cpu) |
| 1159 | { |
| 1160 | struct cpu_dbs_info_s *this_dbs_info; |
| 1161 | |
| 1162 | this_dbs_info = &per_cpu(od_cpu_dbs_info, dest_cpu); |
| 1163 | |
| 1164 | return sync_pending(this_dbs_info); |
| 1165 | } |
| 1166 | |
| 1167 | static void run_dbs_sync(unsigned int dest_cpu) |
| 1168 | { |
| 1169 | int src_cpu, cpu = dest_cpu; |
| 1170 | unsigned int src_freq, src_max_load; |
| 1171 | struct cpu_dbs_info_s *this_dbs_info, *src_dbs_info; |
| 1172 | struct cpufreq_policy *policy; |
| 1173 | int delay; |
| 1174 | |
| 1175 | this_dbs_info = &per_cpu(od_cpu_dbs_info, cpu); |
| 1176 | |
| 1177 | get_online_cpus(); |
| 1178 | |
| 1179 | src_cpu = atomic_read(&this_dbs_info->src_sync_cpu); |
| 1180 | src_dbs_info = &per_cpu(od_cpu_dbs_info, src_cpu); |
| 1181 | if (src_dbs_info != NULL && src_dbs_info->cur_policy != NULL) { |
| 1182 | src_freq = src_dbs_info->cur_policy->cur; |
| 1183 | src_max_load = src_dbs_info->max_load; |
| 1184 | } else { |
| 1185 | src_freq = dbs_tuners_ins.sync_freq; |
| 1186 | src_max_load = 0; |
| 1187 | } |
| 1188 | |
| 1189 | if (lock_policy_rwsem_write(cpu) < 0) |
| 1190 | goto bail_acq_sema_failed; |
| 1191 | |
| 1192 | if (!atomic_read(&this_dbs_info->sync_enabled)) { |
| 1193 | atomic_set(&this_dbs_info->src_sync_cpu, -1); |
| 1194 | put_online_cpus(); |
| 1195 | unlock_policy_rwsem_write(cpu); |
| 1196 | return; |
| 1197 | } |
| 1198 | |
| 1199 | policy = this_dbs_info->cur_policy; |
| 1200 | if (!policy) { |
| 1201 | /* CPU not using ondemand governor */ |
| 1202 | goto bail_incorrect_governor; |
| 1203 | } |
| 1204 | delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
| 1205 | |
| 1206 | |
| 1207 | if (policy->cur < src_freq) { |
| 1208 | /* cancel the next ondemand sample */ |
| 1209 | cancel_delayed_work_sync(&this_dbs_info->work); |
| 1210 | |
| 1211 | /* |
| 1212 | * Arch specific cpufreq driver may fail. |
| 1213 | * Don't update governor frequency upon failure. |
| 1214 | */ |
| 1215 | if (__cpufreq_driver_target(policy, src_freq, |
| 1216 | CPUFREQ_RELATION_L) >= 0) { |
| 1217 | policy->cur = src_freq; |
| 1218 | if (src_max_load > this_dbs_info->max_load) { |
| 1219 | this_dbs_info->max_load = src_max_load; |
| 1220 | this_dbs_info->prev_load = src_max_load; |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | /* reschedule the next ondemand sample */ |
| 1225 | mutex_lock(&this_dbs_info->timer_mutex); |
| 1226 | schedule_delayed_work_on(cpu, &this_dbs_info->work, |
| 1227 | delay); |
| 1228 | mutex_unlock(&this_dbs_info->timer_mutex); |
| 1229 | } |
| 1230 | |
| 1231 | bail_incorrect_governor: |
| 1232 | unlock_policy_rwsem_write(cpu); |
| 1233 | bail_acq_sema_failed: |
| 1234 | put_online_cpus(); |
| 1235 | atomic_set(&this_dbs_info->src_sync_cpu, -1); |
| 1236 | } |
| 1237 | |
| 1238 | static struct smp_hotplug_thread dbs_sync_threads = { |
| 1239 | .store = &sync_thread, |
| 1240 | .thread_should_run = dbs_sync_should_run, |
| 1241 | .thread_fn = run_dbs_sync, |
| 1242 | .thread_comm = "dbs_sync/%u", |
| 1243 | }; |
| 1244 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, |
| 1246 | unsigned int event) |
| 1247 | { |
| 1248 | unsigned int cpu = policy->cpu; |
| 1249 | struct cpu_dbs_info_s *this_dbs_info; |
| 1250 | unsigned int j; |
| Jeff Garzik | 914f7c3 | 2006-10-20 14:31:00 -0700 | [diff] [blame] | 1251 | int rc; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
| Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1253 | this_dbs_info = &per_cpu(od_cpu_dbs_info, cpu); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | switch (event) { |
| 1256 | case CPUFREQ_GOV_START: |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 1257 | if ((!cpu_online(cpu)) || (!policy->cur)) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | return -EINVAL; |
| 1259 | |
| akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 1260 | mutex_lock(&dbs_mutex); |
| Jeff Garzik | 914f7c3 | 2006-10-20 14:31:00 -0700 | [diff] [blame] | 1261 | |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 1262 | dbs_enable++; |
| Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 1263 | for_each_cpu(j, policy->cpus) { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | struct cpu_dbs_info_s *j_dbs_info; |
| Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1265 | j_dbs_info = &per_cpu(od_cpu_dbs_info, j); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | j_dbs_info->cur_policy = policy; |
| Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1267 | |
| venkatesh.pallipadi@intel.com | 3430502 | 2008-08-04 11:59:09 -0700 | [diff] [blame] | 1268 | j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j, |
| Viresh Kumar | efa514d | 2013-05-17 11:26:32 +0000 | [diff] [blame^] | 1269 | &j_dbs_info->prev_cpu_wall, dbs_tuners_ins.io_is_busy); |
| Glauber Costa | 3292beb | 2011-11-28 14:45:17 -0200 | [diff] [blame] | 1270 | if (dbs_tuners_ins.ignore_nice) |
| Venkatesh Pallipadi | 1ca3abd | 2009-01-23 09:25:02 -0500 | [diff] [blame] | 1271 | j_dbs_info->prev_cpu_nice = |
| Glauber Costa | 3292beb | 2011-11-28 14:45:17 -0200 | [diff] [blame] | 1272 | kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
| Rohit Gupta | 92daa72 | 2013-06-17 17:56:27 -0700 | [diff] [blame] | 1273 | if (!dbs_tuners_ins.powersave_bias) |
| 1274 | atomic_set(&j_dbs_info->sync_enabled, 1); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | } |
| Venkatesh Pallipadi | 529af7a | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1276 | this_dbs_info->cpu = cpu; |
| David C Niemi | 3f78a9f | 2010-10-06 16:54:24 -0400 | [diff] [blame] | 1277 | this_dbs_info->rate_mult = 1; |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 1278 | ondemand_powersave_bias_init_cpu(cpu); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | /* |
| 1280 | * Start the timerschedule work, when this governor |
| 1281 | * is used for first time |
| 1282 | */ |
| 1283 | if (dbs_enable == 1) { |
| 1284 | unsigned int latency; |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 1285 | |
| 1286 | rc = sysfs_create_group(cpufreq_global_kobject, |
| 1287 | &dbs_attr_group); |
| 1288 | if (rc) { |
| 1289 | mutex_unlock(&dbs_mutex); |
| 1290 | return rc; |
| 1291 | } |
| 1292 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | /* policy latency is in nS. Convert it to uS first */ |
| Dave Jones | df8b59b | 2005-09-20 12:39:35 -0700 | [diff] [blame] | 1294 | latency = policy->cpuinfo.transition_latency / 1000; |
| 1295 | if (latency == 0) |
| 1296 | latency = 1; |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 1297 | /* Bring kernel and HW constraints together */ |
| 1298 | min_sampling_rate = max(min_sampling_rate, |
| 1299 | MIN_LATENCY_MULTIPLIER * latency); |
| 1300 | dbs_tuners_ins.sampling_rate = |
| 1301 | max(min_sampling_rate, |
| 1302 | latency * LATENCY_MULTIPLIER); |
| Arjan van de Ven | 19379b1 | 2010-05-09 08:26:51 -0700 | [diff] [blame] | 1303 | dbs_tuners_ins.io_is_busy = should_io_be_busy(); |
| Narayanan Gopalakrishnan | fabf0f1 | 2012-10-19 17:24:53 -0700 | [diff] [blame] | 1304 | |
| 1305 | if (dbs_tuners_ins.optimal_freq == 0) |
| 1306 | dbs_tuners_ins.optimal_freq = policy->min; |
| 1307 | |
| 1308 | if (dbs_tuners_ins.sync_freq == 0) |
| 1309 | dbs_tuners_ins.sync_freq = policy->min; |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1310 | |
| 1311 | atomic_notifier_chain_register(&migration_notifier_head, |
| 1312 | &dbs_migration_nb); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1314 | if (!cpu) |
| 1315 | rc = input_register_handler(&dbs_input_handler); |
| akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 1316 | mutex_unlock(&dbs_mutex); |
| venkatesh.pallipadi@intel.com | 7d26e2d | 2009-07-02 17:08:30 -0700 | [diff] [blame] | 1317 | |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 1318 | |
| 1319 | if (!ondemand_powersave_bias_setspeed( |
| 1320 | this_dbs_info->cur_policy, |
| 1321 | NULL, |
| 1322 | dbs_tuners_ins.powersave_bias)) |
| 1323 | dbs_timer_init(this_dbs_info); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | break; |
| 1325 | |
| 1326 | case CPUFREQ_GOV_STOP: |
| Linus Torvalds | 2cd7cbd | 2006-07-23 12:05:00 -0700 | [diff] [blame] | 1327 | dbs_timer_exit(this_dbs_info); |
| venkatesh.pallipadi@intel.com | 7d26e2d | 2009-07-02 17:08:30 -0700 | [diff] [blame] | 1328 | |
| 1329 | mutex_lock(&dbs_mutex); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | dbs_enable--; |
| Steve Muckle | d5d59a5 | 2013-05-31 10:39:31 -0700 | [diff] [blame] | 1331 | |
| 1332 | for_each_cpu(j, policy->cpus) { |
| 1333 | struct cpu_dbs_info_s *j_dbs_info; |
| 1334 | j_dbs_info = &per_cpu(od_cpu_dbs_info, j); |
| 1335 | atomic_set(&j_dbs_info->sync_enabled, 0); |
| 1336 | } |
| 1337 | |
| Anitha Anand | 3dd6509 | 2012-01-18 17:17:40 -0800 | [diff] [blame] | 1338 | /* If device is being removed, policy is no longer |
| 1339 | * valid. */ |
| 1340 | this_dbs_info->cur_policy = NULL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1341 | if (!cpu) |
| 1342 | input_unregister_handler(&dbs_input_handler); |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1343 | if (!dbs_enable) { |
| Thomas Renninger | 0e625ac | 2009-07-24 15:25:06 +0200 | [diff] [blame] | 1344 | sysfs_remove_group(cpufreq_global_kobject, |
| 1345 | &dbs_attr_group); |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1346 | atomic_notifier_chain_unregister( |
| 1347 | &migration_notifier_head, |
| 1348 | &dbs_migration_nb); |
| 1349 | } |
| 1350 | |
| Swetha Chikkaboraiah | fbb12f3 | 2013-10-31 17:55:48 +0530 | [diff] [blame] | 1351 | mutex_unlock(&dbs_mutex); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
| 1353 | break; |
| 1354 | |
| 1355 | case CPUFREQ_GOV_LIMITS: |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 1356 | mutex_lock(&this_dbs_info->timer_mutex); |
| Swetha Chikkaboraiah | b69d159 | 2013-11-20 17:24:06 +0530 | [diff] [blame] | 1357 | if (!this_dbs_info->cur_policy) { |
| 1358 | pr_err("Dbs policy is NULL\n"); |
| 1359 | mutex_unlock(&this_dbs_info->timer_mutex); |
| 1360 | return -EINVAL; |
| 1361 | } |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | if (policy->max < this_dbs_info->cur_policy->cur) |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 1363 | __cpufreq_driver_target(this_dbs_info->cur_policy, |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 1364 | policy->max, CPUFREQ_RELATION_H); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | else if (policy->min > this_dbs_info->cur_policy->cur) |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 1366 | __cpufreq_driver_target(this_dbs_info->cur_policy, |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 1367 | policy->min, CPUFREQ_RELATION_L); |
| David Ng | 8192a2f | 2012-01-19 14:16:19 -0800 | [diff] [blame] | 1368 | else if (dbs_tuners_ins.powersave_bias != 0) |
| 1369 | ondemand_powersave_bias_setspeed( |
| 1370 | this_dbs_info->cur_policy, |
| 1371 | policy, |
| 1372 | dbs_tuners_ins.powersave_bias); |
| venkatesh.pallipadi@intel.com | 5a75c82 | 2009-07-02 17:08:32 -0700 | [diff] [blame] | 1373 | mutex_unlock(&this_dbs_info->timer_mutex); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | break; |
| 1375 | } |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | static int __init cpufreq_gov_dbs_init(void) |
| 1380 | { |
| Andrea Righi | 4f6e6b9 | 2008-09-18 10:43:40 +0000 | [diff] [blame] | 1381 | u64 idle_time; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1382 | unsigned int i; |
| myfluxi | 5ece427 | 2014-02-06 21:14:57 +0100 | [diff] [blame] | 1383 | int rc, cpu = get_cpu(); |
| venkatesh.pallipadi@intel.com | 8080091 | 2008-08-04 11:59:12 -0700 | [diff] [blame] | 1384 | |
| Kamalesh Babulal | 21f2e3c | 2011-12-09 16:18:42 +0530 | [diff] [blame] | 1385 | idle_time = get_cpu_idle_time_us(cpu, NULL); |
| Andrea Righi | 4f6e6b9 | 2008-09-18 10:43:40 +0000 | [diff] [blame] | 1386 | put_cpu(); |
| venkatesh.pallipadi@intel.com | 8080091 | 2008-08-04 11:59:12 -0700 | [diff] [blame] | 1387 | if (idle_time != -1ULL) { |
| 1388 | /* Idle micro accounting is supported. Use finer thresholds */ |
| 1389 | dbs_tuners_ins.up_threshold = MICRO_FREQUENCY_UP_THRESHOLD; |
| 1390 | dbs_tuners_ins.down_differential = |
| 1391 | MICRO_FREQUENCY_DOWN_DIFFERENTIAL; |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 1392 | /* |
| Paul Bolle | bd74b32 | 2011-08-06 14:33:43 +0200 | [diff] [blame] | 1393 | * In nohz/micro accounting case we set the minimum frequency |
| Thomas Renninger | cef9615 | 2009-04-22 13:48:29 +0200 | [diff] [blame] | 1394 | * not depending on HZ, but fixed (very low). The deferred |
| 1395 | * timer might skip some samples if idle/sleeping as needed. |
| 1396 | */ |
| 1397 | min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE; |
| 1398 | } else { |
| 1399 | /* For correct statistics, we need 10 ticks for each measure */ |
| 1400 | min_sampling_rate = |
| 1401 | MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10); |
| venkatesh.pallipadi@intel.com | 8080091 | 2008-08-04 11:59:12 -0700 | [diff] [blame] | 1402 | } |
| Akinobu Mita | 888a794 | 2008-07-14 12:00:45 +0900 | [diff] [blame] | 1403 | |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 1404 | dbs_wq = alloc_workqueue("ondemand_dbs_wq", WQ_HIGHPRI, 0); |
| 1405 | if (!dbs_wq) { |
| 1406 | printk(KERN_ERR "Failed to create ondemand_dbs_wq workqueue\n"); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1407 | return -EFAULT; |
| 1408 | } |
| 1409 | for_each_possible_cpu(i) { |
| Praveen Chidambaram | 457a445 | 2012-07-19 10:45:07 -0600 | [diff] [blame] | 1410 | struct cpu_dbs_info_s *this_dbs_info = |
| 1411 | &per_cpu(od_cpu_dbs_info, i); |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 1412 | struct dbs_work_struct *dbs_work = |
| 1413 | &per_cpu(dbs_refresh_work, i); |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1414 | |
| Praveen Chidambaram | 457a445 | 2012-07-19 10:45:07 -0600 | [diff] [blame] | 1415 | mutex_init(&this_dbs_info->timer_mutex); |
| Stephen Boyd | b94083c | 2012-10-31 17:43:08 -0700 | [diff] [blame] | 1416 | INIT_WORK(&dbs_work->work, dbs_refresh_callback); |
| 1417 | dbs_work->cpu = i; |
| Rohit Gupta | 093a213 | 2013-04-04 15:45:16 -0700 | [diff] [blame] | 1418 | |
| Steve Muckle | d5d59a5 | 2013-05-31 10:39:31 -0700 | [diff] [blame] | 1419 | atomic_set(&this_dbs_info->src_sync_cpu, -1); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| myfluxi | 5ece427 | 2014-02-06 21:14:57 +0100 | [diff] [blame] | 1422 | rc = smpboot_register_percpu_thread(&dbs_sync_threads); |
| 1423 | if (rc) |
| 1424 | printk(KERN_ERR "Failed to register dbs_sync threads\n"); |
| 1425 | |
| Tejun Heo | 57df557 | 2011-01-26 12:12:50 +0100 | [diff] [blame] | 1426 | return cpufreq_register_governor(&cpufreq_gov_ondemand); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | static void __exit cpufreq_gov_dbs_exit(void) |
| 1430 | { |
| Anji Jonnala | 1676aad | 2012-11-14 13:34:54 +0530 | [diff] [blame] | 1431 | unsigned int i; |
| 1432 | |
| Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 1433 | cpufreq_unregister_governor(&cpufreq_gov_ondemand); |
| Anji Jonnala | 1676aad | 2012-11-14 13:34:54 +0530 | [diff] [blame] | 1434 | for_each_possible_cpu(i) { |
| 1435 | struct cpu_dbs_info_s *this_dbs_info = |
| 1436 | &per_cpu(od_cpu_dbs_info, i); |
| 1437 | mutex_destroy(&this_dbs_info->timer_mutex); |
| 1438 | } |
| Matt Wagantall | e3f2f66 | 2013-05-23 15:52:49 -0700 | [diff] [blame] | 1439 | destroy_workqueue(dbs_wq); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 1443 | MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>"); |
| 1444 | MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>"); |
| 1445 | MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for " |
| Dave Jones | 2b03f89 | 2009-01-18 01:43:44 -0500 | [diff] [blame] | 1446 | "Low Latency Frequency Transition capable processors"); |
| Venkatesh Pallipadi | ffac80e | 2006-06-28 13:52:18 -0700 | [diff] [blame] | 1447 | MODULE_LICENSE("GPL"); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
| Johannes Weiner | 6915719 | 2008-01-17 15:21:08 -0800 | [diff] [blame] | 1449 | #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND |
| 1450 | fs_initcall(cpufreq_gov_dbs_init); |
| 1451 | #else |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | module_init(cpufreq_gov_dbs_init); |
| Johannes Weiner | 6915719 | 2008-01-17 15:21:08 -0800 | [diff] [blame] | 1453 | #endif |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | module_exit(cpufreq_gov_dbs_exit); |