1f71cd93dSMike Leach.. SPDX-License-Identifier: GPL-2.0 2f71cd93dSMike Leach 3f71cd93dSMike Leach====================================== 4f71cd93dSMike LeachCoreSight System Configuration Manager 5f71cd93dSMike Leach====================================== 6f71cd93dSMike Leach 7f71cd93dSMike Leach :Author: Mike Leach <mike.leach@linaro.org> 8f71cd93dSMike Leach :Date: October 2020 9f71cd93dSMike Leach 10f71cd93dSMike LeachIntroduction 11f71cd93dSMike Leach============ 12f71cd93dSMike Leach 13f71cd93dSMike LeachThe CoreSight System Configuration manager is an API that allows the 14f71cd93dSMike Leachprogramming of the CoreSight system with pre-defined configurations that 15f71cd93dSMike Leachcan then be easily enabled from sysfs or perf. 16f71cd93dSMike Leach 17f71cd93dSMike LeachMany CoreSight components can be programmed in complex ways - especially ETMs. 18f71cd93dSMike LeachIn addition, components can interact across the CoreSight system, often via 19f71cd93dSMike Leachthe cross trigger components such as CTI and CTM. These system settings can 20f71cd93dSMike Leachbe defined and enabled as named configurations. 21f71cd93dSMike Leach 22f71cd93dSMike Leach 23f71cd93dSMike LeachBasic Concepts 24f71cd93dSMike Leach============== 25f71cd93dSMike Leach 26f71cd93dSMike LeachThis section introduces the basic concepts of a CoreSight system configuration. 27f71cd93dSMike Leach 28f71cd93dSMike Leach 29f71cd93dSMike LeachFeatures 30f71cd93dSMike Leach-------- 31f71cd93dSMike Leach 32f71cd93dSMike LeachA feature is a named set of programming for a CoreSight device. The programming 33f71cd93dSMike Leachis device dependent, and can be defined in terms of absolute register values, 34f71cd93dSMike Leachresource usage and parameter values. 35f71cd93dSMike Leach 36f71cd93dSMike LeachThe feature is defined using a descriptor. This descriptor is used to load onto 37f71cd93dSMike Leacha matching device, either when the feature is loaded into the system, or when the 38f71cd93dSMike LeachCoreSight device is registered with the configuration manager. 39f71cd93dSMike Leach 40f71cd93dSMike LeachThe load process involves interpreting the descriptor into a set of register 41f71cd93dSMike Leachaccesses in the driver - the resource usage and parameter descriptions 42f71cd93dSMike Leachtranslated into appropriate register accesses. This interpretation makes it easy 43f71cd93dSMike Leachand efficient for the feature to be programmed onto the device when required. 44f71cd93dSMike Leach 45f71cd93dSMike LeachThe feature will not be active on the device until the feature is enabled, and 46f71cd93dSMike Leachthe device itself is enabled. When the device is enabled then enabled features 47f71cd93dSMike Leachwill be programmed into the device hardware. 48f71cd93dSMike Leach 49f71cd93dSMike LeachA feature is enabled as part of a configuration being enabled on the system. 50f71cd93dSMike Leach 51f71cd93dSMike Leach 52f71cd93dSMike LeachParameter Value 53f71cd93dSMike Leach~~~~~~~~~~~~~~~ 54f71cd93dSMike Leach 55f71cd93dSMike LeachA parameter value is a named value that may be set by the user prior to the 56f71cd93dSMike Leachfeature being enabled that can adjust the behaviour of the operation programmed 57f71cd93dSMike Leachby the feature. 58f71cd93dSMike Leach 59f71cd93dSMike LeachFor example, this could be a count value in a programmed operation that repeats 60f71cd93dSMike Leachat a given rate. When the feature is enabled then the current value of the 61f71cd93dSMike Leachparameter is used in programming the device. 62f71cd93dSMike Leach 63f71cd93dSMike LeachThe feature descriptor defines a default value for a parameter, which is used 64f71cd93dSMike Leachif the user does not supply a new value. 65f71cd93dSMike Leach 66f71cd93dSMike LeachUsers can update parameter values using the configfs API for the CoreSight 67f71cd93dSMike Leachsystem - which is described below. 68f71cd93dSMike Leach 69f71cd93dSMike LeachThe current value of the parameter is loaded into the device when the feature 70f71cd93dSMike Leachis enabled on that device. 71f71cd93dSMike Leach 72f71cd93dSMike Leach 73f71cd93dSMike LeachConfigurations 74f71cd93dSMike Leach-------------- 75f71cd93dSMike Leach 76f71cd93dSMike LeachA configuration defines a set of features that are to be used in a trace 77f71cd93dSMike Leachsession where the configuration is selected. For any trace session only one 78f71cd93dSMike Leachconfiguration may be selected. 79f71cd93dSMike Leach 80f71cd93dSMike LeachThe features defined may be on any type of device that is registered 81f71cd93dSMike Leachto support system configuration. A configuration may select features to be 82f71cd93dSMike Leachenabled on a class of devices - i.e. any ETMv4, or specific devices, e.g. a 83f71cd93dSMike Leachspecific CTI on the system. 84f71cd93dSMike Leach 85f71cd93dSMike LeachAs with the feature, a descriptor is used to define the configuration. 86f71cd93dSMike LeachThis will define the features that must be enabled as part of the configuration 87f71cd93dSMike Leachas well as any preset values that can be used to override default parameter 88f71cd93dSMike Leachvalues. 89f71cd93dSMike Leach 90f71cd93dSMike Leach 91f71cd93dSMike LeachPreset Values 92f71cd93dSMike Leach~~~~~~~~~~~~~ 93f71cd93dSMike Leach 94f71cd93dSMike LeachPreset values are easily selectable sets of parameter values for the features 95f71cd93dSMike Leachthat the configuration uses. The number of values in a single preset set, equals 96f71cd93dSMike Leachthe sum of parameter values in the features used by the configuration. 97f71cd93dSMike Leach 98f71cd93dSMike Leache.g. a configuration consists of 3 features, one has 2 parameters, one has 99f71cd93dSMike Leacha single parameter, and another has no parameters. A single preset set will 100f71cd93dSMike Leachtherefore have 3 values. 101f71cd93dSMike Leach 102f71cd93dSMike LeachPresets are optionally defined by the configuration, up to 15 can be defined. 103f71cd93dSMike LeachIf no preset is selected, then the parameter values defined in the feature 104f71cd93dSMike Leachare used as normal. 105f71cd93dSMike Leach 106f71cd93dSMike Leach 107f71cd93dSMike LeachOperation 108f71cd93dSMike Leach~~~~~~~~~ 109f71cd93dSMike Leach 110f71cd93dSMike LeachThe following steps take place in the operation of a configuration. 111f71cd93dSMike Leach 112f71cd93dSMike Leach1) In this example, the configuration is 'autofdo', which has an 113f71cd93dSMike Leach associated feature 'strobing' that works on ETMv4 CoreSight Devices. 114f71cd93dSMike Leach 115f71cd93dSMike Leach2) The configuration is enabled. For example 'perf' may select the 116f71cd93dSMike Leach configuration as part of its command line:: 117f71cd93dSMike Leach 118f71cd93dSMike Leach perf record -e cs_etm/autofdo/ myapp 119f71cd93dSMike Leach 120f71cd93dSMike Leach which will enable the 'autofdo' configuration. 121f71cd93dSMike Leach 122f71cd93dSMike Leach3) perf starts tracing on the system. As each ETMv4 that perf uses for 123f71cd93dSMike Leach trace is enabled, the configuration manager will check if the ETMv4 124f71cd93dSMike Leach has a feature that relates to the currently active configuration. 125f71cd93dSMike Leach In this case 'strobing' is enabled & programmed into the ETMv4. 126f71cd93dSMike Leach 127f71cd93dSMike Leach4) When the ETMv4 is disabled, any registers marked as needing to be 128f71cd93dSMike Leach saved will be read back. 129f71cd93dSMike Leach 130f71cd93dSMike Leach5) At the end of the perf session, the configuration will be disabled. 131f71cd93dSMike Leach 132f71cd93dSMike Leach 133f71cd93dSMike LeachViewing Configurations and Features 134f71cd93dSMike Leach=================================== 135f71cd93dSMike Leach 136f71cd93dSMike LeachThe set of configurations and features that are currently loaded into the 137f71cd93dSMike Leachsystem can be viewed using the configfs API. 138f71cd93dSMike Leach 139f71cd93dSMike LeachMount configfs as normal and the 'cs-syscfg' subsystem will appear:: 140f71cd93dSMike Leach 141f71cd93dSMike Leach $ ls /config 142f71cd93dSMike Leach cs-syscfg stp-policy 143f71cd93dSMike Leach 144f71cd93dSMike LeachThis has two sub-directories:: 145f71cd93dSMike Leach 146f71cd93dSMike Leach $ cd cs-syscfg/ 147f71cd93dSMike Leach $ ls 148f71cd93dSMike Leach configurations features 149f71cd93dSMike Leach 150f71cd93dSMike LeachThe system has the configuration 'autofdo' built in. It may be examined as 151f71cd93dSMike Leachfollows:: 152f71cd93dSMike Leach 153f71cd93dSMike Leach $ cd configurations/ 154f71cd93dSMike Leach $ ls 155f71cd93dSMike Leach autofdo 156f71cd93dSMike Leach $ cd autofdo/ 157f71cd93dSMike Leach $ ls 158*f9809d56SMike Leach description feature_refs preset1 preset3 preset5 preset7 preset9 159*f9809d56SMike Leach enable preset preset2 preset4 preset6 preset8 160f71cd93dSMike Leach $ cat description 161f71cd93dSMike Leach Setup ETMs with strobing for autofdo 162f71cd93dSMike Leach $ cat feature_refs 163f71cd93dSMike Leach strobing 164f71cd93dSMike Leach 165*f9809d56SMike LeachEach preset declared has a 'preset<n>' subdirectory declared. The values for 166f71cd93dSMike Leachthe preset can be examined:: 167f71cd93dSMike Leach 168f71cd93dSMike Leach $ cat preset1/values 169f71cd93dSMike Leach strobing.window = 0x1388 strobing.period = 0x2 170f71cd93dSMike Leach $ cat preset2/values 171f71cd93dSMike Leach strobing.window = 0x1388 strobing.period = 0x4 172f71cd93dSMike Leach 173*f9809d56SMike LeachThe 'enable' and 'preset' files allow the control of a configuration when 174*f9809d56SMike Leachusing CoreSight with sysfs. 175*f9809d56SMike Leach 176f71cd93dSMike LeachThe features referenced by the configuration can be examined in the features 177f71cd93dSMike Leachdirectory:: 178f71cd93dSMike Leach 179f71cd93dSMike Leach $ cd ../../features/strobing/ 180f71cd93dSMike Leach $ ls 181f71cd93dSMike Leach description matches nr_params params 182f71cd93dSMike Leach $ cat description 183f71cd93dSMike Leach Generate periodic trace capture windows. 184f71cd93dSMike Leach parameter 'window': a number of CPU cycles (W) 185f71cd93dSMike Leach parameter 'period': trace enabled for W cycles every period x W cycles 186f71cd93dSMike Leach $ cat matches 187f71cd93dSMike Leach SRC_ETMV4 188f71cd93dSMike Leach $ cat nr_params 189f71cd93dSMike Leach 2 190f71cd93dSMike Leach 191f71cd93dSMike LeachMove to the params directory to examine and adjust parameters:: 192f71cd93dSMike Leach 193f71cd93dSMike Leach cd params 194f71cd93dSMike Leach $ ls 195f71cd93dSMike Leach period window 196f71cd93dSMike Leach $ cd period 197f71cd93dSMike Leach $ ls 198f71cd93dSMike Leach value 199f71cd93dSMike Leach $ cat value 200f71cd93dSMike Leach 0x2710 201f71cd93dSMike Leach # echo 15000 > value 202f71cd93dSMike Leach # cat value 203f71cd93dSMike Leach 0x3a98 204f71cd93dSMike Leach 205f71cd93dSMike LeachParameters adjusted in this way are reflected in all device instances that have 206f71cd93dSMike Leachloaded the feature. 207f71cd93dSMike Leach 208f71cd93dSMike Leach 209f71cd93dSMike LeachUsing Configurations in perf 210f71cd93dSMike Leach============================ 211f71cd93dSMike Leach 212f71cd93dSMike LeachThe configurations loaded into the CoreSight configuration management are 213f71cd93dSMike Leachalso declared in the perf 'cs_etm' event infrastructure so that they can 214f71cd93dSMike Leachbe selected when running trace under perf:: 215f71cd93dSMike Leach 216f71cd93dSMike Leach $ ls /sys/devices/cs_etm 21766bd1333SMike Leach cpu0 cpu2 events nr_addr_filters power subsystem uevent 21866bd1333SMike Leach cpu1 cpu3 format perf_event_mux_interval_ms sinks type 219f71cd93dSMike Leach 22066bd1333SMike LeachThe key directory here is 'events' - a generic perf directory which allows 22166bd1333SMike Leachselection on the perf command line. As with the sinks entries, this provides 22266bd1333SMike Leacha hash of the configuration name. 223f71cd93dSMike Leach 224f71cd93dSMike LeachThe entry in the 'events' directory uses perfs built in syntax generator 225f71cd93dSMike Leachto substitute the syntax for the name when evaluating the command:: 226f71cd93dSMike Leach 227f71cd93dSMike Leach $ ls events/ 228f71cd93dSMike Leach autofdo 229f71cd93dSMike Leach $ cat events/autofdo 230f71cd93dSMike Leach configid=0xa7c3dddd 231f71cd93dSMike Leach 232f71cd93dSMike LeachThe 'autofdo' configuration may be selected on the perf command line:: 233f71cd93dSMike Leach 234f71cd93dSMike Leach $ perf record -e cs_etm/autofdo/u --per-thread <application> 235f71cd93dSMike Leach 236f71cd93dSMike LeachA preset to override the current parameter values can also be selected:: 237f71cd93dSMike Leach 238f71cd93dSMike Leach $ perf record -e cs_etm/autofdo,preset=1/u --per-thread <application> 239f71cd93dSMike Leach 240f71cd93dSMike LeachWhen configurations are selected in this way, then the trace sink used is 241f71cd93dSMike Leachautomatically selected. 242*f9809d56SMike Leach 243*f9809d56SMike LeachUsing Configurations in sysfs 244*f9809d56SMike Leach============================= 245*f9809d56SMike Leach 246*f9809d56SMike LeachCoresight can be controlled using sysfs. When this is in use then a configuration 247*f9809d56SMike Leachcan be made active for the devices that are used in the sysfs session. 248*f9809d56SMike Leach 249*f9809d56SMike LeachIn a configuration there are 'enable' and 'preset' files. 250*f9809d56SMike Leach 251*f9809d56SMike LeachTo enable a configuration for use with sysfs:: 252*f9809d56SMike Leach 253*f9809d56SMike Leach $ cd configurations/autofdo 254*f9809d56SMike Leach $ echo 1 > enable 255*f9809d56SMike Leach 256*f9809d56SMike LeachThis will then use any default parameter values in the features - which can be 257*f9809d56SMike Leachadjusted as described above. 258*f9809d56SMike Leach 259*f9809d56SMike LeachTo use a preset<n> set of parameter values:: 260*f9809d56SMike Leach 261*f9809d56SMike Leach $ echo 3 > preset 262*f9809d56SMike Leach 263*f9809d56SMike LeachThis will select preset3 for the configuration. 264*f9809d56SMike LeachThe valid values for preset are 0 - to deselect presets, and any value of 265*f9809d56SMike Leach<n> where a preset<n> sub-directory is present. 266*f9809d56SMike Leach 267*f9809d56SMike LeachNote that the active sysfs configuration is a global parameter, therefore 268*f9809d56SMike Leachonly a single configuration can be active for sysfs at any one time. 269*f9809d56SMike LeachAttempting to enable a second configuration will result in an error. 270*f9809d56SMike LeachAdditionally, attempting to disable the configuration while in use will 271*f9809d56SMike Leachalso result in an error. 272*f9809d56SMike Leach 273*f9809d56SMike LeachThe use of the active configuration by sysfs is independent of the configuration 274*f9809d56SMike Leachused in perf. 275*f9809d56SMike Leach 276*f9809d56SMike Leach 277*f9809d56SMike LeachCreating and Loading Custom Configurations 278*f9809d56SMike Leach========================================== 279*f9809d56SMike Leach 280*f9809d56SMike LeachCustom configurations and / or features can be dynamically loaded into the 281*f9809d56SMike Leachsystem by using a loadable module. 282*f9809d56SMike Leach 283*f9809d56SMike LeachAn example of a custom configuration is found in ./samples/coresight. 284*f9809d56SMike Leach 285*f9809d56SMike LeachThis creates a new configuration that uses the existing built in 286*f9809d56SMike Leachstrobing feature, but provides a different set of presets. 287*f9809d56SMike Leach 288*f9809d56SMike LeachWhen the module is loaded, then the configuration appears in the configfs 289*f9809d56SMike Leachfile system and is selectable in the same way as the built in configuration 290*f9809d56SMike Leachdescribed above. 291*f9809d56SMike Leach 292*f9809d56SMike LeachConfigurations can use previously loaded features. The system will ensure 293*f9809d56SMike Leachthat it is not possible to unload a feature that is currently in use, by 294*f9809d56SMike Leachenforcing the unload order as the strict reverse of the load order. 295