brintos

brintos / linux-shallow public Read only

0
0
Text · 6.6 KiB · 1ed49dd Raw
144 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3===================4System Trace Module5===================6 7System Trace Module (STM) is a device described in MIPI STP specs as8STP trace stream generator. STP (System Trace Protocol) is a trace9protocol multiplexing data from multiple trace sources, each one of10which is assigned a unique pair of master and channel. While some of11these masters and channels are statically allocated to certain12hardware trace sources, others are available to software. Software13trace sources are usually free to pick for themselves any14master/channel combination from this pool.15 16On the receiving end of this STP stream (the decoder side), trace17sources can only be identified by master/channel combination, so in18order for the decoder to be able to make sense of the trace that19involves multiple trace sources, it needs to be able to map those20master/channel pairs to the trace sources that it understands.21 22For instance, it is helpful to know that syslog messages come on23master 7 channel 15, while arbitrary user applications can use masters2448 to 63 and channels 0 to 127.25 26To solve this mapping problem, stm class provides a policy management27mechanism via configfs, that allows defining rules that map string28identifiers to ranges of masters and channels. If these rules (policy)29are consistent with what decoder expects, it will be able to properly30process the trace data.31 32This policy is a tree structure containing rules (policy_node) that33have a name (string identifier) and a range of masters and channels34associated with it, located in "stp-policy" subsystem directory in35configfs. The topmost directory's name (the policy) is formatted as36the STM device name to which this policy applies and an arbitrary37string identifier separated by a stop. From the example above, a rule38may look like this::39 40	$ ls /config/stp-policy/dummy_stm.my-policy/user41	channels masters42	$ cat /config/stp-policy/dummy_stm.my-policy/user/masters43	48 6344	$ cat /config/stp-policy/dummy_stm.my-policy/user/channels45	0 12746 47which means that the master allocation pool for this rule consists of48masters 48 through 63 and channel allocation pool has channels 049through 127 in it. Now, any producer (trace source) identifying itself50with "user" identification string will be allocated a master and51channel from within these ranges.52 53These rules can be nested, for example, one can define a rule "dummy"54under "user" directory from the example above and this new rule will55be used for trace sources with the id string of "user/dummy".56 57Trace sources have to open the stm class device's node and write their58trace data into its file descriptor.59 60In order to find an appropriate policy node for a given trace source,61several mechanisms can be used. First, a trace source can explicitly62identify itself by calling an STP_POLICY_ID_SET ioctl on the character63device's file descriptor, providing their id string, before they write64any data there. Secondly, if they chose not to perform the explicit65identification (because you may not want to patch existing software66to do this), they can just start writing the data, at which point the67stm core will try to find a policy node with the name matching the68task's name (e.g., "syslogd") and if one exists, it will be used.69Thirdly, if the task name can't be found among the policy nodes, the70catch-all entry "default" will be used, if it exists. This entry also71needs to be created and configured by the system administrator or72whatever tools are taking care of the policy configuration. Finally,73if all the above steps failed, the write() to an stm file descriptor74will return a error (EINVAL).75 76Previously, if no policy nodes were found for a trace source, the stm77class would silently fall back to allocating the first available78contiguous range of master/channels from the beginning of the device's79master/channel range. The new requirement for a policy node to exist80will help programmers and sysadmins identify gaps in configuration81and have better control over the un-identified sources.82 83Some STM devices may allow direct mapping of the channel mmio regions84to userspace for zero-copy writing. One mappable page (in terms of85mmu) will usually contain multiple channels' mmios, so the user will86need to allocate that many channels to themselves (via the87aforementioned ioctl() call) to be able to do this. That is, if your88stm device's channel mmio region is 64 bytes and hardware page size is894096 bytes, after a successful STP_POLICY_ID_SET ioctl() call with90width==64, you should be able to mmap() one page on this file91descriptor and obtain direct access to an mmio region for 64 channels.92 93Examples of STM devices are Intel(R) Trace Hub [1] and Coresight STM94[2].95 96stm_source97==========98 99For kernel-based trace sources, there is "stm_source" device100class. Devices of this class can be connected and disconnected to/from101stm devices at runtime via a sysfs attribute called "stm_source_link"102by writing the name of the desired stm device there, for example::103 104	$ echo dummy_stm.0 > /sys/class/stm_source/console/stm_source_link105 106For examples on how to use stm_source interface in the kernel, refer107to stm_console, stm_heartbeat or stm_ftrace drivers.108 109Each stm_source device will need to assume a master and a range of110channels, depending on how many channels it requires. These are111allocated for the device according to the policy configuration. If112there's a node in the root of the policy directory that matches the113stm_source device's name (for example, "console"), this node will be114used to allocate master and channel numbers. If there's no such policy115node, the stm core will use the catch-all entry "default", if one116exists. If neither policy nodes exist, the write() to stm_source_link117will return an error.118 119stm_console120===========121 122One implementation of this interface also used in the example above is123the "stm_console" driver, which basically provides a one-way console124for kernel messages over an stm device.125 126To configure the master/channel pair that will be assigned to this127console in the STP stream, create a "console" policy entry (see the128beginning of this text on how to do that). When initialized, it will129consume one channel.130 131stm_ftrace132==========133 134This is another "stm_source" device, once the stm_ftrace has been135linked with an stm device, and if "function" tracer is enabled,136function address and parent function address which Ftrace subsystem137would store into ring buffer will be exported via the stm device at138the same time.139 140Currently only Ftrace "function" tracer is supported.141 142* [1] https://software.intel.com/sites/default/files/managed/d3/3c/intel-th-developer-manual.pdf143* [2] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0444b/index.html144