Skip to contentSkip to conversation

Fix stack-skip counts for caller and stackdepth

PATCH Superseded [email protected] 3 participants 41 messages May 22, 2025 – Jun 25, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/14 Fix stack-skip counts for caller and stackdepth

From: Eugene Loh <[email protected]>

Apparently, when we call the BPF get_stack() helper function, it generally knows how many frames to skip to get the real kernel stack. For fentry/fexit, however, this is apparently not the case, and commit bc65cb44d
("cg: allow providers to specify a skip count for stack retrieval") added the ability to skip frames for fentry/fexit probes.

When this "skip" is needed, however, it must must be even deeper when we descend further frames, such as when we call dt_bpf_*() precompiled functions.

Add this support for dt_bpf_caller() and dt_bpf_stackdepth(). That is, if there are stack-skip frames, skip yet one more frame when inside a bpf/get_bvar.c function.

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

---
 bpf/get_bvar.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
bpf/get_bvar.c +14 -3
index 9625e764e..99a6503d5 100644
@@ -53,12 +53,17 @@ noinline uint64_t dt_bvar_args(const dt_dctx_t *dctx, uint32_t idx)
 
 noinline uint64_t dt_bvar_caller(const dt_dctx_t *dctx)
 {
-	uint64_t	buf[2] = { 0, };
+	uint64_t	buf[3] = { 0, };
+	volatile uint64_t
+			skip = (uint64_t)(&STACK_SKIP);
 
 	if (bpf_get_stack(dctx->ctx, buf, sizeof(buf),
-			  (uint64_t)(&STACK_SKIP) & BPF_F_SKIP_FIELD_MASK) < 0)
+			  skip & BPF_F_SKIP_FIELD_MASK) < 0)
 		return 0;
 
+	/* If we had to skip any frames, account for the dt_bvar_caller() frame. */
+	if (skip)
+		return buf[2];
 	return buf[1];
 }
 
@@ -203,9 +208,11 @@ noinline uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
 	uint32_t	bufsiz = (uint32_t) (uint64_t) (&STKSIZ);
 	char		*buf = dctx->mem + (uint64_t)(&STACK_OFF);
 	uint64_t	retv;
+	volatile uint64_t
+			skip = (uint64_t)(&STACK_SKIP);
 
 	retv = bpf_get_stack(dctx->ctx, buf, bufsiz,
-			     (uint64_t)(&STACK_SKIP) & BPF_F_SKIP_FIELD_MASK);
+			     skip & BPF_F_SKIP_FIELD_MASK);
 	if (retv < 0)
 		return error(dctx, DTRACEFLT_BADSTACK, 0 /* FIXME */);
 
@@ -217,7 +224,11 @@ noinline uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
 	 * If retv==bufsiz, presumably the stack is larger than what we
 	 * can retrieve.  But it's also possible that the buffer was exactly
 	 * large enough.  So, leave it to the user to interpret the result.
+	 *
+	 * If we had to skip any frames, account for the dt_bvar_stackdepth() frame.
 	 */
+	if (skip)
+		return retv / sizeof(uint64_t) - 1;
 	return retv / sizeof(uint64_t);
 }
 
Signature · 1 line
2.43.5
#1 lore raw

PATCH 2/14 Add stack-skip frame count for rawtp provider

From: Eugene Loh <[email protected]>

---
 libdtrace/dt_prov_rawtp.c | 1 +
 1 file changed, 1 insertion(+)
libdtrace/dt_prov_rawtp.c +1 -0
index f1d3b6bc4..a36bb51f4 100644
@@ -296,6 +296,7 @@ use_alt:
 dt_provimpl_t	dt_rawtp = {
 	.name		= prvname,
 	.prog_type	= BPF_PROG_TYPE_RAW_TRACEPOINT,
+	.stack_skip	= 4,
 	.populate	= &populate,
 	.load_prog	= &dt_bpf_prog_load,
 	.trampoline	= &trampoline,
Signature · 1 line
2.43.5
Reviewed-by on v1 2/14
#2 lore raw

Re: [PATCH 02/14] Add stack-skip frame count for rawtp provider

On 22 May 2025, eugene loh outgrape:

Quoted 3 lines

From: Eugene Loh <[email protected]>

(looking back, 4 is the right figure. If it's wrong, the tests will tell us, anyway -- presumably we hope that the underlying bug is fixed before it changes in the future and requires us to make this a per-kernel-release value...)

Signature · 1 line
NULL && (void)
#3 lore raw

PATCH 3/14 Test: remove unnecessary "unstable" tag

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 test/unittest/sched/tst.stackdepth.d | 1 -
 1 file changed, 1 deletion(-)
test/unittest/sched/tst.stackdepth.d +0 -1
index 02a878bea..e6ffca01c 100644
@@ -4,7 +4,6 @@
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
-/* @@tags: unstable */
 
 #pragma D option switchrate=100hz
 
Signature · 1 line
2.43.5
#5 lore raw

PATCH 4/14 Test: caller and stackdepth tests for fbt provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

We will introduce a set of tests for the caller and stackdepth built-in variables for a wide selection of providers.

For the caller test, we will essentially call

        stack(2);
        sym(caller);

and then compare the caller to the second stack frame using the new script check_caller_to_stack2.awk.

For the stackdepth test, we will essentially call

        printf("%d\n", stackdepth);
        stack();

and then compare the stackdepth to the reported frames using the new script check_stackdepth_to_stack.awk.

In this patch, introduce tests for the fbt provider, along with the support scripts they need. Subsequent patches will handle other providers.

The old tst.caller2.d and tst.stackdepth2.d, which tested fbt, become obsolete. Remove them.

---
 .../variables/bvar/check_caller_to_stack2.awk | 32 +++++++++++++++++
 ...pth2.r.p => check_stackdepth_to_stack.awk} | 16 ++++++---
 test/unittest/variables/bvar/tst.caller-fbt.d | 25 +++++++++++++
 test/unittest/variables/bvar/tst.caller-fbt.r |  1 +
 .../variables/bvar/tst.caller-fbt.r.p         |  1 +
 test/unittest/variables/bvar/tst.caller2.d    | 31 ----------------
 test/unittest/variables/bvar/tst.caller2.r    |  1 -
 test/unittest/variables/bvar/tst.caller2.r.p  | 11 ------
 .../variables/bvar/tst.stackdepth-fbt.d       | 27 ++++++++++++++
 ...tst.stackdepth2.r => tst.stackdepth-fbt.r} |  0
 .../variables/bvar/tst.stackdepth-fbt.r.p     |  1 +
 .../unittest/variables/bvar/tst.stackdepth2.d | 36 -------------------
 12 files changed, 99 insertions(+), 83 deletions(-)
 create mode 100755 test/unittest/variables/bvar/check_caller_to_stack2.awk
 rename test/unittest/variables/bvar/{tst.stackdepth2.r.p => check_stackdepth_to_stack.awk} (63%)
 create mode 100644 test/unittest/variables/bvar/tst.caller-fbt.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-fbt.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-fbt.r.p
 delete mode 100644 test/unittest/variables/bvar/tst.caller2.d
 delete mode 100644 test/unittest/variables/bvar/tst.caller2.r
 delete mode 100755 test/unittest/variables/bvar/tst.caller2.r.p
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-fbt.d
 rename test/unittest/variables/bvar/{tst.stackdepth2.r => tst.stackdepth-fbt.r} (100%)
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-fbt.r.p
 delete mode 100644 test/unittest/variables/bvar/tst.stackdepth2.d
test/unittest/variables/bvar/check_caller_to_stack2.awk new file +32 -0
new file mode 100755
index 000000000..8499852a7
@@ -0,0 +1,32 @@
+#!/usr/bin/gawk -f
+
+# Check output of tst.caller-$provider.d tests of the form
+#
+# {
+#     stack(2);
+#     sym(caller);
+# }
+#
+# Confirm that the caller information matches the stack information.
+
+# Look for the first nonblank line.
+NF != 0 {
+	# It is the current frame.  Skip it.
+	if (getline != 1) { print "ERROR: missing expected output"; exit(1); }
+
+	# Now we have the caller frame.  Strip off the offset.
+	expect=$1
+	sub("+0x[0-9a-f]*$", "", expect);
+
+	# Finally, get the sym(caller) output.
+	if (getline != 1) { print "ERROR: missing expected output"; exit(1); }
+
+	# Compare.
+	if (expect == $1) {
+		print "success";
+		exit(0);
+	} else {
+		print "ERROR: expect", expect, "but got", $1;
+		exit(1);
+	}
+}
test/unittest/variables/bvar/check_stackdepth_to_stack.awk renamed from test/unittest/variables/bvar/tst.stackdepth2.r.p +12 -4
similarity index 63%
rename from test/unittest/variables/bvar/tst.stackdepth2.r.p
rename to test/unittest/variables/bvar/check_stackdepth_to_stack.awk
index 9b071181f..fba1f4242 100755
@@ -1,8 +1,16 @@
 #!/usr/bin/gawk -f
