2021-01-28 17:51:40

by Mike Leach

[permalink] [raw]
Subject: [PATCH v4 00/10] CoreSight configuration management; ETM strobing

This patchset introduces initial concepts in CoreSight system
configuration management support. to allow more detailed and complex
programming to be applied to CoreSight systems during trace capture.

Configurations consist of 2 elements:-
1) Features - programming combinations for devices, applied to a class of
device on the system (all ETMv4), or individual devices.
2) Configurations - a set of programmed features used when the named
configuration is selected.

Features and configurations are declared as a data table, a set of register,
resource and parameter requirements. Features and configurations are loaded
into the system by the virtual cs_syscfg device. This then matches features
to any registered devices and loads the feature into them.

Individual device classes that support feature and configuration register
with cs_syscfg.

Once loaded a configuration can be enabled for a specific trace run.
Configurations are registered with the perf cs_etm event as entries in
cs_etm/cs_config. These can be selected on the perf command line as follows:-

perf record -e cs_etm/<config_name>/ ...

This patch set has one pre-loaded configuration and feature.
A named "strobing" feature is provided for ETMv4.
A named "autofdo" configuration is provided. This configuration enables
strobing on any ETM in used.

Thus the command:
perf record -e cs_etm/autofdo/ ...

will trace the supplied application while enabling the "autofdo" configuation
on each ETM as it is enabled by perf. This in turn will enable strobing for
the ETM - with default parameters. Parameters can be adjusted using configfs.

The sink used in the trace run will be automatically selected.

A configuation can supply up to 15 of preset parameter values, which will
subsitute in parameter values for any feature used in the configuration.

Selection of preset values as follows
perf record -e cs_etm/autofdo,preset=1/ ...

(valid presets 1-N, where N is the number supplied in the configuration, not
exceeding 15. preset=0 is the same as not selecting a preset.)

Applies to coresight/next (5.11-rc2 base)

Changes since v3: (Primarily based on comments from Matthieu)
1) Locking mechanisms simplified.
2) Removed the possibility to enable features independently from
configurations.Only configurations can be enabled now. Simplifies programming
logic.
3) Configuration now uses an activate->enable mechanism. This means that perf
will activate a selected configuration at the start of a session (during
setup_aux), and disable at the end of a session (around free_aux)
The active configuration and associated features will be programmed into the
CoreSight device instances when they are enabled. This locks the configuration
into the system while in use. Parameters cannot be altered while this is
in place. This mechanism will be extended in future for dynamic load / unload
of configurations to prevent removal while in use.
4) Removed the custom bus / driver as un-necessary. A single device is
registered to own perf fs elements and configfs.
5) Various other minor issues addressed.

Changes since v2:
1) Added documentation file.
2) Altered cs_syscfg driver to no longer be coresight_device based, and moved
to its own custom bus to remove it from the main coresight bus. (Mathieu)
3) Added configfs support to inspect and control loaded configurations and
features. Allows listing of preset values (Yabin Cui)
4) Dropped sysfs support for adjusting feature parameters on the per device
basis, in favour of a single point adjustment in configfs that is pushed to all
device instances.
5) Altered how the config and preset command line options are handled in perf
and the drivers. (Mathieu and Suzuki).
6) Fixes for various issues and technical points (Mathieu, Yabin)

Changes since v1:
1) Moved preloaded configurations and features out of individual drivers.
2) Added cs_syscfg driver to manage configurations and features. Individual
drivers register with cs_syscfg indicating support for config, and provide
matching information that the system uses to load features into the drivers.
This allows individual drivers to be updated on an as needed basis - and
removes the need to consider devices that cannot benefit from configuration -
static replicators, funnels, tpiu.
3) Added perf selection of configuarations.
4) Rebased onto the coresight module loading set.


To follow in future revisions / sets:-
a) load of additional config and features by loadable module.
b) load of additional config and features by configfs
c) enhanced resource management for ETMv4 and checking features have sufficient
resources to be enabled.
d) ECT and CTI support for configuration and features.

Mike Leach (10):
coresight: syscfg: Initial coresight system configuration
coresight: syscfg: Add registration and feature loading for cs devices
coresight: config: Add configuration and feature generic functions
coresight: etm-perf: update to handle configuration selection
coresight: syscfg: Add API to activate and enable configurations
coresight: etm-perf: Update to activate selected configuration
coresight: etm4x: Add complex configuration handlers to etmv4
coresight: config: Add preloaded configurations
coresight: syscfg: Add initial configfs support
coresight: docs: Add documentation for CoreSight config

