Skip to content

Commit

Permalink
Reimplement the arm64 dtrace_gethrtime(), which provides the
Browse files Browse the repository at this point in the history
high-resolution nanosecond timestamp 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.

MFC after:	3 days
Reviewed by:	andrew, bsdimp (older version)
Useful comments appreciated:	jrtc27, emaste
  • Loading branch information
rwatson committed Feb 19, 2021
1 parent 50b7c1f commit c3feaea
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions sys/cddl/dev/dtrace/aarch64/dtrace_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit c3feaea

Please sign in to comment.