-# Oracle Linux DTrace.
-# Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
-# Licensed under the Universal Permissive License v 1.0 as shown at
-# http://oss.oracle.com/licenses/upl.
+#
+# Check output of tst.stackdepth-$provider.d tests of the form
+#
+# {
+#     printf("DEPTH %d\n", stackdepth);
+#     printf("TRACE BEGIN\n");
+#     stack();
+#     printf("TRACE END\n");
+#     exit(0);
+# }
+#
+# Confirm that the stackdepth information matches the stack information.
 
 /^DEPTH/ {
 	depth = int($2);
test/unittest/variables/bvar/tst.caller-fbt.d new file +25 -0
new file mode 100644
index 000000000..695104134
@@ -0,0 +1,25 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+fbt::ksys_write:entry
+/pid == $target/
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-fbt.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-fbt.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.caller2.d deleted +0 -31
deleted file mode 100644
index ca6dbfd22..000000000
@@ -1,31 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-/*
- * ASSERTION: The 'caller' should be consistent with stack().
- *
- * SECTION: Variables/Built-in Variables/caller
- */
-
-#pragma D option quiet
-#pragma D option destructive
-
-BEGIN
-{
-        system("echo write something > /dev/null");
-}
-
-fbt::ksys_write:entry
-{
-	stack(2);
-	sym(caller);
-	exit(0);
-}
-
-ERROR {
-	exit(1);
-}
test/unittest/variables/bvar/tst.caller2.r deleted +0 -1
deleted file mode 100644
index 0cfbf0888..000000000
@@ -1 +0,0 @@
-2
test/unittest/variables/bvar/tst.caller2.r.p deleted +0 -11
deleted file mode 100755
index 1a26a4df2..000000000
@@ -1,11 +0,0 @@
-#!/bin/bash
-
-# sed:  remove +0x{ptr} offsets
-# awk:  look for the ksys_write frame, then write the next two lines
-# uniq:  count unique lines
-# awk:  report the counts
-
-sed 's/+0x.*$//' \
-| /usr/bin/gawk '/ksys_write/ {getline; print $1; getline; print $1; exit(0)}' \
-| uniq -c \
-| /usr/bin/gawk '{print $1}'
test/unittest/variables/bvar/tst.stackdepth-fbt.d new file +27 -0
new file mode 100644
index 000000000..10b05399e
@@ -0,0 +1,27 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+fbt::ksys_write:entry
+/pid == $target/
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-fbt.r renamed from test/unittest/variables/bvar/tst.stackdepth2.r +0 -0
similarity index 100%
rename from test/unittest/variables/bvar/tst.stackdepth2.r
rename to test/unittest/variables/bvar/tst.stackdepth-fbt.r
test/unittest/variables/bvar/tst.stackdepth-fbt.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth2.d deleted +0 -36
deleted file mode 100644
index 2b1c0866a..000000000
@@ -1,36 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-#pragma D option destructive
-#pragma D option quiet
-
-/*
- * ASSERTION:
- *   Test the stackdepth variable.  Verify its value against the stack trace.
- *
- * SECTION: Variables/Built-in Variables
- *
- */
-
-BEGIN
-{
-	system("echo write something > /dev/null");
-}
-
-fbt::ksys_write:entry
-{
-	printf("DEPTH %d\n", stackdepth);
-	printf("TRACE BEGIN\n");
-	stack();
-	printf("TRACE END\n");
-	exit(0);
-}
-
-ERROR
-{
-	exit(1);
-}
Signature · 1 line
2.43.5
Reviewed-by on v1 4/14
#6 lore raw

Re: [DTrace-devel] [PATCH 04/14] Test: caller and stackdepth tests for fbt provider

On 22 May 2025, eugene loh uttered the following:

Quoted 17 lines

From: Eugene Loh <[email protected]>

We will introduce a set of tests for the caller and stackdepth built-in variables for a wide selection of providers.

For the caller test, we will essentially call

        stack(2);
        sym(caller);

and then compare the caller to the second stack frame using the new script check_caller_to_stack2.awk.

For the stackdepth test, we will essentially call

        printf("%d\n", stackdepth);
        stack();

and then compare the stackdepth to the reported frames using the new script check_stackdepth_to_stack.awk.

Quoted 6 lines

In this patch, introduce tests for the fbt provider, along with the support scripts they need. Subsequent patches will handle other providers.

The old tst.caller2.d and tst.stackdepth2.d, which tested fbt, become obsolete. Remove them.

Nice! My only caveat (easily fixed) is that the old tests had header comments saying what they were testing, while the new ones don't. (Yes, the awk scripts do make it clearer, but still...)

Quoted 1 line
Signature · 1 line
NULL && (void)
author
#7 lore raw

Re: [DTrace-devel] [PATCH 04/14] Test: caller and stackdepth tests for fbt provider

Quoted 23 lines · Nick Alcock

On 22 May 2025, eugene loh uttered the following:

Quoted 21 lines

From: Eugene Loh <[email protected]>

We will introduce a set of tests for the caller and stackdepth built-in variables for a wide selection of providers.

For the caller test, we will essentially call

         stack(2);
         sym(caller);

and then compare the caller to the second stack frame using the new script check_caller_to_stack2.awk.

For the stackdepth test, we will essentially call

         printf("%d\n", stackdepth);
         stack();

and then compare the stackdepth to the reported frames using the new script check_stackdepth_to_stack.awk.

In this patch, introduce tests for the fbt provider, along with the support scripts they need. Subsequent patches will handle other providers.

Quoted 5 lines
Quoted 2 lines

The old tst.caller2.d and tst.stackdepth2.d, which tested fbt, become obsolete. Remove them.

Nice! My only caveat (easily fixed) is that the old tests had header comments saying what they were testing, while the new ones don't. (Yes, the awk scripts do make it clearer, but still...)

Got it.  I'll add a brief comment.

Quoted 3 lines
Quoted 1 line
#8 lore raw

Re: [DTrace-devel] [PATCH 04/14] Test: caller and stackdepth tests for fbt provider

Quoted 25 lines · Eugene Loh
Quoted 23 lines · Nick Alcock

On 22 May 2025, eugene loh uttered the following:

Quoted 21 lines

From: Eugene Loh <[email protected]>

We will introduce a set of tests for the caller and stackdepth built-in variables for a wide selection of providers.

For the caller test, we will essentially call

         stack(2);
         sym(caller);

and then compare the caller to the second stack frame using the new script check_caller_to_stack2.awk.

For the stackdepth test, we will essentially call

         printf("%d\n", stackdepth);
         stack();

and then compare the stackdepth to the reported frames using the new script check_stackdepth_to_stack.awk.

In this patch, introduce tests for the fbt provider, along with the support scripts they need. Subsequent patches will handle other providers.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

The old tst.caller2.d and tst.stackdepth2.d, which tested fbt, become obsolete. Remove them.

Nice! My only caveat (easily fixed) is that the old tests had header comments saying what they were testing, while the new ones don't. (Yes, the awk scripts do make it clearer, but still...)

Got it.  I'll add a brief comment.

Can you please post the updated v2 patch ASAP so I can merge the series?

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
#9 lore raw

PATCH 5/14 Test: caller and stackdepth tests for dtrace provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

Also, a few old tests, which tested caller and stackdepth using the dtrace provider, are now superfluous given the new, provider-named tests. The old tests were extremely lenient -- e.g., simply checking that these built-in variables were not -1, even though both variables are unsigned anyhow!

---
 test/unittest/builtinvar/tst.caller.d         | 25 -------------------
 .../variables/bvar/tst.caller-dtrace.d        | 19 ++++++++++++++
 .../variables/bvar/tst.caller-dtrace.r        |  1 +
 test/unittest/variables/bvar/tst.caller.d     | 23 -----------------
 .../variables/bvar/tst.stackdepth-dtrace.d    | 22 ++++++++++++++++
 .../variables/bvar/tst.stackdepth-dtrace.r    |  5 ++++
 test/unittest/variables/bvar/tst.stackdepth.d | 23 -----------------
 7 files changed, 47 insertions(+), 71 deletions(-)
 delete mode 100644 test/unittest/builtinvar/tst.caller.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-dtrace.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-dtrace.r
 delete mode 100644 test/unittest/variables/bvar/tst.caller.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-dtrace.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-dtrace.r
 delete mode 100644 test/unittest/variables/bvar/tst.stackdepth.d
test/unittest/builtinvar/tst.caller.d deleted +0 -25
deleted file mode 100644
index 19a4bab9e..000000000
@@ -1,25 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-/*
- * ASSERTION: print 'caller' and make sure it succeeds.
- *
- * SECTION: Variables/Built-in Variables
- */
-
-#pragma D option quiet
-
-BEGIN
-{
-	printf("The caller is %u\n", caller);
-	exit(0);
-}
-
-ERROR
-{
-	exit(1);
-}
test/unittest/variables/bvar/tst.caller-dtrace.d new file +19 -0
new file mode 100644
index 000000000..d69386930
@@ -0,0 +1,19 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+BEGIN {
+	trace(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-dtrace.r new file +1 -0
new file mode 100644
index 000000000..573541ac9
@@ -0,0 +1 @@
+0
test/unittest/variables/bvar/tst.caller.d deleted +0 -23
deleted file mode 100644
index 3d64fa98c..000000000
@@ -1,23 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-/*
- * ASSERTION: The 'caller' variable can be accessed and is not -1.
- *
- * SECTION: Variables/Built-in Variables/caller
- */
-
-#pragma D option quiet
-
-BEGIN {
-	trace(caller);
-	exit(caller != -1 ? 0 : 1);
-}
-
-ERROR {
-	exit(1);
-}
test/unittest/variables/bvar/tst.stackdepth-dtrace.d new file +22 -0
new file mode 100644
index 000000000..f0f828f23
@@ -0,0 +1,22 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+BEGIN {
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack();
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-dtrace.r new file +5 -0
new file mode 100644
index 000000000..1afb1f057
@@ -0,0 +1,5 @@
+DEPTH 0
+TRACE BEGIN
+
+TRACE END
+
test/unittest/variables/bvar/tst.stackdepth.d deleted +0 -23
deleted file mode 100644
index ad728fd85..000000000
@@ -1,23 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-/*
- * ASSERTION: The 'stackdepth' variable can be accessed and is not -1.
- *
- * SECTION: Variables/Built-in Variables/stackdepth
- */
-
-#pragma D option quiet
-
-BEGIN {
-	trace(stackdepth);
-	exit(stackdepth != -1 ? 0 : 1);
-}
-
-ERROR {
-	exit(1);
-}
Signature · 1 line
2.43.5
Reviewed-by on v1 5/14
#10 lore raw

Re: [PATCH 05/14] Test: caller and stackdepth tests for dtrace provider

Quoted 9 lines · eugene loh

From: Eugene Loh <[email protected]>

Also, a few old tests, which tested caller and stackdepth using the dtrace provider, are now superfluous given the new, provider-named tests. The old tests were extremely lenient -- e.g., simply checking that these built-in variables were not -1, even though both variables are unsigned anyhow!

(with the same comments regarding the old tests having a description of what they were testing, and could the new ones do the same?)

Signature · 1 line
NULL && (void)
#11 lore raw

PATCH 6/14 Test: caller and stackdepth tests for rawtp provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

Also, add skip_rawtp_old.x, to skip rawtp testing on older kernels for the reasons described in the file.

---
 test/unittest/variables/bvar/skip_rawtp_old.x | 31 +++++++++++++++++++
 .../variables/bvar/tst.caller-rawtp.d         | 24 ++++++++++++++
 .../variables/bvar/tst.caller-rawtp.r         |  1 +
 .../variables/bvar/tst.caller-rawtp.r.p       |  1 +
 .../variables/bvar/tst.caller-rawtp.x         |  1 +
 .../variables/bvar/tst.stackdepth-rawtp.d     | 26 ++++++++++++++++
 .../variables/bvar/tst.stackdepth-rawtp.r     |  1 +
 .../variables/bvar/tst.stackdepth-rawtp.r.p   |  1 +
 .../variables/bvar/tst.stackdepth-rawtp.x     |  1 +
 9 files changed, 87 insertions(+)
 create mode 100755 test/unittest/variables/bvar/skip_rawtp_old.x
 create mode 100644 test/unittest/variables/bvar/tst.caller-rawtp.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-rawtp.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-rawtp.r.p
 create mode 120000 test/unittest/variables/bvar/tst.caller-rawtp.x
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-rawtp.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-rawtp.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-rawtp.r.p
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-rawtp.x
test/unittest/variables/bvar/skip_rawtp_old.x new file +31 -0
new file mode 100755
index 000000000..bf7970832
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+#
+# In older kernels (e.g., UEK6), the BPF helper function had a bug with
+# skipping stack frames.  While that many stack frames were correctly
+# skipped on the leaf end of the stack, that many frames were also
+# incorrectly skipped at the root end of the output buffer.
+#
+# Only two DTrace providers ask for a nonzero skip count.  One is the
+# fentry/fexit implementation of fbt, but it was not used on such older
+# kernels.
+#
+# The other is rawtp.  Therefore, rawtp stack(), caller, and stackdepth
+# results on such older kernels can be incorrect.
+#
+# A few other providers also have some or most probes implemented in
+# terms of rawtp probes.  They could have similar problems, depending
+# on which probes are used.
+#
+
+read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
+
+if [ $MAJOR -gt 5 ]; then
+	exit 0
+fi
+if [ $MAJOR -eq 5 -a $MINOR -ge 10 ]; then
+	exit 0
+fi
+
+echo "rawtp caller, stack(), and stackdepth problematic in old kernels"
+exit 2
test/unittest/variables/bvar/tst.caller-rawtp.d new file +24 -0
new file mode 100644
index 000000000..9f8475071
@@ -0,0 +1,24 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+rawtp:sched::
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-rawtp.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-rawtp.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.caller-rawtp.x new file +1 -0
new file mode 120000
index 000000000..37b3ef9f8
@@ -0,0 +1 @@
+skip_rawtp_old.x
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-rawtp.d new file +26 -0
new file mode 100644
index 000000000..ddcc0a13f
@@ -0,0 +1,26 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+rawtp:sched::
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-rawtp.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-rawtp.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-rawtp.x new file +1 -0
new file mode 120000
index 000000000..37b3ef9f8
@@ -0,0 +1 @@
+skip_rawtp_old.x
\ No newline at end of file
Signature · 1 line
2.43.5
#13 lore raw

PATCH 7/14 Test: caller and stackdepth tests for cpc provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 test/unittest/variables/bvar/tst.caller-cpc.d | 22 +++++++++++++++++
 test/unittest/variables/bvar/tst.caller-cpc.r |  1 +
 .../variables/bvar/tst.caller-cpc.r.p         |  1 +
 .../variables/bvar/tst.stackdepth-cpc.d       | 24 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-cpc.r       |  1 +
 .../variables/bvar/tst.stackdepth-cpc.r.p     |  1 +
 6 files changed, 50 insertions(+)
 create mode 100644 test/unittest/variables/bvar/tst.caller-cpc.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-cpc.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-cpc.r.p
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-cpc.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-cpc.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-cpc.r.p
test/unittest/variables/bvar/tst.caller-cpc.d new file +22 -0
new file mode 100644
index 000000000..8932185ee
@@ -0,0 +1,22 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+cpc:::cpu_clock-all-100000000
+/stackdepth > 1/
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-cpc.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-cpc.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-cpc.d new file +24 -0
new file mode 100644
index 000000000..abefee0b0
@@ -0,0 +1,24 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+cpc:::cpu_clock-all-100000000
+/stackdepth > 1/
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-cpc.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-cpc.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
Signature · 1 line
2.43.5
Reviewed-by on v1 7/14
#14 lore raw

Re: [DTrace-devel] [PATCH 07/14] Test: caller and stackdepth tests for cpc provider

On 22 May 2025, eugene loh outgrape:

Quoted 3 lines

From: Eugene Loh <[email protected]>

Quoted 1 line

+cpc:::cpu_clock-all-100000000

1/10th of a second: seems legit. (But having it use nanoseconds makes probe names hard to read! Yes, I know we have no choice here.)

Signature · 1 line
NULL && (void)
#15 lore raw

PATCH 8/14 Test: caller and stackdepth tests for ip provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 test/unittest/variables/bvar/perlping.pl      |  8 +++++++
 test/unittest/variables/bvar/tst.caller-ip.d  | 21 ++++++++++++++++
 test/unittest/variables/bvar/tst.caller-ip.r  |  1 +
 .../unittest/variables/bvar/tst.caller-ip.r.p |  1 +
 test/unittest/variables/bvar/tst.caller-ip.t  |  6 +++++
 .../variables/bvar/tst.stackdepth-ip.d        | 24 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-ip.r        |  1 +
 .../variables/bvar/tst.stackdepth-ip.r.p      |  1 +
 .../variables/bvar/tst.stackdepth-ip.t        |  6 +++++
 9 files changed, 69 insertions(+)
 create mode 100755 test/unittest/variables/bvar/perlping.pl
 create mode 100644 test/unittest/variables/bvar/tst.caller-ip.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-ip.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-ip.r.p
 create mode 100755 test/unittest/variables/bvar/tst.caller-ip.t
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-ip.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-ip.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-ip.r.p
 create mode 100755 test/unittest/variables/bvar/tst.stackdepth-ip.t
test/unittest/variables/bvar/perlping.pl new file +8 -0
new file mode 100755
index 000000000..97c9b09e9
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -w
+# Oracle Linux DTrace.
+# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+use Net::Ping;
+my $p = Net::Ping->new(${ARGV[0]}, 5, 56);
+$p->ping(${ARGV[1]});
test/unittest/variables/bvar/tst.caller-ip.d new file +21 -0
new file mode 100644
index 000000000..83dbcec5e
@@ -0,0 +1,21 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+ip:::
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-ip.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-ip.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.caller-ip.t new file +6 -0
new file mode 100755
index 000000000..836d283da
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+testdir="$(dirname $_test)"
+local=127.0.0.1
+
+$testdir/perlping.pl icmp $local
test/unittest/variables/bvar/tst.stackdepth-ip.d new file +24 -0
new file mode 100644
index 000000000..eef942b5b
@@ -0,0 +1,24 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+ip:::
+/stackdepth > 0/
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-ip.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-ip.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-ip.t new file +6 -0
new file mode 100755
index 000000000..836d283da
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+testdir="$(dirname $_test)"
+local=127.0.0.1
+
+$testdir/perlping.pl icmp $local
Signature · 1 line
2.43.5
Reviewed-by on v1 8/14
#16 lore raw

Re: [DTrace-devel] [PATCH 08/14] Test: caller and stackdepth tests for ip provider

On 22 May 2025, eugene loh spake thusly:

Quoted 3 lines

From: Eugene Loh <[email protected]>

with the microscopic caveat below.

Quoted 6 lines
test/unittest/variables/bvar/perlping.pl new file +0 -0
new file mode 100755
index 000000000..97c9b09e9

test/unittest/variables/bvar/perlping.pl line 8

Quoted 8 lines
test/unittest/variables/bvar/perlping.pl new file +8 -0
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -w
+# Oracle Linux DTrace.
+# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+use Net::Ping;
+my $p = Net::Ping->new(${ARGV[0]}, 5, 56);
+$p->ping(${ARGV[1]});

Is there some reason we can't just use $testdir/../../ip/perlping.pl and avoid duplicating this?

Signature · 1 line
NULL && (void)
author
#17 lore raw

Re: [DTrace-devel] [PATCH 08/14] Test: caller and stackdepth tests for ip provider

Quoted 9 lines · Nick Alcock

On 22 May 2025, eugene loh spake thusly:

Quoted 3 lines

From: Eugene Loh <[email protected]>

with the microscopic caveat below.

Quoted 16 lines
Quoted 6 lines
test/unittest/variables/bvar/perlping.pl new file +0 -0
new file mode 100755
index 000000000..97c9b09e9

test/unittest/variables/bvar/perlping.pl line 8

Quoted 8 lines
test/unittest/variables/bvar/perlping.pl new file +8 -0
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -w
+# Oracle Linux DTrace.
+# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+use Net::Ping;
+my $p = Net::Ping->new(${ARGV[0]}, 5, 56);
+$p->ping(${ARGV[1]});

Is there some reason we can't just use $testdir/../../ip/perlping.pl and avoid duplicating this?

Thanks.  Okay, I did this.

#18 lore raw

Re: [DTrace-devel] [PATCH 08/14] Test: caller and stackdepth tests for ip provider

Quoted 29 lines · Eugene Loh
Quoted 9 lines · Nick Alcock

On 22 May 2025, eugene loh spake thusly:

Quoted 3 lines

From: Eugene Loh <[email protected]>

with the microscopic caveat below.

Quoted 16 lines
Quoted 6 lines
test/unittest/variables/bvar/perlping.pl new file +0 -0
new file mode 100755
index 000000000..97c9b09e9

test/unittest/variables/bvar/perlping.pl line 8

Quoted 8 lines
test/unittest/variables/bvar/perlping.pl new file +8 -0
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -w
+# Oracle Linux DTrace.
+# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+use Net::Ping;
+my $p = Net::Ping->new(${ARGV[0]}, 5, 56);
+$p->ping(${ARGV[1]});

Is there some reason we can't just use $testdir/../../ip/perlping.pl and avoid duplicating this?

Quoted 2 lines

Thanks.  Okay, I did this.

Can you please post the updated v2 ASAP so I can merge the series?

#19 lore raw

PATCH 9/14 Test: caller and stackdepth tests for profile provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 test/unittest/builtinvar/tst.caller1.d        | 29 -------------------
 .../variables/bvar/tst.caller-profile.d       | 22 ++++++++++++++
 .../variables/bvar/tst.caller-profile.r       |  1 +
 .../variables/bvar/tst.caller-profile.r.p     |  1 +
 .../variables/bvar/tst.stackdepth-profile.d   | 24 +++++++++++++++
 .../variables/bvar/tst.stackdepth-profile.r   |  1 +
 .../variables/bvar/tst.stackdepth-profile.r.p |  1 +
 7 files changed, 50 insertions(+), 29 deletions(-)
 delete mode 100644 test/unittest/builtinvar/tst.caller1.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-profile.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-profile.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-profile.r.p
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-profile.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-profile.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-profile.r.p
test/unittest/builtinvar/tst.caller1.d deleted +0 -29
deleted file mode 100644
index ca0f098f3..000000000
@@ -1,29 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-/*
- * ASSERTION: To print caller from profile and make sure it succeeds.
- *
- * SECTION: Variables/Built-in Variables
- */
-
-#pragma D option quiet
-
-BEGIN
-{
-}
-
-tick-10ms
-{
-	printf("The caller is %u\n", caller);
-	exit (0);
-}
-
-ERROR
-{
-	exit(1);
-}
test/unittest/variables/bvar/tst.caller-profile.d new file +22 -0
new file mode 100644
index 000000000..6e322bb70
@@ -0,0 +1,22 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+profile:::tick-50ms
+/stackdepth > 1/
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-profile.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-profile.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-profile.d new file +24 -0
new file mode 100644
index 000000000..8b42e9016
@@ -0,0 +1,24 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+profile:::tick-50ms
+/stackdepth > 1/
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-profile.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-profile.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
Signature · 1 line
2.43.5
#21 lore raw

PATCH 10/14 Test: caller and stackdepth tests for sched provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 .../variables/bvar/tst.caller-sched.d         | 31 +++++++++++++++++
 .../variables/bvar/tst.caller-sched.r         |  1 +
 .../variables/bvar/tst.caller-sched.r.p       |  1 +
 .../variables/bvar/tst.stackdepth-sched.d     | 33 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-sched.r     |  1 +
 .../variables/bvar/tst.stackdepth-sched.r.p   |  1 +
 6 files changed, 68 insertions(+)
 create mode 100644 test/unittest/variables/bvar/tst.caller-sched.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-sched.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-sched.r.p
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-sched.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-sched.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-sched.r.p
test/unittest/variables/bvar/tst.caller-sched.d new file +31 -0
new file mode 100644
index 000000000..087571531
@@ -0,0 +1,31 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+
+/*
+ * Some probes are implemented in terms of rawtp probes.  Avoid them
+ * due to stack-skip issues on older kernels.
+ */
+sched:::dequeue,
+sched:::enqueue,
+sched:::tick
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-sched.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-sched.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-sched.d new file +33 -0
new file mode 100644
index 000000000..d3e9e18d5
@@ -0,0 +1,33 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+
+/*
+ * Some probes are implemented in terms of rawtp probes.  Avoid them
+ * due to stack-skip issues on older kernels.
+ */
+sched:::dequeue,
+sched:::enqueue,
+sched:::tick
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-sched.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-sched.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
Signature · 1 line
2.43.5
#23 lore raw

PATCH 11/14 Test: caller and stackdepth tests for proc provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 .../unittest/variables/bvar/tst.caller-proc.d | 34 ++++++++++++++++++
 .../unittest/variables/bvar/tst.caller-proc.r |  1 +
 .../variables/bvar/tst.caller-proc.r.p        |  1 +
 .../variables/bvar/tst.stackdepth-proc.d      | 36 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-proc.r      |  1 +
 .../variables/bvar/tst.stackdepth-proc.r.p    |  1 +
 6 files changed, 74 insertions(+)
 create mode 100644 test/unittest/variables/bvar/tst.caller-proc.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-proc.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-proc.r.p
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-proc.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-proc.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-proc.r.p
test/unittest/variables/bvar/tst.caller-proc.d new file +34 -0
new file mode 100644
index 000000000..7c3557e2c
@@ -0,0 +1,34 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+/*
+ * Some probes are implemented in terms of rawtp probes.  Avoid them
+ * due to stack-skip issues on older kernels.
+ */
+proc:::exec,
+proc:::exec-failure,
+proc:::exec-success,
+proc:::lwp-start,
+proc:::signal-clear,
+proc:::signal-send,
+proc:::start
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-proc.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-proc.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-proc.d new file +36 -0
new file mode 100644
index 000000000..75f720370
@@ -0,0 +1,36 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+/*
+ * Some probes are implemented in terms of rawtp probes.  Avoid them
+ * due to stack-skip issues on older kernels.
+ */
+proc:::exec,
+proc:::exec-failure,
+proc:::exec-success,
+proc:::lwp-start,
+proc:::signal-clear,
+proc:::signal-send,
+proc:::start
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-proc.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-proc.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
Signature · 1 line
2.43.5
author
#25 lore raw

Re: [PATCH 11/14] Test: caller and stackdepth tests for proc provider

Thanks.

I'm getting to these out of order, but I figured I'd mention that I'm going to turn the capitalized "Test:" into "test:" for this series of patches to conform to the style in related patches.

Quoted 7 lines · Nick Alcock

On 22 May 2025, eugene loh told this:

Quoted 3 lines

From: Eugene Loh <[email protected]>

#26 lore raw

Re: [PATCH 11/14] Test: caller and stackdepth tests for proc provider

On 15 Jun 2025, Eugene Loh stated:

Quoted 4 lines

Thanks.

I'm getting to these out of order, but I figured I'd mention that I'm going to turn the capitalized "Test:" into "test:" for this series of patches to conform to the style in related patches.

Makes sense! I totally failed to notice that.

#27 lore raw

Re: [PATCH 11/14] Test: caller and stackdepth tests for proc provider

In reply to Eugene Loh
Quoted 5 lines · Eugene Loh

Thanks.

I'm getting to these out of order, but I figured I'd mention that I'm going to turn the capitalized "Test:" into "test:" for this series of patches to conform to the style in related patches.

In that case, please post v2 of the series ASAP because I cannot merge without updated patches.

Quoted 9 lines · Nick Alcock
Quoted 7 lines

On 22 May 2025, eugene loh told this:

Quoted 3 lines

From: Eugene Loh <[email protected]>

#28 lore raw

PATCH 12/14 Test: caller and stackdepth tests for rawfbt provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 .../variables/bvar/tst.caller-rawfbt.d        | 25 +++++++++++++++++
 .../variables/bvar/tst.caller-rawfbt.r        |  1 +
 .../variables/bvar/tst.caller-rawfbt.r.p      |  1 +
 .../variables/bvar/tst.stackdepth-rawfbt.d    | 27 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-rawfbt.r    |  1 +
 .../variables/bvar/tst.stackdepth-rawfbt.r.p  |  1 +
 6 files changed, 56 insertions(+)
 create mode 100644 test/unittest/variables/bvar/tst.caller-rawfbt.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-rawfbt.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-rawfbt.r.p
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-rawfbt.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-rawfbt.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-rawfbt.r.p
test/unittest/variables/bvar/tst.caller-rawfbt.d new file +25 -0
new file mode 100644
index 000000000..08ab3eba1
@@ -0,0 +1,25 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+rawfbt::ksys_write:entry
+/pid == $target/
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-rawfbt.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-rawfbt.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-rawfbt.d new file +27 -0
new file mode 100644
index 000000000..15a9991cb
@@ -0,0 +1,27 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+/*
+ * @@trigger: periodic_output
+ */
+
+#pragma D option quiet
+
+rawfbt::ksys_write:entry
+/pid == $target/
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-rawfbt.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-rawfbt.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
Signature · 1 line
2.43.5
Reviewed-by on v1 12/14
#29 lore raw

Re: [DTrace-devel] [PATCH 12/14] Test: caller and stackdepth tests for rawfbt provider

On 22 May 2025, eugene loh spake thusly:

Quoted 3 lines

From: Eugene Loh <[email protected]>

I note the lack of any sort of skipping on older kernels. Do the concerns about older kernels not apply here?

If not, and this was intentional...

Signature · 1 line
NULL && (void)
author
#30 lore raw

Re: [DTrace-devel] [PATCH 12/14] Test: caller and stackdepth tests for rawfbt provider

Quoted 7 lines · Nick Alcock

On 22 May 2025, eugene loh spake thusly:

Quoted 3 lines

From: Eugene Loh <[email protected]>

I note the lack of any sort of skipping on older kernels. Do the concerns about older kernels not apply here?

You mean with skipping frames and the BPF helper function?  Right. Only two providers worry about that.  One is fentry, but we do not use it on those older kernels (fbt uses kprobes instead).  The other is rawtp.

Did I say "only two"?  Well some providers (like sched and proc) use rawtp to implement certain probes.  So, they kind of worry about this problem.

But this provider (rawfbt) seems to be fine.

Quoted 3 lines

If not, and this was intentional...

Thanks.

#31 lore raw

PATCH 13/14 Test: caller and stackdepth tests for io provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 test/unittest/variables/bvar/tst.caller-io.r  |  1 +
 .../unittest/variables/bvar/tst.caller-io.r.p |  1 +
 test/unittest/variables/bvar/tst.caller-io.sh | 37 ++++++++++++++++++
 test/unittest/variables/bvar/tst.caller-io.x  |  1 +
 .../variables/bvar/tst.stackdepth-io.r        |  1 +
 .../variables/bvar/tst.stackdepth-io.r.p      |  1 +
 .../variables/bvar/tst.stackdepth-io.sh       | 39 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-io.x        |  1 +
 8 files changed, 82 insertions(+)
 create mode 100644 test/unittest/variables/bvar/tst.caller-io.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-io.r.p
 create mode 100755 test/unittest/variables/bvar/tst.caller-io.sh
 create mode 120000 test/unittest/variables/bvar/tst.caller-io.x
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-io.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-io.r.p
 create mode 100755 test/unittest/variables/bvar/tst.stackdepth-io.sh
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-io.x
test/unittest/variables/bvar/tst.caller-io.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-io.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.caller-io.sh new file +37 -0
new file mode 100755
index 000000000..876ea70e3
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+dtrace=$1
+nblocks=1024
+filesize=$((1024*$nblocks))
+fsoptions="defaults,atime,diratime,nosuid,nodev"
+iodir=$tmpdir/tst-caller-io.$$
+tempfile=`mktemp -u -p $iodir`
+
+trap "umount $iodir; rmdir $iodir; rm -f $iodir.img" QUIT EXIT
+
+# create loopback file system
+dd if=/dev/zero of=$iodir.img bs=1024 count=$((300*$nblocks)) status=none
+mkfs.xfs $iodir.img > /dev/null
+mkdir $iodir
+test/triggers/io-mount-local.sh $iodir xfs $fsoptions
+
+$dtrace $dt_flags -c "test/triggers/doio.sh $tempfile $filesize test/triggers/io-mount-local.sh $iodir xfs $fsoptions" -qn '
+io:::
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}'
+
+exit $?
test/unittest/variables/bvar/tst.caller-io.x new file +1 -0
new file mode 120000
index 000000000..37b3ef9f8
@@ -0,0 +1 @@
+skip_rawtp_old.x
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-io.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-io.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-io.sh new file +39 -0
new file mode 100755
index 000000000..3bbf38a47
@@ -0,0 +1,39 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+dtrace=$1
+nblocks=1024
+filesize=$((1024*$nblocks))
+fsoptions="defaults,atime,diratime,nosuid,nodev"
+iodir=$tmpdir/tst-stackdepth-io.$$
+tempfile=`mktemp -u -p $iodir`
+
+trap "umount $iodir; rmdir $iodir; rm -f $iodir.img" QUIT EXIT
+
+# create loopback file system
+dd if=/dev/zero of=$iodir.img bs=1024 count=$((300*$nblocks)) status=none
+mkfs.xfs $iodir.img > /dev/null
+mkdir $iodir
+test/triggers/io-mount-local.sh $iodir xfs $fsoptions
+
+$dtrace $dt_flags -c "test/triggers/doio.sh $tempfile $filesize test/triggers/io-mount-local.sh $iodir xfs $fsoptions" -qn '
+io:::
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}'
+
+exit $?
test/unittest/variables/bvar/tst.stackdepth-io.x new file +1 -0
new file mode 120000
index 000000000..37b3ef9f8
@@ -0,0 +1 @@
+skip_rawtp_old.x
\ No newline at end of file
Signature · 1 line
2.43.5
Reviewed-by on v1 13/14
#32 lore raw

Re: [DTrace-devel] [PATCH 13/14] Test: caller and stackdepth tests for io provider

On 22 May 2025, eugene loh spake thusly:

Quoted 3 lines

From: Eugene Loh <[email protected]>

Quoted 10 lines
test/unittest/variables/bvar/tst.caller-io.sh new file +7 -0
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+

test/unittest/variables/bvar/tst.caller-io.sh line 17

Quoted 10 lines
test/unittest/variables/bvar/tst.caller-io.sh new file +10 -0
+dtrace=$1
+nblocks=1024
+filesize=$((1024*$nblocks))
+fsoptions="defaults,atime,diratime,nosuid,nodev"
+iodir=$tmpdir/tst-caller-io.$$
+tempfile=`mktemp -u -p $iodir`
+
+trap "umount $iodir; rmdir $iodir; rm -f $iodir.img" QUIT EXIT
+
+# create loopback file system

We have quite a lot of these I/O-trigger filesystem things now (this is our sixth and seventh). Maybe we should think about refactoring the mount-and-mkfs-and-dd-and-umount bit out into shared code at some point...

Signature · 1 line
NULL && (void)
#33 lore raw

PATCH 14/14 Test: caller and stackdepth tests for lockstat provider

In reply to [email protected]

From: Eugene Loh <[email protected]>

---
 .../variables/bvar/skip_lockstat_5.10.x       | 13 ++++++++++
 .../variables/bvar/tst.caller-lockstat.d      | 22 +++++++++++++++++
 .../variables/bvar/tst.caller-lockstat.r      |  1 +
 .../variables/bvar/tst.caller-lockstat.r.p    |  1 +
 .../variables/bvar/tst.caller-lockstat.t      |  3 +++
 .../variables/bvar/tst.caller-lockstat.x      |  1 +
 .../variables/bvar/tst.stackdepth-lockstat.d  | 24 +++++++++++++++++++
 .../variables/bvar/tst.stackdepth-lockstat.r  |  1 +
 .../bvar/tst.stackdepth-lockstat.r.p          |  1 +
 .../variables/bvar/tst.stackdepth-lockstat.t  |  3 +++
 .../variables/bvar/tst.stackdepth-lockstat.x  |  1 +
 11 files changed, 71 insertions(+)
 create mode 100755 test/unittest/variables/bvar/skip_lockstat_5.10.x
 create mode 100644 test/unittest/variables/bvar/tst.caller-lockstat.d
 create mode 100644 test/unittest/variables/bvar/tst.caller-lockstat.r
 create mode 120000 test/unittest/variables/bvar/tst.caller-lockstat.r.p
 create mode 100755 test/unittest/variables/bvar/tst.caller-lockstat.t
 create mode 120000 test/unittest/variables/bvar/tst.caller-lockstat.x
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-lockstat.d
 create mode 100644 test/unittest/variables/bvar/tst.stackdepth-lockstat.r
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-lockstat.r.p
 create mode 100755 test/unittest/variables/bvar/tst.stackdepth-lockstat.t
 create mode 120000 test/unittest/variables/bvar/tst.stackdepth-lockstat.x
test/unittest/variables/bvar/skip_lockstat_5.10.x new file +13 -0
new file mode 100755
index 000000000..146443fd2
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
+
+if [ $MAJOR -gt 5 ]; then
+	exit 0
+fi
+if [ $MAJOR -eq 5 -a $MINOR -ge 10 ]; then
+	exit 0
+fi
+
+echo "lockstat disabled prior to 5.10"
+exit 1
test/unittest/variables/bvar/tst.caller-lockstat.d new file +22 -0
new file mode 100644
index 000000000..95eb08578
@@ -0,0 +1,22 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+lockstat:::*acquire
+/pid == $target/
+{
+	stack(2);
+	sym(caller);
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.caller-lockstat.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/variables/bvar/tst.caller-lockstat.r.p new file +1 -0
new file mode 120000
index 000000000..954ca96aa
@@ -0,0 +1 @@
+check_caller_to_stack2.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.caller-lockstat.t new file +3 -0
new file mode 100755
index 000000000..fec0d2715
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+sleep 10s
test/unittest/variables/bvar/tst.caller-lockstat.x new file +1 -0
new file mode 120000
index 000000000..539f14255
@@ -0,0 +1 @@
+skip_lockstat_5.10.x
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-lockstat.d new file +24 -0
new file mode 100644
index 000000000..46f937067
@@ -0,0 +1,24 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+#pragma D option quiet
+
+lockstat:::*acquire
+/pid == $target/
+{
+	printf("DEPTH %d\n", stackdepth);
+	printf("TRACE BEGIN\n");
+	stack(100);
+	printf("TRACE END\n");
+	exit(0);
+}
+
+ERROR
+{
+	printf("error encountered\n");
+	exit(1);
+}
test/unittest/variables/bvar/tst.stackdepth-lockstat.r new file +1 -0
new file mode 100644
index 000000000..3bd29b8ed
@@ -0,0 +1 @@
+Stack depth OK
test/unittest/variables/bvar/tst.stackdepth-lockstat.r.p new file +1 -0
new file mode 120000
index 000000000..e50f12822
@@ -0,0 +1 @@
+check_stackdepth_to_stack.awk
\ No newline at end of file
test/unittest/variables/bvar/tst.stackdepth-lockstat.t new file +3 -0
new file mode 100755
index 000000000..fec0d2715
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+sleep 10s
test/unittest/variables/bvar/tst.stackdepth-lockstat.x new file +1 -0
new file mode 120000
index 000000000..539f14255
@@ -0,0 +1 @@
+skip_lockstat_5.10.x
\ No newline at end of file
Signature · 1 line
2.43.5
#35 lore raw
In reply to [email protected]

On 22 May 2025, eugene loh told this:

Quoted 9 lines

From: Eugene Loh <[email protected]>

Apparently, when we call the BPF get_stack() helper function, it generally knows how many frames to skip to get the real kernel stack. For fentry/fexit, however, this is apparently not the case, and commit bc65cb44d
("cg: allow providers to specify a skip count for stack retrieval") added the ability to skip frames for fentry/fexit probes.

Quoted 3 lines

When this "skip" is needed, however, it must must be even deeper when we descend further frames, such as when we call dt_bpf_*() precompiled functions.

Ack.

Quoted 3 lines

Add this support for dt_bpf_caller() and dt_bpf_stackdepth(). That is, if there are stack-skip frames, skip yet one more frame when inside a bpf/get_bvar.c function.

The general approach here seems sound, but this confuses me. Is the assumption that if the skip is not needed, get_stack() will itself know how many frames to skip, and will skip dt_dt_bvar_caller() for you?

(So a zero skip is actually a "the system knows", and a nonzero skip causes the system to not skip anything, so you have to do all the skipping yourself?

This behaviour is not documented in bpf_get_stack()'s documentation, which absolutely does not mean it doesn't do it...)

Quoted 3 lines

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

... why doesn't this apply to every other extern global variable in get_bvar()? They're all similarly relocated...

Quoted 53 lines
---
 bpf/get_bvar.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
bpf/get_bvar.c +14 -3
index 9625e764e..99a6503d5 100644
@@ -53,12 +53,17 @@ noinline uint64_t dt_bvar_args(const dt_dctx_t *dctx, uint32_t idx)
 
 noinline uint64_t dt_bvar_caller(const dt_dctx_t *dctx)
 {
-	uint64_t	buf[2] = { 0, };
+	uint64_t	buf[3] = { 0, };
+	volatile uint64_t
+			skip = (uint64_t)(&STACK_SKIP);
 
 	if (bpf_get_stack(dctx->ctx, buf, sizeof(buf),
-			  (uint64_t)(&STACK_SKIP) & BPF_F_SKIP_FIELD_MASK) < 0)
+			  skip & BPF_F_SKIP_FIELD_MASK) < 0)
 		return 0;
 
+	/* If we had to skip any frames, account for the dt_bvar_caller() frame. */
+	if (skip)
+		return buf[2];
 	return buf[1];
 }
 
@@ -203,9 +208,11 @@ noinline uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
 	uint32_t	bufsiz = (uint32_t) (uint64_t) (&STKSIZ);
 	char		*buf = dctx->mem + (uint64_t)(&STACK_OFF);
 	uint64_t	retv;
+	volatile uint64_t
+			skip = (uint64_t)(&STACK_SKIP);
 
 	retv = bpf_get_stack(dctx->ctx, buf, bufsiz,
-			     (uint64_t)(&STACK_SKIP) & BPF_F_SKIP_FIELD_MASK);
+			     skip & BPF_F_SKIP_FIELD_MASK);
 	if (retv < 0)
 		return error(dctx, DTRACEFLT_BADSTACK, 0 /* FIXME */);
 
