[DTrace-devel] [PATCH 14/19] Ignore clauses in USDT trampoline if we know they are impossible

eugene.loh at oracle.com eugene.loh at oracle.com
Thu Aug 29 05:25:53 UTC 2024


From: Eugene Loh <eugene.loh at oracle.com>

An underlying probe might have to call all sorts of clauses if new
USDT processes start up.  Currently, the underlying probe trampoline
simply loops over all clauses, deciding whether to call a clause
based on a run-time bit mask.

While this approach works, it can mean, e.g., that clauses are being
loaded unnecessarily into BPF programs, bloating code.  It also means
that the trampoline is looping over unnecessarily many clauses.

Meanwhile, it is possible to know in certain cases that a clause
could never be called for a particular underlying probe.  The
heuristics can be tricky, but that challenge can be faced incrementally.

Introduce an ignore_clause() function that, for an underlying probe,
determines whether some clause (denoted by index) can safely be
ignored.

The same ignore_clause() function should be called both during code
generation of the trampoline as well as during the construction of
the bit mask.  Further, for a given clause n and underlying probe upp,
the function should always give the same output.  The set of ignored
clauses should remain fixed over the lifetime of an underlying probe.

For now, conservatively, ignore_clause() ignores nothing.  Later
patches will introduce heuristics for ignoring clauses.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_prov_uprobe.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/libdtrace/dt_prov_uprobe.c b/libdtrace/dt_prov_uprobe.c
index 98d7b79b..883a3e9d 100644
--- a/libdtrace/dt_prov_uprobe.c
+++ b/libdtrace/dt_prov_uprobe.c
@@ -232,6 +232,17 @@ grow_strtab(dtrace_hdl_t *dtp)
 	return 0;
 }
 
+/*
+ * Judge whether clause "n" could ever be called as a USDT probe
+ * for this underlying probe.
+ */
+static int
+ignore_clause(dtrace_hdl_t *dtp, int n, const dt_probe_t *uprp)
+{
+	/* To be safe, ignore nothing. */
+	return 0;
+}
+
 /*
  * Update the uprobe provider.
  */
@@ -348,6 +359,9 @@ static void update_uprobe(dtrace_hdl_t *dtp, void *datap)
 				int n;
 
 				for (n = 0; n < dtp->dt_clause_nextid; n++) {
+					if (ignore_clause(dtp, n, uprp))
+						continue;
+
 					if (dt_gmatch(prp->desc->prv, dtp->dt_stmts[n]->dtsd_ecbdesc->dted_probe.prv) &&
 					    dt_gmatch(prp->desc->mod, dtp->dt_stmts[n]->dtsd_ecbdesc->dted_probe.mod) &&
 					    dt_gmatch(prp->desc->fun, dtp->dt_stmts[n]->dtsd_ecbdesc->dted_probe.fun) &&
@@ -803,7 +817,12 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
 	 */
 	for (n = 0; n < dtp->dt_clause_nextid; n++) {
 		dt_ident_t	*idp = dtp->dt_stmts[n]->dtsd_clause;
-		uint_t		lbl_next = dt_irlist_label(dlp);
+		uint_t		lbl_next;
+
+		if (ignore_clause(dtp, n, uprp))
+			continue;
+
+		lbl_next = dt_irlist_label(dlp);
 
 		/* If the lowest %r6 bit is 0, skip over this clause. */
 		emit(dlp,  BPF_MOV_REG(BPF_REG_1, BPF_REG_6));
-- 
2.43.5




More information about the DTrace-devel mailing list