linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
@ 2020-08-07  7:16 Leo Yan
  2020-08-07  7:16 ` [PATCH v2 1/4] perf tools: Support Arm arch timer counter Leo Yan
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Leo Yan @ 2020-08-07  7:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel
  Cc: Leo Yan

This patch set is to enable Arm arch timer counter and Arm SPE is the
first customer to use arch timer counter for its timestamp.

Patches 01 ~ 03 enables Arm arch timer counter in Perf tool; patch 01 is
to retrieve arch timer's parameters from mmaped page; patch 02 provides
APIs for the conversion between arch timer's counter and time; patch 03
adds a test for patches 01 and 02.

As the first customer to use Arm arch timer counter in perf tool, patch
04 is to generate sample's timestamp for ARM SPE AUX trace data.

This patch set has been rebased on perf/core branch with the latest
commit c4735d990268 ("perf evsel: Don't set
sample_regs_intr/sample_regs_user for dummy event").

After changes:

  # perf test 67 -v
    67: Convert perf time to arch timer counter
    --- start ---
    test child forked, pid 5463
    mmap size 528384B
    1st event perf time 2231755083020 arch timer cnt 113097053477
    test time           2231755087460 arch timer cnt 113097053699
    2nd event perf time 2231755090680 arch timer cnt 113097053860
    test child finished with 0
    ---- end ----

  Reports the SPE sample with timestamp:

  $ perf script -F,+time
    dd  6799 [034] 25496.733475:          1              l1d-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733475:          1              tlb-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733479:          1              l1d-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733479:          1              tlb-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733485:          1              l1d-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733485:          1              tlb-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)

Changes from v1:
* Rebased on the latest perf/core branch;
* Added a testing for Arm timer counter conversion (Ian Rogers).


Leo Yan (4):
  perf tools: Support Arm arch timer counter
  perf arm_arch_timer: Convert between counter and timestamp
  perf arm_arch_timer: Test conversion between counter and timestamp
  perf arm-spe: Enable timestamp with arch timer counter

 tools/perf/arch/arm64/include/arch-tests.h    |   6 +
 tools/perf/arch/arm64/tests/Build             |   1 +
 tools/perf/arch/arm64/tests/arch-tests.c      |   4 +
 .../tests/perf-time-to-arch-timer-counter.c   | 189 ++++++++++++++++++
 tools/perf/arch/arm64/util/Build              |   1 +
 tools/perf/arch/arm64/util/arch_timer.c       |  50 +++++
 tools/perf/arch/arm64/util/arm-spe.c          |  17 ++
 tools/perf/util/Build                         |   1 +
 tools/perf/util/arm-spe.c                     |  16 +-
 tools/perf/util/arm-spe.h                     |   5 +
 tools/perf/util/arm_arch_timer.c              |  28 +++
 tools/perf/util/arm_arch_timer.h              |  23 +++
 12 files changed, 339 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c
 create mode 100644 tools/perf/arch/arm64/util/arch_timer.c
 create mode 100644 tools/perf/util/arm_arch_timer.c
 create mode 100644 tools/perf/util/arm_arch_timer.h

-- 
2.17.1


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

* [PATCH v2 1/4] perf tools: Support Arm arch timer counter
  2020-08-07  7:16 [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
@ 2020-08-07  7:16 ` Leo Yan
  2020-08-20  2:56   ` liwei (GF)
  2020-08-07  7:16 ` [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp Leo Yan
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2020-08-07  7:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel
  Cc: Leo Yan

The Arm arch timer can be used to calculate timestamp, the basic idea is
the arch timer's counter value can be recorded in the hardware tracing
data, e.g. the arch timer's counter value can be used for Arm CoreSight
(not now but might be implemented later) and Arm SPE.  So we need a way
to convert the arch timer's counter to the system time, the conversion
is dependent on some related parameters, e.g. 'time_shift', 'time_mult',
'time_offset', etc; furthermore, to handle the counter wrapping issue,
perf tool needs to know 'time_cycles' and 'time_mask' for correction.

This patch is to support Arm arch timer by reading out the relevant
parameters from the head of first mmaped page.  And these parameters
will be stored into the structure 'perf_arch_timer_conversion' for
later calculation timestamp.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/arch/arm64/util/Build        |  1 +
 tools/perf/arch/arm64/util/arch_timer.c | 50 +++++++++++++++++++++++++
 tools/perf/util/arm_arch_timer.h        | 20 ++++++++++
 3 files changed, 71 insertions(+)
 create mode 100644 tools/perf/arch/arm64/util/arch_timer.c
 create mode 100644 tools/perf/util/arm_arch_timer.h

diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build
index 5c13438c7bd4..77f4d7b30932 100644
--- a/tools/perf/arch/arm64/util/Build
+++ b/tools/perf/arch/arm64/util/Build
@@ -1,3 +1,4 @@
+perf-y += arch_timer.o
 perf-y += header.o
 perf-y += machine.o
 perf-y += perf_regs.o
diff --git a/tools/perf/arch/arm64/util/arch_timer.c b/tools/perf/arch/arm64/util/arch_timer.c
new file mode 100644
index 000000000000..dcc217c294fc
--- /dev/null
+++ b/tools/perf/arch/arm64/util/arch_timer.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdbool.h>
+#include <errno.h>
+
+#include <linux/stddef.h>
+#include <linux/perf_event.h>
+
+#include <linux/types.h>
+#include <asm/barrier.h>
+#include "../../../util/debug.h"
+#include "../../../util/event.h"
+#include "../../../util/synthetic-events.h"
+#include "../../../util/arm_arch_timer.h"
+
+int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
+				    struct perf_arch_timer_conversion *tc)
+{
+	bool cap_user_time_zero, cap_user_time_short;
+	u32 seq;
+	int i = 0;
+
+	while (1) {
+		seq = pc->lock;
+		/* Add barrier between the sequence lock and data accessing */
+		rmb();
+
+		tc->time_mult = pc->time_mult;
+		tc->time_shift = pc->time_shift;
+		tc->time_zero = pc->time_zero;
+		tc->time_cycles = pc->time_cycles;
+		tc->time_mask = pc->time_mask;
+		cap_user_time_zero = pc->cap_user_time_zero;
+		cap_user_time_short = pc->cap_user_time_short;
+
+		/* Add barrier between the data accessing and sequence lock */
+		rmb();
+		if (pc->lock == seq && !(seq & 1))
+			break;
+		if (++i > 10000) {
+			pr_debug("%s: failed to get perf_event_mmap_page lock\n",
+				 __func__);
+			return -EINVAL;
+		}
+	}
+
+	if (!cap_user_time_zero || !cap_user_time_short)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
diff --git a/tools/perf/util/arm_arch_timer.h b/tools/perf/util/arm_arch_timer.h
new file mode 100644
index 000000000000..a3263cc4e5cf
--- /dev/null
+++ b/tools/perf/util/arm_arch_timer.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PERF_ARM_ARCH_TIMER_H
+#define __PERF_ARM_ARCH_TIMER_H
+
+#include <linux/types.h>
+
+struct perf_arch_timer_conversion {
+	u16 time_shift;
+	u32 time_mult;
+	u64 time_zero;
+	u64 time_cycles;
+	u64 time_mask;
+};
+
+struct perf_event_mmap_page;
+
+int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
+				    struct perf_arch_timer_conversion *tc);
+
+#endif // __PERF_ARM_ARCH_TIMER_H
-- 
2.17.1


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