@@ -217,7 +224,11 @@ noinline uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
 	 * If retv==bufsiz, presumably the stack is larger than what we
 	 * can retrieve.  But it's also possible that the buffer was exactly
 	 * large enough.  So, leave it to the user to interpret the result.
+	 *
+	 * If we had to skip any frames, account for the dt_bvar_stackdepth() frame.
 	 */
+	if (skip)
+		return retv / sizeof(uint64_t) - 1;
 	return retv / sizeof(uint64_t);
 }
Signature · 1 line
NULL && (void)
author
#36 lore raw
Quoted 14 lines · Nick Alcock

On 22 May 2025, eugene loh told this:

Quoted 9 lines

From: Eugene Loh <[email protected]>

Apparently, when we call the BPF get_stack() helper function, it generally knows how many frames to skip to get the real kernel stack. For fentry/fexit, however, this is apparently not the case, and commit bc65cb44d
("cg: allow providers to specify a skip count for stack retrieval") added the ability to skip frames for fentry/fexit probes.

Quoted 3 lines

When this "skip" is needed, however, it must must be even deeper when we descend further frames, such as when we call dt_bpf_*() precompiled functions.

Quoted 8 lines

Ack.

Quoted 3 lines

Add this support for dt_bpf_caller() and dt_bpf_stackdepth(). That is, if there are stack-skip frames, skip yet one more frame when inside a bpf/get_bvar.c function.

