public inbox for dtrace@lists.linux.dev
 help / color / mirror / Atom feed
From: eugene.loh@oracle.com
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH v2 14/19] Ignore clauses in USDT trampoline if we know they are impossible
Date: Tue, 24 Sep 2024 16:25:53 -0400	[thread overview]
Message-ID: <20240924202554.7011-6-eugene.loh@oracle.com> (raw)
In-Reply-To: <20240924202554.7011-1-eugene.loh@oracle.com>

From: Eugene Loh <eugene.loh@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@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 d08bd2e14..51ad3b55f 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.
  */
@@ -358,6 +369,9 @@ static void update_uprobe(dtrace_hdl_t *dtp, void *datap)
 					stp = dtp->dt_stmts[n];
 					assert(stp != NULL);
 
+					if (ignore_clause(dtp, n, uprp))
+						continue;
+
 					if (dt_gmatch(prp->desc->prv, stp->dtsd_ecbdesc->dted_probe.prv) &&
 					    dt_gmatch(prp->desc->mod, stp->dtsd_ecbdesc->dted_probe.mod) &&
 					    dt_gmatch(prp->desc->fun, stp->dtsd_ecbdesc->dted_probe.fun) &&
@@ -814,11 +828,16 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
 	for (n = 0; n < dtp->dt_stmt_nextid; n++) {
 		dtrace_stmtdesc_t *stp;
 		dt_ident_t	*idp;
-		uint_t		lbl_next = dt_irlist_label(dlp);
+		uint_t		lbl_next;
 
 		stp = dtp->dt_stmts[n];
 		assert(stp != NULL);
+
+		if (ignore_clause(dtp, n, uprp))
+			continue;
+
 		idp = stp->dtsd_clause;
+		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


  parent reply	other threads:[~2024-09-24 20:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24 20:25 [PATCH v7 03/19] Deprecate enabled probe ID (epid) eugene.loh
2024-09-24 20:25 ` [PATCH v2 05/19] Split dt_pid_create_probes() into pid and USDT functions eugene.loh
2024-09-24 20:25 ` [PATCH v3 07/19] Create the BPF usdt_prids map eugene.loh
2024-09-24 20:25 ` [PATCH v3 09/19] Use usdt_prids map to call clauses conditionally for USDT probes eugene.loh
2024-09-24 20:25 ` [PATCH v3 11/19] Support USDT wildcard provider descriptions eugene.loh
2024-10-24 16:38   ` Kris Van Hees
2024-10-25  5:56     ` Eugene Loh
2024-10-25 12:48       ` Kris Van Hees
2024-09-24 20:25 ` eugene.loh [this message]
2024-09-24 20:25 ` [PATCH v2 15/19] Ignore clauses: some clauses are impossible regardless of uprp eugene.loh
2024-10-23 20:28   ` Kris Van Hees
2024-10-24 19:30     ` Eugene Loh
2024-10-24 21:12       ` [DTrace-devel] " Kris Van Hees
2024-10-24 21:53         ` Eugene Loh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240924202554.7011-6-eugene.loh@oracle.com \
    --to=eugene.loh@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox