cpufreq_conservative.c 18 KB

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