lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 15 Jul 2020 10:34:00 +0800
From:   Leo Yan <leo.yan@...aro.org>
To:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Kemeng Shi <shikemeng@...wei.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Ian Rogers <irogers@...gle.com>,
        Mathieu Poirier <mathieu.poirier@...aro.org>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Igor Lubashev <ilubashe@...mai.com>,
        Andi Kleen <ak@...ux.intel.com>,
        Jin Yao <yao.jin@...ux.intel.com>,
        James Clark <james.clark@....com>, linux-kernel@...r.kernel.org
Cc:     Leo Yan <leo.yan@...aro.org>
Subject: [PATCH v1 2/3] perf arm_arch_timer: Convert between counter and timestamp

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@...aro.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