.../trace/coresight/coresight-config.rst | 244 ++++++
Documentation/trace/coresight/coresight.rst | 16 +
drivers/hwtracing/coresight/Makefile | 7 +-
.../hwtracing/coresight/coresight-cfg-afdo.c | 154 ++++
.../coresight/coresight-cfg-preload.c | 25 +
.../coresight/coresight-cfg-preload.h | 11 +
.../hwtracing/coresight/coresight-config.c | 246 ++++++
.../hwtracing/coresight/coresight-config.h | 282 +++++++
drivers/hwtracing/coresight/coresight-core.c | 18 +-
.../hwtracing/coresight/coresight-etm-perf.c | 180 ++++-
.../hwtracing/coresight/coresight-etm-perf.h | 12 +-
.../hwtracing/coresight/coresight-etm4x-cfg.c | 184 +++++
.../hwtracing/coresight/coresight-etm4x-cfg.h | 29 +
.../coresight/coresight-etm4x-core.c | 38 +-
.../coresight/coresight-etm4x-sysfs.c | 3 +
.../coresight/coresight-syscfg-configfs.c | 399 +++++++++
.../coresight/coresight-syscfg-configfs.h | 45 ++
.../hwtracing/coresight/coresight-syscfg.c | 761 ++++++++++++++++++
.../hwtracing/coresight/coresight-syscfg.h | 90 +++
include/linux/coresight.h | 7 +
20 files changed, 2721 insertions(+), 30 deletions(-)
create mode 100644 Documentation/trace/coresight/coresight-config.rst
create mode 100644 drivers/hwtracing/coresight/coresight-cfg-afdo.c
create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.c
create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.h
create mode 100644 drivers/hwtracing/coresight/coresight-config.c
create mode 100644 drivers/hwtracing/coresight/coresight-config.h
create mode 100644 drivers/hwtracing/coresight/coresight-etm4x-cfg.c
create mode 100644 drivers/hwtracing/coresight/coresight-etm4x-cfg.h
create mode 100644 drivers/hwtracing/coresight/coresight-syscfg-configfs.c
create mode 100644 drivers/hwtracing/coresight/coresight-syscfg-configfs.h
create mode 100644 drivers/hwtracing/coresight/coresight-syscfg.c
create mode 100644 drivers/hwtracing/coresight/coresight-syscfg.h

--
2.17.1


2021-01-28 17:51:41

by Mike Leach

[permalink] [raw]
Subject: [PATCH v4 08/10] coresight: config: Add preloaded configurations

Preload set of configurations.

This patch creates a small set of preloaded configurations and features
that are available immediately after coresight has been initialised.

The current set provides a strobing feature for ETMv4, that creates a
periodic sampling of trace by switching trace generation on and off
using counters in the ETM.

A configuration called "autofdo" is also provided that uses the 'strobing'
feature and provides a couple of preset values, selectable on the perf
command line.

Signed-off-by: Mike Leach <[email protected]>
---
drivers/hwtracing/coresight/Makefile | 3 +-
.../hwtracing/coresight/coresight-cfg-afdo.c | 154 ++++++++++++++++++
.../coresight/coresight-cfg-preload.c | 25 +++
.../coresight/coresight-cfg-preload.h | 11 ++
drivers/hwtracing/coresight/coresight-core.c | 6 +
.../hwtracing/coresight/coresight-syscfg.h | 1 +
6 files changed, 199 insertions(+), 1 deletion(-)
create mode 100644 drivers/hwtracing/coresight/coresight-cfg-afdo.c
create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.c
create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.h

diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index ea544206204d..2707bfef1b76 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -4,7 +4,8 @@
#
obj-$(CONFIG_CORESIGHT) += coresight.o
coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.o \
- coresight-sysfs.o coresight-syscfg.o coresight-config.o
+ coresight-sysfs.o coresight-syscfg.o coresight-config.o \
+ coresight-cfg-preload.o coresight-cfg-afdo.o
obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
coresight-tmc-etr.o
diff --git a/drivers/hwtracing/coresight/coresight-cfg-afdo.c b/drivers/hwtracing/coresight/coresight-cfg-afdo.c
new file mode 100644
index 000000000000..ff69fb3f4434
--- /dev/null
+++ b/drivers/hwtracing/coresight/coresight-cfg-afdo.c
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright(C) 2020 Linaro Limited. All rights reserved.
+ * Author: Mike Leach <[email protected]>
+ */
+
+#include "coresight-config.h"
+#include "coresight-etm4x-cfg.h"
+
+/* preload configurations and features */
+
+/* preload in features for ETMv4 */
+
+/* strobe feature */
+static struct cscfg_parameter_desc strobe_params[] = {
+ {
+ .name = "window",
+ .value = 5000,
+ },
+ {
+ .name = "period",
+ .value = 10000,
+ },
+};
+
+static struct cscfg_regval_desc strobe_regs[] = {
+ /* resource selectors */
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE,
+ .offset = TRCRSCTLRn(2),
+ .hw_info = ETM4_CFG_RES_SEL,
+ .val32 = 0x20001,
+ },
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE,
+ .offset = TRCRSCTLRn(3),
+ .hw_info = ETM4_CFG_RES_SEQ,
+ .val32 = 0x20002,
+ },
+ /* strobe window counter 0 - reload from param 0 */
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_SAVE,
+ .offset = TRCCNTVRn(0),
+ .hw_info = ETM4_CFG_RES_CTR,
+ },
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_PARAM,
+ .offset = TRCCNTRLDVRn(0),
+ .hw_info = ETM4_CFG_RES_CTR,
+ .val32 = 0,
+ },
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE,
+ .offset = TRCCNTCTLRn(0),
+ .hw_info = ETM4_CFG_RES_CTR,
+ .val32 = 0x10001,
+ },
+ /* strobe period counter 1 - reload from param 1 */
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_SAVE,
+ .offset = TRCCNTVRn(1),
+ .hw_info = ETM4_CFG_RES_CTR,
+ },
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_PARAM,
+ .offset = TRCCNTRLDVRn(1),
+ .hw_info = ETM4_CFG_RES_CTR,
+ .val32 = 1,
+ },
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE,
+ .offset = TRCCNTCTLRn(1),
+ .hw_info = ETM4_CFG_RES_CTR,
+ .val32 = 0x8102,
+ },
+ /* sequencer */
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE,
+ .offset = TRCSEQEVRn(0),
+ .hw_info = ETM4_CFG_RES_SEQ,
+ .val32 = 0x0081,
+ },
+ {
+ .type = CS_CFG_REG_TYPE_RESOURCE,
+ .offset = TRCSEQEVRn(1),
+ .hw_info = ETM4_CFG_RES_SEQ,
+ .val32 = 0x0000,
+ },
+ /* view-inst */
+ {
+ .type = CS_CFG_REG_TYPE_STD | CS_CFG_REG_TYPE_VAL_MASK,
+ .offset = TRCVICTLR,
+ .val32 = 0x0003,
+ .mask32 = 0x0003,
+ },
+ /* end of regs */
+};
+
+struct cscfg_feature_desc strobe = {
+ .name = "strobing",
+ .brief = "Generate periodic trace capture windows.\n"
+ "parameter \'window\': a number of CPU cycles (W)\n"
+ "parameter \'period\': trace enabled for W cycles every period x W cycles\n",
+ .match_flags = CS_CFG_MATCH_CLASS_SRC_ETM4,
+ .nr_params = ARRAY_SIZE(strobe_params),
+ .params = strobe_params,
+ .nr_regs = ARRAY_SIZE(strobe_regs),
+ .regs = strobe_regs,
+};
+
+/* create an autofdo configuration */
+
+/* we will provide 9 sets of preset parameter values */
+#define AFDO_NR_PRESETS 9
+/* the total number of parameters in used features */
+#define AFDO_NR_PARAM_SUM ARRAY_SIZE(strobe_params)
+
+#define AFDO_MATCH_STROBING (CS_CFG_MATCH_INST_ANY | CS_CFG_MATCH_CLASS_SRC_ETM4)
+
+static struct cscfg_config_feat_ref afdo_refs[] = {
+ {
+ .name = "strobing",
+ .match = {
+ .match_flags = AFDO_MATCH_STROBING,
+ },
+ },
+};
+
+/*
+ * set of presets leaves strobing window constant while varying period to allow
+ * experimentation with mark / space ratios for various workloads
+ */
+static u64 afdo_presets[AFDO_NR_PRESETS][AFDO_NR_PARAM_SUM] = {
+ { 5000, 2 },
+ { 5000, 4 },
+ { 5000, 8 },
+ { 5000, 16 },
+ { 5000, 64 },
+ { 5000, 128 },
+ { 5000, 512 },
+ { 5000, 1024 },
+ { 5000, 4096 },
+};
+
+struct cscfg_config_desc afdo = {
+ .name = "autofdo",
+ .brief = "Setup ETMs with strobing for autofdo\n"
+ "Supplied presets allow experimentation with mark-space ratio for various loads\n",
+ .nr_refs = ARRAY_SIZE(afdo_refs),
+ .refs = afdo_refs,
+ .nr_presets = AFDO_NR_PRESETS,
+ .nr_total_params = AFDO_NR_PARAM_SUM,
+ .presets = &afdo_presets[0][0],
+};
diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.c b/drivers/hwtracing/coresight/coresight-cfg-preload.c
new file mode 100644
index 000000000000..c7ec5cbdd990
--- /dev/null
+++ b/drivers/hwtracing/coresight/coresight-cfg-preload.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright(C) 2020 Linaro Limited. All rights reserved.
+ * Author: Mike Leach <[email protected]>
+ */
+
+#include "coresight-cfg-preload.h"
+#include "coresight-config.h"
+#include "coresight-syscfg.h"
+
+static struct cscfg_feature_desc *preload_feats[] = {
+ &strobe,
+ 0
+};
+
+static struct cscfg_config_desc *preload_cfgs[] = {
+ &afdo,
+ 0
+};
+
+/* preload called with mutex locked */
+int cscfg_preload(void)
+{
+ return cscfg_load_config_sets(preload_cfgs, preload_feats);
+}
diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.h b/drivers/hwtracing/coresight/coresight-cfg-preload.h
new file mode 100644
index 000000000000..fc4ac7faa93d
--- /dev/null
+++ b/drivers/hwtracing/coresight/coresight-cfg-preload.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright(C) 2020 Linaro Limited. All rights reserved.
+ * Author: Mike Leach <[email protected]>
+ */
+
+/* declare preloaded configurations and features */
+
+/* from coresight-cfg-afdo.c */
+extern struct cscfg_feature_desc strobe;
+extern struct cscfg_config_desc afdo;
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index 6bd41de46648..633ddcffc6c7 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1744,9 +1744,15 @@ static int __init coresight_init(void)

