From: Kris Van Hees <kris.van.hees@oracle.com>
To: eugene.loh@oracle.com
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH 19/38] Retain probe descriptions
Date: Thu, 18 Jul 2024 17:25:10 -0400 [thread overview]
Message-ID: <ZpmINm9hojBpvWhP@oracle.com> (raw)
In-Reply-To: <20240627053810.21928-1-eugene.loh@oracle.com>
I think this needs an actual description of what you are trying to do, because
retaining pdescs in and of itself does not seem meaningful. They do not
contain a reference to the clause they were associated with when the code was
parsed and compiled) and it seems to me that you are doing a sort-of reverse
association, and are actually (indirectly) retaining clauses by keeping a
link of pdescs, one per clause. And you identify the clause by its numeric
id as obtained from its identifier name (which is dynamically assigned during
compilation). That seems fragile and rather non-intuitive.
If memory serves me right, the intent was to retain enablings. Of course, in
the current implementation of DTrace, enablings are nothing more than probes
because the probes have BPF programs associated with them (unless they are
overlying probes, in which case the actual code that gets loaded is part of the
BPF program of the underlying probe (which will be in the enablings list).
When we are retaining enablings, it seems to me that it would make more sense
to keep a list of objects { pdesc, clause } where clause would be the
identifier name of the compiled clause (similar to a function name). Using a
pointer to the actual clause instead is (I think) not going to work becauase
AFAIK the clause does not store a pointer to its own identiifier.
In the end, this will largely do the same thing as your code (here and when it
gets used later), but it removes the implied dependency on how identifier names
for clauses are generated. That could change in the future, and doing so would
completely break this imlementation.
On Thu, Jun 27, 2024 at 01:38:10AM -0400, eugene.loh@oracle.com wrote:
> From: Eugene Loh <eugene.loh@oracle.com>
>
> To support matching probes after dtrace has started, we retain
> probe descriptions.
>
> Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
> ---
> libdtrace/dt_impl.h | 2 ++
> libdtrace/dt_program.c | 37 ++++++++++++++++++++++++++++++++++++-
> 2 files changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
> index 2132eda2..445cd602 100644
> --- a/libdtrace/dt_impl.h
> +++ b/libdtrace/dt_impl.h
> @@ -300,6 +300,8 @@ struct dtrace_hdl {
> dt_list_t dt_programs; /* linked list of dtrace_prog_t's */
> dt_list_t dt_xlators; /* linked list of dt_xlator_t's */
> dt_list_t dt_enablings; /* list of (to be) enabled probes */
> + dtrace_probedesc_t **dt_retained; /* array of retained pdescs */
> + int dt_maxretained; /* number of retained pdescs allocated */
> struct dt_xlator **dt_xlatormap; /* dt_xlator_t's indexed by dx_id */
> id_t dt_xlatorid; /* next dt_xlator_t id to assign */
> dt_ident_t *dt_externs; /* linked list of external symbol identifiers */
> diff --git a/libdtrace/dt_program.c b/libdtrace/dt_program.c
> index a4b052fc..7106c249 100644
> --- a/libdtrace/dt_program.c
> +++ b/libdtrace/dt_program.c
> @@ -163,7 +163,42 @@ dt_prog_stmt(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, dtrace_stmtdesc_t *sdp,
> {
> pi_state_t st;
> dtrace_probedesc_t *pdp = &sdp->dtsd_ecbdesc->dted_probe;
> - int rc;
> + char *sclause = sdp->dtsd_clause->di_name;
> + int rc, nclause;
> +
> + /* Get the clause number from the clause name "dt_clause_"$n. */
> + assert(strncmp(sclause, "dt_clause_", strlen("dt_clause_")) == 0); // FIXME can probably drop this check (make sure the name starts "dt_clause_")
> + nclause = atoi(sclause + strlen("dt_clause_"));
> + assert(nclause < 65536); // FIXME are we okay here with some arbitrary limit?
> +
> + /* Grow the list of retained pdescs, if necessary. */
> + if (nclause >= dtp->dt_maxretained) {
> + int newm;
> + dtrace_probedesc_t **newr;
> +
> + /* Figure how big to make the array. */
> + if (dtp->dt_maxretained > 0)
> + newm = 2 * dtp->dt_maxretained;
> + else
> + newm = 8;
> + while (newm <= nclause)
> + newm *= 2;
> +
> + /* Allocate the bigger array. */
> + newr = dt_zalloc(dtp, newm * sizeof(dtrace_probedesc_t *));
> + if (newr == NULL)
> + return 0;
> +
> + /* Copy data and reset the parameters. */
> + memcpy(newr, dtp->dt_retained, dtp->dt_maxretained * sizeof(dtrace_probedesc_t *));
> + dt_free(dtp, dtp->dt_retained);
> + dtp->dt_retained = newr;
> + dtp->dt_maxretained = newm;
> + }
> +
> + /* Add probe description to retained pdescs. */
> + assert(dtp->dt_retained[nclause] == NULL); // FIXME can probably drop this
> + dtp->dt_retained[nclause] = pdp; // FIXME I think just pointing to pdp is okay. No need to cache my own copy.
>
> st.cnt = cnt;
> st.idp = sdp->dtsd_clause;
> --
> 2.18.4
>
next prev parent reply other threads:[~2024-07-18 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-27 5:38 [PATCH 19/38] Retain probe descriptions eugene.loh
2024-07-18 21:25 ` Kris Van Hees [this message]
2024-07-19 3:34 ` Eugene Loh
2024-07-19 19:52 ` Kris Van Hees
2024-07-22 18:37 ` 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=ZpmINm9hojBpvWhP@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=eugene.loh@oracle.com \
/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