linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] coresight: Patches for v5.12 (part 2)
@ 2021-02-10 16:36 Mathieu Poirier
  2021-02-10 16:36 ` [PATCH 1/2] coresight: etm-perf: Support PID tracing for kernel at EL2 Mathieu Poirier
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mathieu Poirier @ 2021-02-10 16:36 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, linux-arm-kernel

Hi Greg,

Please see if you can add these 2 patches to your 5.12 tally.  No worries
if you think it is too close to the merge window, I'll simply queue them
for the next one.

Thanks,
Mathieu

Leo Yan (1):
  Documentation: coresight: Add PID tracing description

Suzuki K Poulose (1):
  coresight: etm-perf: Support PID tracing for kernel at EL2

 Documentation/trace/coresight/coresight.rst   | 32 +++++++++++++++++++
 .../hwtracing/coresight/coresight-etm-perf.c  | 27 +++++++++++++++-
 .../coresight/coresight-etm4x-core.c          | 13 ++++++++
 include/linux/coresight-pmu.h                 |  3 ++
 4 files changed, 74 insertions(+), 1 deletion(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] coresight: etm-perf: Support PID tracing for kernel at EL2
  2021-02-10 16:36 [PATCH 0/2] coresight: Patches for v5.12 (part 2) Mathieu Poirier
@ 2021-02-10 16:36 ` Mathieu Poirier
  2021-02-10 16:36 ` [PATCH 2/2] Documentation: coresight: Add PID tracing description Mathieu Poirier
  2021-02-10 17:10 ` [PATCH 0/2] coresight: Patches for v5.12 (part 2) Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Mathieu Poirier @ 2021-02-10 16:36 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, linux-arm-kernel

From: Suzuki K Poulose <suzuki.poulose@arm.com>

When the kernel is running at EL2, the PID is stored in CONTEXTIDR_EL2.
So, tracing CONTEXTIDR_EL1 doesn't give us the pid of the process.
Thus we should trace the VMID with VMIDOPT set to trace CONTEXTIDR_EL2
instead of CONTEXTIDR_EL1.  Given that we have an existing config
option "contextid" and this will be useful for tracing virtual machines
(when we get to support virtualization).

So instead, this patch extends option CTXTID with an extra bit
ETM_OPT_CTXTID2 (bit 15), thus on an EL2 kernel, we will have another
bit available for the perf tool: ETM_OPT_CTXTID is for kernel running in
EL1, ETM_OPT_CTXTID2 is used when kernel runs in EL2 with VHE enabled.

The tool must be backward compatible for users, i.e, "contextid" today
traces PID and that should remain the same; for this purpose, the perf
tool is updated to automatically set corresponding bit for the
"contextid" config, therefore, the user doesn't have to bother which EL
the kernel is running.

  i.e, perf record -e cs_etm/contextid/u --

will always do the "pid" tracing, independent of the kernel EL.

The driver parses the format "contextid", which traces CONTEXTIDR_EL1
for ETM_OPT_CTXTID (on EL1 kernel) and traces CONTEXTIDR_EL2 for
ETM_OPT_CTXTID2 (on EL2 kernel).

Besides the enhancement for format "contexid", extra two formats are
introduced: "contextid1" and "contextid2".  This considers to support
tracing both CONTEXTIDR_EL1 and CONTEXTIDR_EL2 when the kernel is
running at EL2.  Finally, the PMU formats are defined as follow:

  "contextid1": Available on both EL1 kernel and EL2 kernel.  When the
                kernel is running at EL1, "contextid1" enables the PID
		tracing; when the kernel is running at EL2, this enables
		tracing the PID of guest applications.

  "contextid2": Only usable when the kernel is running at EL2.  When
                selected, enables PID tracing on EL2 kernel.

  "contextid":  Will be an alias for the option that enables PID
                tracing.  I.e,
                contextid == contextid1, on EL1 kernel.
                contextid == contextid2, on EL2 kernel.

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Al Grant <al.grant@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
[ Added two config formats: contextid1, contextid2 ]
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Message-Id: <20210206150833.42120-4-leo.yan@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 .../hwtracing/coresight/coresight-etm-perf.c  | 27 ++++++++++++++++++-
 .../coresight/coresight-etm4x-core.c          | 13 +++++++++
 include/linux/coresight-pmu.h                 |  3 +++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 465ef1aa8c82..0f603b4094f2 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -32,15 +32,40 @@ static DEFINE_PER_CPU(struct coresight_device *, csdev_src);
  * now take them as general formats and apply on all ETMs.
  */
 PMU_FORMAT_ATTR(cycacc,		"config:" __stringify(ETM_OPT_CYCACC));
