From patchwork Mon Jul 4 15:42:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12905534 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 897CCC433EF for ; Mon, 4 Jul 2022 15:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4f9zADPKO5i5D5dHSy37yrhMEz0owjnTjvo2VC7voB0=; b=oC/lKuMHaI7HvE UrTbUm9Qf8dEaeSey/oLquHowYkt0QnzlZLo7/x4Onk+rk6Cxmh6VT6NQdUa3n8vF+IlCq5wezt16 5epakqEARlPIz/3rWrMVxRwKR2bVs36QpB9pwzOAQD3PevTbU6QYraB3xxmvwhE2mtiWQ2W+uDxug U28PRnZf1o0S0U0Q2vDumNPpoOiNeeq6o6lSyK85E1pHovpve6j+WvzlaG6soR4GUvaP3FhOMboyz Ydlji2SW9UQgC6PpCqMn+NwvufzpB3orncqEv5028g2N4K3U8/ZftkWMHAZdcvxbpRFWiTYgqD3bg tqW2b63FUrfCmqTG15Cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8OFC-009mEw-0W; Mon, 04 Jul 2022 15:44:14 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8OE0-009llB-KX for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2022 15:43:02 +0000 Received: by mail-wm1-x334.google.com with SMTP id f190so5618132wma.5 for ; Mon, 04 Jul 2022 08:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=20URghUEhnd48vVWNIo4NcdPqwWP3OApoVFQSqBizbk=; b=aI3lRra6RdQgQW5qVEVV5qlEQowVjQERD7fgGhTtzuE/AmB3oMX+os4xQAq386fKru XFlR4A+6LCUB/3OaOFjnlTkqeI0S4M9m/ktLBvCfB7Y8rbT7ZHIBb8UgUeGm1gWgH6vj N6W4bgFtoleVPetp9BFJmBq2/7CO1DfIO2SHjVIAfo8SVErRET/CKirJSEyDXTP47Nu/ MbW0yRNIOCIIncUQBpnKT3AKQHm9DN78X9rQAppvrpmScv1tSjAk2wpoZ/ztbaT5KYFb OwU62eZcvq/RA1AlMNghv8jnZhTVuvx1Q1DpllIW4il0Ps37GQFka58CiZPn7CI6BCoo U6Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=20URghUEhnd48vVWNIo4NcdPqwWP3OApoVFQSqBizbk=; b=ug45GRCl4Ymwi4nf+MBtBCl/cWEiG3yu20QHT2uFtpd/o48u60p6lYAGxmH96XBTFN jVuUY8T/tkRuuGbXRKH6kggo/hqPjMDLz+vl3V8t32I2NbYXUHMSjNvMSqN+wxNPt69g yx8r7/KyXPdBRbxULM9KJVGkduNQEOtlZO3UgfCwlhHrsmxY3AwozfjJBr5zwLoYCOd0 WRbJSA13C1G3d57vTv4vQLOlWBNgP7ugl+xHRgy6qQIzrLcloQNXUxfdE+q1Wyvf8Ya7 lIYPtuQRBWuqtREPCQ0ij/P3j4X7J/CegseGJ/pg+O1R+crTpF+8yhWajOivzUek7r3o Tflg== X-Gm-Message-State: AJIora869iLS7VCpJ09Mc/IAtKbj3PMwGw+zch7XvNllQjiRSJeVV0U+ wJ2IAV1JWksSfgACMt0btKW97Ed32vyqAQ== X-Google-Smtp-Source: AGRyM1vUjayhhF9itLimifgtEv6TFBAqsWs030GZ+veu/QlNS9RMYOI8pn0VnSnKvh+Jcj/nrXmwhw== X-Received: by 2002:a05:600c:3592:b0:3a0:4c17:5ec1 with SMTP id p18-20020a05600c359200b003a04c175ec1mr33230222wmq.4.1656949376903; Mon, 04 Jul 2022 08:42:56 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:a9e8:9fdd:fa2d:1c72]) by smtp.gmail.com with ESMTPSA id j6-20020adfff86000000b0021d6b851ca1sm2763749wrr.111.2022.07.04.08.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 08:42:56 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, acme@kernel.org, james.clark@arm.com, Mike Leach , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH v4 6/7] Documentation: coresight: docs for config load via configfs Date: Mon, 4 Jul 2022 16:42:48 +0100 Message-Id: <20220704154249.11501-7-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220704154249.11501-1-mike.leach@linaro.org> References: <20220704154249.11501-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220704_084300_765083_466B1BA0 X-CRM114-Status: GOOD ( 30.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add documentation covering the configfs updates that allow binary configuration files to be loaded and unloaded via configfs, along with the demonstration programs in samples. Cc: Jonathan Corbet Cc: linux-doc@vger.kernel.org Signed-off-by: Mike Leach --- .../trace/coresight/coresight-config.rst | 202 +++++++++++++++++- 1 file changed, 195 insertions(+), 7 deletions(-) diff --git a/Documentation/trace/coresight/coresight-config.rst b/Documentation/trace/coresight/coresight-config.rst index 6d5ffa6f7347..109053eb1b93 100644 --- a/Documentation/trace/coresight/coresight-config.rst +++ b/Documentation/trace/coresight/coresight-config.rst @@ -141,11 +141,11 @@ Mount configfs as normal and the 'cs-syscfg' subsystem will appear:: $ ls /config cs-syscfg stp-policy -This has two sub-directories:: +This has two sub-directories, with the load and unload attribute files:: $ cd cs-syscfg/ $ ls - configurations features + configurations features load unload The system has the configuration 'autofdo' built in. It may be examined as follows:: @@ -278,9 +278,16 @@ Creating and Loading Custom Configurations ========================================== Custom configurations and / or features can be dynamically loaded into the -system by using a loadable module. +system by using a loadable module, or by loading a binary configuration +file in configfs. -An example of a custom configuration is found in ./samples/coresight. +Loaded configurations can use previously loaded features. The system will +ensure that it is not possible to unload a feature that is currently in +use, by enforcing the unload order as the strict reverse of the load order. + + +Using a Loadable Module +----------------------- This creates a new configuration that uses the existing built in strobing feature, but provides a different set of presets. @@ -289,6 +296,187 @@ When the module is loaded, then the configuration appears in the configfs file system and is selectable in the same way as the built in configuration described above. -Configurations can use previously loaded features. The system will ensure -that it is not possible to unload a feature that is currently in use, by -enforcing the unload order as the strict reverse of the load order. +The file 'coresight-cfg-sample.c' contains the configuration and module +initialisation code needed to create the loadable module. + +This will be built alongside the kernel modules if select in KConfig. + +An example of a custom configuration module is found in './samples/coresight'. + +Using a Binary Configuration File +--------------------------------- + +The './tools/coresight' directory contains example programs to generate and +read and print binary configuration files. + +Building the tools creates the 'coresight-cfg-file-gen' program that will +generate a configuration binary 'example1.cscfg' that can be loaded into the +system using configfs. The configuration declared in the source file +'coresight-cfg-example1.c' is named 'autofdo3' - the name that will be used +once loaded. + +The source files 'coresight-cfg-bufw.h' and 'coresight-cfg-bufw.c' provide a +standard function to convert a configuration declared in 'C' into the correct +binary buffer format. These files can be re-used to create new custom +configurations. Alternatively, addition examples can be added to the +'coresight-cfg-file-gen' program:: + + $ ./coresight-cfg-file-gen + Coresight Configuration file Generator + + Generating example1 example + Generating example2 example + +The program 'coresight-cfg-file-read' can read back and print a configuration +binary. This is built using the file reader from the driver code +(coresight-config-file.c), which is copied over into './tools/coresight' at +build time.:: + + ./coresight-cfg-file-read example1.cscfg + CoreSight Configuration file reader + ============================================ + + Configuration 1 + Name:- autofdo3 + Description:- + Setup ETMs with strobing for autofdo + Supplied presets allow experimentation with mark-space ratio for various loads + + Uses 1 features:- + Feature-1: strobing + + Provides 4 sets of preset values, 2 presets per set + set[0]: 0x7d0, 0x64, + set[1]: 0x7d0, 0x3e8, + set[2]: 0x7d0, 0x1388, + set[3]: 0x7d0, 0x2710, + + ============================================ + File contains no features + +There are additional attributes in the cs-syscfg directory - load and +unload that can be used to load and unload configuration binary files. To +load, 'cat' the binary config into the load attribute:: + + $ ls /config/cs-syscfg + configurations features load unload + $ cat example1.cscfg > /config/cs-syscfg/load + $ ls /config/cs-syscfg/configurations/ + autofdo autofdo3 + +To unload, use the same file in the unload attribute:: + + $ cat example1.cscfg > /config/cs-syscfg/unload + ls /config/cs-syscfg/configurations/ + autofdo + + + +Binary Configuration File Format +-------------------------------- + +The file format is defined in the source file **coresight-config-file.h** + +The source reader and generator examples produce a binary of this format. + +This arrangement is reproduced below:- + +Overall File structure +~~~~~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_header] // Mandatory + [CONFIG_ELEM]* // Optional - multiple, defined by cscfg_file_header.nr_configs + [FEATURE_ELEM]* // Optional - multiple, defined by cscfg_file_header.nr_features + +File is invalid if both [CONFIG_ELEM] and [FEATURE_ELEM] are omitted. + +A file that contains only [FEATURE_ELEM] may be loaded, and the features used +by subsequently loaded files with [CONFIG_ELEM] elements. + +Element Name Strings +~~~~~~~~~~~~~~~~~~~~ + +Configuration name strings are required to consist of alphanumeric characters and '_' only. Other special characters are not permitted. + +:: + my_config_2 // is a valid name. + this-bad-config#5 // this will not work + +This is in order to comply with the requirements of the perf command line. + +It is recommended that Feature and Parameter names use the same convention to allow for future enhancements to the command line syntax. + +CONFIG_ELEM element +~~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_elem_header] // header length value to end of feature strings. + [cscfg_file_elem_str] // name of the configuration. + // (see element string name requirements) + [cscfg_file_elem_str] // description of configuration. + [u16 value](nr_presets) // number of defined sets presets values. + [u32 value](nr_total_params) // total parameters defined by all used features. + [u16 value](nr_feat_refs) // number of features referenced by the configuration + [u64 values] * (nr_presets * nr_total_params) // the preset values. + [cscfg_file_elem_str] * (nr_feat_refs) // names of features used in the configurations. + +FEATURE_ELEM element +~~~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_elem_header] // header length is total bytes to end of param structures. + [cscfg_file_elem_str] // feature name. + [cscfg_file_elem_str] // feature description. + [u32 value](match_flags) // flags to associate the feature with a device. + [u16 value](nr_regs) // number of registers. + [u16 value](nr_params) // number of parameters. + [cscfg_regval_desc struct] * (nr_regs) // register definitions + [PARAM_ELEM] * (nr_params) // parameters definitions + +PARAM_ELEM element +~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_elem_str] // parameter name. + [u64 value](param_value) // initial value. + +Additional definitions. +~~~~~~~~~~~~~~~~~~~~~~~ + +The following structures are defined in **coresight-config-file.h** + + * **struct cscfg_file_header** : This structure contains an initial magic number, the total + length of the file, and the number of configurations and features in the file. + * **struct cscfg_file_elem_header**: This defines the total length and type of a CONFIG_ELEM + or a FEATURE_ELEM. + * **struct cscfg_file_elem_str**: This defines a string and its length. + +The magic number in cscfg_file_header is defined as two bitfields:: + + [31:8] Fixed magic number to identify file type. + [7:0] Current file format version. + +The following defines determine the maximum overall file size and maximum individual +string size:: + + CSCFG_FILE_MAXSIZE // maximum overall file size. + CSCFG_FILE_STR_MAXSIZE // maximum individual string size. + +Load Dependencies. +~~~~~~~~~~~~~~~~~~ + +Files may be unloaded only in the strict reverse order of loading. This is enforced by the +configuration system. + +This is to ensure that any load dependencies are maintained. + +A configuration file that contains a CONFIG_ELEM that references named features "feat_A" and "feat_B" will load only if either:- +a) "feat_A" and/or "feat_B" has been loaded previously, or are present as built-in / module loaded features. +b) "feat_A" and/or "feat_B" are declared as FEAT_ELEM in the same file as the CONFIG_ELEM. + +Files that contain features or configurations with the same names as those already loaded will fail to load.