[DTrace-devel] [PATCH v3 14/19] Ignore clauses in USDT trampoline if we know they are impossible
Kris Van Hees
kris.van.hees at oracle.com
Thu Oct 24 16:45:09 UTC 2024
On Wed, Oct 16, 2024 at 12:01:39PM -0400, eugene.loh at oracle.com wrote:
> 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>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> libdtrace/dt_prov_uprobe.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/libdtrace/dt_prov_uprobe.c b/libdtrace/dt_prov_uprobe.c
> index 0289c9223..a3c04478c 100644
> --- a/libdtrace/dt_prov_uprobe.c
> +++ b/libdtrace/dt_prov_uprobe.c
> @@ -263,6 +263,17 @@ clean_usdt_probes(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;
> +}
> +
> static int add_probe_uprobe(dtrace_hdl_t *dtp, dt_probe_t *prp)
> {
> dtrace_difo_t *dp;
> @@ -388,6 +399,9 @@ static int add_probe_usdt(dtrace_hdl_t *dtp, dt_probe_t *prp)
> if (stp == NULL)
> continue;
>
> + 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) &&
> @@ -862,13 +876,17 @@ 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];
> if (stp == NULL)
> continue;
>
> + 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
>
More information about the DTrace-devel
mailing list