cpufreq_ondemand.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * drivers/cpufreq/cpufreq_ondemand.c
  3. *
  4. * Copyright (C) 2001 Russell King
  5. * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
  6. * Jun Nakajima <jun.nakajima@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/cpufreq.h>
  16. #include <linux/cpu.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/kernel_stat.h>
  19. #include <linux/mutex.h>
  20. /*
  21. * dbs is used in this file as a shortform for demandbased switching
  22. * It helps to keep variable names smaller, simpler
  23. */
  24. #define DEF_FREQUENCY_UP_THRESHOLD (80)
  25. #define MIN_FREQUENCY_UP_THRESHOLD (11)
  26. #define MAX_FREQUENCY_UP_THRESHOLD (100)
  27. /*
  28. * The polling frequency of this governor depends on the capability of
  29. * the processor. Default polling frequency is 1000 times the transition
  30. * latency of the processor. The governor will work on any processor with
  31. * transition latency <= 10mS, using appropriate sampling
  32. * rate.
  33. * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL)
  34. * this governor will not work.
  35. * All times here are in uS.
  36. */
  37. static unsigned int def_sampling_rate;
  38. #define MIN_SAMPLING_RATE_RATIO (2)
  39. /* for correct statistics, we need at least 10 ticks between each measure */
  40. #define MIN_STAT_SAMPLING_RATE \
  41. (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
  42. #define MIN_SAMPLING_RATE \
  43. (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
  44. #define MAX_SAMPLING_RATE (500 * def_sampling_rate)
  45. #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000)
  46. #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
  47. static void do_dbs_timer(struct work_struct *work);
  48. /* Sampling types */
  49. enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE};
  50. struct cpu_dbs_info_s {
  51. cputime64_t prev_cpu_idle;
  52. cputime64_t prev_cpu_wall;
  53. struct cpufreq_policy *cur_policy;
  54. struct delayed_work work;
  55. struct cpufreq_frequency_table *freq_table;
  56. unsigned int freq_lo;
  57. unsigned int freq_lo_jiffies;
  58. unsigned int freq_hi_jiffies;
  59. int cpu;
  60. unsigned int enable:1,
  61. sample_type:1;
  62. };
  63. static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
  64. static unsigned int dbs_enable; /* number of CPUs using this policy */
  65. /*
  66. * DEADLOCK ALERT! There is a ordering requirement between cpu_hotplug
  67. * lock and dbs_mutex. cpu_hotplug lock should always be held before
  68. * dbs_mutex. If any function that can potentially take cpu_hotplug lock
  69. * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then
  70. * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock
  71. * is recursive for the same process. -Venki
  72. */
  73. static DEFINE_MUTEX(dbs_mutex);
  74. static struct workqueue_struct *kondemand_wq;
  75. static struct dbs_tuners {
  76. unsigned int sampling_rate;
  77. unsigned int up_threshold;
  78. unsigned int ignore_nice;
  79. unsigned int powersave_bias;
  80. } dbs_tuners_ins = {
  81. .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
  82. .ignore_nice = 0,
  83. .powersave_bias = 0,
  84. };
  85. static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall)
  86. {
  87. cputime64_t idle_time;
  88. cputime64_t cur_wall_time;
  89. cputime64_t busy_time;
  90. cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
  91. busy_time = cputime64_add(kstat_cpu(cpu).cpustat.user,
  92. kstat_cpu(cpu).cpustat.system);
  93. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.irq);
  94. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.softirq);
  95. busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.steal);
  96. if (!dbs_tuners_ins.ignore_nice) {
  97. busy_time = cputime64_add(busy_time,
  98. kstat_cpu(cpu).cpustat.nice);
  99. }
  100. idle_time = cputime64_sub(cur_wall_time, busy_time);
  101. if (wall)
  102. *wall = cur_wall_time;
  103. return idle_time;
  104. }
  105. /*
  106. * Find right freq to be set now with powersave_bias on.
  107. * Returns the freq_hi to be used right now and will set freq_hi_jiffies,
  108. * freq_lo, and freq_lo_jiffies in percpu area for averaging freqs.
  109. */
  110. static unsigned int powersave_bias_target(struct cpufreq_policy *policy,
  111. unsigned int freq_next,
  112. unsigned int relation)
  113. {
  114. unsigned int freq_req, freq_reduc, freq_avg;
  115. unsigned int freq_hi, freq_lo;
  116. unsigned int index = 0;
  117. unsigned int jiffies_total, jiffies_hi, jiffies_lo;
  118. struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, policy->cpu);
  119. if (!dbs_info->freq_table) {
  120. dbs_info->freq_lo = 0;
  121. dbs_info->freq_lo_jiffies = 0;
  122. return freq_next;
  123. }
  124. cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_next,
  125. relation, &index);
  126. freq_req = dbs_info->freq_table[index].frequency;
  127. freq_reduc = freq_req * dbs_tuners_ins.powersave_bias / 1000;
  128. freq_avg = freq_req - freq_reduc;
  129. /* Find freq bounds for freq_avg in freq_table */
  130. index = 0;
  131. cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg,
  132. CPUFREQ_RELATION_H, &index);
  133. freq_lo = dbs_info->freq_table[index].frequency;
  134. index = 0;
  135. cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg,
  136. CPUFREQ_RELATION_L, &index);
  137. freq_hi = dbs_info->freq_table[index].frequency;
  138. /* Find out how long we have to be in hi and lo freqs */
  139. if (freq_hi == freq_lo) {
  140. dbs_info->freq_lo = 0;
  141. dbs_info->freq_lo_jiffies = 0;
  142. return freq_lo;
  143. }
  144. jiffies_total = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
  145. jiffies_hi = (freq_avg - freq_lo) * jiffies_total;
  146. jiffies_hi += ((freq_hi - freq_lo) / 2);
  147. jiffies_hi /= (freq_hi - freq_lo);
  148. jiffies_lo = jiffies_total - jiffies_hi;
  149. dbs_info->freq_lo = freq_lo;
  150. dbs_info->freq_lo_jiffies = jiffies_lo;
  151. dbs_info->freq_hi_jiffies = jiffies_hi;
  152. return freq_hi;
  153. }
  154. static void ondemand_powersave_bias_init(void)
  155. {
  156. int i;
  157. for_each_online_cpu(i) {
  158. struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, i);
  159. dbs_info->freq_table = cpufreq_frequency_get_table(i);
  160. dbs_info->freq_lo = 0;
  161. }
  162. }
  163. /************************** sysfs interface ************************/
  164. static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf)
  165. {
  166. return sprintf (buf, "%u\n", MAX_SAMPLING_RATE);
  167. }
  168. static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf)
  169. {
  170. return sprintf (buf, "%u\n", MIN_SAMPLING_RATE);
  171. }
  172. #define define_one_ro(_name) \
  173. static struct freq_attr _name = \
  174. __ATTR(_name, 0444, show_##_name, NULL)
  175. define_one_ro(sampling_rate_max);
  176. define_one_ro(sampling_rate_min);
  177. /* cpufreq_ondemand Governor Tunables */
  178. #define show_one(file_name, object) \
  179. static ssize_t show_##file_name \
  180. (struct cpufreq_policy *unused, char *buf) \
  181. { \
  182. return sprintf(buf, "%u\n", dbs_tuners_ins.object); \
  183. }
  184. show_one(sampling_rate, sampling_rate);
  185. show_one(up_threshold, up_threshold);
  186. show_one(ignore_nice_load, ignore_nice);
  187. show_one(powersave_bias, powersave_bias);
  188. static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
  189. const char *buf, size_t count)
  190. {
  191. unsigned int input;
  192. int ret;
  193. ret = sscanf(buf, "%u", &input);
  194. mutex_lock(&dbs_mutex);
  195. if (ret != 1 || input > MAX_SAMPLING_RATE
  196. || input < MIN_SAMPLING_RATE) {
  197. mutex_unlock(&dbs_mutex);
  198. return -EINVAL;
  199. }
  200. dbs_tuners_ins.sampling_rate = input;
  201. mutex_unlock(&dbs_mutex);
  202. return count;
  203. }
  204. static ssize_t store_up_threshold(struct cpufreq_policy *unused,
  205. const char *buf, size_t count)
  206. {
  207. unsigned int input;
  208. int ret;
  209. ret = sscanf(buf, "%u", &input);
  210. mutex_lock(&dbs_mutex);
  211. if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
  212. input < MIN_FREQUENCY_UP_THRESHOLD) {
  213. mutex_unlock(&dbs_mutex);
  214. return -EINVAL;
  215. }
  216. dbs_tuners_ins.up_threshold = input;
  217. mutex_unlock(&dbs_mutex);
  218. return count;
  219. }
  220. static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
  221. const char *buf, size_t count)
  222. {
  223. unsigned int input;
  224. int ret;
  225. unsigned int j;
  226. ret = sscanf(buf, "%u", &input);
  227. if ( ret != 1 )
  228. return -EINVAL;
  229. if ( input > 1 )
  230. input = 1;
  231. mutex_lock(&dbs_mutex);
  232. if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */
  233. mutex_unlock(&dbs_mutex);
  234. return count;
  235. }
  236. dbs_tuners_ins.ignore_nice = input;
  237. /* we need to re-evaluate prev_cpu_idle */
  238. for_each_online_cpu(j) {
  239. struct cpu_dbs_info_s *dbs_info;
  240. dbs_info = &per_cpu(cpu_dbs_info, j);
  241. dbs_info->prev_cpu_idle = get_cpu_idle_time(j,
  242. &dbs_info->prev_cpu_wall);
  243. }
  244. mutex_unlock(&dbs_mutex);
  245. return count;
  246. }
  247. static ssize_t store_powersave_bias(struct cpufreq_policy *unused,
  248. const char *buf, size_t count)
  249. {
  250. unsigned int input;
  251. int ret;
  252. ret = sscanf(buf, "%u", &input);
  253. if (ret != 1)
  254. return -EINVAL;
  255. if (input > 1000)
  256. input = 1000;
  257. mutex_lock(&dbs_mutex);
  258. dbs_tuners_ins.powersave_bias = input;
  259. ondemand_powersave_bias_init();
  260. mutex_unlock(&dbs_mutex);
  261. return count;
  262. }
  263. #define define_one_rw(_name) \
  264. static struct freq_attr _name = \
  265. __ATTR(_name, 0644, show_##_name, store_##_name)
  266. define_one_rw(sampling_rate);
  267. define_one_rw(up_threshold);
  268. define_one_rw(ignore_nice_load);
  269. define_one_rw(powersave_bias);
  270. static struct attribute * dbs_attributes[] = {
  271. &sampling_rate_max.attr,
  272. &sampling_rate_min.attr,
  273. &sampling_rate.attr,
  274. &up_threshold.attr,
  275. &ignore_nice_load.attr,
  276. &powersave_bias.attr,
  277. NULL
  278. };
  279. static struct attribute_group dbs_attr_group = {
  280. .attrs = dbs_attributes,
  281. .name = "ondemand",
  282. };
  283. /************************** sysfs end ************************/
  284. static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
  285. {
  286. unsigned int max_load_freq;
  287. struct cpufreq_policy *policy;
  288. unsigned int j;
  289. if (!this_dbs_info->enable)
  290. return;
  291. this_dbs_info->freq_lo = 0;
  292. policy = this_dbs_info->cur_policy;
  293. /*
  294. * Every sampling_rate, we check, if current idle time is less
  295. * than 20% (default), then we try to increase frequency
  296. * Every sampling_rate, we look for a the lowest
  297. * frequency which can sustain the load while keeping idle time over
  298. * 30%. If such a frequency exist, we try to decrease to this frequency.
  299. *
  300. * Any frequency increase takes it to the maximum frequency.
  301. * Frequency reduction happens at minimum steps of
  302. * 5% (default) of current frequency
  303. */
  304. /* Get Absolute Load - in terms of freq */
  305. max_load_freq = 0;
  306. for_each_cpu_mask_nr(j, policy->cpus) {
  307. struct cpu_dbs_info_s *j_dbs_info;
  308. cputime64_t cur_wall_time, cur_idle_time;
  309. unsigned int idle_time, wall_time;
  310. unsigned int load, load_freq;
  311. int freq_avg;
  312. j_dbs_info = &per_cpu(cpu_dbs_info, j);
  313. cur_idle_time = get_cpu_idle_time(j, &cur_wall_time);
  314. wall_time = (unsigned int) cputime64_sub(cur_wall_time,
  315. j_dbs_info->prev_cpu_wall);
  316. j_dbs_info->prev_cpu_wall = cur_wall_time;
  317. idle_time = (unsigned int) cputime64_sub(cur_idle_time,
  318. j_dbs_info->prev_cpu_idle);
  319. j_dbs_info->prev_cpu_idle = cur_idle_time;
  320. if (unlikely(!wall_time || wall_time < idle_time))
  321. continue;
  322. load = 100 * (wall_time - idle_time) / wall_time;
  323. freq_avg = __cpufreq_driver_getavg(policy, j);
  324. if (freq_avg <= 0)
  325. freq_avg = policy->cur;
  326. load_freq = load * freq_avg;
  327. if (load_freq > max_load_freq)
  328. max_load_freq = load_freq;
  329. }
  330. /* Check for frequency increase */
  331. if (max_load_freq > dbs_tuners_ins.up_threshold * policy->cur) {
  332. /* if we are already at full speed then break out early */
  333. if (!dbs_tuners_ins.powersave_bias) {
  334. if (policy->cur == policy->max)
  335. return;
  336. __cpufreq_driver_target(policy, policy->max,
  337. CPUFREQ_RELATION_H);
  338. } else {
  339. int freq = powersave_bias_target(policy, policy->max,
  340. CPUFREQ_RELATION_H);
  341. __cpufreq_driver_target(policy, freq,
  342. CPUFREQ_RELATION_L);
  343. }
  344. return;
  345. }
  346. /* Check for frequency decrease */
  347. /* if we cannot reduce the frequency anymore, break out early */
  348. if (policy->cur == policy->min)
  349. return;
  350. /*
  351. * The optimal frequency is the frequency that is the lowest that
  352. * can support the current CPU usage without triggering the up
  353. * policy. To be safe, we focus 10 points under the threshold.
  354. */
  355. if (max_load_freq < (dbs_tuners_ins.up_threshold - 10) * policy->cur) {
  356. unsigned int freq_next;
  357. freq_next = max_load_freq / (dbs_tuners_ins.up_threshold - 10);
  358. if (!dbs_tuners_ins.powersave_bias) {
  359. __cpufreq_driver_target(policy, freq_next,
  360. CPUFREQ_RELATION_L);
  361. } else {
  362. int freq = powersave_bias_target(policy, freq_next,
  363. CPUFREQ_RELATION_L);
  364. __cpufreq_driver_target(policy, freq,
  365. CPUFREQ_RELATION_L);
  366. }
  367. }
  368. }
  369. static void do_dbs_timer(struct work_struct *work)
  370. {
  371. struct cpu_dbs_info_s *dbs_info =
  372. container_of(work, struct cpu_dbs_info_s, work.work);
  373. unsigned int cpu = dbs_info->cpu;
  374. int sample_type = dbs_info->sample_type;
  375. /* We want all CPUs to do sampling nearly on same jiffy */
  376. int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
  377. delay -= jiffies % delay;
  378. if (lock_policy_rwsem_write(cpu) < 0)
  379. return;
  380. if (!dbs_info->enable) {
  381. unlock_policy_rwsem_write(cpu);
  382. return;
  383. }
  384. /* Common NORMAL_SAMPLE setup */
  385. dbs_info->sample_type = DBS_NORMAL_SAMPLE;
  386. if (!dbs_tuners_ins.powersave_bias ||
  387. sample_type == DBS_NORMAL_SAMPLE) {
  388. dbs_check_cpu(dbs_info);
  389. if (dbs_info->freq_lo) {
  390. /* Setup timer for SUB_SAMPLE */
  391. dbs_info->sample_type = DBS_SUB_SAMPLE;
  392. delay = dbs_info->freq_hi_jiffies;
  393. }
  394. } else {
  395. __cpufreq_driver_target(dbs_info->cur_policy,
  396. dbs_info->freq_lo,
  397. CPUFREQ_RELATION_H);
  398. }
  399. queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work, delay);
  400. unlock_policy_rwsem_write(cpu);
  401. }
  402. static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
  403. {
  404. /* We want all CPUs to do sampling nearly on same jiffy */
  405. int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
  406. delay -= jiffies % delay;
  407. dbs_info->enable = 1;
  408. ondemand_powersave_bias_init();
  409. dbs_info->sample_type = DBS_NORMAL_SAMPLE;
  410. INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
  411. queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work,
  412. delay);
  413. }
  414. static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
  415. {
  416. dbs_info->enable = 0;
  417. cancel_delayed_work(&dbs_info->work);
  418. }
  419. static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
  420. unsigned int event)
  421. {
  422. unsigned int cpu = policy->cpu;
  423. struct cpu_dbs_info_s *this_dbs_info;
  424. unsigned int j;
  425. int rc;
  426. this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
  427. switch (event) {
  428. case CPUFREQ_GOV_START:
  429. if ((!cpu_online(cpu)) || (!policy->cur))
  430. return -EINVAL;
  431. if (this_dbs_info->enable) /* Already enabled */
  432. break;
  433. mutex_lock(&dbs_mutex);
  434. dbs_enable++;
  435. rc = sysfs_create_group(&policy->kobj, &dbs_attr_group);
  436. if (rc) {
  437. dbs_enable--;
  438. mutex_unlock(&dbs_mutex);
  439. return rc;
  440. }
  441. for_each_cpu_mask_nr(j, policy->cpus) {
  442. struct cpu_dbs_info_s *j_dbs_info;
  443. j_dbs_info = &per_cpu(cpu_dbs_info, j);
  444. j_dbs_info->cur_policy = policy;
  445. j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j,
  446. &j_dbs_info->prev_cpu_wall);
  447. }
  448. this_dbs_info->cpu = cpu;
  449. /*
  450. * Start the timerschedule work, when this governor
  451. * is used for first time
  452. */
  453. if (dbs_enable == 1) {
  454. unsigned int latency;
  455. /* policy latency is in nS. Convert it to uS first */
  456. latency = policy->cpuinfo.transition_latency / 1000;
  457. if (latency == 0)
  458. latency = 1;
  459. def_sampling_rate = latency *
  460. DEF_SAMPLING_RATE_LATENCY_MULTIPLIER;
  461. if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
  462. def_sampling_rate = MIN_STAT_SAMPLING_RATE;
  463. dbs_tuners_ins.sampling_rate = def_sampling_rate;
  464. }
  465. dbs_timer_init(this_dbs_info);
  466. mutex_unlock(&dbs_mutex);
  467. break;
  468. case CPUFREQ_GOV_STOP:
  469. mutex_lock(&dbs_mutex);
  470. dbs_timer_exit(this_dbs_info);
  471. sysfs_remove_group(&policy->kobj, &dbs_attr_group);
  472. dbs_enable--;
  473. mutex_unlock(&dbs_mutex);
  474. break;
  475. case CPUFREQ_GOV_LIMITS:
  476. mutex_lock(&dbs_mutex);
  477. if (policy->max < this_dbs_info->cur_policy->cur)
  478. __cpufreq_driver_target(this_dbs_info->cur_policy,
  479. policy->max,
  480. CPUFREQ_RELATION_H);
  481. else if (policy->min > this_dbs_info->cur_policy->cur)
  482. __cpufreq_driver_target(this_dbs_info->cur_policy,
  483. policy->min,
  484. CPUFREQ_RELATION_L);
  485. mutex_unlock(&dbs_mutex);
  486. break;
  487. }
  488. return 0;
  489. }
  490. struct cpufreq_governor cpufreq_gov_ondemand = {
  491. .name = "ondemand",
  492. .governor = cpufreq_governor_dbs,
  493. .max_transition_latency = TRANSITION_LATENCY_LIMIT,
  494. .owner = THIS_MODULE,
  495. };
  496. EXPORT_SYMBOL(cpufreq_gov_ondemand);
  497. static int __init cpufreq_gov_dbs_init(void)
  498. {
  499. int err;
  500. kondemand_wq = create_workqueue("kondemand");
  501. if (!kondemand_wq) {
  502. printk(KERN_ERR "Creation of kondemand failed\n");
  503. return -EFAULT;
  504. }
  505. err = cpufreq_register_governor(&cpufreq_gov_ondemand);
  506. if (err)
  507. destroy_workqueue(kondemand_wq);
  508. return err;
  509. }
  510. static void __exit cpufreq_gov_dbs_exit(void)
  511. {
  512. cpufreq_unregister_governor(&cpufreq_gov_ondemand);
  513. destroy_workqueue(kondemand_wq);
  514. }
  515. MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
  516. MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>");
  517. MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
  518. "Low Latency Frequency Transition capable processors");
  519. MODULE_LICENSE("GPL");
  520. #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
  521. fs_initcall(cpufreq_gov_dbs_init);
  522. #else
  523. module_init(cpufreq_gov_dbs_init);
  524. #endif
  525. module_exit(cpufreq_gov_dbs_exit);