The general approach here seems sound, but this confuses me. Is the assumption that if the skip is not needed, get_stack() will itself know how many frames to skip, and will skip dt_dt_bvar_caller() for you?

Yes.  I confirmed this with tests.

Quoted 3 lines

(So a zero skip is actually a "the system knows", and a nonzero skip causes the system to not skip anything, so you have to do all the skipping yourself?

Yes.

Quoted 2 lines

This behaviour is not documented in bpf_get_stack()'s documentation, which absolutely does not mean it doesn't do it...)

Yup:  I did not learn this from documentation!

Quoted 5 lines
Quoted 3 lines

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

... why doesn't this apply to every other extern global variable in get_bvar()? They're all similarly relocated...

Right.  There is potentially a broader problem.  But we simply do not have evidence of misbehavior in other cases.  Ruggedizing other cases could be the subject of a different patch.

The problem in this case is that the compiler seems to assume &symbol!=0, which is reasonable except that we violate that behavior for our relocation tricks.

Consider the C code:

    uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
    {
        uint32_t          bufsiz = (uint32_t) (uint64_t) (&STKSIZ); char              *buf = dctx->mem + (uint64_t)(&STACK_OFF); uint64_t          retv;
        volatile uint64_t skip = (uint64_t)(&STACK_SKIP);

        retv = bpf_get_stack(dctx->ctx,
                             buf,
                             bufsiz,
                             skip & BPF_F_SKIP_FIELD_MASK);

        if (skip)
                return retv / sizeof(uint64_t) - 1;      // branch "A" return retv / sizeof(uint64_t);                  // branch "B" }

If you omit "volatile", the compiler assumes &STACK_SKIP!=0. The emitted code has:

    *)  no run-time "if (skip)" check

    *)  no code for branch "B"

    *)  only code for branch "A"

