System Trace Module¶
System Trace Module (STM) is a device described in MIPI STP specs asSTP trace stream generator. STP (System Trace Protocol) is a traceprotocol multiplexing data from multiple trace sources, each one ofwhich is assigned a unique pair of master and channel. While some ofthese masters and channels are statically allocated to certainhardware trace sources, others are available to software. Softwaretrace sources are usually free to pick for themselves anymaster/channel combination from this pool.
On the receiving end of this STP stream (the decoder side), tracesources can only be identified by master/channel combination, so inorder for the decoder to be able to make sense of the trace thatinvolves multiple trace sources, it needs to be able to map thosemaster/channel pairs to the trace sources that it understands.
For instance, it is helpful to know that syslog messages come onmaster 7 channel 15, while arbitrary user applications can use masters48 to 63 and channels 0 to 127.
To solve this mapping problem, stm class provides a policy managementmechanism via configfs, that allows defining rules that map stringidentifiers to ranges of masters and channels. If these rules (policy)are consistent with what decoder expects, it will be able to properlyprocess the trace data.
This policy is a tree structure containing rules (policy_node) thathave a name (string identifier) and a range of masters and channelsassociated with it, located in “stp-policy” subsystem directory inconfigfs. The topmost directory’s name (the policy) is formatted asthe STM device name to which this policy applies and an arbitrarystring identifier separated by a stop. From the example above, a rulemay look like this:
$ ls /config/stp-policy/dummy_stm.my-policy/userchannels masters$ cat /config/stp-policy/dummy_stm.my-policy/user/masters48 63$ cat /config/stp-policy/dummy_stm.my-policy/user/channels0 127
which means that the master allocation pool for this rule consists ofmasters 48 through 63 and channel allocation pool has channels 0through 127 in it. Now, any producer (trace source) identifying itselfwith “user” identification string will be allocated a master andchannel from within these ranges.
These rules can be nested, for example, one can define a rule “dummy”under “user” directory from the example above and this new rule willbe used for trace sources with the id string of “user/dummy”.
Trace sources have to open the stm class device’s node and write theirtrace data into its file descriptor.
In order to find an appropriate policy node for a given trace source,several mechanisms can be used. First, a trace source can explicitlyidentify itself by calling an STP_POLICY_ID_SET ioctl on the characterdevice’s file descriptor, providing their id string, before they writeany data there. Secondly, if they chose not to perform the explicitidentification (because you may not want to patch existing softwareto do this), they can just start writing the data, at which point thestm core will try to find a policy node with the name matching thetask’s name (e.g., “syslogd”) and if one exists, it will be used.Thirdly, if the task name can’t be found among the policy nodes, thecatch-all entry “default” will be used, if it exists. This entry alsoneeds to be created and configured by the system administrator orwhatever tools are taking care of the policy configuration. Finally,if all the above steps failed, the write() to an stm file descriptorwill return a error (EINVAL).
Previously, if no policy nodes were found for a trace source, the stmclass would silently fall back to allocating the first availablecontiguous range of master/channels from the beginning of the device’smaster/channel range. The new requirement for a policy node to existwill help programmers and sysadmins identify gaps in configurationand have better control over the un-identified sources.
Some STM devices may allow direct mapping of the channel mmio regionsto userspace for zero-copy writing. One mappable page (in terms ofmmu) will usually contain multiple channels’ mmios, so the user willneed to allocate that many channels to themselves (via theaforementioned ioctl() call) to be able to do this. That is, if yourstm device’s channel mmio region is 64 bytes and hardware page size is4096 bytes, after a successful STP_POLICY_ID_SET ioctl() call withwidth==64, you should be able to mmap() one page on this filedescriptor and obtain direct access to an mmio region for 64 channels.
Examples of STM devices are Intel(R) Trace Hub [1] and Coresight STM[2].
stm_source¶
For kernel-based trace sources, there is “stm_source” deviceclass. Devices of this class can be connected and disconnected to/fromstm devices at runtime via a sysfs attribute called “stm_source_link”by writing the name of the desired stm device there, for example:
$ echo dummy_stm.0 > /sys/class/stm_source/console/stm_source_link
For examples on how to use stm_source interface in the kernel, referto stm_console, stm_heartbeat or stm_ftrace drivers.
Each stm_source device will need to assume a master and a range ofchannels, depending on how many channels it requires. These areallocated for the device according to the policy configuration. Ifthere’s a node in the root of the policy directory that matches thestm_source device’s name (for example, “console”), this node will beused to allocate master and channel numbers. If there’s no such policynode, the stm core will use the catch-all entry “default”, if oneexists. If neither policy nodes exist, the write() to stm_source_linkwill return an error.
stm_console¶
One implementation of this interface also used in the example above isthe “stm_console” driver, which basically provides a one-way consolefor kernel messages over an stm device.
To configure the master/channel pair that will be assigned to thisconsole in the STP stream, create a “console” policy entry (see thebeginning of this text on how to do that). When initialized, it willconsume one channel.
stm_ftrace¶
This is another “stm_source” device, once the stm_ftrace has beenlinked with an stm device, and if “function” tracer is enabled,function address and parent function address which Ftrace subsystemwould store into ring buffer will be exported via the stm device atthe same time.
Currently only Ftrace “function” tracer is supported.