cpufreq_conservative.c 18 KB

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