* [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp
  2020-08-07  7:16 [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
  2020-08-07  7:16 ` [PATCH v2 1/4] perf tools: Support Arm arch timer counter Leo Yan
@ 2020-08-07  7:16 ` Leo Yan
  2020-08-20  3:05   ` liwei (GF)
  2020-08-07  7:16 ` [PATCH v2 3/4] perf arm_arch_timer: Test conversion " Leo Yan
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2020-08-07  7:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel
  Cc: Leo Yan

This patch introduces two new APIs, one is to calculate from converting
counter to timestamp and provides a reverse flow to convert timestamp
to counter.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/Build            |  1 +
 tools/perf/util/arm_arch_timer.c | 28 ++++++++++++++++++++++++++++
 tools/perf/util/arm_arch_timer.h |  3 +++
 3 files changed, 32 insertions(+)
 create mode 100644 tools/perf/util/arm_arch_timer.c

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8d18380ecd10..ba504549844f 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -101,6 +101,7 @@ perf-y += call-path.o
 perf-y += rwsem.o
 perf-y += thread-stack.o
 perf-y += spark.o
+perf-y += arm_arch_timer.o
 perf-$(CONFIG_AUXTRACE) += auxtrace.o
 perf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
 perf-$(CONFIG_AUXTRACE) += intel-pt.o
diff --git a/tools/perf/util/arm_arch_timer.c b/tools/perf/util/arm_arch_timer.c
new file mode 100644
index 000000000000..c37ffa4d9710
--- /dev/null
+++ b/tools/perf/util/arm_arch_timer.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#include "arm_arch_timer.h"
+
+u64 perf_time_to_arch_timer_cyc(u64 ns, struct perf_arch_timer_conversion *tc)
+{
+	u64 t, quot, rem;
+
+	t = ns - tc->time_zero;
+	quot = t / tc->time_mult;
+	rem  = t % tc->time_mult;
+	return (quot << tc->time_shift) +
+	       (rem << tc->time_shift) / tc->time_mult;
+}
+
+u64 arch_timer_cyc_to_perf_time(u64 cyc, struct perf_arch_timer_conversion *tc)
+{
+	u64 quot, rem;
+
+	cyc = tc->time_cycles + ((cyc - tc->time_cycles) & tc->time_mask);
+
+	quot = cyc >> tc->time_shift;
+	rem  = cyc & (((u64)1 << tc->time_shift) - 1);
+	return tc->time_zero + quot * tc->time_mult +
+	       ((rem * tc->time_mult) >> tc->time_shift);
+}
diff --git a/tools/perf/util/arm_arch_timer.h b/tools/perf/util/arm_arch_timer.h
index a3263cc4e5cf..7d9271f544f2 100644
--- a/tools/perf/util/arm_arch_timer.h
+++ b/tools/perf/util/arm_arch_timer.h
@@ -17,4 +17,7 @@ struct perf_event_mmap_page;
 int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
 				    struct perf_arch_timer_conversion *tc);
 
+u64 arch_timer_cyc_to_perf_time(u64 cyc, struct perf_arch_timer_conversion *tc);
+u64 perf_time_to_arch_timer_cyc(u64 ns, struct perf_arch_timer_conversion *tc);
+
 #endif // __PERF_ARM_ARCH_TIMER_H
-- 
2.17.1


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

* [PATCH v2 3/4] perf arm_arch_timer: Test conversion between counter and timestamp
  2020-08-07  7:16 [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
  2020-08-07  7:16 ` [PATCH v2 1/4] perf tools: Support Arm arch timer counter Leo Yan
  2020-08-07  7:16 ` [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp Leo Yan
@ 2020-08-07  7:16 ` Leo Yan
  2020-08-07  7:16 ` [PATCH v2 4/4] perf arm-spe: Enable timestamp with arch timer counter Leo Yan
  2020-08-12 16:06 ` [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Mathieu Poirier
  4 siblings, 0 replies; 16+ messages in thread
From: Leo Yan @ 2020-08-07  7:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel
  Cc: Leo Yan

x86 arch has provides the testing for conversion between tsc and perf
time, this patch studies it and writes a similar testing for conversion
between arch timer's counter and sample's time.

The testing approach firstly creates three time points:

  Time point 1: 1st process's sample with perf time 'comm1_time';
  Time point 2: read out arch timer counter 'test_arch_timer_cnt';
  Time point 3: 2nd process's sample with perf time 'comm2_time';

The testing converts perf time to and from arch timer counter for these
three values and the testing can pass only if the counter values and
time values are in the order.

The test steps are as below:

  # perf test list
    [...]
    67: Convert perf time to arch timer counter

  # perf test 67 -v
    67: Convert perf time to arch timer counter
    --- start ---
    test child forked, pid 5463
    mmap size 528384B
    1st event perf time 2231755083020 arch timer cnt 113097053477
    test time           2231755087460 arch timer cnt 113097053699
    2nd event perf time 2231755090680 arch timer cnt 113097053860
    test child finished with 0
    ---- end ----

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/arch/arm64/include/arch-tests.h    |   6 +
 tools/perf/arch/arm64/tests/Build             |   1 +
 tools/perf/arch/arm64/tests/arch-tests.c      |   4 +
 .../tests/perf-time-to-arch-timer-counter.c   | 189 ++++++++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100644 tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c

diff --git a/tools/perf/arch/arm64/include/arch-tests.h b/tools/perf/arch/arm64/include/arch-tests.h
index 90ec4c8cb880..12ad7592c9aa 100644
--- a/tools/perf/arch/arm64/include/arch-tests.h
+++ b/tools/perf/arch/arm64/include/arch-tests.h
@@ -2,6 +2,12 @@
 #ifndef ARCH_TESTS_H
 #define ARCH_TESTS_H
 
+#include <linux/compiler.h>
+
+/* Tests */
+int test__perf_time_to_arch_timer_cnt(struct test *test __maybe_unused,
+				      int subtest __maybe_unused);
+
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
 struct thread;
 struct perf_sample;
diff --git a/tools/perf/arch/arm64/tests/Build b/tools/perf/arch/arm64/tests/Build
index a61c06bdb757..1fd819e4f80f 100644
--- a/tools/perf/arch/arm64/tests/Build
+++ b/tools/perf/arch/arm64/tests/Build
@@ -2,3 +2,4 @@ perf-y += regs_load.o
 perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
 
 perf-y += arch-tests.o
+perf-y += perf-time-to-arch-timer-counter.o
diff --git a/tools/perf/arch/arm64/tests/arch-tests.c b/tools/perf/arch/arm64/tests/arch-tests.c
index 5b1543c98022..99d8ab865668 100644
--- a/tools/perf/arch/arm64/tests/arch-tests.c
+++ b/tools/perf/arch/arm64/tests/arch-tests.c
@@ -4,6 +4,10 @@
 #include "arch-tests.h"
 
 struct test arch_tests[] = {
+	{
+		.desc = "Convert perf time to arch timer counter",
+		.func = test__perf_time_to_arch_timer_cnt,
+	},
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
 	{
 		.desc = "DWARF unwind",
diff --git a/tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c b/tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c
new file mode 100644
index 000000000000..09b9f43b48a4
--- /dev/null
+++ b/tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <linux/types.h>
+#include <sys/prctl.h>
+#include <perf/cpumap.h>
+#include <perf/evlist.h>
+#include <perf/mmap.h>
+
+#include "arm_arch_timer.h"
+#include "debug.h"
+#include "parse-events.h"
+#include "evlist.h"
+#include "evsel.h"
+#include "thread_map.h"
+#include "record.h"
+#include "util/mmap.h"
+#include "tests/tests.h"
+
+#include "arch-tests.h"
+
+#define CHECK_NOT_LESS_ZERO(x) {		\
+	while ((x) < 0) {			\
+		pr_debug(#x " failed!\n");	\
+		goto out_err;			\
+	}					\
+}
+
+#define CHECK_NOT_NULL(x) {			\
+	while ((x) == NULL) {			\
+		pr_debug(#x " failed!\n");	\
+		goto out_err;			\
+	}					\
+}
+
+/*
+ * The arch timer's offset is set to zero, the virtual counter and physical
+ * counter should have the same value; so the user space program can read out
+ * counter with system register cntvct_el0 and it can be used to compare with
+ * kernel's counter.
+ */
+#define read_cntvct_el0(r) ({					\
+	u64 __val;						\
+	asm volatile("mrs %0, cntvct_el0" : "=r" (__val));	\
+	__val;							\
+})
+
+/**
+ * test__perf_time_to_arch_timer_cnt - test converting perf time to Arm arch
+ * timer counter.
+ *
+ * This function implements a test that checks that the conversion of perf time
+ * to and from Arm arch timer counter is consistent with the order of events.
+ * Returns 0 if the test passes, otherwise returns -1.  If TSC conversion is not
+ * supported then then the test passes but " (not supported)" is printed.
+ */
+int test__perf_time_to_arch_timer_cnt(struct test *test __maybe_unused,
+				      int subtest __maybe_unused)
+{
+	struct record_opts opts = {
+		.mmap_pages	     = UINT_MAX,
+		.user_freq	     = UINT_MAX,
+		.user_interval	     = ULLONG_MAX,
+		.target		     = {
+			.uses_mmap   = true,
+		},
+		.sample_time	     = true,
+	};
+	struct perf_thread_map *threads = NULL;
+	struct perf_cpu_map *cpus = NULL;
+	struct evlist *evlist = NULL;
+	struct evsel *evsel = NULL;
+	int err = -1, ret, i;
+	const char *comm1, *comm2;
+	struct perf_arch_timer_conversion tc;
+	struct perf_event_mmap_page *pc;
+	union perf_event *event;
+	u64 test_arch_timer_cnt;
+	u64 comm1_arch_timer_cnt;
+	u64 comm2_arch_timer_cnt;
+	u64 test_time, comm1_time = 0, comm2_time = 0;
+	struct mmap *md;
+
+	threads = thread_map__new(-1, getpid(), UINT_MAX);
+	CHECK_NOT_NULL(threads);
+
+	cpus = perf_cpu_map__new(NULL);
+	CHECK_NOT_NULL(cpus);
+
+	evlist = evlist__new();
+	CHECK_NOT_NULL(evlist);
+
+	perf_evlist__set_maps(&evlist->core, cpus, threads);
+
+	CHECK_NOT_LESS_ZERO(parse_events(evlist, "cycles:u", NULL));
+
+	perf_evlist__config(evlist, &opts, NULL);
+
+	evsel = evlist__first(evlist);
+
+	evsel->core.attr.comm = 1;
+	evsel->core.attr.disabled = 1;
+	evsel->core.attr.enable_on_exec = 0;
+
+	CHECK_NOT_LESS_ZERO(evlist__open(evlist));
+
+	CHECK_NOT_LESS_ZERO(evlist__mmap(evlist, UINT_MAX));
+
+	pc = evlist->mmap[0].core.base;
+	ret = perf_read_arch_timer_conversion(pc, &tc);
+	if (ret) {
+		if (ret == -EOPNOTSUPP) {
+			fprintf(stderr, " (not supported)");
+			return 0;
+		}
+		goto out_err;
+	}
+
+	evlist__enable(evlist);
+
+	comm1 = "Test COMM 1";
+	CHECK_NOT_LESS_ZERO(prctl(PR_SET_NAME, (unsigned long)comm1, 0, 0, 0));
+
+	test_arch_timer_cnt = read_cntvct_el0();
+
+	comm2 = "Test COMM 2";
+	CHECK_NOT_LESS_ZERO(prctl(PR_SET_NAME, (unsigned long)comm2, 0, 0, 0));
+
+	evlist__disable(evlist);
+
+	for (i = 0; i < evlist->core.nr_mmaps; i++) {
+		md = &evlist->mmap[i];
+		if (perf_mmap__read_init(&md->core) < 0)
+			continue;
+
+		while ((event = perf_mmap__read_event(&md->core)) != NULL) {
+			struct perf_sample sample;
+
+			if (event->header.type != PERF_RECORD_COMM ||
+			    (pid_t)event->comm.pid != getpid() ||
+			    (pid_t)event->comm.tid != getpid())
+				goto next_event;
+
+			if (strcmp(event->comm.comm, comm1) == 0) {
+				CHECK_NOT_LESS_ZERO(evsel__parse_sample(evsel, event, &sample));
+				comm1_time = sample.time;
+			}
+			if (strcmp(event->comm.comm, comm2) == 0) {
+				CHECK_NOT_LESS_ZERO(evsel__parse_sample(evsel, event, &sample));
+				comm2_time = sample.time;
+			}
+next_event:
+			perf_mmap__consume(&md->core);
+		}
+		perf_mmap__read_done(&md->core);
+	}
+
+	if (!comm1_time || !comm2_time)
+		goto out_err;
+
+	test_time = arch_timer_cyc_to_perf_time(test_arch_timer_cnt, &tc);
+	comm1_arch_timer_cnt = perf_time_to_arch_timer_cyc(comm1_time, &tc);
+	comm2_arch_timer_cnt = perf_time_to_arch_timer_cyc(comm2_time, &tc);
+
+	pr_debug("1st event perf time %"PRIu64" arch timer cnt %"PRIu64"\n",
+		 comm1_time, comm1_arch_timer_cnt);
+	pr_debug("test time           %"PRIu64" arch timer cnt %"PRIu64"\n",
+		 test_time, test_arch_timer_cnt);
+	pr_debug("2nd event perf time %"PRIu64" arch timer cnt %"PRIu64"\n",
+		 comm2_time, comm2_arch_timer_cnt);
+
+	if (test_time <= comm1_time ||
+	    test_time >= comm2_time)
+		goto out_err;
+
+	if (test_arch_timer_cnt <= comm1_arch_timer_cnt ||
+	    test_arch_timer_cnt >= comm2_arch_timer_cnt)
+		goto out_err;
+
+	err = 0;
+
+out_err:
+	evlist__delete(evlist);
+	return err;
+}
-- 
2.17.1


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

* [PATCH v2 4/4] perf arm-spe: Enable timestamp with arch timer counter
  2020-08-07  7:16 [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
                   ` (2 preceding siblings ...)
  2020-08-07  7:16 ` [PATCH v2 3/4] perf arm_arch_timer: Test conversion " Leo Yan
@ 2020-08-07  7:16 ` Leo Yan
  2020-08-12 16:06 ` [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Mathieu Poirier
  4 siblings, 0 replies; 16+ messages in thread
From: Leo Yan @ 2020-08-07  7:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel
  Cc: Leo Yan

Since the arch timer's counter is used for SPE tracing data, and now
it's ready to use arch timer for sample's timestamp in Perf tool, this
patch is to enable timestamp by convert the arch timer counter value to
the time.

After enabling timestamp for Arm SPE with this patch, we can see the
timestamp with 'time' field:

  $ perf script -F,+time
    dd  6799 [034] 25496.733475:          1              l1d-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733475:          1              tlb-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733479:          1              l1d-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733479:          1              tlb-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733485:          1              l1d-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
    dd  6799 [034] 25496.733485:          1              tlb-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/arch/arm64/util/arm-spe.c | 17 +++++++++++++++++
 tools/perf/util/arm-spe.c            | 16 ++++++++++++++--
 tools/perf/util/arm-spe.h            |  5 +++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index e3593063b3d1..a7cbd5fdb30e 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -11,6 +11,7 @@
 #include <linux/zalloc.h>
 #include <time.h>
 
+#include "../../../util/arm_arch_timer.h"
 #include "../../../util/cpumap.h"
 #include "../../../util/event.h"
 #include "../../../util/evsel.h"
@@ -22,6 +23,7 @@
 #include "../../../util/auxtrace.h"
 #include "../../../util/record.h"
 #include "../../../util/arm-spe.h"
+#include "../../../util/mmap.h"
 
 #define KiB(x) ((x) * 1024)
 #define MiB(x) ((x) * 1024 * 1024)
@@ -47,6 +49,9 @@ static int arm_spe_info_fill(struct auxtrace_record *itr,
 	struct arm_spe_recording *sper =
 			container_of(itr, struct arm_spe_recording, itr);
 	struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu;
+	struct perf_event_mmap_page *pc;
+	struct perf_arch_timer_conversion tc = { 0 };
+	int err;
 
 	if (priv_size != ARM_SPE_AUXTRACE_PRIV_SIZE)
 		return -EINVAL;
@@ -54,8 +59,20 @@ static int arm_spe_info_fill(struct auxtrace_record *itr,
 	if (!session->evlist->core.nr_mmaps)
 		return -EINVAL;
 
+	pc = session->evlist->mmap[0].core.base;
+	if (pc) {
+		err = perf_read_arch_timer_conversion(pc, &tc);
+		if (err)
+			return err;
+	}
+
 	auxtrace_info->type = PERF_AUXTRACE_ARM_SPE;
 	auxtrace_info->priv[ARM_SPE_PMU_TYPE] = arm_spe_pmu->type;
+	auxtrace_info->priv[ARM_SPE_TIME_SHIFT] = tc.time_shift;
+	auxtrace_info->priv[ARM_SPE_TIME_MULT] = tc.time_mult;
+	auxtrace_info->priv[ARM_SPE_TIME_ZERO] = tc.time_zero;
+	auxtrace_info->priv[ARM_SPE_TIME_CYCLES] = tc.time_cycles;
+	auxtrace_info->priv[ARM_SPE_TIME_MASK] = tc.time_mask;
 
 	return 0;
 }
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 3882a5360ada..07232664c927 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -16,6 +16,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "arm_arch_timer.h"
 #include "auxtrace.h"
 #include "color.h"
 #include "debug.h"
@@ -44,6 +45,7 @@ struct arm_spe {
 	struct perf_session		*session;
 	struct machine			*machine;
 	u32				pmu_type;
+	struct perf_arch_timer_conversion tc;
 
 	u8				timeless_decoding;
 	u8				data_queued;
@@ -229,7 +231,8 @@ 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 = arch_timer_cyc_to_perf_time(speq->timestamp,
+							   &spe->tc);
 
 	sample->ip = record->from_ip;
 	sample->cpumode = arm_spe_cpumode(spe, sample->ip);
@@ -350,6 +353,7 @@ 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)
@@ -369,6 +373,9 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
 		if (ret < 0)
 			continue;
 
+		record = &speq->decoder->record;
+		speq->timestamp = record->timestamp;
+
 		ret = arm_spe_sample(speq);
 		if (ret)
 			return ret;
@@ -585,7 +592,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_arch_timer_cyc(sample->time, &spe->tc);
 	else
 		timestamp = 0;
 
@@ -934,6 +941,11 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	spe->machine = &session->machines.host; /* No kvm support */
 	spe->auxtrace_type = auxtrace_info->type;
 	spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE];
+	spe->tc.time_shift = auxtrace_info->priv[ARM_SPE_TIME_SHIFT];
+	spe->tc.time_mult = auxtrace_info->priv[ARM_SPE_TIME_MULT];
+	spe->tc.time_zero = auxtrace_info->priv[ARM_SPE_TIME_ZERO];
+	spe->tc.time_cycles = auxtrace_info->priv[ARM_SPE_TIME_CYCLES];
+	spe->tc.time_mask = auxtrace_info->priv[ARM_SPE_TIME_MASK];
 
 	spe->timeless_decoding = arm_spe__is_timeless_decoding(spe);
 	spe->auxtrace.process_event = arm_spe_process_event;
diff --git a/tools/perf/util/arm-spe.h b/tools/perf/util/arm-spe.h
index 98d3235781c3..8baa32ad179d 100644
--- a/tools/perf/util/arm-spe.h
+++ b/tools/perf/util/arm-spe.h
@@ -12,6 +12,11 @@
 enum {
 	ARM_SPE_PMU_TYPE,
 	ARM_SPE_PER_CPU_MMAPS,
+	ARM_SPE_TIME_SHIFT,
+	ARM_SPE_TIME_MULT,
+	ARM_SPE_TIME_ZERO,
+	ARM_SPE_TIME_CYCLES,
+	ARM_SPE_TIME_MASK,
 	ARM_SPE_AUXTRACE_PRIV_MAX,
 };
 
-- 
2.17.1


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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-07  7:16 [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
                   ` (3 preceding siblings ...)
  2020-08-07  7:16 ` [PATCH v2 4/4] perf arm-spe: Enable timestamp with arch timer counter Leo Yan
@ 2020-08-12 16:06 ` Mathieu Poirier
  2020-08-12 18:53   ` Arnaldo Carvalho de Melo
  4 siblings, 1 reply; 16+ messages in thread
From: Mathieu Poirier @ 2020-08-12 16:06 UTC (permalink / raw)
  To: Leo Yan, Arnaldo Carvalho de Melo
  Cc: Ian Rogers, Will Deacon, Mark Rutland, Peter Zijlstra,
	Ingo Molnar, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Kemeng Shi, Naveen N. Rao, Adrian Hunter, Igor Lubashev,
	Andi Kleen, Jin Yao, Stephane Eranian, James Clark,
	Linux Kernel Mailing List

Hi Arnaldo,

On Fri, 7 Aug 2020 at 01:16, Leo Yan <leo.yan@linaro.org> wrote:
>
> This patch set is to enable Arm arch timer counter and Arm SPE is the
> first customer to use arch timer counter for its timestamp.
>
> Patches 01 ~ 03 enables Arm arch timer counter in Perf tool; patch 01 is
> to retrieve arch timer's parameters from mmaped page; patch 02 provides
> APIs for the conversion between arch timer's counter and time; patch 03
> adds a test for patches 01 and 02.
>
> As the first customer to use Arm arch timer counter in perf tool, patch
> 04 is to generate sample's timestamp for ARM SPE AUX trace data.
>
> This patch set has been rebased on perf/core branch with the latest
> commit c4735d990268 ("perf evsel: Don't set
> sample_regs_intr/sample_regs_user for dummy event").

The ARM SPE perf tools code is orphan and I don't have the cycles to
pick it up.  Leo has spent a lot of time in that code and as such I
suggest that he starts maintaining it, probably following the same
kind of arrangement you and I have for coresight.

Thanks,
Mathieu

>
> After changes:
>
>   # perf test 67 -v
>     67: Convert perf time to arch timer counter
>     --- start ---
>     test child forked, pid 5463
>     mmap size 528384B
>     1st event perf time 2231755083020 arch timer cnt 113097053477
>     test time           2231755087460 arch timer cnt 113097053699
>     2nd event perf time 2231755090680 arch timer cnt 113097053860
>     test child finished with 0
>     ---- end ----
>
>   Reports the SPE sample with timestamp:
>
>   $ perf script -F,+time
>     dd  6799 [034] 25496.733475:          1              l1d-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
>     dd  6799 [034] 25496.733475:          1              tlb-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
>     dd  6799 [034] 25496.733479:          1              l1d-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
>     dd  6799 [034] 25496.733479:          1              tlb-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
>     dd  6799 [034] 25496.733485:          1              l1d-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
>     dd  6799 [034] 25496.733485:          1              tlb-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
>
> Changes from v1:
> * Rebased on the latest perf/core branch;
> * Added a testing for Arm timer counter conversion (Ian Rogers).
>
>
> Leo Yan (4):
>   perf tools: Support Arm arch timer counter
>   perf arm_arch_timer: Convert between counter and timestamp
>   perf arm_arch_timer: Test conversion between counter and timestamp
>   perf arm-spe: Enable timestamp with arch timer counter
>
>  tools/perf/arch/arm64/include/arch-tests.h    |   6 +
>  tools/perf/arch/arm64/tests/Build             |   1 +
>  tools/perf/arch/arm64/tests/arch-tests.c      |   4 +
>  .../tests/perf-time-to-arch-timer-counter.c   | 189 ++++++++++++++++++
>  tools/perf/arch/arm64/util/Build              |   1 +
>  tools/perf/arch/arm64/util/arch_timer.c       |  50 +++++
>  tools/perf/arch/arm64/util/arm-spe.c          |  17 ++
>  tools/perf/util/Build                         |   1 +
>  tools/perf/util/arm-spe.c                     |  16 +-
>  tools/perf/util/arm-spe.h                     |   5 +
>  tools/perf/util/arm_arch_timer.c              |  28 +++
>  tools/perf/util/arm_arch_timer.h              |  23 +++
>  12 files changed, 339 insertions(+), 2 deletions(-)
>  create mode 100644 tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c
>  create mode 100644 tools/perf/arch/arm64/util/arch_timer.c
>  create mode 100644 tools/perf/util/arm_arch_timer.c
>  create mode 100644 tools/perf/util/arm_arch_timer.h
>
> --
> 2.17.1
>

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-12 16:06 ` [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Mathieu Poirier
@ 2020-08-12 18:53   ` Arnaldo Carvalho de Melo
  2020-08-13  1:54     ` Leo Yan
                       ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-08-12 18:53 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: Leo Yan, Ian Rogers, Will Deacon, Mark Rutland, Peter Zijlstra,
	Ingo Molnar, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Kemeng Shi, Naveen N. Rao, Adrian Hunter, Igor Lubashev,
	Andi Kleen, Jin Yao, Stephane Eranian, James Clark,
	Linux Kernel Mailing List

Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
> Hi Arnaldo,
> 
> On Fri, 7 Aug 2020 at 01:16, Leo Yan <leo.yan@linaro.org> wrote:
> >
> > This patch set is to enable Arm arch timer counter and Arm SPE is the
> > first customer to use arch timer counter for its timestamp.
> >
> > Patches 01 ~ 03 enables Arm arch timer counter in Perf tool; patch 01 is
> > to retrieve arch timer's parameters from mmaped page; patch 02 provides
> > APIs for the conversion between arch timer's counter and time; patch 03
> > adds a test for patches 01 and 02.
> >
> > As the first customer to use Arm arch timer counter in perf tool, patch
> > 04 is to generate sample's timestamp for ARM SPE AUX trace data.
> >
> > This patch set has been rebased on perf/core branch with the latest
> > commit c4735d990268 ("perf evsel: Don't set
> > sample_regs_intr/sample_regs_user for dummy event").
> 
> The ARM SPE perf tools code is orphan and I don't have the cycles to
> pick it up.  Leo has spent a lot of time in that code and as such I
> suggest that he starts maintaining it, probably following the same
> kind of arrangement you and I have for coresight.

Thats ok with me, I think we should reflect that on the MAINTAINERS
file, right?

We have this already:

PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
R:      John Garry <john.garry@huawei.com>
R:      Will Deacon <will@kernel.org>
L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
S:      Supported
F:      tools/perf/pmu-events/arch/arm64/

I think we should have entries for CoreSight and ARM SPE, one listing
you as the maintainer and the other listing Leo, right?

Leo, it would be good for you to try and find someone at your
organization or elsewhere that could help with this, this way I would
wait a bit, see if someone else Acks it, and collect those, processing
it from you after a while if nobody chimes in.

Please continue providing 'perf test' regression tests, etc, to help
with maintaining this code being checked.

- Arnaldo
 
> Thanks,
> Mathieu
> 
> >
> > After changes:
> >
> >   # perf test 67 -v
> >     67: Convert perf time to arch timer counter
> >     --- start ---
> >     test child forked, pid 5463
> >     mmap size 528384B
> >     1st event perf time 2231755083020 arch timer cnt 113097053477
> >     test time           2231755087460 arch timer cnt 113097053699
> >     2nd event perf time 2231755090680 arch timer cnt 113097053860
> >     test child finished with 0
> >     ---- end ----
> >
> >   Reports the SPE sample with timestamp:
> >
> >   $ perf script -F,+time
> >     dd  6799 [034] 25496.733475:          1              l1d-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> >     dd  6799 [034] 25496.733475:          1              tlb-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> >     dd  6799 [034] 25496.733479:          1              l1d-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> >     dd  6799 [034] 25496.733479:          1              tlb-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> >     dd  6799 [034] 25496.733485:          1              l1d-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> >     dd  6799 [034] 25496.733485:          1              tlb-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> >
> > Changes from v1:
> > * Rebased on the latest perf/core branch;
> > * Added a testing for Arm timer counter conversion (Ian Rogers).
> >
> >
> > Leo Yan (4):
> >   perf tools: Support Arm arch timer counter
> >   perf arm_arch_timer: Convert between counter and timestamp
> >   perf arm_arch_timer: Test conversion between counter and timestamp
> >   perf arm-spe: Enable timestamp with arch timer counter
> >
> >  tools/perf/arch/arm64/include/arch-tests.h    |   6 +
> >  tools/perf/arch/arm64/tests/Build             |   1 +
> >  tools/perf/arch/arm64/tests/arch-tests.c      |   4 +
> >  .../tests/perf-time-to-arch-timer-counter.c   | 189 ++++++++++++++++++
> >  tools/perf/arch/arm64/util/Build              |   1 +
> >  tools/perf/arch/arm64/util/arch_timer.c       |  50 +++++
> >  tools/perf/arch/arm64/util/arm-spe.c          |  17 ++
> >  tools/perf/util/Build                         |   1 +
> >  tools/perf/util/arm-spe.c                     |  16 +-
> >  tools/perf/util/arm-spe.h                     |   5 +
> >  tools/perf/util/arm_arch_timer.c              |  28 +++
> >  tools/perf/util/arm_arch_timer.h              |  23 +++
> >  12 files changed, 339 insertions(+), 2 deletions(-)
> >  create mode 100644 tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c
> >  create mode 100644 tools/perf/arch/arm64/util/arch_timer.c
> >  create mode 100644 tools/perf/util/arm_arch_timer.c
> >  create mode 100644 tools/perf/util/arm_arch_timer.h
> >
> > --
> > 2.17.1
> >

-- 

- Arnaldo

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-12 18:53   ` Arnaldo Carvalho de Melo
@ 2020-08-13  1:54     ` Leo Yan
  2020-08-13  9:59     ` Will Deacon
  2020-08-13 16:17     ` Mathieu Poirier
  2 siblings, 0 replies; 16+ messages in thread
From: Leo Yan @ 2020-08-13  1:54 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Mathieu Poirier, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Igor Lubashev, Andi Kleen, Jin Yao, Stephane Eranian,
	James Clark, Linux Kernel Mailing List

On Wed, Aug 12, 2020 at 03:53:34PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
> > Hi Arnaldo,
> > 
> > On Fri, 7 Aug 2020 at 01:16, Leo Yan <leo.yan@linaro.org> wrote:
> > >
> > > This patch set is to enable Arm arch timer counter and Arm SPE is the
> > > first customer to use arch timer counter for its timestamp.
> > >
> > > Patches 01 ~ 03 enables Arm arch timer counter in Perf tool; patch 01 is
> > > to retrieve arch timer's parameters from mmaped page; patch 02 provides
> > > APIs for the conversion between arch timer's counter and time; patch 03
> > > adds a test for patches 01 and 02.
> > >
> > > As the first customer to use Arm arch timer counter in perf tool, patch
> > > 04 is to generate sample's timestamp for ARM SPE AUX trace data.
> > >
> > > This patch set has been rebased on perf/core branch with the latest
> > > commit c4735d990268 ("perf evsel: Don't set
> > > sample_regs_intr/sample_regs_user for dummy event").
> > 
> > The ARM SPE perf tools code is orphan and I don't have the cycles to
> > pick it up.  Leo has spent a lot of time in that code and as such I
> > suggest that he starts maintaining it, probably following the same
> > kind of arrangement you and I have for coresight.
> 
> Thats ok with me, I think we should reflect that on the MAINTAINERS
> file, right?

Very appreciate for the promoting, Mathieu and Arnaldo.

> We have this already:
> 
> PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
> R:      John Garry <john.garry@huawei.com>
> R:      Will Deacon <will@kernel.org>
> L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
> S:      Supported
> F:      tools/perf/pmu-events/arch/arm64/
> 
> I think we should have entries for CoreSight and ARM SPE, one listing
> you as the maintainer and the other listing Leo, right?
> 
> Leo, it would be good for you to try and find someone at your
> organization or elsewhere that could help with this, this way I would
> wait a bit, see if someone else Acks it, and collect those, processing
> it from you after a while if nobody chimes in.

I will follow up this and might offline to check with relevant
maintainers (Will and John) for what's good way to proceed.

> Please continue providing 'perf test' regression tests, etc, to help
> with maintaining this code being checked.

Sure, I'm glad to continue the maintaining and testing works :)

Thanks,
Leo

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-12 18:53   ` Arnaldo Carvalho de Melo
  2020-08-13  1:54     ` Leo Yan
@ 2020-08-13  9:59     ` Will Deacon
  2020-08-13 11:18       ` Will Deacon
  2020-08-13 16:17     ` Mathieu Poirier
  2 siblings, 1 reply; 16+ messages in thread
From: Will Deacon @ 2020-08-13  9:59 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Mathieu Poirier, Leo Yan, Ian Rogers, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Igor Lubashev, Andi Kleen, Jin Yao, Stephane Eranian,
	James Clark, Linux Kernel Mailing List

On Wed, Aug 12, 2020 at 03:53:34PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
> > On Fri, 7 Aug 2020 at 01:16, Leo Yan <leo.yan@linaro.org> wrote:
> > >
> > > This patch set is to enable Arm arch timer counter and Arm SPE is the
> > > first customer to use arch timer counter for its timestamp.
> > >
> > > Patches 01 ~ 03 enables Arm arch timer counter in Perf tool; patch 01 is
> > > to retrieve arch timer's parameters from mmaped page; patch 02 provides
> > > APIs for the conversion between arch timer's counter and time; patch 03
> > > adds a test for patches 01 and 02.
> > >
> > > As the first customer to use Arm arch timer counter in perf tool, patch
> > > 04 is to generate sample's timestamp for ARM SPE AUX trace data.
> > >
> > > This patch set has been rebased on perf/core branch with the latest
> > > commit c4735d990268 ("perf evsel: Don't set
> > > sample_regs_intr/sample_regs_user for dummy event").
> > 
> > The ARM SPE perf tools code is orphan and I don't have the cycles to
> > pick it up.  Leo has spent a lot of time in that code and as such I
> > suggest that he starts maintaining it, probably following the same
> > kind of arrangement you and I have for coresight.
> 
> Thats ok with me, I think we should reflect that on the MAINTAINERS
> file, right?
> 
> We have this already:
> 
> PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
> R:      John Garry <john.garry@huawei.com>
> R:      Will Deacon <will@kernel.org>
> L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
> S:      Supported
> F:      tools/perf/pmu-events/arch/arm64/
> 
> I think we should have entries for CoreSight and ARM SPE, one listing
> you as the maintainer and the other listing Leo, right?

Fine by me. I'll continue to maintain the in-kernel SPE driver, but I'd love
to see somebody step up to looking after the userspace code. It's seriously
unloved on arm64 :(

I'd even be happy to see one or two M: entries added for
tools/perf/pmu-events/arch/arm64/. I realistically don't have the time to
take that on, but I'd be thrilled if any/all of John, Mathieu and Leo were
to be listed there if they are willing to do so and can spare the time to
look after it. Even just silly things like making sure the thing
cross-compiles have been broken in the recent past, so it's not necessarily
about handling huge amounts of incoming patches.

In other words, rather than slice up the arm64 parts of the perf tool, I'd
argue in favour of a joint maintainership model for all the arm64 bits, if
we have a few willing volunteers.

Will

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-13  9:59     ` Will Deacon
@ 2020-08-13 11:18       ` Will Deacon
  2020-08-13 12:08         ` John Garry
  0 siblings, 1 reply; 16+ messages in thread
From: Will Deacon @ 2020-08-13 11:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Mathieu Poirier, Leo Yan, Ian Rogers, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Igor Lubashev, Andi Kleen, Jin Yao, Stephane Eranian,
	James Clark, Linux Kernel Mailing List, john.garry

[ Adding John, as I only just realised he wasn't on CC and we were talking
  about him! ]

On Thu, Aug 13, 2020 at 10:59:01AM +0100, Will Deacon wrote:
> On Wed, Aug 12, 2020 at 03:53:34PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
> > > The ARM SPE perf tools code is orphan and I don't have the cycles to
> > > pick it up.  Leo has spent a lot of time in that code and as such I
> > > suggest that he starts maintaining it, probably following the same
> > > kind of arrangement you and I have for coresight.
> > 
> > Thats ok with me, I think we should reflect that on the MAINTAINERS
> > file, right?
> > 
> > We have this already:
> > 
> > PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
> > R:      John Garry <john.garry@huawei.com>
> > R:      Will Deacon <will@kernel.org>
> > L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
> > S:      Supported
> > F:      tools/perf/pmu-events/arch/arm64/
> > 
> > I think we should have entries for CoreSight and ARM SPE, one listing
> > you as the maintainer and the other listing Leo, right?
> 
> Fine by me. I'll continue to maintain the in-kernel SPE driver, but I'd love
> to see somebody step up to looking after the userspace code. It's seriously
> unloved on arm64 :(
> 
> I'd even be happy to see one or two M: entries added for
> tools/perf/pmu-events/arch/arm64/. I realistically don't have the time to
> take that on, but I'd be thrilled if any/all of John, Mathieu and Leo were
> to be listed there if they are willing to do so and can spare the time to
> look after it. Even just silly things like making sure the thing
> cross-compiles have been broken in the recent past, so it's not necessarily
> about handling huge amounts of incoming patches.
> 
> In other words, rather than slice up the arm64 parts of the perf tool, I'd
> argue in favour of a joint maintainership model for all the arm64 bits, if
> we have a few willing volunteers.
> 
> Will

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-13 11:18       ` Will Deacon
@ 2020-08-13 12:08         ` John Garry
  2020-08-13 13:05           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 16+ messages in thread
From: John Garry @ 2020-08-13 12:08 UTC (permalink / raw)
  To: Will Deacon, Arnaldo Carvalho de Melo
  Cc: Mathieu Poirier, Leo Yan, Ian Rogers, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Igor Lubashev, Andi Kleen, Jin Yao, Stephane Eranian,
	James Clark, Linux Kernel Mailing List

On 13/08/2020 12:18, Will Deacon wrote:
> [ Adding John, as I only just realised he wasn't on CC and we were talking
>    about him! ]
> 
> On Thu, Aug 13, 2020 at 10:59:01AM +0100, Will Deacon wrote:
>> On Wed, Aug 12, 2020 at 03:53:34PM -0300, Arnaldo Carvalho de Melo wrote:
>>> Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
>>>> The ARM SPE perf tools code is orphan and I don't have the cycles to
>>>> pick it up.  Leo has spent a lot of time in that code and as such I
>>>> suggest that he starts maintaining it, probably following the same
>>>> kind of arrangement you and I have for coresight.
>>>
>>> Thats ok with me, I think we should reflect that on the MAINTAINERS
>>> file, right?
>>>
>>> We have this already:
>>>
>>> PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
>>> R:      John Garry <john.garry@huawei.com>
>>> R:      Will Deacon <will@kernel.org>
>>> L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
>>> S:      Supported
>>> F:      tools/perf/pmu-events/arch/arm64/
>>>
>>> I think we should have entries for CoreSight and ARM SPE, one listing
>>> you as the maintainer and the other listing Leo, right?
>>
>> Fine by me. I'll continue to maintain the in-kernel SPE driver, but I'd love
>> to see somebody step up to looking after the userspace code. It's seriously
>> unloved on arm64 :(
>>
>> I'd even be happy to see one or two M: entries added for
>> tools/perf/pmu-events/arch/arm64/. I realistically don't have the time to
>> take that on, but I'd be thrilled if any/all of John, Mathieu and Leo were
>> to be listed there if they are willing to do so and can spare the time to
>> look after it. Even just silly things like making sure the thing
>> cross-compiles have been broken in the recent past, so it's not necessarily
>> about handling huge amounts of incoming patches.
>>
>> In other words, rather than slice up the arm64 parts of the perf tool, I'd
>> argue in favour of a joint maintainership model for all the arm64 bits, if
>> we have a few willing volunteers.

Right, it makes sense not to chop up too much, so happy to see 
"PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS" expanded in terms of 
scope and membership.

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-13 12:08         ` John Garry
@ 2020-08-13 13:05           ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-08-13 13:05 UTC (permalink / raw)
  To: John Garry
  Cc: Will Deacon, Mathieu Poirier, Leo Yan, Ian Rogers, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Igor Lubashev, Andi Kleen, Jin Yao, Stephane Eranian,
	James Clark, Linux Kernel Mailing List

Em Thu, Aug 13, 2020 at 01:08:02PM +0100, John Garry escreveu:
> On 13/08/2020 12:18, Will Deacon wrote:
> > [ Adding John, as I only just realised he wasn't on CC and we were talking
> >    about him! ]
> > 
> > On Thu, Aug 13, 2020 at 10:59:01AM +0100, Will Deacon wrote:
> > > On Wed, Aug 12, 2020 at 03:53:34PM -0300, Arnaldo Carvalho de Melo wrote:
> > > > Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
> > > > > The ARM SPE perf tools code is orphan and I don't have the cycles to
> > > > > pick it up.  Leo has spent a lot of time in that code and as such I
> > > > > suggest that he starts maintaining it, probably following the same
> > > > > kind of arrangement you and I have for coresight.
> > > > 
> > > > Thats ok with me, I think we should reflect that on the MAINTAINERS
> > > > file, right?
> > > > 
> > > > We have this already:
> > > > 
> > > > PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
> > > > R:      John Garry <john.garry@huawei.com>
> > > > R:      Will Deacon <will@kernel.org>
> > > > L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
> > > > S:      Supported
> > > > F:      tools/perf/pmu-events/arch/arm64/
> > > > 
> > > > I think we should have entries for CoreSight and ARM SPE, one listing
> > > > you as the maintainer and the other listing Leo, right?
> > > 
> > > Fine by me. I'll continue to maintain the in-kernel SPE driver, but I'd love
> > > to see somebody step up to looking after the userspace code. It's seriously
> > > unloved on arm64 :(
> > > 
> > > I'd even be happy to see one or two M: entries added for
> > > tools/perf/pmu-events/arch/arm64/. I realistically don't have the time to
> > > take that on, but I'd be thrilled if any/all of John, Mathieu and Leo were
> > > to be listed there if they are willing to do so and can spare the time to
> > > look after it. Even just silly things like making sure the thing
> > > cross-compiles have been broken in the recent past, so it's not necessarily
> > > about handling huge amounts of incoming patches.
> > > 
> > > In other words, rather than slice up the arm64 parts of the perf tool, I'd
> > > argue in favour of a joint maintainership model for all the arm64 bits, if
> > > we have a few willing volunteers.
> 
> Right, it makes sense not to chop up too much, so happy to see "PERFORMANCE
> EVENTS SUBSYSTEM ARM64 PMU EVENTS" expanded in terms of scope and
> membership.

Discuss this as long as you need and then send me a patch for the
MAINTAINERS file with your conclusion.

Great to see this happening,

- Arnaldo

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

* Re: [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp
  2020-08-12 18:53   ` Arnaldo Carvalho de Melo
  2020-08-13  1:54     ` Leo Yan
  2020-08-13  9:59     ` Will Deacon
@ 2020-08-13 16:17     ` Mathieu Poirier
  2 siblings, 0 replies; 16+ messages in thread
From: Mathieu Poirier @ 2020-08-13 16:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Leo Yan, Ian Rogers, Will Deacon, Mark Rutland, Peter Zijlstra,
	Ingo Molnar, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Kemeng Shi, Naveen N. Rao, Adrian Hunter, Igor Lubashev,
	Andi Kleen, Jin Yao, Stephane Eranian, James Clark,
	Linux Kernel Mailing List

On Wed, 12 Aug 2020 at 12:53, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> Em Wed, Aug 12, 2020 at 10:06:53AM -0600, Mathieu Poirier escreveu:
> > Hi Arnaldo,
> >
> > On Fri, 7 Aug 2020 at 01:16, Leo Yan <leo.yan@linaro.org> wrote:
> > >
> > > This patch set is to enable Arm arch timer counter and Arm SPE is the
> > > first customer to use arch timer counter for its timestamp.
> > >
> > > Patches 01 ~ 03 enables Arm arch timer counter in Perf tool; patch 01 is
> > > to retrieve arch timer's parameters from mmaped page; patch 02 provides
> > > APIs for the conversion between arch timer's counter and time; patch 03
> > > adds a test for patches 01 and 02.
> > >
> > > As the first customer to use Arm arch timer counter in perf tool, patch
> > > 04 is to generate sample's timestamp for ARM SPE AUX trace data.
> > >
> > > This patch set has been rebased on perf/core branch with the latest
> > > commit c4735d990268 ("perf evsel: Don't set
> > > sample_regs_intr/sample_regs_user for dummy event").
> >
> > The ARM SPE perf tools code is orphan and I don't have the cycles to
> > pick it up.  Leo has spent a lot of time in that code and as such I
> > suggest that he starts maintaining it, probably following the same
> > kind of arrangement you and I have for coresight.
>
> Thats ok with me, I think we should reflect that on the MAINTAINERS
> file, right?
>

I agree, it is time to sort out this part.

> We have this already:
>
> PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
> R:      John Garry <john.garry@huawei.com>
> R:      Will Deacon <will@kernel.org>
> L:      linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
> S:      Supported
> F:      tools/perf/pmu-events/arch/arm64/
>
> I think we should have entries for CoreSight and ARM SPE, one listing
> you as the maintainer and the other listing Leo, right?
>

Yes - I'll send you a patch for that once v5.9-rc1 comes out (unless
you want it now).

> Leo, it would be good for you to try and find someone at your
> organization or elsewhere that could help with this, this way I would
> wait a bit, see if someone else Acks it, and collect those, processing
> it from you after a while if nobody chimes in.
>

Right, the same kind of arrangement you and I have for coresight.  So
far this has worked quite well and I don't see a need to proceed
differently.

> Please continue providing 'perf test' regression tests, etc, to help
> with maintaining this code being checked.

Those are quite useful.

>
> - Arnaldo
>
> > Thanks,
> > Mathieu
> >
> > >
> > > After changes:
> > >
> > >   # perf test 67 -v
> > >     67: Convert perf time to arch timer counter
> > >     --- start ---
> > >     test child forked, pid 5463
> > >     mmap size 528384B
> > >     1st event perf time 2231755083020 arch timer cnt 113097053477
> > >     test time           2231755087460 arch timer cnt 113097053699
> > >     2nd event perf time 2231755090680 arch timer cnt 113097053860
> > >     test child finished with 0
> > >     ---- end ----
> > >
> > >   Reports the SPE sample with timestamp:
> > >
> > >   $ perf script -F,+time
> > >     dd  6799 [034] 25496.733475:          1              l1d-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> > >     dd  6799 [034] 25496.733475:          1              tlb-access:      ffff87f37b88 _dl_start+0x288 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> > >     dd  6799 [034] 25496.733479:          1              l1d-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> > >     dd  6799 [034] 25496.733479:          1              tlb-access:      ffff87f37c74 _dl_start+0x374 (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> > >     dd  6799 [034] 25496.733485:          1              l1d-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> > >     dd  6799 [034] 25496.733485:          1              tlb-access:      ffff87f49af4 __GI___tunables_init+0x3c (/usr/lib/aarch64-linux-gnu/ld-2.28.so)
> > >
> > > Changes from v1:
> > > * Rebased on the latest perf/core branch;
> > > * Added a testing for Arm timer counter conversion (Ian Rogers).
> > >
> > >
> > > Leo Yan (4):
> > >   perf tools: Support Arm arch timer counter
> > >   perf arm_arch_timer: Convert between counter and timestamp
> > >   perf arm_arch_timer: Test conversion between counter and timestamp
> > >   perf arm-spe: Enable timestamp with arch timer counter
> > >
> > >  tools/perf/arch/arm64/include/arch-tests.h    |   6 +
> > >  tools/perf/arch/arm64/tests/Build             |   1 +
> > >  tools/perf/arch/arm64/tests/arch-tests.c      |   4 +
> > >  .../tests/perf-time-to-arch-timer-counter.c   | 189 ++++++++++++++++++
> > >  tools/perf/arch/arm64/util/Build              |   1 +
> > >  tools/perf/arch/arm64/util/arch_timer.c       |  50 +++++
> > >  tools/perf/arch/arm64/util/arm-spe.c          |  17 ++
> > >  tools/perf/util/Build                         |   1 +
> > >  tools/perf/util/arm-spe.c                     |  16 +-
> > >  tools/perf/util/arm-spe.h                     |   5 +
> > >  tools/perf/util/arm_arch_timer.c              |  28 +++
> > >  tools/perf/util/arm_arch_timer.h              |  23 +++
> > >  12 files changed, 339 insertions(+), 2 deletions(-)
> > >  create mode 100644 tools/perf/arch/arm64/tests/perf-time-to-arch-timer-counter.c
> > >  create mode 100644 tools/perf/arch/arm64/util/arch_timer.c
> > >  create mode 100644 tools/perf/util/arm_arch_timer.c
> > >  create mode 100644 tools/perf/util/arm_arch_timer.h
> > >
> > > --
> > > 2.17.1
> > >
>
> --
>
> - Arnaldo

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

* Re: [PATCH v2 1/4] perf tools: Support Arm arch timer counter
  2020-08-07  7:16 ` [PATCH v2 1/4] perf tools: Support Arm arch timer counter Leo Yan
@ 2020-08-20  2:56   ` liwei (GF)
  2020-08-21  9:36     ` Leo Yan
  0 siblings, 1 reply; 16+ messages in thread
From: liwei (GF) @ 2020-08-20  2:56 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel

Hi Leo

On 2020/8/7 15:16, Leo Yan wrote:
> The Arm arch timer can be used to calculate timestamp, the basic idea is
> the arch timer's counter value can be recorded in the hardware tracing
> data, e.g. the arch timer's counter value can be used for Arm CoreSight
> (not now but might be implemented later) and Arm SPE.  So we need a way
> to convert the arch timer's counter to the system time, the conversion
> is dependent on some related parameters, e.g. 'time_shift', 'time_mult',
> 'time_offset', etc; furthermore, to handle the counter wrapping issue,
> perf tool needs to know 'time_cycles' and 'time_mask' for correction.
> 
> This patch is to support Arm arch timer by reading out the relevant
> parameters from the head of first mmaped page.  And these parameters
> will be stored into the structure 'perf_arch_timer_conversion' for
> later calculation timestamp.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/arch/arm64/util/Build        |  1 +
>  tools/perf/arch/arm64/util/arch_timer.c | 50 +++++++++++++++++++++++++
>  tools/perf/util/arm_arch_timer.h        | 20 ++++++++++
>  3 files changed, 71 insertions(+)
>  create mode 100644 tools/perf/arch/arm64/util/arch_timer.c
>  create mode 100644 tools/perf/util/arm_arch_timer.h
> 
> diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build
> index 5c13438c7bd4..77f4d7b30932 100644
> --- a/tools/perf/arch/arm64/util/Build
> +++ b/tools/perf/arch/arm64/util/Build
> @@ -1,3 +1,4 @@
> +perf-y += arch_timer.o
>  perf-y += header.o
>  perf-y += machine.o
>  perf-y += perf_regs.o
> diff --git a/tools/perf/arch/arm64/util/arch_timer.c b/tools/perf/arch/arm64/util/arch_timer.c
> new file mode 100644
> index 000000000000..dcc217c294fc
> --- /dev/null
> +++ b/tools/perf/arch/arm64/util/arch_timer.c
> @@ -0,0 +1,50 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <stdbool.h>
> +#include <errno.h>
> +
> +#include <linux/stddef.h>
> +#include <linux/perf_event.h>
> +
> +#include <linux/types.h>
> +#include <asm/barrier.h>
> +#include "../../../util/debug.h"
> +#include "../../../util/event.h"
> +#include "../../../util/synthetic-events.h"
> +#include "../../../util/arm_arch_timer.h"
> +
> +int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
> +				    struct perf_arch_timer_conversion *tc)
> +{
> +	bool cap_user_time_zero, cap_user_time_short;
> +	u32 seq;
> +	int i = 0;
> +
> +	while (1) {
> +		seq = pc->lock;
> +		/* Add barrier between the sequence lock and data accessing */
> +		rmb();
> +
> +		tc->time_mult = pc->time_mult;
> +		tc->time_shift = pc->time_shift;
> +		tc->time_zero = pc->time_zero;
> +		tc->time_cycles = pc->time_cycles;
> +		tc->time_mask = pc->time_mask;
> +		cap_user_time_zero = pc->cap_user_time_zero;
> +		cap_user_time_short = pc->cap_user_time_short;
> +
> +		/* Add barrier between the data accessing and sequence lock */
> +		rmb();
> +		if (pc->lock == seq && !(seq & 1))
> +			break;
> +		if (++i > 10000) {
> +			pr_debug("%s: failed to get perf_event_mmap_page lock\n",
> +				 __func__);
> +			return -EINVAL;
> +		}
> +	}
> +
> +	if (!cap_user_time_zero || !cap_user_time_short)
> +		return -EOPNOTSUPP;
> +
> +	return 0;
> +}

Should we implement the perf_event__synth_time_conv() method? As it can be supported
on arm64 arch now.

These is also a tsc get method called rdtsc(), weak implementation in 'tools/perf/util/tsc.c',
maybe we should rename it to an arch independent name, and implement the arm64 version
(read_cntvct_el0 in patch 3) here. Thus we can also make the testcase generic,
instead of adding a new one for arm64 :).

Thanks,
Wei

> diff --git a/tools/perf/util/arm_arch_timer.h b/tools/perf/util/arm_arch_timer.h
> new file mode 100644
> index 000000000000..a3263cc4e5cf
> --- /dev/null
> +++ b/tools/perf/util/arm_arch_timer.h
> @@ -0,0 +1,20 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __PERF_ARM_ARCH_TIMER_H
> +#define __PERF_ARM_ARCH_TIMER_H
> +
> +#include <linux/types.h>
> +
> +struct perf_arch_timer_conversion {
> +	u16 time_shift;
> +	u32 time_mult;
> +	u64 time_zero;
> +	u64 time_cycles;
> +	u64 time_mask;
> +};
> +
> +struct perf_event_mmap_page;
> +
> +int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
> +				    struct perf_arch_timer_conversion *tc);
> +
> +#endif // __PERF_ARM_ARCH_TIMER_H
> 

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

* Re: [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp
  2020-08-07  7:16 ` [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp Leo Yan
@ 2020-08-20  3:05   ` liwei (GF)
  0 siblings, 0 replies; 16+ messages in thread
From: liwei (GF) @ 2020-08-20  3:05 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel

Hi Leo,

On 2020/8/7 15:16, Leo Yan wrote:
> This patch introduces two new APIs, one is to calculate from converting
> counter to timestamp and provides a reverse flow to convert timestamp
> to counter.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/util/Build            |  1 +
>  tools/perf/util/arm_arch_timer.c | 28 ++++++++++++++++++++++++++++
>  tools/perf/util/arm_arch_timer.h |  3 +++
>  3 files changed, 32 insertions(+)
>  create mode 100644 tools/perf/util/arm_arch_timer.c
> 
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 8d18380ecd10..ba504549844f 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -101,6 +101,7 @@ perf-y += call-path.o
>  perf-y += rwsem.o
>  perf-y += thread-stack.o
>  perf-y += spark.o
> +perf-y += arm_arch_timer.o
>  perf-$(CONFIG_AUXTRACE) += auxtrace.o
>  perf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
>  perf-$(CONFIG_AUXTRACE) += intel-pt.o
> diff --git a/tools/perf/util/arm_arch_timer.c b/tools/perf/util/arm_arch_timer.c
> new file mode 100644
> index 000000000000..c37ffa4d9710
> --- /dev/null
> +++ b/tools/perf/util/arm_arch_timer.c
> @@ -0,0 +1,28 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <linux/compiler.h>
> +#include <linux/types.h>
> +
> +#include "arm_arch_timer.h"
> +
> +u64 perf_time_to_arch_timer_cyc(u64 ns, struct perf_arch_timer_conversion *tc)
> +{
> +	u64 t, quot, rem;
> +
> +	t = ns - tc->time_zero;
> +	quot = t / tc->time_mult;
> +	rem  = t % tc->time_mult;
> +	return (quot << tc->time_shift) +
> +	       (rem << tc->time_shift) / tc->time_mult;
> +}
> +
> +u64 arch_timer_cyc_to_perf_time(u64 cyc, struct perf_arch_timer_conversion *tc)
> +{
> +	u64 quot, rem;
> +
> +	cyc = tc->time_cycles + ((cyc - tc->time_cycles) & tc->time_mask);
> +
> +	quot = cyc >> tc->time_shift;
> +	rem  = cyc & (((u64)1 << tc->time_shift) - 1);
> +	return tc->time_zero + quot * tc->time_mult +
> +	       ((rem * tc->time_mult) >> tc->time_shift);
> +}

Can we merge these methods with 'tools/perf/util/tsc.c'?  I think the converting
between arch timestamp and the perf time should be arch independent. And in fact, we
have built tsc_to_perf_time() into the perf on arm64. So maybe we can add
cap_user_time_xxx into 'struct perf_tsc_conversion', then dispatch for different
capabilities.

Thanks,
Wei

> diff --git a/tools/perf/util/arm_arch_timer.h b/tools/perf/util/arm_arch_timer.h
> index a3263cc4e5cf..7d9271f544f2 100644
> --- a/tools/perf/util/arm_arch_timer.h
> +++ b/tools/perf/util/arm_arch_timer.h
> @@ -17,4 +17,7 @@ struct perf_event_mmap_page;
>  int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
>  				    struct perf_arch_timer_conversion *tc);
>  
> +u64 arch_timer_cyc_to_perf_time(u64 cyc, struct perf_arch_timer_conversion *tc);
> +u64 perf_time_to_arch_timer_cyc(u64 ns, struct perf_arch_timer_conversion *tc);
> +
>  #endif // __PERF_ARM_ARCH_TIMER_H
> 

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

* Re: [PATCH v2 1/4] perf tools: Support Arm arch timer counter
  2020-08-20  2:56   ` liwei (GF)
@ 2020-08-21  9:36     ` Leo Yan
  0 siblings, 0 replies; 16+ messages in thread
From: Leo Yan @ 2020-08-21  9:36 UTC (permalink / raw)
  To: liwei (GF)
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Will Deacon, Mark Rutland,
	Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Kemeng Shi, Naveen N. Rao, Adrian Hunter,
	Mathieu Poirier, Igor Lubashev, Andi Kleen, Jin Yao,
	Stephane Eranian, James Clark, linux-kernel

Hi Wei,

On Thu, Aug 20, 2020 at 10:56:46AM +0800, liwei (GF) wrote:

[...]

> > +int perf_read_arch_timer_conversion(const struct perf_event_mmap_page *pc,
> > +				    struct perf_arch_timer_conversion *tc)
> > +{
> > +	bool cap_user_time_zero, cap_user_time_short;
> > +	u32 seq;
> > +	int i = 0;
> > +
> > +	while (1) {
> > +		seq = pc->lock;
> > +		/* Add barrier between the sequence lock and data accessing */
> > +		rmb();
> > +
> > +		tc->time_mult = pc->time_mult;
> > +		tc->time_shift = pc->time_shift;
> > +		tc->time_zero = pc->time_zero;
> > +		tc->time_cycles = pc->time_cycles;
> > +		tc->time_mask = pc->time_mask;
> > +		cap_user_time_zero = pc->cap_user_time_zero;
> > +		cap_user_time_short = pc->cap_user_time_short;
> > +
> > +		/* Add barrier between the data accessing and sequence lock */
> > +		rmb();
> > +		if (pc->lock == seq && !(seq & 1))
> > +			break;
> > +		if (++i > 10000) {
> > +			pr_debug("%s: failed to get perf_event_mmap_page lock\n",
> > +				 __func__);
> > +			return -EINVAL;
> > +		}
> > +	}
> > +
> > +	if (!cap_user_time_zero || !cap_user_time_short)
> > +		return -EOPNOTSUPP;
> > +
> > +	return 0;
> > +}
> 
> Should we implement the perf_event__synth_time_conv() method? As it can be supported
> on arm64 arch now.

Thanks a lot for pointing out, agree that we should implement
perf_event__synth_time_conv() for Arm64.  Will do it in next spin.

> These is also a tsc get method called rdtsc(), weak implementation in 'tools/perf/util/tsc.c',
> maybe we should rename it to an arch independent name, and implement the arm64 version
> (read_cntvct_el0 in patch 3) here.

If connect with your comment in patch 02, I think you are asking to
consolidate for TSC common APIs and operations.  I took time to review
the codes for conversion between timer counter and time stamp, your
suggestion is reasonable and feasible for me.

But the consolidation will impact the existed x86 implementation, before
proceed to this direction for the next patch set, I'd like to get some
review from x86's developers.

@PeterZ, could you take a look for this and let me know if you have any
concern for the consolidation?

> Thus we can also make the testcase generic,
> instead of adding a new one for arm64 :).

Exactly.  Will do this if we get agreement for consolidation.

Thanks for the reviewing,
Leo

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

end of thread, other threads:[~2020-08-21  9:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07  7:16 [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
2020-08-07  7:16 ` [PATCH v2 1/4] perf tools: Support Arm arch timer counter Leo Yan
2020-08-20  2:56   ` liwei (GF)
2020-08-21  9:36     ` Leo Yan
2020-08-07  7:16 ` [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp Leo Yan
2020-08-20  3:05   ` liwei (GF)
2020-08-07  7:16 ` [PATCH v2 3/4] perf arm_arch_timer: Test conversion " Leo Yan
2020-08-07  7:16 ` [PATCH v2 4/4] perf arm-spe: Enable timestamp with arch timer counter Leo Yan
2020-08-12 16:06 ` [PATCH v2 0/4] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Mathieu Poirier
2020-08-12 18:53   ` Arnaldo Carvalho de Melo
2020-08-13  1:54     ` Leo Yan
2020-08-13  9:59     ` Will Deacon
2020-08-13 11:18       ` Will Deacon
2020-08-13 12:08         ` John Garry
2020-08-13 13:05           ` Arnaldo Carvalho de Melo
2020-08-13 16:17     ` Mathieu Poirier

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