cpufreq_conservative.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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>
  7. * (C) 2009 Alexander Clouter <alex@digriz.org.uk>
  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. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/cpufreq.h>
  17. #include <linux/cpu.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/kernel_stat.h>
  20. #include <linux/mutex.h>
  21. #include <linux/hrtimer.h>
  22. #include <linux/tick.h>
  23. #include <linux/ktime.h>
  24. #include <linux/sched.h>
  25. /*
  26. * dbs is used in this file as a shortform for demandbased switching
  27. * It helps to keep variable names smaller, simpler
  28. */
  29. #define DEF_FREQUENCY_UP_THRESHOLD (80)
  30. #define DEF_FREQUENCY_DOWN_THRESHOLD (20)
  31. /*
  32. * The polling frequency of this governor depends on the capability of
  33. * the processor. Default polling frequency is 1000 times the transition
  34. * latency of the processor. The governor will work on any processor with
  35. * transition latency <= 10mS, using appropriate sampling
  36. * rate.
  37. * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL)
  38. * this governor will not work.
  39. * All times here are in uS.
  40. */
  41. static unsigned int def_sampling_rate;
  42. #define MIN_SAMPLING_RATE_RATIO (2)
  43. /* for correct statistics, we need at least 10 ticks between each measure */
  44. #define MIN_STAT_SAMPLING_RATE \
  45. (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
  46. #define MIN_SAMPLING_RATE \
  47. (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
  48. /* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon
  49. * Define the minimal settable sampling rate to the greater of:
  50. * - "HW transition latency" * 100 (same as default sampling / 10)
  51. * - MIN_STAT_SAMPLING_RATE
  52. * To avoid that userspace shoots itself.
  53. */
  54. static unsigned int minimum_sampling_rate(void)
  55. {
  56. return max(def_sampling_rate / 10, MIN_STAT_SAMPLING_RATE);
  57. }
  58. /* This will also vanish soon with removing sampling_rate_max */
  59. #define MAX_SAMPLING_RATE (500 * def_sampling_rate)
  60. #define LATENCY_MULTIPLIER (1000)
  61. #define DEF_SAMPLING_DOWN_FACTOR (1)
  62. #define MAX_SAMPLING_DOWN_FACTOR (10)
  63. #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
  64. static void do_dbs_timer(struct work_struct *work);
  65. struct cpu_dbs_info_s {
  66. cputime64_t prev_cpu_idle;
  67. cputime64_t prev_cpu_wall;
  68. cputime64_t prev_cpu_nice;
  69. struct cpufreq_policy *cur_policy;
  70. struct delayed_work work;
  71. unsigned int down_skip;
  72. unsigned int requested_freq;
  73. int cpu;
  74. unsigned int enable:1;
  75. };
  76. static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
  77. static unsigned int dbs_enable; /* number of CPUs using this policy */
  78. /*
  79. * DEADLOCK ALERT! There is a ordering requirement between cpu_hotplug
  80. * lock and dbs_mutex. cpu_hotplug lock should always be held before
  81. * dbs_mutex. If any function that can potentially take cpu_hotplug lock
  82. * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then
  83. * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock
  84. * is recursive for the same process. -Venki
  85. */
  86. static DEFINE_MUTEX(dbs_mutex);
  87. static struct workqueue_struct *kconservative_wq;
  88. static struct dbs_tuners {
  89. unsigned int sampling_rate;
  90. unsigned int sampling_down_factor;
  91. unsigned int up_threshold;
  92. unsigned int down_threshold;
  93. unsigned int ignore_nice;
  94. unsigned int freq_step;
  95. } dbs_tuners_ins = {
  96. .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
  97. .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
  98. .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
  99. .ignore_nice = 0,
  100. .freq_step = 5,
  101. };
  102. static inline cputime64_t get_cpu_idle_time_jiffy(unsigned int cpu,
  103. cputime64_t *wall)
  104. {
  105. cputime64_t idle_time;
  106. cputime64_t cur_wall_time;
  107. cputime64_t busy_time;
  108. cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
  109. busy_time = cputime64_add(kstat_cpu(cpu).cpustat.user,
  110. kstat_cpu(cpu).cpustat.system);
  111. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.irq);
  112. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.softirq);
  113. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.steal);
  114. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.nice);
  115. idle_time = cputime64_sub(cur_wall_time, busy_time);
  116. if (wall)
  117. *wall = cur_wall_time;
  118. return idle_time;
  119. }
  120. static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall)
  121. {
  122. u64 idle_time = get_cpu_idle_time_us(cpu, wall);
  123. if (idle_time == -1ULL)
  124. return get_cpu_idle_time_jiffy(cpu, wall);
  125. return idle_time;
  126. }
  127. /* keep track of frequency transitions */
  128. static int
  129. dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
  130. void *data)
  131. {
  132. struct cpufreq_freqs *freq = data;
  133. struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info,
  134. freq->cpu);
  135. struct cpufreq_policy *policy;
  136. if (!this_dbs_info->enable)
  137. return 0;
  138. policy = this_dbs_info->cur_policy;
  139. /*
  140. * we only care if our internally tracked freq moves outside
  141. * the 'valid' ranges of freqency available to us otherwise
  142. * we do not change it
  143. */
  144. if (this_dbs_info->requested_freq > policy->max
  145. || this_dbs_info->requested_freq < policy->min)
  146. this_dbs_info->requested_freq = freq->new;
  147. return 0;
  148. }
  149. static struct notifier_block dbs_cpufreq_notifier_block = {
  150. .notifier_call = dbs_cpufreq_notifier
  151. };
  152. /************************** sysfs interface ************************/
  153. static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf)
  154. {
  155. static int print_once;
  156. if (!print_once) {
  157. printk(KERN_INFO "CPUFREQ: conservative sampling_rate_max "
  158. "sysfs file is deprecated - used by: %s\n",
  159. current->comm);
  160. print_once = 1;
  161. }
  162. return sprintf(buf, "%u\n", MAX_SAMPLING_RATE);
  163. }
  164. static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf)
  165. {
  166. static int print_once;
  167. if (!print_once) {
  168. printk(KERN_INFO "CPUFREQ: conservative sampling_rate_max "
  169. "sysfs file is deprecated - used by: %s\n", current->comm);
  170. print_once = 1;
  171. }
  172. return sprintf(buf, "%u\n", MIN_SAMPLING_RATE);
  173. }
  174. #define define_one_ro(_name) \
  175. static struct freq_attr _name = \
  176. __ATTR(_name, 0444, show_##_name, NULL)
  177. define_one_ro(sampling_rate_max);
  178. define_one_ro(sampling_rate_min);
  179. /* cpufreq_conservative Governor Tunables */
  180. #define show_one(file_name, object) \
  181. static ssize_t show_##file_name \
  182. (struct cpufreq_policy *unused, char *buf) \
  183. { \
  184. return sprintf(buf, "%u\n", dbs_tuners_ins.object); \
  185. }
  186. show_one(sampling_rate, sampling_rate);
  187. show_one(sampling_down_factor, sampling_down_factor);
  188. show_one(up_threshold, up_threshold);
  189. show_one(down_threshold, down_threshold);
  190. show_one(ignore_nice_load, ignore_nice);
  191. show_one(freq_step, freq_step);
  192. static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
  193. const char *buf, size_t count)
  194. {
  195. unsigned int input;
  196. int ret;
  197. ret = sscanf(buf, "%u", &input);
  198. if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
  199. return -EINVAL;
  200. mutex_lock(&dbs_mutex);
  201. dbs_tuners_ins.sampling_down_factor = input;
  202. mutex_unlock(&dbs_mutex);
  203. return count;
  204. }
  205. static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
  206. const char *buf, size_t count)
  207. {
  208. unsigned int input;
  209. int ret;
  210. ret = sscanf(buf, "%u", &input);
  211. if (ret != 1)
  212. return -EINVAL;
  213. mutex_lock(&dbs_mutex);
  214. dbs_tuners_ins.sampling_rate = max(input, minimum_sampling_rate());
  215. mutex_unlock(&dbs_mutex);
  216. return count;
  217. }
  218. static ssize_t store_up_threshold(struct cpufreq_policy *unused,
  219. const char *buf, size_t count)
  220. {
  221. unsigned int input;
  222. int ret;
  223. ret = sscanf(buf, "%u", &input);
  224. mutex_lock(&dbs_mutex);
  225. if (ret != 1 || input > 100 ||
  226. input <= dbs_tuners_ins.down_threshold) {
  227. mutex_unlock(&dbs_mutex);
  228. return -EINVAL;
  229. }
  230. dbs_tuners_ins.up_threshold = input;
  231. mutex_unlock(&dbs_mutex);
  232. return count;
  233. }
  234. static ssize_t store_down_threshold(struct cpufreq_policy *unused,
  235. const char *buf, size_t count)
  236. {
  237. unsigned int input;
  238. int ret;
  239. ret = sscanf(buf, "%u", &input);
  240. mutex_lock(&dbs_mutex);
  241. /* cannot be lower than 11 otherwise freq will not fall */
  242. if (ret != 1 || input < 11 || input > 100 ||
  243. input >= dbs_tuners_ins.up_threshold) {
  244. mutex_unlock(&dbs_mutex);
  245. return -EINVAL;
  246. }
  247. dbs_tuners_ins.down_threshold = input;
  248. mutex_unlock(&dbs_mutex);
  249. return count;
  250. }
  251. static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
  252. const char *buf, size_t count)
  253. {
  254. unsigned int input;
  255. int ret;
  256. unsigned int j;
  257. ret = sscanf(buf, "%u", &input);
  258. if (ret != 1)
  259. return -EINVAL;
  260. if (input > 1)
  261. input = 1;
  262. mutex_lock(&dbs_mutex);
  263. if (input == dbs_tuners_ins.ignore_nice) { /* nothing to do */
  264. mutex_unlock(&dbs_mutex);
  265. return count;
  266. }
  267. dbs_tuners_ins.ignore_nice = input;
  268. /* we need to re-evaluate prev_cpu_idle */
  269. for_each_online_cpu(j) {
  270. struct cpu_dbs_info_s *dbs_info;
  271. dbs_info = &per_cpu(cpu_dbs_info, j);
  272. dbs_info->prev_cpu_idle = get_cpu_idle_time(j,
  273. &dbs_info->prev_cpu_wall);
  274. if (dbs_tuners_ins.ignore_nice)
  275. dbs_info->prev_cpu_nice = kstat_cpu(j).cpustat.nice;
  276. }
  277. mutex_unlock(&dbs_mutex);
  278. return count;
  279. }
  280. static ssize_t store_freq_step(struct cpufreq_policy *policy,
  281. const char *buf, size_t count)
  282. {
  283. unsigned int input;
  284. int ret;
  285. ret = sscanf(buf, "%u", &input);
  286. if (ret != 1)
  287. return -EINVAL;
  288. if (input > 100)
  289. input = 100;
  290. /* no need to test here if freq_step is zero as the user might actually
  291. * want this, they would be crazy though :) */
  292. mutex_lock(&dbs_mutex);
  293. dbs_tuners_ins.freq_step = input;
  294. mutex_unlock(&dbs_mutex);
  295. return count;
  296. }
  297. #define define_one_rw(_name) \
  298. static struct freq_attr _name = \
  299. __ATTR(_name, 0644, show_##_name, store_##_name)
  300. define_one_rw(sampling_rate);
  301. define_one_rw(sampling_down_factor);
  302. define_one_rw(up_threshold);
  303. define_one_rw(down_threshold);
  304. define_one_rw(ignore_nice_load);
  305. define_one_rw(freq_step);
  306. static struct attribute *dbs_attributes[] = {
  307. &sampling_rate_max.attr,
  308. &sampling_rate_min.attr,
  309. &sampling_rate.attr,
  310. &sampling_down_factor.attr,
  311. &up_threshold.attr,
  312. &down_threshold.attr,
  313. &ignore_nice_load.attr,
  314. &freq_step.attr,
  315. NULL
  316. };
  317. static struct attribute_group dbs_attr_group = {
  318. .attrs = dbs_attributes,
  319. .name = "conservative",
  320. };
  321. /************************** sysfs end ************************/
  322. static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
  323. {
  324. unsigned int load = 0;
  325. unsigned int freq_target;
  326. struct cpufreq_policy *policy;
  327. unsigned int j;
  328. policy = this_dbs_info->cur_policy;
  329. /*
  330. * Every sampling_rate, we check, if current idle time is less
  331. * than 20% (default), then we try to increase frequency
  332. * Every sampling_rate*sampling_down_factor, we check, if current
  333. * idle time is more than 80%, then we try to decrease frequency
  334. *
  335. * Any frequency increase takes it to the maximum frequency.
  336. * Frequency reduction happens at minimum steps of
  337. * 5% (default) of maximum frequency
  338. */
  339. /* Get Absolute Load */
  340. for_each_cpu(j, policy->cpus) {
  341. struct cpu_dbs_info_s *j_dbs_info;
  342. cputime64_t cur_wall_time, cur_idle_time;
  343. unsigned int idle_time, wall_time;
  344. j_dbs_info = &per_cpu(cpu_dbs_info, j);
  345. cur_idle_time = get_cpu_idle_time(j, &cur_wall_time);
  346. wall_time = (unsigned int) cputime64_sub(cur_wall_time,
  347. j_dbs_info->prev_cpu_wall);
  348. j_dbs_info->prev_cpu_wall = cur_wall_time;
  349. idle_time = (unsigned int) cputime64_sub(cur_idle_time,
  350. j_dbs_info->prev_cpu_idle);
  351. j_dbs_info->prev_cpu_idle = cur_idle_time;
  352. if (dbs_tuners_ins.ignore_nice) {
  353. cputime64_t cur_nice;
  354. unsigned long cur_nice_jiffies;
  355. cur_nice = cputime64_sub(kstat_cpu(j).cpustat.nice,
  356. j_dbs_info->prev_cpu_nice);
  357. /*
  358. * Assumption: nice time between sampling periods will
  359. * be less than 2^32 jiffies for 32 bit sys
  360. */
  361. cur_nice_jiffies = (unsigned long)
  362. cputime64_to_jiffies64(cur_nice);
  363. j_dbs_info->prev_cpu_nice = kstat_cpu(j).cpustat.nice;
  364. idle_time += jiffies_to_usecs(cur_nice_jiffies);
  365. }
  366. if (unlikely(!wall_time || wall_time < idle_time))
  367. continue;
  368. load = 100 * (wall_time - idle_time) / wall_time;
  369. }
  370. /*
  371. * break out if we 'cannot' reduce the speed as the user might
  372. * want freq_step to be zero
  373. */
  374. if (dbs_tuners_ins.freq_step == 0)
  375. return;
  376. /* Check for frequency increase */
  377. if (load > dbs_tuners_ins.up_threshold) {
  378. this_dbs_info->down_skip = 0;
  379. /* if we are already at full speed then break out early */
  380. if (this_dbs_info->requested_freq == policy->max)
  381. return;
  382. freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100;
  383. /* max freq cannot be less than 100. But who knows.... */
  384. if (unlikely(freq_target == 0))
  385. freq_target = 5;
  386. this_dbs_info->requested_freq += freq_target;
  387. if (this_dbs_info->requested_freq > policy->max)
  388. this_dbs_info->requested_freq = policy->max;
  389. __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
  390. CPUFREQ_RELATION_H);
  391. return;
  392. }
  393. /*
  394. * The optimal frequency is the frequency that is the lowest that
  395. * can support the current CPU usage without triggering the up
  396. * policy. To be safe, we focus 10 points under the threshold.
  397. */
  398. if (load < (dbs_tuners_ins.down_threshold - 10)) {
  399. freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100;
  400. this_dbs_info->requested_freq -= freq_target;
  401. if (this_dbs_info->requested_freq < policy->min)
  402. this_dbs_info->requested_freq = policy->min;
  403. /*
  404. * if we cannot reduce the frequency anymore, break out early
  405. */
  406. if (policy->cur == policy->min)
  407. return;
  408. __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
  409. CPUFREQ_RELATION_H);
  410. return;
  411. }
  412. }
  413. static void do_dbs_timer(struct work_struct *work)
  414. {
  415. struct cpu_dbs_info_s *dbs_info =
  416. container_of(work, struct cpu_dbs_info_s, work.work);
  417. unsigned int cpu = dbs_info->cpu;
  418. /* We want all CPUs to do sampling nearly on same jiffy */
  419. int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
  420. delay -= jiffies % delay;
  421. if (lock_policy_rwsem_write(cpu) < 0)
  422. return;
  423. if (!dbs_info->enable) {
  424. unlock_policy_rwsem_write(cpu);
  425. return;
  426. }
  427. dbs_check_cpu(dbs_info);
  428. queue_delayed_work_on(cpu, kconservative_wq, &dbs_info->work, delay);
  429. unlock_policy_rwsem_write(cpu);
  430. }
  431. static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
  432. {
  433. /* We want all CPUs to do sampling nearly on same jiffy */
  434. int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
  435. delay -= jiffies % delay;
  436. dbs_info->enable = 1;
  437. INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
  438. queue_delayed_work_on(dbs_info->cpu, kconservative_wq, &dbs_info->work,
  439. delay);
  440. }
  441. static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
  442. {
  443. dbs_info->enable = 0;
  444. cancel_delayed_work(&dbs_info->work);
  445. }
  446. static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
  447. unsigned int event)
  448. {
  449. unsigned int cpu = policy->cpu;
  450. struct cpu_dbs_info_s *this_dbs_info;
  451. unsigned int j;
  452. int rc;
  453. this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
  454. switch (event) {
  455. case CPUFREQ_GOV_START:
  456. if ((!cpu_online(cpu)) || (!policy->cur))
  457. return -EINVAL;
  458. if (this_dbs_info->enable) /* Already enabled */
  459. break;
  460. mutex_lock(&dbs_mutex);
  461. rc = sysfs_create_group(&policy->kobj, &dbs_attr_group);
  462. if (rc) {
  463. mutex_unlock(&dbs_mutex);
  464. return rc;
  465. }
  466. for_each_cpu(j, policy->cpus) {
  467. struct cpu_dbs_info_s *j_dbs_info;
  468. j_dbs_info = &per_cpu(cpu_dbs_info, j);
  469. j_dbs_info->cur_policy = policy;
  470. j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j,
  471. &j_dbs_info->prev_cpu_wall);
  472. if (dbs_tuners_ins.ignore_nice) {
  473. j_dbs_info->prev_cpu_nice =
  474. kstat_cpu(j).cpustat.nice;
  475. }
  476. }
  477. this_dbs_info->down_skip = 0;
  478. this_dbs_info->requested_freq = policy->cur;
  479. dbs_enable++;
  480. /*
  481. * Start the timerschedule work, when this governor
  482. * is used for first time
  483. */
  484. if (dbs_enable == 1) {
  485. unsigned int latency;
  486. /* policy latency is in nS. Convert it to uS first */
  487. latency = policy->cpuinfo.transition_latency / 1000;
  488. if (latency == 0)
  489. latency = 1;
  490. def_sampling_rate =
  491. max(latency * LATENCY_MULTIPLIER,
  492. MIN_STAT_SAMPLING_RATE);
  493. dbs_tuners_ins.sampling_rate = def_sampling_rate;
  494. cpufreq_register_notifier(
  495. &dbs_cpufreq_notifier_block,
  496. CPUFREQ_TRANSITION_NOTIFIER);
  497. }
  498. dbs_timer_init(this_dbs_info);
  499. mutex_unlock(&dbs_mutex);
  500. break;
  501. case CPUFREQ_GOV_STOP:
  502. mutex_lock(&dbs_mutex);
  503. dbs_timer_exit(this_dbs_info);
  504. sysfs_remove_group(&policy->kobj, &dbs_attr_group);
  505. dbs_enable--;
  506. /*
  507. * Stop the timerschedule work, when this governor
  508. * is used for first time
  509. */
  510. if (dbs_enable == 0)
  511. cpufreq_unregister_notifier(
  512. &dbs_cpufreq_notifier_block,
  513. CPUFREQ_TRANSITION_NOTIFIER);
  514. mutex_unlock(&dbs_mutex);
  515. break;
  516. case CPUFREQ_GOV_LIMITS:
  517. mutex_lock(&dbs_mutex);
  518. if (policy->max < this_dbs_info->cur_policy->cur)
  519. __cpufreq_driver_target(
  520. this_dbs_info->cur_policy,
  521. policy->max, CPUFREQ_RELATION_H);
  522. else if (policy->min > this_dbs_info->cur_policy->cur)
  523. __cpufreq_driver_target(
  524. this_dbs_info->cur_policy,
  525. policy->min, CPUFREQ_RELATION_L);
  526. mutex_unlock(&dbs_mutex);
  527. break;
  528. }
  529. return 0;
  530. }
  531. #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
  532. static
  533. #endif
  534. struct cpufreq_governor cpufreq_gov_conservative = {
  535. .name = "conservative",
  536. .governor = cpufreq_governor_dbs,
  537. .max_transition_latency = TRANSITION_LATENCY_LIMIT,
  538. .owner = THIS_MODULE,
  539. };
  540. static int __init cpufreq_gov_dbs_init(void)
  541. {
  542. int err;
  543. kconservative_wq = create_workqueue("kconservative");
  544. if (!kconservative_wq) {
  545. printk(KERN_ERR "Creation of kconservative failed\n");
  546. return -EFAULT;
  547. }
  548. err = cpufreq_register_governor(&cpufreq_gov_conservative);
  549. if (err)
  550. destroy_workqueue(kconservative_wq);
  551. return err;
  552. }
  553. static void __exit cpufreq_gov_dbs_exit(void)
  554. {
  555. cpufreq_unregister_governor(&cpufreq_gov_conservative);
  556. destroy_workqueue(kconservative_wq);
  557. }
  558. MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>");
  559. MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for "
  560. "Low Latency Frequency Transition capable processors "
  561. "optimised for use in a battery environment");
  562. MODULE_LICENSE("GPL");
  563. #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
  564. fs_initcall(cpufreq_gov_dbs_init);
  565. #else
  566. module_init(cpufreq_gov_dbs_init);
  567. #endif
  568. module_exit(cpufreq_gov_dbs_exit);