Skip to content

Commit 7bd1d40

Browse files
virtuosogregkh
authored andcommitted
stm class: Introduce an abstraction for System Trace Module devices
A System Trace Module (STM) is a device exporting data in System Trace Protocol (STP) format as defined by MIPI STP standards. Examples of such devices are Intel(R) Trace Hub and Coresight STM. This abstraction provides a unified interface for software trace sources to send their data over an STM device to a debug host. In order to do that, such a trace source needs to be assigned a pair of master/channel identifiers that all the data from this source will be tagged with. The STP decoder on the debug host side will use these master/channel tags to distinguish different trace streams from one another inside one STP stream. This abstraction provides a configfs-based policy management mechanism for dynamic allocation of these master/channel pairs based on trace source-supplied string identifier. It has the flexibility of being defined at runtime and at the same time (provided that the policy definition is aligned with the decoding end) consistency. For userspace trace sources, this abstraction provides write()-based and mmap()-based (if the underlying stm device allows this) output mechanism. For kernel-side trace sources, we provide "stm_source" device class that can be connected to an stm device at run time. Cc: [email protected] Reviewed-by: Mathieu Poirier <[email protected]> Signed-off-by: Alexander Shishkin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9b76968 commit 7bd1d40

File tree

14 files changed

+1991
-0
lines changed

14 files changed

+1991
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
What: /config/stp-policy
2+
Date: June 2015
3+
KernelVersion: 4.3
4+
Description:
5+
This group contains policies mandating Master/Channel allocation
6+
for software sources wishing to send trace data over an STM
7+
device.
8+
9+
What: /config/stp-policy/<device>.<policy>
10+
Date: June 2015
11+
KernelVersion: 4.3
12+
Description:
13+
This group is the root of a policy; its name is a concatenation
14+
of an stm device name to which this policy applies and an
15+
arbitrary string. If <device> part doesn't match an existing
16+
stm device, mkdir will fail with ENODEV; if that device already
17+
has a policy assigned to it, mkdir will fail with EBUSY.
18+
19+
What: /config/stp-policy/<device>.<policy>/device
20+
Date: June 2015
21+
KernelVersion: 4.3
22+
Description:
23+
STM device to which this policy applies, read only. Same as the
24+
<device> component of its parent directory.
25+
26+
What: /config/stp-policy/<device>.<policy>/<node>
27+
Date: June 2015
28+
KernelVersion: 4.3
29+
Description:
30+
Policy node is a string identifier that software clients will
31+
use to request a master/channel to be allocated and assigned to
32+
them.
33+
34+
What: /config/stp-policy/<device>.<policy>/<node>/masters
35+
Date: June 2015
36+
KernelVersion: 4.3
37+
Description:
38+
Range of masters from which to allocate for users of this node.
39+
Write two numbers: the first master and the last master number.
40+
41+
What: /config/stp-policy/<device>.<policy>/<node>/channels
42+
Date: June 2015
43+
KernelVersion: 4.3
44+
Description:
45+
Range of channels from which to allocate for users of this node.
46+
Write two numbers: the first channel and the last channel
47+
number.
48+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
What: /sys/class/stm/<stm>/masters
2+
Date: June 2015
3+
KernelVersion: 4.3
4+
Contact: Alexander Shishkin <[email protected]>
5+
Description:
6+
Shows first and last available to software master numbers on
7+
this STM device.
8+
9+
What: /sys/class/stm/<stm>/channels
10+
Date: June 2015
11+
KernelVersion: 4.3
12+
Contact: Alexander Shishkin <[email protected]>
13+
Description:
14+
Shows the number of channels per master on this STM device.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
What: /sys/class/stm_source/<stm_source>/stm_source_link
2+
Date: June 2015
3+
KernelVersion: 4.3
4+
Contact: Alexander Shishkin <[email protected]>
5+
Description:
6+
stm_source device linkage to stm device, where its tracing data
7+
is directed. Reads return an existing connection or "<none>" if
8+
this stm_source is not connected to any stm device yet.
9+
Write an existing (registered) stm device's name here to
10+
connect that device. If a device is already connected to this
11+
stm_source, it will first be disconnected.

Documentation/ioctl/ioctl-number.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Code Seq#(hex) Include File Comments
8181
0x22 all scsi/sg.h
8282
'#' 00-3F IEEE 1394 Subsystem Block for the entire subsystem
8383
'$' 00-0F linux/perf_counter.h, linux/perf_event.h
84+
'%' 00-0F include/uapi/linux/stm.h
85+
System Trace Module subsystem
86+
8487
'&' 00-07 drivers/firewire/nosy-user.h
8588
'1' 00-1F <linux/timepps.h> PPS kit from Ulrich Windl
8689
<ftp://ftp.de.kernel.org/pub/linux/daemons/ntp/PPS/>

Documentation/trace/stm.txt

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

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,6 @@ source "drivers/nvdimm/Kconfig"
188188

189189
source "drivers/nvmem/Kconfig"
190190

191+
source "drivers/hwtracing/stm/Kconfig"
192+
191193
endmenu

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,6 @@ obj-$(CONFIG_PERF_EVENTS) += perf/
165165
obj-$(CONFIG_RAS) += ras/
166166
obj-$(CONFIG_THUNDERBOLT) += thunderbolt/
167167
obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/
168+
obj-$(CONFIG_STM) += hwtracing/stm/
168169
obj-$(CONFIG_ANDROID) += android/
169170
obj-$(CONFIG_NVMEM) += nvmem/

drivers/hwtracing/stm/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
config STM
2+
tristate "System Trace Module devices"
3+
help
4+
A System Trace Module (STM) is a device exporting data in System
5+
Trace Protocol (STP) format as defined by MIPI STP standards.
6+
Examples of such devices are Intel(R) Trace Hub and Coresight STM.
7+
8+
Say Y here to enable System Trace Module device support.

drivers/hwtracing/stm/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
obj-$(CONFIG_STM) += stm_core.o
2+
3+
stm_core-y := core.o policy.o

0 commit comments

Comments
 (0)