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 v2 15/19] Ignore clauses: some clauses are impossible regardless of uprp
Date: Wed, 23 Oct 2024 16:28:30 -0400 [thread overview]
Message-ID: <Zxlcbjd4QSoU8H+T@oracle.com> (raw)
In-Reply-To: <20240924202554.7011-7-eugene.loh@oracle.com>
On Tue, Sep 24, 2024 at 04:25:54PM -0400, eugene.loh@oracle.com wrote:
> From: Eugene Loh <eugene.loh@oracle.com>
>
> In ignore_clauses, for an underlying probe uprp, we try to
> decide if we can safely ignore clause n.
>
> Meanwhile, for some clauses, the probe description tells us the
> clause will not be called for any USDT probe, regardless of the
> underlying probe. For example, "syscall::write:" can safely be
> ignored, for all uprp.
>
> Add a dtsd_usdt variable to each statement to track status:
>
> USDT_FLAG_UNINITIALIZED not yet initialized
>
> USDT_FLAG_POSSIBLE clause could possibly be called
> for some USDT probe
>
> USDT_FLAG_IGNORE clause can safely be ignored for
> all USDT probes
I think it would be better to use the dtsd_clauseflags member for this.
You can add dt_stmt_set_flag() and dt_stmt_test_flag() (or similar names)
to set and test for specific bits in the dtsd_clauseflags member using
DT_CLSFLAG_* constants. You should be OK with just 2, one to indicate
POSSIBLE and one to indicate IGNORE (neither being set obviously meansnot
yet initialized).
I don't really know what symbol names would be best... perhaps for now use
DT_CLSFLAG_USDT_INCLUDE and DT_CLSFLAG_USDT_EXCLUDE?
Main thing I would like to accomplish here is simply to access flags on the
statements through functions rather than accessing them directly.
>
> Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
> ---
> libdtrace/dt_prov_uprobe.c | 56 ++++++++++++++++++++++++++++++++++++--
> libdtrace/dtrace.h | 1 +
> 2 files changed, 55 insertions(+), 2 deletions(-)
>
> diff --git a/libdtrace/dt_prov_uprobe.c b/libdtrace/dt_prov_uprobe.c
> index 51ad3b55f..938c5784a 100644
> --- a/libdtrace/dt_prov_uprobe.c
> +++ b/libdtrace/dt_prov_uprobe.c
> @@ -27,6 +27,7 @@
> */
> #include <sys/types.h>
> #include <assert.h>
> +#include <ctype.h>
> #include <errno.h>
> #include <string.h>
>
> @@ -232,6 +233,10 @@ grow_strtab(dtrace_hdl_t *dtp)
> return 0;
> }
>
> +#define USDT_FLAG_UNINITIALIZED 0
> +#define USDT_FLAG_POSSIBLE 1
> +#define USDT_FLAG_IGNORE 2
> +
> /*
> * Judge whether clause "n" could ever be called as a USDT probe
> * for this underlying probe.
> @@ -239,7 +244,53 @@ grow_strtab(dtrace_hdl_t *dtp)
> static int
> ignore_clause(dtrace_hdl_t *dtp, int n, const dt_probe_t *uprp)
> {
> - /* To be safe, ignore nothing. */
> + dtrace_probedesc_t *pdp = &dtp->dt_stmts[n]->dtsd_ecbdesc->dted_probe;
> + int *usdt_stat = &dtp->dt_stmts[n]->dtsd_usdt;
> +
> + /*
> + * Some clauses could never be called for a USDT probe,
> + * regardless of the underlying probe uprp. Cache this
> + * status in dt_stmts[n]->dtsd_usdt (pointed to by usdt_stat).
> + */
> + if (*usdt_stat == USDT_FLAG_UNINITIALIZED) {
> + char lastchar = pdp->prv[strlen(pdp->prv) - 1];
> +
> + /*
> + * If the last char in the provider description is
> + * neither '*' nor a digit, it cannot be a USDT probe.
> + */
> + if (lastchar != '*' && !isdigit(lastchar)) {
> + *usdt_stat = USDT_FLAG_IGNORE;
> + return 1;
> + }
> +
> + /*
> + * If the provider description is "pid[0-9]*", it
> + * is a pid probe, not USDT.
> + */
> + if (strncmp(pdp->prv, "pid", 3) == 0) {
> + int i, l = strlen(pdp->prv);
> +
> + for (i = 3; i < l; i++)
> + if (!isdigit((pdp->prv[i])))
> + break;
> +
> + if (i == l) {
> + *usdt_stat = USDT_FLAG_IGNORE;
> + return 1;
> + }
> + }
> +
> + /* Otherwise, it is possibly a USDT probe. */
> + *usdt_stat = USDT_FLAG_POSSIBLE;
> + }
> + if (*usdt_stat == USDT_FLAG_IGNORE)
> + return 1;
> +
> + /*
> + * If USDT_FLAG_POSSIBLE, try to use uprp.
> + */
> +
> return 0;
> }
>
> @@ -271,7 +322,8 @@ static void update_uprobe(dtrace_hdl_t *dtp, void *datap)
>
> stp = dtp->dt_stmts[i];
> assert(stp != NULL);
> - dt_pid_create_usdt_probes(&stp->dtsd_ecbdesc->dted_probe, dtp, &pcb);
> + if (stp->dtsd_usdt != USDT_FLAG_IGNORE)
> + dt_pid_create_usdt_probes(&stp->dtsd_ecbdesc->dted_probe, dtp, &pcb);
> }
>
> while (prid < dtp->dt_probe_id) {
> diff --git a/libdtrace/dtrace.h b/libdtrace/dtrace.h
> index 0f716cd40..f99fb5b6e 100644
> --- a/libdtrace/dtrace.h
> +++ b/libdtrace/dtrace.h
> @@ -151,6 +151,7 @@ typedef struct dtrace_stmtdesc {
> dtrace_attribute_t dtsd_stmtattr; /* statement attributes */
> int dtsd_clauseflags; /* clause flags */
> int dtsd_id; /* index in dtp->dt_stmts */
> + int dtsd_usdt; /* flags describing USDT use, see dt_prov_uprobe.c */
> } dtrace_stmtdesc_t;
>
> /* dtsd clause flags */
> --
> 2.43.5
>
next prev parent reply other threads:[~2024-10-23 20:28 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 ` [PATCH v2 14/19] Ignore clauses in USDT trampoline if we know they are impossible eugene.loh
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 [this message]
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=Zxlcbjd4QSoU8H+T@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