linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/6] perf arm-spe: Enable timestamp
@ 2021-04-12  9:10 Leo Yan
  2021-04-12  9:10 ` [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS Leo Yan
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

This patch set is to enable timestamp for Arm SPE trace.  It reads out
TSC parameters from the TIME_CONV event, the parameters are used for
conversion between timer counter and kernel time and which is applied
for Arm SPE samples.

This version dropped the change for adding hardware clock parameters
into auxtrace info, alternatively, it utilizes the TIME_CONV event to
extract the clock parameters which is used for timestamp calculation.

This patch set can be clearly applied on perf/core branch with:

  commit 2c0cb9f56020 ("perf test: Add a shell test for 'perf stat --bpf-counters' new option")

Ths patch series has been tested on Hisilicon D06 platform.

Changes from v3:
* Let to be backwards-compatible for TIME_CONV event (Adrian).

Changes from v2:
* Changed to use TIME_CONV event for extracting clock parameters (Al).

Changes from v1:
* Rebased patch series on the latest perf/core branch;
* Fixed the patch for dumping TSC parameters to support both the
  older and new auxtrace info format.


Leo Yan (6):
  perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS
  perf arm-spe: Save clock parameters from TIME_CONV event
  perf arm-spe: Convert event kernel time to counter value
  perf arm-spe: Assign kernel time to synthesized event
  perf arm-spe: Bail out if the trace is later than perf event
  perf arm-spe: Don't wait for PERF_RECORD_EXIT event

 tools/perf/util/arm-spe.c | 74 +++++++++++++++++++++++++++++++++------
 tools/perf/util/arm-spe.h |  1 -
 2 files changed, 64 insertions(+), 11 deletions(-)

-- 
2.25.1


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

* [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
@ 2021-04-12  9:10 ` Leo Yan
  2021-04-15 14:13   ` James Clark
  2021-04-12  9:10 ` [PATCH v4 2/6] perf arm-spe: Save clock parameters from TIME_CONV event Leo Yan
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

The enum value 'ARM_SPE_PER_CPU_MMAPS' is never used so remove it.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/arm-spe.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/perf/util/arm-spe.h b/tools/perf/util/arm-spe.h
index 98d3235781c3..105ce0ea0a01 100644
--- a/tools/perf/util/arm-spe.h
+++ b/tools/perf/util/arm-spe.h
@@ -11,7 +11,6 @@
 
 enum {
 	ARM_SPE_PMU_TYPE,
-	ARM_SPE_PER_CPU_MMAPS,
 	ARM_SPE_AUXTRACE_PRIV_MAX,
 };
 
-- 
2.25.1


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

