mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Kemeng Shi <shikemeng@huawei.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Ian Rogers <irogers@google.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Igor Lubashev <ilubashe@akamai.com>,
	Andi Kleen <ak@linux.intel.com>,
	Jin Yao <yao.jin@linux.intel.com>,
	James Clark <james.clark@arm.com>,
	linux-kernel@vger.kernel.org
Cc: Leo Yan <leo.yan@linaro.org>
Subject: [PATCH v1 1/3] perf tools: Support Arm arch timer counter
Date: Wed, 15 Jul 2020 10:33:59 +0800	[thread overview]
Message-ID: <20200715023401.23988-2-leo.yan@linaro.org> (raw)
In-Reply-To: <20200715023401.23988-1-leo.yan@linaro.org>

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


  reply	other threads:[~2020-07-15  2:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-15  2:33 [PATCH v1 0/3] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Leo Yan
2020-07-15  2:33 ` Leo Yan [this message]
2020-07-15  2:34 ` [PATCH v1 2/3] perf arm_arch_timer: Convert between counter and timestamp Leo Yan
2020-07-15  2:34 ` [PATCH v1 3/3] perf arm-spe: Enable timestamp with arch timer counter Leo Yan
2020-07-15 16:31 ` [PATCH v1 0/3] Perf tool: Enable Arm arch timer counter and arm-spe's timestamp Ian Rogers
2020-07-16  1:17   ` Leo Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200715023401.23988-2-leo.yan@linaro.org \
    --to=leo.yan@linaro.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ilubashe@akamai.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=shikemeng@huawei.com \
    --cc=yao.jin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®