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