cpufreq_ondemand.c 17 KB

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