core.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. 1. General Information
  14. =======================
  15. The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
  16. cpufreq code offers a standardized interface for the CPUFreq
  17. architecture drivers (those pieces of code that do actual
  18. frequency transitions), as well as to "notifiers". These are device
  19. drivers or other part of the kernel that need to be informed of
  20. policy changes (ex. thermal modules like ACPI) or of all
  21. frequency changes (ex. timing code) or even need to force certain
  22. speed limits (like LCD drivers on ARM architecture). Additionally, the
  23. kernel "constant" loops_per_jiffy is updated on frequency changes
  24. here.
  25. Reference counting is done by cpufreq_get_cpu and cpufreq_put_cpu,
  26. which make sure that the cpufreq processor driver is correctly
  27. registered with the core, and will not be unloaded until
  28. cpufreq_put_cpu is called.
  29. 2. CPUFreq notifiers
  30. ====================
  31. CPUFreq notifiers conform to the standard kernel notifier interface.
  32. See linux/include/linux/notifier.h for details on notifiers.
  33. There are two different CPUFreq notifiers - policy notifiers and
  34. transition notifiers.
  35. 2.1 CPUFreq policy notifiers
  36. ----------------------------
  37. These are notified when a new policy is intended to be set. Each
  38. CPUFreq policy notifier is called three times for a policy transition:
  39. 1.) During CPUFREQ_ADJUST all CPUFreq notifiers may change the limit if
  40. they see a need for this - may it be thermal considerations or
  41. hardware limitations.
  42. 2.) During CPUFREQ_INCOMPATIBLE only changes may be done in order to avoid
  43. hardware failure.
  44. 3.) And during CPUFREQ_NOTIFY all notifiers are informed of the new policy
  45. - if two hardware drivers failed to agree on a new policy before this
  46. stage, the incompatible hardware shall be shut down, and the user
  47. informed of this.
  48. The phase is specified in the second argument to the notifier.
  49. The third argument, a void *pointer, points to a struct cpufreq_policy
  50. consisting of five values: cpu, min, max, policy and max_cpu_freq. min
  51. and max are the lower and upper frequencies (in kHz) of the new
  52. policy, policy the new policy, cpu the number of the affected CPU; and
  53. max_cpu_freq the maximum supported CPU frequency. This value is given
  54. for informational purposes only.
  55. 2.2 CPUFreq transition notifiers
  56. --------------------------------
  57. These are notified twice when the CPUfreq driver switches the CPU core
  58. frequency and this change has 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. If the cpufreq core detects the frequency has changed while the system
  67. was suspended, these notifiers are called with CPUFREQ_RESUMECHANGE as
  68. second argument.