If you include "volatile", however, the compiler caches &STACK_SKIP on the BPF stack and later performs a run-time check on its value to correctly execute either branch "A" or branch "B".

Incidentally, I looked at this using the function like this:

    profile:::tick-1s,
    fbt:vmlinux:ksys_write:entry
    {
       trace(stackdepth);
    }

Notice that the profile probe has STACK_SKIP==0 while the fbt probe has STACK_SKIP==4.

I looked at the disassembly in three ways:

    *)  as emitted by the compiler:  objdump -d build/bpf--get_bvar.o
       (not too interesting but establishes a baseline;  e.g., that a branch is missing)

    *)  after relocation for tick-1s (-xdisasm=8 -S)

    *)  after relocation for fbt::ksys_write:entry (-xdisasm=8 -S)

The latter two confirm the relocations are correct.

Quoted 53 lines
Quoted 53 lines
---
  bpf/get_bvar.c | 17 ++++++++++++++---
  1 file changed, 14 insertions(+), 3 deletions(-)
bpf/get_bvar.c +14 -3
index 9625e764e..99a6503d5 100644
@@ -53,12 +53,17 @@ noinline uint64_t dt_bvar_args(const dt_dctx_t *dctx, uint32_t idx)
 
  noinline uint64_t dt_bvar_caller(const dt_dctx_t *dctx)
  {
-	uint64_t	buf[2] = { 0, };
+	uint64_t	buf[3] = { 0, };
+	volatile uint64_t
+			skip = (uint64_t)(&STACK_SKIP);
 
  	if (bpf_get_stack(dctx->ctx, buf, sizeof(buf),
-			  (uint64_t)(&STACK_SKIP) & BPF_F_SKIP_FIELD_MASK) < 0)
+			  skip & BPF_F_SKIP_FIELD_MASK) < 0)
  		return 0;
 
