stm.txt 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. System Trace Module
  2. ===================
  3. System Trace Module (STM) is a device described in MIPI STP specs as
  4. STP trace stream generator. STP (System Trace Protocol) is a trace
  5. protocol multiplexing data from multiple trace sources, each one of
  6. which is assigned a unique pair of master and channel. While some of
  7. these masters and channels are statically allocated to certain
  8. hardware trace sources, others are available to software. Software
  9. trace sources are usually free to pick for themselves any
  10. master/channel combination from this pool.
  11. On the receiving end of this STP stream (the decoder side), trace
  12. sources can only be identified by master/channel combination, so in
  13. order for the decoder to be able to make sense of the trace that
  14. involves multiple trace sources, it needs to be able to map those
  15. master/channel pairs to the trace sources that it understands.
  16. For instance, it is helpful to know that syslog messages come on
  17. master 7 channel 15, while arbitrary user applications can use masters
  18. 48 to 63 and channels 0 to 127.
  19. To solve this mapping problem, stm class provides a policy management
  20. mechanism via configfs, that allows defining rules that map string
  21. identifiers to ranges of masters and channels. If these rules (policy)
  22. are consistent with what decoder expects, it will be able to properly
  23. process the trace data.
  24. This policy is a tree structure containing rules (policy_node) that
  25. have a name (string identifier) and a range of masters and channels
  26. associated with it, located in "stp-policy" subsystem directory in
  27. configfs. The topmost directory's name (the policy) is formatted as
  28. the STM device name to which this policy applies and and arbitrary
  29. string identifier separated by a stop. From the examle above, a rule
  30. may look like this:
  31. $ ls /config/stp-policy/dummy_stm.my-policy/user
  32. channels masters
  33. $ cat /config/stp-policy/dummy_stm.my-policy/user/masters
  34. 48 63
  35. $ cat /config/stp-policy/dummy_stm.my-policy/user/channels
  36. 0 127
  37. which means that the master allocation pool for this rule consists of
  38. masters 48 through 63 and channel allocation pool has channels 0
  39. through 127 in it. Now, any producer (trace source) identifying itself
  40. with "user" identification string will be allocated a master and
  41. channel from within these ranges.
  42. These rules can be nested, for example, one can define a rule "dummy"
  43. under "user" directory from the example above and this new rule will
  44. be used for trace sources with the id string of "user/dummy".
  45. Trace sources have to open the stm class device's node and write their
  46. trace data into its file descriptor. In order to identify themselves
  47. to the policy, they need to do a STP_POLICY_ID_SET ioctl on this file
  48. descriptor providing their id string. Otherwise, they will be
  49. automatically allocated a master/channel pair upon first write to this
  50. file descriptor according to the "default" rule of the policy, if such
  51. exists.
  52. Some STM devices may allow direct mapping of the channel mmio regions
  53. to userspace for zero-copy writing. One mappable page (in terms of
  54. mmu) will usually contain multiple channels' mmios, so the user will
  55. need to allocate that many channels to themselves (via the
  56. aforementioned ioctl() call) to be able to do this. That is, if your
  57. stm device's channel mmio region is 64 bytes and hardware page size is
  58. 4096 bytes, after a successful STP_POLICY_ID_SET ioctl() call with
  59. width==64, you should be able to mmap() one page on this file
  60. descriptor and obtain direct access to an mmio region for 64 channels.
  61. For kernel-based trace sources, there is "stm_source" device
  62. class. Devices of this class can be connected and disconnected to/from
  63. stm devices at runtime via a sysfs attribute.
  64. Examples of STM devices are Intel(R) Trace Hub [1] and Coresight STM
  65. [2].
  66. [1] https://software.intel.com/sites/default/files/managed/d3/3c/intel-th-developer-manual.pdf
  67. [2] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0444b/index.html