[DTrace-devel] [PATCH 07/12] Fix drop counter handling for local-only updates

Kris Van Hees kris.van.hees at oracle.com
Fri Jan 5 05:29:17 UTC 2024


When at the end of a work loop, the drop counters are updates for local
updates only (i.e. when tracing is not stopped yet), an invalid drop
count could be reported if a drop occured in the BEGIN probe.  The cause
is that the code assumed that both copies of the status data contained
valid data.  But when a drop occurs in the BEGIN probe, only the first
copy will have non-zero values.  Since local-only updates assume that
the two copies are identical except for a possible change due to the
local update, and any earlier status update would already have reported
any differences, it is safe to just copy all data prior to performing
the local updates.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_work.c                           |  4 ++-
 .../drops/drp.DTRACEDROP_DYNAMIC.local_only.d | 30 +++++++++++++++++++
 .../drops/drp.DTRACEDROP_DYNAMIC.local_only.r |  6 ++++
 3 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.d
 create mode 100644 test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.r

diff --git a/libdtrace/dt_work.c b/libdtrace/dt_work.c
index fe88a48e..6cac93ea 100644
--- a/libdtrace/dt_work.c
+++ b/libdtrace/dt_work.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2024, 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.
  */
@@ -271,6 +271,8 @@ dtrace_work(dtrace_hdl_t *dtp, FILE *fp, dtrace_consume_probe_f *pfunc,
 	 * than once).
 	 */
 	if (!dtp->dt_stopped) {
+		gen = dtp->dt_statusgen;
+		dtp->dt_status[gen] = dtp->dt_status[gen ^ 1];
 		dt_add_local_status(dtp);
 		gen = dtp->dt_statusgen ^ 1;
 	} else {
diff --git a/test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.d b/test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.d
new file mode 100644
index 00000000..2ebcf150
--- /dev/null
+++ b/test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.d
@@ -0,0 +1,30 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2024, 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.
+ */
+
+/*
+ * Ensure that when (at the end of a work loop) a local-only update is done, we
+ * do not end up reporting (unsigned long long)-1.
+ *
+ * If this bug exists, output will look like:
+ *	dtrace: [DTRACEDROP_DYNAMIC] 1 dynamic variable drop
+ *	dtrace: [DTRACEDROP_DYNAMIC] 18446744073709551615 dynamic variable drops
+ */
+
+#pragma D option dynvarsize=15
+
+BEGIN
+{
+	self->a = 1;
+	self->b = 2;
+	self->c = 3;
+	self->d = 4;
+}
+
+tick-1s
+{
+	exit(0);
+}
diff --git a/test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.r b/test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.r
new file mode 100644
index 00000000..8af0a5f5
--- /dev/null
+++ b/test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.r
@@ -0,0 +1,6 @@
+                   FUNCTION:NAME
+                        :tick-1s 
+
+-- @@stderr --
+dtrace: script 'test/unittest/drops/drp.DTRACEDROP_DYNAMIC.local_only.d' matched 2 probes
+dtrace: [DTRACEDROP_DYNAMIC] 1 dynamic variable drop
-- 
2.42.0




More information about the DTrace-devel mailing list