* [PATCH v4 2/6] perf arm-spe: Save clock parameters from TIME_CONV event
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
  2021-04-12  9:10 ` [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS Leo Yan
@ 2021-04-12  9:10 ` Leo Yan
  2021-04-12  9:10 ` [PATCH v4 3/6] perf arm-spe: Convert event kernel time to counter value Leo Yan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

During the recording phase, "perf record" tool synthesizes event
PERF_RECORD_TIME_CONV for the hardware clock parameters and saves the
event into the data file.

Afterwards, when processing the data file, the event TIME_CONV will be
processed at the very early time and is stored into session context.

This patch extracts these parameters from the session context and saves
into the structure "spe->tc" with the type perf_tsc_conversion, so that
the parameters are ready for conversion between clock counter and time
stamp.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/arm-spe.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 2539d4baec44..7620dcc45940 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -26,6 +26,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include "thread-stack.h"
+#include "tsc.h"
 #include "tool.h"
 #include "util/synthetic-events.h"
 
@@ -45,6 +46,8 @@ struct arm_spe {
 	struct machine			*machine;
 	u32				pmu_type;
 
+	struct perf_tsc_conversion	tc;
+
 	u8				timeless_decoding;
 	u8				data_queued;
 
@@ -1006,6 +1009,7 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 {
 	struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info;
 	size_t min_sz = sizeof(u64) * ARM_SPE_AUXTRACE_PRIV_MAX;
+	struct perf_record_time_conv *tc = &session->time_conv;
 	struct arm_spe *spe;
 	int err;
 
@@ -1027,6 +1031,29 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE];
 
 	spe->timeless_decoding = arm_spe__is_timeless_decoding(spe);
+
+	/*
+	 * The synthesized event PERF_RECORD_TIME_CONV has been handled ahead
+	 * and the parameters for hardware clock are stored in the session
+	 * context.  Passes these parameters to the struct perf_tsc_conversion
+	 * in "spe->tc", which is used for later conversion between clock
+	 * counter and timestamp.
+	 *
+	 * For backward compatibility, checks the event size and save extended
+	 * fields staring from "time_cycles" if these fields are contained in
+	 * the event.
+	 */
+	spe->tc.time_shift = tc->time_shift;
+	spe->tc.time_mult = tc->time_mult;
+	spe->tc.time_zero = tc->time_zero;
+
+	if (tc->header.size > ((void *)&tc->time_cycles - (void *)tc)) {
+		spe->tc.time_cycles = tc->time_cycles;
+		spe->tc.time_mask = tc->time_mask;
+		spe->tc.cap_user_time_zero = tc->cap_user_time_zero;
+		spe->tc.cap_user_time_short = tc->cap_user_time_short;
+	}
+
 	spe->auxtrace.process_event = arm_spe_process_event;
 	spe->auxtrace.process_auxtrace_event = arm_spe_process_auxtrace_event;
 	spe->auxtrace.flush_events = arm_spe_flush;
-- 
2.25.1


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

* [PATCH v4 3/6] perf arm-spe: Convert event kernel time to counter value
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
  2021-04-12  9:10 ` [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS Leo Yan
  2021-04-12  9:10 ` [PATCH v4 2/6] perf arm-spe: Save clock parameters from TIME_CONV event Leo Yan
@ 2021-04-12  9:10 ` Leo Yan
  2021-04-12  9:10 ` [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event Leo Yan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

When handle a perf event, Arm SPE decoder needs to decide if this perf
event is earlier or later than the samples from Arm SPE trace data; to
do comparision, it needs to use the same unit for the time.

This patch converts the event kernel time to arch timer's counter value,
thus it can be used to compare with counter value contained in Arm SPE
Timestamp packet.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/arm-spe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 7620dcc45940..23714cf0380e 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -669,7 +669,7 @@ static int arm_spe_process_event(struct perf_session *session,
 	}
 
 	if (sample->time && (sample->time != (u64) -1))
-		timestamp = sample->time;
+		timestamp = perf_time_to_tsc(sample->time, &spe->tc);
 	else
 		timestamp = 0;
 
-- 
2.25.1


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

* [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
                   ` (2 preceding siblings ...)
  2021-04-12  9:10 ` [PATCH v4 3/6] perf arm-spe: Convert event kernel time to counter value Leo Yan
@ 2021-04-12  9:10 ` Leo Yan
  2021-04-15 14:46   ` James Clark
  2021-04-12  9:10 ` [PATCH v4 5/6] perf arm-spe: Bail out if the trace is later than perf event Leo Yan
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

In current code, it assigns the arch timer counter to the synthesized
samples Arm SPE trace, thus the samples don't contain the kernel time
but only contain the raw counter value.

To fix the issue, this patch converts the timer counter to kernel time
and assigns it to sample timestamp.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/arm-spe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 23714cf0380e..c13a89f06ab8 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -234,7 +234,7 @@ static void arm_spe_prep_sample(struct arm_spe *spe,
 	struct arm_spe_record *record = &speq->decoder->record;
 
 	if (!spe->timeless_decoding)
-		sample->time = speq->timestamp;
+		sample->time = tsc_to_perf_time(record->timestamp, &spe->tc);
 
 	sample->ip = record->from_ip;
 	sample->cpumode = arm_spe_cpumode(spe, sample->ip);
-- 
2.25.1


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

* [PATCH v4 5/6] perf arm-spe: Bail out if the trace is later than perf event
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
                   ` (3 preceding siblings ...)
  2021-04-12  9:10 ` [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event Leo Yan
@ 2021-04-12  9:10 ` Leo Yan
  2021-04-12  9:10 ` [PATCH v4 6/6] perf arm-spe: Don't wait for PERF_RECORD_EXIT event Leo Yan
  2021-04-15 14:43 ` [PATCH v4 0/6] perf arm-spe: Enable timestamp James Clark
  6 siblings, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

It's possible that record in Arm SPE trace is later than perf event and
vice versa.  This asks to correlate the perf events and Arm SPE
synthesized events to be processed in the manner of correct timing.

To achieve the time ordering, this patch reverses the flow, it firstly
calls arm_spe_sample() and then calls arm_spe_decode().  By comparing
the timestamp value and detect the perf event is coming earlier than Arm
SPE trace data, it bails out from the decoding loop, the last record is
pushed into auxtrace stack and is deferred to generate sample.  To track
the timestamp, everytime it updates timestamp for the latest record.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/arm-spe.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index c13a89f06ab8..b37d1cacebe9 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -434,12 +434,36 @@ static int arm_spe_sample(struct arm_spe_queue *speq)
 static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
 {
 	struct arm_spe *spe = speq->spe;
+	struct arm_spe_record *record;
 	int ret;
 
 	if (!spe->kernel_start)
 		spe->kernel_start = machine__kernel_start(spe->machine);
 
 	while (1) {
+		/*
+		 * The usual logic is firstly to decode the packets, and then
+		 * based the record to synthesize sample; but here the flow is
+		 * reversed: it calls arm_spe_sample() for synthesizing samples
+		 * prior to arm_spe_decode().
+		 *
+		 * Two reasons for this code logic:
+		 * 1. Firstly, when setup queue in arm_spe__setup_queue(), it
+		 * has decoded trace data and generated a record, but the record
+		 * is left to generate sample until run to here, so it's correct
+		 * to synthesize sample for the left record.
+		 * 2. After decoding trace data, it needs to compare the record
+		 * timestamp with the coming perf event, if the record timestamp
+		 * is later than the perf event, it needs bail out and pushs the
+		 * record into auxtrace heap, thus the record can be deferred to
+		 * synthesize sample until run to here at the next time; so this
+		 * can correlate samples between Arm SPE trace data and other
+		 * perf events with correct time ordering.
+		 */
+		ret = arm_spe_sample(speq);
+		if (ret)
+			return ret;
+
 		ret = arm_spe_decode(speq->decoder);
 		if (!ret) {
 			pr_debug("No data or all data has been processed.\n");
@@ -453,10 +477,17 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
 		if (ret < 0)
 			continue;
 
-		ret = arm_spe_sample(speq);
-		if (ret)
-			return ret;
+		record = &speq->decoder->record;
 
+		/* Update timestamp for the last record */
+		if (record->timestamp > speq->timestamp)
+			speq->timestamp = record->timestamp;
+
+		/*
+		 * If the timestamp of the queue is later than timestamp of the
+		 * coming perf event, bail out so can allow the perf event to
+		 * be processed ahead.
+		 */
 		if (!spe->timeless_decoding && speq->timestamp >= *timestamp) {
 			*timestamp = speq->timestamp;
 			return 0;
-- 
2.25.1


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

* [PATCH v4 6/6] perf arm-spe: Don't wait for PERF_RECORD_EXIT event
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
                   ` (4 preceding siblings ...)
  2021-04-12  9:10 ` [PATCH v4 5/6] perf arm-spe: Bail out if the trace is later than perf event Leo Yan
@ 2021-04-12  9:10 ` Leo Yan
  2021-04-15 14:43 ` [PATCH v4 0/6] perf arm-spe: Enable timestamp James Clark
  6 siblings, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-12  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, James Clark, linux-arm-kernel, linux-kernel
  Cc: Leo Yan

When decode Arm SPE trace, it waits for PERF_RECORD_EXIT event (the last
perf event) for processing trace data, which is needless and even might
cause logic error, e.g. it might fail to correlate perf events with Arm
SPE events correctly.

So this patch removes the condition checking for PERF_RECORD_EXIT event.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/arm-spe.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index b37d1cacebe9..654fa2413823 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -717,11 +717,7 @@ static int arm_spe_process_event(struct perf_session *session,
 					sample->time);
 		}
 	} else if (timestamp) {
-		if (event->header.type == PERF_RECORD_EXIT) {
-			err = arm_spe_process_queues(spe, timestamp);
-			if (err)
-				return err;
-		}
+		err = arm_spe_process_queues(spe, timestamp);
 	}
 
 	return err;
-- 
2.25.1


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

* Re: [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS
  2021-04-12  9:10 ` [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS Leo Yan
@ 2021-04-15 14:13   ` James Clark
  2021-04-15 14:41     ` Leo Yan
  0 siblings, 1 reply; 17+ messages in thread
From: James Clark @ 2021-04-15 14:13 UTC (permalink / raw)
  To: Leo Yan, Arnaldo Carvalho de Melo, Al Grant, John Garry,
	Will Deacon, Mathieu Poirier, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Dave Martin, linux-arm-kernel, linux-kernel



On 12/04/2021 12:10, Leo Yan wrote:
> The enum value 'ARM_SPE_PER_CPU_MMAPS' is never used so remove it.

Hi Leo,

I think this causes an error when attempting to open a newly recorded file
with an old version of perf. The value ARM_SPE_AUXTRACE_PRIV_MAX is used here:

	size_t min_sz = sizeof(u64) * ARM_SPE_AUXTRACE_PRIV_MAX;
	struct perf_record_time_conv *tc = &session->time_conv;
	struct arm_spe *spe;
	int err;

	if (auxtrace_info->header.size < sizeof(struct perf_record_auxtrace_info) +
					min_sz)
		return -EINVAL;

And removing ARM_SPE_PER_CPU_MMAPS changes the value of ARM_SPE_AUXTRACE_PRIV_MAX.

At least I think that's what's causing the problem. I get this error:

	./perf report -i per-thread-spe-time.data
	0x1c0 [0x18]: failed to process type: 70 [Invalid argument]
	Error:
	failed to process sample
	# To display the perf.data header info, please use --header/--header-only options.
	#

James

> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/util/arm-spe.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/tools/perf/util/arm-spe.h b/tools/perf/util/arm-spe.h
> index 98d3235781c3..105ce0ea0a01 100644
> --- a/tools/perf/util/arm-spe.h
> +++ b/tools/perf/util/arm-spe.h
> @@ -11,7 +11,6 @@
>  
>  enum {
>  	ARM_SPE_PMU_TYPE,
> -	ARM_SPE_PER_CPU_MMAPS,
>  	ARM_SPE_AUXTRACE_PRIV_MAX,
>  };
>  
> 

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

* Re: [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS
  2021-04-15 14:13   ` James Clark
@ 2021-04-15 14:41     ` Leo Yan
  2021-04-15 14:49       ` James Clark
  0 siblings, 1 reply; 17+ messages in thread
From: Leo Yan @ 2021-04-15 14:41 UTC (permalink / raw)
  To: James Clark
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel

Hi James,

On Thu, Apr 15, 2021 at 05:13:36PM +0300, James Clark wrote:
> On 12/04/2021 12:10, Leo Yan wrote:
> > The enum value 'ARM_SPE_PER_CPU_MMAPS' is never used so remove it.
> 
> Hi Leo,
> 
> I think this causes an error when attempting to open a newly recorded file
> with an old version of perf. The value ARM_SPE_AUXTRACE_PRIV_MAX is used here:
> 
> 	size_t min_sz = sizeof(u64) * ARM_SPE_AUXTRACE_PRIV_MAX;
> 	struct perf_record_time_conv *tc = &session->time_conv;
> 	struct arm_spe *spe;
> 	int err;
> 
> 	if (auxtrace_info->header.size < sizeof(struct perf_record_auxtrace_info) +
> 					min_sz)
> 		return -EINVAL;
> 
> And removing ARM_SPE_PER_CPU_MMAPS changes the value of ARM_SPE_AUXTRACE_PRIV_MAX.
> 
> At least I think that's what's causing the problem. I get this error:
> 
> 	./perf report -i per-thread-spe-time.data
> 	0x1c0 [0x18]: failed to process type: 70 [Invalid argument]
> 	Error:
> 	failed to process sample
> 	# To display the perf.data header info, please use --header/--header-only options.
> 	#

Yes, when working on this patch I had concern as well.

I carefully thought that the perf tool should be backwards-compatible,
but there have no requirement for forwards-compatibility.  This is the
main reason why I kept this patch.

If you or anyone could confirm the forwards-compatibility is required,
it's quite fine for me to drop this patch.

Thanks a lot for the reviewing and testing!
Leo

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

* Re: [PATCH v4 0/6] perf arm-spe: Enable timestamp
  2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
                   ` (5 preceding siblings ...)
  2021-04-12  9:10 ` [PATCH v4 6/6] perf arm-spe: Don't wait for PERF_RECORD_EXIT event Leo Yan
@ 2021-04-15 14:43 ` James Clark
  2021-04-15 14:56   ` Leo Yan
  6 siblings, 1 reply; 17+ messages in thread
From: James Clark @ 2021-04-15 14:43 UTC (permalink / raw)
  To: Leo Yan, Arnaldo Carvalho de Melo, Al Grant, John Garry,
	Will Deacon, Mathieu Poirier, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Dave Martin, linux-arm-kernel, linux-kernel

Hi Leo,

I was looking at testing this on N1SDP and I thought I would try the round trip with perf inject and
then perf report but saw that perf inject with SPE always results in an error (unrelated to your change)

	 -> ./perf report -i per-thread-spe-time.inject.data
	0x1328 [0x8]: failed to process type: 9 [Bad address]
	Error:
	failed to process sample


Do you have any test suggestions other than looking at the raw data?

Thanks
James

On 12/04/2021 12:10, Leo Yan wrote:
> This patch set is to enable timestamp for Arm SPE trace.  It reads out
> TSC parameters from the TIME_CONV event, the parameters are used for
> conversion between timer counter and kernel time and which is applied
> for Arm SPE samples.
> 
> This version dropped the change for adding hardware clock parameters
> into auxtrace info, alternatively, it utilizes the TIME_CONV event to
> extract the clock parameters which is used for timestamp calculation.
> 
> This patch set can be clearly applied on perf/core branch with:
> 
>   commit 2c0cb9f56020 ("perf test: Add a shell test for 'perf stat --bpf-counters' new option")
> 
> Ths patch series has been tested on Hisilicon D06 platform.
> 
> Changes from v3:
> * Let to be backwards-compatible for TIME_CONV event (Adrian).
> 
> Changes from v2:
> * Changed to use TIME_CONV event for extracting clock parameters (Al).
> 
> Changes from v1:
> * Rebased patch series on the latest perf/core branch;
> * Fixed the patch for dumping TSC parameters to support both the
>   older and new auxtrace info format.
> 
> 
> Leo Yan (6):
>   perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS
>   perf arm-spe: Save clock parameters from TIME_CONV event
>   perf arm-spe: Convert event kernel time to counter value
>   perf arm-spe: Assign kernel time to synthesized event
>   perf arm-spe: Bail out if the trace is later than perf event
>   perf arm-spe: Don't wait for PERF_RECORD_EXIT event
> 
>  tools/perf/util/arm-spe.c | 74 +++++++++++++++++++++++++++++++++------
>  tools/perf/util/arm-spe.h |  1 -
>  2 files changed, 64 insertions(+), 11 deletions(-)
> 

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

* Re: [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event
  2021-04-12  9:10 ` [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event Leo Yan
@ 2021-04-15 14:46   ` James Clark
  2021-04-15 15:23     ` Leo Yan
  0 siblings, 1 reply; 17+ messages in thread
From: James Clark @ 2021-04-15 14:46 UTC (permalink / raw)
  To: Leo Yan, Arnaldo Carvalho de Melo, Al Grant, John Garry,
	Will Deacon, Mathieu Poirier, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Dave Martin, linux-arm-kernel, linux-kernel



On 12/04/2021 12:10, Leo Yan wrote:
> In current code, it assigns the arch timer counter to the synthesized
> samples Arm SPE trace, thus the samples don't contain the kernel time
> but only contain the raw counter value.
> 
> To fix the issue, this patch converts the timer counter to kernel time
> and assigns it to sample timestamp.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/util/arm-spe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 23714cf0380e..c13a89f06ab8 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -234,7 +234,7 @@ static void arm_spe_prep_sample(struct arm_spe *spe,
>  	struct arm_spe_record *record = &speq->decoder->record;
>  
>  	if (!spe->timeless_decoding)
> -		sample->time = speq->timestamp;
> +		sample->time = tsc_to_perf_time(record->timestamp, &spe->tc);


I noticed that in arm_spe_recording_options() the TIME sample bit is set regardless of any options.
I don't know of a way to remove this, and if there isn't, does that mean that all the code in this
file that looks at spe->timeless_decoding is untested and has never been hit?

Unless there is a way to get a perf file with only the AUXTRACE event and no others? I think that one
might have no timestamp set. Otherwise other events will always have timestamps so spe->timeless_decoding
is always false.



>  
>  	sample->ip = record->from_ip;
>  	sample->cpumode = arm_spe_cpumode(spe, sample->ip);
> 

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

* Re: [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS
  2021-04-15 14:41     ` Leo Yan
@ 2021-04-15 14:49       ` James Clark
  0 siblings, 0 replies; 17+ messages in thread
From: James Clark @ 2021-04-15 14:49 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel



On 15/04/2021 17:41, Leo Yan wrote:
> Hi James,
> 
> On Thu, Apr 15, 2021 at 05:13:36PM +0300, James Clark wrote:
>> On 12/04/2021 12:10, Leo Yan wrote:
>>> The enum value 'ARM_SPE_PER_CPU_MMAPS' is never used so remove it.
>>
>> Hi Leo,
>>
>> I think this causes an error when attempting to open a newly recorded file
>> with an old version of perf. The value ARM_SPE_AUXTRACE_PRIV_MAX is used here:
>>
>> 	size_t min_sz = sizeof(u64) * ARM_SPE_AUXTRACE_PRIV_MAX;
>> 	struct perf_record_time_conv *tc = &session->time_conv;
>> 	struct arm_spe *spe;
>> 	int err;
>>
>> 	if (auxtrace_info->header.size < sizeof(struct perf_record_auxtrace_info) +
>> 					min_sz)
>> 		return -EINVAL;
>>
>> And removing ARM_SPE_PER_CPU_MMAPS changes the value of ARM_SPE_AUXTRACE_PRIV_MAX.
>>
>> At least I think that's what's causing the problem. I get this error:
>>
>> 	./perf report -i per-thread-spe-time.data
>> 	0x1c0 [0x18]: failed to process type: 70 [Invalid argument]
>> 	Error:
>> 	failed to process sample
>> 	# To display the perf.data header info, please use --header/--header-only options.
>> 	#
> 
> Yes, when working on this patch I had concern as well.
> 
> I carefully thought that the perf tool should be backwards-compatible,
> but there have no requirement for forwards-compatibility.  This is the
> main reason why I kept this patch.
> 
> If you or anyone could confirm the forwards-compatibility is required,
> it's quite fine for me to drop this patch.
> 

Personally, I can easily imagine sending a file to someone to open with an older version and it causing
friction where it could be easily avoided. And it even made testing a bit more difficult because
I wanted to compare opening the same file with the patched and un-patched version. But if there
is no hard requirement I can't really put too much pressure to not remove it.

> Thanks a lot for the reviewing and testing!
> Leo
> 

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

* Re: [PATCH v4 0/6] perf arm-spe: Enable timestamp
  2021-04-15 14:43 ` [PATCH v4 0/6] perf arm-spe: Enable timestamp James Clark
@ 2021-04-15 14:56   ` Leo Yan
  0 siblings, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-15 14:56 UTC (permalink / raw)
  To: James Clark
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel

On Thu, Apr 15, 2021 at 05:43:24PM +0300, James Clark wrote:
> Hi Leo,
> 
> I was looking at testing this on N1SDP and I thought I would try the round trip with perf inject and
> then perf report but saw that perf inject with SPE always results in an error (unrelated to your change)
> 
> 	 -> ./perf report -i per-thread-spe-time.inject.data
> 	0x1328 [0x8]: failed to process type: 9 [Bad address]
> 	Error:
> 	failed to process sample
> 
> 
> Do you have any test suggestions other than looking at the raw data?

Good catching!  I didn't use inject mode for Arm SPE before (it's not
not like Arm CoreSight for instruction sample, or SPE's branch sample
is statistical so we cannot generate branch samples based on accurate
interval).

For the debugging, it's good to use "git grep" to search "Bad address"
to check where the error happens, and can use gdb.  I personally think
it's possible to go back to check the sythenization flow, simply to
say, it might have problems when inject samples but not in the
decoding flow.

Thanks,
Leo

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

* Re: [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event
  2021-04-15 14:46   ` James Clark
@ 2021-04-15 15:23     ` Leo Yan
  2021-04-16 12:51       ` James Clark
  0 siblings, 1 reply; 17+ messages in thread
From: Leo Yan @ 2021-04-15 15:23 UTC (permalink / raw)
  To: James Clark
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel

On Thu, Apr 15, 2021 at 05:46:31PM +0300, James Clark wrote:
> 
> 
> On 12/04/2021 12:10, Leo Yan wrote:
> > In current code, it assigns the arch timer counter to the synthesized
> > samples Arm SPE trace, thus the samples don't contain the kernel time
> > but only contain the raw counter value.
> > 
> > To fix the issue, this patch converts the timer counter to kernel time
> > and assigns it to sample timestamp.
> > 
> > Signed-off-by: Leo Yan <leo.yan@linaro.org>
> > ---
> >  tools/perf/util/arm-spe.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> > index 23714cf0380e..c13a89f06ab8 100644
> > --- a/tools/perf/util/arm-spe.c
> > +++ b/tools/perf/util/arm-spe.c
> > @@ -234,7 +234,7 @@ static void arm_spe_prep_sample(struct arm_spe *spe,
> >  	struct arm_spe_record *record = &speq->decoder->record;
> >  
> >  	if (!spe->timeless_decoding)
> > -		sample->time = speq->timestamp;
> > +		sample->time = tsc_to_perf_time(record->timestamp, &spe->tc);
> 
> 
> I noticed that in arm_spe_recording_options() the TIME sample bit is set regardless of any options.
> I don't know of a way to remove this, and if there isn't, does that mean that all the code in this
> file that looks at spe->timeless_decoding is untested and has never been hit?
> 
> Unless there is a way to get a perf file with only the AUXTRACE event and no others? I think that one
> might have no timestamp set. Otherwise other events will always have timestamps so spe->timeless_decoding
> is always false.

Good point.  To be honest, I never noticed this issue until you
mentioned this.

We should fix for the "timeless" flow; and it's questionable for the
function arm_spe_recording_options(), except for setting
PERF_SAMPLE_TIME, it also hard codes for setting
PERF_SAMPLE_CPU and PERF_SAMPLE_TID.  Might need to carefully go
through this function.

Thanks,
Leo

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

* Re: [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event
  2021-04-15 15:23     ` Leo Yan
@ 2021-04-16 12:51       ` James Clark
  2021-04-16 13:21         ` Leo Yan
  2021-04-29 15:23         ` Leo Yan
  0 siblings, 2 replies; 17+ messages in thread
From: James Clark @ 2021-04-16 12:51 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel



On 15/04/2021 18:23, Leo Yan wrote:
> On Thu, Apr 15, 2021 at 05:46:31PM +0300, James Clark wrote:
>>
>>
>> On 12/04/2021 12:10, Leo Yan wrote:
>>> In current code, it assigns the arch timer counter to the synthesized
>>> samples Arm SPE trace, thus the samples don't contain the kernel time
>>> but only contain the raw counter value.
>>>
>>> To fix the issue, this patch converts the timer counter to kernel time
>>> and assigns it to sample timestamp.
>>>
>>> Signed-off-by: Leo Yan <leo.yan@linaro.org>
>>> ---
>>>  tools/perf/util/arm-spe.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
>>> index 23714cf0380e..c13a89f06ab8 100644
>>> --- a/tools/perf/util/arm-spe.c
>>> +++ b/tools/perf/util/arm-spe.c
>>> @@ -234,7 +234,7 @@ static void arm_spe_prep_sample(struct arm_spe *spe,
>>>  	struct arm_spe_record *record = &speq->decoder->record;
>>>  
>>>  	if (!spe->timeless_decoding)
>>> -		sample->time = speq->timestamp;
>>> +		sample->time = tsc_to_perf_time(record->timestamp, &spe->tc);
>>
>>
>> I noticed that in arm_spe_recording_options() the TIME sample bit is set regardless of any options.
>> I don't know of a way to remove this, and if there isn't, does that mean that all the code in this
>> file that looks at spe->timeless_decoding is untested and has never been hit?
>>
>> Unless there is a way to get a perf file with only the AUXTRACE event and no others? I think that one
>> might have no timestamp set. Otherwise other events will always have timestamps so spe->timeless_decoding
>> is always false.
> 
> Good point.  To be honest, I never noticed this issue until you
> mentioned this.
> 
> We should fix for the "timeless" flow; and it's questionable for the
> function arm_spe_recording_options(), except for setting
> PERF_SAMPLE_TIME, it also hard codes for setting
> PERF_SAMPLE_CPU and PERF_SAMPLE_TID.  Might need to carefully go
> through this function.
> 

Yeah, it's not strictly related to your change, which is definitely an improvement.
But maybe we should have a look at the SPE implementation relating to timestamps as a whole.

> Thanks,
> Leo
> 

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

* Re: [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event
  2021-04-16 12:51       ` James Clark
@ 2021-04-16 13:21         ` Leo Yan
  2021-04-29 15:23         ` Leo Yan
  1 sibling, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-16 13:21 UTC (permalink / raw)
  To: James Clark
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel

On Fri, Apr 16, 2021 at 03:51:25PM +0300, James Clark wrote:

[...]

> >> I noticed that in arm_spe_recording_options() the TIME sample bit is set regardless of any options.
> >> I don't know of a way to remove this, and if there isn't, does that mean that all the code in this
> >> file that looks at spe->timeless_decoding is untested and has never been hit?
> >>
> >> Unless there is a way to get a perf file with only the AUXTRACE event and no others? I think that one
> >> might have no timestamp set. Otherwise other events will always have timestamps so spe->timeless_decoding
> >> is always false.
> > 
> > Good point.  To be honest, I never noticed this issue until you
> > mentioned this.
> > 
> > We should fix for the "timeless" flow; and it's questionable for the
> > function arm_spe_recording_options(), except for setting
> > PERF_SAMPLE_TIME, it also hard codes for setting
> > PERF_SAMPLE_CPU and PERF_SAMPLE_TID.  Might need to carefully go
> > through this function.
> > 
> 
> Yeah, it's not strictly related to your change, which is definitely an improvement.
> But maybe we should have a look at the SPE implementation relating to timestamps as a whole.

Totally agree, at least this patch series should not introduce any
barrier for timeless case.  I will go back to verify it; if you'd
like to fix timeless issue, please feel free to go ahead.

Thanks,
Leo

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

* Re: [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event
  2021-04-16 12:51       ` James Clark
  2021-04-16 13:21         ` Leo Yan
@ 2021-04-29 15:23         ` Leo Yan
  1 sibling, 0 replies; 17+ messages in thread
From: Leo Yan @ 2021-04-29 15:23 UTC (permalink / raw)
  To: James Clark
  Cc: Arnaldo Carvalho de Melo, Al Grant, John Garry, Will Deacon,
	Mathieu Poirier, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
	Dave Martin, linux-arm-kernel, linux-kernel

Hi James,

On Fri, Apr 16, 2021 at 03:51:25PM +0300, James Clark wrote:

[...]

> >>> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> >>> index 23714cf0380e..c13a89f06ab8 100644
> >>> --- a/tools/perf/util/arm-spe.c
> >>> +++ b/tools/perf/util/arm-spe.c
> >>> @@ -234,7 +234,7 @@ static void arm_spe_prep_sample(struct arm_spe *spe,
> >>>  	struct arm_spe_record *record = &speq->decoder->record;
> >>>  
> >>>  	if (!spe->timeless_decoding)
> >>> -		sample->time = speq->timestamp;
> >>> +		sample->time = tsc_to_perf_time(record->timestamp, &spe->tc);
> >>
> >>
> >> I noticed that in arm_spe_recording_options() the TIME sample bit is set regardless of any options.
> >> I don't know of a way to remove this, and if there isn't, does that mean that all the code in this
> >> file that looks at spe->timeless_decoding is untested and has never been hit?
> >>
> >> Unless there is a way to get a perf file with only the AUXTRACE event and no others? I think that one
> >> might have no timestamp set. Otherwise other events will always have timestamps so spe->timeless_decoding
> >> is always false.
> > 
> > Good point.  To be honest, I never noticed this issue until you
> > mentioned this.
> > 
> > We should fix for the "timeless" flow; and it's questionable for the
> > function arm_spe_recording_options(), except for setting
> > PERF_SAMPLE_TIME, it also hard codes for setting
> > PERF_SAMPLE_CPU and PERF_SAMPLE_TID.  Might need to carefully go
> > through this function.
> > 
> 
> Yeah, it's not strictly related to your change, which is definitely an improvement.
> But maybe we should have a look at the SPE implementation relating to timestamps as a whole.

Just now I sent another patch series "perf arm-spe: Correct recording
configurations", which is the following up for the issue you found at
here.

After correcting sample flags, and combining with current patch series
"perf arm-spe: Enable timestamp", I verified the Arm SPE decoding
flows for "timeless" decoding, which can work as expected.

So I think we can move forward for this patch series, for easier review,
I have uploaded my testing branch wiht the complete patches [1].  Could
you help confirm if this works for you?  Thanks!

Leo

[1] https://github.com/Leo-Yan/linux/tree/perf_arm_spe_timestamp_v4_with_correcting_sample_flags

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

end of thread, other threads:[~2021-04-29 15:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12  9:10 [PATCH v4 0/6] perf arm-spe: Enable timestamp Leo Yan
2021-04-12  9:10 ` [PATCH v4 1/6] perf arm-spe: Remove unused enum value ARM_SPE_PER_CPU_MMAPS Leo Yan
2021-04-15 14:13   ` James Clark
2021-04-15 14:41     ` Leo Yan
2021-04-15 14:49       ` James Clark
2021-04-12  9:10 ` [PATCH v4 2/6] perf arm-spe: Save clock parameters from TIME_CONV event Leo Yan
2021-04-12  9:10 ` [PATCH v4 3/6] perf arm-spe: Convert event kernel time to counter value Leo Yan
2021-04-12  9:10 ` [PATCH v4 4/6] perf arm-spe: Assign kernel time to synthesized event Leo Yan
2021-04-15 14:46   ` James Clark
2021-04-15 15:23     ` Leo Yan
2021-04-16 12:51       ` James Clark
2021-04-16 13:21         ` Leo Yan
2021-04-29 15:23         ` Leo Yan
2021-04-12  9:10 ` [PATCH v4 5/6] perf arm-spe: Bail out if the trace is later than perf event Leo Yan
2021-04-12  9:10 ` [PATCH v4 6/6] perf arm-spe: Don't wait for PERF_RECORD_EXIT event Leo Yan
2021-04-15 14:43 ` [PATCH v4 0/6] perf arm-spe: Enable timestamp James Clark
2021-04-15 14:56   ` Leo Yan

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).