stm.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ===================
  2. System Trace Module
  3. ===================
  4. System Trace Module (STM) is a device described in MIPI STP specs as
  5. STP trace stream generator. STP (System Trace Protocol) is a trace
  6. protocol multiplexing data from multiple trace sources, each one of
  7. which is assigned a unique pair of master and channel. While some of
  8. these masters and channels are statically allocated to certain
  9. hardware trace sources, others are available to software. Software
  10. trace sources are usually free to pick for themselves any
  11. master/channel combination from this pool.
  12. On the receiving end of this STP stream (the decoder side), trace
  13. sources can only be identified by master/channel combination, so in
  14. order for the decoder to be able to make sense of the trace that
  15. involves multiple trace sources, it needs to be able to map those
  16. master/channel pairs to the trace sources that it understands.
  17. For instance, it is helpful to know that syslog messages come on
  18. master 7 channel 15, while arbitrary user applications can use masters
  19. 48 to 63 and channels 0 to 127.
  20. To solve this mapping problem, stm class provides a policy management
  21. mechanism via configfs, that allows defining rules that map string
  22. identifiers to ranges of masters and channels. If these rules (policy)
  23. are consistent with what decoder expects, it will be able to properly
  24. process the trace data.
  25. This policy is a tree structure containing rules (policy_node) that
  26. have a name (string identifier) and a range of masters and channels
  27. associated with it, located in "stp-policy" subsystem directory in
  28. configfs. The topmost directory's name (the policy) is formatted as
  29. the STM device name to which this policy applies and and arbitrary
  30. string identifier separated by a stop. From the examle above, a rule
  31. may look like this::
  32. $ ls /config/stp-policy/dummy_stm.my-policy/user
  33. channels masters
  34. $ cat /config/stp-policy/dummy_stm.my-policy/user/masters
  35. 48 63
  36. $ cat /config/stp-policy/dummy_stm.my-policy/user/channels
  37. 0 127
  38. which means that the master allocation pool for this rule consists of
  39. masters 48 through 63 and channel allocation pool has channels 0
  40. through 127 in it. Now, any producer (trace source) identifying itself
  41. with "user" identification string will be allocated a master and
  42. channel from within these ranges.
  43. These rules can be nested, for example, one can define a rule "dummy"
  44. under "user" directory from the example above and this new rule will
  45. be used for trace sources with the id string of "user/dummy".
  46. Trace sources have to open the stm class device's node and write their
  47. trace data into its file descriptor. In order to identify themselves
  48. to the policy, they need to do a STP_POLICY_ID_SET ioctl on this file
  49. descriptor providing their id string. Otherwise, they will be
  50. automatically allocated a master/channel pair upon first write to this
  51. file descriptor according to the "default" rule of the policy, if such
  52. exists.
  53. Some STM devices may allow direct mapping of the channel mmio regions
  54. to userspace for zero-copy writing. One mappable page (in terms of
  55. mmu) will usually contain multiple channels' mmios, so the user will
  56. need to allocate that many channels to themselves (via the
  57. aforementioned ioctl() call) to be able to do this. That is, if your
  58. stm device's channel mmio region is 64 bytes and hardware page size is
  59. 4096 bytes, after a successful STP_POLICY_ID_SET ioctl() call with
  60. width==64, you should be able to mmap() one page on this file
  61. descriptor and obtain direct access to an mmio region for 64 channels.
  62. Examples of STM devices are Intel(R) Trace Hub [1] and Coresight STM
  63. [2].
  64. stm_source
  65. ==========
  66. For kernel-based trace sources, there is "stm_source" device
  67. class. Devices of this class can be connected and disconnected to/from
  68. stm devices at runtime via a sysfs attribute called "stm_source_link"
  69. by writing the name of the desired stm device there, for example::
  70. $ echo dummy_stm.0 > /sys/class/stm_source/console/stm_source_link
  71. For examples on how to use stm_source interface in the kernel, refer
  72. to stm_console, stm_heartbeat or stm_ftrace drivers.
  73. Each stm_source device will need to assume a master and a range of
  74. channels, depending on how many channels it requires. These are
  75. allocated for the device according to the policy configuration. If
  76. there's a node in the root of the policy directory that matches the
  77. stm_source device's name (for example, "console"), this node will be
  78. used to allocate master and channel numbers. If there's no such policy
  79. node, the stm core will pick the first contiguous chunk of channels
  80. within the first available master. Note that the node must exist
  81. before the stm_source device is connected to its stm device.
  82. stm_console
  83. ===========
  84. One implementation of this interface also used in the example above is
  85. the "stm_console" driver, which basically provides a one-way console
  86. for kernel messages over an stm device.
  87. To configure the master/channel pair that will be assigned to this
  88. console in the STP stream, create a "console" policy entry (see the
  89. beginning of this text on how to do that). When initialized, it will
  90. consume one channel.
  91. stm_ftrace
  92. ==========
  93. This is another "stm_source" device, once the stm_ftrace has been
  94. linked with an stm device, and if "function" tracer is enabled,
  95. function address and parent function address which Ftrace subsystem
  96. would store into ring buffer will be exported via the stm device at
  97. the same time.
  98. Currently only Ftrace "function" tracer is supported.
  99. * [1] https://software.intel.com/sites/default/files/managed/d3/3c/intel-th-developer-manual.pdf
  100. * [2] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0444b/index.html