Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Nov 2022 09:07:23 -0500
From:      Mark Johnston <markj@freebsd.org>
To:        Mateusz Piotrowski <0mp@freebsd.org>
Cc:        freebsd-dtrace@freebsd.org
Subject:   Re: In DTrace, why does timestamp increase after a call to chill() but vtimestamp and walltimestamp do not?
Message-ID:  <Y34pG8Hdt6Ku5pM6@nuc>
In-Reply-To: <F2030DBF-E15F-40BB-90D8-394EF6331FDC@FreeBSD.org>
References:  <F2030DBF-E15F-40BB-90D8-394EF6331FDC@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 21, 2022 at 06:19:16PM +0100, Mateusz Piotrowski wrote:
> Hello all,
> 
> I'd like to understand why calling chill() in a DTrace action block increases the timestampvariable, but not vtimestamp and walltimestamp.
> Here's an example showing timestamp increasing after a call to chill():

I think you found a bug in dtrace.  When a dtrace probe fires and
actions attached to that probe are executed, the value of *timestamp is
cached in a struct dtrace_mstate on the firing CPU's stack.  This means
that in D, within a probe body, multiple accesses of *timestamp will
return the same cached value.

As it turns out, the implementation of chill() will invalidate that
cached value, but only for "timestamp", not for walltimestamp, which
seems incorrect.  Below is an untested patch which should fix your
example.

I think the behaviour of vtimestamp that you observe is expected.  From
the description, "The counter does not include the time that is spent in
DTrace predicates and actions", so I wouldn't expect it to advance while
dtrace_probe() is running.  And indeed, it gets advanced once at the
beginning of dtrace_probe().

diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
index 44a85db65117..cd6ed332af7b 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
@@ -7082,11 +7082,12 @@ dtrace_action_chill(dtrace_mstate_t *mstate, hrtime_t val)
 		continue;
 
 	/*
-	 * Normally, we assure that the value of the variable "timestamp" does
-	 * not change within an ECB.  The presence of chill() represents an
-	 * exception to this rule, however.
+	 * Normally, we assure that the value of the variables "timestamp" and
+	 * "walltimestamp" do not change within an ECB.  The presence of chill()
+	 * represents an exception to this rule, however.
 	 */
-	mstate->dtms_present &= ~DTRACE_MSTATE_TIMESTAMP;
+	mstate->dtms_present &=
+	    ~(DTRACE_MSTATE_TIMESTAMP | DTRACE_MSTATE_WALLTIMESTAMP);
 	cpu->cpu_dtrace_chilled += val;
 }
 



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