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 2/3] perf arm_arch_timer: Convert between counter and timestamp
Date: Wed, 15 Jul 2020 10:34:00 +0800 [thread overview]
Message-ID: <20200715023401.23988-3-leo.yan@linaro.org> (raw)
In-Reply-To: <20200715023401.23988-1-leo.yan@linaro.org>
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
next prev parent 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 ` [PATCH v1 1/3] perf tools: Support Arm arch timer counter Leo Yan
2020-07-15 2:34 ` Leo Yan [this message]
2020-07-15 2:34 ` [PATCH v1 3/3] perf arm-spe: Enable timestamp with " 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-3-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®