+	/* If we had to skip any frames, account for the dt_bvar_caller() frame. */
+	if (skip)
+		return buf[2];
  	return buf[1];
  }
 
@@ -203,9 +208,11 @@ noinline uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
  	uint32_t	bufsiz = (uint32_t) (uint64_t) (&STKSIZ);
  	char		*buf = dctx->mem + (uint64_t)(&STACK_OFF);
  	uint64_t	retv;
+	volatile uint64_t
+			skip = (uint64_t)(&STACK_SKIP);
 
  	retv = bpf_get_stack(dctx->ctx, buf, bufsiz,
-			     (uint64_t)(&STACK_SKIP) & BPF_F_SKIP_FIELD_MASK);
+			     skip & BPF_F_SKIP_FIELD_MASK);
  	if (retv < 0)
  		return error(dctx, DTRACEFLT_BADSTACK, 0 /* FIXME */);
 
@@ -217,7 +224,11 @@ noinline uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
  	 * If retv==bufsiz, presumably the stack is larger than what we
  	 * can retrieve.  But it's also possible that the buffer was exactly
  	 * large enough.  So, leave it to the user to interpret the result.
+	 *
+	 * If we had to skip any frames, account for the dt_bvar_stackdepth() frame.
  	 */
+	if (skip)
+		return retv / sizeof(uint64_t) - 1;
  	return retv / sizeof(uint64_t);
  }
