pm_qos_interface.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. 2. the per-device PM QoS framework provides the API to manage the per-device latency
  8. constraints and PM QoS flags.
  9. Each parameters have defined units:
  10. * latency: usec
  11. * timeout: usec
  12. * throughput: kbs (kilo bit / sec)
  13. 1. PM QoS framework
  14. The infrastructure exposes multiple misc device nodes one per implemented
  15. parameter. The set of parameters implement is defined by pm_qos_power_init()
  16. and pm_qos.h. This is done because having the available parameters
  17. being runtime configurable or changeable from a driver was seen as too easy to
  18. abuse.
  19. For each parameter a list of performance requests is maintained along with
  20. an aggregated target value. The aggregated target value is updated with
  21. changes to the request list or elements of the list. Typically the
  22. aggregated target value is simply the max or min of the request values held
  23. in the parameter list elements.
  24. Note: the aggregated target value is implemented as an atomic variable so that
  25. reading the aggregated value does not require any locking mechanism.
  26. From kernel mode the use of this interface is simple:
  27. void pm_qos_add_request(handle, param_class, target_value):
  28. Will insert an element into the list for that identified PM QoS class with the
  29. target value. Upon change to this list the new target is recomputed and any
  30. registered notifiers are called only if the target value is now different.
  31. Clients of pm_qos need to save the returned handle for future use in other
  32. pm_qos API functions.
  33. void pm_qos_update_request(handle, new_target_value):
  34. Will update the list element pointed to by the handle with the new target value
  35. and recompute the new aggregated target, calling the notification tree if the
  36. target is changed.
  37. void pm_qos_remove_request(handle):
  38. Will remove the element. After removal it will update the aggregate target and
  39. call the notification tree if the target was changed as a result of removing
  40. the request.
  41. int pm_qos_request(param_class):
  42. Returns the aggregated value for a given PM QoS class.
  43. int pm_qos_request_active(handle):
  44. Returns if the request is still active, i.e. it has not been removed from a
  45. PM QoS class constraints list.
  46. int pm_qos_add_notifier(param_class, notifier):
  47. Adds a notification callback function to the PM QoS class. The callback is
  48. called when the aggregated value for the PM QoS class is changed.
  49. int pm_qos_remove_notifier(int param_class, notifier):
  50. Removes the notification callback function for the PM QoS class.
  51. From user mode:
  52. Only processes can register a pm_qos request. To provide for automatic
  53. cleanup of a process, the interface requires the process to register its
  54. parameter requests in the following way:
  55. To register the default pm_qos target for the specific parameter, the process
  56. must open one of /dev/[cpu_dma_latency, network_latency, network_throughput]
  57. As long as the device node is held open that process has a registered
  58. request on the parameter.
  59. To change the requested target value the process needs to write an s32 value to
  60. the open device node. Alternatively the user mode program could write a hex
  61. string for the value using 10 char long format e.g. "0x12345678". This
  62. translates to a pm_qos_update_request call.
  63. To remove the user mode request for a target value simply close the device
  64. node.
  65. 2. PM QoS per-device latency and flags framework
  66. For each device, there are two lists of PM QoS requests. One is maintained
  67. along with the aggregated target of latency value and the other is for PM QoS
  68. flags. Values are updated in response to changes of the request list.
  69. Target latency value is simply the minimum of the request values held in the
  70. parameter list elements. The PM QoS flags aggregate value is a gather (bitwise
  71. OR) of all list elements' values. Two device PM QoS flags are defined currently:
  72. PM_QOS_FLAG_NO_POWER_OFF and PM_QOS_FLAG_REMOTE_WAKEUP.
  73. Note: the aggregated target value is implemented as an atomic variable so that
  74. reading the aggregated value does not require any locking mechanism.
  75. From kernel mode the use of this interface is the following:
  76. int dev_pm_qos_add_request(device, handle, type, value):
  77. Will insert an element into the list for that identified device with the
  78. target value. Upon change to this list the new target is recomputed and any
  79. registered notifiers are called only if the target value is now different.
  80. Clients of dev_pm_qos need to save the handle for future use in other
  81. dev_pm_qos API functions.
  82. int dev_pm_qos_update_request(handle, new_value):
  83. Will update the list element pointed to by the handle with the new target value
  84. and recompute the new aggregated target, calling the notification trees if the
  85. target is changed.
  86. int dev_pm_qos_remove_request(handle):
  87. Will remove the element. After removal it will update the aggregate target and
  88. call the notification trees if the target was changed as a result of removing
  89. the request.
  90. s32 dev_pm_qos_read_value(device):
  91. Returns the aggregated value for a given device's constraints list.
  92. enum pm_qos_flags_status dev_pm_qos_flags(device, mask)
  93. Check PM QoS flags of the given device against the given mask of flags.
  94. The meaning of the return values is as follows:
  95. PM_QOS_FLAGS_ALL: All flags from the mask are set
  96. PM_QOS_FLAGS_SOME: Some flags from the mask are set
  97. PM_QOS_FLAGS_NONE: No flags from the mask are set
  98. PM_QOS_FLAGS_UNDEFINED: The device's PM QoS structure has not been
  99. initialized or the list of requests is empty.
  100. int dev_pm_qos_add_ancestor_request(dev, handle, value)
  101. Add a PM QoS request for the first direct ancestor of the given device whose
  102. power.ignore_children flag is unset.
  103. int dev_pm_qos_expose_latency_limit(device, value)
  104. Add a request to the device's PM QoS list of latency constraints and create
  105. a sysfs attribute pm_qos_resume_latency_us under the device's power directory
  106. allowing user space to manipulate that request.
  107. void dev_pm_qos_hide_latency_limit(device)
  108. Drop the request added by dev_pm_qos_expose_latency_limit() from the device's
  109. PM QoS list of latency constraints and remove sysfs attribute pm_qos_resume_latency_us
  110. from the device's power directory.
  111. int dev_pm_qos_expose_flags(device, value)
  112. Add a request to the device's PM QoS list of flags and create sysfs attributes
  113. pm_qos_no_power_off and pm_qos_remote_wakeup under the device's power directory
  114. allowing user space to change these flags' value.
  115. void dev_pm_qos_hide_flags(device)
  116. Drop the request added by dev_pm_qos_expose_flags() from the device's PM QoS list
  117. of flags and remove sysfs attributes pm_qos_no_power_off and pm_qos_remote_wakeup
  118. under the device's power directory.
  119. Notification mechanisms:
  120. The per-device PM QoS framework has 2 different and distinct notification trees:
  121. a per-device notification tree and a global notification tree.
  122. int dev_pm_qos_add_notifier(device, notifier):
  123. Adds a notification callback function for the device.
  124. The callback is called when the aggregated value of the device constraints list
  125. is changed.
  126. int dev_pm_qos_remove_notifier(device, notifier):
  127. Removes the notification callback function for the device.
  128. int dev_pm_qos_add_global_notifier(notifier):
  129. Adds a notification callback function in the global notification tree of the
  130. framework.
  131. The callback is called when the aggregated value for any device is changed.
  132. int dev_pm_qos_remove_global_notifier(notifier):
  133. Removes the notification callback function from the global notification tree
  134. of the framework.
  135. From user mode:
  136. No API for user space access to the per-device latency constraints is provided
  137. yet - still under discussion.