From: eugene.loh@oracle.com
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH 08/14] Use uprobes map to call clauses conditionally
Date: Tue, 4 Jun 2024 14:11:07 -0400 [thread overview]
Message-ID: <20240604181113.11505-9-eugene.loh@oracle.com> (raw)
In-Reply-To: <20240604181113.11505-1-eugene.loh@oracle.com>
From: Eugene Loh <eugene.loh@oracle.com>
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
---
libdtrace/dt_prov_uprobe.c | 88 +++++++++++++++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/libdtrace/dt_prov_uprobe.c b/libdtrace/dt_prov_uprobe.c
index 591f2fab..cb79e0a3 100644
--- a/libdtrace/dt_prov_uprobe.c
+++ b/libdtrace/dt_prov_uprobe.c
@@ -498,7 +498,7 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
dt_irlist_t *dlp = &pcb->pcb_ir;
const dt_probe_t *uprp = pcb->pcb_probe;
const dt_uprobe_t *upp = uprp->prv_data;
- const list_probe_t *pop;
+// const list_probe_t *pop;
uint_t lbl_exit = pcb->pcb_exitlbl;
dt_cg_tramp_prologue(pcb);
@@ -522,6 +522,7 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_current_pid_tgid));
emit(dlp, BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, 32));
+#if 0
/*
* Generate a composite conditional clause:
*
@@ -565,6 +566,91 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emitl(dlp, lbl_next,
BPF_NOP());
}
+#else
+ dt_ident_t *uprobes = dt_dlib_get_map(pcb->pcb_hdl, "uprobes");
+ list_clause_t *cl;
+
+ assert(uprobes != NULL);
+
+ /*
+ * Look up in the BPF uprobes map. Space for the look-up key will be used
+ * on the BPF stack at %r9-sizeof(uprobe_map_key_t). The key comprises the
+ * pid (in %r0) and the underlying-probe prid.
+ */
+ emit(dlp, BPF_STORE(BPF_W, BPF_REG_9, (int)(-sizeof(uprobe_map_key_t)), BPF_REG_0));
+ emit(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_9, (int)(-sizeof(dtrace_id_t)) /* or -sizeof(uprobe_map_key_t) + sizeof(pid_t) */, uprp->desc->id));
+ dt_cg_xsetx(dlp, uprobes, DT_LBL_NONE, BPF_REG_1, uprobes->di_id);
+ emit(dlp, BPF_MOV_REG(BPF_REG_2, BPF_REG_9));
+ emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, (int)(-sizeof(uprobe_map_key_t))));
+ emit(dlp, BPF_CALL_HELPER(BPF_FUNC_map_lookup_elem));
+ emit(dlp, BPF_BRANCH_IMM(BPF_JEQ, BPF_REG_0, 0, lbl_exit));
+
+ /* Read the PRID from the table lookup and store to mst->prid. */
+ emit(dlp, BPF_LOAD(BPF_W, BPF_REG_1, BPF_REG_0, 0));
+ emit(dlp, BPF_STORE(BPF_W, BPF_REG_7, DMST_PRID, BPF_REG_1));
+
+ /* Read the bit mask from the table lookup in %r6. */ // FIXME someday, extend this past 64 bits
+ emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_6, BPF_REG_0, offsetof(uprobe_map_val_t, mask)));
+
+ /*
+ * Now loop over clauses.
+ *
+ * How do we know which clauses are called by this underlying probe?
+ * Each dt_probe_t has a "clauses" list, but that's built by
+ *
+ * dt_program.c
+ * dtrace_program_exec()
+ * dtrace_stmt_iter(..., dt_prog_stmt, ...);
+ * dt_prog_stmt()
+ * dt_probe_iter(..., dt_stmt_probe, ...);
+ * dt_stmt_probe()
+ * dt_probe_add_clause(...);
+ *
+ * which is to say that the "clauses" list will be built for overlying
+ * probes, while we are interested here in underlying probes. Should
+ * dt_probe_add_clause() also take some provider-specific action?
+ *
+ * For now, let's just look up the clause using what we know about
+ * the clause numbering.
+ */
+ /*
+ * Hold the bit mask in %r6.
+ */
+ for (cl = dt_list_next(&upp->clauses); cl != NULL; cl = dt_list_next(cl)) {
+ char nm[32]; // FIXME hardwired size
+ dt_ident_t *idp;
+ uint_t lbl_next = dt_irlist_label(dlp);
+
+ sprintf(nm, "dt_clause_%d", cl->clause);
+ idp = dt_idhash_lookup(pcb->pcb_hdl->dt_bpfsyms, nm); // FIXME what if idp is NULL?
+
+ /* Test the lowest bit. */
+ emit(dlp, BPF_MOV_REG(BPF_REG_1, BPF_REG_6));
+ emit(dlp, BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 1));
+ emit(dlp, BPF_BRANCH_IMM(BPF_JEQ, BPF_REG_1, 0, lbl_next));
+
+ /*
+ * if (*dctx.act != act) // ldw %r0, [%r9 + DCTX_ACT]
+ * goto exit; // ldw %r0, [%r0 + 0]
+ * // jne %r0, act, lbl_exit
+ */
+ emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_9, DCTX_ACT));
+ emit(dlp, BPF_LOAD(BPF_W, BPF_REG_0, BPF_REG_0, 0));
+ emit(dlp, BPF_BRANCH_IMM(BPF_JNE, BPF_REG_0, DT_ACTIVITY_ACTIVE, lbl_exit));
+
+ /* dctx.mst->scratch_top = 8 */
+ emit(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_7, DMST_SCRATCH_TOP, 8));
+
+ /* Call clause. */
+ emit(dlp, BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
+ emite(dlp, BPF_CALL_FUNC(idp->di_id), idp);
+
+ /* Finished this clause. */
+ emitl(dlp, lbl_next,
+ BPF_NOP());
+ emit(dlp, BPF_ALU64_IMM(BPF_RSH, BPF_REG_6, 1));
+ }
+#endif
dt_cg_tramp_return(pcb);
--
2.18.4
next prev parent reply other threads:[~2024-06-04 18:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 18:10 "proof of concept" for systemwide USDT eugene.loh
2024-06-04 18:11 ` [PATCH 01/14] Move comment closer to the code it describes eugene.loh
2024-06-04 18:21 ` [DTrace-devel] " Kris Van Hees
2024-06-04 18:11 ` [PATCH 02/14] Clean up prp/uprp variable names eugene.loh
2024-06-04 18:44 ` [DTrace-devel] " Kris Van Hees
2024-06-05 18:18 ` Eugene Loh
2024-06-04 18:11 ` [PATCH 03/14] Let USDT module names contain dots eugene.loh
2024-06-04 20:42 ` [DTrace-devel] " Kris Van Hees
2024-06-04 22:30 ` Eugene Loh
2024-06-07 18:48 ` Nick Alcock
2024-06-07 22:22 ` Eugene Loh
2024-06-04 18:11 ` [PATCH 04/14] Track uprobe provider descriptions eugene.loh
2024-06-04 21:10 ` [DTrace-devel] " Kris Van Hees
2024-06-07 21:40 ` Eugene Loh
2024-06-07 22:16 ` Kris Van Hees
2024-06-10 21:23 ` Eugene Loh
2024-06-10 21:31 ` Kris Van Hees
2024-06-04 18:11 ` [PATCH 05/14] Add a hook for a provider-specific "update" function eugene.loh
2024-06-04 21:38 ` [DTrace-devel] " Kris Van Hees
2024-06-10 22:14 ` Eugene Loh
2024-06-04 18:11 ` [PATCH 06/14] Add clauses to per-uprobe list eugene.loh
2024-06-04 18:11 ` [PATCH 07/14] Create the BPF uprobes map eugene.loh
2024-06-05 4:33 ` [DTrace-devel] " Kris Van Hees
2024-06-10 20:55 ` Eugene Loh
2024-06-04 18:11 ` eugene.loh [this message]
2024-06-04 18:11 ` [PATCH 09/14] Systemwide USDT WIP eugene.loh
2024-06-04 18:11 ` [PATCH 10/14] Fix the consumer's picture of the EPID eugene.loh
2024-06-04 18:11 ` [PATCH 11/14] Back out the previous patch eugene.loh
2024-06-04 18:11 ` [PATCH 12/14] Fix comments that hardwire DBUF_ offsets eugene.loh
2024-06-04 18:11 ` [PATCH 13/14] Clean up some comments eugene.loh
2024-06-04 18:11 ` [PATCH 14/14] Have the consumer get the PRID from the output buffer 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=20240604181113.11505-9-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