pm_qos_interface.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. PM Quality Of Service Interface.
  2. This interface provides a kernel and user mode interface for registering
  3. performance expectations by drivers, subsystems and user space applications on
  4. one of the parameters.
  5. Two different PM QoS frameworks are available:
  6. 1. PM QoS classes for cpu_dma_latency, network_latency, network_throughput,
  7. memory_bandwidth.
  8. 2. the per-device PM QoS framework provides the API to manage the per-device latency
  9. constraints and PM QoS flags.
  10. Each parameters have defined units:
  11. * latency: usec
  12. * timeout: usec
  13. * throughput: kbs (kilo bit / sec)
  14. * memory bandwidth: mbs (mega bit / sec)
  15. 1. PM QoS framework
  16. The infrastructure exposes multiple misc device nodes one per implemented
  17. parameter. The set of parameters implement is defined by pm_qos_power_init()
  18. and pm_qos_params.h. This is done because having the available parameters
  19. being runtime configurable or changeable from a driver was seen as too easy to
  20. abuse.
  21. For each parameter a list of performance requests is maintained along with
  22. an aggregated target value. The aggregated target value is updated with
  23. changes to the request list or elements of the list. Typically the
  24. aggregated target value is simply the max or min of the request values held
  25. in the parameter list elements.
  26. Note: the aggregated target value is implemented as an atomic variable so that
  27. reading the aggregated value does not require any locking mechanism.
  28. From kernel mode the use of this interface is simple:
  29. void pm_qos_add_request(handle, param_class, target_value):
  30. Will insert an element into the list for that identified PM QoS class with the
  31. target value. Upon change to this list the new target is recomputed and any
  32. registered notifiers are called only if the target value is now different.
  33. Clients of pm_qos need to save the returned handle for future use in other
  34. pm_qos API functions.
  35. void pm_qos_update_request(handle, new_target_value):
  36. Will update the list element pointed to by the handle with the new target value
  37. and recompute the new aggregated target, calling the notification tree if the
  38. target is changed.
  39. void pm_qos_remove_request(handle):
  40. Will remove the element. After removal it will update the aggregate target and
  41. call the notification tree if the target was changed as a result of removing
  42. the request.
  43. int pm_qos_request(param_class):
  44. Returns the aggregated value for a given PM QoS class.
  45. int pm_qos_request_active(handle):
  46. Returns if the request is still active, i.e. it has not been removed from a
  47. PM QoS class constraints list.
  48. int pm_qos_add_notifier(param_class, notifier):
  49. Adds a notification callback function to the PM QoS class. The callback is
  50. called when the aggregated value for the PM QoS class is changed.
  51. int pm_qos_remove_notifier(int param_class, notifier):
  52. Removes the notification callback function for the PM QoS class.
  53. From user mode:
  54. Only processes can register a pm_qos request. To provide for automatic
  55. cleanup of a process, the interface requires the process to register its
  56. parameter requests in the following way:
  57. To register the default pm_qos target for the specific parameter, the process
  58. must open one of /dev/[cpu_dma_latency, network_latency, network_throughput]
  59. As long as the device node is held open that process has a registered
  60. request on the parameter.
  61. To change the requested target value the process needs to write an s32 value to
  62. the open device node. Alternatively the user mode program could write a hex
  63. string for the value using 10 char long format e.g. "0x12345678". This
  64. translates to a pm_qos_update_request call.
  65. To remove the user mode request for a target value simply close the device
  66. node.
  67. 2. PM QoS per-device latency and flags framework
  68. For each device, there are three lists of PM QoS requests. Two of them are
  69. maintained along with the aggregated targets of resume latency and active
  70. state latency tolerance (in microseconds) and the third one is for PM QoS flags.
  71. Values are updated in response to changes of the request list.
  72. The target values of resume latency and active state latency tolerance are
  73. simply the minimum of the request values held in the parameter list elements.
  74. The PM QoS flags aggregate value is a gather (bitwise OR) of all list elements'
  75. values. Two device PM QoS flags are defined currently: PM_QOS_FLAG_NO_POWER_OFF
  76. and PM_QOS_FLAG_REMOTE_WAKEUP.
  77. Note: The aggregated target values are implemented in such a way that reading
  78. the aggregated value does not require any locking mechanism.
  79. From kernel mode the use of this interface is the following:
  80. int dev_pm_qos_add_request(device, handle, type, value):
  81. Will insert an element into the list for that identified device with the
  82. target value. Upon change to this list the new target is recomputed and any
  83. registered notifiers are called only if the target value is now different.
  84. Clients of dev_pm_qos need to save the handle for future use in other
  85. dev_pm_qos API functions.
  86. int dev_pm_qos_update_request(handle, new_value):
  87. Will update the list element pointed to by the handle with the new target value
  88. and recompute the new aggregated target, calling the notification trees if the
  89. target is changed.
  90. int dev_pm_qos_remove_request(handle):
  91. Will remove the element. After removal it will update the aggregate target and
  92. call the notification trees if the target was changed as a result of removing
  93. the request.
  94. s32 dev_pm_qos_read_value(device):
  95. Returns the aggregated value for a given device's constraints list.
  96. enum pm_qos_flags_status dev_pm_qos_flags(device, mask)
  97. Check PM QoS flags of the given device against the given mask of flags.
  98. The meaning of the return values is as follows:
  99. PM_QOS_FLAGS_ALL: All flags from the mask are set
  100. PM_QOS_FLAGS_SOME: Some flags from the mask are set
  101. PM_QOS_FLAGS_NONE: No flags from the mask are set
  102. PM_QOS_FLAGS_UNDEFINED: The device's PM QoS structure has not been
  103. initialized or the list of requests is empty.
  104. int dev_pm_qos_add_ancestor_request(dev, handle, type, value)
  105. Add a PM QoS request for the first direct ancestor of the given device whose
  106. power.ignore_children flag is unset (for DEV_PM_QOS_RESUME_LATENCY requests)
  107. or whose power.set_latency_tolerance callback pointer is not NULL (for
  108. DEV_PM_QOS_LATENCY_TOLERANCE requests).
  109. int dev_pm_qos_expose_latency_limit(device, value)
  110. Add a request to the device's PM QoS list of resume latency constraints and
  111. create a sysfs attribute pm_qos_resume_latency_us under the device's power
  112. directory allowing user space to manipulate that request.
  113. void dev_pm_qos_hide_latency_limit(device)
  114. Drop the request added by dev_pm_qos_expose_latency_limit() from the device's
  115. PM QoS list of resume latency constraints and remove sysfs attribute
  116. pm_qos_resume_latency_us from the device's power directory.
  117. int dev_pm_qos_expose_flags(device, value)
  118. Add a request to the device's PM QoS list of flags and create sysfs attributes
  119. pm_qos_no_power_off and pm_qos_remote_wakeup under the device's power directory
  120. allowing user space to change these flags' value.
  121. void dev_pm_qos_hide_flags(device)
  122. Drop the request added by dev_pm_qos_expose_flags() from the device's PM QoS list
  123. of flags and remove sysfs attributes pm_qos_no_power_off and pm_qos_remote_wakeup
  124. under the device's power directory.
  125. Notification mechanisms:
  126. The per-device PM QoS framework has 2 different and distinct notification trees:
  127. a per-device notification tree and a global notification tree.
  128. int dev_pm_qos_add_notifier(device, notifier):
  129. Adds a notification callback function for the device.
  130. The callback is called when the aggregated value of the device constraints list
  131. is changed (for resume latency device PM QoS only).
  132. int dev_pm_qos_remove_notifier(device, notifier):
  133. Removes the notification callback function for the device.
  134. int dev_pm_qos_add_global_notifier(notifier):
  135. Adds a notification callback function in the global notification tree of the
  136. framework.
  137. The callback is called when the aggregated value for any device is changed
  138. (for resume latency device PM QoS only).
  139. int dev_pm_qos_remove_global_notifier(notifier):
  140. Removes the notification callback function from the global notification tree
  141. of the framework.
  142. Active state latency tolerance
  143. This device PM QoS type is used to support systems in which hardware may switch
  144. to energy-saving operation modes on the fly. In those systems, if the operation
  145. mode chosen by the hardware attempts to save energy in an overly aggressive way,
  146. it may cause excess latencies to be visible to software, causing it to miss
  147. certain protocol requirements or target frame or sample rates etc.
  148. If there is a latency tolerance control mechanism for a given device available
  149. to software, the .set_latency_tolerance callback in that device's dev_pm_info
  150. structure should be populated. The routine pointed to by it is should implement
  151. whatever is necessary to transfer the effective requirement value to the
  152. hardware.
  153. Whenever the effective latency tolerance changes for the device, its
  154. .set_latency_tolerance() callback will be executed and the effective value will
  155. be passed to it. If that value is negative, which means that the list of
  156. latency tolerance requirements for the device is empty, the callback is expected
  157. to switch the underlying hardware latency tolerance control mechanism to an
  158. autonomous mode if available. If that value is PM_QOS_LATENCY_ANY, in turn, and
  159. the hardware supports a special "no requirement" setting, the callback is
  160. expected to use it. That allows software to prevent the hardware from
  161. automatically updating the device's latency tolerance in response to its power
  162. state changes (e.g. during transitions from D3cold to D0), which generally may
  163. be done in the autonomous latency tolerance control mode.
  164. If .set_latency_tolerance() is present for the device, sysfs attribute
  165. pm_qos_latency_tolerance_us will be present in the devivce's power directory.
  166. Then, user space can use that attribute to specify its latency tolerance
  167. requirement for the device, if any. Writing "any" to it means "no requirement,
  168. but do not let the hardware control latency tolerance" and writing "auto" to it
  169. allows the hardware to be switched to the autonomous mode if there are no other
  170. requirements from the kernel side in the device's list.
  171. Kernel code can use the functions described above along with the
  172. DEV_PM_QOS_LATENCY_TOLERANCE device PM QoS type to add, remove and update
  173. latency tolerance requirements for devices.