#37 lore raw

On 16 Jun 2025, Eugene Loh verbalised:

Quoted 10 lines · Nick Alcock
Quoted 6 lines
Quoted 4 lines

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

... why doesn't this apply to every other extern global variable in get_bvar()? They're all similarly relocated...

Right.  There is potentially a broader problem.  But we simply do not have evidence of misbehavior in other cases.  Ruggedizing other cases could be the subject of a different patch.

Aha, OK. I was just wondering if there was some extra reason.

Quoted 2 lines

The problem in this case is that the compiler seems to assume &symbol!=0, which is reasonable except that we violate that behavior for our relocation tricks.

I wonder where the code for that is... plenty of symbols have value zero.

But, really...

Quoted 6 lines

Consider the C code:

    uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
    {
        uint32_t          bufsiz = (uint32_t) (uint64_t) (&STKSIZ); char              *buf = dctx->mem + (uint64_t)(&STACK_OFF);

Hm...

extern uint64_t STACK_SKIP;

So we encode information about the stack size and skip value by encoding it in the *address* of the variable? Is there some reason we don't use its value? unlike the stack offset, we're *using* it as a value, not an address...

Quoted 8 lines

        uint64_t          retv;
        volatile uint64_t skip = (uint64_t)(&STACK_SKIP);

        retv = bpf_get_stack(dctx->ctx,
                             buf,
                             bufsiz,
                             skip & BPF_F_SKIP_FIELD_MASK);

Quoted 6 lines

        if (skip)
                return retv / sizeof(uint64_t) - 1;      // branch "A" return retv / sizeof(uint64_t);                  // branch "B" }

If you omit "volatile", the compiler assumes &STACK_SKIP!=0. The emitted code has:

(which is a reasonable assumption if not freestanding, I'd say. Why don't we compile BPF code with -ffreestanding? BPF is almost the *definition* of a freestanding environment...)

Quoted 9 lines

    *)  no run-time "if (skip)" check

    *)  no code for branch "B"

    *)  only code for branch "A"

If you include "volatile", however, the compiler caches &STACK_SKIP on the BPF stack and later performs a run-time check on its value to correctly execute either branch "A" or branch "B".

This feels very mucvh like a workaround to me. Does compiling BPF with -ffreestanding help?

I mean it fixes a bug, so I suppose it should go in if nothing else works, but using volatile is almost always a desperate sticking plaster and this feels like one of those occasions to me.

Signature · 1 line
NULL && (void)
#38 lore raw
Quoted 30 lines · Nick Alcock

On 16 Jun 2025, Eugene Loh verbalised:

Quoted 10 lines · Nick Alcock
Quoted 6 lines
Quoted 4 lines

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

... why doesn't this apply to every other extern global variable in get_bvar()? They're all similarly relocated...

Right.  There is potentially a broader problem.  But we simply do not have evidence of misbehavior in other cases.  Ruggedizing other cases could be the subject of a different patch.

Aha, OK. I was just wondering if there was some extra reason.

Quoted 2 lines

The problem in this case is that the compiler seems to assume &symbol!=0, which is reasonable except that we violate that behavior for our relocation tricks.

I wonder where the code for that is... plenty of symbols have value zero.

But, really...

Quoted 6 lines