/* initialise the coresight syscfg API */
ret = cscfg_init();
+ if (ret)
+ goto exit_perf_close;
+
+ /* preload builtin configurations */
+ ret = cscfg_preload();
if (!ret)
return 0;

+exit_perf_close:
etm_perf_exit();
exit_bus_unregister:
bus_unregister(&coresight_bustype);
diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h
index 301e26e1e98f..a8a6b21315d8 100644
--- a/drivers/hwtracing/coresight/coresight-syscfg.h
+++ b/drivers/hwtracing/coresight/coresight-syscfg.h
@@ -47,6 +47,7 @@ struct cscfg_csdev_register {
/* internal core operations for cscfg */
int __init cscfg_init(void);
void __exit cscfg_exit(void);
+int cscfg_preload(void);

/* syscfg manager external API */
int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs,
--
2.17.1

2021-03-01 01:19:27

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH v4 08/10] coresight: config: Add preloaded configurations

On Thu, Jan 28, 2021 at 05:09:34PM +0000, Mike Leach wrote:
> Preload set of configurations.
>
> This patch creates a small set of preloaded configurations and features
> that are available immediately after coresight has been initialised.
>
> The current set provides a strobing feature for ETMv4, that creates a
> periodic sampling of trace by switching trace generation on and off
> using counters in the ETM.
>
> A configuration called "autofdo" is also provided that uses the 'strobing'
> feature and provides a couple of preset values, selectable on the perf
> command line.
>
> Signed-off-by: Mike Leach <[email protected]>
> ---
> drivers/hwtracing/coresight/Makefile | 3 +-
> .../hwtracing/coresight/coresight-cfg-afdo.c | 154 ++++++++++++++++++
> .../coresight/coresight-cfg-preload.c | 25 +++
> .../coresight/coresight-cfg-preload.h | 11 ++
> drivers/hwtracing/coresight/coresight-core.c | 6 +
> .../hwtracing/coresight/coresight-syscfg.h | 1 +
> 6 files changed, 199 insertions(+), 1 deletion(-)
> create mode 100644 drivers/hwtracing/coresight/coresight-cfg-afdo.c
> create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.c
> create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.h
>
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index ea544206204d..2707bfef1b76 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -4,7 +4,8 @@
> #
> obj-$(CONFIG_CORESIGHT) += coresight.o
> coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.o \
> - coresight-sysfs.o coresight-syscfg.o coresight-config.o
> + coresight-sysfs.o coresight-syscfg.o coresight-config.o \
> + coresight-cfg-preload.o coresight-cfg-afdo.o
> obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
> coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
> coresight-tmc-etr.o
> diff --git a/drivers/hwtracing/coresight/coresight-cfg-afdo.c b/drivers/hwtracing/coresight/coresight-cfg-afdo.c
> new file mode 100644
> index 000000000000..ff69fb3f4434
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-cfg-afdo.c
> @@ -0,0 +1,154 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright(C) 2020 Linaro Limited. All rights reserved.
> + * Author: Mike Leach <[email protected]>
> + */
> +
> +#include "coresight-config.h"
> +#include "coresight-etm4x-cfg.h"
> +
> +/* preload configurations and features */
> +
> +/* preload in features for ETMv4 */
> +
> +/* strobe feature */
> +static struct cscfg_parameter_desc strobe_params[] = {
> + {
> + .name = "window",
> + .value = 5000,
> + },
> + {
> + .name = "period",
> + .value = 10000,
> + },
> +};
> +
> +static struct cscfg_regval_desc strobe_regs[] = {
> + /* resource selectors */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCRSCTLRn(2),
> + .hw_info = ETM4_CFG_RES_SEL,
> + .val32 = 0x20001,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCRSCTLRn(3),
> + .hw_info = ETM4_CFG_RES_SEQ,
> + .val32 = 0x20002,
> + },
> + /* strobe window counter 0 - reload from param 0 */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_SAVE,
> + .offset = TRCCNTVRn(0),
> + .hw_info = ETM4_CFG_RES_CTR,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_PARAM,
> + .offset = TRCCNTRLDVRn(0),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 0,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCCNTCTLRn(0),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 0x10001,
> + },
> + /* strobe period counter 1 - reload from param 1 */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_SAVE,
> + .offset = TRCCNTVRn(1),
> + .hw_info = ETM4_CFG_RES_CTR,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_PARAM,
> + .offset = TRCCNTRLDVRn(1),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 1,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCCNTCTLRn(1),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 0x8102,
> + },
> + /* sequencer */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCSEQEVRn(0),
> + .hw_info = ETM4_CFG_RES_SEQ,
> + .val32 = 0x0081,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCSEQEVRn(1),
> + .hw_info = ETM4_CFG_RES_SEQ,
> + .val32 = 0x0000,
> + },
> + /* view-inst */
> + {
> + .type = CS_CFG_REG_TYPE_STD | CS_CFG_REG_TYPE_VAL_MASK,
> + .offset = TRCVICTLR,
> + .val32 = 0x0003,
> + .mask32 = 0x0003,
> + },
> + /* end of regs */
> +};
> +
> +struct cscfg_feature_desc strobe = {
> + .name = "strobing",
> + .brief = "Generate periodic trace capture windows.\n"
> + "parameter \'window\': a number of CPU cycles (W)\n"
> + "parameter \'period\': trace enabled for W cycles every period x W cycles\n",
> + .match_flags = CS_CFG_MATCH_CLASS_SRC_ETM4,
> + .nr_params = ARRAY_SIZE(strobe_params),
> + .params = strobe_params,
> + .nr_regs = ARRAY_SIZE(strobe_regs),
> + .regs = strobe_regs,
> +};
> +
> +/* create an autofdo configuration */
> +
> +/* we will provide 9 sets of preset parameter values */
> +#define AFDO_NR_PRESETS 9
> +/* the total number of parameters in used features */
> +#define AFDO_NR_PARAM_SUM ARRAY_SIZE(strobe_params)
> +
> +#define AFDO_MATCH_STROBING (CS_CFG_MATCH_INST_ANY | CS_CFG_MATCH_CLASS_SRC_ETM4)
> +
> +static struct cscfg_config_feat_ref afdo_refs[] = {
> + {
> + .name = "strobing",
> + .match = {
> + .match_flags = AFDO_MATCH_STROBING,
> + },
> + },
> +};
> +
> +/*
> + * set of presets leaves strobing window constant while varying period to allow
> + * experimentation with mark / space ratios for various workloads
> + */
> +static u64 afdo_presets[AFDO_NR_PRESETS][AFDO_NR_PARAM_SUM] = {
> + { 5000, 2 },
> + { 5000, 4 },
> + { 5000, 8 },
> + { 5000, 16 },
> + { 5000, 64 },
> + { 5000, 128 },
> + { 5000, 512 },
> + { 5000, 1024 },
> + { 5000, 4096 },
> +};
> +
> +struct cscfg_config_desc afdo = {
> + .name = "autofdo",
> + .brief = "Setup ETMs with strobing for autofdo\n"
> + "Supplied presets allow experimentation with mark-space ratio for various loads\n",
> + .nr_refs = ARRAY_SIZE(afdo_refs),
> + .refs = afdo_refs,
> + .nr_presets = AFDO_NR_PRESETS,
> + .nr_total_params = AFDO_NR_PARAM_SUM,
> + .presets = &afdo_presets[0][0],
> +};
> diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.c b/drivers/hwtracing/coresight/coresight-cfg-preload.c
> new file mode 100644
> index 000000000000..c7ec5cbdd990
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-cfg-preload.c
> @@ -0,0 +1,25 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright(C) 2020 Linaro Limited. All rights reserved.
> + * Author: Mike Leach <[email protected]>
> + */
> +
> +#include "coresight-cfg-preload.h"
> +#include "coresight-config.h"
> +#include "coresight-syscfg.h"
> +
> +static struct cscfg_feature_desc *preload_feats[] = {
> + &strobe,
> + 0
> +};
> +
> +static struct cscfg_config_desc *preload_cfgs[] = {
> + &afdo,
> + 0
> +};
> +

