Re: [PATCH v2 2/4] perf arm_arch_timer: Convert between counter and timestamp
From: liwei (GF)
Date: Wed Aug 19 2020 - 23:05:30 EST
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@xxxxxxxxxx>
> ---
> 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
>