Consider the C code:

    uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
    {
        uint32_t          bufsiz = (uint32_t) (uint64_t) (&STKSIZ); char              *buf = dctx->mem + (uint64_t)(&STACK_OFF);

Quoted 8 lines

Hm...

extern uint64_t STACK_SKIP;

So we encode information about the stack size and skip value by encoding it in the *address* of the variable? Is there some reason we don't use its value? unlike the stack offset, we're *using* it as a value, not an address...

The issue seems to be (and perhaps this is a cross compiler problem) that e.g.

extern uint64_t PC;

and then code accessing the value of PC (e.g. foo(PC) as a call argument) will yield:

50: 18 02 00 00 00 00 00 00 lddw %r2,0
58: 00 00 00 00 00 00 00 00

                        50: R_BPF_INSN_64       PC

60: 79 22 00 00 00 00 00 00 ldxdw %r2,[%r2+0]

which shows that it is interpreting PC as an address to a symbol, because it loads the address of the symbol and then dereferences it with offset 0. So, we cannot plug in the value during relocation because the only value we can put there would be an address where the vlaue can be found. To get around this, we "use" Tthe address as the entity to store the value in, knowing that we *never* will interpret it as an address for these specific externs.

Quoted 38 lines
Quoted 8 lines

        uint64_t          retv;
        volatile uint64_t skip = (uint64_t)(&STACK_SKIP);

        retv = bpf_get_stack(dctx->ctx,
                             buf,
                             bufsiz,
                             skip & BPF_F_SKIP_FIELD_MASK);

Quoted 6 lines

        if (skip)
                return retv / sizeof(uint64_t) - 1;      // branch "A" return retv / sizeof(uint64_t);                  // branch "B" }

If you omit "volatile", the compiler assumes &STACK_SKIP!=0. The emitted code has:

(which is a reasonable assumption if not freestanding, I'd say. Why don't we compile BPF code with -ffreestanding? BPF is almost the *definition* of a freestanding environment...)

Quoted 9 lines

    *)  no run-time "if (skip)" check

    *)  no code for branch "B"

    *)  only code for branch "A"

If you include "volatile", however, the compiler caches &STACK_SKIP on the BPF stack and later performs a run-time check on its value to correctly execute either branch "A" or branch "B".

This feels very mucvh like a workaround to me. Does compiling BPF with -ffreestanding help?

I mean it fixes a bug, so I suppose it should go in if nothing else works, but using volatile is almost always a desperate sticking plaster and this feels like one of those occasions to me.

Signature · 1 line
NULL && (void)
#39 lore raw
Quoted 50 lines · Kris Van Hees
Quoted 30 lines · Nick Alcock

On 16 Jun 2025, Eugene Loh verbalised:

Quoted 10 lines · Nick Alcock
Quoted 6 lines
Quoted 4 lines

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

... why doesn't this apply to every other extern global variable in get_bvar()? They're all similarly relocated...

Right.  There is potentially a broader problem.  But we simply do not have evidence of misbehavior in other cases.  Ruggedizing other cases could be the subject of a different patch.

Aha, OK. I was just wondering if there was some extra reason.

Quoted 2 lines

The problem in this case is that the compiler seems to assume &symbol!=0, which is reasonable except that we violate that behavior for our relocation tricks.

I wonder where the code for that is... plenty of symbols have value zero.

But, really...

Quoted 6 lines

Consider the C code:

    uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
    {
        uint32_t          bufsiz = (uint32_t) (uint64_t) (&STKSIZ); char              *buf = dctx->mem + (uint64_t)(&STACK_OFF);

Quoted 8 lines

Hm...

extern uint64_t STACK_SKIP;

So we encode information about the stack size and skip value by encoding it in the *address* of the variable? Is there some reason we don't use its value? unlike the stack offset, we're *using* it as a value, not an address...

The issue seems to be (and perhaps this is a cross compiler problem) that e.g.

extern uint64_t PC;

and then code accessing the value of PC (e.g. foo(PC) as a call argument) will yield:

50: 18 02 00 00 00 00 00 00 lddw %r2,0
58: 00 00 00 00 00 00 00 00

                        50: R_BPF_INSN_64       PC
Quoted 8 lines

60: 79 22 00 00 00 00 00 00 ldxdw %r2,[%r2+0]

which shows that it is interpreting PC as an address to a symbol, because it loads the address of the symbol and then dereferences it with offset 0. So, we cannot plug in the value during relocation because the only value we can put there would be an address where the vlaue can be found. To get around this, we "use" Tthe address as the entity to store the value in, knowing that we *never* will interpret it as an address for these specific externs.

Not a compiler error - since PC is extern uint64_t PC it *is* a variable and so it is present (and accessible) as an address in .data in the location where it is actually defined. Since we never define it, we don't have a .data (which is fine because we only use this for constants known at link time) BUT the compiler of course is free to assume that we *do* have an address to the storage location for PC and thus that we get the value that way. It does not know that the value is constant. So, the trick I use is needed to make this work.

Quoted 38 lines
Quoted 38 lines
Quoted 8 lines

        uint64_t          retv;
        volatile uint64_t skip = (uint64_t)(&STACK_SKIP);

        retv = bpf_get_stack(dctx->ctx,
                             buf,
                             bufsiz,
                             skip & BPF_F_SKIP_FIELD_MASK);

Quoted 6 lines

        if (skip)
                return retv / sizeof(uint64_t) - 1;      // branch "A" return retv / sizeof(uint64_t);                  // branch "B" }

If you omit "volatile", the compiler assumes &STACK_SKIP!=0. The emitted code has:

(which is a reasonable assumption if not freestanding, I'd say. Why don't we compile BPF code with -ffreestanding? BPF is almost the *definition* of a freestanding environment...)

Quoted 9 lines

    *)  no run-time "if (skip)" check

    *)  no code for branch "B"

    *)  only code for branch "A"

If you include "volatile", however, the compiler caches &STACK_SKIP on the BPF stack and later performs a run-time check on its value to correctly execute either branch "A" or branch "B".

This feels very mucvh like a workaround to me. Does compiling BPF with -ffreestanding help?

I mean it fixes a bug, so I suppose it should go in if nothing else works, but using volatile is almost always a desperate sticking plaster and this feels like one of those occasions to me.

Signature · 1 line
NULL && (void)
#40 lore raw

On 19 Jun 2025, Kris Van Hees uttered the following:

Quoted 60 lines · Kris Van Hees
Quoted 50 lines · Nick Alcock
Quoted 30 lines

On 16 Jun 2025, Eugene Loh verbalised:

Quoted 10 lines · Nick Alcock
Quoted 6 lines
Quoted 4 lines

Note that we declare the skip count volatile. The compiler might optimize code that uses the STACK_SKIP value, but we will subsequently perform relocations that adjust this value.

... why doesn't this apply to every other extern global variable in get_bvar()? They're all similarly relocated...

Right.  There is potentially a broader problem.  But we simply do not have evidence of misbehavior in other cases.  Ruggedizing other cases could be the subject of a different patch.

Aha, OK. I was just wondering if there was some extra reason.

Quoted 2 lines

The problem in this case is that the compiler seems to assume &symbol!=0, which is reasonable except that we violate that behavior for our relocation tricks.

I wonder where the code for that is... plenty of symbols have value zero.

But, really...

Quoted 6 lines

Consider the C code:

    uint64_t dt_bvar_stackdepth(const dt_dctx_t *dctx)
    {
        uint32_t          bufsiz = (uint32_t) (uint64_t) (&STKSIZ); char              *buf = dctx->mem + (uint64_t)(&STACK_OFF);

Quoted 8 lines

Hm...

extern uint64_t STACK_SKIP;

So we encode information about the stack size and skip value by encoding it in the *address* of the variable? Is there some reason we don't use its value? unlike the stack offset, we're *using* it as a value, not an address...

The issue seems to be (and perhaps this is a cross compiler problem) that e.g.

extern uint64_t PC;

and then code accessing the value of PC (e.g. foo(PC) as a call argument) will yield:

50: 18 02 00 00 00 00 00 00 lddw %r2,0
58: 00 00 00 00 00 00 00 00

                        50: R_BPF_INSN_64       PC
Quoted 8 lines

60: 79 22 00 00 00 00 00 00 ldxdw %r2,[%r2+0]

which shows that it is interpreting PC as an address to a symbol, because it loads the address of the symbol and then dereferences it with offset 0. So, we cannot plug in the value during relocation because the only value we can put there would be an address where the vlaue can be found. To get around this, we "use" Tthe address as the entity to store the value in, knowing that we *never* will interpret it as an address for these specific externs.

Quoted 8 lines

Not a compiler error - since PC is extern uint64_t PC it *is* a variable and so it is present (and accessible) as an address in .data in the location where it is actually defined. Since we never define it, we don't have a .data (which is fine because we only use this for constants known at link time) BUT the compiler of course is free to assume that we *do* have an address to the storage location for PC and thus that we get the value that way. It does not know that the value is constant. So, the trick I use is needed to make this work.

I'm just not sure why it's assuming that its value cannot be NULL, given that you're not dereferencing it anywhere. I guess it's because it's a symbol, but that's only a guess: I haven't managed to find the code that implements this (?)optimization.

Anyway, this is not an objection to this patch, and a patch changing this approach to something that didn't require us to throw volatiles around and hope the compiler doesn't optimize things wrong would be a separate patch anyway: you have my