-PMU_FORMAT_ATTR(contextid,	"config:" __stringify(ETM_OPT_CTXTID));
+/* contextid1 enables tracing CONTEXTIDR_EL1 for ETMv4 */
+PMU_FORMAT_ATTR(contextid1,	"config:" __stringify(ETM_OPT_CTXTID));
+/* contextid2 enables tracing CONTEXTIDR_EL2 for ETMv4 */
+PMU_FORMAT_ATTR(contextid2,	"config:" __stringify(ETM_OPT_CTXTID2));
 PMU_FORMAT_ATTR(timestamp,	"config:" __stringify(ETM_OPT_TS));
 PMU_FORMAT_ATTR(retstack,	"config:" __stringify(ETM_OPT_RETSTK));
 /* Sink ID - same for all ETMs */
 PMU_FORMAT_ATTR(sinkid,		"config2:0-31");
 
+/*
+ * contextid always traces the "PID".  The PID is in CONTEXTIDR_EL1
+ * when the kernel is running at EL1; when the kernel is at EL2,
+ * the PID is in CONTEXTIDR_EL2.
+ */
+static ssize_t format_attr_contextid_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *page)
+{
+	int pid_fmt = ETM_OPT_CTXTID;
+
+#if defined(CONFIG_CORESIGHT_SOURCE_ETM4X)
+	pid_fmt = is_kernel_in_hyp_mode() ? ETM_OPT_CTXTID2 : ETM_OPT_CTXTID;
+#endif
+	return sprintf(page, "config:%d\n", pid_fmt);
+}
+
+struct device_attribute format_attr_contextid =
+	__ATTR(contextid, 0444, format_attr_contextid_show, NULL);
+
 static struct attribute *etm_config_formats_attr[] = {
 	&format_attr_cycacc.attr,
 	&format_attr_contextid.attr,
+	&format_attr_contextid1.attr,
+	&format_attr_contextid2.attr,
 	&format_attr_timestamp.attr,
 	&format_attr_retstack.attr,
 	&format_attr_sinkid.attr,
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
index 5017d33ba4f5..bb1ec5f28ff6 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -550,6 +550,19 @@ static int etm4_parse_event_config(struct etmv4_drvdata *drvdata,
 		/* bit[6], Context ID tracing bit */
 		config->cfg |= BIT(ETM4_CFG_BIT_CTXTID);
 
+	/*
+	 * If set bit ETM_OPT_CTXTID2 in perf config, this asks to trace VMID
+	 * for recording CONTEXTIDR_EL2.  Do not enable VMID tracing if the
+	 * kernel is not running in EL2.
+	 */
+	if (attr->config & BIT(ETM_OPT_CTXTID2)) {
+		if (!is_kernel_in_hyp_mode()) {
+			ret = -EINVAL;
+			goto out;
+		}
+		config->cfg |= BIT(ETM4_CFG_BIT_VMID) | BIT(ETM4_CFG_BIT_VMID_OPT);
+	}
+
 	/* return stack - enable if selected and supported */
 	if ((attr->config & BIT(ETM_OPT_RETSTK)) && drvdata->retstack)
 		/* bit[12], Return stack enable bit */
diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h
index 5dc47cfdcf07..4ac5c081af93 100644
--- a/include/linux/coresight-pmu.h
+++ b/include/linux/coresight-pmu.h
@@ -20,14 +20,17 @@
  */
 #define ETM_OPT_CYCACC		12
 #define ETM_OPT_CTXTID		14
+#define ETM_OPT_CTXTID2		15
 #define ETM_OPT_TS		28
 #define ETM_OPT_RETSTK		29
 
 /* ETMv4 CONFIGR programming bits for the ETM OPTs */
 #define ETM4_CFG_BIT_CYCACC	4
 #define ETM4_CFG_BIT_CTXTID	6
+#define ETM4_CFG_BIT_VMID	7
 #define ETM4_CFG_BIT_TS		11
 #define ETM4_CFG_BIT_RETSTK	12
+#define ETM4_CFG_BIT_VMID_OPT	15
 
 static inline int coresight_get_trace_id(int cpu)
 {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Documentation: coresight: Add PID tracing description
  2021-02-10 16:36 [PATCH 0/2] coresight: Patches for v5.12 (part 2) Mathieu Poirier
  2021-02-10 16:36 ` [PATCH 1/2] coresight: etm-perf: Support PID tracing for kernel at EL2 Mathieu Poirier
@ 2021-02-10 16:36 ` Mathieu Poirier
  2021-02-10 17:10 ` [PATCH 0/2] coresight: Patches for v5.12 (part 2) Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Mathieu Poirier @ 2021-02-10 16:36 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, linux-arm-kernel

From: Leo Yan <leo.yan@linaro.org>

After support the PID tracing for the kernel in EL1 or EL2, the usage
gets more complicated.

This patch gives description for the PMU formats of contextID configs,
this can help users to understand how to control the knobs for PID
tracing when the kernel is in different ELs.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Message-Id: <20210206150833.42120-9-leo.yan@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 Documentation/trace/coresight/coresight.rst | 32 +++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/Documentation/trace/coresight/coresight.rst b/Documentation/trace/coresight/coresight.rst
index 0b73acb44efa..169749efd8d1 100644
--- a/Documentation/trace/coresight/coresight.rst
+++ b/Documentation/trace/coresight/coresight.rst
@@ -512,6 +512,38 @@ The --itrace option controls the type and frequency of synthesized events
 Note that only 64-bit programs are currently supported - further work is
 required to support instruction decode of 32-bit Arm programs.
 
+2.2) Tracing PID
+
+The kernel can be built to write the PID value into the PE ContextID registers.
+For a kernel running at EL1, the PID is stored in CONTEXTIDR_EL1.  A PE may
+implement Arm Virtualization Host Extensions (VHE), which the kernel can
+run at EL2 as a virtualisation host; in this case, the PID value is stored in
+CONTEXTIDR_EL2.
+
+perf provides PMU formats that program the ETM to insert these values into the
+trace data; the PMU formats are defined as below:
+
+  "contextid1": Available on both EL1 kernel and EL2 kernel.  When the
+                kernel is running at EL1, "contextid1" enables the PID
+                tracing; when the kernel is running at EL2, this enables
+                tracing the PID of guest applications.
+
+  "contextid2": Only usable when the kernel is running at EL2.  When
+                selected, enables PID tracing on EL2 kernel.
+
+  "contextid":  Will be an alias for the option that enables PID
+                tracing.  I.e,
+                contextid == contextid1, on EL1 kernel.
+                contextid == contextid2, on EL2 kernel.
+
+perf will always enable PID tracing at the relevant EL, this is accomplished by
+automatically enable the "contextid" config - but for EL2 it is possible to make
+specific adjustments using configs "contextid1" and "contextid2", E.g. if a user
+wants to trace PIDs for both host and guest, the two configs "contextid1" and
+"contextid2" can be set at the same time:
+
+  perf record -e cs_etm/contextid1,contextid2/u -- vm
+
 
 Generating coverage files for Feedback Directed Optimization: AutoFDO
 ---------------------------------------------------------------------
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] coresight: Patches for v5.12 (part 2)
  2021-02-10 16:36 [PATCH 0/2] coresight: Patches for v5.12 (part 2) Mathieu Poirier
  2021-02-10 16:36 ` [PATCH 1/2] coresight: etm-perf: Support PID tracing for kernel at EL2 Mathieu Poirier
  2021-02-10 16:36 ` [PATCH 2/2] Documentation: coresight: Add PID tracing description Mathieu Poirier
@ 2021-02-10 17:10 ` Greg KH
  2021-02-10 17:11   ` Greg KH
  2 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2021-02-10 17:10 UTC (permalink / raw)
  To: Mathieu Poirier; +Cc: linux-kernel, linux-arm-kernel

On Wed, Feb 10, 2021 at 09:36:08AM -0700, Mathieu Poirier wrote:
> Hi Greg,
> 
> Please see if you can add these 2 patches to your 5.12 tally.  No worries
> if you think it is too close to the merge window, I'll simply queue them
> for the next one.
> 
> Thanks,
> Mathieu
> 
> Leo Yan (1):
>   Documentation: coresight: Add PID tracing description
> 
> Suzuki K Poulose (1):
>   coresight: etm-perf: Support PID tracing for kernel at EL2
> 
>  Documentation/trace/coresight/coresight.rst   | 32 +++++++++++++++++++
>  .../hwtracing/coresight/coresight-etm-perf.c  | 27 +++++++++++++++-
>  .../coresight/coresight-etm4x-core.c          | 13 ++++++++
>  include/linux/coresight-pmu.h                 |  3 ++
>  4 files changed, 74 insertions(+), 1 deletion(-)

This does not apply to my char-misc-next branch (the second patch does
not apply, I'll take the first one.)  Can you fix it up and resend?

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] coresight: Patches for v5.12 (part 2)
  2021-02-10 17:10 ` [PATCH 0/2] coresight: Patches for v5.12 (part 2) Greg KH
@ 2021-02-10 17:11   ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-02-10 17:11 UTC (permalink / raw)
  To: Mathieu Poirier; +Cc: linux-kernel, linux-arm-kernel

On Wed, Feb 10, 2021 at 06:10:34PM +0100, Greg KH wrote:
> On Wed, Feb 10, 2021 at 09:36:08AM -0700, Mathieu Poirier wrote:
> > Hi Greg,
> > 
> > Please see if you can add these 2 patches to your 5.12 tally.  No worries
> > if you think it is too close to the merge window, I'll simply queue them
> > for the next one.
> > 
> > Thanks,
> > Mathieu
> > 
> > Leo Yan (1):
> >   Documentation: coresight: Add PID tracing description
> > 
> > Suzuki K Poulose (1):
> >   coresight: etm-perf: Support PID tracing for kernel at EL2
> > 
> >  Documentation/trace/coresight/coresight.rst   | 32 +++++++++++++++++++
> >  .../hwtracing/coresight/coresight-etm-perf.c  | 27 +++++++++++++++-
> >  .../coresight/coresight-etm4x-core.c          | 13 ++++++++
> >  include/linux/coresight-pmu.h                 |  3 ++
> >  4 files changed, 74 insertions(+), 1 deletion(-)
> 
> This does not apply to my char-misc-next branch (the second patch does
> not apply, I'll take the first one.)  Can you fix it up and resend?

Oops, I mean the first one doesn't apply, so I'm not going to take
either.

thanks,

greg k-

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-10 17:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 16:36 [PATCH 0/2] coresight: Patches for v5.12 (part 2) Mathieu Poirier
2021-02-10 16:36 ` [PATCH 1/2] coresight: etm-perf: Support PID tracing for kernel at EL2 Mathieu Poirier
2021-02-10 16:36 ` [PATCH 2/2] Documentation: coresight: Add PID tracing description Mathieu Poirier
2021-02-10 17:10 ` [PATCH 0/2] coresight: Patches for v5.12 (part 2) Greg KH
2021-02-10 17:11   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).