pm_qos_interface.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. The handle is a pm_qos_request object. By default the request object sets the
  36. request type to PM_QOS_REQ_ALL_CORES, in which case, the PM QoS request
  37. applies to all cores. However, the driver can also specify a request type to
  38. be either of
  39. PM_QOS_REQ_ALL_CORES,
  40. PM_QOS_REQ_AFFINE_CORES,
  41. PM_QOS_REQ_AFFINE_IRQ,
  42. Specify the cpumask when type is set to PM_QOS_REQ_AFFINE_CORES and specify
  43. the IRQ number with PM_QOS_REQ_AFFINE_IRQ.
  44. void pm_qos_update_request(handle, new_target_value):
  45. Will update the list element pointed to by the handle with the new target value
  46. and recompute the new aggregated target, calling the notification tree if the
  47. target is changed.
  48. void pm_qos_remove_request(handle):
  49. Will remove the element. After removal it will update the aggregate target and
  50. call the notification tree if the target was changed as a result of removing
  51. the request.
  52. int pm_qos_request(param_class):
  53. Returns the aggregated value for a given PM QoS class.
  54. int pm_qos_request_for_cpu(param_class, cpu):
  55. Returns the aggregated value for a given PM QoS class for the specified cpu.
  56. int pm_qos_request_for_cpumask(param_class, cpumask):
  57. Returns the aggregated value for a given PM QoS class for the specified
  58. cpumask.
  59. int pm_qos_request_active(handle):
  60. Returns if the request is still active, i.e. it has not been removed from a
  61. PM QoS class constraints list.
  62. int pm_qos_add_notifier(param_class, notifier):
  63. Adds a notification callback function to the PM QoS class. The callback is
  64. called when the aggregated value for the PM QoS class is changed.
  65. int pm_qos_remove_notifier(int param_class, notifier):
  66. Removes the notification callback function for the PM QoS class.
  67. From user mode:
  68. Only processes can register a pm_qos request. To provide for automatic
  69. cleanup of a process, the interface requires the process to register its
  70. parameter requests in the following way:
  71. To register the default pm_qos target for the specific parameter, the process
  72. must open one of /dev/[cpu_dma_latency, network_latency, network_throughput]
  73. As long as the device node is held open that process has a registered
  74. request on the parameter.
  75. To change the requested target value the process needs to write an s32 value to
  76. the open device node. Alternatively the user mode program could write a hex
  77. string for the value using 10 char long format e.g. "0x12345678". This
  78. translates to a pm_qos_update_request call.
  79. To remove the user mode request for a target value simply close the device
  80. node.
  81. 2. PM QoS per-device latency and flags framework
  82. For each device, there are three lists of PM QoS requests. Two of them are
  83. maintained along with the aggregated targets of resume latency and active
  84. state latency tolerance (in microseconds) and the third one is for PM QoS flags.
  85. Values are updated in response to changes of the request list.
  86. The target values of resume latency and active state latency tolerance are
  87. simply the minimum of the request values held in the parameter list elements.
  88. The PM QoS flags aggregate value is a gather (bitwise OR) of all list elements'
  89. values. Two device PM QoS flags are defined currently: PM_QOS_FLAG_NO_POWER_OFF
  90. and PM_QOS_FLAG_REMOTE_WAKEUP.
  91. Note: The aggregated target values are implemented in such a way that reading
  92. the aggregated value does not require any locking mechanism.
  93. From kernel mode the use of this interface is the following:
  94. int dev_pm_qos_add_request(device, handle, type, value):
  95. Will insert an element into the list for that identified device with the
  96. target value. Upon change to this list the new target is recomputed and any
  97. registered notifiers are called only if the target value is now different.
  98. Clients of dev_pm_qos need to save the handle for future use in other
  99. dev_pm_qos API functions.
  100. int dev_pm_qos_update_request(handle, new_value):
  101. Will update the list element pointed to by the handle with the new target value
  102. and recompute the new aggregated target, calling the notification trees if the
  103. target is changed.
  104. int dev_pm_qos_remove_request(handle):
  105. Will remove the element. After removal it will update the aggregate target and
  106. call the notification trees if the target was changed as a result of removing
  107. the request.
  108. s32 dev_pm_qos_read_value(device):
  109. Returns the aggregated value for a given device's constraints list.
  110. enum pm_qos_flags_status dev_pm_qos_flags(device, mask)
  111. Check PM QoS flags of the given device against the given mask of flags.
  112. The meaning of the return values is as follows:
  113. PM_QOS_FLAGS_ALL: All flags from the mask are set
  114. PM_QOS_FLAGS_SOME: Some flags from the mask are set
  115. PM_QOS_FLAGS_NONE: No flags from the mask are set
  116. PM_QOS_FLAGS_UNDEFINED: The device's PM QoS structure has not been
  117. initialized or the list of requests is empty.
  118. int dev_pm_qos_add_ancestor_request(dev, handle, type, value)
  119. Add a PM QoS request for the first direct ancestor of the given device whose
  120. power.ignore_children flag is unset (for DEV_PM_QOS_RESUME_LATENCY requests)
  121. or whose power.set_latency_tolerance callback pointer is not NULL (for
  122. DEV_PM_QOS_LATENCY_TOLERANCE requests).
  123. int dev_pm_qos_expose_latency_limit(device, value)
  124. Add a request to the device's PM QoS list of resume latency constraints and
  125. create a sysfs attribute pm_qos_resume_latency_us under the device's power
  126. directory allowing user space to manipulate that request.
  127. void dev_pm_qos_hide_latency_limit(device)
  128. Drop the request added by dev_pm_qos_expose_latency_limit() from the device's
  129. PM QoS list of resume latency constraints and remove sysfs attribute
  130. pm_qos_resume_latency_us from the device's power directory.
  131. int dev_pm_qos_expose_flags(device, value)
  132. Add a request to the device's PM QoS list of flags and create sysfs attributes
  133. pm_qos_no_power_off and pm_qos_remote_wakeup under the device's power directory
  134. allowing user space to change these flags' value.
  135. void dev_pm_qos_hide_flags(device)
  136. Drop the request added by dev_pm_qos_expose_flags() from the device's PM QoS list
  137. of flags and remove sysfs attributes pm_qos_no_power_off and pm_qos_remote_wakeup
  138. under the device's power directory.
  139. Notification mechanisms:
  140. The per-device PM QoS framework has 2 different and distinct notification trees:
  141. a per-device notification tree and a global notification tree.
  142. int dev_pm_qos_add_notifier(device, notifier):
  143. Adds a notification callback function for the device.
  144. The callback is called when the aggregated value of the device constraints list
  145. is changed (for resume latency device PM QoS only).
  146. int dev_pm_qos_remove_notifier(device, notifier):
  147. Removes the notification callback function for the device.
  148. int dev_pm_qos_add_global_notifier(notifier):
  149. Adds a notification callback function in the global notification tree of the
  150. framework.
  151. The callback is called when the aggregated value for any device is changed
  152. (for resume latency device PM QoS only).
  153. int dev_pm_qos_remove_global_notifier(notifier):
  154. Removes the notification callback function from the global notification tree
  155. of the framework.
  156. Active state latency tolerance
  157. This device PM QoS type is used to support systems in which hardware may switch
  158. to energy-saving operation modes on the fly. In those systems, if the operation
  159. mode chosen by the hardware attempts to save energy in an overly aggressive way,
  160. it may cause excess latencies to be visible to software, causing it to miss
  161. certain protocol requirements or target frame or sample rates etc.
  162. If there is a latency tolerance control mechanism for a given device available
  163. to software, the .set_latency_tolerance callback in that device's dev_pm_info
  164. structure should be populated. The routine pointed to by it is should implement
  165. whatever is necessary to transfer the effective requirement value to the
  166. hardware.
  167. Whenever the effective latency tolerance changes for the device, its
  168. .set_latency_tolerance() callback will be executed and the effective value will
  169. be passed to it. If that value is negative, which means that the list of
  170. latency tolerance requirements for the device is empty, the callback is expected
  171. to switch the underlying hardware latency tolerance control mechanism to an
  172. autonomous mode if available. If that value is PM_QOS_LATENCY_ANY, in turn, and
  173. the hardware supports a special "no requirement" setting, the callback is
  174. expected to use it. That allows software to prevent the hardware from
  175. automatically updating the device's latency tolerance in response to its power
  176. state changes (e.g. during transitions from D3cold to D0), which generally may
  177. be done in the autonomous latency tolerance control mode.
  178. If .set_latency_tolerance() is present for the device, sysfs attribute
  179. pm_qos_latency_tolerance_us will be present in the devivce's power directory.
  180. Then, user space can use that attribute to specify its latency tolerance
  181. requirement for the device, if any. Writing "any" to it means "no requirement,
  182. but do not let the hardware control latency tolerance" and writing "auto" to it
  183. allows the hardware to be switched to the autonomous mode if there are no other
  184. requirements from the kernel side in the device's list.
  185. Kernel code can use the functions described above along with the
  186. DEV_PM_QOS_LATENCY_TOLERANCE device PM QoS type to add, remove and update
  187. latency tolerance requirements for devices.