Perfect - thanks for making the change.

Mathieu

> +/* preload called with mutex locked */
> +int cscfg_preload(void)
> +{
> + return cscfg_load_config_sets(preload_cfgs, preload_feats);
> +}
> diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.h b/drivers/hwtracing/coresight/coresight-cfg-preload.h
> new file mode 100644
> index 000000000000..fc4ac7faa93d
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-cfg-preload.h
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright(C) 2020 Linaro Limited. All rights reserved.
> + * Author: Mike Leach <[email protected]>
> + */
> +
> +/* declare preloaded configurations and features */
> +
> +/* from coresight-cfg-afdo.c */
> +extern struct cscfg_feature_desc strobe;
> +extern struct cscfg_config_desc afdo;
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index 6bd41de46648..633ddcffc6c7 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1744,9 +1744,15 @@ static int __init coresight_init(void)
>
> /* initialise the coresight syscfg API */
> ret = cscfg_init();
> + if (ret)
> + goto exit_perf_close;
> +
> + /* preload builtin configurations */
> + ret = cscfg_preload();
> if (!ret)
> return 0;
>
> +exit_perf_close:
> etm_perf_exit();
> exit_bus_unregister:
> bus_unregister(&coresight_bustype);
> diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h
> index 301e26e1e98f..a8a6b21315d8 100644
> --- a/drivers/hwtracing/coresight/coresight-syscfg.h
> +++ b/drivers/hwtracing/coresight/coresight-syscfg.h
> @@ -47,6 +47,7 @@ struct cscfg_csdev_register {
> /* internal core operations for cscfg */
> int __init cscfg_init(void);
> void __exit cscfg_exit(void);
> +int cscfg_preload(void);
>
> /* syscfg manager external API */
> int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs,
> --
> 2.17.1
>

2021-03-05 13:42:54

by Suzuki K Poulose

[permalink] [raw]
Subject: Re: [PATCH v4 08/10] coresight: config: Add preloaded configurations

On 1/28/21 5:09 PM, Mike Leach wrote:
> Preload set of configurations.
>
> This patch creates a small set of preloaded configurations and features
> that are available immediately after coresight has been initialised.
>
> The current set provides a strobing feature for ETMv4, that creates a
> periodic sampling of trace by switching trace generation on and off
> using counters in the ETM.
>
> A configuration called "autofdo" is also provided that uses the 'strobing'
> feature and provides a couple of preset values, selectable on the perf
> command line.
>
> Signed-off-by: Mike Leach <[email protected]>
> ---
> drivers/hwtracing/coresight/Makefile | 3 +-
> .../hwtracing/coresight/coresight-cfg-afdo.c | 154 ++++++++++++++++++
> .../coresight/coresight-cfg-preload.c | 25 +++
> .../coresight/coresight-cfg-preload.h | 11 ++
> drivers/hwtracing/coresight/coresight-core.c | 6 +
> .../hwtracing/coresight/coresight-syscfg.h | 1 +
> 6 files changed, 199 insertions(+), 1 deletion(-)
> create mode 100644 drivers/hwtracing/coresight/coresight-cfg-afdo.c
> create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.c
> create mode 100644 drivers/hwtracing/coresight/coresight-cfg-preload.h
>
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index ea544206204d..2707bfef1b76 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -4,7 +4,8 @@
> #
> obj-$(CONFIG_CORESIGHT) += coresight.o
> coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.o \
> - coresight-sysfs.o coresight-syscfg.o coresight-config.o
> + coresight-sysfs.o coresight-syscfg.o coresight-config.o \
> + coresight-cfg-preload.o coresight-cfg-afdo.o
> obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
> coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
> coresight-tmc-etr.o
> diff --git a/drivers/hwtracing/coresight/coresight-cfg-afdo.c b/drivers/hwtracing/coresight/coresight-cfg-afdo.c
> new file mode 100644
> index 000000000000..ff69fb3f4434
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-cfg-afdo.c
> @@ -0,0 +1,154 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright(C) 2020 Linaro Limited. All rights reserved.
> + * Author: Mike Leach <[email protected]>
> + */
> +
> +#include "coresight-config.h"
> +#include "coresight-etm4x-cfg.h"
> +
> +/* preload configurations and features */
> +
> +/* preload in features for ETMv4 */
> +
> +/* strobe feature */
> +static struct cscfg_parameter_desc strobe_params[] = {
> + {
> + .name = "window",
> + .value = 5000,
> + },
> + {
> + .name = "period",
> + .value = 10000,
> + },
> +};
> +
> +static struct cscfg_regval_desc strobe_regs[] = {
> + /* resource selectors */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCRSCTLRn(2),
> + .hw_info = ETM4_CFG_RES_SEL,
> + .val32 = 0x20001,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCRSCTLRn(3),
> + .hw_info = ETM4_CFG_RES_SEQ,
> + .val32 = 0x20002,
> + },
> + /* strobe window counter 0 - reload from param 0 */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_SAVE,
> + .offset = TRCCNTVRn(0),
> + .hw_info = ETM4_CFG_RES_CTR,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_PARAM,
> + .offset = TRCCNTRLDVRn(0),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 0,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCCNTCTLRn(0),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 0x10001,
> + },
> + /* strobe period counter 1 - reload from param 1 */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_SAVE,
> + .offset = TRCCNTVRn(1),
> + .hw_info = ETM4_CFG_RES_CTR,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE | CS_CFG_REG_TYPE_VAL_PARAM,
> + .offset = TRCCNTRLDVRn(1),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 1,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCCNTCTLRn(1),
> + .hw_info = ETM4_CFG_RES_CTR,
> + .val32 = 0x8102,
> + },
> + /* sequencer */
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCSEQEVRn(0),
> + .hw_info = ETM4_CFG_RES_SEQ,
> + .val32 = 0x0081,
> + },
> + {
> + .type = CS_CFG_REG_TYPE_RESOURCE,
> + .offset = TRCSEQEVRn(1),
> + .hw_info = ETM4_CFG_RES_SEQ,
> + .val32 = 0x0000,
> + },
> + /* view-inst */
> + {
> + .type = CS_CFG_REG_TYPE_STD | CS_CFG_REG_TYPE_VAL_MASK,
> + .offset = TRCVICTLR,
> + .val32 = 0x0003,
> + .mask32 = 0x0003,
> + },
> + /* end of regs */
> +};
> +
> +struct cscfg_feature_desc strobe = {
> + .name = "strobing",
> + .brief = "Generate periodic trace capture windows.\n"
> + "parameter \'window\': a number of CPU cycles (W)\n"
> + "parameter \'period\': trace enabled for W cycles every period x W cycles\n",

nit: Could we align the string as below:

.brief = "Generate periodic trace capture windows.\n"
"parameter \'window\': a number of CPU cycles (W)\n"
"parameter \'period\': trace enabled for W cycles every period x W cycles\n",

> + .match_flags = CS_CFG_MATCH_CLASS_SRC_ETM4,
> + .nr_params = ARRAY_SIZE(strobe_params),
> + .params = strobe_params,
> + .nr_regs = ARRAY_SIZE(strobe_regs),
> + .regs = strobe_regs,
> +};
> +
> +/* create an autofdo configuration */
> +
> +/* we will provide 9 sets of preset parameter values */
> +#define AFDO_NR_PRESETS 9
> +/* the total number of parameters in used features */
> +#define AFDO_NR_PARAM_SUM ARRAY_SIZE(strobe_params)

