core.txt 4.1 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. Clock scaling allows you to change the clock speed of the CPUs on the
  7. fly. This is a nice method to save battery power, because the lower
  8. the clock speed, the less power the CPU consumes.
  9. Contents:
  10. ---------
  11. 1. CPUFreq core and interfaces
  12. 2. CPUFreq notifiers
  13. 3. CPUFreq Table Generation with Operating Performance Point (OPP)
  14. 1. General Information
  15. =======================
  16. The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
  17. cpufreq code offers a standardized interface for the CPUFreq
  18. architecture drivers (those pieces of code that do actual
  19. frequency transitions), as well as to "notifiers". These are device
  20. drivers or other part of the kernel that need to be informed of
  21. policy changes (ex. thermal modules like ACPI) or of all
  22. frequency changes (ex. timing code) or even need to force certain
  23. speed limits (like LCD drivers on ARM architecture). Additionally, the
  24. kernel "constant" loops_per_jiffy is updated on frequency changes
  25. here.
  26. Reference counting is done by cpufreq_get_cpu and cpufreq_put_cpu,
  27. which make sure that the cpufreq processor driver is correctly
  28. registered with the core, and will not be unloaded until
  29. cpufreq_put_cpu is called.
  30. 2. CPUFreq notifiers
  31. ====================
  32. CPUFreq notifiers conform to the standard kernel notifier interface.
  33. See linux/include/linux/notifier.h for details on notifiers.
  34. There are two different CPUFreq notifiers - policy notifiers and
  35. transition notifiers.
  36. 2.1 CPUFreq policy notifiers
  37. ----------------------------
  38. These are notified when a new policy is intended to be set. Each
  39. CPUFreq policy notifier is called twice for a policy transition:
  40. 1.) During CPUFREQ_ADJUST all CPUFreq notifiers may change the limit if
  41. they see a need for this - may it be thermal considerations or
  42. hardware limitations.
  43. 2.) And during CPUFREQ_NOTIFY all notifiers are informed of the new policy
  44. - if two hardware drivers failed to agree on a new policy before this
  45. stage, the incompatible hardware shall be shut down, and the user
  46. informed of this.
  47. The phase is specified in the second argument to the notifier.
  48. The third argument, a void *pointer, points to a struct cpufreq_policy
  49. consisting of five values: cpu, min, max, policy and max_cpu_freq. min
  50. and max are the lower and upper frequencies (in kHz) of the new
  51. policy, policy the new policy, cpu the number of the affected CPU; and
  52. max_cpu_freq the maximum supported CPU frequency. This value is given
  53. for informational purposes only.
  54. 2.2 CPUFreq transition notifiers
  55. --------------------------------
  56. These are notified twice when the CPUfreq driver switches the CPU core
  57. frequency and this change has any external implications.
  58. The second argument specifies the phase - CPUFREQ_PRECHANGE or
  59. CPUFREQ_POSTCHANGE.
  60. The third argument is a struct cpufreq_freqs with the following
  61. values:
  62. cpu - number of the affected CPU
  63. old - old frequency
  64. new - new frequency
  65. 3. CPUFreq Table Generation with Operating Performance Point (OPP)
  66. ==================================================================
  67. For details about OPP, see Documentation/power/opp.txt
  68. dev_pm_opp_init_cpufreq_table - cpufreq framework typically is initialized with
  69. cpufreq_frequency_table_cpuinfo which is provided with the list of
  70. frequencies that are available for operation. This function provides
  71. a ready to use conversion routine to translate the OPP layer's internal
  72. information about the available frequencies into a format readily
  73. 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. cpufreq_frequency_table_cpuinfo(policy, 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