cpufreq_conservative.c 18 KB

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