core.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =============================================================
  3. General description of the CPUFreq core and CPUFreq notifiers
  4. =============================================================
  5. Authors:
  6. - Dominik Brodowski <[email protected]>
  7. - David Kimdon <[email protected]>
  8. - Rafael J. Wysocki <[email protected]>
  9. - Viresh Kumar <[email protected]>
  10. .. Contents:
  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 of the cpufreq policies is done by cpufreq_cpu_get
  27. and cpufreq_cpu_put, which make sure that the cpufreq driver is
  28. correctly registered with the core, and will not be unloaded until
  29. cpufreq_put_cpu is called. That also ensures that the respective cpufreq
  30. policy doesn't get freed while being used.
  31. 2. CPUFreq notifiers
  32. ====================
  33. CPUFreq notifiers conform to the standard kernel notifier interface.
  34. See linux/include/linux/notifier.h for details on notifiers.
  35. There are two different CPUFreq notifiers - policy notifiers and
  36. transition notifiers.
  37. 2.1 CPUFreq policy notifiers
  38. ----------------------------
  39. These are notified when a new policy is created or removed.
  40. The phase is specified in the second argument to the notifier. The phase is
  41. CPUFREQ_CREATE_POLICY when the policy is first created and it is
  42. CPUFREQ_REMOVE_POLICY when the policy is removed.
  43. The third argument, a ``void *pointer``, points to a struct cpufreq_policy
  44. consisting of several values, including min, max (the lower and upper
  45. frequencies (in kHz) of the new policy).
  46. 2.2 CPUFreq transition notifiers
  47. --------------------------------
  48. These are notified twice for each online CPU in the policy, when the
  49. CPUfreq driver switches the CPU core frequency and this change has no
  50. any external implications.
  51. The second argument specifies the phase - CPUFREQ_PRECHANGE or
  52. CPUFREQ_POSTCHANGE.
  53. The third argument is a struct cpufreq_freqs with the following
  54. values:
  55. ====== ======================================
  56. policy a pointer to the struct cpufreq_policy
  57. old old frequency
  58. new new frequency
  59. flags flags of the cpufreq driver
  60. ====== ======================================
  61. 3. CPUFreq Table Generation with Operating Performance Point (OPP)
  62. ==================================================================
  63. For details about OPP, see Documentation/power/opp.rst
  64. dev_pm_opp_init_cpufreq_table -
  65. This function provides a ready to use conversion routine to translate
  66. the OPP layer's internal information about the available frequencies
  67. into a format readily providable to cpufreq.
  68. .. Warning::
  69. Do not use this function in interrupt context.
  70. Example::
  71. soc_pm_init()
  72. {
  73. /* Do things */
  74. r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
  75. if (!r)
  76. policy->freq_table = freq_table;
  77. /* Do other things */
  78. }
  79. .. note::
  80. This function is available only if CONFIG_CPU_FREQ is enabled in
  81. addition to CONFIG_PM_OPP.
  82. dev_pm_opp_free_cpufreq_table
  83. Free up the table allocated by dev_pm_opp_init_cpufreq_table