core.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. CPU frequency and voltage scaling code in the Linux(TM) kernel
  2. L i n u x C P U F r e q
  3. C P U F r e q C o r e
  4. Dominik Brodowski <linux@brodo.de>
  5. David Kimdon <dwhedon@debian.org>
  6. Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  7. Viresh Kumar <viresh.kumar@linaro.org>
  8. Clock scaling allows you to change the clock speed of the CPUs on the
  9. fly. This is a nice method to save battery power, because the lower
  10. the clock speed, the less power the CPU consumes.
  11. Contents:
  12. ---------
  13. 1. CPUFreq core and interfaces
  14. 2. CPUFreq notifiers
  15. 3. CPUFreq Table Generation with Operating Performance Point (OPP)
  16. 1. General Information
  17. =======================
  18. The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
  19. cpufreq code offers a standardized interface for the CPUFreq
  20. architecture drivers (those pieces of code that do actual
  21. frequency transitions), as well as to "notifiers". These are device
  22. drivers or other part of the kernel that need to be informed of
  23. policy changes (ex. thermal modules like ACPI) or of all
  24. frequency changes (ex. timing code) or even need to force certain
  25. speed limits (like LCD drivers on ARM architecture). Additionally, the
  26. kernel "constant" loops_per_jiffy is updated on frequency changes
  27. here.
  28. Reference counting of the cpufreq policies is done by cpufreq_cpu_get
  29. and cpufreq_cpu_put, which make sure that the cpufreq driver is
  30. correctly registered with the core, and will not be unloaded until
  31. cpufreq_put_cpu is called. That also ensures that the respective cpufreq
  32. policy doesn't get freed while being used.
  33. 2. CPUFreq notifiers
  34. ====================
  35. CPUFreq notifiers conform to the standard kernel notifier interface.
  36. See linux/include/linux/notifier.h for details on notifiers.
  37. There are two different CPUFreq notifiers - policy notifiers and
  38. transition notifiers.
  39. 2.1 CPUFreq policy notifiers
  40. ----------------------------
  41. These are notified when a new policy is intended to be set. Each
  42. CPUFreq policy notifier is called twice for a policy transition:
  43. 1.) During CPUFREQ_ADJUST all CPUFreq notifiers may change the limit if
  44. they see a need for this - may it be thermal considerations or
  45. hardware limitations.
  46. 2.) And during CPUFREQ_NOTIFY all notifiers are informed of the new policy
  47. - if two hardware drivers failed to agree on a new policy before this
  48. stage, the incompatible hardware shall be shut down, and the user
  49. informed of this.
  50. The phase is specified in the second argument to the notifier.
  51. The third argument, a void *pointer, points to a struct cpufreq_policy
  52. consisting of several values, including min, max (the lower and upper
  53. frequencies (in kHz) of the new policy).
  54. 2.2 CPUFreq transition notifiers
  55. --------------------------------
  56. These are notified twice for each online CPU in the policy, when the
  57. CPUfreq driver switches the CPU core frequency and this change has no
  58. any external implications.
  59. The second argument specifies the phase - CPUFREQ_PRECHANGE or
  60. CPUFREQ_POSTCHANGE.
  61. The third argument is a struct cpufreq_freqs with the following
  62. values:
  63. cpu - number of the affected CPU
  64. old - old frequency
  65. new - new frequency
  66. flags - flags of the cpufreq driver
  67. 3. CPUFreq Table Generation with Operating Performance Point (OPP)
  68. ==================================================================
  69. For details about OPP, see Documentation/power/opp.txt
  70. dev_pm_opp_init_cpufreq_table -
  71. This function provides a ready to use conversion routine to translate
  72. the OPP layer's internal information about the available frequencies
  73. into a format readily providable to cpufreq.
  74. WARNING: Do not use this function in interrupt context.
  75. Example:
  76. soc_pm_init()
  77. {
  78. /* Do things */
  79. r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
  80. if (!r)
  81. policy->freq_table = freq_table;
  82. /* Do other things */
  83. }
  84. NOTE: This function is available only if CONFIG_CPU_FREQ is enabled in
  85. addition to CONFIG_PM_OPP.
  86. dev_pm_opp_free_cpufreq_table - Free up the table allocated by dev_pm_opp_init_cpufreq_table