nit: alignment consistency. i.e 1 TAB vs 2 TABs (with AFDO_NR_PRESETS)

minor nit : s/AFDO_NR_PARAM_SUM/AFDO_NR_TOTAL_PARAMS ? or even AFDO_NR_PARAMS

> +
> +#define AFDO_MATCH_STROBING (CS_CFG_MATCH_INST_ANY | CS_CFG_MATCH_CLASS_SRC_ETM4)
> +
> +static struct cscfg_config_feat_ref afdo_refs[] = {
> + {
> + .name = "strobing",
> + .match = {
> + .match_flags = AFDO_MATCH_STROBING,
> + },
> + },
> +};
> +
> +/*
> + * set of presets leaves strobing window constant while varying period to allow
> + * experimentation with mark / space ratios for various workloads
> + */
> +static u64 afdo_presets[AFDO_NR_PRESETS][AFDO_NR_PARAM_SUM] = {
> + { 5000, 2 },
> + { 5000, 4 },
> + { 5000, 8 },
> + { 5000, 16 },
> + { 5000, 64 },
> + { 5000, 128 },
> + { 5000, 512 },
> + { 5000, 1024 },
> + { 5000, 4096 },
> +};
> +
> +struct cscfg_config_desc afdo = {
> + .name = "autofdo",
> + .brief = "Setup ETMs with strobing for autofdo\n"
> + "Supplied presets allow experimentation with mark-space ratio for various loads\n",

Same alignment comments as above

> + .nr_refs = ARRAY_SIZE(afdo_refs),
> + .refs = afdo_refs,
> + .nr_presets = AFDO_NR_PRESETS,
> + .nr_total_params = AFDO_NR_PARAM_SUM,
> + .presets = &afdo_presets[0][0],
> +};
> diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.c b/drivers/hwtracing/coresight/coresight-cfg-preload.c
> new file mode 100644
> index 000000000000..c7ec5cbdd990
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-cfg-preload.c
> @@ -0,0 +1,25 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright(C) 2020 Linaro Limited. All rights reserved.
> + * Author: Mike Leach <[email protected]>

