Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Feb 2021 21:42:11 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: bbcdd9faca55 - stable/13 - Reimplemen FreeBSD/arm64 dtrace_gethrtime() to use the system timer. dtrace_gethrtime() is the high-resolution nanosecond timestemp used for the DTrace 'timestamp' built-in variable. The new implementation uses the EL0 cycle counter and frequency registers in ARMv8-A. This replaces a previous implementation that relied on an instrumentation-safe implementation of getnanotime(), which provided only timer resolution.
Message-ID:  <202102252142.11PLgBUi046599@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by rwatson:

URL: https://cgit.FreeBSD.org/src/commit/?id=bbcdd9faca55758b228b949f1c1bb41b85e90a8e

commit bbcdd9faca55758b228b949f1c1bb41b85e90a8e
Author:     Robert Watson <rwatson@FreeBSD.org>
AuthorDate: 2021-02-16 15:19:05 +0000
Commit:     Robert Watson <rwatson@FreeBSD.org>
CommitDate: 2021-02-25 21:38:30 +0000

    Reimplemen FreeBSD/arm64 dtrace_gethrtime() to use the system timer.
    dtrace_gethrtime() is the high-resolution nanosecond timestemp used
    for the DTrace 'timestamp' built-in variable.  The new implementation
    uses the EL0 cycle counter and frequency registers in ARMv8-A.  This
    replaces a previous implementation that relied on an
    instrumentation-safe implementation of getnanotime(), which provided
    only timer resolution.
    
    Approved by:    re (gjb)
    Reviewed by:    andrew, bsdimp (older version)
    Useful comments appreciated:    jrtc27, emaste
    Differential Revision:  https://reviews.freebsd.org/D28723
---
 sys/cddl/dev/dtrace/aarch64/dtrace_subr.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c b/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c
index 6646e51fc191..9bf9f0798bb5 100644
--- a/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c
+++ b/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c
@@ -153,23 +153,26 @@ dtrace_sync(void)
 }
 
 /*
- * DTrace needs a high resolution time function which can
- * be called from a probe context and guaranteed not to have
- * instrumented with probes itself.
+ * DTrace needs a high resolution time function which can be called from a
+ * probe context and guaranteed not to have instrumented with probes itself.
  *
- * Returns nanoseconds since boot.
+ * Returns nanoseconds since some arbitrary point in time (likely SoC reset?).
  */
 uint64_t
-dtrace_gethrtime()
+dtrace_gethrtime(void)
 {
-	struct timespec curtime;
-
-	dtrace_getnanouptime(&curtime);
-
-	return (curtime.tv_sec * 1000000000UL + curtime.tv_nsec);
+	uint64_t count, freq;
 
+	count = READ_SPECIALREG(cntvct_el0);
+	freq = READ_SPECIALREG(cntfrq_el0);
+	return ((1000000000UL * count) / freq);
 }
 
+/*
+ * Return a much lower resolution wallclock time based on the system clock
+ * updated by the timer.  If needed, we could add a version interpolated from
+ * the system clock as is the case with dtrace_gethrtime().
+ */
 uint64_t
 dtrace_gethrestime(void)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102252142.11PLgBUi046599>