cpufreq_ondemand.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/cpufreq.h>
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/kobject.h>
  18. #include <linux/module.h>
  19. #include <linux/mutex.h>
  20. #include <linux/percpu-defs.h>
  21. #include <linux/slab.h>
  22. #include <linux/sysfs.h>
  23. #include <linux/tick.h>
  24. #include <linux/types.h>
  25. #include "cpufreq_governor.h"
  26. /* On-demand governor macros */
  27. #define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10)
  28. #define DEF_FREQUENCY_UP_THRESHOLD (80)
  29. #define DEF_SAMPLING_DOWN_FACTOR (1)
  30. #define MAX_SAMPLING_DOWN_FACTOR (100000)
  31. #define MICRO_FREQUENCY_DOWN_DIFFERENTIAL (3)
  32. #define MICRO_FREQUENCY_UP_THRESHOLD (95)
  33. #define MICRO_FREQUENCY_MIN_SAMPLE_RATE (10000)
  34. #define MIN_FREQUENCY_UP_THRESHOLD (11)
  35. #define MAX_FREQUENCY_UP_THRESHOLD (100)
  36. static DEFINE_PER_CPU(struct od_cpu_dbs_info_s, od_cpu_dbs_info);
  37. #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
  38. static struct cpufreq_governor cpufreq_gov_ondemand;
  39. #endif
  40. static void ondemand_powersave_bias_init_cpu(int cpu)
  41. {
  42. struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
  43. dbs_info->freq_table = cpufreq_frequency_get_table(cpu);
  44. dbs_info->freq_lo = 0;
  45. }
  46. /*
  47. * Not all CPUs want IO time to be accounted as busy; this depends on how
  48. * efficient idling at a higher frequency/voltage is.
  49. * Pavel Machek says this is not so for various generations of AMD and old
  50. * Intel systems.
  51. * Mike Chan (android.com) claims this is also not true for ARM.
  52. * Because of this, whitelist specific known (series) of CPUs by default, and
  53. * leave all others up to the user.
  54. */
  55. static int should_io_be_busy(void)
  56. {
  57. #if defined(CONFIG_X86)
  58. /*
  59. * For Intel, Core 2 (model 15) and later have an efficient idle.
  60. */
  61. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  62. boot_cpu_data.x86 == 6 &&
  63. boot_cpu_data.x86_model >= 15)
  64. return 1;
  65. #endif
  66. return 0;
  67. }
  68. /*
  69. * Find right freq to be set now with powersave_bias on.
  70. * Returns the freq_hi to be used right now and will set freq_hi_jiffies,
  71. * freq_lo, and freq_lo_jiffies in percpu area for averaging freqs.
  72. */
  73. static unsigned int powersave_bias_target(struct cpufreq_policy *policy,
  74. unsigned int freq_next, unsigned int relation)
  75. {
  76. unsigned int freq_req, freq_reduc, freq_avg;
  77. unsigned int freq_hi, freq_lo;
  78. unsigned int index = 0;
  79. unsigned int jiffies_total, jiffies_hi, jiffies_lo;
  80. struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
  81. policy->cpu);
  82. struct dbs_data *dbs_data = policy->governor_data;
  83. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  84. if (!dbs_info->freq_table) {
  85. dbs_info->freq_lo = 0;
  86. dbs_info->freq_lo_jiffies = 0;
  87. return freq_next;
  88. }
  89. cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_next,
  90. relation, &index);
  91. freq_req = dbs_info->freq_table[index].frequency;
  92. freq_reduc = freq_req * od_tuners->powersave_bias / 1000;
  93. freq_avg = freq_req - freq_reduc;
  94. /* Find freq bounds for freq_avg in freq_table */
  95. index = 0;
  96. cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg,
  97. CPUFREQ_RELATION_H, &index);
  98. freq_lo = dbs_info->freq_table[index].frequency;
  99. index = 0;
  100. cpufreq_frequency_table_target(policy, dbs_info->freq_table, freq_avg,
  101. CPUFREQ_RELATION_L, &index);
  102. freq_hi = dbs_info->freq_table[index].frequency;
  103. /* Find out how long we have to be in hi and lo freqs */
  104. if (freq_hi == freq_lo) {
  105. dbs_info->freq_lo = 0;
  106. dbs_info->freq_lo_jiffies = 0;
  107. return freq_lo;
  108. }
  109. jiffies_total = usecs_to_jiffies(od_tuners->sampling_rate);
  110. jiffies_hi = (freq_avg - freq_lo) * jiffies_total;
  111. jiffies_hi += ((freq_hi - freq_lo) / 2);
  112. jiffies_hi /= (freq_hi - freq_lo);
  113. jiffies_lo = jiffies_total - jiffies_hi;
  114. dbs_info->freq_lo = freq_lo;
  115. dbs_info->freq_lo_jiffies = jiffies_lo;
  116. dbs_info->freq_hi_jiffies = jiffies_hi;
  117. return freq_hi;
  118. }
  119. static void ondemand_powersave_bias_init(void)
  120. {
  121. int i;
  122. for_each_online_cpu(i) {
  123. ondemand_powersave_bias_init_cpu(i);
  124. }
  125. }
  126. static void dbs_freq_increase(struct cpufreq_policy *p, unsigned int freq)
  127. {
  128. struct dbs_data *dbs_data = p->governor_data;
  129. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  130. if (od_tuners->powersave_bias)
  131. freq = powersave_bias_target(p, freq, CPUFREQ_RELATION_H);
  132. else if (p->cur == p->max)
  133. return;
  134. __cpufreq_driver_target(p, freq, od_tuners->powersave_bias ?
  135. CPUFREQ_RELATION_L : CPUFREQ_RELATION_H);
  136. }
  137. /*
  138. * Every sampling_rate, we check, if current idle time is less than 20%
  139. * (default), then we try to increase frequency. Every sampling_rate, we look
  140. * for the lowest frequency which can sustain the load while keeping idle time
  141. * over 30%. If such a frequency exist, we try to decrease to this frequency.
  142. *
  143. * Any frequency increase takes it to the maximum frequency. Frequency reduction
  144. * happens at minimum steps of 5% (default) of current frequency
  145. */
  146. static void od_check_cpu(int cpu, unsigned int load_freq)
  147. {
  148. struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
  149. struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
  150. struct dbs_data *dbs_data = policy->governor_data;
  151. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  152. dbs_info->freq_lo = 0;
  153. /* Check for frequency increase */
  154. if (load_freq > od_tuners->up_threshold * policy->cur) {
  155. /* If switching to max speed, apply sampling_down_factor */
  156. if (policy->cur < policy->max)
  157. dbs_info->rate_mult =
  158. od_tuners->sampling_down_factor;
  159. dbs_freq_increase(policy, policy->max);
  160. return;
  161. }
  162. /* Check for frequency decrease */
  163. /* if we cannot reduce the frequency anymore, break out early */
  164. if (policy->cur == policy->min)
  165. return;
  166. /*
  167. * The optimal frequency is the frequency that is the lowest that can
  168. * support the current CPU usage without triggering the up policy. To be
  169. * safe, we focus 10 points under the threshold.
  170. */
  171. if (load_freq < od_tuners->adj_up_threshold
  172. * policy->cur) {
  173. unsigned int freq_next;
  174. freq_next = load_freq / od_tuners->adj_up_threshold;
  175. /* No longer fully busy, reset rate_mult */
  176. dbs_info->rate_mult = 1;
  177. if (freq_next < policy->min)
  178. freq_next = policy->min;
  179. if (!od_tuners->powersave_bias) {
  180. __cpufreq_driver_target(policy, freq_next,
  181. CPUFREQ_RELATION_L);
  182. } else {
  183. int freq = powersave_bias_target(policy, freq_next,
  184. CPUFREQ_RELATION_L);
  185. __cpufreq_driver_target(policy, freq,
  186. CPUFREQ_RELATION_L);
  187. }
  188. }
  189. }
  190. static void od_dbs_timer(struct work_struct *work)
  191. {
  192. struct od_cpu_dbs_info_s *dbs_info =
  193. container_of(work, struct od_cpu_dbs_info_s, cdbs.work.work);
  194. unsigned int cpu = dbs_info->cdbs.cur_policy->cpu;
  195. struct od_cpu_dbs_info_s *core_dbs_info = &per_cpu(od_cpu_dbs_info,
  196. cpu);
  197. struct dbs_data *dbs_data = dbs_info->cdbs.cur_policy->governor_data;
  198. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  199. int delay = 0, sample_type = core_dbs_info->sample_type;
  200. bool modify_all = true;
  201. mutex_lock(&core_dbs_info->cdbs.timer_mutex);
  202. if (!need_load_eval(&core_dbs_info->cdbs, od_tuners->sampling_rate)) {
  203. modify_all = false;
  204. goto max_delay;
  205. }
  206. /* Common NORMAL_SAMPLE setup */
  207. core_dbs_info->sample_type = OD_NORMAL_SAMPLE;
  208. if (sample_type == OD_SUB_SAMPLE) {
  209. delay = core_dbs_info->freq_lo_jiffies;
  210. __cpufreq_driver_target(core_dbs_info->cdbs.cur_policy,
  211. core_dbs_info->freq_lo, CPUFREQ_RELATION_H);
  212. } else {
  213. dbs_check_cpu(dbs_data, cpu);
  214. if (core_dbs_info->freq_lo) {
  215. /* Setup timer for SUB_SAMPLE */
  216. core_dbs_info->sample_type = OD_SUB_SAMPLE;
  217. delay = core_dbs_info->freq_hi_jiffies;
  218. }
  219. }
  220. max_delay:
  221. if (!delay)
  222. delay = delay_for_sampling_rate(od_tuners->sampling_rate
  223. * core_dbs_info->rate_mult);
  224. gov_queue_work(dbs_data, dbs_info->cdbs.cur_policy, delay, modify_all);
  225. mutex_unlock(&core_dbs_info->cdbs.timer_mutex);
  226. }
  227. /************************** sysfs interface ************************/
  228. static struct common_dbs_data od_dbs_cdata;
  229. /**
  230. * update_sampling_rate - update sampling rate effective immediately if needed.
  231. * @new_rate: new sampling rate
  232. *
  233. * If new rate is smaller than the old, simply updating
  234. * dbs_tuners_int.sampling_rate might not be appropriate. For example, if the
  235. * original sampling_rate was 1 second and the requested new sampling rate is 10
  236. * ms because the user needs immediate reaction from ondemand governor, but not
  237. * sure if higher frequency will be required or not, then, the governor may
  238. * change the sampling rate too late; up to 1 second later. Thus, if we are
  239. * reducing the sampling rate, we need to make the new value effective
  240. * immediately.
  241. */
  242. static void update_sampling_rate(struct dbs_data *dbs_data,
  243. unsigned int new_rate)
  244. {
  245. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  246. int cpu;
  247. od_tuners->sampling_rate = new_rate = max(new_rate,
  248. dbs_data->min_sampling_rate);
  249. for_each_online_cpu(cpu) {
  250. struct cpufreq_policy *policy;
  251. struct od_cpu_dbs_info_s *dbs_info;
  252. unsigned long next_sampling, appointed_at;
  253. policy = cpufreq_cpu_get(cpu);
  254. if (!policy)
  255. continue;
  256. if (policy->governor != &cpufreq_gov_ondemand) {
  257. cpufreq_cpu_put(policy);
  258. continue;
  259. }
  260. dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
  261. cpufreq_cpu_put(policy);
  262. mutex_lock(&dbs_info->cdbs.timer_mutex);
  263. if (!delayed_work_pending(&dbs_info->cdbs.work)) {
  264. mutex_unlock(&dbs_info->cdbs.timer_mutex);
  265. continue;
  266. }
  267. next_sampling = jiffies + usecs_to_jiffies(new_rate);
  268. appointed_at = dbs_info->cdbs.work.timer.expires;
  269. if (time_before(next_sampling, appointed_at)) {
  270. mutex_unlock(&dbs_info->cdbs.timer_mutex);
  271. cancel_delayed_work_sync(&dbs_info->cdbs.work);
  272. mutex_lock(&dbs_info->cdbs.timer_mutex);
  273. gov_queue_work(dbs_data, dbs_info->cdbs.cur_policy,
  274. usecs_to_jiffies(new_rate), true);
  275. }
  276. mutex_unlock(&dbs_info->cdbs.timer_mutex);
  277. }
  278. }
  279. static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
  280. size_t count)
  281. {
  282. unsigned int input;
  283. int ret;
  284. ret = sscanf(buf, "%u", &input);
  285. if (ret != 1)
  286. return -EINVAL;
  287. update_sampling_rate(dbs_data, input);
  288. return count;
  289. }
  290. static ssize_t store_io_is_busy(struct dbs_data *dbs_data, const char *buf,
  291. size_t count)
  292. {
  293. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  294. unsigned int input;
  295. int ret;
  296. unsigned int j;
  297. ret = sscanf(buf, "%u", &input);
  298. if (ret != 1)
  299. return -EINVAL;
  300. od_tuners->io_is_busy = !!input;
  301. /* we need to re-evaluate prev_cpu_idle */
  302. for_each_online_cpu(j) {
  303. struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
  304. j);
  305. dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
  306. &dbs_info->cdbs.prev_cpu_wall, od_tuners->io_is_busy);
  307. }
  308. return count;
  309. }
  310. static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
  311. size_t count)
  312. {
  313. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  314. unsigned int input;
  315. int ret;
  316. ret = sscanf(buf, "%u", &input);
  317. if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
  318. input < MIN_FREQUENCY_UP_THRESHOLD) {
  319. return -EINVAL;
  320. }
  321. /* Calculate the new adj_up_threshold */
  322. od_tuners->adj_up_threshold += input;
  323. od_tuners->adj_up_threshold -= od_tuners->up_threshold;
  324. od_tuners->up_threshold = input;
  325. return count;
  326. }
  327. static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
  328. const char *buf, size_t count)
  329. {
  330. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  331. unsigned int input, j;
  332. int ret;
  333. ret = sscanf(buf, "%u", &input);
  334. if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
  335. return -EINVAL;
  336. od_tuners->sampling_down_factor = input;
  337. /* Reset down sampling multiplier in case it was active */
  338. for_each_online_cpu(j) {
  339. struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
  340. j);
  341. dbs_info->rate_mult = 1;
  342. }
  343. return count;
  344. }
  345. static ssize_t store_ignore_nice(struct dbs_data *dbs_data, const char *buf,
  346. size_t count)
  347. {
  348. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  349. unsigned int input;
  350. int ret;
  351. unsigned int j;
  352. ret = sscanf(buf, "%u", &input);
  353. if (ret != 1)
  354. return -EINVAL;
  355. if (input > 1)
  356. input = 1;
  357. if (input == od_tuners->ignore_nice) { /* nothing to do */
  358. return count;
  359. }
  360. od_tuners->ignore_nice = input;
  361. /* we need to re-evaluate prev_cpu_idle */
  362. for_each_online_cpu(j) {
  363. struct od_cpu_dbs_info_s *dbs_info;
  364. dbs_info = &per_cpu(od_cpu_dbs_info, j);
  365. dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
  366. &dbs_info->cdbs.prev_cpu_wall, od_tuners->io_is_busy);
  367. if (od_tuners->ignore_nice)
  368. dbs_info->cdbs.prev_cpu_nice =
  369. kcpustat_cpu(j).cpustat[CPUTIME_NICE];
  370. }
  371. return count;
  372. }
  373. static ssize_t store_powersave_bias(struct dbs_data *dbs_data, const char *buf,
  374. size_t count)
  375. {
  376. struct od_dbs_tuners *od_tuners = dbs_data->tuners;
  377. unsigned int input;
  378. int ret;
  379. ret = sscanf(buf, "%u", &input);
  380. if (ret != 1)
  381. return -EINVAL;
  382. if (input > 1000)
  383. input = 1000;
  384. od_tuners->powersave_bias = input;
  385. ondemand_powersave_bias_init();
  386. return count;
  387. }
  388. show_store_one(od, sampling_rate);
  389. show_store_one(od, io_is_busy);
  390. show_store_one(od, up_threshold);
  391. show_store_one(od, sampling_down_factor);
  392. show_store_one(od, ignore_nice);
  393. show_store_one(od, powersave_bias);
  394. declare_show_sampling_rate_min(od);
  395. gov_sys_pol_attr_rw(sampling_rate);
  396. gov_sys_pol_attr_rw(io_is_busy);
  397. gov_sys_pol_attr_rw(up_threshold);
  398. gov_sys_pol_attr_rw(sampling_down_factor);
  399. gov_sys_pol_attr_rw(ignore_nice);
  400. gov_sys_pol_attr_rw(powersave_bias);
  401. gov_sys_pol_attr_ro(sampling_rate_min);
  402. static struct attribute *dbs_attributes_gov_sys[] = {
  403. &sampling_rate_min_gov_sys.attr,
  404. &sampling_rate_gov_sys.attr,
  405. &up_threshold_gov_sys.attr,
  406. &sampling_down_factor_gov_sys.attr,
  407. &ignore_nice_gov_sys.attr,
  408. &powersave_bias_gov_sys.attr,
  409. &io_is_busy_gov_sys.attr,
  410. NULL
  411. };
  412. static struct attribute_group od_attr_group_gov_sys = {
  413. .attrs = dbs_attributes_gov_sys,
  414. .name = "ondemand",
  415. };
  416. static struct attribute *dbs_attributes_gov_pol[] = {
  417. &sampling_rate_min_gov_pol.attr,
  418. &sampling_rate_gov_pol.attr,
  419. &up_threshold_gov_pol.attr,
  420. &sampling_down_factor_gov_pol.attr,
  421. &ignore_nice_gov_pol.attr,
  422. &powersave_bias_gov_pol.attr,
  423. &io_is_busy_gov_pol.attr,
  424. NULL
  425. };
  426. static struct attribute_group od_attr_group_gov_pol = {
  427. .attrs = dbs_attributes_gov_pol,
  428. .name = "ondemand",
  429. };
  430. /************************** sysfs end ************************/
  431. static int od_init(struct dbs_data *dbs_data)
  432. {
  433. struct od_dbs_tuners *tuners;
  434. u64 idle_time;
  435. int cpu;
  436. tuners = kzalloc(sizeof(struct od_dbs_tuners), GFP_KERNEL);
  437. if (!tuners) {
  438. pr_err("%s: kzalloc failed\n", __func__);
  439. return -ENOMEM;
  440. }
  441. cpu = get_cpu();
  442. idle_time = get_cpu_idle_time_us(cpu, NULL);
  443. put_cpu();
  444. if (idle_time != -1ULL) {
  445. /* Idle micro accounting is supported. Use finer thresholds */
  446. tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
  447. tuners->adj_up_threshold = MICRO_FREQUENCY_UP_THRESHOLD -
  448. MICRO_FREQUENCY_DOWN_DIFFERENTIAL;
  449. /*
  450. * In nohz/micro accounting case we set the minimum frequency
  451. * not depending on HZ, but fixed (very low). The deferred
  452. * timer might skip some samples if idle/sleeping as needed.
  453. */
  454. dbs_data->min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE;
  455. } else {
  456. tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
  457. tuners->adj_up_threshold = DEF_FREQUENCY_UP_THRESHOLD -
  458. DEF_FREQUENCY_DOWN_DIFFERENTIAL;
  459. /* For correct statistics, we need 10 ticks for each measure */
  460. dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
  461. jiffies_to_usecs(10);
  462. }
  463. tuners->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
  464. tuners->ignore_nice = 0;
  465. tuners->powersave_bias = 0;
  466. tuners->io_is_busy = should_io_be_busy();
  467. dbs_data->tuners = tuners;
  468. pr_info("%s: tuners %p\n", __func__, tuners);
  469. mutex_init(&dbs_data->mutex);
  470. return 0;
  471. }
  472. static void od_exit(struct dbs_data *dbs_data)
  473. {
  474. kfree(dbs_data->tuners);
  475. }
  476. define_get_cpu_dbs_routines(od_cpu_dbs_info);
  477. static struct od_ops od_ops = {
  478. .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
  479. .powersave_bias_target = powersave_bias_target,
  480. .freq_increase = dbs_freq_increase,
  481. };
  482. static struct common_dbs_data od_dbs_cdata = {
  483. .governor = GOV_ONDEMAND,
  484. .attr_group_gov_sys = &od_attr_group_gov_sys,
  485. .attr_group_gov_pol = &od_attr_group_gov_pol,
  486. .get_cpu_cdbs = get_cpu_cdbs,
  487. .get_cpu_dbs_info_s = get_cpu_dbs_info_s,
  488. .gov_dbs_timer = od_dbs_timer,
  489. .gov_check_cpu = od_check_cpu,
  490. .gov_ops = &od_ops,
  491. .init = od_init,
  492. .exit = od_exit,
  493. };
  494. static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
  495. unsigned int event)
  496. {
  497. return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
  498. }
  499. #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
  500. static
  501. #endif
  502. struct cpufreq_governor cpufreq_gov_ondemand = {
  503. .name = "ondemand",
  504. .governor = od_cpufreq_governor_dbs,
  505. .max_transition_latency = TRANSITION_LATENCY_LIMIT,
  506. .owner = THIS_MODULE,
  507. };
  508. static int __init cpufreq_gov_dbs_init(void)
  509. {
  510. return cpufreq_register_governor(&cpufreq_gov_ondemand);
  511. }
  512. static void __exit cpufreq_gov_dbs_exit(void)
  513. {
  514. cpufreq_unregister_governor(&cpufreq_gov_ondemand);
  515. }
  516. MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
  517. MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>");
  518. MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
  519. "Low Latency Frequency Transition capable processors");
  520. MODULE_LICENSE("GPL");
  521. #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
  522. fs_initcall(cpufreq_gov_dbs_init);
  523. #else
  524. module_init(cpufreq_gov_dbs_init);
  525. #endif
  526. module_exit(cpufreq_gov_dbs_exit);