One line on the brief of the files purpose is helpful.

> + */
> +
> +#include "coresight-cfg-preload.h"
> +#include "coresight-config.h"
> +#include "coresight-syscfg.h"
> +
> +static struct cscfg_feature_desc *preload_feats[] = {
> + &strobe,
> + 0
> +};
> +
> +static struct cscfg_config_desc *preload_cfgs[] = {
> + &afdo,
> + 0
> +};
> +
> +/* preload called with mutex locked */
> +int cscfg_preload(void)
> +{
> + return cscfg_load_config_sets(preload_cfgs, preload_feats);
> +}
> diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.h b/drivers/hwtracing/coresight/coresight-cfg-preload.h
> new file mode 100644
> index 000000000000..fc4ac7faa93d
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-cfg-preload.h
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright(C) 2020 Linaro Limited. All rights reserved.
> + * Author: Mike Leach <[email protected]>
> + */
> +
> +/* declare preloaded configurations and features */
> +
> +/* from coresight-cfg-afdo.c */
> +extern struct cscfg_feature_desc strobe;
> +extern struct cscfg_config_desc afdo;
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index 6bd41de46648..633ddcffc6c7 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1744,9 +1744,15 @@ static int __init coresight_init(void)
>
> /* initialise the coresight syscfg API */
> ret = cscfg_init();
> + if (ret)
> + goto exit_perf_close;
> +
> + /* preload builtin configurations */
> + ret = cscfg_preload();
> if (!ret)
> return 0;

Could this be folded into cscfg_init() ?

Otherwise looks fine to me

Suzuki