Support multiple overlying probes in the uprobe trampoline
PATCH v2 8/19 Support multiple overlying probes in the uprobe trampoline
From: Eugene Loh <[email protected]>
An underlying probe could support all sorts of overlying probes:
- pid entry
- pid return
- pid offset
- USDT
- USDT is-enabled
The overlying probes belonging to an underlying probe match the underlying probe -- except possibly in pid. So, an underlying probe loops over its overlying probes, looking for a pid match.
The trampoline would look for only one match.
However, more than one overlying probe might match. Therefore, change the loop to keep going even after a match has been found.
Incidentally, it is actually only pid offset probes that could "collide" with any other overlying probes for a given pid:
-) pid return probes are implemented with uretprobes
and so cannot "collide" with any other probes
-) no two USDT probes -- is-enabled or not -- can map
to the same underlying probe for any pid
-) no USDT probe -- is-enabled or not -- can map to
to the same underlying probe as a pid entry
So, possibly one could optimize the trampoline -- e.g., by adding BPF code to exit once two matches have been made.
Note that the flag we pass in to dt_cg_tramp_copy_args_from_regs() should depend on whether the overlying probe is a pid or USDT probe. We used to check PP_IS_FUNCALL, but the upp could be for both. So check the provider for the overlying probe instead. (A later patch will move USDT probes to a different mechanism anyhow.)
--- libdtrace/dt_prov_uprobe.c | 45 +++++----- test/unittest/pid/tst.entry_off0.sh | 125 ++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 26 deletions(-) create mode 100755 test/unittest/pid/tst.entry_off0.sh
libdtrace/dt_prov_uprobe.c +19 -26
@@ -754,38 +754,23 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)* // (%r7 = dctx->mst) * // (%r8 = dctx->ctx) */ - -dt_cg_tramp_copy_regs (pcb); -if (upp->flags &PP_IS_RETURN ) -dt_cg_tramp_copy_rval_from_regs (pcb); -else -dt_cg_tramp_copy_args_from_regs (pcb, - !(upp->flags &PP_IS_FUNCALL )); +dt_cg_tramp_copy_regs (pcb);// call this only once for all clauses? /* -* Retrieve the PID of the process that caused the probe to fire. +* Hold the PID of the process that caused the probe to fire in %r6. */ emit (dlp,BPF_CALL_HELPER (BPF_FUNC_get_current_pid_tgid));emit (dlp,BPF_ALU64_IMM (BPF_RSH ,BPF_REG_0 ,32 )); +emit (dlp,BPF_MOV_REG (BPF_REG_6 ,BPF_REG_0 ));/* -* Generate a composite conditional clause: +* Loop over overlying probes, calling clauses for those that match: * -* if (pid == PID1) { -* dctx->mst->prid = PRID1; -* < any number of clause calls > -* goto exit; -* } else if (pid == PID2) { -* dctx->mst->prid = PRID2; -* < any number of clause calls > -* goto exit; -* } else if (pid == ...) { -* < ... > -* } -* -* It is valid and safe to use %r0 to hold the pid value because there -* are no assignments to %r0 possible in between the conditional -* statements. +* for overlying probes (that match except possibly for pid) +* if (pid matches) { +* dctx->mst->prid = PRID1; +* < any number of clause calls > +* } */ for (pop =dt_list_next (&upp->probes); pop !=NULL ; pop =dt_list_next (pop)) {
@@ -800,14 +785,22 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl) idp =dt_dlib_add_probe_var (pcb->pcb_hdl, prp);assert (idp !=NULL ); +/* +* Register copies. +*/ +if (upp->flags &PP_IS_RETURN ) +dt_cg_tramp_copy_rval_from_regs (pcb); +else +dt_cg_tramp_copy_args_from_regs (pcb, + prp->prov->impl == &dt_pid ?1 :0 ); +/* * Check whether this pid-provider probe serves the current * process, and emit a sequence of clauses for it when it does. */ -emit (dlp,BPF_BRANCH_IMM (BPF_JNE ,BPF_REG_0 , pid, lbl_next)); +emit (dlp,BPF_BRANCH_IMM (BPF_JNE ,BPF_REG_6 , pid, lbl_next));emite (dlp,BPF_STORE_IMM (BPF_W ,BPF_REG_7 ,DMST_PRID , prp->desc->id), idp);dt_cg_tramp_call_clauses (pcb, prp,DT_ACTIVITY_ACTIVE ); -emit (dlp,BPF_JUMP (lbl_exit));emitl (dlp, lbl_next,BPF_NOP ()); }
test/unittest/pid/tst.entry_off0.sh new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v4 11/19 Support USDT wildcard provider descriptions
From: Eugene Loh <[email protected]>
To look for pid probes, whose pid values must be specified explicitly, we can require that the provider description should end in a digit.
For USDT probes, however, there can be wildcard descriptions. This includes a blank provider description as well as a description that ends in an '*'.
So, get rid of dt_pid_create_probes(), replacing it with
dt_pid_create_pid_probes() dt_pid_create_usdt_probes()
calling each one appropriately.
This is rudimentary support. We still need to:
- handle globs in dt_pid_create_probes_module()
- add process monitoring / inotify
--- libdtrace/dt_cc.c | 17 ++++++++++------- libdtrace/dt_pid.c | 8 -------- libdtrace/dt_pid.h | 4 ++-- .../dtrace-util/tst.ListProbesFuncUSDT.sh | 1 - .../dtrace-util/tst.ListProbesModuleUSDT.sh | 1 - .../dtrace-util/tst.ListProbesNameUSDT.sh | 1 - .../dtrace-util/tst.ListProbesProviderUSDT.sh | 1 - test/unittest/usdt/tst.forker.sh | 1 - 8 files changed, 12 insertions(+), 22 deletions(-)
libdtrace/dt_cc.c +10 -7
@@ -262,24 +262,27 @@ dt_setcontext(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp)int err;/* -* Both kernel and pid based providers are allowed to have names -* ending with what could be interpreted as a number. We assume it's -* a pid and that we may need to dynamically create probes for -* that process if: +* A provider name ending in a digit could be for a pid provider. +* We may need to dynamically create probes for that process if: * * (1) The provider doesn't exist, or, * (2) The provider exists and has DT_PROVIDER_PID flag set. * -* On an error, dt_pid_create_probes() will set the error message +* On an error, dt_pid_create_pid_probes() will set the error message * and tag -- we just have to longjmp() out of here. */ if (pdp->prv && pdp->prv[0 ] &&isdigit (pdp->prv[strlen (pdp->prv) -1 ]) && ((pvp =dt_provider_lookup (dtp, pdp->prv)) ==NULL || pvp->pv_flags &DT_PROVIDER_PID ) && -dt_pid_create_probes ((dtrace_probedesc_t *)pdp, dtp, yypcb) !=0 ) { +dt_pid_create_pid_probes ((dtrace_probedesc_t *)pdp, dtp, yypcb) !=0 ) +longjmp (yypcb->pcb_jmpbuf,EDT_COMPILER ); + +/* +* USDT probes. +*/ +if (dt_pid_create_usdt_probes ((dtrace_probedesc_t *)pdp, dtp, yypcb) !=0 )longjmp (yypcb->pcb_jmpbuf,EDT_COMPILER ); - }/* * Call dt_probe_info() to get the probe arguments and attributes. If
libdtrace/dt_pid.c +0 -8
@@ -1207,14 +1207,6 @@ dt_pid_create_usdt_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp, dt_pcb_t *return err ?-1 :0 ; } -int -dt_pid_create_probes (dtrace_probedesc_t *pdp,dtrace_hdl_t *dtp,dt_pcb_t *pcb) -{ -if (dt_pid_create_pid_probes (pdp, dtp, pcb)) -return -1 ; -return dt_pid_create_usdt_probes (pdp, dtp, pcb); -} -int dt_pid_create_probes_module (dtrace_hdl_t *dtp,dt_proc_t *dpr) {
libdtrace/dt_pid.h +2 -2
@@ -16,10 +16,10 @@extern "C" {#endif +extern int dt_pid_create_pid_probes (dtrace_probedesc_t *,dtrace_hdl_t *, +dt_pcb_t *);extern int dt_pid_create_usdt_probes (dtrace_probedesc_t *,dtrace_hdl_t *,dt_pcb_t *); -extern int dt_pid_create_probes (dtrace_probedesc_t *,dtrace_hdl_t *, -dt_pcb_t *);extern int dt_pid_create_probes_module (dtrace_hdl_t *,dt_proc_t *);extern pid_t dt_pid_get_pid (const dtrace_probedesc_t *,dtrace_hdl_t *,dt_pcb_t *,dt_proc_t *);
test/unittest/dtrace-util/tst.ListProbesFuncUSDT.sh +0 -1
@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #
test/unittest/dtrace-util/tst.ListProbesModuleUSDT.sh +0 -1
@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #
test/unittest/dtrace-util/tst.ListProbesNameUSDT.sh +0 -1
@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #
test/unittest/dtrace-util/tst.ListProbesProviderUSDT.sh +0 -1
@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #
test/unittest/usdt/tst.forker.sh +0 -1
@@ -7,7 +7,6 @@ # # # @@timeout: 120 -# @@xfail: dtv2 USDT wildcard if [ $# != 1 ]; then echo expected one argument: '<'dtrace-path'>'
Signature · 1 line
2.43.5
Re: [PATCH v4 11/19] Support USDT wildcard provider descriptions
Quoted 14 lines · On Fri, Oct 25, 2024 at 02:34:22AM -0400, [email protected] wrote:
From: Eugene Loh <[email protected]>
To look for pid probes, whose pid values must be specified explicitly, we can require that the provider description should end in a digit.
For USDT probes, however, there can be wildcard descriptions. This includes a blank provider description as well as a description that ends in an '*'.
So, get rid of
dt_pid_create_probes(), replacing it with
dt_pid_create_pid_probes()dt_pid_create_usdt_probes()
calling each one appropriately.
Quoted 5 lines
This is rudimentary support. We still need to:
- handle globs indt_pid_create_probes_module()
- add process monitoring / inotifySigned-off-by Eugene Loh <[email protected]>
Quoted 149 lines
--- libdtrace/dt_cc.c | 17 ++++++++++------- libdtrace/dt_pid.c | 8 -------- libdtrace/dt_pid.h | 4 ++-- .../dtrace-util/tst.ListProbesFuncUSDT.sh | 1 - .../dtrace-util/tst.ListProbesModuleUSDT.sh | 1 - .../dtrace-util/tst.ListProbesNameUSDT.sh | 1 - .../dtrace-util/tst.ListProbesProviderUSDT.sh | 1 - test/unittest/usdt/tst.forker.sh | 1 - 8 files changed, 12 insertions(+), 22 deletions(-)libdtrace/dt_cc.c +10
-7@@ -262,24 +262,27 @@ dt_setcontext(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp)int err;/* -* Both kernel and pid based providers are allowed to have names -* ending with what could be interpreted as a number. We assume it's -* a pid and that we may need to dynamically create probes for -* that process if: +* A provider name ending in a digit could be for a pid provider. +* We may need to dynamically create probes for that process if: * * (1) The provider doesn't exist, or, * (2) The provider exists and has DT_PROVIDER_PID flag set. * -* On an error, dt_pid_create_probes() will set the error message +* On an error, dt_pid_create_pid_probes() will set the error message * and tag -- we just have to longjmp() out of here. */ if (pdp->prv && pdp->prv[0 ] &&isdigit (pdp->prv[strlen (pdp->prv) -1 ]) && ((pvp =dt_provider_lookup (dtp, pdp->prv)) ==NULL || pvp->pv_flags &DT_PROVIDER_PID ) && -dt_pid_create_probes ((dtrace_probedesc_t *)pdp, dtp, yypcb) !=0 ) { +dt_pid_create_pid_probes ((dtrace_probedesc_t *)pdp, dtp, yypcb) !=0 ) +longjmp (yypcb->pcb_jmpbuf,EDT_COMPILER ); + +/* +* USDT probes. +*/ +if (dt_pid_create_usdt_probes ((dtrace_probedesc_t *)pdp, dtp, yypcb) !=0 )longjmp (yypcb->pcb_jmpbuf,EDT_COMPILER ); - }/* * Call dt_probe_info() to get the probe arguments and attributes. If libdtrace/dt_pid.c +0
-8@@ -1207,14 +1207,6 @@ dt_pid_create_usdt_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp, dt_pcb_t *return err ?-1 :0 ; } -int -dt_pid_create_probes (dtrace_probedesc_t *pdp,dtrace_hdl_t *dtp,dt_pcb_t *pcb) -{ -if (dt_pid_create_pid_probes (pdp, dtp, pcb)) -return -1 ; -return dt_pid_create_usdt_probes (pdp, dtp, pcb); -} -int dt_pid_create_probes_module (dtrace_hdl_t *dtp,dt_proc_t *dpr) {libdtrace/dt_pid.h +2
-2@@ -16,10 +16,10 @@extern "C" {#endif +extern int dt_pid_create_pid_probes (dtrace_probedesc_t *,dtrace_hdl_t *, +dt_pcb_t *);extern int dt_pid_create_usdt_probes (dtrace_probedesc_t *,dtrace_hdl_t *,dt_pcb_t *); -extern int dt_pid_create_probes (dtrace_probedesc_t *,dtrace_hdl_t *, -dt_pcb_t *);extern int dt_pid_create_probes_module (dtrace_hdl_t *,dt_proc_t *);extern pid_t dt_pid_get_pid (const dtrace_probedesc_t *,dtrace_hdl_t *,dt_pcb_t *,dt_proc_t *);test/unittest/dtrace-util/tst.ListProbesFuncUSDT.sh +0
-1@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #test/unittest/dtrace-util/tst.ListProbesModuleUSDT.sh +0
-1@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #test/unittest/dtrace-util/tst.ListProbesNameUSDT.sh +0
-1@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #test/unittest/dtrace-util/tst.ListProbesProviderUSDT.sh +0
-1@@ -5,7 +5,6 @@ # Licensed under the Universal Permissive License v 1.0 as shown at # http://oss.oracle.com/licenses/upl. # -# @@xfail: dtv2 ## #test/unittest/usdt/tst.forker.sh +0
-1@@ -7,7 +7,6 @@ # # # @@timeout: 120 -# @@xfail: dtv2 USDT wildcard if [ $# != 1 ]; then echo expected one argument: '<'dtrace-path'>'Signature · 1 line
2.43.5
PATCH v3 15/19 Ignore clauses: some clauses are impossible regardless of uprp
In reply to [email protected]From: Eugene Loh <[email protected]>
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 clause flags to track a statement's status. Specifically, a flag may indicate that a statement can be excluded for every possible USDT probe or included because it might be needed for some possible USDT probe.
--- libdtrace/dt_program.c | 15 +++++++++++ libdtrace/dt_program.h | 3 +++ libdtrace/dt_prov_uprobe.c | 53 ++++++++++++++++++++++++++++++++++++-- libdtrace/dtrace.h | 2 ++ 4 files changed, 71 insertions(+), 2 deletions(-)
libdtrace/dt_program.c +15 -0
@@ -20,6 +20,21 @@#include <dt_probe.h> #include <dt_bpf.h> +int +dt_stmt_clsflag_set (dtrace_stmtdesc_t *stp,int flags) { + stp->dtsd_clauseflags |= flags; + +return 0 ; +} + +int +dt_stmt_clsflag_test (dtrace_stmtdesc_t *stp,int flags) { +if (stp->dtsd_clauseflags & flags) +return 1 ; + +return 0 ; +} +dtrace_prog_t *dt_program_create (dtrace_hdl_t *dtp) {
libdtrace/dt_program.h +3 -0
@@ -28,6 +28,9 @@ struct dtrace_prog {uint8_t dp_dofversion;/* DOF version this program requires */ }; +extern int dt_stmt_clsflag_set (dtrace_stmtdesc_t *stp,int flags); +extern int dt_stmt_clsflag_test (dtrace_stmtdesc_t *stp,int flags); +extern dtrace_prog_t *dt_program_create (dtrace_hdl_t *);extern void dt_program_destroy (dtrace_hdl_t *,dtrace_prog_t *);
libdtrace/dt_prov_uprobe.c +51 -2
77 lines not on this page · raw message
libdtrace/dtrace.h +2 -0
@@ -161,6 +161,8 @@ typedef struct dtrace_stmtdesc {#define DT_CLSFLAG_EXIT 16/* exit */ #define DT_CLSFLAG_DESTRUCT 32/* destructive */ #define DT_CLSFLAG_AGGREGATION 64/* aggregation */ +#define DT_CLSFLAG_USDT_INCLUDE 128/* could be used in USDT clause */ +#define DT_CLSFLAG_USDT_EXCLUDE 256/* could not be used in USDT clause */ typedef int dtrace_stmt_f (dtrace_hdl_t *dtp,dtrace_prog_t *pgp,dtrace_stmtdesc_t *sdp,void *data);
Signature · 1 line
2.43.5
Re: [PATCH v3 15/19] Ignore clauses: some clauses are impossible regardless of uprp
Quoted 10 lines · On Fri, Oct 25, 2024 at 02:34:23AM -0400, [email protected] wrote:
From: Eugene Loh <[email protected]>
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.
Quoted 6 lines
Add clause flags to track a statement's status. Specifically, a flag may indicate that a statement can be excluded for every possible USDT probe or included because it might be needed for some possible USDT probe.
Signed-off-by Eugene Loh <[email protected]>
Quoted 148 lines
--- libdtrace/dt_program.c | 15 +++++++++++ libdtrace/dt_program.h | 3 +++ libdtrace/dt_prov_uprobe.c | 53 ++++++++++++++++++++++++++++++++++++-- libdtrace/dtrace.h | 2 ++ 4 files changed, 71 insertions(+), 2 deletions(-)libdtrace/dt_program.c +15
-0@@ -20,6 +20,21 @@#include <dt_probe.h> #include <dt_bpf.h> +int +dt_stmt_clsflag_set (dtrace_stmtdesc_t *stp,int flags) { + stp->dtsd_clauseflags |= flags; + +return 0 ; +} + +int +dt_stmt_clsflag_test (dtrace_stmtdesc_t *stp,int flags) { +if (stp->dtsd_clauseflags & flags) +return 1 ; + +return 0 ; +} +dtrace_prog_t *dt_program_create (dtrace_hdl_t *dtp) {libdtrace/dt_program.h +3
-0@@ -28,6 +28,9 @@ struct dtrace_prog {uint8_t dp_dofversion;/* DOF version this program requires */ }; +extern int dt_stmt_clsflag_set (dtrace_stmtdesc_t *stp,int flags); +extern int dt_stmt_clsflag_test (dtrace_stmtdesc_t *stp,int flags); +extern dtrace_prog_t *dt_program_create (dtrace_hdl_t *);extern void dt_program_destroy (dtrace_hdl_t *,dtrace_prog_t *);libdtrace/dt_prov_uprobe.c +51
-2@@ -27,6 +27,7 @@*/ #include <sys/types.h> #include <assert.h> +#include <ctype.h> #include <errno.h> #include <string.h> @@ -37,6 +38,7 @@#include "dt_list.h" #include "dt_provider_tp.h" #include "dt_probe.h" +#include "dt_program.h" #include "dt_pid.h" #include "dt_string.h" #include "port.h" @@ -270,7 +272,53 @@ clean_usdt_probes(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_stmtdesc_t *stp = dtp->dt_stmts[n]; +dtrace_probedesc_t *pdp = &stp->dtsd_ecbdesc->dted_probe; + +/* +* Some clauses could never be called for a USDT probe, +* regardless of the underlying probe uprp. Cache this +* status in the clause flags for dt_stmts[n]. +*/ +if (dt_stmt_clsflag_test (stp,DT_CLSFLAG_USDT_INCLUDE |DT_CLSFLAG_USDT_EXCLUDE ) ==0 ) { +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)) { +dt_stmt_clsflag_set (stp,DT_CLSFLAG_USDT_EXCLUDE ); +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) { +dt_stmt_clsflag_set (stp,DT_CLSFLAG_USDT_EXCLUDE ); +return 1 ; + } + } + +/* Otherwise, it is possibly a USDT probe. */ +dt_stmt_clsflag_set (stp,DT_CLSFLAG_USDT_INCLUDE ); + } +if (dt_stmt_clsflag_test (stp,DT_CLSFLAG_USDT_EXCLUDE ) ==1 ) +return 1 ; + +/* +* If we cannot ignore this statement, try to use uprp. +*/ +return 0 ; }@@ -453,7 +501,8 @@ static int discover(dtrace_hdl_t *dtp) stp = dtp->dt_stmts[i];if (stp ==NULL )continue ; -dt_pid_create_usdt_probes (&stp->dtsd_ecbdesc->dted_probe, dtp, &pcb); +if (dt_stmt_clsflag_test (stp,DT_CLSFLAG_USDT_EXCLUDE ) !=1 ) +dt_pid_create_usdt_probes (&stp->dtsd_ecbdesc->dted_probe, dtp, &pcb); }return 0 ;libdtrace/dtrace.h +2
-0@@ -161,6 +161,8 @@ typedef struct dtrace_stmtdesc {#define DT_CLSFLAG_EXIT 16/* exit */ #define DT_CLSFLAG_DESTRUCT 32/* destructive */ #define DT_CLSFLAG_AGGREGATION 64/* aggregation */ +#define DT_CLSFLAG_USDT_INCLUDE 128/* could be used in USDT clause */ +#define DT_CLSFLAG_USDT_EXCLUDE 256/* could not be used in USDT clause */ typedef int dtrace_stmt_f (dtrace_hdl_t *dtp,dtrace_prog_t *pgp,dtrace_stmtdesc_t *sdp,void *data);Signature · 1 line
2.43.5
Quoted 52 lines · On Fri, Oct 25, 2024 at 02:34:21AM -0400, [email protected] wrote:
From: Eugene Loh <[email protected]>
An underlying probe could support all sorts of overlying probes:
- pid entry
- pid return
- pid offset
- USDT
- USDT is-enabledThe overlying probes belonging to an underlying probe match the underlying probe -- except possibly in pid. So, an underlying probe loops over its overlying probes, looking for a pid match.
The trampoline would look for only one match.
However, more than one overlying probe might match. Therefore, change the loop to keep going even after a match has been found.
Incidentally, it is actually only pid offset probes that could "collide" with any other overlying probes for a given pid:
(quoted diff) +0
-3-) pid return probes are implemented with uretprobes and so cannot "collide" with any other probes -) no two USDT probes -- is-enabled or not -- can map to the same underlying probe for any pid -) no USDT probe -- is-enabled or not -- can map to to the same underlying probe as a pid entrySo, possibly one could optimize the trampoline -- e.g., by adding BPF code to exit once two matches have been made.
Note that the flag we pass in to
dt_cg_tramp_copy_args_from_regs()should depend on whether the overlying probe is a pid or USDT probe. We used to checkPP_IS_FUNCALL, but the upp could be for both. So check the provider for the overlying probe instead. (A later patch will move USDT probes to a different mechanism anyhow.)Signed-off-by Eugene Loh <[email protected]>--- libdtrace/dt_prov_uprobe.c | 45 +++++----- test/unittest/pid/tst.entry_off0.sh | 125 ++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 26 deletions(-) create mode 100755 test/unittest/pid/tst.entry_off0.shlibdtrace/dt_prov_uprobe.c +0
-0@@ -754,38 +754,23 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)* // (%r7 = dctx->mst)
libdtrace/dt_prov_uprobe.c static int trampoline(dt_pcb_t *pcb, uint_t exitlbl) · line 757
Quoted 10 lines
libdtrace/dt_prov_uprobe.c +1
-7* // (%r8 = dctx->ctx) */ - -dt_cg_tramp_copy_regs (pcb); -if (upp->flags &PP_IS_RETURN ) -dt_cg_tramp_copy_rval_from_regs (pcb); -else -dt_cg_tramp_copy_args_from_regs (pcb, - !(upp->flags &PP_IS_FUNCALL )); +dt_cg_tramp_copy_regs (pcb);// call this only once for all clauses?
Per previous review, no need for the comment. The copying of the regs is a one-time only thing because nothing changes them.
Quoted 36 lines
libdtrace/dt_prov_uprobe.c +8
-17/* -* Retrieve the PID of the process that caused the probe to fire. +* Hold the PID of the process that caused the probe to fire in %r6. */ emit (dlp,BPF_CALL_HELPER (BPF_FUNC_get_current_pid_tgid));emit (dlp,BPF_ALU64_IMM (BPF_RSH ,BPF_REG_0 ,32 )); +emit (dlp,BPF_MOV_REG (BPF_REG_6 ,BPF_REG_0 ));/* -* Generate a composite conditional clause: +* Loop over overlying probes, calling clauses for those that match: * -* if (pid == PID1) { -* dctx->mst->prid = PRID1; -* < any number of clause calls > -* goto exit; -* } else if (pid == PID2) { -* dctx->mst->prid = PRID2; -* < any number of clause calls > -* goto exit; -* } else if (pid == ...) { -* < ... > -* } -* -* It is valid and safe to use %r0 to hold the pid value because there -* are no assignments to %r0 possible in between the conditional -* statements. +* for overlying probes (that match except possibly for pid) +* if (pid matches) { +* dctx->mst->prid = PRID1; +* < any number of clause calls > +* } */ for (pop =dt_list_next (&upp->probes); pop !=NULL ; pop =dt_list_next (pop)) {
libdtrace/dt_prov_uprobe.c static int trampoline(dt_pcb_t *pcb, uint_t exitlbl) · line 789
Quoted 5 lines
libdtrace/dt_prov_uprobe.c +2
-0@@ -800,14 +785,22 @@ static int trampoline(dt_pcb_t *pcb, uint_t exitlbl) idp =dt_dlib_add_probe_var (pcb->pcb_hdl, prp);assert (idp !=NULL ); +/* +* Register copies.
Actually, what we are doing in the following code is populate the probe arguments, so a better comment would be to state that?
Quoted 153 lines
libdtrace/dt_prov_uprobe.c +8
-2+*/ +if (upp->flags &PP_IS_RETURN ) +dt_cg_tramp_copy_rval_from_regs (pcb); +else +dt_cg_tramp_copy_args_from_regs (pcb, + prp->prov->impl == &dt_pid ?1 :0 ); +/* * Check whether this pid-provider probe serves the current * process, and emit a sequence of clauses for it when it does. */ -emit (dlp,BPF_BRANCH_IMM (BPF_JNE ,BPF_REG_0 , pid, lbl_next)); +emit (dlp,BPF_BRANCH_IMM (BPF_JNE ,BPF_REG_6 , pid, lbl_next));emite (dlp,BPF_STORE_IMM (BPF_W ,BPF_REG_7 ,DMST_PRID , prp->desc->id), idp);dt_cg_tramp_call_clauses (pcb, prp,DT_ACTIVITY_ACTIVE ); -emit (dlp,BPF_JUMP (lbl_exit));emitl (dlp, lbl_next,BPF_NOP ()); }test/unittest/pid/tst.entry_off0.sh new file +125
-0@@ -0,0 +1,125 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. +# + +dtrace=$1 + +trig=`pwd`/test/triggers/ustack-tst-basic + +DIRNAME="$tmpdir/enter_off0.$$.$RANDOM" +mkdir -p $DIRNAME +cd $DIRNAME + +# Run DTrace, dumping all probe functions and names, plus PC, in a.out. + +$dtrace $dt_flags -c $trig -n ' +pid$target:a.out:: +{ + @[probefunc, probename, uregs[R_PC]] = count(); +} + +profile:::tick-1s +{ + exit(0); +}' > D.out +if [ $? -ne 0 ]; then + echo ERROR: dtrace + cat D.out + exit 1 +fi + +# Generate the expected list of functions for our trigger program. + +echo main > expected.tmp +echo mycallee >> expected.tmp +for x in 0 1 2 3 4 5 6 7 8 9 \ + a b c d e f g h i j k l m n o p q r s t u v w x y z \ + A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do + echo myfunc_$x >> expected.tmp +done +sort expected.tmp > expected.txt + +# Check output for probe name "0" or "entry". + +awk '$2 == "0" || $2 == "entry"' D.out | awk ' +{ + fun = $1; + prb = $2; + PC = $3; + cnt = $4; +} + +# Check that the count is 1. +cnt != 1 { + print "ERROR: count is not 1"; + print; + exit(1); +} + +# Check that we have not gotten the same (fun,prb) already. +prb == "0" && fun in PC0 { + print "ERROR: already have offset 0 for this func"; + print; + exit(1); +} +prb == "entry" && fun in PCentry { + print "ERROR: already have entry for this func"; + print; + exit(1); +} + +# Record the PC. +prb == "0" { PC0[fun] = PC; } +prb == "entry" { PCentry[fun] = PC; } + +# Do final matchup. +END { + # Walk functions for the offset-0 probes. + for (fun in PC0) { + # Make sure each offset-0 probe has a matching entry probe. + if (!(fun in PCentry)) { + print "ERROR: func", fun, "has offset-0 but no entry"; + exit(1); + } + + # Make sure the matching probes report the same PC. + if (PC0[fun] != PCentry[fun]) { + print "ERROR: func", fun, "has mismatching PCs for offset-0 and entry:", PC0[fun], PCentry[fun]; + exit(1); + } + + # Dump the function name and delete these entries. + print fun; + delete PC0[fun]; + delete PCentry[fun]; + } + + # Check if there are any leftover entry probes. + for (fun in PCentry) { + print "ERROR: func", fun, "has entry but no offset-0"; + exit(1); + } +} +' | sort > awk.out + +# Report any problems. + +if ! diff -q awk.out expected.txt; then + echo ERROR: diff failure + echo ==== function list + cat awk.out + echo ==== expected function list + cat expected.txt + echo ==== diff + diff awk.out expected.txt + echo ==== DTrace output + cat D.out + exit 1 +fi + +echo success +exit 0Signature · 1 line
2.43.5